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.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_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))
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  {
571  //As the server is authenticating via a PSK, it does not send a
572  //Certificate or a CertificateVerify message
574  }
575  else
576  {
577  //A server can optionally request a certificate from the client
579  }
580 
581  //Successful processing
582  return NO_ERROR;
583 }
584 
585 
586 /**
587  * @brief Parse NewSessionTicket message
588  *
589  * At any time after the server has received the client Finished message, it
590  * may send a NewSessionTicket message
591  *
592  * @param[in] context Pointer to the TLS context
593  * @param[in] message Incoming NewSessionTicket message to parse
594  * @param[in] length Message length
595  * @return Error code
596  **/
597 
599  const Tls13NewSessionTicket *message, size_t length)
600 {
601  error_t error;
602  size_t n;
603  const uint8_t *p;
604  const Tls13Ticket *ticket;
605  const HashAlgo *hashAlgo;
607 
608  //Debug message
609  TRACE_INFO("NewSessionTicket message received (%" PRIuSIZE " bytes)...\r\n", length);
611 
612  //Check TLS version
613  if(context->version != TLS_VERSION_1_3)
615 
616  //Check current state
617  if(context->state != TLS_STATE_APPLICATION_DATA &&
618  context->state != TLS_STATE_CLOSING)
619  {
620  //Report an error
622  }
623 
624  //Check the length of the NewSessionTicket message
625  if(length < sizeof(Tls13NewSessionTicket))
626  return ERROR_DECODING_FAILED;
627 
628  //Point to the ticket nonce
629  p = message->ticketNonce;
630  //Remaining bytes to process
631  length -= sizeof(Tls13NewSessionTicket);
632 
633  //Malformed NewSessionTicket message?
634  if(length < message->ticketNonceLen)
635  return ERROR_DECODING_FAILED;
636 
637  //Point to the next field
638  p += message->ticketNonceLen;
639  //Remaining bytes to process
640  length -= message->ticketNonceLen;
641 
642  //Malformed NewSessionTicket message?
643  if(length < sizeof(Tls13Ticket))
644  return ERROR_DECODING_FAILED;
645 
646  //Point to the session ticket
647  ticket = (Tls13Ticket *) p;
648  //Retrieve the length of the ticket
649  n = ntohs(ticket->length);
650 
651  //Malformed NewSessionTicket message?
652  if(length < (sizeof(Tls13Ticket) + n))
653  return ERROR_DECODING_FAILED;
654 
655  //Point to the next field
656  p += sizeof(Tls13Ticket) + n;
657  //Remaining bytes to process
658  length -= sizeof(Tls13Ticket) + n;
659 
660  //The message includes a set of extension values for the ticket
662  &extensions);
663  //Any error to report?
664  if(error)
665  return error;
666 
667  //Check the list of extensions offered by the server
669  context->version, &extensions);
670  //Any error to report?
671  if(error)
672  return error;
673 
674  //A ticket_lifetime value of zero indicates that the ticket should be
675  //discarded immediately
676  if(ntohl(message->ticketLifetime) > 0)
677  {
678  //Check the length of the session ticket
679  if(n > 0 && n <= TLS13_MAX_TICKET_SIZE)
680  {
681  //Servers may send multiple tickets on a single connection
682  if(context->ticket != NULL)
683  {
684  //Release memory
685  osMemset(context->ticket, 0, context->ticketLen);
686  tlsFreeMem(context->ticket);
687  context->ticket = NULL;
688  context->ticketLen = 0;
689  }
690 
691  //Allocate a memory block to hold the ticket
692  context->ticket = tlsAllocMem(n);
693  //Failed to allocate memory?
694  if(context->ticket == NULL)
695  return ERROR_OUT_OF_MEMORY;
696 
697  //Copy session ticket
698  osMemcpy(context->ticket, ticket->data, n);
699  context->ticketLen = n;
700 
701  //The client's view of the age of a ticket is the time since the
702  //receipt of the NewSessionTicket message
703  context->ticketTimestamp = osGetSystemTime();
704 
705  //Save the lifetime of the ticket
706  context->ticketLifetime = ntohl(message->ticketLifetime);
707 
708  //Clients must not cache tickets for longer than 7 days, regardless
709  //of the ticket_lifetime value (refer to RFC 8446, section 4.6.1)
710  context->ticketLifetime = MIN(context->ticketLifetime,
712 
713  //Random value used to obscure the age of the ticket
714  context->ticketAgeAdd = ntohl(message->ticketAgeAdd);
715 
716  //The sole extension currently defined for NewSessionTicket is
717  //EarlyData indicating that the ticket may be used to send 0-RTT data
718  error = tls13ParseServerEarlyDataExtension(context,
719  TLS_TYPE_NEW_SESSION_TICKET, extensions.earlyDataIndication);
720  //Any error to report?
721  if(error)
722  return error;
723 
724  //The hash function used by HKDF is the cipher suite hash algorithm
725  hashAlgo = context->cipherSuite.prfHashAlgo;
726  //Make sure the hash algorithm is valid
727  if(hashAlgo == NULL)
728  return ERROR_FAILURE;
729 
730  //Calculate the PSK associated with the ticket
731  error = tls13HkdfExpandLabel(context->transportProtocol, hashAlgo,
732  context->resumptionMasterSecret, hashAlgo->digestSize, "resumption",
733  message->ticketNonce, message->ticketNonceLen, context->ticketPsk,
734  hashAlgo->digestSize);
735  //Any error to report?
736  if(error)
737  return error;
738 
739  //Set the length of the PSK associated with the ticket
740  context->ticketPskLen = hashAlgo->digestSize;
741 
742  //Debug message
743  TRACE_DEBUG("Ticket PSK:\r\n");
744  TRACE_DEBUG_ARRAY(" ", context->ticketPsk, context->ticketPskLen);
745  }
746  }
747 
748  //Successful processing
749  return NO_ERROR;
750 }
751 
752 #endif
uint8_t message[]
Definition: chap.h:154
#define PRIuSIZE
#define ntohl(value)
Definition: cpu_endian.h:422
#define ntohs(value)
Definition: cpu_endian.h:421
#define LOAD16BE(p)
Definition: cpu_endian.h:186
Debugging facilities.
#define TRACE_DEBUG_ARRAY(p, a, n)
Definition: debug.h:108
#define TRACE_DEBUG(...)
Definition: debug.h:107
#define TRACE_INFO(...)
Definition: debug.h:95
uint8_t n
error_t
Error codes.
Definition: error.h:43
@ ERROR_ILLEGAL_PARAMETER
Definition: error.h:242
@ ERROR_WOULD_BLOCK
Definition: error.h:96
@ ERROR_VERSION_NOT_SUPPORTED
Definition: error.h:67
@ ERROR_TIMEOUT
Definition: error.h:95
@ ERROR_HANDSHAKE_FAILED
Definition: error.h:232
@ ERROR_DECODING_FAILED
Definition: error.h:240
@ ERROR_NOT_IMPLEMENTED
Definition: error.h:66
@ NO_ERROR
Success.
Definition: error.h:44
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
@ ERROR_UNEXPECTED_MESSAGE
Definition: error.h:194
HKDF (HMAC-based Key Derivation Function)
uint8_t p
Definition: ndp.h:300
#define osMemset(p, value, length)
Definition: os_port.h:135
#define osStrcmp(s1, s2)
Definition: os_port.h:171
#define osMemcpy(dest, src, length)
Definition: os_port.h:141
#define MIN(a, b)
Definition: os_port.h:63
#define osMemcmp(p1, p2, length)
Definition: os_port.h:153
#define TRUE
Definition: os_port.h:50
systime_t osGetSystemTime(void)
Retrieve system time.
Common interface for hash algorithms.
Definition: crypto.h:1014
size_t digestSize
Definition: crypto.h:1020
Hello extensions.
Definition: tls.h:2081
uint8_t length
Definition: tcp.h:368
error_t tls13ParseNewSessionTicket(TlsContext *context, const Tls13NewSessionTicket *message, size_t length)
Parse NewSessionTicket message.
Definition: tls13_client.c:598
error_t tls13FormatEndOfEarlyData(TlsContext *context, Tls13EndOfEarlyData *message, size_t *length)
Format EndOfEarlyData message.
Definition: tls13_client.c:128
error_t tls13ParseHelloRetryRequest(TlsContext *context, const Tls13HelloRetryRequest *message, size_t length)
Parse HelloRetryRequest message.
Definition: tls13_client.c:152
error_t tls13ParseEncryptedExtensions(TlsContext *context, const Tls13EncryptedExtensions *message, size_t length)
Parse EncryptedExtensions message.
Definition: tls13_client.c:420
error_t tls13SendEndOfEarlyData(TlsContext *context)
Send EndOfEarlyData message.
Definition: tls13_client.c:67
Handshake message processing (TLS 1.3 client)
error_t tls13ParseCookieExtension(TlsContext *context, const Tls13Cookie *cookie)
Parse Cookie extension.
error_t tls13ParseSelectedGroupExtension(TlsContext *context, const TlsExtension *selectedGroup)
Parse KeyShare extension (HelloRetryRequest message)
error_t tls13ParseServerEarlyDataExtension(TlsContext *context, TlsMessageType msgType, const TlsExtension *earlyDataIndication)
Parse EarlyData extension.
error_t tls13ParseServerSupportedVersionsExtension(TlsContext *context, const TlsExtension *selectedVersion)
Parse SupportedVersions extension.
Formatting and parsing of extensions (TLS 1.3 client)
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.
TLS 1.3 key schedule.
error_t tls13DigestClientHello1(TlsContext *context)
Hash ClientHello1 in the transcript when HelloRetryRequest is used.
Definition: tls13_misc.c:493
bool_t tls13IsPskValid(TlsContext *context)
Check whether an externally established PSK is valid.
Definition: tls13_misc.c:538
TLS 1.3 helper functions.
Tls13NewSessionTicket
Definition: tls13_misc.h:314
Tls13Ticket
Definition: tls13_misc.h:335
void * Tls13EndOfEarlyData
EndOfEarlyData message.
Definition: tls13_misc.h:290
#define TLS13_MAX_TICKET_LIFETIME
Definition: tls13_misc.h:99
uint8_t extensions[]
Definition: tls13_misc.h:300
Tls13EncryptedExtensions
Definition: tls13_misc.h:301
Tls13HelloRetryRequest
Definition: tls13_misc.h:283
uint8_t ticketNonceLen
Definition: tls13_misc.h:312
#define TLS13_MAX_TICKET_SIZE
Definition: tls13_misc.h:92
bool_t tls13IsTicketValid(TlsContext *context)
Check whether a session ticket is valid.
Definition: tls13_ticket.c:51
TLS 1.3 session tickets.
TLS (Transport Layer Security)
#define tlsAllocMem(size)
Definition: tls.h:846
@ TLS_STATE_CLIENT_FINISHED
Definition: tls.h:1459
@ TLS_STATE_SERVER_FINISHED
Definition: tls.h:1463
@ TLS_STATE_CLIENT_HELLO_2
Definition: tls.h:1440
@ TLS_STATE_SERVER_HELLO
Definition: tls.h:1444
@ TLS_STATE_APPLICATION_DATA
Definition: tls.h:1468
@ TLS_STATE_CLOSING
Definition: tls.h:1469
@ TLS_STATE_SERVER_HELLO_3
Definition: tls.h:1446
@ TLS_STATE_CERTIFICATE_REQUEST
Definition: tls.h:1452
@ TLS_STATE_CLIENT_CHANGE_CIPHER_SPEC
Definition: tls.h:1457
@ TLS_STATE_ENCRYPTED_EXTENSIONS
Definition: tls.h:1448
@ TLS13_KEY_EXCH_PSK_DHE
Definition: tls.h:1146
@ TLS13_KEY_EXCH_PSK
Definition: tls.h:1145
@ TLS13_KEY_EXCH_PSK_ECDHE
Definition: tls.h:1147
@ TLS_TRANSPORT_PROTOCOL_STREAM
Definition: tls.h:941
@ TLS_TRANSPORT_PROTOCOL_EAP
Definition: tls.h:943
@ TLS_COMPRESSION_METHOD_NULL
Definition: tls.h:1113
#define tlsFreeMem(p)
Definition: tls.h:851
TlsServerHello
Definition: tls.h:1770
uint8_t ticket[]
Definition: tls.h:1827
@ TLS_HASH_ALGO_NONE
Definition: tls.h:1196
#define TLS_VERSION_1_3
Definition: tls.h:97
#define TlsContext
Definition: tls.h:36
uint16_t cipherSuite
Cipher suite identifier.
Definition: tls.h:1866
@ TLS_CONNECTION_END_CLIENT
Definition: tls.h:953
@ TLS_TYPE_END_OF_EARLY_DATA
Definition: tls.h:1030
@ TLS_TYPE_ENCRYPTED_EXTENSIONS
Definition: tls.h:1032
@ TLS_TYPE_NEW_SESSION_TICKET
Definition: tls.h:1029
@ TLS_TYPE_HELLO_RETRY_REQUEST
Definition: tls.h:1031
#define TLS_VERSION_1_2
Definition: tls.h:96
const char_t * tlsGetCipherSuiteName(uint16_t identifier)
Convert cipher suite identifier to string representation.
TLS cipher suites.
error_t tlsParseServerAlpnExtension(TlsContext *context, const TlsProtocolNameList *protocolNameList)
Parse ALPN extension.
error_t tlsParseServerCertTypeExtension(TlsContext *context, const TlsExtension *serverCertType)
Parse ServerCertType extension.
error_t tlsParseServerSniExtension(TlsContext *context, const TlsServerNameList *serverNameList)
Parse SNI extension.
error_t tlsParseClientCertTypeExtension(TlsContext *context, const TlsExtension *clientCertType)
Parse ClientCertType extension.
error_t tlsParseServerMaxFragLenExtension(TlsContext *context, const TlsExtension *maxFragLen)
Parse MaxFragmentLength extension.
error_t tlsParseServerRecordSizeLimitExtension(TlsContext *context, const TlsExtension *recordSizeLimit)
Parse RecordSizeLimit extension.
Formatting and parsing of extensions (TLS client)
error_t tlsFormatInitialClientHello(TlsContext *context)
Format initial ClientHello message.
Helper functions for TLS client.
error_t tlsParseHelloExtensions(TlsMessageType msgType, const uint8_t *p, size_t length, TlsHelloExtensions *extensions)
Parse Hello extensions.
error_t tlsCheckHelloExtensions(TlsMessageType msgType, uint16_t version, TlsHelloExtensions *extensions)
Check Hello extensions.
Parsing and checking of TLS extensions.
error_t tlsSendHandshakeMessage(TlsContext *context, const void *data, size_t length, TlsMessageType type)
Send handshake message.
TLS handshake.
error_t tlsSelectCipherSuite(TlsContext *context, uint16_t identifier)
Set cipher suite.
Definition: tls_misc.c:333
void tlsFreeEncryptionEngine(TlsEncryptionEngine *encryptionEngine)
Release encryption engine.
Definition: tls_misc.c:917
void tlsChangeState(TlsContext *context, TlsState newState)
Update TLS state.
Definition: tls_misc.c:54
__weak_func error_t tlsInitEncryptionEngine(TlsContext *context, TlsEncryptionEngine *encryptionEngine, TlsConnectionEnd entity, const uint8_t *secret)
Initialize encryption engine.
Definition: tls_misc.c:670
const char_t * tlsGetVersionName(uint16_t version)
Convert TLS version to string representation.
Definition: tls_misc.c:1112
const HashAlgo * tlsGetHashAlgo(TlsHashAlgo hashAlgoId)
Get the hash algorithm that matches the specified identifier.
Definition: tls_misc.c:1173
TLS helper functions.
void tlsFreeTranscriptHash(TlsContext *context)
Release transcript hash context.
error_t tlsInitTranscriptHash(TlsContext *context)
Initialize handshake message hashing.
Transcript hash calculation.