tls_server_extensions.c
Go to the documentation of this file.
1 /**
2  * @file tls_server_extensions.c
3  * @brief Formatting and parsing of extensions (TLS server)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSSL Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.6.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL TLS_TRACE_LEVEL
33 
34 //Dependencies
35 #include "tls.h"
36 #include "tls_cipher_suites.h"
37 #include "tls_server_extensions.h"
38 #include "tls_extensions.h"
39 #include "tls_misc.h"
40 #include "debug.h"
41 
42 //Check TLS library configuration
43 #if (TLS_SUPPORT == ENABLED && TLS_SERVER_SUPPORT == ENABLED)
44 
45 
46 /**
47  * @brief Format SNI extension
48  * @param[in] context Pointer to the TLS context
49  * @param[in] p Output stream where to write the ServerName extension
50  * @param[out] written Total number of bytes that have been written
51  * @return Error code
52  **/
53 
55  uint8_t *p, size_t *written)
56 {
57  size_t n = 0;
58 
59 #if (TLS_SNI_SUPPORT == ENABLED)
60  //A server that receives a ClientHello containing the SNI extension may use
61  //the information contained in the extension to guide its selection of an
62  //appropriate certificate to return to the client. In this event, the server
63  //shall include an extension of type SNI in the ServerHello
64  if(context->serverName != NULL)
65  {
66  TlsExtension *extension;
67 
68  //Add SNI (Server Name Indication) extension
69  extension = (TlsExtension *) p;
70  //Type of the extension
71  extension->type = HTONS(TLS_EXT_SERVER_NAME);
72 
73  //The extension data field of this extension shall be empty (refer to
74  //RFC 6066, section 3)
75  extension->length = HTONS(0);
76 
77  //Compute the length, in bytes, of the ServerName extension
78  n = sizeof(TlsExtension);
79 
80  //Version of TLS prior to TLS 1.3?
81  if(context->version <= TLS_VERSION_1_2)
82  {
83  //When resuming a session, the server must not include a ServerName
84  //extension in the ServerHello (refer to RFC 6066, section 3)
85  if(context->resume)
86  {
87  n = 0;
88  }
89  }
90  else
91  {
92  //When resuming a session, the server must not include a ServerName
93  //extension in the ServerHello (refer to RFC 6066, section 3)
94  if(context->keyExchMethod == TLS13_KEY_EXCH_PSK_DHE ||
95  context->keyExchMethod == TLS13_KEY_EXCH_PSK_ECDHE ||
96  context->keyExchMethod == TLS13_KEY_EXCH_PSK_MLKEM ||
97  context->keyExchMethod == TLS13_KEY_EXCH_PSK_HYBRID)
98  {
99  n = 0;
100  }
101  }
102  }
103 #endif
104 
105  //Total number of bytes that have been written
106  *written = n;
107 
108  //Successful processing
109  return NO_ERROR;
110 }
111 
112 
113 /**
114  * @brief Format MaxFragmentLength extension
115  * @param[in] context Pointer to the TLS context
116  * @param[in] p Output stream where to write the MaxFragmentLength extension
117  * @param[out] written Total number of bytes that have been written
118  * @return Error code
119  **/
120 
122  uint8_t *p, size_t *written)
123 {
124  size_t n = 0;
125 
126 #if (TLS_MAX_FRAG_LEN_SUPPORT == ENABLED)
127  //An extension type must not appear in the ServerHello unless the same
128  //extension type appeared in the corresponding ClientHello
129  if(context->maxFragLenExtReceived)
130  {
131  //Servers that receive an ClientHello containing a MaxFragmentLength
132  //extension may accept the requested maximum fragment length by including
133  //an extension of type MaxFragmentLength in the ServerHello
134  if(context->maxFragLen == 512 || context->maxFragLen == 1024 ||
135  context->maxFragLen == 2048 || context->maxFragLen == 4096)
136  {
137  TlsExtension *extension;
138 
139  //Add the MaxFragmentLength extension
140  extension = (TlsExtension *) p;
141  //Type of the extension
142  extension->type = HTONS(TLS_EXT_MAX_FRAGMENT_LENGTH);
143 
144  //The data field of this extension shall contain a MaxFragmentLength
145  //whose value is the same as the requested maximum fragment length
146  switch(context->maxFragLen)
147  {
148  case 512:
149  extension->value[0] = TLS_MAX_FRAGMENT_LENGTH_512;
150  break;
151 
152  case 1024:
153  extension->value[0] = TLS_MAX_FRAGMENT_LENGTH_1024;
154  break;
155 
156  case 2048:
157  extension->value[0] = TLS_MAX_FRAGMENT_LENGTH_2048;
158  break;
159 
160  default:
161  extension->value[0] = TLS_MAX_FRAGMENT_LENGTH_4096;
162  break;
163  }
164 
165  //The extension data field contains a single byte
166  n = sizeof(uint8_t);
167  //Fix the length of the extension
168  extension->length = htons(n);
169 
170  //Compute the length, in bytes, of the MaxFragmentLength extension
171  n += sizeof(TlsExtension);
172  }
173  }
174 #endif
175 
176  //Total number of bytes that have been written
177  *written = n;
178 
179  //Successful processing
180  return NO_ERROR;
181 }
182 
183 
184 /**
185  * @brief Format RecordSizeLimit extension
186  * @param[in] context Pointer to the TLS context
187  * @param[in] p Output stream where to write the RecordSizeLimit extension
188  * @param[out] written Total number of bytes that have been written
189  * @return Error code
190  **/
191 
193  uint8_t *p, size_t *written)
194 {
195  size_t n = 0;
196 
197 #if (TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
198  //An extension type must not appear in the ServerHello unless the same
199  //extension type appeared in the corresponding ClientHello
200  if(context->recordSizeLimitExtReceived)
201  {
202  size_t recordSizeLimit;
203  TlsExtension *extension;
204 
205  //Add the RecordSizeLimit extension
206  extension = (TlsExtension *) p;
207  //Type of the extension
208  extension->type = HTONS(TLS_EXT_RECORD_SIZE_LIMIT);
209 
210  //An endpoint must not send a value higher than the protocol-defined
211  //maximum record size (refer to RFC 8449, section 4)
212  recordSizeLimit = MIN(context->rxBufferMaxLen, TLS_MAX_RECORD_LENGTH);
213 
214  //TLS 1.3 currently selected?
215  if(context->version == TLS_VERSION_1_3)
216  {
217  //The value includes the content type and padding added in TLS 1.3
218  recordSizeLimit++;
219  }
220 
221  //The value of RecordSizeLimit is the maximum size of record in octets
222  //that the endpoint is willing to receive
223  STORE16BE(recordSizeLimit, extension->value);
224 
225  //The extension data field contains a 16-bit unsigned integer
226  n = sizeof(uint16_t);
227  //Fix the length of the extension
228  extension->length = htons(n);
229 
230  //Compute the length, in bytes, of the RecordSizeLimit extension
231  n += sizeof(TlsExtension);
232  }
233 #endif
234 
235  //Total number of bytes that have been written
236  *written = n;
237 
238  //Successful processing
239  return NO_ERROR;
240 }
241 
242 
243 /**
244  * @brief Format EcPointFormats extension
245  * @param[in] context Pointer to the TLS context
246  * @param[in] p Output stream where to write the EcPointFormats extension
247  * @param[out] written Total number of bytes that have been written
248  * @return Error code
249  **/
250 
252  uint8_t *p, size_t *written)
253 {
254  size_t n = 0;
255 
256 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2)
257  //TLS 1.3 has removed point format negotiation in favor of a single point
258  //format for each curve (refer to RFC 8446, section 1.2)
259  if(context->version <= TLS_VERSION_1_2)
260  {
261 #if (TLS_ECDH_ANON_KE_SUPPORT == ENABLED || TLS_ECDHE_RSA_KE_SUPPORT == ENABLED || \
262  TLS_ECDHE_ECDSA_KE_SUPPORT == ENABLED || TLS_ECDHE_PSK_KE_SUPPORT == ENABLED)
263  //An extension type must not appear in the ServerHello unless the same
264  //extension type appeared in the corresponding ClientHello
265  if(context->ecPointFormatsExtReceived)
266  {
267  //A server that selects an ECC cipher suite in response to a ClientHello
268  //message including an EcPointFormats extension appends this extension
269  //to its ServerHello message
270  if((context->cipherSuiteTypes & TLS_CIPHER_SUITE_TYPE_ECDH) != 0)
271  {
272  TlsExtension *extension;
273  TlsEcPointFormatList *ecPointFormatList;
274 
275  //Add the EcPointFormats extension
276  extension = (TlsExtension *) p;
277  //Type of the extension
278  extension->type = HTONS(TLS_EXT_EC_POINT_FORMATS);
279 
280  //Point to the list of supported EC point formats
281  ecPointFormatList = (TlsEcPointFormatList *) extension->value;
282  //Items in the list are ordered according to server's preferences
283  n = 0;
284 
285  //The server can parse only the uncompressed point format...
286  ecPointFormatList->value[n++] = TLS_EC_POINT_FORMAT_UNCOMPRESSED;
287  //Fix the length of the list
288  ecPointFormatList->length = (uint8_t) n;
289 
290  //Consider the length field that precedes the list
291  n += sizeof(TlsEcPointFormatList);
292  //Fix the length of the extension
293  extension->length = htons(n);
294 
295  //Compute the length, in bytes, of the EcPointFormats extension
296  n += sizeof(TlsExtension);
297  }
298  }
299 #endif
300  }
301 #endif
302 
303  //Total number of bytes that have been written
304  *written = n;
305 
306  //Successful processing
307  return NO_ERROR;
308 }
309 
310 
311 /**
312  * @brief Format ALPN extension
313  * @param[in] context Pointer to the TLS context
314  * @param[in] p Output stream where to write the ALPN extension
315  * @param[out] written Total number of bytes that have been written
316  * @return Error code
317  **/
318 
320  uint8_t *p, size_t *written)
321 {
322  size_t n = 0;
323 
324 #if (TLS_ALPN_SUPPORT == ENABLED)
325  //The ALPN extension may be returned to the client within the extended
326  //ServerHello message
327  if(context->selectedProtocol != NULL)
328  {
329  //Empty strings must not be included
330  if(context->selectedProtocol[0] != '\0')
331  {
332  TlsExtension *extension;
333  TlsProtocolName *protocolName;
334  TlsProtocolNameList *protocolNameList;
335 
336  //Add ALPN (Application-Layer Protocol Negotiation) extension
337  extension = (TlsExtension *) p;
338  //Type of the extension
339  extension->type = HTONS(TLS_EXT_ALPN);
340 
341  //Point to the list of protocol names
342  protocolNameList = (TlsProtocolNameList *) extension->value;
343  //The list must contain exactly one protocol name
344  protocolName = (TlsProtocolName *) protocolNameList->value;
345 
346  //Retrieve the length of the protocol name
347  n = osStrlen(context->selectedProtocol);
348 
349  //Fill in the length field
350  protocolName->length = (uint8_t) n;
351  //Copy protocol name
352  osMemcpy(protocolName->value, context->selectedProtocol, n);
353 
354  //Adjust the length of the list
355  n += sizeof(TlsProtocolName);
356  //Fix the length of the list
357  protocolNameList->length = htons(n);
358 
359  //Consider the 2-byte length field that precedes the list
360  n += sizeof(TlsProtocolNameList);
361  //Fix the length of the extension
362  extension->length = htons(n);
363 
364  //Compute the length, in bytes, of the ALPN extension
365  n += sizeof(TlsExtension);
366  }
367  }
368 #endif
369 
370  //Total number of bytes that have been written
371  *written = n;
372 
373  //Successful processing
374  return NO_ERROR;
375 }
376 
377 
378 /**
379  * @brief Format ClientCertType extension
380  * @param[in] context Pointer to the TLS context
381  * @param[in] p Output stream where to write the ClientCertType extension
382  * @param[out] written Total number of bytes that have been written
383  * @return Error code
384  **/
385 
387  uint8_t *p, size_t *written)
388 {
389  size_t n = 0;
390 
391 #if (TLS_RAW_PUBLIC_KEY_SUPPORT == ENABLED)
392  //An extension type must not appear in the ServerHello unless the same
393  //extension type appeared in the corresponding ClientHello
394  if(context->clientCertTypeExtReceived)
395  {
396  TlsExtension *extension;
397 
398  //Add the ClientCertType extension
399  extension = (TlsExtension *) p;
400  //Type of the extension
401  extension->type = HTONS(TLS_EXT_CLIENT_CERT_TYPE);
402 
403  //The ClientCertType extension in the ServerHello indicates the type
404  //of certificates the client is requested to provide in a subsequent
405  //certificate payload
406  extension->value[0] = context->peerCertFormat;
407 
408  //The extension data field contains a single byte
409  n = sizeof(uint8_t);
410  //Fix the length of the extension
411  extension->length = htons(n);
412 
413  //Compute the length, in bytes, of the ClientCertType extension
414  n += sizeof(TlsExtension);
415  }
416 #endif
417 
418  //Total number of bytes that have been written
419  *written = n;
420 
421  //Successful processing
422  return NO_ERROR;
423 }
424 
425 
426 /**
427  * @brief Format ServerCertType extension
428  * @param[in] context Pointer to the TLS context
429  * @param[in] p Output stream where to write the ServerCertType extension
430  * @param[out] written Total number of bytes that have been written
431  * @return Error code
432  **/
433 
435  uint8_t *p, size_t *written)
436 {
437  size_t n = 0;
438 
439 #if (TLS_RAW_PUBLIC_KEY_SUPPORT == ENABLED)
440  //An extension type must not appear in the ServerHello unless the same
441  //extension type appeared in the corresponding ClientHello
442  if(context->serverCertTypeExtReceived)
443  {
444  TlsExtension *extension;
445 
446  //Add the ServerCertType extension
447  extension = (TlsExtension *) p;
448  //Type of the extension
449  extension->type = HTONS(TLS_EXT_SERVER_CERT_TYPE);
450 
451  //With the ServerCertType extension in the ServerHello, the TLS server
452  //indicates the certificate type carried in the certificate payload
453  extension->value[0] = context->certFormat;
454 
455  //The extension data field contains a single byte
456  n = sizeof(uint8_t);
457  //Fix the length of the extension
458  extension->length = htons(n);
459 
460  //Compute the length, in bytes, of the ServerCertType extension
461  n += sizeof(TlsExtension);
462  }
463 #endif
464 
465  //Total number of bytes that have been written
466  *written = n;
467 
468  //Successful processing
469  return NO_ERROR;
470 }
471 
472 
473 /**
474  * @brief Format EncryptThenMac extension
475  * @param[in] context Pointer to the TLS context
476  * @param[in] p Output stream where to write the EncryptThenMac extension
477  * @param[out] written Total number of bytes that have been written
478  * @return Error code
479  **/
480 
482  uint8_t *p, size_t *written)
483 {
484  size_t n = 0;
485 
486 #if (TLS_ENCRYPT_THEN_MAC_SUPPORT == ENABLED)
487  //If the server receives a ClientHello without the EncryptThenMac extension,
488  //then it must not include the extension in the ServerHello
489  if(context->etmExtReceived)
490  {
491  TlsExtension *extension;
492 
493  //Add the EncryptThenMac extension
494  extension = (TlsExtension *) p;
495  //Type of the extension
496  extension->type = HTONS(TLS_EXT_ENCRYPT_THEN_MAC);
497 
498  //The extension data field of this extension shall be empty (refer to
499  //RFC 7366, section 2)
500  extension->length = HTONS(0);
501 
502  //Compute the length, in bytes, of the EncryptThenMac extension
503  n = sizeof(TlsExtension);
504  }
505 #endif
506 
507  //Total number of bytes that have been written
508  *written = n;
509 
510  //Successful processing
511  return NO_ERROR;
512 }
513 
514 
515 /**
516  * @brief Format ExtendedMasterSecret extension
517  * @param[in] context Pointer to the TLS context
518  * @param[in] p Output stream where to write the ExtendedMasterSecret extension
519  * @param[out] written Total number of bytes that have been written
520  * @return Error code
521  **/
522 
524  uint8_t *p, size_t *written)
525 {
526  size_t n = 0;
527 
528 #if (TLS_EXT_MASTER_SECRET_SUPPORT == ENABLED)
529  //If the server receives a ClientHello without the ExtendedMasterSecret
530  //extension, then it must not include the extension in the ServerHello
531  if(context->emsExtReceived)
532  {
533  TlsExtension *extension;
534 
535  //Add the ExtendedMasterSecret extension
536  extension = (TlsExtension *) p;
537  //Type of the extension
538  extension->type = HTONS(TLS_EXT_EXTENDED_MASTER_SECRET);
539 
540  //The extension data field of this extension is empty
541  extension->length = HTONS(0);
542 
543  //Compute the length, in bytes, of the ExtendedMasterSecret extension
544  n = sizeof(TlsExtension);
545  }
546 #endif
547 
548  //Total number of bytes that have been written
549  *written = n;
550 
551  //Successful processing
552  return NO_ERROR;
553 }
554 
555 
556 /**
557  * @brief Format SessionTicket extension
558  * @param[in] context Pointer to the TLS context
559  * @param[in] p Output stream where to write the SessionTicket extension
560  * @param[out] written Total number of bytes that have been written
561  * @return Error code
562  **/
563 
565  uint8_t *p, size_t *written)
566 {
567  size_t n = 0;
568 
569 #if (TLS_TICKET_SUPPORT == ENABLED)
570  //The server must not send this extension if it does not receive one in the
571  //ClientHello (refer to RFC 5077, section 3.2)
572  if(context->sessionTicketExtSent)
573  {
574  TlsExtension *extension;
575 
576  //Add the SessionTicket extension
577  extension = (TlsExtension *) p;
578  //Type of the extension
579  extension->type = HTONS(TLS_EXT_SESSION_TICKET);
580 
581  //The server uses a zero-length SessionTicket extension to indicate to the
582  //client that it will send a new session ticket using the NewSessionTicket
583  //handshake message
584  n = 0;
585 
586  //Set the length of the extension
587  extension->length = htons(n);
588 
589  //Compute the length, in bytes, of the SessionTicket extension
590  n += sizeof(TlsExtension);
591  }
592 #endif
593 
594  //Total number of bytes that have been written
595  *written = n;
596 
597  //Successful processing
598  return NO_ERROR;
599 }
600 
601 
602 /**
603  * @brief Format RenegotiationInfo extension
604  * @param[in] context Pointer to the TLS context
605  * @param[in] p Output stream where to write the RenegotiationInfo extension
606  * @param[out] written Total number of bytes that have been written
607  * @return Error code
608  **/
609 
611  uint8_t *p, size_t *written)
612 {
613  size_t n = 0;
614 
615 #if (TLS_SECURE_RENEGOTIATION_SUPPORT == ENABLED)
616  //Check whether secure renegotiation is enabled
617  if(context->secureRenegoEnabled)
618  {
619  //During secure renegotiation, the server must include a renegotiation_info
620  //extension containing the saved client_verify_data and server_verify_data
621  if(context->secureRenegoFlag)
622  {
623  TlsExtension *extension;
624  TlsRenegoInfo *renegoInfo;
625 
626  //Determine the length of the renegotiated_connection field
627  n = context->clientVerifyDataLen + context->serverVerifyDataLen;
628 
629  //Add the RenegotiationInfo extension
630  extension = (TlsExtension *) p;
631  //Type of the extension
632  extension->type = HTONS(TLS_EXT_RENEGOTIATION_INFO);
633 
634  //Point to the renegotiated_connection field
635  renegoInfo = (TlsRenegoInfo *) extension->value;
636  //Set the length of the verify data
637  renegoInfo->length = (uint8_t) n;
638 
639  //Copy the saved client_verify_data
640  osMemcpy(renegoInfo->value, context->clientVerifyData,
641  context->clientVerifyDataLen);
642 
643  //Copy the saved client_verify_data
644  osMemcpy(renegoInfo->value + context->clientVerifyDataLen,
645  context->serverVerifyData, context->serverVerifyDataLen);
646 
647  //Consider the length field that precedes the renegotiated_connection
648  //field
649  n += sizeof(TlsRenegoInfo);
650  //Fix the length of the extension
651  extension->length = htons(n);
652 
653  //Compute the length, in bytes, of the RenegotiationInfo extension
654  n += sizeof(TlsExtension);
655  }
656  }
657 #endif
658 
659  //Total number of bytes that have been written
660  *written = n;
661 
662  //Successful processing
663  return NO_ERROR;
664 }
665 
666 
667 /**
668  * @brief Parse SupportedVersions extension
669  * @param[in] context Pointer to the TLS context
670  * @param[in] supportedVersionList Pointer to the SupportedVersions extension
671  * @return Error code
672  **/
673 
675  const TlsSupportedVersionList *supportedVersionList)
676 {
677  error_t error;
678  uint_t i;
679  uint_t j;
680  uint_t n;
681 
682  //Supported TLS versions
683  const uint16_t supportedVersions[] =
684  {
689  };
690 
691  //Initialize status code
693 
694  //Retrieve the number of items in the list
695  n = supportedVersionList->length / sizeof(uint16_t);
696 
697  //Loop through the list of TLS versions supported by the server
698  for(i = 0; i < arraysize(supportedVersions) && error; i++)
699  {
700  //The extension contains a list of TLS versions supported by the client
701  for(j = 0; j < n && error; j++)
702  {
703  //Servers must only select a version of TLS present in that extension
704  //and must ignore any unknown versions
705  if(ntohs(supportedVersionList->value[j]) == supportedVersions[i])
706  {
707  //Set the TLS version to be used
708  error = tlsSelectVersion(context, supportedVersions[i]);
709  }
710  }
711  }
712 
713  //Return status code
714  return error;
715 }
716 
717 
718 /**
719  * @brief Parse SNI extension
720  * @param[in] context Pointer to the TLS context
721  * @param[in] serverNameList Pointer to the SNI extension
722  * @return Error code
723  **/
724 
726  const TlsServerNameList *serverNameList)
727 {
728 #if (TLS_SNI_SUPPORT == ENABLED)
729  //SNI extension found?
730  if(serverNameList != NULL)
731  {
732  size_t i;
733  size_t n;
734  size_t length;
735  const TlsServerName *serverName;
736 
737  //In order to provide the server name, clients may include ServerName
738  //extension
739  if(context->serverName != NULL)
740  {
741  //Release memory
742  tlsFreeMem(context->serverName);
743  context->serverName = NULL;
744  }
745 
746  //Retrieve the length of the list
747  length = ntohs(serverNameList->length);
748 
749  //Loop through the list of server names advertised by the client
750  for(i = 0; i < length; i += sizeof(TlsServerName) + n)
751  {
752  //Point to the current server name
753  serverName = (TlsServerName *) (serverNameList->value + i);
754 
755  //Malformed extension?
756  if(length < (i + sizeof(TlsServerName)))
757  return ERROR_DECODING_FAILED;
758  if(length < (i + sizeof(TlsServerName) + ntohs(serverName->length)))
759  return ERROR_DECODING_FAILED;
760 
761  //Retrieve the length of the server name
762  n = ntohs(serverName->length);
763 
764  //Empty strings must not be included in the list
765  if(n == 0)
766  return ERROR_DECODING_FAILED;
767 
768  //Currently, the only server names supported are DNS hostnames
769  if(serverName->type == TLS_NAME_TYPE_HOSTNAME)
770  {
771  //The server name must be a valid DNS hostname
772  if(!tlsCheckDnsHostname(serverName->hostname, n))
774 
775  //The ServerNameList must not contain more than one name of the
776  //same type (refer to RFC 6066, section 3)
777  if(context->serverName != NULL)
779 
780  //Check the length of the name
782  {
783  //Allocate a memory block to hold the server name
784  context->serverName = tlsAllocMem(n + 1);
785  //Failed to allocate memory?
786  if(context->serverName == NULL)
787  return ERROR_OUT_OF_MEMORY;
788 
789  //Save server name
790  osMemcpy(context->serverName, serverName->hostname, n);
791  //Properly terminate the string with a NULL character
792  context->serverName[n] = '\0';
793  }
794  }
795  }
796  }
797 #endif
798 
799  //Successful processing
800  return NO_ERROR;
801 }
802 
803 
804 /**
805  * @brief Parse MaxFragmentLength extension
806  * @param[in] context Pointer to the TLS context
807  * @param[in] maxFragLen Pointer to the MaxFragmentLength extension
808  * @return Error code
809  **/
810 
812  const TlsExtension *maxFragLen)
813 {
814  error_t error;
815 
816  //Initialize status code
817  error = NO_ERROR;
818 
819 #if (TLS_MAX_FRAG_LEN_SUPPORT == ENABLED)
820  //MaxFragmentLength extension found?
821  if(maxFragLen != NULL)
822  {
823  size_t n;
824 
825  //Retrieve the value advertised by the client
826  switch(maxFragLen->value[0])
827  {
829  n = 512;
830  break;
831 
833  n = 1024;
834  break;
835 
837  n = 2048;
838  break;
839 
841  n = 4096;
842  break;
843 
844  default:
845  n = 0;
846  break;
847  }
848 
849  //Acceptable value?
850  if(n > 0)
851  {
852  //Once a maximum fragment length has been successfully negotiated,
853  //the server must immediately begin fragmenting messages (including
854  //handshake messages) to ensure that no fragment larger than the
855  //negotiated length is sent
856  context->maxFragLen = n;
857  }
858  else
859  {
860  //If a server receives a maximum fragment length negotiation request
861  //for a value other than the allowed values, it must abort the handshake
862  //with an illegal_parameter alert
863  error = ERROR_ILLEGAL_PARAMETER;
864  }
865 
866  //The ClientHello includes a MaxFragmentLength extension
867  context->maxFragLenExtReceived = TRUE;
868  }
869  else
870  {
871  //The ClientHello does not contain any MaxFragmentLength extension
872  context->maxFragLenExtReceived = FALSE;
873  }
874 #endif
875 
876  //Return status code
877  return error;
878 }
879 
880 
881 /**
882  * @brief Parse RecordSizeLimit extension
883  * @param[in] context Pointer to the TLS context
884  * @param[in] recordSizeLimit Pointer to the RecordSizeLimit extension
885  * @return Error code
886  **/
887 
889  const TlsExtension *recordSizeLimit)
890 {
891 #if (TLS_RECORD_SIZE_LIMIT_SUPPORT == ENABLED)
892  //RecordSizeLimit extension found?
893  if(recordSizeLimit != NULL)
894  {
895  uint16_t n;
896 
897  //The value of RecordSizeLimit is the maximum size of record in octets
898  //that the peer is willing to receive
899  n = LOAD16BE(recordSizeLimit->value);
900 
901  //Endpoints must not send a RecordSizeLimit extension with a value
902  //smaller than 64
903  if(n < 64)
904  {
905  //An endpoint must treat receipt of a smaller value as a fatal error
906  //and generate an illegal_parameter alert
908  }
909 
910  //TLS 1.3 currently selected?
911  if(context->version == TLS_VERSION_1_3)
912  {
913  //The value includes the content type and padding added in TLS 1.3
914  n--;
915  }
916 
917  //Initial or updated ClientHello?
918  if(context->state == TLS_STATE_CLIENT_HELLO_3)
919  {
920  //When responding to a HelloRetryRequest, the client must send the
921  //same ClientHello without modification
922  if(!context->recordSizeLimitExtReceived ||
923  context->recordSizeLimit != n)
924  {
926  }
927  }
928 
929  //The peer can include any limit up to the protocol-defined limit for
930  //maximum record size. Even if a larger value is provided by a peer, an
931  //endpoint must not send records larger than the protocol-defined limit
932  context->recordSizeLimit = MIN(n, TLS_MAX_RECORD_LENGTH);
933 
934  //The ClientHello includes a RecordSizeLimit extension
935  context->recordSizeLimitExtReceived = TRUE;
936  }
937  else
938  {
939  //Initial or updated ClientHello?
940  if(context->state == TLS_STATE_CLIENT_HELLO_3)
941  {
942  //When responding to a HelloRetryRequest, the client must send the
943  //same ClientHello without modification
944  if(context->recordSizeLimitExtReceived)
946  }
947 
948  //If this extension is not negotiated, endpoints can send records of any
949  //size permitted by the protocol or other negotiated extensions
950  context->recordSizeLimit = TLS_MAX_RECORD_LENGTH;
951 
952  //The RecordSizeLimit extension is not supported by the client
953  context->recordSizeLimitExtReceived = FALSE;
954  }
955 #endif
956 
957  //Successful processing
958  return NO_ERROR;
959 }
960 
961 
962 /**
963  * @brief Parse EcPointFormats extension
964  * @param[in] context Pointer to the TLS context
965  * @param[in] ecPointFormatList Pointer to the EcPointFormats extension
966  * @return Error code
967  **/
968 
970  const TlsEcPointFormatList *ecPointFormatList)
971 {
972  error_t error;
973 
974 #if (TLS_MAX_VERSION >= TLS_VERSION_1_0 && TLS_MIN_VERSION <= TLS_VERSION_1_2)
975  //Initialize status code
976  error = NO_ERROR;
977 
978 #if (TLS_ECDH_ANON_KE_SUPPORT == ENABLED || TLS_ECDHE_RSA_KE_SUPPORT == ENABLED || \
979  TLS_ECDHE_ECDSA_KE_SUPPORT == ENABLED || TLS_ECDHE_PSK_KE_SUPPORT == ENABLED)
980  //EcPointFormats extension found?
981  if(ecPointFormatList != NULL)
982  {
983  uint_t i;
984 
985  //The ClientHello includes a EcPointFormats extension
986  context->ecPointFormatsExtReceived = TRUE;
987 
988  //Loop through the list of supported EC point formats
989  for(i = 0; i < ecPointFormatList->length; i++)
990  {
991  //Uncompressed point format?
992  if(ecPointFormatList->value[i] == TLS_EC_POINT_FORMAT_UNCOMPRESSED)
993  {
994  break;
995  }
996  }
997 
998  //The uncompressed point format must be supported by any TLS application
999  //that supports this extension (refer to RFC 4492, section 5.1)
1000  if(i >= ecPointFormatList->length)
1001  {
1002  //Report an error
1003  error = ERROR_ILLEGAL_PARAMETER;
1004  }
1005  }
1006  else
1007  {
1008  //If no SupportedPointsFormat extension is sent, the uncompressed format
1009  //has to be used
1010  context->ecPointFormatsExtReceived = FALSE;
1011  }
1012 #endif
1013 #else
1014  //Not implemented
1015  error = ERROR_NOT_IMPLEMENTED;
1016 #endif
1017 
1018  //Return status code
1019  return error;
1020 }
1021 
1022 
1023 /**
1024  * @brief Parse ALPN extension
1025  * @param[in] context Pointer to the TLS context
1026  * @param[in] protocolNameList Pointer to the ALPN extension
1027  * @return Error code
1028  **/
1029 
1031  const TlsProtocolNameList *protocolNameList)
1032 {
1033 #if (TLS_ALPN_SUPPORT == ENABLED)
1034  //The protocol identified in the ALPN extension type in the ServerHello
1035  //shall be definitive for the connection, until renegotiated (refer to
1036  //RFC 7301, section 3.2)
1037  if(context->selectedProtocol != NULL)
1038  {
1039  //Release memory
1040  tlsFreeMem(context->selectedProtocol);
1041  context->selectedProtocol = NULL;
1042  }
1043 
1044  //ALPN extension found?
1045  if(protocolNameList != NULL)
1046  {
1047  size_t i;
1048  size_t n;
1049  size_t length;
1050  const TlsProtocolName *protocolName;
1051 
1052  //Retrieve the length of the list
1053  length = ntohs(protocolNameList->length);
1054 
1055  //The list must not be be empty
1056  if(length == 0)
1057  return ERROR_DECODING_FAILED;
1058 
1059  //Loop through the list of protocols advertised by the client
1060  for(i = 0; i < length; i += sizeof(TlsProtocolName) + n)
1061  {
1062  //Point to the current protocol
1063  protocolName = (TlsProtocolName *) (protocolNameList->value + i);
1064 
1065  //Malformed extension?
1066  if(length < (i + sizeof(TlsProtocolName)))
1067  return ERROR_DECODING_FAILED;
1068  if(length < (i + sizeof(TlsProtocolName) + protocolName->length))
1069  return ERROR_DECODING_FAILED;
1070 
1071  //Retrieve the length of the protocol name
1072  n = protocolName->length;
1073 
1074  //Empty strings must not be included in the list
1075  if(n == 0)
1076  return ERROR_DECODING_FAILED;
1077 
1078  //Check whether the protocol is supported by the server
1079  if(tlsIsAlpnProtocolSupported(context, protocolName->value, n))
1080  {
1081  //Select the current protocol
1082  if(context->selectedProtocol == NULL)
1083  {
1084  //Allocate a memory block to hold the protocol name
1085  context->selectedProtocol = tlsAllocMem(n + 1);
1086  //Failed to allocate memory?
1087  if(context->selectedProtocol == NULL)
1088  return ERROR_OUT_OF_MEMORY;
1089 
1090  //Save protocol name
1091  osMemcpy(context->selectedProtocol, protocolName->value, n);
1092  //Properly terminate the string with a NULL character
1093  context->selectedProtocol[n] = '\0';
1094  }
1095  }
1096  }
1097 
1098  //ALPN protocol selection failed?
1099  if(context->protocolList != NULL && context->selectedProtocol == NULL)
1100  {
1101  //Report an error if unknown ALPN protocols are disallowed
1102  if(!context->unknownProtocolsAllowed)
1103  {
1104  //In the event that the server supports no protocols that the
1105  //client advertises, then the server shall respond with a fatal
1106  //no_application_protocol alert
1108  }
1109  }
1110  }
1111 
1112  //Any registered callback?
1113  if(context->alpnCallback != NULL)
1114  {
1115  //Invoke user callback function
1116  return context->alpnCallback(context, context->selectedProtocol);
1117  }
1118 #endif
1119 
1120  //Successful processing
1121  return NO_ERROR;
1122 }
1123 
1124 
1125 /**
1126  * @brief Parse ClientCertType extension
1127  * @param[in] context Pointer to the TLS context
1128  * @param[in] clientCertTypeList Pointer to the ClientCertType extension
1129  * @return Error code
1130  **/
1131 
1133  const TlsCertTypeList *clientCertTypeList)
1134 {
1135  error_t error;
1136 
1137  //Initialize status code
1138  error = NO_ERROR;
1139 
1140 #if (TLS_RAW_PUBLIC_KEY_SUPPORT == ENABLED)
1141  //ClientCertType extension found?
1142  if(clientCertTypeList != NULL)
1143  {
1144  //If the server does not send any CertificateRequest message, then the
1145  //ClientCertType extension in the ServerHello must be omitted
1146  if(context->clientAuthMode != TLS_CLIENT_AUTH_NONE)
1147  {
1148  uint_t i;
1149 
1150  //The ClientCertType extension carries a list of supported certificate
1151  //types, sorted by client preference
1152  for(i = 0; i < clientCertTypeList->length; i++)
1153  {
1154  //Check certificate type
1155  if(clientCertTypeList->value[i] == TLS_CERT_FORMAT_X509)
1156  {
1157  //Select X.509 certificate format
1158  context->peerCertFormat = TLS_CERT_FORMAT_X509;
1159  //Exit immediately
1160  break;
1161  }
1162  else if(clientCertTypeList->value[i] == TLS_CERT_FORMAT_RAW_PUBLIC_KEY)
1163  {
1164  //Ensure the server is able to process raw public keys
1165  if(context->rpkVerifyCallback != NULL)
1166  {
1167  //Select raw public key format
1168  context->peerCertFormat = TLS_CERT_FORMAT_RAW_PUBLIC_KEY;
1169  //Exit immediately
1170  break;
1171  }
1172  }
1173  else
1174  {
1175  //Unsupported certificate type
1176  }
1177  }
1178 
1179  //If the server does not have any certificate type in common with the
1180  //client, then the server terminates the session with a fatal alert
1181  if(i >= clientCertTypeList->length)
1182  {
1183  //Report an error
1185  }
1186 
1187  //The ClientHello includes a ClientCertType extension
1188  context->clientCertTypeExtReceived = TRUE;
1189  }
1190  }
1191  else
1192  {
1193  //The ClientHello does not contain any ClientCertType extension
1194  context->clientCertTypeExtReceived = FALSE;
1195  //Select default certificate format
1196  context->peerCertFormat = TLS_CERT_FORMAT_X509;
1197  }
1198 #endif
1199 
1200  //Return status code
1201  return error;
1202 }
1203 
1204 
1205 /**
1206  * @brief Parse ServerCertType extension
1207  * @param[in] context Pointer to the TLS context
1208  * @param[in] serverCertTypeList Pointer to the ServerCertType extension
1209  * @return Error code
1210  **/
1211 
1213  const TlsCertTypeList *serverCertTypeList)
1214 {
1215  error_t error;
1216 
1217  //Initialize status code
1218  error = NO_ERROR;
1219 
1220 #if (TLS_RAW_PUBLIC_KEY_SUPPORT == ENABLED)
1221  //ServerCertType extension found?
1222  if(serverCertTypeList != NULL)
1223  {
1224  uint_t i;
1225 
1226  //The ServerCertType extension carries a list of supported certificate
1227  //types, sorted by client preference
1228  for(i = 0; i < serverCertTypeList->length; i++)
1229  {
1230  //Check certificate type
1231  if(serverCertTypeList->value[i] == TLS_CERT_FORMAT_X509 ||
1232  serverCertTypeList->value[i] == TLS_CERT_FORMAT_RAW_PUBLIC_KEY)
1233  {
1234  //The certificate type is selected from one of the values provided
1235  //by the client
1236  context->certFormat = (TlsCertificateFormat) serverCertTypeList->value[i];
1237 
1238  //We are done
1239  break;
1240  }
1241  }
1242 
1243  //If the server does not have any certificate type in common with the
1244  //client, then the server terminates the session with a fatal alert
1245  if(i >= serverCertTypeList->length)
1246  {
1247  //Report an error
1249  }
1250 
1251  //The ClientHello includes a ServerCertType extension
1252  context->serverCertTypeExtReceived = TRUE;
1253  }
1254  else
1255  {
1256  //The ClientHello does not contain any ServerCertType extension
1257  context->serverCertTypeExtReceived = FALSE;
1258  //Select default certificate format
1259  context->certFormat = TLS_CERT_FORMAT_X509;
1260  }
1261 #endif
1262 
1263  //Return status code
1264  return error;
1265 }
1266 
1267 
1268 /**
1269  * @brief Parse EncryptThenMac extension
1270  * @param[in] context Pointer to the TLS context
1271  * @param[in] encryptThenMac Pointer to the EncryptThenMac extension
1272  * @return Error code
1273  **/
1274 
1276  const TlsExtension *encryptThenMac)
1277 {
1278 #if (TLS_ENCRYPT_THEN_MAC_SUPPORT == ENABLED)
1279  //EncryptThenMac extension found?
1280  if(encryptThenMac != NULL)
1281  {
1282  //CBC cipher suite?
1283  if(context->cipherSuite.cipherMode == CIPHER_MODE_CBC)
1284  {
1285  //Use encrypt-then-MAC construction rather than the default
1286  //MAC-then-encrypt
1287  context->etmExtReceived = TRUE;
1288  }
1289  else
1290  {
1291  //If a server receives an encrypt-then-MAC request extension from a
1292  //client and then selects a stream or AEAD ciphersuite, it must not
1293  //send an encrypt-then-MAC response extension back to the client (refer
1294  //to RFC 7366, section 3)
1295  context->etmExtReceived = FALSE;
1296  }
1297  }
1298  else
1299  {
1300  //Use default MAC-then-encrypt construction
1301  context->etmExtReceived = FALSE;
1302  }
1303 #endif
1304 
1305  //Successful processing
1306  return NO_ERROR;
1307 }
1308 
1309 
1310 /**
1311  * @brief Parse ExtendedMasterSecret extension
1312  * @param[in] context Pointer to the TLS context
1313  * @param[in] extendedMasterSecret Pointer to the ExtendedMasterSecret extension
1314  * @return Error code
1315  **/
1316 
1319 {
1320  error_t error;
1321 
1322  //Initialize status code
1323  error = NO_ERROR;
1324 
1325 #if (TLS_EXT_MASTER_SECRET_SUPPORT == ENABLED)
1326  //ExtendedMasterSecret extension found?
1327  if(extendedMasterSecret != NULL)
1328  {
1329  //Use the extended master secret computation
1330  context->emsExtReceived = TRUE;
1331  }
1332  else
1333  {
1334  //Abbreviated handshake?
1335  if(context->resume)
1336  {
1337  //If the original session used the ExtendedMasterSecret extension but
1338  //the new ClientHello does not contain it, the server must abort the
1339  //abbreviated handshake
1340  if(context->emsExtReceived)
1341  {
1342  //Report an error
1343  error = ERROR_HANDSHAKE_FAILED;
1344  }
1345  }
1346 
1347  //If the client and server choose to continue a full handshake without
1348  //the extension, they must use the standard master secret derivation
1349  //for the new session
1350  context->emsExtReceived = FALSE;
1351  }
1352 #endif
1353 
1354  //Return status code
1355  return error;
1356 }
1357 
1358 
1359 /**
1360  * @brief Parse SessionTicket extension
1361  * @param[in] context Pointer to the TLS context
1362  * @param[in] sessionTicket Pointer to the SessionTicket extension
1363  * @return Error code
1364  **/
1365 
1367  const TlsExtension *sessionTicket)
1368 {
1369 #if (TLS_TICKET_SUPPORT == ENABLED)
1370  //Clear flags
1371  context->sessionTicketExtReceived = FALSE;
1372  context->sessionTicketExtSent = FALSE;
1373 
1374  //SessionTicket extension found?
1375  if(sessionTicket != NULL)
1376  {
1377  //Check whether session ticket mechanism is enabled
1378  if(context->sessionTicketEnabled &&
1379  context->ticketEncryptCallback != NULL &&
1380  context->ticketDecryptCallback != NULL)
1381  {
1382  //The ClientHello includes a SessionTicket extension
1383  context->sessionTicketExtReceived = TRUE;
1384  }
1385  }
1386 #endif
1387 
1388  //Successful processing
1389  return NO_ERROR;
1390 }
1391 
1392 
1393 /**
1394  * @brief Parse RenegotiationInfo extension
1395  * @param[in] context Pointer to the TLS context
1396  * @param[in] extensions ClientHello extensions offered by the client
1397  * @return Error code
1398  **/
1399 
1402 {
1403  error_t error;
1404 
1405  //Initialize status code
1406  error = NO_ERROR;
1407 
1408 #if (TLS_SECURE_RENEGOTIATION_SUPPORT == ENABLED)
1409  //RenegotiationInfo extension found?
1410  if(extensions->renegoInfo != NULL)
1411  {
1412  //Initial handshake?
1413  if(context->clientVerifyDataLen == 0)
1414  {
1415  //Set the secure_renegotiation flag to TRUE
1416  context->secureRenegoFlag = TRUE;
1417 
1418  //The server must then verify that the length of the
1419  //renegotiated_connection field is zero
1420  if(extensions->renegoInfo->length != 0)
1421  {
1422  //If it is not, the server must abort the handshake
1423  error = ERROR_HANDSHAKE_FAILED;
1424  }
1425  }
1426  //Secure renegotiation?
1427  else
1428  {
1429  //Check the length of the renegotiated_connection field
1430  if(extensions->renegoInfo->length != context->clientVerifyDataLen)
1431  {
1432  //The server must abort the handshake
1433  error = ERROR_HANDSHAKE_FAILED;
1434  }
1435  else
1436  {
1437  //Verify that the value of the renegotiated_connection field is
1438  //equal to the saved client_verify_data value
1439  if(osMemcmp(extensions->renegoInfo->value,
1440  context->clientVerifyData, context->clientVerifyDataLen))
1441  {
1442  //If it is not, the server must abort the handshake
1443  error = ERROR_HANDSHAKE_FAILED;
1444  }
1445  }
1446 
1447 #if (TLS_ENCRYPT_THEN_MAC_SUPPORT == ENABLED)
1448  //Implementations must not renegotiate a downgrade from
1449  //encrypt-then-MAC to MAC-then-encrypt (refer to RFC 7366, section 3.1)
1450  if(extensions->encryptThenMac == NULL && context->etmExtReceived)
1451  {
1452  error = ERROR_HANDSHAKE_FAILED;
1453  }
1454 #endif
1455 
1456 #if (TLS_EXT_MASTER_SECRET_SUPPORT == ENABLED)
1457  //ExtendedMasterSecret extension found?
1458  if(extensions->extendedMasterSecret != NULL)
1459  {
1460  //If the initial handshake did not use the ExtendedMasterSecret
1461  //extension but the new ClientHello contains the extension, the
1462  //server must abort the handshake
1463  if(!context->emsExtReceived)
1464  {
1465  error = ERROR_HANDSHAKE_FAILED;
1466  }
1467  }
1468  else
1469  {
1470  //If the initial handshake used the ExtendedMasterSecret extension
1471  //but the new ClientHello does not contain the extension, the
1472  //server must abort the handshake
1473  if(context->emsExtReceived)
1474  {
1475  error = ERROR_HANDSHAKE_FAILED;
1476  }
1477  }
1478 #endif
1479  }
1480  }
1481  else
1482  {
1483  //Secure renegotiation?
1484  if(context->clientVerifyDataLen != 0 || context->serverVerifyDataLen != 0)
1485  {
1486  //The server must verify that the renegotiation_info extension is
1487  //present. If it is not, the server must abort the handshake
1488  error = ERROR_HANDSHAKE_FAILED;
1489  }
1490  }
1491 #endif
1492 
1493  //Return status code
1494  return error;
1495 }
1496 
1497 #endif
error_t tlsFormatServerSessionTicketExtension(TlsContext *context, uint8_t *p, size_t *written)
Format SessionTicket extension.
#define TLS_MAX_RECORD_LENGTH
Definition: tls.h:977
#define tlsAllocMem(size)
Definition: tls.h:888
@ TLS_EXT_MAX_FRAGMENT_LENGTH
Definition: tls.h:1351
#define htons(value)
Definition: cpu_endian.h:413
Parsing and checking of TLS extensions.
error_t tlsFormatServerEmsExtension(TlsContext *context, uint8_t *p, size_t *written)
Format ExtendedMasterSecret extension.
@ TLS_CERT_FORMAT_RAW_PUBLIC_KEY
Definition: tls.h:1223
TLS helper functions.
TlsServerName
Definition: tls.h:1729
uint8_t extensions[]
Definition: ntp_common.h:213
error_t tlsParseClientMaxFragLenExtension(TlsContext *context, const TlsExtension *maxFragLen)
Parse MaxFragmentLength extension.
TLS cipher suites.
error_t tlsParseClientSupportedVersionsExtension(TlsContext *context, const TlsSupportedVersionList *supportedVersionList)
Parse SupportedVersions extension.
@ CIPHER_MODE_CBC
Definition: crypto.h:1063
@ TLS13_KEY_EXCH_PSK_DHE
Definition: tls.h:1208
error_t tlsParseClientEcPointFormatsExtension(TlsContext *context, const TlsEcPointFormatList *ecPointFormatList)
Parse EcPointFormats extension.
@ ERROR_VERSION_NOT_SUPPORTED
Definition: error.h:67
@ ERROR_NOT_IMPLEMENTED
Definition: error.h:66
@ ERROR_ILLEGAL_PARAMETER
Definition: error.h:244
uint8_t p
Definition: ndp.h:300
error_t tlsParseServerCertTypeListExtension(TlsContext *context, const TlsCertTypeList *serverCertTypeList)
Parse ServerCertType extension.
error_t tlsSelectVersion(TlsContext *context, uint16_t version)
Set the TLS version to be used.
Definition: tls_misc.c:305
#define TRUE
Definition: os_port.h:50
error_t tlsFormatServerRenegoInfoExtension(TlsContext *context, uint8_t *p, size_t *written)
Format RenegotiationInfo extension.
bool_t tlsIsAlpnProtocolSupported(TlsContext *context, const char_t *protocol, size_t length)
Check whether the specified ALPN protocol is supported.
TlsEcPointFormatList
Definition: tls.h:1784
TlsRenegoInfo
Definition: tls.h:1806
@ TLS13_KEY_EXCH_PSK_MLKEM
Definition: tls.h:1210
#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_UNSUPPORTED_CERTIFICATE
Definition: error.h:237
#define osStrlen(s)
Definition: os_port.h:168
TlsProtocolNameList
Definition: tls.h:1762
error_t tlsParseClientCertTypeListExtension(TlsContext *context, const TlsCertTypeList *clientCertTypeList)
Parse ClientCertType extension.
TlsExtension
Definition: tls.h:1695
@ TLS_EXT_SESSION_TICKET
Definition: tls.h:1383
error_t tlsFormatServerSniExtension(TlsContext *context, uint8_t *p, size_t *written)
Format SNI extension.
@ TLS13_KEY_EXCH_PSK_HYBRID
Definition: tls.h:1211
@ TLS_MAX_FRAGMENT_LENGTH_4096
Definition: tls.h:1428
bool_t extendedMasterSecret
Extended master secret computation.
Definition: tls.h:2010
@ TLS_EXT_SERVER_NAME
Definition: tls.h:1350
#define FALSE
Definition: os_port.h:46
error_t tlsFormatServerRecordSizeLimitExtension(TlsContext *context, uint8_t *p, size_t *written)
Format RecordSizeLimit extension.
#define osMemcpy(dest, src, length)
Definition: os_port.h:144
error_t tlsParseClientSessionTicketExtension(TlsContext *context, const TlsExtension *sessionTicket)
Parse SessionTicket extension.
TlsCertificateFormat
Certificate formats.
Definition: tls.h:1220
@ TLS_EXT_CLIENT_CERT_TYPE
Definition: tls.h:1369
#define TlsContext
Definition: tls.h:36
error_t
Error codes.
Definition: error.h:43
@ TLS_EXT_EXTENDED_MASTER_SECRET
Definition: tls.h:1373
error_t tlsParseClientEtmExtension(TlsContext *context, const TlsExtension *encryptThenMac)
Parse EncryptThenMac extension.
#define TLS_VERSION_1_2
Definition: tls.h:96
@ TLS_EXT_RENEGOTIATION_INFO
Definition: tls.h:1405
#define STORE16BE(a, p)
Definition: cpu_endian.h:262
@ TLS_EXT_ENCRYPT_THEN_MAC
Definition: tls.h:1372
@ TLS_CIPHER_SUITE_TYPE_ECDH
error_t tlsFormatClientCertTypeExtension(TlsContext *context, uint8_t *p, size_t *written)
Format ClientCertType extension.
bool_t tlsCheckDnsHostname(const char_t *name, size_t length)
DNS hostname verification.
Definition: tls_misc.c:1737
#define TLS_VERSION_1_3
Definition: tls.h:97
TlsServerNameList
Definition: tls.h:1740
@ TLS_MAX_FRAGMENT_LENGTH_2048
Definition: tls.h:1427
TlsProtocolName
Definition: tls.h:1751
@ TLS_EC_POINT_FORMAT_UNCOMPRESSED
Definition: tls.h:1517
error_t tlsParseClientAlpnExtension(TlsContext *context, const TlsProtocolNameList *protocolNameList)
Parse ALPN extension.
uint8_t length
Definition: tcp.h:375
@ TLS_CLIENT_AUTH_NONE
Definition: tls.h:1023
#define MIN(a, b)
Definition: os_port.h:63
@ TLS_EXT_EC_POINT_FORMATS
Definition: tls.h:1361
@ TLS_EXT_ALPN
Definition: tls.h:1366
error_t tlsFormatServerMaxFragLenExtension(TlsContext *context, uint8_t *p, size_t *written)
Format MaxFragmentLength extension.
Hello extensions.
Definition: tls.h:2257
#define ntohs(value)
Definition: cpu_endian.h:421
#define TLS_VERSION_1_1
Definition: tls.h:95
@ TLS13_KEY_EXCH_PSK_ECDHE
Definition: tls.h:1209
@ ERROR_NO_APPLICATION_PROTOCOL
Definition: error.h:248
#define HTONS(value)
Definition: cpu_endian.h:410
uint8_t n
error_t tlsFormatServerEcPointFormatsExtension(TlsContext *context, uint8_t *p, size_t *written)
Format EcPointFormats extension.
error_t tlsParseClientRecordSizeLimitExtension(TlsContext *context, const TlsExtension *recordSizeLimit)
Parse RecordSizeLimit extension.
#define TLS_VERSION_1_0
Definition: tls.h:94
@ TLS_EXT_SERVER_CERT_TYPE
Definition: tls.h:1370
@ TLS_NAME_TYPE_HOSTNAME
Definition: tls.h:1415
@ TLS_MAX_FRAGMENT_LENGTH_1024
Definition: tls.h:1426
TLS (Transport Layer Security)
error_t tlsParseClientSniExtension(TlsContext *context, const TlsServerNameList *serverNameList)
Parse SNI extension.
@ TLS_STATE_CLIENT_HELLO_3
Definition: tls.h:1544
Formatting and parsing of extensions (TLS server)
#define TLS_MAX_SERVER_NAME_LEN
Definition: tls.h:780
@ ERROR_DECODING_FAILED
Definition: error.h:242
error_t tlsFormatServerCertTypeExtension(TlsContext *context, uint8_t *p, size_t *written)
Format ServerCertType extension.
unsigned int uint_t
Definition: compiler_port.h:57
#define LOAD16BE(p)
Definition: cpu_endian.h:186
#define tlsFreeMem(p)
Definition: tls.h:893
TlsSupportedVersionList
Definition: tls.h:1717
error_t tlsFormatServerAlpnExtension(TlsContext *context, uint8_t *p, size_t *written)
Format ALPN extension.
error_t tlsParseClientRenegoInfoExtension(TlsContext *context, const TlsHelloExtensions *extensions)
Parse RenegotiationInfo extension.
TlsCertTypeList
Definition: tls.h:1795
@ NO_ERROR
Success.
Definition: error.h:44
@ TLS_EXT_RECORD_SIZE_LIMIT
Definition: tls.h:1377
Debugging facilities.
@ TLS_CERT_FORMAT_X509
Definition: tls.h:1221
error_t tlsFormatServerEtmExtension(TlsContext *context, uint8_t *p, size_t *written)
Format EncryptThenMac extension.
@ TLS_MAX_FRAGMENT_LENGTH_512
Definition: tls.h:1425
#define arraysize(a)
Definition: os_port.h:71
error_t tlsParseClientEmsExtension(TlsContext *context, const TlsExtension *extendedMasterSecret)
Parse ExtendedMasterSecret extension.