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