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.2
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL TLS_TRACE_LEVEL
33 
34 //Dependencies
35 #include "tls/tls.h"
36 #include "tls/tls_cipher_suites.h"
37 #include "tls/tls_handshake.h"
39 #include "tls/tls_client_misc.h"
40 #include "tls/tls_extensions.h"
42 #include "tls/tls_misc.h"
43 #include "tls13/tls13_client.h"
46 #include "tls13/tls13_ticket.h"
47 #include "tls13/tls13_misc.h"
48 #include "quic/tls_quic_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  //Calculate client handshake traffic keys
98  error = tlsUpdateEncryptionEngine(context, context->encryptionEngine,
100  context->clientHsTrafficSecret);
101 
102  //Handshake traffic keys successfully calculated?
103  if(!error)
104  {
105  //Send a Finished message to the server
107  }
108  }
109 
110  //Return status code
111  return error;
112 #else
113  //Not implemented
114  return ERROR_NOT_IMPLEMENTED;
115 #endif
116 }
117 
118 
119 /**
120  * @brief Format EndOfEarlyData message
121  * @param[in] context Pointer to the TLS context
122  * @param[out] message Buffer where to format the EndOfEarlyData message
123  * @param[out] length Length of the resulting EndOfEarlyData message
124  * @return Error code
125  **/
126 
129 {
130  //The EndOfEarlyData message does not contain any data
131  *length = 0;
132 
133  //Successful processing
134  return NO_ERROR;
135 }
136 
137 
138 /**
139  * @brief Parse HelloRetryRequest message
140  *
141  * The server will send this message in response to a ClientHello message if
142  * it is able to find an acceptable set of parameters but the ClientHello does
143  * not contain sufficient information to proceed with the handshake
144  *
145  * @param[in] context Pointer to the TLS context
146  * @param[in] message Incoming HelloRetryRequest message to parse
147  * @param[in] length Message length
148  * @return Error code
149  **/
150 
152  const Tls13HelloRetryRequest *message, size_t length)
153 {
154  error_t error;
155  uint16_t cipherSuite;
156  uint8_t compressMethod;
157  const uint8_t *p;
158  const HashAlgo *hashAlgo;
160 
161  //Debug message
162  TRACE_INFO("HelloRetryRequest message received (%" PRIuSIZE " bytes)...\r\n", length);
164 
165  //Check TLS version
166  if(context->versionMax != TLS_VERSION_1_3)
168 
169  //If a client receives a second HelloRetryRequest in the same connection,
170  //it must abort the handshake with an unexpected_message alert
171  if(context->state != TLS_STATE_SERVER_HELLO &&
172  context->state != TLS_STATE_SERVER_HELLO_3)
173  {
174  //Report an error
176  }
177 
178  //Check the length of the ServerHello message
179  if(length < sizeof(TlsServerHello))
180  return ERROR_DECODING_FAILED;
181 
182  //Point to the session ID
183  p = message->sessionId;
184  //Remaining bytes to process
185  length -= sizeof(TlsServerHello);
186 
187  //Check the length of the session ID
188  if(message->sessionIdLen > length)
189  return ERROR_DECODING_FAILED;
190  if(message->sessionIdLen > 32)
191  return ERROR_DECODING_FAILED;
192 
193  //Point to the next field
194  p += message->sessionIdLen;
195  //Remaining bytes to process
196  length -= message->sessionIdLen;
197 
198  //Malformed ServerHello message?
199  if(length < sizeof(uint16_t))
200  return ERROR_DECODING_FAILED;
201 
202  //Get the negotiated cipher suite
204  //Point to the next field
205  p += sizeof(uint16_t);
206  //Remaining bytes to process
207  length -= sizeof(uint16_t);
208 
209  //Malformed ServerHello message?
210  if(length < sizeof(uint8_t))
211  return ERROR_DECODING_FAILED;
212 
213  //Get the value of the legacy_compression_method field
214  compressMethod = *p;
215  //Point to the next field
216  p += sizeof(uint8_t);
217  //Remaining bytes to process
218  length -= sizeof(uint8_t);
219 
220  //Legacy version
221  TRACE_INFO(" legacyVersion = 0x%04" PRIX16 " (%s)\r\n",
222  ntohs(message->serverVersion),
223  tlsGetVersionName(ntohs(message->serverVersion)));
224 
225  //Server random value
226  TRACE_DEBUG(" random\r\n");
227  TRACE_DEBUG_ARRAY(" ", message->random, 32);
228 
229  //Session identifier
230  TRACE_DEBUG(" sessionId\r\n");
231  TRACE_DEBUG_ARRAY(" ", message->sessionId, message->sessionIdLen);
232 
233  //Cipher suite identifier
234  TRACE_INFO(" cipherSuite = 0x%04" PRIX16 " (%s)\r\n",
236 
237  //Compression method
238  TRACE_DEBUG(" legacyCompressMethod = 0x%02" PRIX8 "\r\n", compressMethod);
239 
240  //DTLS protocol?
241  if(context->transportProtocol == TLS_TRANSPORT_PROTOCOL_DATAGRAM)
242  {
243  //The legacy_version field must be set to {254, 253}, which is the
244  //version number for DTLS 1.2
245  if(ntohs(message->serverVersion) != DTLS_VERSION_1_2)
247 
248  //DTLS 1.3 clients must abort the handshake with an illegal_parameter
249  //alert if the legacy_session_id_echo field is not empty
250  if(message->sessionIdLen != 0)
252  }
253  else
254  {
255  //The legacy_version field must be set to 0x0303, which is the version
256  //number for TLS 1.2
257  if(ntohs(message->serverVersion) != TLS_VERSION_1_2)
259 
260  //A client which receives a legacy_session_id_echo field that does not
261  //match what it sent in the ClientHello must abort the handshake with an
262  //illegal_parameter alert (RFC 8446, section 4.1.4)
263  if(message->sessionIdLen != context->sessionIdLen ||
264  osMemcmp(message->sessionId, context->sessionId,
265  message->sessionIdLen))
266  {
268  }
269  }
270 
271  //Upon receipt of a HelloRetryRequest, the client must check that the
272  //legacy_compression_method is 0
273  if(compressMethod != TLS_COMPRESSION_METHOD_NULL)
274  return ERROR_DECODING_FAILED;
275 
276  //Parse the list of extensions offered by the server
278  &extensions);
279  //Any error to report?
280  if(error)
281  return error;
282 
283  //The HelloRetryRequest message must contain a SupportedVersions extension
284  if(extensions.selectedVersion == NULL)
286 
287  //TLS protocol?
288  if(context->transportProtocol == TLS_TRANSPORT_PROTOCOL_STREAM ||
289  context->transportProtocol == TLS_TRANSPORT_PROTOCOL_QUIC ||
290  context->transportProtocol == TLS_TRANSPORT_PROTOCOL_EAP)
291  {
292  //Release transcript hash context
293  tlsFreeTranscriptHash(context);
294 
295  //Format initial ClientHello message
296  error = tlsFormatInitialClientHello(context);
297  //Any error to report?
298  if(error)
299  return error;
300  }
301 
302  //The SupportedVersions extension contains the selected version
304  extensions.selectedVersion);
305  //Any error to report?
306  if(error)
307  return error;
308 
309  //Check the list of extensions offered by the server
311  context->version, &extensions);
312  //Any error to report?
313  if(error)
314  return error;
315 
316  //Set cipher suite
317  error = tlsSelectCipherSuite(context, cipherSuite);
318  //Specified cipher suite not supported?
319  if(error)
320  return error;
321 
322  //Initialize handshake message hashing
323  error = tlsInitTranscriptHash(context);
324  //Any error to report?
325  if(error)
326  return error;
327 
328 #if (DTLS_SUPPORT == ENABLED)
329  //DTLS protocol?
330  if(context->transportProtocol == TLS_TRANSPORT_PROTOCOL_DATAGRAM)
331  {
332  //Exit from the WAITING state
333  context->txBufferLen = 0;
334  }
335 #endif
336 
337  //When the server responds to a ClientHello with a HelloRetryRequest, the
338  //value of ClientHello1 is replaced with a special synthetic handshake
339  //message of handshake type MessageHash containing Hash(ClientHello1)
340  error = tls13DigestClientHello1(context);
341  //Any error to report?
342  if(error)
343  return error;
344 
345  //When sending a HelloRetryRequest, the server may provide a Cookie
346  //extension to the client
347  error = tls13ParseServerCookieExtension(context, extensions.cookie);
348  //Any error to report?
349  if(error)
350  return error;
351 
352  //The KeyShare extension contains the mutually supported group the server
353  //intends to negotiate
354  error = tls13ParseSelectedGroupExtension(context, extensions.selectedGroup);
355  //Any error to report?
356  if(error)
357  return error;
358 
359  //Point to the cipher suite hash algorithm
360  hashAlgo = context->cipherSuite.prfHashAlgo;
361  //Make sure the hash algorithm is valid
362  if(hashAlgo == NULL)
363  return ERROR_FAILURE;
364 
365  //In addition, in its updated ClientHello, the client should not offer any
366  //pre-shared keys associated with a hash other than that of the selected
367  //cipher suite. This allows the client to avoid having to compute partial
368  //hash transcripts for multiple hashes in the second ClientHello
369  if(tls13IsPskValid(context))
370  {
371  //Remove any PSKs which are incompatible with the server's indicated
372  //cipher suite
373  if(tlsGetHashAlgo(context->pskHashAlgo) != hashAlgo)
374  {
375  context->pskHashAlgo = TLS_HASH_ALGO_NONE;
376  context->ticketHashAlgo = TLS_HASH_ALGO_NONE;
377  }
378  }
379  else if(tls13IsTicketValid(context))
380  {
381  //Remove any PSKs which are incompatible with the server's indicated
382  //cipher suite
383  if(tlsGetHashAlgo(context->ticketHashAlgo) != hashAlgo)
384  {
385  context->ticketHashAlgo = TLS_HASH_ALGO_NONE;
386  }
387  }
388 
389  //Any 0-RTT data sent by the client?
390  if(context->earlyDataEnabled)
391  {
392  //A client must not include the EarlyData extension in its followup
393  //ClientHello (refer to RFC 8446, section 4.2.10)
394  context->earlyDataRejected = TRUE;
395  }
396 
397  //Clients must abort the handshake with an illegal_parameter alert if the
398  //HelloRetryRequest would not result in any change in the ClientHello
399  if(context->cookieLen == 0 && context->namedGroup == context->preferredGroup)
400  {
401  //Report an error
403  }
404 
405  //Another handshake message cannot be packed in the same record as the
406  //HelloRetryRequest
407  if(context->rxBufferLen != 0)
409 
410 #if (TLS13_MIDDLEBOX_COMPAT_SUPPORT == ENABLED)
411  //The middlebox compatibility mode improves the chance of successfully
412  //connecting through middleboxes
413  if(context->transportProtocol == TLS_TRANSPORT_PROTOCOL_STREAM &&
414  context->state == TLS_STATE_SERVER_HELLO)
415  {
416  //In middlebox compatibility mode, the client sends a dummy
417  //ChangeCipherSpec record immediately before its second flight
419  }
420  else
421 #endif
422  {
423  //The client can send its second flight
425  }
426 
427  //Successful processing
428  return NO_ERROR;
429 }
430 
431 
432 /**
433  * @brief Parse EncryptedExtensions message
434  *
435  * The server sends the EncryptedExtensions message immediately after the
436  * ServerHello message. The EncryptedExtensions message contains extensions
437  * that can be protected
438  *
439  * @param[in] context Pointer to the TLS context
440  * @param[in] message Incoming EncryptedExtensions message to parse
441  * @param[in] length Message length
442  * @return Error code
443  **/
444 
446  const Tls13EncryptedExtensions *message, size_t length)
447 {
448  error_t error;
450 
451  //Debug message
452  TRACE_INFO("EncryptedExtensions message received (%" PRIuSIZE " bytes)...\r\n", length);
454 
455  //Check TLS version
456  if(context->version != TLS_VERSION_1_3)
458 
459  //Check current state
460  if(context->state != TLS_STATE_ENCRYPTED_EXTENSIONS)
462 
463  //Check the length of the EncryptedExtensions message
464  if(length < sizeof(Tls13EncryptedExtensions))
465  return ERROR_DECODING_FAILED;
466 
467  //Parse the list of extensions offered by the server
469  (uint8_t *) message, length, &extensions);
470  //Any error to report?
471  if(error)
472  return error;
473 
474  //Check the list of extensions offered by the server
476  context->version, &extensions);
477  //Any error to report?
478  if(error)
479  return error;
480 
481 #if (TLS_SNI_SUPPORT == ENABLED)
482  //When the server includes a ServerName extension, the data field of
483  //this extension may be empty
484  error = tlsParseServerSniExtension(context, extensions.serverNameList);
485  //Any error to report?
486  if(error)
487  return error;
488 #endif
489 
490 #if (TLS_MAX_FRAG_LEN_SUPPORT == ENABLED && TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
491  //A client must treat receipt of both MaxFragmentLength and RecordSizeLimit
492  //extensions as a fatal error, and it should generate an illegal_parameter
493  //alert (refer to RFC 8449, section 5)
494  if(extensions.maxFragLen != NULL && extensions.recordSizeLimit != NULL)
496 #endif
497 
498 #if (TLS_MAX_FRAG_LEN_SUPPORT == ENABLED)
499  //Servers that receive an ClientHello containing a MaxFragmentLength
500  //extension may accept the requested maximum fragment length by including
501  //an extension of type MaxFragmentLength in the ServerHello
502  error = tlsParseServerMaxFragLenExtension(context, extensions.maxFragLen);
503  //Any error to report?
504  if(error)
505  return error;
506 #endif
507 
508 #if (TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
509  //The value of RecordSizeLimit is the maximum size of record in octets
510  //that the peer is willing to receive
512  extensions.recordSizeLimit);
513  //Any error to report?
514  if(error)
515  return error;
516 #endif
517 
518 #if (TLS_ALPN_SUPPORT == ENABLED)
519  //Parse ALPN extension
520  error = tlsParseServerAlpnExtension(context, extensions.protocolNameList);
521  //Any error to report?
522  if(error)
523  return error;
524 #endif
525 
526 #if (TLS_RAW_PUBLIC_KEY_SUPPORT == ENABLED)
527  //Parse ClientCertType extension
528  error = tlsParseClientCertTypeExtension(context, extensions.clientCertType);
529  //Any error to report?
530  if(error)
531  return error;
532 
533  //Parse ServerCertType extension
534  error = tlsParseServerCertTypeExtension(context, extensions.serverCertType);
535  //Any error to report?
536  if(error)
537  return error;
538 #endif
539 
540 #if (TLS13_EARLY_DATA_SUPPORT == ENABLED)
541  //Parse EarlyData extension
542  error = tls13ParseServerEarlyDataExtension(context,
543  TLS_TYPE_ENCRYPTED_EXTENSIONS, extensions.earlyDataIndication);
544  //Any error to report?
545  if(error)
546  return error;
547 
548  //Check whether the server has accepted the early data
549  if(context->earlyDataExtReceived)
550  {
551 #if (TLS_ALPN_SUPPORT == ENABLED)
552  //Valid ticket?
553  if(!tls13IsPskValid(context) && tls13IsTicketValid(context))
554  {
555  //Enforce ALPN protocol
556  if(context->selectedProtocol != NULL || context->ticketAlpn != NULL)
557  {
558  if(context->selectedProtocol != NULL && context->ticketAlpn != NULL)
559  {
560  //Compare the selected ALPN protocol against the expected value
561  if(osStrcmp(context->selectedProtocol, context->ticketAlpn) != 0)
562  {
563  //The selected ALPN protocol is not acceptable
564  return ERROR_HANDSHAKE_FAILED;
565  }
566  }
567  else
568  {
569  //The selected ALPN protocol is not acceptable
570  return ERROR_HANDSHAKE_FAILED;
571  }
572  }
573  }
574 #endif
575 
576  //The EndOfEarlyData message is encrypted with the 0-RTT traffic keys
577  error = tlsUpdateEncryptionEngine(context, context->encryptionEngine,
579  context->clientEarlyTrafficSecret);
580  //Any error to report?
581  if(error)
582  return error;
583 
584  //Restore sequence number
585  context->encryptionEngine[0].seqNum = context->earlyDataSeqNum;
586  }
587 #endif
588 
589 #if (TLS_QUIC_SUPPORT == ENABLED)
590  //Parse QuicTransportParameters extension
591  error = tlsParseQuicTransportParamsExtension(context,
592  extensions.quicTransportParams);
593  //Any error to report?
594  if(error)
595  return error;
596 #endif
597 
598  //PSK key exchange method?
599  if(context->keyExchMethod == TLS13_KEY_EXCH_PSK ||
600  context->keyExchMethod == TLS13_KEY_EXCH_PSK_DHE ||
601  context->keyExchMethod == TLS13_KEY_EXCH_PSK_ECDHE ||
602  context->keyExchMethod == TLS13_KEY_EXCH_PSK_HYBRID)
603  {
604  //As the server is authenticating via a PSK, it does not send a
605  //Certificate or a CertificateVerify message
607  }
608  else
609  {
610  //A server can optionally request a certificate from the client
612  }
613 
614  //Successful processing
615  return NO_ERROR;
616 }
617 
618 
619 /**
620  * @brief Parse NewSessionTicket message
621  *
622  * At any time after the server has received the client Finished message, it
623  * may send a NewSessionTicket message
624  *
625  * @param[in] context Pointer to the TLS context
626  * @param[in] message Incoming NewSessionTicket message to parse
627  * @param[in] length Message length
628  * @return Error code
629  **/
630 
632  const Tls13NewSessionTicket *message, size_t length)
633 {
634  error_t error;
635  size_t n;
636  const uint8_t *p;
637  const Tls13Ticket *ticket;
638  const HashAlgo *hashAlgo;
640 
641  //Debug message
642  TRACE_INFO("NewSessionTicket message received (%" PRIuSIZE " bytes)...\r\n", length);
644 
645  //Check TLS version
646  if(context->version != TLS_VERSION_1_3)
648 
649  //Check current state
650  if(context->state != TLS_STATE_APPLICATION_DATA &&
651  context->state != TLS_STATE_CLIENT_FINISHED_ACK &&
652  context->state != TLS_STATE_KEY_UPDATE_ACK &&
653  context->state != TLS_STATE_CLOSING)
654  {
655  //Report an error
657  }
658 
659  //Check the length of the NewSessionTicket message
660  if(length < sizeof(Tls13NewSessionTicket))
661  return ERROR_DECODING_FAILED;
662 
663  //Point to the ticket nonce
664  p = message->ticketNonce;
665  //Remaining bytes to process
666  length -= sizeof(Tls13NewSessionTicket);
667 
668  //Malformed NewSessionTicket message?
669  if(length < message->ticketNonceLen)
670  return ERROR_DECODING_FAILED;
671 
672  //Point to the next field
673  p += message->ticketNonceLen;
674  //Remaining bytes to process
675  length -= message->ticketNonceLen;
676 
677  //Malformed NewSessionTicket message?
678  if(length < sizeof(Tls13Ticket))
679  return ERROR_DECODING_FAILED;
680 
681  //Point to the session ticket
682  ticket = (Tls13Ticket *) p;
683  //Retrieve the length of the ticket
684  n = ntohs(ticket->length);
685 
686  //Empty tickets are not allowed
687  if(n == 0)
688  return ERROR_DECODING_FAILED;
689 
690  //Malformed NewSessionTicket message?
691  if(length < (sizeof(Tls13Ticket) + n))
692  return ERROR_DECODING_FAILED;
693 
694  //Point to the next field
695  p += sizeof(Tls13Ticket) + n;
696  //Remaining bytes to process
697  length -= sizeof(Tls13Ticket) + n;
698 
699  //The message includes a set of extension values for the ticket
701  &extensions);
702  //Any error to report?
703  if(error)
704  return error;
705 
706  //Check the list of extensions offered by the server
708  context->version, &extensions);
709  //Any error to report?
710  if(error)
711  return error;
712 
713  //A ticket_lifetime value of zero indicates that the ticket should be
714  //discarded immediately
715  if(ntohl(message->ticketLifetime) > 0)
716  {
717  //Check the length of the session ticket
718  if(n <= TLS13_MAX_TICKET_SIZE)
719  {
720  //Servers may send multiple tickets on a single connection
721  if(context->ticket != NULL)
722  {
723  //Release memory
724  osMemset(context->ticket, 0, context->ticketLen);
725  tlsFreeMem(context->ticket);
726  context->ticket = NULL;
727  context->ticketLen = 0;
728  }
729 
730  //Allocate a memory block to hold the ticket
731  context->ticket = tlsAllocMem(n);
732  //Failed to allocate memory?
733  if(context->ticket == NULL)
734  return ERROR_OUT_OF_MEMORY;
735 
736  //Copy session ticket
737  osMemcpy(context->ticket, ticket->data, n);
738  context->ticketLen = n;
739 
740  //The client's view of the age of a ticket is the time since the
741  //receipt of the NewSessionTicket message
742  context->ticketTimestamp = osGetSystemTime();
743 
744  //Save the lifetime of the ticket
745  context->ticketLifetime = ntohl(message->ticketLifetime);
746 
747  //Clients must not cache tickets for longer than 7 days, regardless
748  //of the ticket_lifetime value (refer to RFC 8446, section 4.6.1)
749  context->ticketLifetime = MIN(context->ticketLifetime,
751 
752  //Random value used to obscure the age of the ticket
753  context->ticketAgeAdd = ntohl(message->ticketAgeAdd);
754 
755  //The sole extension currently defined for NewSessionTicket is
756  //EarlyData indicating that the ticket may be used to send 0-RTT data
757  error = tls13ParseServerEarlyDataExtension(context,
758  TLS_TYPE_NEW_SESSION_TICKET, extensions.earlyDataIndication);
759  //Any error to report?
760  if(error)
761  return error;
762 
763  //The hash function used by HKDF is the cipher suite hash algorithm
764  hashAlgo = context->cipherSuite.prfHashAlgo;
765  //Make sure the hash algorithm is valid
766  if(hashAlgo == NULL)
767  return ERROR_FAILURE;
768 
769  //Calculate the PSK associated with the ticket
770  error = tls13HkdfExpandLabel(context->transportProtocol, hashAlgo,
771  context->resumptionMasterSecret, hashAlgo->digestSize, "resumption",
772  message->ticketNonce, message->ticketNonceLen, context->ticketPsk,
773  hashAlgo->digestSize);
774  //Any error to report?
775  if(error)
776  return error;
777 
778  //Set the length of the PSK associated with the ticket
779  context->ticketPskLen = hashAlgo->digestSize;
780 
781  //Debug message
782  TRACE_DEBUG("Ticket PSK:\r\n");
783  TRACE_DEBUG_ARRAY(" ", context->ticketPsk, context->ticketPskLen);
784  }
785  }
786 
787  //Successful processing
788  return NO_ERROR;
789 }
790 
791 #endif
@ TLS13_KEY_EXCH_PSK
Definition: tls.h:1224
#define tlsAllocMem(size)
Definition: tls.h:889
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
error_t tlsUpdateEncryptionEngine(TlsContext *context, TlsEncryptionEngine *encryptionEngine, TlsConnectionEnd entity, TlsEncryptionLevel level, const uint8_t *secret)
Update encryption engine.
Definition: tls_misc.c:1051
@ TLS_TRANSPORT_PROTOCOL_QUIC
Definition: tls.h:1018
TLS cipher suites.
uint16_t cipherSuite
Cipher suite identifier.
Definition: tls.h:2026
const HashAlgo * tlsGetHashAlgo(TlsHashAlgo hashAlgoId)
Get the hash algorithm that matches the specified identifier.
Definition: tls_misc.c:1431
@ ERROR_WOULD_BLOCK
Definition: error.h:96
@ TLS13_KEY_EXCH_PSK_DHE
Definition: tls.h:1225
TLS handshake.
@ TLS_COMPRESSION_METHOD_NULL
Definition: tls.h:1190
@ 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:1572
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:1017
@ TLS_STATE_APPLICATION_DATA
Definition: tls.h:1589
#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:445
error_t tls13FormatEndOfEarlyData(TlsContext *context, Tls13EndOfEarlyData *message, size_t *length)
Format EndOfEarlyData message.
Definition: tls13_client.c:127
uint8_t ticketNonceLen
Definition: tls13_misc.h:340
@ TLS_ENCRYPTION_LEVEL_EARLY_DATA
Definition: tls.h:1606
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:1106
@ TLS_ENCRYPTION_LEVEL_HANDSHAKE
Definition: tls.h:1607
@ TLS13_KEY_EXCH_PSK_HYBRID
Definition: tls.h:1228
error_t tls13ParseNewSessionTicket(TlsContext *context, const Tls13NewSessionTicket *message, size_t length)
Parse NewSessionTicket message.
Definition: tls13_client.c:631
@ TLS_HASH_ALGO_NONE
Definition: tls.h:1277
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:1564
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 tls13ParseServerCookieExtension(TlsContext *context, const Tls13Cookie *cookie)
Parse Cookie 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.
#define TLS_VERSION_1_2
Definition: tls.h:97
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:1585
#define TLS_VERSION_1_3
Definition: tls.h:98
@ TLS_TYPE_ENCRYPTED_EXTENSIONS
Definition: tls.h:1108
bool_t tls13IsTicketValid(TlsContext *context)
Check whether a session ticket is valid.
Definition: tls13_ticket.c:51
@ TLS_TRANSPORT_PROTOCOL_EAP
Definition: tls.h:1019
@ TLS_STATE_SERVER_HELLO_3
Definition: tls.h:1566
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:1577
Hello extensions.
Definition: tls.h:2278
Transcript hash calculation.
Tls13Ticket
Definition: tls13_misc.h:363
Formatting and parsing of extensions (TLS client)
#define ntohs(value)
Definition: cpu_endian.h:421
#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:1987
@ TLS13_KEY_EXCH_PSK_ECDHE
Definition: tls.h:1226
@ TLS_STATE_CLIENT_HELLO_2
Definition: tls.h:1560
@ TLS_STATE_CLOSING
Definition: tls.h:1594
#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:1930
bool_t tls13IsPskValid(TlsContext *context)
Check whether an externally established PSK is valid.
Definition: tls13_misc.c:909
uint8_t n
HKDF (HMAC-based Key Derivation Function)
Tls13NewSessionTicket
Definition: tls13_misc.h:342
@ TLS_STATE_ENCRYPTED_EXTENSIONS
Definition: tls.h:1568
error_t tls13ParseHelloRetryRequest(TlsContext *context, const Tls13HelloRetryRequest *message, size_t length)
Parse HelloRetryRequest message.
Definition: tls13_client.c:151
error_t tlsInitTranscriptHash(TlsContext *context)
Initialize handshake message hashing.
@ TLS_STATE_CLIENT_FINISHED_ACK
Definition: tls.h:1590
@ TLS_CONNECTION_END_CLIENT
Definition: tls.h:1029
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:1016
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: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:1370
@ TLS_TYPE_NEW_SESSION_TICKET
Definition: tls.h:1105
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:1107
#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:894
error_t tls13DigestClientHello1(TlsContext *context)
Hash ClientHello1 in the transcript when HelloRetryRequest is used.
Definition: tls13_misc.c:844
@ TLS_STATE_CLIENT_FINISHED
Definition: tls.h:1579
@ TLS_STATE_KEY_UPDATE_ACK
Definition: tls.h:1593
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.
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.