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-2026 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.6.0
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  //DTLS protocol?
244  if(context->transportProtocol == TLS_TRANSPORT_PROTOCOL_DATAGRAM)
245  {
246  //The legacy_version field must be set to {254, 253}, which is the
247  //version number for DTLS 1.2
248  if(ntohs(message->serverVersion) != DTLS_VERSION_1_2)
250  }
251  else
252  {
253  //The legacy_version field must be set to 0x0303, which is the version
254  //number for TLS 1.2
255  if(ntohs(message->serverVersion) != TLS_VERSION_1_2)
257  }
258 
259  //A client which receives a legacy_session_id_echo field that does not
260  //match what it sent in the ClientHello must abort the handshake with an
261  //illegal_parameter alert (RFC 8446, section 4.1.4)
262  if(message->sessionIdLen != context->sessionIdLen ||
263  osMemcmp(message->sessionId, context->sessionId, message->sessionIdLen))
264  {
265  //The legacy_session_id_echo field is not valid
267  }
268 
269  //Upon receipt of a HelloRetryRequest, the client must check that the
270  //legacy_compression_method is 0
271  if(compressMethod != TLS_COMPRESSION_METHOD_NULL)
272  return ERROR_DECODING_FAILED;
273 
274  //Parse the list of extensions offered by the server
276  &extensions);
277  //Any error to report?
278  if(error)
279  return error;
280 
281  //The HelloRetryRequest message must contain a SupportedVersions extension
282  if(extensions.selectedVersion == NULL)
284 
285  //TLS protocol?
286  if(context->transportProtocol == TLS_TRANSPORT_PROTOCOL_STREAM ||
287  context->transportProtocol == TLS_TRANSPORT_PROTOCOL_QUIC ||
288  context->transportProtocol == TLS_TRANSPORT_PROTOCOL_EAP)
289  {
290  //Release transcript hash context
291  tlsFreeTranscriptHash(context);
292 
293  //Format initial ClientHello message
294  error = tlsFormatInitialClientHello(context);
295  //Any error to report?
296  if(error)
297  return error;
298  }
299 
300  //The SupportedVersions extension contains the selected version
302  extensions.selectedVersion);
303  //Any error to report?
304  if(error)
305  return error;
306 
307  //Check the list of extensions offered by the server
309  context->version, &extensions);
310  //Any error to report?
311  if(error)
312  return error;
313 
314  //Set cipher suite
315  error = tlsSelectCipherSuite(context, cipherSuite);
316  //Specified cipher suite not supported?
317  if(error)
318  return error;
319 
320  //Initialize handshake message hashing
321  error = tlsInitTranscriptHash(context);
322  //Any error to report?
323  if(error)
324  return error;
325 
326  //When the server responds to a ClientHello with a HelloRetryRequest, the
327  //value of ClientHello1 is replaced with a special synthetic handshake
328  //message of handshake type MessageHash containing Hash(ClientHello1)
329  error = tls13DigestClientHello1(context);
330  //Any error to report?
331  if(error)
332  return error;
333 
334  //When sending a HelloRetryRequest, the server may provide a Cookie
335  //extension to the client
336  error = tls13ParseCookieExtension(context, extensions.cookie);
337  //Any error to report?
338  if(error)
339  return error;
340 
341  //The KeyShare extension contains the mutually supported group the server
342  //intends to negotiate
343  error = tls13ParseSelectedGroupExtension(context, extensions.selectedGroup);
344  //Any error to report?
345  if(error)
346  return error;
347 
348  //Point to the cipher suite hash algorithm
349  hashAlgo = context->cipherSuite.prfHashAlgo;
350  //Make sure the hash algorithm is valid
351  if(hashAlgo == NULL)
352  return ERROR_FAILURE;
353 
354  //In addition, in its updated ClientHello, the client should not offer any
355  //pre-shared keys associated with a hash other than that of the selected
356  //cipher suite. This allows the client to avoid having to compute partial
357  //hash transcripts for multiple hashes in the second ClientHello
358  if(tls13IsPskValid(context))
359  {
360  //Remove any PSKs which are incompatible with the server's indicated
361  //cipher suite
362  if(tlsGetHashAlgo(context->pskHashAlgo) != hashAlgo)
363  {
364  context->pskHashAlgo = TLS_HASH_ALGO_NONE;
365  context->ticketHashAlgo = TLS_HASH_ALGO_NONE;
366  }
367  }
368  else if(tls13IsTicketValid(context))
369  {
370  //Remove any PSKs which are incompatible with the server's indicated
371  //cipher suite
372  if(tlsGetHashAlgo(context->ticketHashAlgo) != hashAlgo)
373  {
374  context->ticketHashAlgo = TLS_HASH_ALGO_NONE;
375  }
376  }
377 
378  //Any 0-RTT data sent by the client?
379  if(context->earlyDataEnabled)
380  {
381  //A client must not include the EarlyData extension in its followup
382  //ClientHello (refer to RFC 8446, section 4.2.10)
383  context->earlyDataRejected = TRUE;
384  }
385 
386  //Clients must abort the handshake with an illegal_parameter alert if the
387  //HelloRetryRequest would not result in any change in the ClientHello
388  if(context->cookieLen == 0 && context->namedGroup == context->preferredGroup)
389  {
390  //Report an error
392  }
393 
394  //Another handshake message cannot be packed in the same record as the
395  //HelloRetryRequest
396  if(context->rxBufferLen != 0)
398 
399 #if (TLS13_MIDDLEBOX_COMPAT_SUPPORT == ENABLED)
400  //The middlebox compatibility mode improves the chance of successfully
401  //connecting through middleboxes
402  if(context->transportProtocol == TLS_TRANSPORT_PROTOCOL_STREAM &&
403  context->state == TLS_STATE_SERVER_HELLO)
404  {
405  //In middlebox compatibility mode, the client sends a dummy
406  //ChangeCipherSpec record immediately before its second flight
408  }
409  else
410 #endif
411  {
412  //The client can send its second flight
414  }
415 
416  //Successful processing
417  return NO_ERROR;
418 }
419 
420 
421 /**
422  * @brief Parse EncryptedExtensions message
423  *
424  * The server sends the EncryptedExtensions message immediately after the
425  * ServerHello message. The EncryptedExtensions message contains extensions
426  * that can be protected
427  *
428  * @param[in] context Pointer to the TLS context
429  * @param[in] message Incoming EncryptedExtensions message to parse
430  * @param[in] length Message length
431  * @return Error code
432  **/
433 
435  const Tls13EncryptedExtensions *message, size_t length)
436 {
437  error_t error;
439 
440  //Debug message
441  TRACE_INFO("EncryptedExtensions message received (%" PRIuSIZE " bytes)...\r\n", length);
443 
444  //Check TLS version
445  if(context->version != TLS_VERSION_1_3)
447 
448  //Check current state
449  if(context->state != TLS_STATE_ENCRYPTED_EXTENSIONS)
451 
452  //Check the length of the EncryptedExtensions message
453  if(length < sizeof(Tls13EncryptedExtensions))
454  return ERROR_DECODING_FAILED;
455 
456  //Parse the list of extensions offered by the server
458  (uint8_t *) message, length, &extensions);
459  //Any error to report?
460  if(error)
461  return error;
462 
463  //Check the list of extensions offered by the server
465  context->version, &extensions);
466  //Any error to report?
467  if(error)
468  return error;
469 
470 #if (TLS_SNI_SUPPORT == ENABLED)
471  //When the server includes a ServerName extension, the data field of
472  //this extension may be empty
473  error = tlsParseServerSniExtension(context, extensions.serverNameList);
474  //Any error to report?
475  if(error)
476  return error;
477 #endif
478 
479 #if (TLS_MAX_FRAG_LEN_SUPPORT == ENABLED && TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
480  //A client must treat receipt of both MaxFragmentLength and RecordSizeLimit
481  //extensions as a fatal error, and it should generate an illegal_parameter
482  //alert (refer to RFC 8449, section 5)
483  if(extensions.maxFragLen != NULL && extensions.recordSizeLimit != NULL)
485 #endif
486 
487 #if (TLS_MAX_FRAG_LEN_SUPPORT == ENABLED)
488  //Servers that receive an ClientHello containing a MaxFragmentLength
489  //extension may accept the requested maximum fragment length by including
490  //an extension of type MaxFragmentLength in the ServerHello
491  error = tlsParseServerMaxFragLenExtension(context, extensions.maxFragLen);
492  //Any error to report?
493  if(error)
494  return error;
495 #endif
496 
497 #if (TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
498  //The value of RecordSizeLimit is the maximum size of record in octets
499  //that the peer is willing to receive
501  extensions.recordSizeLimit);
502  //Any error to report?
503  if(error)
504  return error;
505 #endif
506 
507 #if (TLS_ALPN_SUPPORT == ENABLED)
508  //Parse ALPN extension
509  error = tlsParseServerAlpnExtension(context, extensions.protocolNameList);
510  //Any error to report?
511  if(error)
512  return error;
513 #endif
514 
515 #if (TLS_RAW_PUBLIC_KEY_SUPPORT == ENABLED)
516  //Parse ClientCertType extension
517  error = tlsParseClientCertTypeExtension(context, extensions.clientCertType);
518  //Any error to report?
519  if(error)
520  return error;
521 
522  //Parse ServerCertType extension
523  error = tlsParseServerCertTypeExtension(context, extensions.serverCertType);
524  //Any error to report?
525  if(error)
526  return error;
527 #endif
528 
529 #if (TLS13_EARLY_DATA_SUPPORT == ENABLED)
530  //Parse EarlyData extension
531  error = tls13ParseServerEarlyDataExtension(context,
532  TLS_TYPE_ENCRYPTED_EXTENSIONS, extensions.earlyDataIndication);
533  //Any error to report?
534  if(error)
535  return error;
536 
537  //Check whether the server has accepted the early data
538  if(context->earlyDataExtReceived)
539  {
540 #if (TLS_ALPN_SUPPORT == ENABLED)
541  //Valid ticket?
542  if(!tls13IsPskValid(context) && tls13IsTicketValid(context))
543  {
544  //Enforce ALPN protocol
545  if(context->selectedProtocol != NULL || context->ticketAlpn != NULL)
546  {
547  if(context->selectedProtocol != NULL && context->ticketAlpn != NULL)
548  {
549  //Compare the selected ALPN protocol against the expected value
550  if(osStrcmp(context->selectedProtocol, context->ticketAlpn) != 0)
551  {
552  //The selected ALPN protocol is not acceptable
553  return ERROR_HANDSHAKE_FAILED;
554  }
555  }
556  else
557  {
558  //The selected ALPN protocol is not acceptable
559  return ERROR_HANDSHAKE_FAILED;
560  }
561  }
562  }
563 #endif
564 
565  //The EndOfEarlyData message is encrypted with the 0-RTT traffic keys
566  tlsFreeEncryptionEngine(&context->encryptionEngine);
567 
568  //Calculate client early traffic keys
569  error = tlsInitEncryptionEngine(context, &context->encryptionEngine,
571  context->clientEarlyTrafficSecret);
572  //Any error to report?
573  if(error)
574  return error;
575 
576  //Restore sequence number
577  context->encryptionEngine.seqNum = context->earlyDataSeqNum;
578  }
579 #endif
580 
581 #if (TLS_QUIC_SUPPORT == ENABLED)
582  //Parse QuicTransportParameters extension
583  error = tlsParseQuicTransportParamsExtension(context,
584  extensions.quicTransportParams);
585  //Any error to report?
586  if(error)
587  return error;
588 #endif
589 
590  //PSK key exchange method?
591  if(context->keyExchMethod == TLS13_KEY_EXCH_PSK ||
592  context->keyExchMethod == TLS13_KEY_EXCH_PSK_DHE ||
593  context->keyExchMethod == TLS13_KEY_EXCH_PSK_ECDHE ||
594  context->keyExchMethod == TLS13_KEY_EXCH_PSK_HYBRID)
595  {
596  //As the server is authenticating via a PSK, it does not send a
597  //Certificate or a CertificateVerify message
599  }
600  else
601  {
602  //A server can optionally request a certificate from the client
604  }
605 
606  //Successful processing
607  return NO_ERROR;
608 }
609 
610 
611 /**
612  * @brief Parse NewSessionTicket message
613  *
614  * At any time after the server has received the client Finished message, it
615  * may send a NewSessionTicket message
616  *
617  * @param[in] context Pointer to the TLS context
618  * @param[in] message Incoming NewSessionTicket message to parse
619  * @param[in] length Message length
620  * @return Error code
621  **/
622 
624  const Tls13NewSessionTicket *message, size_t length)
625 {
626  error_t error;
627  size_t n;
628  const uint8_t *p;
629  const Tls13Ticket *ticket;
630  const HashAlgo *hashAlgo;
632 
633  //Debug message
634  TRACE_INFO("NewSessionTicket message received (%" PRIuSIZE " bytes)...\r\n", length);
636 
637  //Check TLS version
638  if(context->version != TLS_VERSION_1_3)
640 
641  //Check current state
642  if(context->state != TLS_STATE_APPLICATION_DATA &&
643  context->state != TLS_STATE_CLOSING)
644  {
645  //Report an error
647  }
648 
649  //Check the length of the NewSessionTicket message
650  if(length < sizeof(Tls13NewSessionTicket))
651  return ERROR_DECODING_FAILED;
652 
653  //Point to the ticket nonce
654  p = message->ticketNonce;
655  //Remaining bytes to process
656  length -= sizeof(Tls13NewSessionTicket);
657 
658  //Malformed NewSessionTicket message?
659  if(length < message->ticketNonceLen)
660  return ERROR_DECODING_FAILED;
661 
662  //Point to the next field
663  p += message->ticketNonceLen;
664  //Remaining bytes to process
665  length -= message->ticketNonceLen;
666 
667  //Malformed NewSessionTicket message?
668  if(length < sizeof(Tls13Ticket))
669  return ERROR_DECODING_FAILED;
670 
671  //Point to the session ticket
672  ticket = (Tls13Ticket *) p;
673  //Retrieve the length of the ticket
674  n = ntohs(ticket->length);
675 
676  //Empty tickets are not allowed
677  if(n == 0)
678  return ERROR_DECODING_FAILED;
679 
680  //Malformed NewSessionTicket message?
681  if(length < (sizeof(Tls13Ticket) + n))
682  return ERROR_DECODING_FAILED;
683 
684  //Point to the next field
685  p += sizeof(Tls13Ticket) + n;
686  //Remaining bytes to process
687  length -= sizeof(Tls13Ticket) + n;
688 
689  //The message includes a set of extension values for the ticket
691  &extensions);
692  //Any error to report?
693  if(error)
694  return error;
695 
696  //Check the list of extensions offered by the server
698  context->version, &extensions);
699  //Any error to report?
700  if(error)
701  return error;
702 
703  //A ticket_lifetime value of zero indicates that the ticket should be
704  //discarded immediately
705  if(ntohl(message->ticketLifetime) > 0)
706  {
707  //Check the length of the session ticket
708  if(n <= TLS13_MAX_TICKET_SIZE)
709  {
710  //Servers may send multiple tickets on a single connection
711  if(context->ticket != NULL)
712  {
713  //Release memory
714  osMemset(context->ticket, 0, context->ticketLen);
715  tlsFreeMem(context->ticket);
716  context->ticket = NULL;
717  context->ticketLen = 0;
718  }
719 
720  //Allocate a memory block to hold the ticket
721  context->ticket = tlsAllocMem(n);
722  //Failed to allocate memory?
723  if(context->ticket == NULL)
724  return ERROR_OUT_OF_MEMORY;
725 
726  //Copy session ticket
727  osMemcpy(context->ticket, ticket->data, n);
728  context->ticketLen = n;
729 
730  //The client's view of the age of a ticket is the time since the
731  //receipt of the NewSessionTicket message
732  context->ticketTimestamp = osGetSystemTime();
733 
734  //Save the lifetime of the ticket
735  context->ticketLifetime = ntohl(message->ticketLifetime);
736 
737  //Clients must not cache tickets for longer than 7 days, regardless
738  //of the ticket_lifetime value (refer to RFC 8446, section 4.6.1)
739  context->ticketLifetime = MIN(context->ticketLifetime,
741 
742  //Random value used to obscure the age of the ticket
743  context->ticketAgeAdd = ntohl(message->ticketAgeAdd);
744 
745  //The sole extension currently defined for NewSessionTicket is
746  //EarlyData indicating that the ticket may be used to send 0-RTT data
747  error = tls13ParseServerEarlyDataExtension(context,
748  TLS_TYPE_NEW_SESSION_TICKET, extensions.earlyDataIndication);
749  //Any error to report?
750  if(error)
751  return error;
752 
753  //The hash function used by HKDF is the cipher suite hash algorithm
754  hashAlgo = context->cipherSuite.prfHashAlgo;
755  //Make sure the hash algorithm is valid
756  if(hashAlgo == NULL)
757  return ERROR_FAILURE;
758 
759  //Calculate the PSK associated with the ticket
760  error = tls13HkdfExpandLabel(context->transportProtocol, hashAlgo,
761  context->resumptionMasterSecret, hashAlgo->digestSize, "resumption",
762  message->ticketNonce, message->ticketNonceLen, context->ticketPsk,
763  hashAlgo->digestSize);
764  //Any error to report?
765  if(error)
766  return error;
767 
768  //Set the length of the PSK associated with the ticket
769  context->ticketPskLen = hashAlgo->digestSize;
770 
771  //Debug message
772  TRACE_DEBUG("Ticket PSK:\r\n");
773  TRACE_DEBUG_ARRAY(" ", context->ticketPsk, context->ticketPskLen);
774  }
775  }
776 
777  //Successful processing
778  return NO_ERROR;
779 }
780 
781 #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:2005
const HashAlgo * tlsGetHashAlgo(TlsHashAlgo hashAlgoId)
Get the hash algorithm that matches the specified identifier.
Definition: tls_misc.c:1325
@ 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:1556
size_t digestSize
Definition: crypto.h:1157
error_t tlsParseServerRecordSizeLimitExtension(TlsContext *context, const TlsExtension *recordSizeLimit)
Parse RecordSizeLimit extension.
TLS 1.3 session tickets.
@ TLS_TRANSPORT_PROTOCOL_DATAGRAM
Definition: tls.h:1000
@ TLS_STATE_APPLICATION_DATA
Definition: tls.h:1572
#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:434
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:1585
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:1586
@ 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:623
@ 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:1548
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:1047
#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:333
error_t tlsParseHelloExtensions(TlsMessageType msgType, const uint8_t *p, size_t length, TlsHelloExtensions *extensions)
Parse Hello extensions.
@ TLS_STATE_SERVER_FINISHED
Definition: tls.h:1567
#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:1550
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:1561
Hello extensions.
Definition: tls.h:2257
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:1966
@ TLS13_KEY_EXCH_PSK_ECDHE
Definition: tls.h:1209
@ TLS_STATE_CLOSING
Definition: tls.h:1573
#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:1909
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:1552
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.
@ TLS_STATE_CLIENT_HELLO_3
Definition: tls.h:1544
Common interface for hash algorithms.
Definition: crypto.h:1151
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:1264
@ 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:1563
Handshake message processing (TLS 1.3 client)
#define DTLS_VERSION_1_2
Definition: dtls_misc.h:36
#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:673
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.