tls13_client.c
Go to the documentation of this file.
1 /**
2  * @file tls13_client.c
3  * @brief Handshake message processing (TLS 1.3 client)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSSL Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.5.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL TLS_TRACE_LEVEL
33 
34 //Dependencies
35 #include "tls.h"
36 #include "tls_cipher_suites.h"
37 #include "tls_handshake.h"
38 #include "tls_client_extensions.h"
39 #include "tls_client_misc.h"
40 #include "tls_extensions.h"
41 #include "tls_transcript_hash.h"
42 #include "tls_quic_misc.h"
43 #include "tls_misc.h"
44 #include "tls13_client.h"
46 #include "tls13_key_material.h"
47 #include "tls13_ticket.h"
48 #include "tls13_misc.h"
49 #include "kdf/hkdf.h"
50 #include "debug.h"
51 
52 //Check TLS library configuration
53 #if (TLS_SUPPORT == ENABLED && TLS_CLIENT_SUPPORT == ENABLED && \
54  TLS_MAX_VERSION >= TLS_VERSION_1_3)
55 
56 
57 /**
58  * @brief Send EndOfEarlyData message
59  *
60  * The EndOfEarlyData message indicates that all 0-RTT application data
61  * messages, if any, have been transmitted and that the following records
62  * are protected under handshake traffic keys
63  *
64  * @param[in] context Pointer to the TLS context
65  * @return Error code
66  **/
67 
69 {
70 #if (TLS13_EARLY_DATA_SUPPORT == ENABLED)
71  error_t error;
72  size_t length;
74 
75  //Point to the buffer where to format the message
76  message = (Tls13EndOfEarlyData *) (context->txBuffer + context->txBufferLen);
77 
78  //If the server has accepted early data, an EndOfEarlyData message will be
79  //sent to indicate the key change
80  error = tls13FormatEndOfEarlyData(context, message, &length);
81 
82  //Check status code
83  if(!error)
84  {
85  //Debug message
86  TRACE_INFO("Sending EndOfEarlyData message (%" PRIuSIZE " bytes)...\r\n", length);
88 
89  //Send handshake message
90  error = tlsSendHandshakeMessage(context, message, length,
92  }
93 
94  //Check status code
95  if(error == NO_ERROR || error == ERROR_WOULD_BLOCK || error == ERROR_TIMEOUT)
96  {
97  //Release encryption engine
98  tlsFreeEncryptionEngine(&context->encryptionEngine);
99 
100  //Calculate client handshake traffic keys
101  error = tlsInitEncryptionEngine(context, &context->encryptionEngine,
103  context->clientHsTrafficSecret);
104 
105  //Handshake traffic keys successfully calculated?
106  if(!error)
107  {
108  //Send a Finished message to the server
110  }
111  }
112 
113  //Return status code
114  return error;
115 #else
116  //Not implemented
117  return ERROR_NOT_IMPLEMENTED;
118 #endif
119 }
120 
121 
122 /**
123  * @brief Format EndOfEarlyData message
124  * @param[in] context Pointer to the TLS context
125  * @param[out] message Buffer where to format the EndOfEarlyData message
126  * @param[out] length Length of the resulting EndOfEarlyData message
127  * @return Error code
128  **/
129 
132 {
133  //The EndOfEarlyData message does not contain any data
134  *length = 0;
135 
136  //Successful processing
137  return NO_ERROR;
138 }
139 
140 
141 /**
142  * @brief Parse HelloRetryRequest message
143  *
144  * The server will send this message in response to a ClientHello message if
145  * it is able to find an acceptable set of parameters but the ClientHello does
146  * not contain sufficient information to proceed with the handshake
147  *
148  * @param[in] context Pointer to the TLS context
149  * @param[in] message Incoming HelloRetryRequest message to parse
150  * @param[in] length Message length
151  * @return Error code
152  **/
153 
155  const Tls13HelloRetryRequest *message, size_t length)
156 {
157  error_t error;
158  uint16_t cipherSuite;
159  uint8_t compressMethod;
160  const uint8_t *p;
161  const HashAlgo *hashAlgo;
163 
164  //Debug message
165  TRACE_INFO("HelloRetryRequest message received (%" PRIuSIZE " bytes)...\r\n", length);
167 
168  //Check TLS version
169  if(context->versionMax != TLS_VERSION_1_3)
171 
172  //If a client receives a second HelloRetryRequest in the same connection,
173  //it must abort the handshake with an unexpected_message alert
174  if(context->state != TLS_STATE_SERVER_HELLO &&
175  context->state != TLS_STATE_SERVER_HELLO_3)
176  {
177  //Report an error
179  }
180 
181  //Check the length of the ServerHello message
182  if(length < sizeof(TlsServerHello))
183  return ERROR_DECODING_FAILED;
184 
185  //Point to the session ID
186  p = message->sessionId;
187  //Remaining bytes to process
188  length -= sizeof(TlsServerHello);
189 
190  //Check the length of the session ID
191  if(message->sessionIdLen > length)
192  return ERROR_DECODING_FAILED;
193  if(message->sessionIdLen > 32)
194  return ERROR_DECODING_FAILED;
195 
196  //Point to the next field
197  p += message->sessionIdLen;
198  //Remaining bytes to process
199  length -= message->sessionIdLen;
200 
201  //Malformed ServerHello message?
202  if(length < sizeof(uint16_t))
203  return ERROR_DECODING_FAILED;
204 
205  //Get the negotiated cipher suite
207  //Point to the next field
208  p += sizeof(uint16_t);
209  //Remaining bytes to process
210  length -= sizeof(uint16_t);
211 
212  //Malformed ServerHello message?
213  if(length < sizeof(uint8_t))
214  return ERROR_DECODING_FAILED;
215 
216  //Get the value of the legacy_compression_method field
217  compressMethod = *p;
218  //Point to the next field
219  p += sizeof(uint8_t);
220  //Remaining bytes to process
221  length -= sizeof(uint8_t);
222 
223  //Legacy version
224  TRACE_INFO(" legacyVersion = 0x%04" PRIX16 " (%s)\r\n",
225  ntohs(message->serverVersion),
226  tlsGetVersionName(ntohs(message->serverVersion)));
227 
228  //Server random value
229  TRACE_DEBUG(" random\r\n");
230  TRACE_DEBUG_ARRAY(" ", message->random, 32);
231 
232  //Session identifier
233  TRACE_DEBUG(" sessionId\r\n");
234  TRACE_DEBUG_ARRAY(" ", message->sessionId, message->sessionIdLen);
235 
236  //Cipher suite identifier
237  TRACE_INFO(" cipherSuite = 0x%04" PRIX16 " (%s)\r\n",
239 
240  //Compression method
241  TRACE_DEBUG(" legacyCompressMethod = 0x%02" PRIX8 "\r\n", compressMethod);
242 
243  //The legacy_version field must be set to 0x0303, which is the version
244  //number for TLS 1.2
245  if(ntohs(message->serverVersion) != TLS_VERSION_1_2)
247 
248  //A client which receives a legacy_session_id_echo field that does not
249  //match what it sent in the ClientHello must abort the handshake with an
250  //illegal_parameter alert (RFC 8446, section 4.1.4)
251  if(message->sessionIdLen != context->sessionIdLen ||
252  osMemcmp(message->sessionId, context->sessionId, message->sessionIdLen))
253  {
254  //The legacy_session_id_echo field is not valid
256  }
257 
258  //Upon receipt of a HelloRetryRequest, the client must check that the
259  //legacy_compression_method is 0
260  if(compressMethod != TLS_COMPRESSION_METHOD_NULL)
261  return ERROR_DECODING_FAILED;
262 
263  //Parse the list of extensions offered by the server
265  &extensions);
266  //Any error to report?
267  if(error)
268  return error;
269 
270  //The HelloRetryRequest message must contain a SupportedVersions extension
271  if(extensions.selectedVersion == NULL)
273 
274  //TLS protocol?
275  if(context->transportProtocol == TLS_TRANSPORT_PROTOCOL_STREAM ||
276  context->transportProtocol == TLS_TRANSPORT_PROTOCOL_QUIC ||
277  context->transportProtocol == TLS_TRANSPORT_PROTOCOL_EAP)
278  {
279  //Release transcript hash context
280  tlsFreeTranscriptHash(context);
281 
282  //Format initial ClientHello message
283  error = tlsFormatInitialClientHello(context);
284  //Any error to report?
285  if(error)
286  return error;
287  }
288 
289  //The SupportedVersions extension contains the selected version
291  extensions.selectedVersion);
292  //Any error to report?
293  if(error)
294  return error;
295 
296  //Check the list of extensions offered by the server
298  context->version, &extensions);
299  //Any error to report?
300  if(error)
301  return error;
302 
303  //Set cipher suite
304  error = tlsSelectCipherSuite(context, cipherSuite);
305  //Specified cipher suite not supported?
306  if(error)
307  return error;
308 
309  //Initialize handshake message hashing
310  error = tlsInitTranscriptHash(context);
311  //Any error to report?
312  if(error)
313  return error;
314 
315  //When the server responds to a ClientHello with a HelloRetryRequest, the
316  //value of ClientHello1 is replaced with a special synthetic handshake
317  //message of handshake type MessageHash containing Hash(ClientHello1)
318  error = tls13DigestClientHello1(context);
319  //Any error to report?
320  if(error)
321  return error;
322 
323  //When sending a HelloRetryRequest, the server may provide a Cookie
324  //extension to the client
325  error = tls13ParseCookieExtension(context, extensions.cookie);
326  //Any error to report?
327  if(error)
328  return error;
329 
330  //The KeyShare extension contains the mutually supported group the server
331  //intends to negotiate
332  error = tls13ParseSelectedGroupExtension(context, extensions.selectedGroup);
333  //Any error to report?
334  if(error)
335  return error;
336 
337  //Point to the cipher suite hash algorithm
338  hashAlgo = context->cipherSuite.prfHashAlgo;
339  //Make sure the hash algorithm is valid
340  if(hashAlgo == NULL)
341  return ERROR_FAILURE;
342 
343  //In addition, in its updated ClientHello, the client should not offer any
344  //pre-shared keys associated with a hash other than that of the selected
345  //cipher suite. This allows the client to avoid having to compute partial
346  //hash transcripts for multiple hashes in the second ClientHello
347  if(tls13IsPskValid(context))
348  {
349  //Remove any PSKs which are incompatible with the server's indicated
350  //cipher suite
351  if(tlsGetHashAlgo(context->pskHashAlgo) != hashAlgo)
352  {
353  context->pskHashAlgo = TLS_HASH_ALGO_NONE;
354  context->ticketHashAlgo = TLS_HASH_ALGO_NONE;
355  }
356  }
357  else if(tls13IsTicketValid(context))
358  {
359  //Remove any PSKs which are incompatible with the server's indicated
360  //cipher suite
361  if(tlsGetHashAlgo(context->ticketHashAlgo) != hashAlgo)
362  {
363  context->ticketHashAlgo = TLS_HASH_ALGO_NONE;
364  }
365  }
366 
367  //Any 0-RTT data sent by the client?
368  if(context->earlyDataEnabled)
369  {
370  //A client must not include the EarlyData extension in its followup
371  //ClientHello (refer to RFC 8446, section 4.2.10)
372  context->earlyDataRejected = TRUE;
373  }
374 
375  //Clients must abort the handshake with an illegal_parameter alert if the
376  //HelloRetryRequest would not result in any change in the ClientHello
377  if(context->cookieLen == 0 && context->namedGroup == context->preferredGroup)
378  {
379  //Report an error
381  }
382 
383  //Another handshake message cannot be packed in the same record as the
384  //HelloRetryRequest
385  if(context->rxBufferLen != 0)
387 
388 #if (TLS13_MIDDLEBOX_COMPAT_SUPPORT == ENABLED)
389  //The middlebox compatibility mode improves the chance of successfully
390  //connecting through middleboxes
391  if(context->transportProtocol == TLS_TRANSPORT_PROTOCOL_STREAM &&
392  context->state == TLS_STATE_SERVER_HELLO)
393  {
394  //In middlebox compatibility mode, the client sends a dummy
395  //ChangeCipherSpec record immediately before its second flight
397  }
398  else
399 #endif
400  {
401  //The client can send its second flight
403  }
404 
405  //Successful processing
406  return NO_ERROR;
407 }
408 
409 
410 /**
411  * @brief Parse EncryptedExtensions message
412  *
413  * The server sends the EncryptedExtensions message immediately after the
414  * ServerHello message. The EncryptedExtensions message contains extensions
415  * that can be protected
416  *
417  * @param[in] context Pointer to the TLS context
418  * @param[in] message Incoming EncryptedExtensions message to parse
419  * @param[in] length Message length
420  * @return Error code
421  **/
422 
424  const Tls13EncryptedExtensions *message, size_t length)
425 {
426  error_t error;
428 
429  //Debug message
430  TRACE_INFO("EncryptedExtensions message received (%" PRIuSIZE " bytes)...\r\n", length);
432 
433  //Check TLS version
434  if(context->version != TLS_VERSION_1_3)
436 
437  //Check current state
438  if(context->state != TLS_STATE_ENCRYPTED_EXTENSIONS)
440 
441  //Check the length of the EncryptedExtensions message
442  if(length < sizeof(Tls13EncryptedExtensions))
443  return ERROR_DECODING_FAILED;
444 
445  //Parse the list of extensions offered by the server
447  (uint8_t *) message, length, &extensions);
448  //Any error to report?
449  if(error)
450  return error;
451 
452  //Check the list of extensions offered by the server
454  context->version, &extensions);
455  //Any error to report?
456  if(error)
457  return error;
458 
459 #if (TLS_SNI_SUPPORT == ENABLED)
460  //When the server includes a ServerName extension, the data field of
461  //this extension may be empty
462  error = tlsParseServerSniExtension(context, extensions.serverNameList);
463  //Any error to report?
464  if(error)
465  return error;
466 #endif
467 
468 #if (TLS_MAX_FRAG_LEN_SUPPORT == ENABLED && TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
469  //A client must treat receipt of both MaxFragmentLength and RecordSizeLimit
470  //extensions as a fatal error, and it should generate an illegal_parameter
471  //alert (refer to RFC 8449, section 5)
472  if(extensions.maxFragLen != NULL && extensions.recordSizeLimit != NULL)
474 #endif
475 
476 #if (TLS_MAX_FRAG_LEN_SUPPORT == ENABLED)
477  //Servers that receive an ClientHello containing a MaxFragmentLength
478  //extension may accept the requested maximum fragment length by including
479  //an extension of type MaxFragmentLength in the ServerHello
480  error = tlsParseServerMaxFragLenExtension(context, extensions.maxFragLen);
481  //Any error to report?
482  if(error)
483  return error;
484 #endif
485 
486 #if (TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
487  //The value of RecordSizeLimit is the maximum size of record in octets
488  //that the peer is willing to receive
490  extensions.recordSizeLimit);
491  //Any error to report?
492  if(error)
493  return error;
494 #endif
495 
496 #if (TLS_ALPN_SUPPORT == ENABLED)
497  //Parse ALPN extension
498  error = tlsParseServerAlpnExtension(context, extensions.protocolNameList);
499  //Any error to report?
500  if(error)
501  return error;
502 #endif
503 
504 #if (TLS_RAW_PUBLIC_KEY_SUPPORT == ENABLED)
505  //Parse ClientCertType extension
506  error = tlsParseClientCertTypeExtension(context, extensions.clientCertType);
507  //Any error to report?
508  if(error)
509  return error;
510 
511  //Parse ServerCertType extension
512  error = tlsParseServerCertTypeExtension(context, extensions.serverCertType);
513  //Any error to report?
514  if(error)
515  return error;
516 #endif
517 
518 #if (TLS13_EARLY_DATA_SUPPORT == ENABLED)
519  //Parse EarlyData extension
520  error = tls13ParseServerEarlyDataExtension(context,
521  TLS_TYPE_ENCRYPTED_EXTENSIONS, extensions.earlyDataIndication);
522  //Any error to report?
523  if(error)
524  return error;
525 
526  //Check whether the server has accepted the early data
527  if(context->earlyDataExtReceived)
528  {
529 #if (TLS_ALPN_SUPPORT == ENABLED)
530  //Valid ticket?
531  if(!tls13IsPskValid(context) && tls13IsTicketValid(context))
532  {
533  //Enforce ALPN protocol
534  if(context->selectedProtocol != NULL || context->ticketAlpn != NULL)
535  {
536  if(context->selectedProtocol != NULL && context->ticketAlpn != NULL)
537  {
538  //Compare the selected ALPN protocol against the expected value
539  if(osStrcmp(context->selectedProtocol, context->ticketAlpn) != 0)
540  {
541  //The selected ALPN protocol is not acceptable
542  return ERROR_HANDSHAKE_FAILED;
543  }
544  }
545  else
546  {
547  //The selected ALPN protocol is not acceptable
548  return ERROR_HANDSHAKE_FAILED;
549  }
550  }
551  }
552 #endif
553 
554  //The EndOfEarlyData message is encrypted with the 0-RTT traffic keys
555  tlsFreeEncryptionEngine(&context->encryptionEngine);
556 
557  //Calculate client early traffic keys
558  error = tlsInitEncryptionEngine(context, &context->encryptionEngine,
560  context->clientEarlyTrafficSecret);
561  //Any error to report?
562  if(error)
563  return error;
564 
565  //Restore sequence number
566  context->encryptionEngine.seqNum = context->earlyDataSeqNum;
567  }
568 #endif
569 
570 #if (TLS_QUIC_SUPPORT == ENABLED)
571  //Parse QuicTransportParameters extension
572  error = tlsParseQuicTransportParamsExtension(context,
573  extensions.quicTransportParams);
574  //Any error to report?
575  if(error)
576  return error;
577 #endif
578 
579  //PSK key exchange method?
580  if(context->keyExchMethod == TLS13_KEY_EXCH_PSK ||
581  context->keyExchMethod == TLS13_KEY_EXCH_PSK_DHE ||
582  context->keyExchMethod == TLS13_KEY_EXCH_PSK_ECDHE ||
583  context->keyExchMethod == TLS13_KEY_EXCH_PSK_HYBRID)
584  {
585  //As the server is authenticating via a PSK, it does not send a
586  //Certificate or a CertificateVerify message
588  }
589  else
590  {
591  //A server can optionally request a certificate from the client
593  }
594 
595  //Successful processing
596  return NO_ERROR;
597 }
598 
599 
600 /**
601  * @brief Parse NewSessionTicket message
602  *
603  * At any time after the server has received the client Finished message, it
604  * may send a NewSessionTicket message
605  *
606  * @param[in] context Pointer to the TLS context
607  * @param[in] message Incoming NewSessionTicket message to parse
608  * @param[in] length Message length
609  * @return Error code
610  **/
611 
613  const Tls13NewSessionTicket *message, size_t length)
614 {
615  error_t error;
616  size_t n;
617  const uint8_t *p;
618  const Tls13Ticket *ticket;
619  const HashAlgo *hashAlgo;
621 
622  //Debug message
623  TRACE_INFO("NewSessionTicket message received (%" PRIuSIZE " bytes)...\r\n", length);
625 
626  //Check TLS version
627  if(context->version != TLS_VERSION_1_3)
629 
630  //Check current state
631  if(context->state != TLS_STATE_APPLICATION_DATA &&
632  context->state != TLS_STATE_CLOSING)
633  {
634  //Report an error
636  }
637 
638  //Check the length of the NewSessionTicket message
639  if(length < sizeof(Tls13NewSessionTicket))
640  return ERROR_DECODING_FAILED;
641 
642  //Point to the ticket nonce
643  p = message->ticketNonce;
644  //Remaining bytes to process
645  length -= sizeof(Tls13NewSessionTicket);
646 
647  //Malformed NewSessionTicket message?
648  if(length < message->ticketNonceLen)
649  return ERROR_DECODING_FAILED;
650 
651  //Point to the next field
652  p += message->ticketNonceLen;
653  //Remaining bytes to process
654  length -= message->ticketNonceLen;
655 
656  //Malformed NewSessionTicket message?
657  if(length < sizeof(Tls13Ticket))
658  return ERROR_DECODING_FAILED;
659 
660  //Point to the session ticket
661  ticket = (Tls13Ticket *) p;
662  //Retrieve the length of the ticket
663  n = ntohs(ticket->length);
664 
665  //Empty tickets are not allowed
666  if(n == 0)
667  return ERROR_DECODING_FAILED;
668 
669  //Malformed NewSessionTicket message?
670  if(length < (sizeof(Tls13Ticket) + n))
671  return ERROR_DECODING_FAILED;
672 
673  //Point to the next field
674  p += sizeof(Tls13Ticket) + n;
675  //Remaining bytes to process
676  length -= sizeof(Tls13Ticket) + n;
677 
678  //The message includes a set of extension values for the ticket
680  &extensions);
681  //Any error to report?
682  if(error)
683  return error;
684 
685  //Check the list of extensions offered by the server
687  context->version, &extensions);
688  //Any error to report?
689  if(error)
690  return error;
691 
692  //A ticket_lifetime value of zero indicates that the ticket should be
693  //discarded immediately
694  if(ntohl(message->ticketLifetime) > 0)
695  {
696  //Check the length of the session ticket
697  if(n <= TLS13_MAX_TICKET_SIZE)
698  {
699  //Servers may send multiple tickets on a single connection
700  if(context->ticket != NULL)
701  {
702  //Release memory
703  osMemset(context->ticket, 0, context->ticketLen);
704  tlsFreeMem(context->ticket);
705  context->ticket = NULL;
706  context->ticketLen = 0;
707  }
708 
709  //Allocate a memory block to hold the ticket
710  context->ticket = tlsAllocMem(n);
711  //Failed to allocate memory?
712  if(context->ticket == NULL)
713  return ERROR_OUT_OF_MEMORY;
714 
715  //Copy session ticket
716  osMemcpy(context->ticket, ticket->data, n);
717  context->ticketLen = n;
718 
719  //The client's view of the age of a ticket is the time since the
720  //receipt of the NewSessionTicket message
721  context->ticketTimestamp = osGetSystemTime();
722 
723  //Save the lifetime of the ticket
724  context->ticketLifetime = ntohl(message->ticketLifetime);
725 
726  //Clients must not cache tickets for longer than 7 days, regardless
727  //of the ticket_lifetime value (refer to RFC 8446, section 4.6.1)
728  context->ticketLifetime = MIN(context->ticketLifetime,
730 
731  //Random value used to obscure the age of the ticket
732  context->ticketAgeAdd = ntohl(message->ticketAgeAdd);
733 
734  //The sole extension currently defined for NewSessionTicket is
735  //EarlyData indicating that the ticket may be used to send 0-RTT data
736  error = tls13ParseServerEarlyDataExtension(context,
737  TLS_TYPE_NEW_SESSION_TICKET, extensions.earlyDataIndication);
738  //Any error to report?
739  if(error)
740  return error;
741 
742  //The hash function used by HKDF is the cipher suite hash algorithm
743  hashAlgo = context->cipherSuite.prfHashAlgo;
744  //Make sure the hash algorithm is valid
745  if(hashAlgo == NULL)
746  return ERROR_FAILURE;
747 
748  //Calculate the PSK associated with the ticket
749  error = tls13HkdfExpandLabel(context->transportProtocol, hashAlgo,
750  context->resumptionMasterSecret, hashAlgo->digestSize, "resumption",
751  message->ticketNonce, message->ticketNonceLen, context->ticketPsk,
752  hashAlgo->digestSize);
753  //Any error to report?
754  if(error)
755  return error;
756 
757  //Set the length of the PSK associated with the ticket
758  context->ticketPskLen = hashAlgo->digestSize;
759 
760  //Debug message
761  TRACE_DEBUG("Ticket PSK:\r\n");
762  TRACE_DEBUG_ARRAY(" ", context->ticketPsk, context->ticketPskLen);
763  }
764  }
765 
766  //Successful processing
767  return NO_ERROR;
768 }
769 
770 #endif
@ TLS13_KEY_EXCH_PSK
Definition: tls.h:1207
#define tlsAllocMem(size)
Definition: tls.h:888
Parsing and checking of TLS extensions.
#define TLS13_MAX_TICKET_LIFETIME
Definition: tls13_misc.h:127
TLS helper functions.
uint8_t extensions[]
Definition: ntp_common.h:213
@ TLS_TRANSPORT_PROTOCOL_QUIC
Definition: tls.h:1001
TLS cipher suites.
uint16_t cipherSuite
Cipher suite identifier.
Definition: tls.h:2001
const HashAlgo * tlsGetHashAlgo(TlsHashAlgo hashAlgoId)
Get the hash algorithm that matches the specified identifier.
Definition: tls_misc.c:1193
@ ERROR_WOULD_BLOCK
Definition: error.h:96
@ TLS13_KEY_EXCH_PSK_DHE
Definition: tls.h:1208
TLS handshake.
@ TLS_COMPRESSION_METHOD_NULL
Definition: tls.h:1173
@ ERROR_VERSION_NOT_SUPPORTED
Definition: error.h:67
@ ERROR_NOT_IMPLEMENTED
Definition: error.h:66
@ ERROR_ILLEGAL_PARAMETER
Definition: error.h:244
@ ERROR_UNEXPECTED_MESSAGE
Definition: error.h:195
QUIC helper functions.
uint8_t p
Definition: ndp.h:300
Helper functions for TLS client.
uint8_t message[]
Definition: chap.h:154
#define TRUE
Definition: os_port.h:50
@ TLS_STATE_CERTIFICATE_REQUEST
Definition: tls.h:1552
size_t digestSize
Definition: crypto.h:1130
error_t tlsParseServerRecordSizeLimitExtension(TlsContext *context, const TlsExtension *recordSizeLimit)
Parse RecordSizeLimit extension.
TLS 1.3 session tickets.
@ TLS_STATE_APPLICATION_DATA
Definition: tls.h:1568
#define osMemcmp(p1, p2, length)
Definition: os_port.h:156
@ ERROR_HANDSHAKE_FAILED
Definition: error.h:234
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
error_t tlsParseServerSniExtension(TlsContext *context, const TlsServerNameList *serverNameList)
Parse SNI extension.
error_t tlsParseClientCertTypeExtension(TlsContext *context, const TlsExtension *clientCertType)
Parse ClientCertType extension.
#define osStrcmp(s1, s2)
Definition: os_port.h:174
error_t tls13ParseEncryptedExtensions(TlsContext *context, const Tls13EncryptedExtensions *message, size_t length)
Parse EncryptedExtensions message.
Definition: tls13_client.c:423
error_t tls13FormatEndOfEarlyData(TlsContext *context, Tls13EndOfEarlyData *message, size_t *length)
Format EndOfEarlyData message.
Definition: tls13_client.c:130
uint8_t ticketNonceLen
Definition: tls13_misc.h:340
@ TLS_ENCRYPTION_LEVEL_EARLY_DATA
Definition: tls.h:1581
error_t tlsSendHandshakeMessage(TlsContext *context, const void *data, size_t length, TlsMessageType type)
Send handshake message.
@ TLS_TYPE_END_OF_EARLY_DATA
Definition: tls.h:1089
@ TLS_ENCRYPTION_LEVEL_HANDSHAKE
Definition: tls.h:1582
@ TLS13_KEY_EXCH_PSK_HYBRID
Definition: tls.h:1211
error_t tls13ParseNewSessionTicket(TlsContext *context, const Tls13NewSessionTicket *message, size_t length)
Parse NewSessionTicket message.
Definition: tls13_client.c:612
@ TLS_HASH_ALGO_NONE
Definition: tls.h:1260
TLS 1.3 helper functions.
error_t tls13ParseSelectedGroupExtension(TlsContext *context, const TlsExtension *selectedGroup)
Parse KeyShare extension (HelloRetryRequest message)
@ TLS_STATE_SERVER_HELLO
Definition: tls.h:1544
error_t tls13SendEndOfEarlyData(TlsContext *context)
Send EndOfEarlyData message.
Definition: tls13_client.c:68
error_t tlsParseServerMaxFragLenExtension(TlsContext *context, const TlsExtension *maxFragLen)
Parse MaxFragmentLength extension.
error_t tls13ParseServerSupportedVersionsExtension(TlsContext *context, const TlsExtension *selectedVersion)
Parse SupportedVersions extension.
#define osMemcpy(dest, src, length)
Definition: os_port.h:144
#define TlsContext
Definition: tls.h:36
error_t
Error codes.
Definition: error.h:43
error_t tlsParseServerCertTypeExtension(TlsContext *context, const TlsExtension *serverCertType)
Parse ServerCertType extension.
void tlsFreeEncryptionEngine(TlsEncryptionEngine *encryptionEngine)
Release encryption engine.
Definition: tls_misc.c:928
#define TLS_VERSION_1_2
Definition: tls.h:96
Tls13HelloRetryRequest
Definition: tls13_misc.h:311
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
error_t tlsSelectCipherSuite(TlsContext *context, uint16_t identifier)
Set cipher suite.
Definition: tls_misc.c:335
error_t tlsParseHelloExtensions(TlsMessageType msgType, const uint8_t *p, size_t length, TlsHelloExtensions *extensions)
Parse Hello extensions.
@ TLS_STATE_SERVER_FINISHED
Definition: tls.h:1563
#define TLS_VERSION_1_3
Definition: tls.h:97
@ TLS_TYPE_ENCRYPTED_EXTENSIONS
Definition: tls.h:1091
bool_t tls13IsTicketValid(TlsContext *context)
Check whether a session ticket is valid.
Definition: tls13_ticket.c:51
@ TLS_TRANSPORT_PROTOCOL_EAP
Definition: tls.h:1002
@ TLS_STATE_SERVER_HELLO_3
Definition: tls.h:1546
error_t tlsFormatInitialClientHello(TlsContext *context)
Format initial ClientHello message.
#define TRACE_INFO(...)
Definition: debug.h:105
uint8_t length
Definition: tcp.h:375
#define MIN(a, b)
Definition: os_port.h:63
@ TLS_STATE_CLIENT_CHANGE_CIPHER_SPEC
Definition: tls.h:1557
Hello extensions.
Definition: tls.h:2253
Transcript hash calculation.
Tls13Ticket
Definition: tls13_misc.h:363
Formatting and parsing of extensions (TLS client)
#define ntohs(value)
Definition: cpu_endian.h:421
error_t tls13ParseCookieExtension(TlsContext *context, const Tls13Cookie *cookie)
Parse Cookie extension.
#define TLS13_MAX_TICKET_SIZE
Definition: tls13_misc.h:120
#define TRACE_DEBUG(...)
Definition: debug.h:119
@ ERROR_TIMEOUT
Definition: error.h:95
uint8_t ticket[]
Definition: tls.h:1962
@ TLS13_KEY_EXCH_PSK_ECDHE
Definition: tls.h:1209
@ TLS_STATE_CLIENT_HELLO_2
Definition: tls.h:1540
@ TLS_STATE_CLOSING
Definition: tls.h:1569
#define TRACE_DEBUG_ARRAY(p, a, n)
Definition: debug.h:120
const char_t * tlsGetCipherSuiteName(uint16_t identifier)
Convert cipher suite identifier to string representation.
TlsServerHello
Definition: tls.h:1905
bool_t tls13IsPskValid(TlsContext *context)
Check whether an externally established PSK is valid.
Definition: tls13_misc.c:915
uint8_t n
HKDF (HMAC-based Key Derivation Function)
Tls13NewSessionTicket
Definition: tls13_misc.h:342
@ TLS_STATE_ENCRYPTED_EXTENSIONS
Definition: tls.h:1548
error_t tls13ParseHelloRetryRequest(TlsContext *context, const Tls13HelloRetryRequest *message, size_t length)
Parse HelloRetryRequest message.
Definition: tls13_client.c:154
error_t tlsInitTranscriptHash(TlsContext *context)
Initialize handshake message hashing.
@ TLS_CONNECTION_END_CLIENT
Definition: tls.h:1012
Formatting and parsing of extensions (TLS 1.3 client)
TLS (Transport Layer Security)
error_t tlsParseQuicTransportParamsExtension(TlsContext *context, const TlsExtension *quicTransportParams)
Parse QuicTransportParameters extension.
void * Tls13EndOfEarlyData
EndOfEarlyData message.
Definition: tls13_misc.h:318
@ TLS_TRANSPORT_PROTOCOL_STREAM
Definition: tls.h:999
error_t tlsCheckHelloExtensions(TlsMessageType msgType, uint16_t version, TlsHelloExtensions *extensions)
Check Hello extensions.
TLS 1.3 key schedule.
Common interface for hash algorithms.
Definition: crypto.h:1124
error_t tlsParseServerAlpnExtension(TlsContext *context, const TlsProtocolNameList *protocolNameList)
Parse ALPN extension.
error_t tls13HkdfExpandLabel(TlsTransportProtocol transportProtocol, const HashAlgo *hash, const uint8_t *secret, size_t secretLen, const char_t *label, const uint8_t *context, size_t contextLen, uint8_t *output, size_t outputLen)
HKDF-Expand-Label function.
const char_t * tlsGetVersionName(uint16_t version)
Convert TLS version to string representation.
Definition: tls_misc.c:1132
@ TLS_TYPE_NEW_SESSION_TICKET
Definition: tls.h:1088
void tlsChangeState(TlsContext *context, TlsState newState)
Update TLS state.
Definition: tls_misc.c:54
@ ERROR_DECODING_FAILED
Definition: error.h:242
@ TLS_TYPE_HELLO_RETRY_REQUEST
Definition: tls.h:1090
#define PRIuSIZE
#define LOAD16BE(p)
Definition: cpu_endian.h:186
#define osMemset(p, value, length)
Definition: os_port.h:138
#define tlsFreeMem(p)
Definition: tls.h:893
error_t tls13DigestClientHello1(TlsContext *context)
Hash ClientHello1 in the transcript when HelloRetryRequest is used.
Definition: tls13_misc.c:870
@ TLS_STATE_CLIENT_FINISHED
Definition: tls.h:1559
Handshake message processing (TLS 1.3 client)
#define ntohl(value)
Definition: cpu_endian.h:422
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
void tlsFreeTranscriptHash(TlsContext *context)
Release transcript hash context.
__weak_func error_t tlsInitEncryptionEngine(TlsContext *context, TlsEncryptionEngine *encryptionEngine, TlsConnectionEnd entity, TlsEncryptionLevel level, const uint8_t *secret)
Initialize encryption engine.
Definition: tls_misc.c:675
Tls13EncryptedExtensions
Definition: tls13_misc.h:329
error_t tls13ParseServerEarlyDataExtension(TlsContext *context, TlsMessageType msgType, const TlsExtension *earlyDataIndication)
Parse EarlyData extension.
systime_t osGetSystemTime(void)
Retrieve system time.