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-2024 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.4.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_misc.h"
43 #include "tls13_client.h"
45 #include "tls13_key_material.h"
46 #include "tls13_ticket.h"
47 #include "tls13_misc.h"
48 #include "kdf/hkdf.h"
49 #include "debug.h"
50 
51 //Check TLS library configuration
52 #if (TLS_SUPPORT == ENABLED && TLS_CLIENT_SUPPORT == ENABLED && \
53  TLS_MAX_VERSION >= TLS_VERSION_1_3)
54 
55 
56 /**
57  * @brief Send EndOfEarlyData message
58  *
59  * The EndOfEarlyData message indicates that all 0-RTT application data
60  * messages, if any, have been transmitted and that the following records
61  * are protected under handshake traffic keys
62  *
63  * @param[in] context Pointer to the TLS context
64  * @return Error code
65  **/
66 
68 {
69 #if (TLS13_EARLY_DATA_SUPPORT == ENABLED)
70  error_t error;
71  size_t length;
73 
74  //Point to the buffer where to format the message
75  message = (Tls13EndOfEarlyData *) (context->txBuffer + context->txBufferLen);
76 
77  //If the server has accepted early data, an EndOfEarlyData message will be
78  //sent to indicate the key change
79  error = tls13FormatEndOfEarlyData(context, message, &length);
80 
81  //Check status code
82  if(!error)
83  {
84  //Debug message
85  TRACE_INFO("Sending EndOfEarlyData message (%" PRIuSIZE " bytes)...\r\n", length);
87 
88  //Send handshake message
89  error = tlsSendHandshakeMessage(context, message, length,
91  }
92 
93  //Check status code
94  if(error == NO_ERROR || error == ERROR_WOULD_BLOCK || error == ERROR_TIMEOUT)
95  {
96  //Release encryption engine
97  tlsFreeEncryptionEngine(&context->encryptionEngine);
98 
99  //Calculate client handshake traffic keys
100  error = tlsInitEncryptionEngine(context, &context->encryptionEngine,
101  TLS_CONNECTION_END_CLIENT, context->clientHsTrafficSecret);
102 
103  //Handshake traffic keys successfully calculated?
104  if(!error)
105  {
106  //Send a Finished message to the server
108  }
109  }
110 
111  //Return status code
112  return error;
113 #else
114  //Not implemented
115  return ERROR_NOT_IMPLEMENTED;
116 #endif
117 }
118 
119 
120 /**
121  * @brief Format EndOfEarlyData message
122  * @param[in] context Pointer to the TLS context
123  * @param[out] message Buffer where to format the EndOfEarlyData message
124  * @param[out] length Length of the resulting EndOfEarlyData message
125  * @return Error code
126  **/
127 
130 {
131  //The EndOfEarlyData message does not contain any data
132  *length = 0;
133 
134  //Successful processing
135  return NO_ERROR;
136 }
137 
138 
139 /**
140  * @brief Parse HelloRetryRequest message
141  *
142  * The server will send this message in response to a ClientHello message if
143  * it is able to find an acceptable set of parameters but the ClientHello does
144  * not contain sufficient information to proceed with the handshake
145  *
146  * @param[in] context Pointer to the TLS context
147  * @param[in] message Incoming HelloRetryRequest message to parse
148  * @param[in] length Message length
149  * @return Error code
150  **/
151 
153  const Tls13HelloRetryRequest *message, size_t length)
154 {
155  error_t error;
156  uint16_t cipherSuite;
157  uint8_t compressMethod;
158  const uint8_t *p;
159  const HashAlgo *hashAlgo;
161 
162  //Debug message
163  TRACE_INFO("HelloRetryRequest message received (%" PRIuSIZE " bytes)...\r\n", length);
165 
166  //Check TLS version
167  if(context->versionMax != TLS_VERSION_1_3)
169 
170  //If a client receives a second HelloRetryRequest in the same connection,
171  //it must abort the handshake with an unexpected_message alert
172  if(context->state != TLS_STATE_SERVER_HELLO &&
173  context->state != TLS_STATE_SERVER_HELLO_3)
174  {
175  //Report an error
177  }
178 
179  //Check the length of the ServerHello message
180  if(length < sizeof(TlsServerHello))
181  return ERROR_DECODING_FAILED;
182 
183  //Point to the session ID
184  p = message->sessionId;
185  //Remaining bytes to process
186  length -= sizeof(TlsServerHello);
187 
188  //Check the length of the session ID
189  if(message->sessionIdLen > length)
190  return ERROR_DECODING_FAILED;
191  if(message->sessionIdLen > 32)
192  return ERROR_DECODING_FAILED;
193 
194  //Point to the next field
195  p += message->sessionIdLen;
196  //Remaining bytes to process
197  length -= message->sessionIdLen;
198 
199  //Malformed ServerHello message?
200  if(length < sizeof(uint16_t))
201  return ERROR_DECODING_FAILED;
202 
203  //Get the negotiated cipher suite
205  //Point to the next field
206  p += sizeof(uint16_t);
207  //Remaining bytes to process
208  length -= sizeof(uint16_t);
209 
210  //Malformed ServerHello message?
211  if(length < sizeof(uint8_t))
212  return ERROR_DECODING_FAILED;
213 
214  //Get the value of the legacy_compression_method field
215  compressMethod = *p;
216  //Point to the next field
217  p += sizeof(uint8_t);
218  //Remaining bytes to process
219  length -= sizeof(uint8_t);
220 
221  //Legacy version
222  TRACE_INFO(" legacyVersion = 0x%04" PRIX16 " (%s)\r\n",
223  ntohs(message->serverVersion),
224  tlsGetVersionName(ntohs(message->serverVersion)));
225 
226  //Server random value
227  TRACE_DEBUG(" random\r\n");
228  TRACE_DEBUG_ARRAY(" ", message->random, 32);
229 
230  //Session identifier
231  TRACE_DEBUG(" sessionId\r\n");
232  TRACE_DEBUG_ARRAY(" ", message->sessionId, message->sessionIdLen);
233 
234  //Cipher suite identifier
235  TRACE_INFO(" cipherSuite = 0x%04" PRIX16 " (%s)\r\n",
237 
238  //Compression method
239  TRACE_DEBUG(" legacyCompressMethod = 0x%02" PRIX8 "\r\n", compressMethod);
240 
241  //The legacy_version field must be set to 0x0303, which is the version
242  //number for TLS 1.2
243  if(ntohs(message->serverVersion) != TLS_VERSION_1_2)
245 
246  //A client which receives a legacy_session_id_echo field that does not
247  //match what it sent in the ClientHello must abort the handshake with an
248  //illegal_parameter alert (RFC 8446, section 4.1.4)
249  if(message->sessionIdLen != context->sessionIdLen ||
250  osMemcmp(message->sessionId, context->sessionId, message->sessionIdLen))
251  {
252  //The legacy_session_id_echo field is not valid
254  }
255 
256  //Upon receipt of a HelloRetryRequest, the client must check that the
257  //legacy_compression_method is 0
258  if(compressMethod != TLS_COMPRESSION_METHOD_NULL)
259  return ERROR_DECODING_FAILED;
260 
261  //Parse the list of extensions offered by the server
263  &extensions);
264  //Any error to report?
265  if(error)
266  return error;
267 
268  //The HelloRetryRequest message must contain a SupportedVersions extension
269  if(extensions.selectedVersion == NULL)
271 
272  //TLS protocol?
273  if(context->transportProtocol == TLS_TRANSPORT_PROTOCOL_STREAM ||
274  context->transportProtocol == TLS_TRANSPORT_PROTOCOL_EAP)
275  {
276  //Release transcript hash context
277  tlsFreeTranscriptHash(context);
278 
279  //Format initial ClientHello message
280  error = tlsFormatInitialClientHello(context);
281  //Any error to report?
282  if(error)
283  return error;
284  }
285 
286  //The SupportedVersions extension contains the selected version
288  extensions.selectedVersion);
289  //Any error to report?
290  if(error)
291  return error;
292 
293  //Check the list of extensions offered by the server
295  context->version, &extensions);
296  //Any error to report?
297  if(error)
298  return error;
299 
300  //Set cipher suite
301  error = tlsSelectCipherSuite(context, cipherSuite);
302  //Specified cipher suite not supported?
303  if(error)
304  return error;
305 
306  //Initialize handshake message hashing
307  error = tlsInitTranscriptHash(context);
308  //Any error to report?
309  if(error)
310  return error;
311 
312  //When the server responds to a ClientHello with a HelloRetryRequest, the
313  //value of ClientHello1 is replaced with a special synthetic handshake
314  //message of handshake type MessageHash containing Hash(ClientHello1)
315  error = tls13DigestClientHello1(context);
316  //Any error to report?
317  if(error)
318  return error;
319 
320  //When sending a HelloRetryRequest, the server may provide a Cookie
321  //extension to the client
322  error = tls13ParseCookieExtension(context, extensions.cookie);
323  //Any error to report?
324  if(error)
325  return error;
326 
327  //The KeyShare extension contains the mutually supported group the server
328  //intends to negotiate
329  error = tls13ParseSelectedGroupExtension(context, extensions.selectedGroup);
330  //Any error to report?
331  if(error)
332  return error;
333 
334  //Point to the cipher suite hash algorithm
335  hashAlgo = context->cipherSuite.prfHashAlgo;
336  //Make sure the hash algorithm is valid
337  if(hashAlgo == NULL)
338  return ERROR_FAILURE;
339 
340  //In addition, in its updated ClientHello, the client should not offer any
341  //pre-shared keys associated with a hash other than that of the selected
342  //cipher suite. This allows the client to avoid having to compute partial
343  //hash transcripts for multiple hashes in the second ClientHello
344  if(tls13IsPskValid(context))
345  {
346  //Remove any PSKs which are incompatible with the server's indicated
347  //cipher suite
348  if(tlsGetHashAlgo(context->pskHashAlgo) != hashAlgo)
349  {
350  context->pskHashAlgo = TLS_HASH_ALGO_NONE;
351  context->ticketHashAlgo = TLS_HASH_ALGO_NONE;
352  }
353  }
354  else if(tls13IsTicketValid(context))
355  {
356  //Remove any PSKs which are incompatible with the server's indicated
357  //cipher suite
358  if(tlsGetHashAlgo(context->ticketHashAlgo) != hashAlgo)
359  {
360  context->ticketHashAlgo = TLS_HASH_ALGO_NONE;
361  }
362  }
363 
364  //Any 0-RTT data sent by the client?
365  if(context->earlyDataEnabled)
366  {
367  //A client must not include the EarlyData extension in its followup
368  //ClientHello (refer to RFC 8446, section 4.2.10)
369  context->earlyDataRejected = TRUE;
370  }
371 
372  //Clients must abort the handshake with an illegal_parameter alert if the
373  //HelloRetryRequest would not result in any change in the ClientHello
374  if(context->cookieLen == 0 && context->namedGroup == context->preferredGroup)
375  {
376  //Report an error
378  }
379 
380  //Another handshake message cannot be packed in the same record as the
381  //HelloRetryRequest
382  if(context->rxBufferLen != 0)
384 
385 #if (TLS13_MIDDLEBOX_COMPAT_SUPPORT == ENABLED)
386  //The middlebox compatibility mode improves the chance of successfully
387  //connecting through middleboxes
388  if(context->transportProtocol == TLS_TRANSPORT_PROTOCOL_STREAM &&
389  context->state == TLS_STATE_SERVER_HELLO)
390  {
391  //In middlebox compatibility mode, the client sends a dummy
392  //ChangeCipherSpec record immediately before its second flight
394  }
395  else
396 #endif
397  {
398  //The client can send its second flight
400  }
401 
402  //Successful processing
403  return NO_ERROR;
404 }
405 
406 
407 /**
408  * @brief Parse EncryptedExtensions message
409  *
410  * The server sends the EncryptedExtensions message immediately after the
411  * ServerHello message. The EncryptedExtensions message contains extensions
412  * that can be protected
413  *
414  * @param[in] context Pointer to the TLS context
415  * @param[in] message Incoming EncryptedExtensions message to parse
416  * @param[in] length Message length
417  * @return Error code
418  **/
419 
421  const Tls13EncryptedExtensions *message, size_t length)
422 {
423  error_t error;
425 
426  //Debug message
427  TRACE_INFO("EncryptedExtensions message received (%" PRIuSIZE " bytes)...\r\n", length);
429 
430  //Check TLS version
431  if(context->version != TLS_VERSION_1_3)
433 
434  //Check current state
435  if(context->state != TLS_STATE_ENCRYPTED_EXTENSIONS)
437 
438  //Check the length of the EncryptedExtensions message
439  if(length < sizeof(Tls13EncryptedExtensions))
440  return ERROR_DECODING_FAILED;
441 
442  //Parse the list of extensions offered by the server
444  (uint8_t *) message, length, &extensions);
445  //Any error to report?
446  if(error)
447  return error;
448 
449  //Check the list of extensions offered by the server
451  context->version, &extensions);
452  //Any error to report?
453  if(error)
454  return error;
455 
456 #if (TLS_SNI_SUPPORT == ENABLED)
457  //When the server includes a ServerName extension, the data field of
458  //this extension may be empty
459  error = tlsParseServerSniExtension(context, extensions.serverNameList);
460  //Any error to report?
461  if(error)
462  return error;
463 #endif
464 
465 #if (TLS_MAX_FRAG_LEN_SUPPORT == ENABLED && TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
466  //A client must treat receipt of both MaxFragmentLength and RecordSizeLimit
467  //extensions as a fatal error, and it should generate an illegal_parameter
468  //alert (refer to RFC 8449, section 5)
469  if(extensions.maxFragLen != NULL && extensions.recordSizeLimit != NULL)
471 #endif
472 
473 #if (TLS_MAX_FRAG_LEN_SUPPORT == ENABLED)
474  //Servers that receive an ClientHello containing a MaxFragmentLength
475  //extension may accept the requested maximum fragment length by including
476  //an extension of type MaxFragmentLength in the ServerHello
477  error = tlsParseServerMaxFragLenExtension(context, extensions.maxFragLen);
478  //Any error to report?
479  if(error)
480  return error;
481 #endif
482 
483 #if (TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
484  //The value of RecordSizeLimit is the maximum size of record in octets
485  //that the peer is willing to receive
487  extensions.recordSizeLimit);
488  //Any error to report?
489  if(error)
490  return error;
491 #endif
492 
493 #if (TLS_ALPN_SUPPORT == ENABLED)
494  //Parse ALPN extension
495  error = tlsParseServerAlpnExtension(context, extensions.protocolNameList);
496  //Any error to report?
497  if(error)
498  return error;
499 #endif
500 
501 #if (TLS_RAW_PUBLIC_KEY_SUPPORT == ENABLED)
502  //Parse ClientCertType extension
503  error = tlsParseClientCertTypeExtension(context, extensions.clientCertType);
504  //Any error to report?
505  if(error)
506  return error;
507 
508  //Parse ServerCertType extension
509  error = tlsParseServerCertTypeExtension(context, extensions.serverCertType);
510  //Any error to report?
511  if(error)
512  return error;
513 #endif
514 
515 #if (TLS13_EARLY_DATA_SUPPORT == ENABLED)
516  //Parse EarlyData extension
517  error = tls13ParseServerEarlyDataExtension(context,
518  TLS_TYPE_ENCRYPTED_EXTENSIONS, extensions.earlyDataIndication);
519  //Any error to report?
520  if(error)
521  return error;
522 
523  //Check whether the server has accepted the early data
524  if(context->earlyDataExtReceived)
525  {
526 #if (TLS_ALPN_SUPPORT == ENABLED)
527  //Valid ticket?
528  if(!tls13IsPskValid(context) && tls13IsTicketValid(context))
529  {
530  //Enforce ALPN protocol
531  if(context->selectedProtocol != NULL || context->ticketAlpn != NULL)
532  {
533  if(context->selectedProtocol != NULL && context->ticketAlpn != NULL)
534  {
535  //Compare the selected ALPN protocol against the expected value
536  if(osStrcmp(context->selectedProtocol, context->ticketAlpn) != 0)
537  {
538  //The selected ALPN protocol is not acceptable
539  return ERROR_HANDSHAKE_FAILED;
540  }
541  }
542  else
543  {
544  //The selected ALPN protocol is not acceptable
545  return ERROR_HANDSHAKE_FAILED;
546  }
547  }
548  }
549 #endif
550 
551  //The EndOfEarlyData message is encrypted with the 0-RTT traffic keys
552  tlsFreeEncryptionEngine(&context->encryptionEngine);
553 
554  //Calculate client early traffic keys
555  error = tlsInitEncryptionEngine(context, &context->encryptionEngine,
556  TLS_CONNECTION_END_CLIENT, context->clientEarlyTrafficSecret);
557  //Any error to report?
558  if(error)
559  return error;
560 
561  //Restore sequence number
562  context->encryptionEngine.seqNum = context->earlyDataSeqNum;
563  }
564 #endif
565 
566  //PSK key exchange method?
567  if(context->keyExchMethod == TLS13_KEY_EXCH_PSK ||
568  context->keyExchMethod == TLS13_KEY_EXCH_PSK_DHE ||
569  context->keyExchMethod == TLS13_KEY_EXCH_PSK_ECDHE ||
570  context->keyExchMethod == TLS13_KEY_EXCH_PSK_HYBRID)
571  {
572  //As the server is authenticating via a PSK, it does not send a
573  //Certificate or a CertificateVerify message
575  }
576  else
577  {
578  //A server can optionally request a certificate from the client
580  }
581 
582  //Successful processing
583  return NO_ERROR;
584 }
585 
586 
587 /**
588  * @brief Parse NewSessionTicket message
589  *
590  * At any time after the server has received the client Finished message, it
591  * may send a NewSessionTicket message
592  *
593  * @param[in] context Pointer to the TLS context
594  * @param[in] message Incoming NewSessionTicket message to parse
595  * @param[in] length Message length
596  * @return Error code
597  **/
598 
600  const Tls13NewSessionTicket *message, size_t length)
601 {
602  error_t error;
603  size_t n;
604  const uint8_t *p;
605  const Tls13Ticket *ticket;
606  const HashAlgo *hashAlgo;
608 
609  //Debug message
610  TRACE_INFO("NewSessionTicket message received (%" PRIuSIZE " bytes)...\r\n", length);
612 
613  //Check TLS version
614  if(context->version != TLS_VERSION_1_3)
616 
617  //Check current state
618  if(context->state != TLS_STATE_APPLICATION_DATA &&
619  context->state != TLS_STATE_CLOSING)
620  {
621  //Report an error
623  }
624 
625  //Check the length of the NewSessionTicket message
626  if(length < sizeof(Tls13NewSessionTicket))
627  return ERROR_DECODING_FAILED;
628 
629  //Point to the ticket nonce
630  p = message->ticketNonce;
631  //Remaining bytes to process
632  length -= sizeof(Tls13NewSessionTicket);
633 
634  //Malformed NewSessionTicket message?
635  if(length < message->ticketNonceLen)
636  return ERROR_DECODING_FAILED;
637 
638  //Point to the next field
639  p += message->ticketNonceLen;
640  //Remaining bytes to process
641  length -= message->ticketNonceLen;
642 
643  //Malformed NewSessionTicket message?
644  if(length < sizeof(Tls13Ticket))
645  return ERROR_DECODING_FAILED;
646 
647  //Point to the session ticket
648  ticket = (Tls13Ticket *) p;
649  //Retrieve the length of the ticket
650  n = ntohs(ticket->length);
651 
652  //Malformed NewSessionTicket message?
653  if(length < (sizeof(Tls13Ticket) + n))
654  return ERROR_DECODING_FAILED;
655 
656  //Point to the next field
657  p += sizeof(Tls13Ticket) + n;
658  //Remaining bytes to process
659  length -= sizeof(Tls13Ticket) + n;
660 
661  //The message includes a set of extension values for the ticket
663  &extensions);
664  //Any error to report?
665  if(error)
666  return error;
667 
668  //Check the list of extensions offered by the server
670  context->version, &extensions);
671  //Any error to report?
672  if(error)
673  return error;
674 
675  //A ticket_lifetime value of zero indicates that the ticket should be
676  //discarded immediately
677  if(ntohl(message->ticketLifetime) > 0)
678  {
679  //Check the length of the session ticket
680  if(n > 0 && n <= TLS13_MAX_TICKET_SIZE)
681  {
682  //Servers may send multiple tickets on a single connection
683  if(context->ticket != NULL)
684  {
685  //Release memory
686  osMemset(context->ticket, 0, context->ticketLen);
687  tlsFreeMem(context->ticket);
688  context->ticket = NULL;
689  context->ticketLen = 0;
690  }
691 
692  //Allocate a memory block to hold the ticket
693  context->ticket = tlsAllocMem(n);
694  //Failed to allocate memory?
695  if(context->ticket == NULL)
696  return ERROR_OUT_OF_MEMORY;
697 
698  //Copy session ticket
699  osMemcpy(context->ticket, ticket->data, n);
700  context->ticketLen = n;
701 
702  //The client's view of the age of a ticket is the time since the
703  //receipt of the NewSessionTicket message
704  context->ticketTimestamp = osGetSystemTime();
705 
706  //Save the lifetime of the ticket
707  context->ticketLifetime = ntohl(message->ticketLifetime);
708 
709  //Clients must not cache tickets for longer than 7 days, regardless
710  //of the ticket_lifetime value (refer to RFC 8446, section 4.6.1)
711  context->ticketLifetime = MIN(context->ticketLifetime,
713 
714  //Random value used to obscure the age of the ticket
715  context->ticketAgeAdd = ntohl(message->ticketAgeAdd);
716 
717  //The sole extension currently defined for NewSessionTicket is
718  //EarlyData indicating that the ticket may be used to send 0-RTT data
719  error = tls13ParseServerEarlyDataExtension(context,
720  TLS_TYPE_NEW_SESSION_TICKET, extensions.earlyDataIndication);
721  //Any error to report?
722  if(error)
723  return error;
724 
725  //The hash function used by HKDF is the cipher suite hash algorithm
726  hashAlgo = context->cipherSuite.prfHashAlgo;
727  //Make sure the hash algorithm is valid
728  if(hashAlgo == NULL)
729  return ERROR_FAILURE;
730 
731  //Calculate the PSK associated with the ticket
732  error = tls13HkdfExpandLabel(context->transportProtocol, hashAlgo,
733  context->resumptionMasterSecret, hashAlgo->digestSize, "resumption",
734  message->ticketNonce, message->ticketNonceLen, context->ticketPsk,
735  hashAlgo->digestSize);
736  //Any error to report?
737  if(error)
738  return error;
739 
740  //Set the length of the PSK associated with the ticket
741  context->ticketPskLen = hashAlgo->digestSize;
742 
743  //Debug message
744  TRACE_DEBUG("Ticket PSK:\r\n");
745  TRACE_DEBUG_ARRAY(" ", context->ticketPsk, context->ticketPskLen);
746  }
747  }
748 
749  //Successful processing
750  return NO_ERROR;
751 }
752 
753 #endif
@ TLS13_KEY_EXCH_PSK
Definition: tls.h:1161
#define tlsAllocMem(size)
Definition: tls.h:853
Parsing and checking of TLS extensions.
#define TLS13_MAX_TICKET_LIFETIME
Definition: tls13_misc.h:113
TLS helper functions.
uint8_t extensions[]
Definition: ntp_common.h:207
TLS cipher suites.
uint16_t cipherSuite
Cipher suite identifier.
Definition: tls.h:1883
const HashAlgo * tlsGetHashAlgo(TlsHashAlgo hashAlgoId)
Get the hash algorithm that matches the specified identifier.
Definition: tls_misc.c:1173
@ ERROR_WOULD_BLOCK
Definition: error.h:96
@ TLS13_KEY_EXCH_PSK_DHE
Definition: tls.h:1162
TLS handshake.
@ TLS_COMPRESSION_METHOD_NULL
Definition: tls.h:1128
@ ERROR_VERSION_NOT_SUPPORTED
Definition: error.h:67
@ ERROR_NOT_IMPLEMENTED
Definition: error.h:66
@ ERROR_ILLEGAL_PARAMETER
Definition: error.h:243
@ ERROR_UNEXPECTED_MESSAGE
Definition: error.h:194
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:1469
size_t digestSize
Definition: crypto.h:1052
error_t tlsParseServerRecordSizeLimitExtension(TlsContext *context, const TlsExtension *recordSizeLimit)
Parse RecordSizeLimit extension.
TLS 1.3 session tickets.
@ TLS_STATE_APPLICATION_DATA
Definition: tls.h:1485
#define osMemcmp(p1, p2, length)
Definition: os_port.h:153
@ ERROR_HANDSHAKE_FAILED
Definition: error.h:233
@ 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:171
error_t tls13ParseEncryptedExtensions(TlsContext *context, const Tls13EncryptedExtensions *message, size_t length)
Parse EncryptedExtensions message.
Definition: tls13_client.c:420
error_t tls13FormatEndOfEarlyData(TlsContext *context, Tls13EndOfEarlyData *message, size_t *length)
Format EndOfEarlyData message.
Definition: tls13_client.c:128
uint8_t ticketNonceLen
Definition: tls13_misc.h:326
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:1045
@ TLS13_KEY_EXCH_PSK_HYBRID
Definition: tls.h:1164
error_t tls13ParseNewSessionTicket(TlsContext *context, const Tls13NewSessionTicket *message, size_t length)
Parse NewSessionTicket message.
Definition: tls13_client.c:599
@ TLS_HASH_ALGO_NONE
Definition: tls.h:1213
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:1461
error_t tls13SendEndOfEarlyData(TlsContext *context)
Send EndOfEarlyData message.
Definition: tls13_client.c:67
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:141
#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:917
#define TLS_VERSION_1_2
Definition: tls.h:96
Tls13HelloRetryRequest
Definition: tls13_misc.h:297
@ 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:1480
#define TLS_VERSION_1_3
Definition: tls.h:97
@ TLS_TYPE_ENCRYPTED_EXTENSIONS
Definition: tls.h:1047
bool_t tls13IsTicketValid(TlsContext *context)
Check whether a session ticket is valid.
Definition: tls13_ticket.c:51
@ TLS_TRANSPORT_PROTOCOL_EAP
Definition: tls.h:958
@ TLS_STATE_SERVER_HELLO_3
Definition: tls.h:1463
error_t tlsFormatInitialClientHello(TlsContext *context)
Format initial ClientHello message.
#define TRACE_INFO(...)
Definition: debug.h:95
uint8_t length
Definition: tcp.h:368
#define MIN(a, b)
Definition: os_port.h:63
@ TLS_STATE_CLIENT_CHANGE_CIPHER_SPEC
Definition: tls.h:1474
Hello extensions.
Definition: tls.h:2098
Transcript hash calculation.
Tls13Ticket
Definition: tls13_misc.h:349
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:106
#define TRACE_DEBUG(...)
Definition: debug.h:107
@ ERROR_TIMEOUT
Definition: error.h:95
uint8_t ticket[]
Definition: tls.h:1844
@ TLS13_KEY_EXCH_PSK_ECDHE
Definition: tls.h:1163
@ TLS_STATE_CLIENT_HELLO_2
Definition: tls.h:1457
@ TLS_STATE_CLOSING
Definition: tls.h:1486
#define TRACE_DEBUG_ARRAY(p, a, n)
Definition: debug.h:108
const char_t * tlsGetCipherSuiteName(uint16_t identifier)
Convert cipher suite identifier to string representation.
TlsServerHello
Definition: tls.h:1787
bool_t tls13IsPskValid(TlsContext *context)
Check whether an externally established PSK is valid.
Definition: tls13_misc.c:770
uint8_t n
HKDF (HMAC-based Key Derivation Function)
Tls13NewSessionTicket
Definition: tls13_misc.h:328
@ TLS_STATE_ENCRYPTED_EXTENSIONS
Definition: tls.h:1465
error_t tls13ParseHelloRetryRequest(TlsContext *context, const Tls13HelloRetryRequest *message, size_t length)
Parse HelloRetryRequest message.
Definition: tls13_client.c:152
error_t tlsInitTranscriptHash(TlsContext *context)
Initialize handshake message hashing.
@ TLS_CONNECTION_END_CLIENT
Definition: tls.h:968
Formatting and parsing of extensions (TLS 1.3 client)
TLS (Transport Layer Security)
void * Tls13EndOfEarlyData
EndOfEarlyData message.
Definition: tls13_misc.h:304
@ TLS_TRANSPORT_PROTOCOL_STREAM
Definition: tls.h:956
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:1046
__weak_func error_t tlsInitEncryptionEngine(TlsContext *context, TlsEncryptionEngine *encryptionEngine, TlsConnectionEnd entity, const uint8_t *secret)
Initialize encryption engine.
Definition: tls_misc.c:670
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:1112
@ TLS_TYPE_NEW_SESSION_TICKET
Definition: tls.h:1044
void tlsChangeState(TlsContext *context, TlsState newState)
Update TLS state.
Definition: tls_misc.c:54
@ ERROR_DECODING_FAILED
Definition: error.h:241
@ TLS_TYPE_HELLO_RETRY_REQUEST
Definition: tls.h:1046
#define PRIuSIZE
#define LOAD16BE(p)
Definition: cpu_endian.h:186
#define osMemset(p, value, length)
Definition: os_port.h:135
#define tlsFreeMem(p)
Definition: tls.h:858
error_t tls13DigestClientHello1(TlsContext *context)
Hash ClientHello1 in the transcript when HelloRetryRequest is used.
Definition: tls13_misc.c:725
@ TLS_STATE_CLIENT_FINISHED
Definition: tls.h:1476
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.
Tls13EncryptedExtensions
Definition: tls13_misc.h:315
error_t tls13ParseServerEarlyDataExtension(TlsContext *context, TlsMessageType msgType, const TlsExtension *earlyDataIndication)
Parse EarlyData extension.
systime_t osGetSystemTime(void)
Retrieve system time.