Mbed TLS v3.6.4
ssl.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright The Mbed TLS Contributors
8  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9  */
10 #ifndef MBEDTLS_SSL_H
11 #define MBEDTLS_SSL_H
12 #include "mbedtls/platform_util.h"
13 #include "mbedtls/private_access.h"
14 
15 #include "mbedtls/build_info.h"
16 
17 #include "mbedtls/bignum.h"
18 #include "mbedtls/ecp.h"
19 
21 
22 #if defined(MBEDTLS_X509_CRT_PARSE_C)
23 #include "mbedtls/x509_crt.h"
24 #include "mbedtls/x509_crl.h"
25 #endif
26 
27 #if defined(MBEDTLS_DHM_C)
28 #include "mbedtls/dhm.h"
29 #endif
30 
31 #include "mbedtls/md.h"
32 
33 #if defined(MBEDTLS_KEY_EXCHANGE_SOME_ECDH_OR_ECDHE_ANY_ENABLED)
34 #include "mbedtls/ecdh.h"
35 #endif
36 
37 #if defined(MBEDTLS_HAVE_TIME)
38 #include "mbedtls/platform_time.h"
39 #endif
40 
41 #include "psa/crypto.h"
42 
43 /*
44  * SSL Error codes
45  */
47 #define MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS -0x7000
48 
49 #define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080
50 
51 #define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100
52 
53 #define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180
54 
55 #define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200
56 
57 #define MBEDTLS_ERR_SSL_CONN_EOF -0x7280
58 
59 #define MBEDTLS_ERR_SSL_DECODE_ERROR -0x7300
60 /* Error space gap */
62 #define MBEDTLS_ERR_SSL_NO_RNG -0x7400
63 
64 #define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480
65 
66 #define MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION -0x7500
67 
68 #define MBEDTLS_ERR_SSL_NO_APPLICATION_PROTOCOL -0x7580
69 
70 #define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600
71 
72 #define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680
73 
74 #define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700
75 
76 #define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780
77 
78 #define MBEDTLS_ERR_SSL_UNRECOGNIZED_NAME -0x7800
79 
80 #define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880
81 /* Error space gap */
82 /* Error space gap */
84 #define MBEDTLS_ERR_SSL_BAD_CERTIFICATE -0x7A00
85 /* Error space gap */
87 #define MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET -0x7B00
88 
89 #define MBEDTLS_ERR_SSL_CANNOT_READ_EARLY_DATA -0x7B80
90 
99 #define MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA -0x7C00
100 
101 #define MBEDTLS_ERR_SSL_CANNOT_WRITE_EARLY_DATA -0x7C80
102 /* Error space gap */
103 /* Error space gap */
104 /* Error space gap */
105 /* Error space gap */
107 #define MBEDTLS_ERR_SSL_CACHE_ENTRY_NOT_FOUND -0x7E80
108 
109 #define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00
110 
111 #define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80
112 
113 #define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80
114 
115 #define MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION -0x6E80
116 
117 #define MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE -0x6E00
118 
119 #define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80
120 
121 #define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00
122 
123 #define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80
124 
125 #define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00
126 
127 #define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80
128 
129 #define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00
130 
131 #define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80
132 
133 #define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00
134 /* Error space gap */
136 #define MBEDTLS_ERR_SSL_WANT_READ -0x6900
137 
138 #define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880
139 
140 #define MBEDTLS_ERR_SSL_TIMEOUT -0x6800
141 
142 #define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780
143 
144 #define MBEDTLS_ERR_SSL_UNEXPECTED_RECORD -0x6700
145 
146 #define MBEDTLS_ERR_SSL_NON_FATAL -0x6680
147 
148 #define MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER -0x6600
149 
150 #define MBEDTLS_ERR_SSL_CONTINUE_PROCESSING -0x6580
151 
152 #define MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS -0x6500
153 
154 #define MBEDTLS_ERR_SSL_EARLY_MESSAGE -0x6480
155 /* Error space gap */
156 /* Error space gap */
157 /* Error space gap */
158 /* Error space gap */
159 /* Error space gap */
160 /* Error space gap */
161 /* Error space gap */
162 /* Error space gap */
164 #define MBEDTLS_ERR_SSL_UNEXPECTED_CID -0x6000
165 
166 #define MBEDTLS_ERR_SSL_VERSION_MISMATCH -0x5F00
167 
168 #define MBEDTLS_ERR_SSL_BAD_CONFIG -0x5E80
169 /* Error space gap */
204 #define MBEDTLS_ERR_SSL_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME -0x5D80
205 
206 /*
207  * Constants from RFC 8446 for TLS 1.3 PSK modes
208  *
209  * Those are used in the Pre-Shared Key Exchange Modes extension.
210  * See Section 4.2.9 in RFC 8446.
211  */
212 #define MBEDTLS_SSL_TLS1_3_PSK_MODE_PURE 0 /* Pure PSK-based exchange */
213 #define MBEDTLS_SSL_TLS1_3_PSK_MODE_ECDHE 1 /* PSK+ECDHE-based exchange */
214 
215 /*
216  * TLS 1.3 NamedGroup values
217  *
218  * From RF 8446
219  * enum {
220  * // Elliptic Curve Groups (ECDHE)
221  * secp256r1(0x0017), secp384r1(0x0018), secp521r1(0x0019),
222  * x25519(0x001D), x448(0x001E),
223  * // Finite Field Groups (DHE)
224  * ffdhe2048(0x0100), ffdhe3072(0x0101), ffdhe4096(0x0102),
225  * ffdhe6144(0x0103), ffdhe8192(0x0104),
226  * // Reserved Code Points
227  * ffdhe_private_use(0x01FC..0x01FF),
228  * ecdhe_private_use(0xFE00..0xFEFF),
229  * (0xFFFF)
230  * } NamedGroup;
231  *
232  */
233 
234 /* Elliptic Curve Groups (ECDHE) */
235 #define MBEDTLS_SSL_IANA_TLS_GROUP_NONE 0
236 #define MBEDTLS_SSL_IANA_TLS_GROUP_SECP192K1 0x0012
237 #define MBEDTLS_SSL_IANA_TLS_GROUP_SECP192R1 0x0013
238 #define MBEDTLS_SSL_IANA_TLS_GROUP_SECP224K1 0x0014
239 #define MBEDTLS_SSL_IANA_TLS_GROUP_SECP224R1 0x0015
240 #define MBEDTLS_SSL_IANA_TLS_GROUP_SECP256K1 0x0016
241 #define MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1 0x0017
242 #define MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1 0x0018
243 #define MBEDTLS_SSL_IANA_TLS_GROUP_SECP521R1 0x0019
244 #define MBEDTLS_SSL_IANA_TLS_GROUP_BP256R1 0x001A
245 #define MBEDTLS_SSL_IANA_TLS_GROUP_BP384R1 0x001B
246 #define MBEDTLS_SSL_IANA_TLS_GROUP_BP512R1 0x001C
247 #define MBEDTLS_SSL_IANA_TLS_GROUP_X25519 0x001D
248 #define MBEDTLS_SSL_IANA_TLS_GROUP_X448 0x001E
249 /* Finite Field Groups (DHE) */
250 #define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE2048 0x0100
251 #define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE3072 0x0101
252 #define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE4096 0x0102
253 #define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE6144 0x0103
254 #define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE8192 0x0104
255 
256 /*
257  * TLS 1.3 Key Exchange Modes
258  *
259  * Mbed TLS internal identifiers for use with the SSL configuration API
260  * mbedtls_ssl_conf_tls13_key_exchange_modes().
261  */
262 
263 #define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK (1u << 0)
266 #define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL (1u << 1)
269 #define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL (1u << 2)
273 /* Convenience macros for sets of key exchanges. */
274 #define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_ALL \
275  (MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK | \
276  MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL | \
277  MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL)
278 #define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ALL \
279  (MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK | \
280  MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL)
281 #define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ALL \
282  (MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL | \
283  MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL)
285 #define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_NONE (0)
286 
287 /*
288  * Various constants
289  */
290 
291 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
292 /* These are the high and low bytes of ProtocolVersion as defined by:
293  * - RFC 5246: ProtocolVersion version = { 3, 3 }; // TLS v1.2
294  * - RFC 8446: see section 4.2.1
295  */
296 #define MBEDTLS_SSL_MAJOR_VERSION_3 3
297 #define MBEDTLS_SSL_MINOR_VERSION_3 3
298 #define MBEDTLS_SSL_MINOR_VERSION_4 4
299 #endif /* MBEDTLS_DEPRECATED_REMOVED */
300 
301 #define MBEDTLS_SSL_TRANSPORT_STREAM 0
302 #define MBEDTLS_SSL_TRANSPORT_DATAGRAM 1
304 #define MBEDTLS_SSL_MAX_HOST_NAME_LEN 255
305 #define MBEDTLS_SSL_MAX_ALPN_NAME_LEN 255
307 #define MBEDTLS_SSL_MAX_ALPN_LIST_LEN 65535
309 /* RFC 6066 section 4, see also mfl_code_to_length in ssl_tls.c
310  * NONE must be zero so that memset()ing structure to zero works */
311 #define MBEDTLS_SSL_MAX_FRAG_LEN_NONE 0
312 #define MBEDTLS_SSL_MAX_FRAG_LEN_512 1
313 #define MBEDTLS_SSL_MAX_FRAG_LEN_1024 2
314 #define MBEDTLS_SSL_MAX_FRAG_LEN_2048 3
315 #define MBEDTLS_SSL_MAX_FRAG_LEN_4096 4
316 #define MBEDTLS_SSL_MAX_FRAG_LEN_INVALID 5
318 #define MBEDTLS_SSL_IS_CLIENT 0
319 #define MBEDTLS_SSL_IS_SERVER 1
321 #define MBEDTLS_SSL_EXTENDED_MS_DISABLED 0
322 #define MBEDTLS_SSL_EXTENDED_MS_ENABLED 1
323 
324 #define MBEDTLS_SSL_CID_DISABLED 0
325 #define MBEDTLS_SSL_CID_ENABLED 1
326 
327 #define MBEDTLS_SSL_ETM_DISABLED 0
328 #define MBEDTLS_SSL_ETM_ENABLED 1
329 
330 #define MBEDTLS_SSL_COMPRESS_NULL 0
332 #define MBEDTLS_SSL_VERIFY_NONE 0
333 #define MBEDTLS_SSL_VERIFY_OPTIONAL 1
334 #define MBEDTLS_SSL_VERIFY_REQUIRED 2
335 #define MBEDTLS_SSL_VERIFY_UNSET 3 /* Used only for sni_authmode */
337 #define MBEDTLS_SSL_LEGACY_RENEGOTIATION 0
338 #define MBEDTLS_SSL_SECURE_RENEGOTIATION 1
340 #define MBEDTLS_SSL_RENEGOTIATION_DISABLED 0
341 #define MBEDTLS_SSL_RENEGOTIATION_ENABLED 1
342 
343 #define MBEDTLS_SSL_ANTI_REPLAY_DISABLED 0
344 #define MBEDTLS_SSL_ANTI_REPLAY_ENABLED 1
345 
346 #define MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED -1
347 #define MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT 16
348 
349 #define MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION 0
350 #define MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION 1
351 #define MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE 2
353 #define MBEDTLS_SSL_TRUNC_HMAC_DISABLED 0
354 #define MBEDTLS_SSL_TRUNC_HMAC_ENABLED 1
355 #define MBEDTLS_SSL_TRUNCATED_HMAC_LEN 10 /* 80 bits, rfc 6066 section 7 */
357 #define MBEDTLS_SSL_SESSION_TICKETS_DISABLED 0
358 #define MBEDTLS_SSL_SESSION_TICKETS_ENABLED 1
360 #define MBEDTLS_SSL_TLS1_3_SIGNAL_NEW_SESSION_TICKETS_DISABLED 0
361 #define MBEDTLS_SSL_TLS1_3_SIGNAL_NEW_SESSION_TICKETS_ENABLED 1
362 
363 #define MBEDTLS_SSL_PRESET_DEFAULT 0
364 #define MBEDTLS_SSL_PRESET_SUITEB 2
365 
366 #define MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED 1
367 #define MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED 0
368 
369 #define MBEDTLS_SSL_EARLY_DATA_DISABLED 0
370 #define MBEDTLS_SSL_EARLY_DATA_ENABLED 1
371 
372 #define MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED 0
373 #define MBEDTLS_SSL_DTLS_SRTP_MKI_SUPPORTED 1
374 
375 #define MBEDTLS_SSL_SRV_CIPHERSUITE_ORDER_CLIENT 1
376 #define MBEDTLS_SSL_SRV_CIPHERSUITE_ORDER_SERVER 0
377 
378 #if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS)
379 #if defined(PSA_WANT_ALG_SHA_384)
380 #define MBEDTLS_SSL_TLS1_3_TICKET_RESUMPTION_KEY_LEN 48
381 #elif defined(PSA_WANT_ALG_SHA_256)
382 #define MBEDTLS_SSL_TLS1_3_TICKET_RESUMPTION_KEY_LEN 32
383 #endif
384 #endif /* MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_SESSION_TICKETS */
385 /*
386  * Default range for DTLS retransmission timer value, in milliseconds.
387  * RFC 6347 4.2.4.1 says from 1 second to 60 seconds.
388  */
389 #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN 1000
390 #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX 60000
391 
392 /*
393  * Whether early data record should be discarded or not and how.
394  *
395  * The client has indicated early data and the server has rejected them.
396  * The server has then to skip past early data by either:
397  * - attempting to deprotect received records using the handshake traffic
398  * key, discarding records which fail deprotection (up to the configured
399  * max_early_data_size). Once a record is deprotected successfully,
400  * it is treated as the start of the client's second flight and the
401  * server proceeds as with an ordinary 1-RTT handshake.
402  * - skipping all records with an external content type of
403  * "application_data" (indicating that they are encrypted), up to the
404  * configured max_early_data_size. This is the expected behavior if the
405  * server has sent an HelloRetryRequest message. The server ignores
406  * application data message before 2nd ClientHello.
407  */
408 #define MBEDTLS_SSL_EARLY_DATA_NO_DISCARD 0
409 #define MBEDTLS_SSL_EARLY_DATA_TRY_TO_DEPROTECT_AND_DISCARD 1
410 #define MBEDTLS_SSL_EARLY_DATA_DISCARD 2
411 
420 /*
421  * Maximum fragment length in bytes,
422  * determines the size of each of the two internal I/O buffers.
423  *
424  * Note: the RFC defines the default size of SSL / TLS messages. If you
425  * change the value here, other clients / servers may not be able to
426  * communicate with you anymore. Only change this value if you control
427  * both sides of the connection and have it reduced at both sides, or
428  * if you're using the Max Fragment Length extension and you know all your
429  * peers are using it too!
430  */
431 #if !defined(MBEDTLS_SSL_IN_CONTENT_LEN)
432 #define MBEDTLS_SSL_IN_CONTENT_LEN 16384
433 #endif
434 
435 #if !defined(MBEDTLS_SSL_OUT_CONTENT_LEN)
436 #define MBEDTLS_SSL_OUT_CONTENT_LEN 16384
437 #endif
439 /*
440  * Maximum number of heap-allocated bytes for the purpose of
441  * DTLS handshake message reassembly and future message buffering.
442  */
443 #if !defined(MBEDTLS_SSL_DTLS_MAX_BUFFERING)
444 #define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768
445 #endif
446 
447 /*
448  * Maximum length of CIDs for incoming and outgoing messages.
449  */
450 #if !defined(MBEDTLS_SSL_CID_IN_LEN_MAX)
451 #define MBEDTLS_SSL_CID_IN_LEN_MAX 32
452 #endif
453 
454 #if !defined(MBEDTLS_SSL_CID_OUT_LEN_MAX)
455 #define MBEDTLS_SSL_CID_OUT_LEN_MAX 32
456 #endif
458 #if !defined(MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY)
459 #define MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 16
460 #endif
462 #if !defined(MBEDTLS_SSL_MAX_EARLY_DATA_SIZE)
463 #define MBEDTLS_SSL_MAX_EARLY_DATA_SIZE 1024
464 #endif
466 #if !defined(MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE)
467 #define MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE 6000
468 #endif
470 #if !defined(MBEDTLS_SSL_TLS1_3_TICKET_NONCE_LENGTH)
471 #define MBEDTLS_SSL_TLS1_3_TICKET_NONCE_LENGTH 32
472 #endif
474 #if !defined(MBEDTLS_SSL_TLS1_3_DEFAULT_NEW_SESSION_TICKETS)
475 #define MBEDTLS_SSL_TLS1_3_DEFAULT_NEW_SESSION_TICKETS 1
476 #endif
480 /*
481  * Default to standard CID mode
482  */
483 #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) && \
484  !defined(MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT)
485 #define MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 0
486 #endif
487 
488 /*
489  * Length of the verify data for secure renegotiation
490  */
491 #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 12
492 
493 /*
494  * Signaling ciphersuite values (SCSV)
495  */
496 #define MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO 0xFF
498 /*
499  * Supported Signature and Hash algorithms (For TLS 1.2)
500  * RFC 5246 section 7.4.1.4.1
501  */
502 #define MBEDTLS_SSL_HASH_NONE 0
503 #define MBEDTLS_SSL_HASH_MD5 1
504 #define MBEDTLS_SSL_HASH_SHA1 2
505 #define MBEDTLS_SSL_HASH_SHA224 3
506 #define MBEDTLS_SSL_HASH_SHA256 4
507 #define MBEDTLS_SSL_HASH_SHA384 5
508 #define MBEDTLS_SSL_HASH_SHA512 6
510 #define MBEDTLS_SSL_SIG_ANON 0
511 #define MBEDTLS_SSL_SIG_RSA 1
512 #define MBEDTLS_SSL_SIG_ECDSA 3
514 /*
515  * TLS 1.3 signature algorithms
516  * RFC 8446, Section 4.2.3
517  */
519 /* RSASSA-PKCS1-v1_5 algorithms */
520 #define MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA256 0x0401
521 #define MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA384 0x0501
522 #define MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA512 0x0601
523 
524 /* ECDSA algorithms */
525 #define MBEDTLS_TLS1_3_SIG_ECDSA_SECP256R1_SHA256 0x0403
526 #define MBEDTLS_TLS1_3_SIG_ECDSA_SECP384R1_SHA384 0x0503
527 #define MBEDTLS_TLS1_3_SIG_ECDSA_SECP521R1_SHA512 0x0603
529 /* RSASSA-PSS algorithms with public key OID rsaEncryption */
530 #define MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256 0x0804
531 #define MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384 0x0805
532 #define MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512 0x0806
534 /* EdDSA algorithms */
535 #define MBEDTLS_TLS1_3_SIG_ED25519 0x0807
536 #define MBEDTLS_TLS1_3_SIG_ED448 0x0808
538 /* RSASSA-PSS algorithms with public key OID RSASSA-PSS */
539 #define MBEDTLS_TLS1_3_SIG_RSA_PSS_PSS_SHA256 0x0809
540 #define MBEDTLS_TLS1_3_SIG_RSA_PSS_PSS_SHA384 0x080A
541 #define MBEDTLS_TLS1_3_SIG_RSA_PSS_PSS_SHA512 0x080B
543 /* LEGACY ALGORITHMS */
544 #define MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA1 0x0201
545 #define MBEDTLS_TLS1_3_SIG_ECDSA_SHA1 0x0203
547 #define MBEDTLS_TLS1_3_SIG_NONE 0x0
548 
549 /*
550  * Client Certificate Types
551  * RFC 5246 section 7.4.4 plus RFC 4492 section 5.5
552  */
553 #define MBEDTLS_SSL_CERT_TYPE_RSA_SIGN 1
554 #define MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN 64
555 
556 /*
557  * Message, alert and handshake types
558  */
559 #define MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC 20
560 #define MBEDTLS_SSL_MSG_ALERT 21
561 #define MBEDTLS_SSL_MSG_HANDSHAKE 22
562 #define MBEDTLS_SSL_MSG_APPLICATION_DATA 23
563 #define MBEDTLS_SSL_MSG_CID 25
564 
565 #define MBEDTLS_SSL_ALERT_LEVEL_WARNING 1
566 #define MBEDTLS_SSL_ALERT_LEVEL_FATAL 2
568 #define MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY 0 /* 0x00 */
569 #define MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10 /* 0x0A */
570 #define MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC 20 /* 0x14 */
571 #define MBEDTLS_SSL_ALERT_MSG_DECRYPTION_FAILED 21 /* 0x15 */
572 #define MBEDTLS_SSL_ALERT_MSG_RECORD_OVERFLOW 22 /* 0x16 */
573 #define MBEDTLS_SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30 /* 0x1E */
574 #define MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE 40 /* 0x28 */
575 #define MBEDTLS_SSL_ALERT_MSG_NO_CERT 41 /* 0x29 */
576 #define MBEDTLS_SSL_ALERT_MSG_BAD_CERT 42 /* 0x2A */
577 #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT 43 /* 0x2B */
578 #define MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED 44 /* 0x2C */
579 #define MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED 45 /* 0x2D */
580 #define MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN 46 /* 0x2E */
581 #define MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER 47 /* 0x2F */
582 #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_CA 48 /* 0x30 */
583 #define MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED 49 /* 0x31 */
584 #define MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR 50 /* 0x32 */
585 #define MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR 51 /* 0x33 */
586 #define MBEDTLS_SSL_ALERT_MSG_EXPORT_RESTRICTION 60 /* 0x3C */
587 #define MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION 70 /* 0x46 */
588 #define MBEDTLS_SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71 /* 0x47 */
589 #define MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR 80 /* 0x50 */
590 #define MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK 86 /* 0x56 */
591 #define MBEDTLS_SSL_ALERT_MSG_USER_CANCELED 90 /* 0x5A */
592 #define MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION 100 /* 0x64 */
593 #define MBEDTLS_SSL_ALERT_MSG_MISSING_EXTENSION 109 /* 0x6d -- new in TLS 1.3 */
594 #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT 110 /* 0x6E */
595 #define MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME 112 /* 0x70 */
596 #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY 115 /* 0x73 */
597 #define MBEDTLS_SSL_ALERT_MSG_CERT_REQUIRED 116 /* 0x74 */
598 #define MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL 120 /* 0x78 */
600 #define MBEDTLS_SSL_HS_HELLO_REQUEST 0
601 #define MBEDTLS_SSL_HS_CLIENT_HELLO 1
602 #define MBEDTLS_SSL_HS_SERVER_HELLO 2
603 #define MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST 3
604 #define MBEDTLS_SSL_HS_NEW_SESSION_TICKET 4
605 #define MBEDTLS_SSL_HS_END_OF_EARLY_DATA 5
606 #define MBEDTLS_SSL_HS_ENCRYPTED_EXTENSIONS 8
607 #define MBEDTLS_SSL_HS_CERTIFICATE 11
608 #define MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE 12
609 #define MBEDTLS_SSL_HS_CERTIFICATE_REQUEST 13
610 #define MBEDTLS_SSL_HS_SERVER_HELLO_DONE 14
611 #define MBEDTLS_SSL_HS_CERTIFICATE_VERIFY 15
612 #define MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE 16
613 #define MBEDTLS_SSL_HS_FINISHED 20
614 #define MBEDTLS_SSL_HS_MESSAGE_HASH 254
616 /*
617  * TLS extensions
618  */
619 #define MBEDTLS_TLS_EXT_SERVERNAME 0
620 #define MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME 0
621 
622 #define MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH 1
623 
624 #define MBEDTLS_TLS_EXT_TRUNCATED_HMAC 4
625 #define MBEDTLS_TLS_EXT_STATUS_REQUEST 5 /* RFC 6066 TLS 1.2 and 1.3 */
627 #define MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES 10
628 #define MBEDTLS_TLS_EXT_SUPPORTED_GROUPS 10 /* RFC 8422,7919 TLS 1.2 and 1.3 */
629 #define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS 11
631 #define MBEDTLS_TLS_EXT_SIG_ALG 13 /* RFC 8446 TLS 1.3 */
632 #define MBEDTLS_TLS_EXT_USE_SRTP 14
633 #define MBEDTLS_TLS_EXT_HEARTBEAT 15 /* RFC 6520 TLS 1.2 and 1.3 */
634 #define MBEDTLS_TLS_EXT_ALPN 16
636 #define MBEDTLS_TLS_EXT_SCT 18 /* RFC 6962 TLS 1.2 and 1.3 */
637 #define MBEDTLS_TLS_EXT_CLI_CERT_TYPE 19 /* RFC 7250 TLS 1.2 and 1.3 */
638 #define MBEDTLS_TLS_EXT_SERV_CERT_TYPE 20 /* RFC 7250 TLS 1.2 and 1.3 */
639 #define MBEDTLS_TLS_EXT_PADDING 21 /* RFC 7685 TLS 1.2 and 1.3 */
640 #define MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC 22 /* 0x16 */
641 #define MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET 0x0017 /* 23 */
643 #define MBEDTLS_TLS_EXT_RECORD_SIZE_LIMIT 28 /* RFC 8449 (implemented for TLS 1.3 only) */
645 #define MBEDTLS_TLS_EXT_SESSION_TICKET 35
647 #define MBEDTLS_TLS_EXT_PRE_SHARED_KEY 41 /* RFC 8446 TLS 1.3 */
648 #define MBEDTLS_TLS_EXT_EARLY_DATA 42 /* RFC 8446 TLS 1.3 */
649 #define MBEDTLS_TLS_EXT_SUPPORTED_VERSIONS 43 /* RFC 8446 TLS 1.3 */
650 #define MBEDTLS_TLS_EXT_COOKIE 44 /* RFC 8446 TLS 1.3 */
651 #define MBEDTLS_TLS_EXT_PSK_KEY_EXCHANGE_MODES 45 /* RFC 8446 TLS 1.3 */
652 
653 #define MBEDTLS_TLS_EXT_CERT_AUTH 47 /* RFC 8446 TLS 1.3 */
654 #define MBEDTLS_TLS_EXT_OID_FILTERS 48 /* RFC 8446 TLS 1.3 */
655 #define MBEDTLS_TLS_EXT_POST_HANDSHAKE_AUTH 49 /* RFC 8446 TLS 1.3 */
656 #define MBEDTLS_TLS_EXT_SIG_ALG_CERT 50 /* RFC 8446 TLS 1.3 */
657 #define MBEDTLS_TLS_EXT_KEY_SHARE 51 /* RFC 8446 TLS 1.3 */
658 
659 #if MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT == 0
660 #define MBEDTLS_TLS_EXT_CID 54 /* RFC 9146 DTLS 1.2 CID */
661 #else
662 #define MBEDTLS_TLS_EXT_CID 254 /* Pre-RFC 9146 DTLS 1.2 CID */
663 #endif
664 
665 #define MBEDTLS_TLS_EXT_ECJPAKE_KKPP 256 /* experimental */
667 #define MBEDTLS_TLS_EXT_RENEGOTIATION_INFO 0xFF01
668 
669 /*
670  * Size defines
671  */
672 #if !defined(MBEDTLS_PSK_MAX_LEN)
673 /*
674  * If the library supports TLS 1.3 tickets and the cipher suite
675  * TLS1-3-AES-256-GCM-SHA384, set the PSK maximum length to 48 instead of 32.
676  * That way, the TLS 1.3 client and server are able to resume sessions where
677  * the cipher suite is TLS1-3-AES-256-GCM-SHA384 (pre-shared keys are 48
678  * bytes long in that case).
679  */
680 #if defined(MBEDTLS_SSL_PROTO_TLS1_3) && \
681  defined(MBEDTLS_SSL_SESSION_TICKETS) && \
682  defined(MBEDTLS_SSL_HAVE_AES) && defined(MBEDTLS_SSL_HAVE_GCM) && \
683  defined(MBEDTLS_MD_CAN_SHA384)
684 #define MBEDTLS_PSK_MAX_LEN 48 /* 384 bits */
685 #else
686 #define MBEDTLS_PSK_MAX_LEN 32 /* 256 bits */
687 #endif
688 #endif /* !MBEDTLS_PSK_MAX_LEN */
689 
690 /* Dummy type used only for its size */
692  unsigned char dummy; /* Make the union non-empty even with SSL disabled */
693 #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
694  unsigned char _pms_rsa[48]; /* RFC 5246 8.1.1 */
695 #endif
696 #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED)
697  unsigned char _pms_dhm[MBEDTLS_MPI_MAX_SIZE]; /* RFC 5246 8.1.2 */
698 #endif
699 #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
700  defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
701  defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
702  defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
703  unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]; /* RFC 4492 5.10 */
704 #endif
705 #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
706  unsigned char _pms_psk[4 + 2 * MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 2 */
707 #endif
708 #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
710  + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 3 */
711 #endif
712 #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)
713  unsigned char _pms_rsa_psk[52 + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 4 */
714 #endif
715 #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
717  + MBEDTLS_PSK_MAX_LEN]; /* RFC 5489 2 */
718 #endif
719 #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
720  unsigned char _pms_ecjpake[32]; /* Thread spec: SHA-256 output */
721 #endif
722 };
724 #define MBEDTLS_PREMASTER_SIZE sizeof(union mbedtls_ssl_premaster_secret)
725 
726 #define MBEDTLS_TLS1_3_MD_MAX_SIZE PSA_HASH_MAX_SIZE
727 
728 
729 /* Length in number of bytes of the TLS sequence number */
730 #define MBEDTLS_SSL_SEQUENCE_NUMBER_LEN 8
731 
732 /* Helper to state that client_random and server_random need to be stored
733  * after the handshake is complete. This is required for context serialization
734  * and for the keying material exporter in TLS 1.2. */
735 #if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION) || \
736  (defined(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT) && defined(MBEDTLS_SSL_PROTO_TLS1_2))
737 #define MBEDTLS_SSL_KEEP_RANDBYTES
738 #endif
739 
740 #ifdef __cplusplus
741 extern "C" {
742 #endif
744 /*
745  * SSL state machine
746  */
747 typedef enum {
778 }
781 /*
782  * Early data status, client side only.
783  */
784 
785 #if defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_CLI_C)
786 typedef enum {
787 /*
788  * See documentation of mbedtls_ssl_get_early_data_status().
789  */
790  MBEDTLS_SSL_EARLY_DATA_STATUS_NOT_INDICATED,
791  MBEDTLS_SSL_EARLY_DATA_STATUS_ACCEPTED,
792  MBEDTLS_SSL_EARLY_DATA_STATUS_REJECTED,
793 } mbedtls_ssl_early_data_status;
794 #endif /* MBEDTLS_SSL_EARLY_DATA && MBEDTLS_SSL_CLI_C */
795 
813 typedef int mbedtls_ssl_send_t(void *ctx,
814  const unsigned char *buf,
815  size_t len);
816 
837 typedef int mbedtls_ssl_recv_t(void *ctx,
838  unsigned char *buf,
839  size_t len);
840 
863 typedef int mbedtls_ssl_recv_timeout_t(void *ctx,
864  unsigned char *buf,
865  size_t len,
866  uint32_t timeout);
889 typedef void mbedtls_ssl_set_timer_t(void *ctx,
890  uint32_t int_ms,
891  uint32_t fin_ms);
892 
904 typedef int mbedtls_ssl_get_timer_t(void *ctx);
905 
906 /* Defined below */
911 /* Defined in library/ssl_misc.h */
915 #if defined(MBEDTLS_X509_CRT_PARSE_C)
917 #endif
918 #if defined(MBEDTLS_SSL_PROTO_DTLS)
920 #endif
921 
922 #if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS)
923 #define MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_PSK_RESUMPTION \
924  MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK /* 1U << 0 */
925 #define MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_PSK_EPHEMERAL_RESUMPTION \
926  MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL /* 1U << 2 */
927 #define MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_EARLY_DATA (1U << 3)
928 
929 #define MBEDTLS_SSL_TLS1_3_TICKET_FLAGS_MASK \
930  (MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_PSK_RESUMPTION | \
931  MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_PSK_EPHEMERAL_RESUMPTION | \
932  MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_EARLY_DATA)
933 #endif /* MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_SESSION_TICKETS */
934 
958 typedef int mbedtls_ssl_cache_get_t(void *data,
959  unsigned char const *session_id,
960  size_t session_id_len,
961  mbedtls_ssl_session *session);
980 typedef int mbedtls_ssl_cache_set_t(void *data,
981  unsigned char const *session_id,
982  size_t session_id_len,
983  const mbedtls_ssl_session *session);
984 
985 #if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
986 #if defined(MBEDTLS_X509_CRT_PARSE_C)
987 
1058 typedef int mbedtls_ssl_async_sign_t(mbedtls_ssl_context *ssl,
1059  mbedtls_x509_crt *cert,
1060  mbedtls_md_type_t md_alg,
1061  const unsigned char *hash,
1062  size_t hash_len);
1063 
1124 typedef int mbedtls_ssl_async_decrypt_t(mbedtls_ssl_context *ssl,
1125  mbedtls_x509_crt *cert,
1126  const unsigned char *input,
1127  size_t input_len);
1128 #endif /* MBEDTLS_X509_CRT_PARSE_C */
1129 
1172 typedef int mbedtls_ssl_async_resume_t(mbedtls_ssl_context *ssl,
1173  unsigned char *output,
1174  size_t *output_len,
1175  size_t output_size);
1176 
1194 typedef void mbedtls_ssl_async_cancel_t(mbedtls_ssl_context *ssl);
1195 #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
1196 
1197 #if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) && \
1198  !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
1199 #define MBEDTLS_SSL_PEER_CERT_DIGEST_MAX_LEN 48
1200 #if defined(MBEDTLS_MD_CAN_SHA256)
1201 #define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA256
1202 #define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 32
1203 #elif defined(MBEDTLS_MD_CAN_SHA384)
1204 #define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA384
1205 #define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 48
1206 #elif defined(MBEDTLS_MD_CAN_SHA1)
1207 #define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA1
1208 #define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 20
1209 #else
1210 /* This is already checked in check_config.h, but be sure. */
1211 #error "Bad configuration - need SHA-1, SHA-256 or SHA-512 enabled to compute digest of peer CRT."
1212 #endif
1213 #endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED &&
1214  !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
1215 
1216 typedef struct {
1217  unsigned char client_application_traffic_secret_N[MBEDTLS_TLS1_3_MD_MAX_SIZE];
1218  unsigned char server_application_traffic_secret_N[MBEDTLS_TLS1_3_MD_MAX_SIZE];
1219  unsigned char exporter_master_secret[MBEDTLS_TLS1_3_MD_MAX_SIZE];
1220  unsigned char resumption_master_secret[MBEDTLS_TLS1_3_MD_MAX_SIZE];
1223 #if defined(MBEDTLS_SSL_DTLS_SRTP)
1225 #define MBEDTLS_TLS_SRTP_MAX_MKI_LENGTH 255
1226 #define MBEDTLS_TLS_SRTP_MAX_PROFILE_LIST_LENGTH 4
1227 /*
1228  * For code readability use a typedef for DTLS-SRTP profiles
1229  *
1230  * Use_srtp extension protection profiles values as defined in
1231  * http://www.iana.org/assignments/srtp-protection/srtp-protection.xhtml
1232  *
1233  * Reminder: if this list is expanded mbedtls_ssl_check_srtp_profile_value
1234  * must be updated too.
1235  */
1236 #define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80 ((uint16_t) 0x0001)
1237 #define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32 ((uint16_t) 0x0002)
1238 #define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80 ((uint16_t) 0x0005)
1239 #define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32 ((uint16_t) 0x0006)
1240 /* This one is not iana defined, but for code readability. */
1241 #define MBEDTLS_TLS_SRTP_UNSET ((uint16_t) 0x0000)
1243 typedef uint16_t mbedtls_ssl_srtp_profile;
1247  mbedtls_ssl_srtp_profile MBEDTLS_PRIVATE(chosen_dtls_srtp_profile);
1249  uint16_t MBEDTLS_PRIVATE(mki_len);
1252 }
1254 
1255 #endif /* MBEDTLS_SSL_DTLS_SRTP */
1256 
1258 typedef enum {
1260  MBEDTLS_SSL_VERSION_TLS1_2 = 0x0303,
1261  MBEDTLS_SSL_VERSION_TLS1_3 = 0x0304,
1263 
1264 /*
1265  * This structure is used for storing current session data.
1266  *
1267  * Note: when changing this definition, we need to check and update:
1268  * - in tests/suites/test_suite_ssl.function:
1269  * ssl_populate_session() and ssl_serialize_session_save_load()
1270  * - in library/ssl_tls.c:
1271  * mbedtls_ssl_session_init() and mbedtls_ssl_session_free()
1272  * mbedtls_ssl_session_save() and ssl_session_load()
1273  * ssl_session_copy()
1274  */
1275 struct mbedtls_ssl_session {
1276 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
1277  unsigned char MBEDTLS_PRIVATE(mfl_code);
1278 #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
1279 
1281 #if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT)
1282  uint16_t MBEDTLS_PRIVATE(record_size_limit);
1283 #endif /* MBEDTLS_SSL_RECORD_SIZE_LIMIT */
1284 
1285  unsigned char MBEDTLS_PRIVATE(exported);
1286  uint8_t MBEDTLS_PRIVATE(endpoint);
1293 #if defined(MBEDTLS_HAVE_TIME)
1295 #endif
1296  int MBEDTLS_PRIVATE(ciphersuite);
1297  size_t MBEDTLS_PRIVATE(id_len);
1298  unsigned char MBEDTLS_PRIVATE(id)[32];
1299  unsigned char MBEDTLS_PRIVATE(master)[48];
1301 #if defined(MBEDTLS_X509_CRT_PARSE_C)
1302 #if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
1304 #else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
1307  unsigned char *MBEDTLS_PRIVATE(peer_cert_digest);
1308  size_t MBEDTLS_PRIVATE(peer_cert_digest_len);
1309  mbedtls_md_type_t MBEDTLS_PRIVATE(peer_cert_digest_type);
1310 #endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
1311 #endif /* MBEDTLS_X509_CRT_PARSE_C */
1312  uint32_t MBEDTLS_PRIVATE(verify_result);
1314 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
1315  unsigned char *MBEDTLS_PRIVATE(ticket);
1316  size_t MBEDTLS_PRIVATE(ticket_len);
1317  uint32_t MBEDTLS_PRIVATE(ticket_lifetime);
1318 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
1319 
1320 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C) && \
1321  defined(MBEDTLS_HAVE_TIME)
1338  mbedtls_ms_time_t MBEDTLS_PRIVATE(ticket_creation_time);
1339 #endif
1340 
1341 #if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS)
1342  uint32_t MBEDTLS_PRIVATE(ticket_age_add);
1343  uint8_t MBEDTLS_PRIVATE(ticket_flags);
1344  uint8_t MBEDTLS_PRIVATE(resumption_key_len);
1345  unsigned char MBEDTLS_PRIVATE(resumption_key)[MBEDTLS_SSL_TLS1_3_TICKET_RESUMPTION_KEY_LEN];
1346 
1347 #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) && defined(MBEDTLS_SSL_CLI_C)
1348  char *MBEDTLS_PRIVATE(hostname);
1349 #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION && MBEDTLS_SSL_CLI_C */
1351 #if defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_ALPN) && defined(MBEDTLS_SSL_SRV_C)
1352  char *ticket_alpn;
1354 #endif
1355 
1356 #if defined(MBEDTLS_HAVE_TIME) && defined(MBEDTLS_SSL_CLI_C)
1357 
1358  mbedtls_ms_time_t MBEDTLS_PRIVATE(ticket_reception_time);
1359 #endif
1360 #endif /* MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_SESSION_TICKETS */
1361 
1362 #if defined(MBEDTLS_SSL_EARLY_DATA)
1363  uint32_t MBEDTLS_PRIVATE(max_early_data_size);
1364 #endif
1365 
1366 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1367  int MBEDTLS_PRIVATE(encrypt_then_mac);
1368 #endif
1369 
1370 #if defined(MBEDTLS_SSL_PROTO_TLS1_3)
1372 #endif
1373 };
1374 
1375 /*
1376  * Identifiers for PRFs used in various versions of TLS.
1377  */
1378 typedef enum {
1387 typedef enum {
1389 #if defined(MBEDTLS_SSL_PROTO_TLS1_3)
1396 #endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
1414 typedef void mbedtls_ssl_export_keys_t(void *p_expkey,
1416  const unsigned char *secret,
1417  size_t secret_len,
1418  const unsigned char client_random[32],
1419  const unsigned char server_random[32],
1420  mbedtls_tls_prf_types tls_prf_type);
1421 
1422 #if defined(MBEDTLS_SSL_SRV_C)
1423 
1438 typedef int (*mbedtls_ssl_hs_cb_t)(mbedtls_ssl_context *ssl);
1439 #endif
1440 
1441 /* A type for storing user data in a library structure.
1442  *
1443  * The representation of type may change in future versions of the library.
1444  * Only the behaviors guaranteed by documented accessor functions are
1445  * guaranteed to remain stable.
1446  */
1447 typedef union {
1448  uintptr_t n; /* typically a handle to an associated object */
1449  void *p; /* typically a pointer to extra data */
1451 
1456  /* Group items mostly by size. This helps to reduce memory wasted to
1457  * padding. It also helps to keep smaller fields early in the structure,
1458  * so that elements tend to be in the 128-element direct access window
1459  * on Arm Thumb, which reduces the code size. */
1460 
1464  /*
1465  * Flags (could be bit-fields to save RAM, but separate bytes make
1466  * the code smaller on architectures with an instruction for direct
1467  * byte access).
1468  */
1469 
1470  uint8_t MBEDTLS_PRIVATE(endpoint);
1471  uint8_t MBEDTLS_PRIVATE(transport);
1472  uint8_t MBEDTLS_PRIVATE(authmode);
1473  /* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */
1474  uint8_t MBEDTLS_PRIVATE(allow_legacy_renegotiation);
1475 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
1476  uint8_t MBEDTLS_PRIVATE(mfl_code);
1478 #endif
1479 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1480  uint8_t MBEDTLS_PRIVATE(encrypt_then_mac);
1481 #endif
1482 #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
1483  uint8_t MBEDTLS_PRIVATE(extended_ms);
1484 #endif
1485 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
1486  uint8_t MBEDTLS_PRIVATE(anti_replay);
1487 #endif
1488 #if defined(MBEDTLS_SSL_RENEGOTIATION)
1489  uint8_t MBEDTLS_PRIVATE(disable_renegotiation);
1490 #endif
1491 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && \
1492  defined(MBEDTLS_SSL_CLI_C)
1493 
1499  uint8_t MBEDTLS_PRIVATE(session_tickets);
1500 #endif
1501 
1502 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && \
1503  defined(MBEDTLS_SSL_SRV_C) && \
1504  defined(MBEDTLS_SSL_PROTO_TLS1_3)
1505  uint16_t MBEDTLS_PRIVATE(new_session_tickets_count);
1506 #endif
1507 
1508 #if defined(MBEDTLS_SSL_SRV_C)
1509  uint8_t MBEDTLS_PRIVATE(cert_req_ca_list);
1511  uint8_t MBEDTLS_PRIVATE(respect_cli_pref);
1514 #endif
1515 #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1516  uint8_t MBEDTLS_PRIVATE(ignore_unexpected_cid);
1519 #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1520 #if defined(MBEDTLS_SSL_DTLS_SRTP)
1521  uint8_t MBEDTLS_PRIVATE(dtls_srtp_mki_support); /* support having mki_value
1522  in the use_srtp extension? */
1523 #endif
1524 
1525  /*
1526  * Pointers
1527  */
1528 
1530  const int *MBEDTLS_PRIVATE(ciphersuite_list);
1531 
1532 #if defined(MBEDTLS_SSL_PROTO_TLS1_3)
1533 
1534  int MBEDTLS_PRIVATE(tls13_kex_modes);
1535 #endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
1538  void(*MBEDTLS_PRIVATE(f_dbg))(void *, int, const char *, int, const char *);
1539  void *MBEDTLS_PRIVATE(p_dbg);
1542  int(*MBEDTLS_PRIVATE(f_rng))(void *, unsigned char *, size_t);
1543  void *MBEDTLS_PRIVATE(p_rng);
1549  void *MBEDTLS_PRIVATE(p_cache);
1551 #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
1553  int(*MBEDTLS_PRIVATE(f_sni))(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
1554  void *MBEDTLS_PRIVATE(p_sni);
1555 #endif
1556 
1557 #if defined(MBEDTLS_X509_CRT_PARSE_C)
1558 
1559  int(*MBEDTLS_PRIVATE(f_vrfy))(void *, mbedtls_x509_crt *, int, uint32_t *);
1560  void *MBEDTLS_PRIVATE(p_vrfy);
1561 #endif
1562 
1563 #if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
1564 #if defined(MBEDTLS_SSL_SRV_C)
1566  int(*MBEDTLS_PRIVATE(f_psk))(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
1567  void *MBEDTLS_PRIVATE(p_psk);
1568 #endif
1569 #endif
1570 
1571 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
1573  int(*MBEDTLS_PRIVATE(f_cookie_write))(void *, unsigned char **, unsigned char *,
1574  const unsigned char *, size_t);
1576  int(*MBEDTLS_PRIVATE(f_cookie_check))(void *, const unsigned char *, size_t,
1577  const unsigned char *, size_t);
1578  void *MBEDTLS_PRIVATE(p_cookie);
1579 #endif
1580 
1581 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
1583  int(*MBEDTLS_PRIVATE(f_ticket_write))(void *, const mbedtls_ssl_session *,
1584  unsigned char *, const unsigned char *, size_t *,
1585  uint32_t *);
1587  int(*MBEDTLS_PRIVATE(f_ticket_parse))(void *, mbedtls_ssl_session *, unsigned char *, size_t);
1588  void *MBEDTLS_PRIVATE(p_ticket);
1589 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
1590 #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1591  size_t MBEDTLS_PRIVATE(cid_len);
1592 #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1594 #if defined(MBEDTLS_X509_CRT_PARSE_C)
1595  const mbedtls_x509_crt_profile *MBEDTLS_PRIVATE(cert_profile);
1597  mbedtls_x509_crt *MBEDTLS_PRIVATE(ca_chain);
1599 #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
1601  void *MBEDTLS_PRIVATE(p_ca_cb);
1602 #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
1603 #endif /* MBEDTLS_X509_CRT_PARSE_C */
1605 #if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
1606 #if defined(MBEDTLS_X509_CRT_PARSE_C)
1607  mbedtls_ssl_async_sign_t *MBEDTLS_PRIVATE(f_async_sign_start);
1608  mbedtls_ssl_async_decrypt_t *MBEDTLS_PRIVATE(f_async_decrypt_start);
1609 #endif /* MBEDTLS_X509_CRT_PARSE_C */
1610  mbedtls_ssl_async_resume_t *MBEDTLS_PRIVATE(f_async_resume);
1611  mbedtls_ssl_async_cancel_t *MBEDTLS_PRIVATE(f_async_cancel);
1612  void *MBEDTLS_PRIVATE(p_async_config_data);
1613 #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
1614 
1615 #if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
1616 
1617 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
1618  const int *MBEDTLS_PRIVATE(sig_hashes);
1619 #endif
1620  const uint16_t *MBEDTLS_PRIVATE(sig_algs);
1621 #endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
1622 
1623 #if defined(MBEDTLS_ECP_C) && !defined(MBEDTLS_DEPRECATED_REMOVED)
1625 #endif
1627  const uint16_t *MBEDTLS_PRIVATE(group_list);
1629 #if defined(MBEDTLS_DHM_C)
1631  mbedtls_mpi MBEDTLS_PRIVATE(dhm_G);
1632 #endif
1634 #if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
1635 
1636 #if defined(MBEDTLS_USE_PSA_CRYPTO)
1643 #endif /* MBEDTLS_USE_PSA_CRYPTO */
1644  unsigned char *MBEDTLS_PRIVATE(psk);
1648  size_t MBEDTLS_PRIVATE(psk_len);
1654  unsigned char *MBEDTLS_PRIVATE(psk_identity);
1659  size_t MBEDTLS_PRIVATE(psk_identity_len);
1665 #endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
1666 
1667 #if defined(MBEDTLS_SSL_EARLY_DATA)
1668  int MBEDTLS_PRIVATE(early_data_enabled);
1672 #if defined(MBEDTLS_SSL_SRV_C)
1673  /* The maximum amount of 0-RTT data. RFC 8446 section 4.6.1 */
1674  uint32_t MBEDTLS_PRIVATE(max_early_data_size);
1675 #endif /* MBEDTLS_SSL_SRV_C */
1676 
1677 #endif /* MBEDTLS_SSL_EARLY_DATA */
1678 
1679 #if defined(MBEDTLS_SSL_ALPN)
1680  const char **MBEDTLS_PRIVATE(alpn_list);
1681 #endif
1682 
1683 #if defined(MBEDTLS_SSL_DTLS_SRTP)
1684 
1685  const mbedtls_ssl_srtp_profile *MBEDTLS_PRIVATE(dtls_srtp_profile_list);
1687  size_t MBEDTLS_PRIVATE(dtls_srtp_profile_list_len);
1688 #endif /* MBEDTLS_SSL_DTLS_SRTP */
1689 
1690  /*
1691  * Numerical settings (int)
1692  */
1694  uint32_t MBEDTLS_PRIVATE(read_timeout);
1696 #if defined(MBEDTLS_SSL_PROTO_DTLS)
1697  uint32_t MBEDTLS_PRIVATE(hs_timeout_min);
1699  uint32_t MBEDTLS_PRIVATE(hs_timeout_max);
1701 #endif
1702 
1703 #if defined(MBEDTLS_SSL_RENEGOTIATION)
1704  int MBEDTLS_PRIVATE(renego_max_records);
1705  unsigned char MBEDTLS_PRIVATE(renego_period)[8];
1707 #endif
1708 
1709  unsigned int MBEDTLS_PRIVATE(badmac_limit);
1711 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
1712  unsigned int MBEDTLS_PRIVATE(dhm_min_bitlen);
1713 #endif
1714 
1721 
1722 #if defined(MBEDTLS_SSL_SRV_C)
1724 #endif /* MBEDTLS_SSL_SRV_C */
1725 
1726 #if defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED)
1727  const mbedtls_x509_crt *MBEDTLS_PRIVATE(dn_hints);
1728 #endif
1729 };
1730 
1731 struct mbedtls_ssl_context {
1732  const mbedtls_ssl_config *MBEDTLS_PRIVATE(conf);
1734  /*
1735  * Miscellaneous
1736  */
1737  int MBEDTLS_PRIVATE(state);
1738 #if defined(MBEDTLS_SSL_RENEGOTIATION)
1739  int MBEDTLS_PRIVATE(renego_status);
1740  int MBEDTLS_PRIVATE(renego_records_seen);
1743 #endif /* MBEDTLS_SSL_RENEGOTIATION */
1744 
1762 
1763 #if defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_CLI_C)
1764 
1768  int MBEDTLS_PRIVATE(early_data_state);
1769 #endif
1770 
1780  unsigned MBEDTLS_PRIVATE(badmac_seen_or_in_hsfraglen);
1781 
1782 #if defined(MBEDTLS_X509_CRT_PARSE_C)
1783 
1784  int(*MBEDTLS_PRIVATE(f_vrfy))(void *, mbedtls_x509_crt *, int, uint32_t *);
1785  void *MBEDTLS_PRIVATE(p_vrfy);
1786 #endif
1787 
1793  void *MBEDTLS_PRIVATE(p_bio);
1795  /*
1796  * Session layer
1797  */
1798  mbedtls_ssl_session *MBEDTLS_PRIVATE(session_in);
1799  mbedtls_ssl_session *MBEDTLS_PRIVATE(session_out);
1800  mbedtls_ssl_session *MBEDTLS_PRIVATE(session);
1801  mbedtls_ssl_session *MBEDTLS_PRIVATE(session_negotiate);
1806  /*
1807  * Record layer transformations
1808  */
1812  mbedtls_ssl_transform *MBEDTLS_PRIVATE(transform_out);
1818 #if defined(MBEDTLS_SSL_PROTO_TLS1_2)
1819  mbedtls_ssl_transform *MBEDTLS_PRIVATE(transform_negotiate);
1822 #endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
1823 
1824 #if defined(MBEDTLS_SSL_PROTO_TLS1_3)
1827  mbedtls_ssl_transform *MBEDTLS_PRIVATE(transform_application);
1828 #endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
1829 
1830  /*
1831  * Timers
1832  */
1833  void *MBEDTLS_PRIVATE(p_timer);
1838  /*
1839  * Record layer (incoming data)
1840  */
1841  unsigned char *MBEDTLS_PRIVATE(in_buf);
1842  unsigned char *MBEDTLS_PRIVATE(in_ctr);
1845  unsigned char *MBEDTLS_PRIVATE(in_hdr);
1846 #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1847  unsigned char *MBEDTLS_PRIVATE(in_cid);
1849 #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1850  unsigned char *MBEDTLS_PRIVATE(in_len);
1851  unsigned char *MBEDTLS_PRIVATE(in_iv);
1852  unsigned char *MBEDTLS_PRIVATE(in_msg);
1853  unsigned char *MBEDTLS_PRIVATE(in_offt);
1855  int MBEDTLS_PRIVATE(in_msgtype);
1856  size_t MBEDTLS_PRIVATE(in_msglen);
1857  size_t MBEDTLS_PRIVATE(in_left);
1858 #if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
1859  size_t MBEDTLS_PRIVATE(in_buf_len);
1860 #endif
1861 #if defined(MBEDTLS_SSL_PROTO_DTLS)
1862  uint16_t MBEDTLS_PRIVATE(in_epoch);
1863  size_t MBEDTLS_PRIVATE(next_record_offset);
1865 #endif /* MBEDTLS_SSL_PROTO_DTLS */
1866 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
1867  uint64_t MBEDTLS_PRIVATE(in_window_top);
1868  uint64_t MBEDTLS_PRIVATE(in_window);
1869 #endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
1870 
1871  size_t MBEDTLS_PRIVATE(in_hslen);
1873  int MBEDTLS_PRIVATE(nb_zero);
1875  int MBEDTLS_PRIVATE(keep_current_message);
1878  /* The following three variables indicate if and, if yes,
1879  * what kind of alert is pending to be sent.
1880  */
1881  unsigned char MBEDTLS_PRIVATE(send_alert);
1885  unsigned char MBEDTLS_PRIVATE(alert_type);
1887  int MBEDTLS_PRIVATE(alert_reason);
1891 #if defined(MBEDTLS_SSL_PROTO_DTLS)
1892  uint8_t MBEDTLS_PRIVATE(disable_datagram_packing);
1894 #endif /* MBEDTLS_SSL_PROTO_DTLS */
1895 
1896 #if defined(MBEDTLS_SSL_EARLY_DATA)
1897 #if defined(MBEDTLS_SSL_SRV_C)
1898  /*
1899  * One of:
1900  * MBEDTLS_SSL_EARLY_DATA_NO_DISCARD
1901  * MBEDTLS_SSL_EARLY_DATA_TRY_TO_DEPROTECT_AND_DISCARD
1902  * MBEDTLS_SSL_EARLY_DATA_DISCARD
1903  */
1904  uint8_t MBEDTLS_PRIVATE(discard_early_data_record);
1905 #endif
1906  uint32_t MBEDTLS_PRIVATE(total_early_data_size);
1907 #endif /* MBEDTLS_SSL_EARLY_DATA */
1908 
1909  /*
1910  * Record layer (outgoing data)
1911  */
1912  unsigned char *MBEDTLS_PRIVATE(out_buf);
1913  unsigned char *MBEDTLS_PRIVATE(out_ctr);
1914  unsigned char *MBEDTLS_PRIVATE(out_hdr);
1915 #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1916  unsigned char *MBEDTLS_PRIVATE(out_cid);
1918 #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1919  unsigned char *MBEDTLS_PRIVATE(out_len);
1920  unsigned char *MBEDTLS_PRIVATE(out_iv);
1921  unsigned char *MBEDTLS_PRIVATE(out_msg);
1923  int MBEDTLS_PRIVATE(out_msgtype);
1924  size_t MBEDTLS_PRIVATE(out_msglen);
1925  size_t MBEDTLS_PRIVATE(out_left);
1926 #if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
1927  size_t MBEDTLS_PRIVATE(out_buf_len);
1928 #endif
1930  unsigned char MBEDTLS_PRIVATE(cur_out_ctr)[MBEDTLS_SSL_SEQUENCE_NUMBER_LEN];
1932 #if defined(MBEDTLS_SSL_PROTO_DTLS)
1933  uint16_t MBEDTLS_PRIVATE(mtu);
1934 #endif /* MBEDTLS_SSL_PROTO_DTLS */
1935 
1936  /*
1937  * User settings
1938  */
1939 #if defined(MBEDTLS_X509_CRT_PARSE_C)
1940 
1968  char *MBEDTLS_PRIVATE(hostname);
1969 #endif /* MBEDTLS_X509_CRT_PARSE_C */
1970 
1971 #if defined(MBEDTLS_SSL_ALPN)
1972  const char *MBEDTLS_PRIVATE(alpn_chosen);
1973 #endif /* MBEDTLS_SSL_ALPN */
1975 #if defined(MBEDTLS_SSL_DTLS_SRTP)
1976  /*
1977  * use_srtp extension
1978  */
1979  mbedtls_dtls_srtp_info MBEDTLS_PRIVATE(dtls_srtp_info);
1980 #endif /* MBEDTLS_SSL_DTLS_SRTP */
1981 
1982  /*
1983  * Information for DTLS hello verify
1984  */
1985 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
1986  unsigned char *MBEDTLS_PRIVATE(cli_id);
1987  size_t MBEDTLS_PRIVATE(cli_id_len);
1988 #endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
1989 
1990  /*
1991  * Secure renegotiation
1992  */
1993  /* needed to know when to send extension on server */
1994  int MBEDTLS_PRIVATE(secure_renegotiation);
1996 #if defined(MBEDTLS_SSL_RENEGOTIATION)
1997  size_t MBEDTLS_PRIVATE(verify_data_len);
1998  char MBEDTLS_PRIVATE(own_verify_data)[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN];
1999  char MBEDTLS_PRIVATE(peer_verify_data)[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN];
2000 #endif /* MBEDTLS_SSL_RENEGOTIATION */
2001 
2002 #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
2003  /* CID configuration to use in subsequent handshakes. */
2009  unsigned char MBEDTLS_PRIVATE(own_cid)[MBEDTLS_SSL_CID_IN_LEN_MAX];
2010  uint8_t MBEDTLS_PRIVATE(own_cid_len);
2011  uint8_t MBEDTLS_PRIVATE(negotiate_cid);
2015 #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
2019  void *MBEDTLS_PRIVATE(p_export_keys);
2031 };
2032 
2041 const char *mbedtls_ssl_get_ciphersuite_name(const int ciphersuite_id);
2042 
2051 int mbedtls_ssl_get_ciphersuite_id(const char *ciphersuite_name);
2052 
2060 void mbedtls_ssl_init(mbedtls_ssl_context *ssl);
2061 
2094 int mbedtls_ssl_setup(mbedtls_ssl_context *ssl,
2095  const mbedtls_ssl_config *conf);
2096 
2106 int mbedtls_ssl_session_reset(mbedtls_ssl_context *ssl);
2107 
2114 void mbedtls_ssl_conf_endpoint(mbedtls_ssl_config *conf, int endpoint);
2115 
2124 static inline int mbedtls_ssl_conf_get_endpoint(const mbedtls_ssl_config *conf)
2125 {
2126  return conf->MBEDTLS_PRIVATE(endpoint);
2127 }
2128 
2143 void mbedtls_ssl_conf_transport(mbedtls_ssl_config *conf, int transport);
2144 
2171 void mbedtls_ssl_conf_authmode(mbedtls_ssl_config *conf, int authmode);
2172 
2173 #if defined(MBEDTLS_SSL_EARLY_DATA)
2174 
2200 void mbedtls_ssl_conf_early_data(mbedtls_ssl_config *conf,
2201  int early_data_enabled);
2202 
2203 #if defined(MBEDTLS_SSL_SRV_C)
2204 
2228 void mbedtls_ssl_conf_max_early_data_size(
2229  mbedtls_ssl_config *conf, uint32_t max_early_data_size);
2230 #endif /* MBEDTLS_SSL_SRV_C */
2231 
2232 #endif /* MBEDTLS_SSL_EARLY_DATA */
2233 
2234 #if defined(MBEDTLS_X509_CRT_PARSE_C)
2235 
2251  int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
2252  void *p_vrfy);
2253 #endif /* MBEDTLS_X509_CRT_PARSE_C */
2254 
2267  mbedtls_f_rng_t *f_rng,
2268  void *p_rng);
2269 
2285  void (*f_dbg)(void *, int, const char *, int, const char *),
2286  void *p_dbg);
2287 
2299  const mbedtls_ssl_context *ssl)
2300 {
2301  return ssl->MBEDTLS_PRIVATE(conf);
2302 }
2303 
2334 void mbedtls_ssl_set_bio(mbedtls_ssl_context *ssl,
2335  void *p_bio,
2336  mbedtls_ssl_send_t *f_send,
2337  mbedtls_ssl_recv_t *f_recv,
2338  mbedtls_ssl_recv_timeout_t *f_recv_timeout);
2339 
2340 #if defined(MBEDTLS_SSL_PROTO_DTLS)
2341 
2342 #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
2343 
2344 
2429 int mbedtls_ssl_set_cid(mbedtls_ssl_context *ssl,
2430  int enable,
2431  unsigned char const *own_cid,
2432  size_t own_cid_len);
2433 
2463 int mbedtls_ssl_get_own_cid(mbedtls_ssl_context *ssl,
2464  int *enabled,
2465  unsigned char own_cid[MBEDTLS_SSL_CID_IN_LEN_MAX],
2466  size_t *own_cid_len);
2467 
2505 int mbedtls_ssl_get_peer_cid(mbedtls_ssl_context *ssl,
2506  int *enabled,
2507  unsigned char peer_cid[MBEDTLS_SSL_CID_OUT_LEN_MAX],
2508  size_t *peer_cid_len);
2509 
2510 #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
2511 
2551 void mbedtls_ssl_set_mtu(mbedtls_ssl_context *ssl, uint16_t mtu);
2552 #endif /* MBEDTLS_SSL_PROTO_DTLS */
2553 
2554 #if defined(MBEDTLS_X509_CRT_PARSE_C)
2555 
2573 void mbedtls_ssl_set_verify(mbedtls_ssl_context *ssl,
2574  int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
2575  void *p_vrfy);
2576 #endif /* MBEDTLS_X509_CRT_PARSE_C */
2577 
2594 void mbedtls_ssl_conf_read_timeout(mbedtls_ssl_config *conf, uint32_t timeout);
2595 
2640 int mbedtls_ssl_check_record(mbedtls_ssl_context const *ssl,
2641  unsigned char *buf,
2642  size_t buflen);
2643 
2664 void mbedtls_ssl_set_timer_cb(mbedtls_ssl_context *ssl,
2665  void *p_timer,
2666  mbedtls_ssl_set_timer_t *f_set_timer,
2667  mbedtls_ssl_get_timer_t *f_get_timer);
2668 
2669 #if defined(MBEDTLS_SSL_SRV_C)
2670 
2680 static inline void mbedtls_ssl_conf_cert_cb(mbedtls_ssl_config *conf,
2681  mbedtls_ssl_hs_cb_t f_cert_cb)
2682 {
2683  conf->MBEDTLS_PRIVATE(f_cert_cb) = f_cert_cb;
2684 }
2685 #endif /* MBEDTLS_SSL_SRV_C */
2706 typedef int mbedtls_ssl_ticket_write_t(void *p_ticket,
2707  const mbedtls_ssl_session *session,
2708  unsigned char *start,
2709  const unsigned char *end,
2710  size_t *tlen,
2711  uint32_t *lifetime);
2736 typedef int mbedtls_ssl_ticket_parse_t(void *p_ticket,
2737  mbedtls_ssl_session *session,
2738  unsigned char *buf,
2739  size_t len);
2740 
2741 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
2757  mbedtls_ssl_ticket_write_t *f_ticket_write,
2758  mbedtls_ssl_ticket_parse_t *f_ticket_parse,
2759  void *p_ticket);
2760 
2761 #if defined(MBEDTLS_HAVE_TIME)
2762 
2776  mbedtls_ssl_session *session, mbedtls_ms_time_t *ticket_creation_time)
2777 {
2778  if (session == NULL || ticket_creation_time == NULL ||
2779  session->MBEDTLS_PRIVATE(endpoint) != MBEDTLS_SSL_IS_SERVER) {
2781  }
2782 
2783  *ticket_creation_time = session->MBEDTLS_PRIVATE(ticket_creation_time);
2784 
2785  return 0;
2786 }
2787 #endif /* MBEDTLS_HAVE_TIME */
2788 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
2789 
2797 static inline unsigned const char (*mbedtls_ssl_session_get_id(const mbedtls_ssl_session *
2798  session))[32]
2799 {
2800  return &session->MBEDTLS_PRIVATE(id);
2801 }
2802 
2810 static inline size_t mbedtls_ssl_session_get_id_len(const mbedtls_ssl_session *session)
2811 {
2812  return session->MBEDTLS_PRIVATE(id_len);
2813 }
2814 
2822 static inline int mbedtls_ssl_session_get_ciphersuite_id(const mbedtls_ssl_session *session)
2823 {
2824  return session->MBEDTLS_PRIVATE(ciphersuite);
2825 }
2826 
2845 void mbedtls_ssl_set_export_keys_cb(mbedtls_ssl_context *ssl,
2846  mbedtls_ssl_export_keys_t *f_export_keys,
2847  void *p_export_keys);
2848 
2859 static inline void mbedtls_ssl_conf_set_user_data_p(
2860  mbedtls_ssl_config *conf,
2861  void *p)
2862 {
2863  conf->MBEDTLS_PRIVATE(user_data).p = p;
2864 }
2873 static inline void mbedtls_ssl_conf_set_user_data_n(
2874  mbedtls_ssl_config *conf,
2875  uintptr_t n)
2876 {
2877  conf->MBEDTLS_PRIVATE(user_data).n = n;
2878 }
2890 static inline void *mbedtls_ssl_conf_get_user_data_p(
2891  mbedtls_ssl_config *conf)
2892 {
2893  return conf->MBEDTLS_PRIVATE(user_data).p;
2894 }
2895 
2906 static inline uintptr_t mbedtls_ssl_conf_get_user_data_n(
2907  mbedtls_ssl_config *conf)
2908 {
2909  return conf->MBEDTLS_PRIVATE(user_data).n;
2910 }
2911 
2922 static inline void mbedtls_ssl_set_user_data_p(
2923  mbedtls_ssl_context *ssl,
2924  void *p)
2925 {
2926  ssl->MBEDTLS_PRIVATE(user_data).p = p;
2927 }
2936 static inline void mbedtls_ssl_set_user_data_n(
2937  mbedtls_ssl_context *ssl,
2938  uintptr_t n)
2939 {
2940  ssl->MBEDTLS_PRIVATE(user_data).n = n;
2941 }
2953 static inline void *mbedtls_ssl_get_user_data_p(
2954  mbedtls_ssl_context *ssl)
2955 {
2956  return ssl->MBEDTLS_PRIVATE(user_data).p;
2957 }
2958 
2969 static inline uintptr_t mbedtls_ssl_get_user_data_n(
2970  mbedtls_ssl_context *ssl)
2971 {
2972  return ssl->MBEDTLS_PRIVATE(user_data).n;
2973 }
2974 
2975 #if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
2976 
3006 void mbedtls_ssl_conf_async_private_cb(mbedtls_ssl_config *conf,
3007  mbedtls_ssl_async_sign_t *f_async_sign,
3008  mbedtls_ssl_async_decrypt_t *f_async_decrypt,
3009  mbedtls_ssl_async_resume_t *f_async_resume,
3010  mbedtls_ssl_async_cancel_t *f_async_cancel,
3011  void *config_data);
3012 
3021 void *mbedtls_ssl_conf_get_async_config_data(const mbedtls_ssl_config *conf);
3022 
3037 void *mbedtls_ssl_get_async_operation_data(const mbedtls_ssl_context *ssl);
3038 
3050 void mbedtls_ssl_set_async_operation_data(mbedtls_ssl_context *ssl,
3051  void *ctx);
3052 #endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
3053 
3068 typedef int mbedtls_ssl_cookie_write_t(void *ctx,
3069  unsigned char **p, unsigned char *end,
3070  const unsigned char *info, size_t ilen);
3071 
3085 typedef int mbedtls_ssl_cookie_check_t(void *ctx,
3086  const unsigned char *cookie, size_t clen,
3087  const unsigned char *info, size_t ilen);
3088 
3089 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
3090 
3119  mbedtls_ssl_cookie_write_t *f_cookie_write,
3120  mbedtls_ssl_cookie_check_t *f_cookie_check,
3121  void *p_cookie);
3122 
3142 int mbedtls_ssl_set_client_transport_id(mbedtls_ssl_context *ssl,
3143  const unsigned char *info,
3144  size_t ilen);
3145 
3146 #endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
3147 
3148 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
3149 
3165 #endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
3166 
3190 void mbedtls_ssl_conf_dtls_badmac_limit(mbedtls_ssl_config *conf, unsigned limit);
3191 
3192 #if defined(MBEDTLS_SSL_PROTO_DTLS)
3193 
3222 void mbedtls_ssl_set_datagram_packing(mbedtls_ssl_context *ssl,
3223  unsigned allow_packing);
3224 
3256 void mbedtls_ssl_conf_handshake_timeout(mbedtls_ssl_config *conf, uint32_t min, uint32_t max);
3257 #endif /* MBEDTLS_SSL_PROTO_DTLS */
3258 
3259 #if defined(MBEDTLS_SSL_SRV_C)
3260 
3298  void *p_cache,
3299  mbedtls_ssl_cache_get_t *f_get_cache,
3300  mbedtls_ssl_cache_set_t *f_set_cache);
3301 #endif /* MBEDTLS_SSL_SRV_C */
3302 
3303 #if defined(MBEDTLS_SSL_CLI_C)
3304 
3350 int mbedtls_ssl_set_session(mbedtls_ssl_context *ssl, const mbedtls_ssl_session *session);
3351 #endif /* MBEDTLS_SSL_CLI_C */
3352 
3385 int mbedtls_ssl_session_load(mbedtls_ssl_session *session,
3386  const unsigned char *buf,
3387  size_t len);
3388 
3422 int mbedtls_ssl_session_save(const mbedtls_ssl_session *session,
3423  unsigned char *buf,
3424  size_t buf_len,
3425  size_t *olen);
3426 
3469  const int *ciphersuites);
3470 
3471 #if defined(MBEDTLS_SSL_PROTO_TLS1_3)
3472 
3515  const int kex_modes);
3516 #endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
3517 
3518 #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
3519 #define MBEDTLS_SSL_UNEXPECTED_CID_IGNORE 0
3520 #define MBEDTLS_SSL_UNEXPECTED_CID_FAIL 1
3521 
3553 int mbedtls_ssl_conf_cid(mbedtls_ssl_config *conf, size_t len,
3554  int ignore_other_cids);
3555 #endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
3556 
3557 #if defined(MBEDTLS_X509_CRT_PARSE_C)
3558 
3569  const mbedtls_x509_crt_profile *profile);
3570 
3583  mbedtls_x509_crt *ca_chain,
3584  mbedtls_x509_crl *ca_crl);
3585 
3586 #if defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED)
3587 
3598 static inline
3600  const mbedtls_x509_crt *crt)
3601 {
3602  conf->MBEDTLS_PRIVATE(dn_hints) = crt;
3603 }
3604 #endif /* MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */
3606 #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
3607 
3658 void mbedtls_ssl_conf_ca_cb(mbedtls_ssl_config *conf,
3659  mbedtls_x509_crt_ca_cb_t f_ca_cb,
3660  void *p_ca_cb);
3661 #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
3662 
3700  mbedtls_x509_crt *own_cert,
3701  mbedtls_pk_context *pk_key);
3702 #endif /* MBEDTLS_X509_CRT_PARSE_C */
3703 
3704 #if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
3705 
3738  const unsigned char *psk, size_t psk_len,
3739  const unsigned char *psk_identity, size_t psk_identity_len);
3740 
3741 #if defined(MBEDTLS_USE_PSA_CRYPTO)
3742 
3779 int mbedtls_ssl_conf_psk_opaque(mbedtls_ssl_config *conf,
3781  const unsigned char *psk_identity,
3782  size_t psk_identity_len);
3783 #endif /* MBEDTLS_USE_PSA_CRYPTO */
3784 
3801 int mbedtls_ssl_set_hs_psk(mbedtls_ssl_context *ssl,
3802  const unsigned char *psk, size_t psk_len);
3803 
3804 #if defined(MBEDTLS_USE_PSA_CRYPTO)
3805 
3825 int mbedtls_ssl_set_hs_psk_opaque(mbedtls_ssl_context *ssl,
3826  mbedtls_svc_key_id_t psk);
3827 #endif /* MBEDTLS_USE_PSA_CRYPTO */
3828 
3829 #if defined(MBEDTLS_SSL_SRV_C)
3830 
3869  int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *,
3870  size_t),
3871  void *p_psk);
3872 #endif /* MBEDTLS_SSL_SRV_C */
3873 #endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
3874 
3875 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C)
3876 
3890  const unsigned char *dhm_P, size_t P_len,
3891  const unsigned char *dhm_G, size_t G_len);
3892 
3903 #endif /* MBEDTLS_DHM_C && defined(MBEDTLS_SSL_SRV_C) */
3904 
3905 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
3906 
3915  unsigned int bitlen);
3916 #endif /* MBEDTLS_DHM_C && MBEDTLS_SSL_CLI_C */
3917 
3918 #if defined(MBEDTLS_ECP_C)
3919 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
3920 
3962  const mbedtls_ecp_group_id *curves);
3963 #endif /* MBEDTLS_DEPRECATED_REMOVED */
3964 #endif /* MBEDTLS_ECP_C */
3965 
4004  const uint16_t *groups);
4005 
4006 #if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
4007 #if !defined(MBEDTLS_DEPRECATED_REMOVED) && defined(MBEDTLS_SSL_PROTO_TLS1_2)
4008 
4040  const int *hashes);
4041 #endif /* !MBEDTLS_DEPRECATED_REMOVED && MBEDTLS_SSL_PROTO_TLS1_2 */
4042 
4056  const uint16_t *sig_algs);
4057 #endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
4058 
4059 #if defined(MBEDTLS_X509_CRT_PARSE_C)
4060 
4091 int mbedtls_ssl_set_hostname(mbedtls_ssl_context *ssl, const char *hostname);
4092 
4103 static inline const char *mbedtls_ssl_get_hostname(mbedtls_ssl_context *ssl)
4104 {
4105  return ssl->MBEDTLS_PRIVATE(hostname);
4106 }
4107 #endif /* MBEDTLS_X509_CRT_PARSE_C */
4108 
4109 #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
4110 
4128 const unsigned char *mbedtls_ssl_get_hs_sni(mbedtls_ssl_context *ssl,
4129  size_t *name_len);
4130 
4146 int mbedtls_ssl_set_hs_own_cert(mbedtls_ssl_context *ssl,
4147  mbedtls_x509_crt *own_cert,
4148  mbedtls_pk_context *pk_key);
4149 
4161 void mbedtls_ssl_set_hs_ca_chain(mbedtls_ssl_context *ssl,
4162  mbedtls_x509_crt *ca_chain,
4163  mbedtls_x509_crl *ca_crl);
4164 
4165 #if defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED)
4166 
4176 void mbedtls_ssl_set_hs_dn_hints(mbedtls_ssl_context *ssl,
4177  const mbedtls_x509_crt *crt);
4178 #endif /* MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */
4179 
4190 void mbedtls_ssl_set_hs_authmode(mbedtls_ssl_context *ssl,
4191  int authmode);
4192 
4216  int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *,
4217  size_t),
4218  void *p_sni);
4219 #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
4220 
4221 #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
4222 
4240 int mbedtls_ssl_set_hs_ecjpake_password(mbedtls_ssl_context *ssl,
4241  const unsigned char *pw,
4242  size_t pw_len);
4243 
4258 int mbedtls_ssl_set_hs_ecjpake_password_opaque(mbedtls_ssl_context *ssl,
4259  mbedtls_svc_key_id_t pwd);
4260 #endif /*MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
4261 
4262 #if defined(MBEDTLS_SSL_ALPN)
4263 
4275 int mbedtls_ssl_conf_alpn_protocols(mbedtls_ssl_config *conf, const char **protos);
4276 
4286 const char *mbedtls_ssl_get_alpn_protocol(const mbedtls_ssl_context *ssl);
4287 #endif /* MBEDTLS_SSL_ALPN */
4288 
4289 #if defined(MBEDTLS_SSL_DTLS_SRTP)
4290 #if defined(MBEDTLS_DEBUG_C)
4291 static inline const char *mbedtls_ssl_get_srtp_profile_as_string(mbedtls_ssl_srtp_profile profile)
4292 {
4293  switch (profile) {
4295  return "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80";
4297  return "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32";
4299  return "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80";
4301  return "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32";
4302  default: break;
4303  }
4304  return "";
4305 }
4306 #endif /* MBEDTLS_DEBUG_C */
4307 
4321  int support_mki_value);
4322 
4343  (mbedtls_ssl_config *conf,
4344  const mbedtls_ssl_srtp_profile *profiles);
4345 
4362 int mbedtls_ssl_dtls_srtp_set_mki_value(mbedtls_ssl_context *ssl,
4363  unsigned char *mki_value,
4364  uint16_t mki_len);
4383 void mbedtls_ssl_get_dtls_srtp_negotiation_result(const mbedtls_ssl_context *ssl,
4384  mbedtls_dtls_srtp_info *dtls_srtp_info);
4385 #endif /* MBEDTLS_SSL_DTLS_SRTP */
4386 
4387 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
4388 
4406  int minor);
4407 #endif /* MBEDTLS_DEPRECATED_REMOVED */
4408 
4421 static inline void mbedtls_ssl_conf_max_tls_version(mbedtls_ssl_config *conf,
4422  mbedtls_ssl_protocol_version tls_version)
4423 {
4424  conf->MBEDTLS_PRIVATE(max_tls_version) = tls_version;
4425 }
4426 
4427 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
4428 
4463  int minor);
4464 #endif /* MBEDTLS_DEPRECATED_REMOVED */
4465 
4478 static inline void mbedtls_ssl_conf_min_tls_version(mbedtls_ssl_config *conf,
4479  mbedtls_ssl_protocol_version tls_version)
4480 {
4481  conf->MBEDTLS_PRIVATE(min_tls_version) = tls_version;
4482 }
4483 
4484 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
4485 
4497 #endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
4498 
4499 #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
4500 
4512 #endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */
4513 
4514 #if defined(MBEDTLS_SSL_SRV_C)
4515 
4525  char cert_req_ca_list);
4526 #endif /* MBEDTLS_SSL_SRV_C */
4527 
4528 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
4529 
4567 int mbedtls_ssl_conf_max_frag_len(mbedtls_ssl_config *conf, unsigned char mfl_code);
4568 #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
4569 
4570 #if defined(MBEDTLS_SSL_SRV_C)
4571 
4581 #endif /* MBEDTLS_SSL_SRV_C */
4582 
4583 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
4584 
4594 void mbedtls_ssl_conf_session_tickets(mbedtls_ssl_config *conf, int use_tickets);
4595 
4596 #if defined(MBEDTLS_SSL_PROTO_TLS1_3)
4597 
4623  mbedtls_ssl_config *conf, int signal_new_session_tickets);
4624 
4625 #endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
4626 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
4627 
4628 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && \
4629  defined(MBEDTLS_SSL_SRV_C) && \
4630  defined(MBEDTLS_SSL_PROTO_TLS1_3)
4631 
4649  uint16_t num_tickets);
4650 #endif /* MBEDTLS_SSL_SESSION_TICKETS &&
4651  MBEDTLS_SSL_SRV_C &&
4652  MBEDTLS_SSL_PROTO_TLS1_3*/
4653 
4654 #if defined(MBEDTLS_SSL_RENEGOTIATION)
4655 
4672 void mbedtls_ssl_conf_renegotiation(mbedtls_ssl_config *conf, int renegotiation);
4673 #endif /* MBEDTLS_SSL_RENEGOTIATION */
4674 
4702 void mbedtls_ssl_conf_legacy_renegotiation(mbedtls_ssl_config *conf, int allow_legacy);
4703 
4704 #if defined(MBEDTLS_SSL_RENEGOTIATION)
4705 
4742 void mbedtls_ssl_conf_renegotiation_enforced(mbedtls_ssl_config *conf, int max_records);
4743 
4770  const unsigned char period[8]);
4771 #endif /* MBEDTLS_SSL_RENEGOTIATION */
4772 
4811 int mbedtls_ssl_check_pending(const mbedtls_ssl_context *ssl);
4812 
4828 size_t mbedtls_ssl_get_bytes_avail(const mbedtls_ssl_context *ssl);
4829 
4842 uint32_t mbedtls_ssl_get_verify_result(const mbedtls_ssl_context *ssl);
4843 
4851 int mbedtls_ssl_get_ciphersuite_id_from_ssl(const mbedtls_ssl_context *ssl);
4852 
4860 const char *mbedtls_ssl_get_ciphersuite(const mbedtls_ssl_context *ssl);
4861 
4862 
4875  const mbedtls_ssl_context *ssl)
4876 {
4877  return ssl->MBEDTLS_PRIVATE(tls_version);
4878 }
4879 
4887 const char *mbedtls_ssl_get_version(const mbedtls_ssl_context *ssl);
4888 
4897 int mbedtls_ssl_get_record_expansion(const mbedtls_ssl_context *ssl);
4898 
4924 int mbedtls_ssl_get_max_out_record_payload(const mbedtls_ssl_context *ssl);
4925 
4944 int mbedtls_ssl_get_max_in_record_payload(const mbedtls_ssl_context *ssl);
4945 
4946 #if defined(MBEDTLS_X509_CRT_PARSE_C)
4947 
4977 const mbedtls_x509_crt *mbedtls_ssl_get_peer_cert(const mbedtls_ssl_context *ssl);
4978 #endif /* MBEDTLS_X509_CRT_PARSE_C */
4979 
4980 #if defined(MBEDTLS_SSL_CLI_C)
4981 
5008 int mbedtls_ssl_get_session(const mbedtls_ssl_context *ssl,
5009  mbedtls_ssl_session *session);
5010 #endif /* MBEDTLS_SSL_CLI_C */
5011 
5101 int mbedtls_ssl_handshake(mbedtls_ssl_context *ssl);
5102 
5114 static inline int mbedtls_ssl_is_handshake_over(mbedtls_ssl_context *ssl)
5115 {
5116  return ssl->MBEDTLS_PRIVATE(state) >= MBEDTLS_SSL_HANDSHAKE_OVER;
5117 }
5118 
5154 int mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl);
5155 
5156 #if defined(MBEDTLS_SSL_RENEGOTIATION)
5157 
5180 int mbedtls_ssl_renegotiate(mbedtls_ssl_context *ssl);
5181 #endif /* MBEDTLS_SSL_RENEGOTIATION */
5182 
5280 int mbedtls_ssl_read(mbedtls_ssl_context *ssl, unsigned char *buf, size_t len);
5281 
5355 int mbedtls_ssl_write(mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len);
5356 
5373 int mbedtls_ssl_send_alert_message(mbedtls_ssl_context *ssl,
5374  unsigned char level,
5375  unsigned char message);
5389 int mbedtls_ssl_close_notify(mbedtls_ssl_context *ssl);
5390 
5391 #if defined(MBEDTLS_SSL_EARLY_DATA)
5392 
5393 #if defined(MBEDTLS_SSL_SRV_C)
5394 
5441 int mbedtls_ssl_read_early_data(mbedtls_ssl_context *ssl,
5442  unsigned char *buf, size_t len);
5443 #endif /* MBEDTLS_SSL_SRV_C */
5444 
5445 #if defined(MBEDTLS_SSL_CLI_C)
5446 
5530 int mbedtls_ssl_write_early_data(mbedtls_ssl_context *ssl,
5531  const unsigned char *buf, size_t len);
5532 
5559 int mbedtls_ssl_get_early_data_status(mbedtls_ssl_context *ssl);
5560 #endif /* MBEDTLS_SSL_CLI_C */
5561 
5562 #endif /* MBEDTLS_SSL_EARLY_DATA */
5563 
5569 void mbedtls_ssl_free(mbedtls_ssl_context *ssl);
5570 
5571 #if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION)
5572 
5628 int mbedtls_ssl_context_save(mbedtls_ssl_context *ssl,
5629  unsigned char *buf,
5630  size_t buf_len,
5631  size_t *olen);
5632 
5701 int mbedtls_ssl_context_load(mbedtls_ssl_context *ssl,
5702  const unsigned char *buf,
5703  size_t len);
5704 #endif /* MBEDTLS_SSL_CONTEXT_SERIALIZATION */
5705 
5717 
5734  int endpoint, int transport, int preset);
5735 
5742 
5748 void mbedtls_ssl_session_init(mbedtls_ssl_session *session);
5749 
5759 void mbedtls_ssl_session_free(mbedtls_ssl_session *session);
5760 
5777  const unsigned char *secret, size_t slen,
5778  const char *label,
5779  const unsigned char *random, size_t rlen,
5780  unsigned char *dstbuf, size_t dlen);
5781 
5782 #if defined(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT)
5783 /* Maximum value for key_len in mbedtls_ssl_export_keying material. Depending on the TLS
5784  * version and the negotiated ciphersuite, larger keys could in principle be exported,
5785  * but for simplicity, we define one limit that works in all cases. TLS 1.3 with SHA256
5786  * has the strictest limit: 255 blocks of SHA256 output, or 8160 bytes. */
5787 #define MBEDTLS_SSL_EXPORT_MAX_KEY_LEN 8160
5788 
5811 int mbedtls_ssl_export_keying_material(mbedtls_ssl_context *ssl,
5812  uint8_t *out, const size_t key_len,
5813  const char *label, const size_t label_len,
5814  const unsigned char *context, const size_t context_len,
5815  const int use_context);
5816 #endif
5817 #ifdef __cplusplus
5818 }
5819 #endif
5820 
5821 #endif /* ssl.h */
unsigned char _pms_ecdhe_psk[4+MBEDTLS_ECP_MAX_BYTES +MBEDTLS_PSK_MAX_LEN]
Definition: ssl.h:723
int mbedtls_ssl_tls_prf(const mbedtls_tls_prf_types prf, const unsigned char *secret, size_t slen, const char *label, const unsigned char *random, size_t rlen, unsigned char *dstbuf, size_t dlen)
TLS-PRF function for key derivation.
const unsigned char * mbedtls_ssl_get_hs_sni(mbedtls_ssl_context *ssl, size_t *name_len)
Retrieve SNI extension value for the current handshake. Available in f_cert_cb of mbedtls_ssl_conf_ce...
Public key container.
Definition: pk.h:220
#define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80
Definition: ssl.h:1244
void mbedtls_ssl_set_hs_ca_chain(mbedtls_ssl_context *ssl, mbedtls_x509_crt *ca_chain, mbedtls_x509_crl *ca_crl)
Set the data required to verify peer certificate for the current handshake.
int mbedtls_ssl_ticket_parse_t(void *p_ticket, mbedtls_ssl_session *session, unsigned char *buf, size_t len)
Callback type: parse and load session ticket.
Definition: ssl.h:2742
int mbedtls_f_rng_t(void *p_rng, unsigned char *output, size_t output_size)
The type of custom random generator (RNG) callbacks.
const char * mbedtls_ssl_get_ciphersuite_name(const int ciphersuite_id)
Return the name of the ciphersuite associated with the given ID.
void mbedtls_ssl_conf_encrypt_then_mac(mbedtls_ssl_config *conf, char etm)
Enable or disable Encrypt-then-MAC (Default: MBEDTLS_SSL_ETM_ENABLED)
int mbedtls_ssl_cookie_write_t(void *ctx, unsigned char **p, unsigned char *end, const unsigned char *info, size_t ilen)
Callback type: generate a cookie.
Definition: ssl.h:3074
int mbedtls_ssl_dtls_srtp_set_mki_value(mbedtls_ssl_context *ssl, unsigned char *mki_value, uint16_t mki_len)
Set the mki_value for the current DTLS-SRTP session.
int mbedtls_ssl_cookie_check_t(void *ctx, const unsigned char *cookie, size_t clen, const unsigned char *info, size_t ilen)
Callback type: verify a cookie.
Definition: ssl.h:3091
void mbedtls_ssl_set_timer_cb(mbedtls_ssl_context *ssl, void *p_timer, mbedtls_ssl_set_timer_t *f_set_timer, mbedtls_ssl_get_timer_t *f_get_timer)
Set the timer callbacks (Mandatory for DTLS.)
struct mbedtls_ssl_sig_hash_set_t mbedtls_ssl_sig_hash_set_t
Definition: ssl.h:920
uint16_t mbedtls_ssl_srtp_profile
Definition: ssl.h:1249
static int mbedtls_ssl_session_get_ciphersuite_id(const mbedtls_ssl_session *session)
Get the ciphersuite-id.
Definition: ssl.h:2828
void mbedtls_ssl_conf_extended_master_secret(mbedtls_ssl_config *conf, char ems)
Enable or disable Extended Master Secret negotiation. (Default: MBEDTLS_SSL_EXTENDED_MS_ENABLED) ...
int mbedtls_ssl_get_max_in_record_payload(const mbedtls_ssl_context *ssl)
Return the current maximum incoming record payload in bytes.
int mbedtls_ssl_send_t(void *ctx, const unsigned char *buf, size_t len)
Callback type: send data on the network.
Definition: ssl.h:819
#define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32
Definition: ssl.h:1245
void mbedtls_ssl_set_verify(mbedtls_ssl_context *ssl, int(*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), void *p_vrfy)
Set a connection-specific verification callback (optional).
int mbedtls_ssl_recv_t(void *ctx, unsigned char *buf, size_t len)
Callback type: receive data from the network.
Definition: ssl.h:843
This file provides an API for Elliptic Curves over GF(P) (ECP).
static void mbedtls_ssl_set_user_data_n(mbedtls_ssl_context *ssl, uintptr_t n)
Set the user data in an SSL context to an integer.
Definition: ssl.h:2942
#define MBEDTLS_ERR_SSL_BAD_INPUT_DATA
Definition: ssl.h:51
void mbedtls_ssl_conf_preference_order(mbedtls_ssl_config *conf, int order)
Pick the ciphersuites order according to the second parameter in the SSL Server module (MBEDTLS_SSL_S...
void mbedtls_ssl_export_keys_t(void *p_expkey, mbedtls_ssl_key_export_type type, const unsigned char *secret, size_t secret_len, const unsigned char client_random[32], const unsigned char server_random[32], mbedtls_tls_prf_types tls_prf_type)
Callback type: Export key alongside random values for session identification, and PRF for implementat...
Definition: ssl.h:1420
Platform Security Architecture cryptography module.
unsigned char _pms_dhm[MBEDTLS_MPI_MAX_SIZE]
Definition: ssl.h:703
void mbedtls_ssl_conf_verify(mbedtls_ssl_config *conf, int(*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), void *p_vrfy)
Set the verification callback (Optional).
unsigned char _pms_rsa[48]
Definition: ssl.h:700
unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]
Definition: ssl.h:709
static const mbedtls_ssl_config * mbedtls_ssl_context_get_config(const mbedtls_ssl_context *ssl)
Return the SSL configuration structure associated with the given SSL context.
Definition: ssl.h:2304
static const char * mbedtls_ssl_get_hostname(mbedtls_ssl_context *ssl)
Get the hostname that checked against the received server certificate. It is used to set the ServerNa...
Definition: ssl.h:4109
int mbedtls_ssl_get_max_out_record_payload(const mbedtls_ssl_context *ssl)
Return the current maximum outgoing record payload in bytes.
void mbedtls_ssl_conf_renegotiation(mbedtls_ssl_config *conf, int renegotiation)
Enable / Disable renegotiation support for connection when initiated by peer (Default: MBEDTLS_SSL_RE...
static void mbedtls_ssl_conf_cert_cb(mbedtls_ssl_config *conf, mbedtls_ssl_hs_cb_t f_cert_cb)
Set the certificate selection callback (server-side only).
Definition: ssl.h:2686
int mbedtls_ssl_conf_dh_param_bin(mbedtls_ssl_config *conf, const unsigned char *dhm_P, size_t P_len, const unsigned char *dhm_G, size_t G_len)
Set the Diffie-Hellman public P and G values from big-endian binary presentations. (Default values: MBEDTLS_DHM_RFC3526_MODP_2048_[PG]_BIN)
void mbedtls_ssl_conf_sni(mbedtls_ssl_config *conf, int(*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *, size_t), void *p_sni)
Set server side ServerName TLS extension callback (optional, server-side only).
#define MBEDTLS_PRIVATE(member)
void mbedtls_ssl_conf_dtls_anti_replay(mbedtls_ssl_config *conf, char mode)
Enable or disable anti-replay protection for DTLS. (DTLS only, no effect on TLS.) Default: enabled...
int(* mbedtls_x509_crt_ca_cb_t)(void *p_ctx, mbedtls_x509_crt const *child, mbedtls_x509_crt **candidate_cas)
The type of trusted certificate callbacks.
Definition: x509_crt.h:784
void mbedtls_ssl_conf_srtp_mki_value_supported(mbedtls_ssl_config *conf, int support_mki_value)
Manage support for mki(master key id) value in use_srtp extension. MKI is an optional part of SRTP us...
#define MBEDTLS_TLS_SRTP_MAX_MKI_LENGTH
Definition: ssl.h:1231
uint32_t mbedtls_ssl_get_verify_result(const mbedtls_ssl_context *ssl)
Return the result of the certificate verification.
void mbedtls_ssl_conf_session_tickets_cb(mbedtls_ssl_config *conf, mbedtls_ssl_ticket_write_t *f_ticket_write, mbedtls_ssl_ticket_parse_t *f_ticket_parse, void *p_ticket)
Configure SSL session ticket callbacks (server only). (Default: none.)
int mbedtls_ssl_set_cid(mbedtls_ssl_context *ssl, int enable, unsigned char const *own_cid, size_t own_cid_len)
Configure the use of the Connection ID (CID) extension in the next handshake.
int mbedtls_ssl_check_pending(const mbedtls_ssl_context *ssl)
Check if there is data already read from the underlying transport but not yet processed.
static uintptr_t mbedtls_ssl_get_user_data_n(mbedtls_ssl_context *ssl)
Retrieve the user data in an SSL context as an integer.
Definition: ssl.h:2975
const mbedtls_x509_crt * mbedtls_ssl_get_peer_cert(const mbedtls_ssl_context *ssl)
Return the peer certificate from the current connection.
int mbedtls_ssl_session_save(const mbedtls_ssl_session *session, unsigned char *buf, size_t buf_len, size_t *olen)
Save session structure as serialized data in a buffer. On client, this can be used for saving session...
int mbedtls_ssl_send_alert_message(mbedtls_ssl_context *ssl, unsigned char level, unsigned char message)
Send an alert message.
int mbedtls_ssl_recv_timeout_t(void *ctx, unsigned char *buf, size_t len, uint32_t timeout)
Callback type: receive data from the network, with timeout.
Definition: ssl.h:869
SSL Ciphersuites for Mbed TLS.
void mbedtls_ssl_conf_session_cache(mbedtls_ssl_config *conf, void *p_cache, mbedtls_ssl_cache_get_t *f_get_cache, mbedtls_ssl_cache_set_t *f_set_cache)
Set the session cache callbacks (server-side only) If not set, no session resuming is done (except if...
void mbedtls_ssl_conf_renegotiation_period(mbedtls_ssl_config *conf, const unsigned char period[8])
Set record counter threshold for periodic renegotiation. (Default: 2^48 - 1)
unsigned char _pms_dhe_psk[4+MBEDTLS_MPI_MAX_SIZE +MBEDTLS_PSK_MAX_LEN]
Definition: ssl.h:716
void mbedtls_ssl_conf_sig_algs(mbedtls_ssl_config *conf, const uint16_t *sig_algs)
Configure allowed signature algorithms for use in TLS.
int mbedtls_ssl_cache_set_t(void *data, unsigned char const *session_id, size_t session_id_len, const mbedtls_ssl_session *session)
Callback type: server-side session cache setter.
Definition: ssl.h:986
Multi-precision integer library.
int mbedtls_ssl_conf_psk(mbedtls_ssl_config *conf, const unsigned char *psk, size_t psk_len, const unsigned char *psk_identity, size_t psk_identity_len)
Configure pre-shared keys (PSKs) and their identities to be used in PSK-based ciphersuites.
int mbedtls_ssl_conf_max_frag_len(mbedtls_ssl_config *conf, unsigned char mfl_code)
Set the maximum fragment length to emit and/or negotiate. (Typical: the smaller of MBEDTLS_SSL_IN_CON...
Common and shared functions used by multiple modules in the Mbed TLS library.
time_t mbedtls_time_t
Definition: platform_time.h:27
int mbedtls_ssl_write(mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len)
Try to write exactly 'len' application data bytes.
void mbedtls_ssl_conf_cert_req_ca_list(mbedtls_ssl_config *conf, char cert_req_ca_list)
Whether to send a list of acceptable CAs in CertificateRequest messages. (Default: do send) ...
void MBEDTLS_DEPRECATED mbedtls_ssl_conf_curves(mbedtls_ssl_config *conf, const mbedtls_ecp_group_id *curves)
Set the allowed curves in order of preference.
int mbedtls_ssl_close_notify(mbedtls_ssl_context *ssl)
Notify the peer that the connection is being closed.
struct mbedtls_ssl_flight_item mbedtls_ssl_flight_item
Definition: ssl.h:925
int mbedtls_ssl_cache_get_t(void *data, unsigned char const *session_id, size_t session_id_len, mbedtls_ssl_session *session)
Callback type: server-side session cache getter.
Definition: ssl.h:964
void mbedtls_ssl_conf_session_tickets(mbedtls_ssl_config *conf, int use_tickets)
Enable / Disable TLS 1.2 session tickets (client only, TLS 1.2 only). Enabled by default.
static void mbedtls_ssl_conf_dn_hints(mbedtls_ssl_config *conf, const mbedtls_x509_crt *crt)
Set DN hints sent to client in CertificateRequest message.
Definition: ssl.h:3605
void mbedtls_ssl_free(mbedtls_ssl_context *ssl)
Free referenced items in an SSL context and clear memory.
void mbedtls_ssl_conf_endpoint(mbedtls_ssl_config *conf, int endpoint)
Set the current endpoint type.
void mbedtls_ssl_session_free(mbedtls_ssl_session *session)
Free referenced items in an SSL session including the peer certificate and clear memory.
mbedtls_ssl_protocol_version
Definition: ssl.h:1264
static void * mbedtls_ssl_get_user_data_p(mbedtls_ssl_context *ssl)
Retrieve the user data in an SSL context as a pointer.
Definition: ssl.h:2959
struct mbedtls_ssl_transform mbedtls_ssl_transform
Definition: ssl.h:918
#define MBEDTLS_TLS1_3_MD_MAX_SIZE
Definition: ssl.h:732
const char * mbedtls_ssl_get_alpn_protocol(const mbedtls_ssl_context *ssl)
Get the name of the negotiated Application Layer Protocol. This function should be called after the h...
void mbedtls_ssl_conf_dhm_min_bitlen(mbedtls_ssl_config *conf, unsigned int bitlen)
Set the minimum length for Diffie-Hellman parameters. (Client-side only.) (Default: 1024 bits...
int mbedtls_ssl_get_ciphersuite_id_from_ssl(const mbedtls_ssl_context *ssl)
Return the id of the current ciphersuite.
void mbedtls_ssl_conf_dtls_cookies(mbedtls_ssl_config *conf, mbedtls_ssl_cookie_write_t *f_cookie_write, mbedtls_ssl_cookie_check_t *f_cookie_check, void *p_cookie)
Register callbacks for DTLS cookies (Server only. DTLS only.)
int mbedtls_ssl_conf_cid(mbedtls_ssl_config *conf, size_t len, int ignore_other_cids)
Specify the length of Connection IDs for incoming encrypted DTLS records, as well as the behaviour on...
static int mbedtls_ssl_session_get_ticket_creation_time(mbedtls_ssl_session *session, mbedtls_ms_time_t *ticket_creation_time)
Get the creation time of a session ticket.
Definition: ssl.h:2781
int mbedtls_ssl_get_ciphersuite_id(const char *ciphersuite_name)
Return the ID of the ciphersuite associated with the given name.
void mbedtls_ssl_conf_transport(mbedtls_ssl_config *conf, int transport)
Set the transport type (TLS or DTLS). Default: TLS.
mbedtls_ssl_key_export_type
Definition: ssl.h:1393
void mbedtls_ssl_get_dtls_srtp_negotiation_result(const mbedtls_ssl_context *ssl, mbedtls_dtls_srtp_info *dtls_srtp_info)
Get the negotiated DTLS-SRTP information: Protection profile and MKI value.
mbedtls_ssl_states
Definition: ssl.h:753
#define MBEDTLS_SSL_IS_SERVER
Definition: ssl.h:325
#define MBEDTLS_SSL_SEQUENCE_NUMBER_LEN
Definition: ssl.h:736
void mbedtls_ssl_conf_renegotiation_enforced(mbedtls_ssl_config *conf, int max_records)
Enforce renegotiation requests. (Default: enforced, max_records = 16)
void mbedtls_ssl_set_mtu(mbedtls_ssl_context *ssl, uint16_t mtu)
Set the Maximum Transport Unit (MTU). Special value: 0 means unset (no limit). This represents the ma...
int mbedtls_ssl_set_client_transport_id(mbedtls_ssl_context *ssl, const unsigned char *info, size_t ilen)
Set client's transport-level identification info. (Server only. DTLS only.)
void mbedtls_ssl_set_bio(mbedtls_ssl_context *ssl, void *p_bio, mbedtls_ssl_send_t *f_send, mbedtls_ssl_recv_t *f_recv, mbedtls_ssl_recv_timeout_t *f_recv_timeout)
Set the underlying BIO callbacks for write, read and read-with-timeout.
Macro wrapper for struct's members.
static uintptr_t mbedtls_ssl_conf_get_user_data_n(mbedtls_ssl_config *conf)
Retrieve the user data in an SSL configuration as an integer.
Definition: ssl.h:2912
void mbedtls_ssl_conf_new_session_tickets(mbedtls_ssl_config *conf, uint16_t num_tickets)
Number of NewSessionTicket messages for the server to send after handshake completion.
int mbedtls_ssl_context_save(mbedtls_ssl_context *ssl, unsigned char *buf, size_t buf_len, size_t *olen)
Save an active connection as serialized data in a buffer. This allows the freeing or re-using of the ...
int mbedtls_ssl_conf_alpn_protocols(mbedtls_ssl_config *conf, const char **protos)
Set the supported Application Layer Protocols.
void mbedtls_ssl_conf_cert_profile(mbedtls_ssl_config *conf, const mbedtls_x509_crt_profile *profile)
Set the X.509 security profile used for verification.
This file contains Diffie-Hellman-Merkle (DHM) key exchange definitions and functions.
X.509 certificate parsing and writing.
int mbedtls_ssl_context_load(mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len)
Load serialized connection data to an SSL context.
#define MBEDTLS_PSK_MAX_LEN
Definition: ssl.h:690
void mbedtls_ssl_init(mbedtls_ssl_context *ssl)
Initialize an SSL context Just makes the context ready for mbedtls_ssl_setup() or mbedtls_ssl_free() ...
const char * mbedtls_ssl_get_ciphersuite(const mbedtls_ssl_context *ssl)
Return the name of the current ciphersuite.
static unsigned const char(* mbedtls_ssl_session_get_id(const mbedtls_ssl_session *session))[32]
Get the session-id buffer.
Definition: ssl.h:2803
#define MBEDTLS_DEPRECATED
Definition: platform_util.h:37
void mbedtls_ssl_set_export_keys_cb(mbedtls_ssl_context *ssl, mbedtls_ssl_export_keys_t *f_export_keys, void *p_export_keys)
Configure a key export callback. (Default: none.)
mbedtls_ecp_group_id
Definition: ecp.h:102
int mbedtls_ssl_get_timer_t(void *ctx)
Callback type: get status of timers/delays.
Definition: ssl.h:910
The DHM context structure.
Definition: dhm.h:101
int mbedtls_ssl_get_own_cid(mbedtls_ssl_context *ssl, int *enabled, unsigned char own_cid[MBEDTLS_SSL_CID_IN_LEN_MAX], size_t *own_cid_len)
Get information about our request for usage of the CID extension in the current connection.
void mbedtls_ssl_conf_dbg(mbedtls_ssl_config *conf, void(*f_dbg)(void *, int, const char *, int, const char *), void *p_dbg)
Set the debug callback.
int(* mbedtls_ssl_hs_cb_t)(mbedtls_ssl_context *ssl)
Callback type: generic handshake callback.
Definition: ssl.h:1444
void mbedtls_ssl_config_init(mbedtls_ssl_config *conf)
Initialize an SSL configuration context Just makes the context ready for mbedtls_ssl_config_defaults(...
static void mbedtls_ssl_conf_set_user_data_n(mbedtls_ssl_config *conf, uintptr_t n)
Set the user data in an SSL configuration to an integer.
Definition: ssl.h:2879
int mbedtls_ssl_get_record_expansion(const mbedtls_ssl_context *ssl)
Return the (maximum) number of bytes added by the record layer: header + encryption/MAC overhead (inc...
Build-time configuration info.
This file contains ECDH definitions and functions.
int mbedtls_ssl_conf_dh_param_ctx(mbedtls_ssl_config *conf, mbedtls_dhm_context *dhm_ctx)
Set the Diffie-Hellman public P and G values, read from existing context (server-side only) ...
void mbedtls_ssl_conf_groups(mbedtls_ssl_config *conf, const uint16_t *groups)
Set the allowed groups in order of preference.
int mbedtls_ssl_set_session(mbedtls_ssl_context *ssl, const mbedtls_ssl_session *session)
Load a session for session resumption.
#define MBEDTLS_MPI_MAX_SIZE
Definition: bignum.h:74
void MBEDTLS_DEPRECATED mbedtls_ssl_conf_sig_hashes(mbedtls_ssl_config *conf, const int *hashes)
Set the allowed hashes for signatures during the handshake.
void mbedtls_ssl_set_datagram_packing(mbedtls_ssl_context *ssl, unsigned allow_packing)
Allow or disallow packing of multiple handshake records within a single datagram. ...
static void * mbedtls_ssl_conf_get_user_data_p(mbedtls_ssl_config *conf)
Retrieve the user data in an SSL configuration as a pointer.
Definition: ssl.h:2896
int mbedtls_ssl_set_hs_own_cert(mbedtls_ssl_context *ssl, mbedtls_x509_crt *own_cert, mbedtls_pk_context *pk_key)
Set own certificate and key for the current handshake.
This file contains the generic functions for message-digest (hashing) and HMAC.
int mbedtls_ssl_conf_own_cert(mbedtls_ssl_config *conf, mbedtls_x509_crt *own_cert, mbedtls_pk_context *pk_key)
Set own certificate chain and private key.
static const char * mbedtls_ssl_get_srtp_profile_as_string(mbedtls_ssl_srtp_profile profile)
Definition: ssl.h:4297
psa_key_id_t mbedtls_svc_key_id_t
Definition: crypto_types.h:292
int mbedtls_ssl_setup(mbedtls_ssl_context *ssl, const mbedtls_ssl_config *conf)
Set up an SSL context for use.
void MBEDTLS_DEPRECATED mbedtls_ssl_conf_max_version(mbedtls_ssl_config *conf, int major, int minor)
Set the maximum supported version sent from the client side and/or accepted at the server side...
void mbedtls_ssl_conf_legacy_renegotiation(mbedtls_ssl_config *conf, int allow_legacy)
Prevent or allow legacy renegotiation. (Default: MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION) ...
static void mbedtls_ssl_set_user_data_p(mbedtls_ssl_context *ssl, void *p)
Set the user data in an SSL context to a pointer.
Definition: ssl.h:2928
unsigned char _pms_rsa_psk[52+MBEDTLS_PSK_MAX_LEN]
Definition: ssl.h:719
int mbedtls_ssl_renegotiate(mbedtls_ssl_context *ssl)
Initiate an SSL renegotiation on the running connection. Client: perform the renegotiation right now...
#define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32
Definition: ssl.h:1243
static void mbedtls_ssl_conf_set_user_data_p(mbedtls_ssl_config *conf, void *p)
Set the user data in an SSL configuration to a pointer.
Definition: ssl.h:2865
MPI structure.
Definition: bignum.h:208
X.509 certificate revocation list parsing.
void mbedtls_ssl_conf_rng(mbedtls_ssl_config *conf, mbedtls_f_rng_t *f_rng, void *p_rng)
Set the random number generator callback.
void mbedtls_ssl_conf_read_timeout(mbedtls_ssl_config *conf, uint32_t timeout)
Set the timeout period for mbedtls_ssl_read() (Default: no timeout.)
void mbedtls_ssl_config_free(mbedtls_ssl_config *conf)
Free an SSL configuration context.
int mbedtls_ssl_conf_dtls_srtp_protection_profiles(mbedtls_ssl_config *conf, const mbedtls_ssl_srtp_profile *profiles)
Set the supported DTLS-SRTP protection profiles.
#define MBEDTLS_SSL_CID_OUT_LEN_MAX
Definition: ssl.h:461
int mbedtls_ssl_read(mbedtls_ssl_context *ssl, unsigned char *buf, size_t len)
Read at most 'len' application data bytes.
unsigned char dummy
Definition: ssl.h:698
struct mbedtls_ssl_key_cert mbedtls_ssl_key_cert
Definition: ssl.h:922
static mbedtls_ssl_protocol_version mbedtls_ssl_get_version_number(const mbedtls_ssl_context *ssl)
Return the (D)TLS protocol version negotiated in the given connection.
Definition: ssl.h:4880
void mbedtls_ssl_set_timer_t(void *ctx, uint32_t int_ms, uint32_t fin_ms)
Callback type: set a pair of timers/delays to watch.
Definition: ssl.h:895
static int mbedtls_ssl_conf_get_endpoint(const mbedtls_ssl_config *conf)
Get the current endpoint type.
Definition: ssl.h:2130
size_t mbedtls_ssl_get_bytes_avail(const mbedtls_ssl_context *ssl)
Return the number of application data bytes remaining to be read from the current record...
#define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80
Definition: ssl.h:1242
void mbedtls_ssl_conf_tls13_key_exchange_modes(mbedtls_ssl_config *conf, const int kex_modes)
Set the supported key exchange modes for TLS 1.3 connections.
#define MBEDTLS_SSL_CID_IN_LEN_MAX
Definition: ssl.h:457
int mbedtls_ssl_get_peer_cid(mbedtls_ssl_context *ssl, int *enabled, unsigned char peer_cid[MBEDTLS_SSL_CID_OUT_LEN_MAX], size_t *peer_cid_len)
Get information about the use of the CID extension in the current connection.
void mbedtls_ssl_session_init(mbedtls_ssl_session *session)
Initialize SSL session structure.
struct mbedtls_dtls_srtp_info_t mbedtls_dtls_srtp_info
void mbedtls_ssl_conf_tls13_enable_signal_new_session_tickets(mbedtls_ssl_config *conf, int signal_new_session_tickets)
Enable / Disable handling of TLS 1.3 NewSessionTicket messages (client only, TLS 1.3 only).
int mbedtls_ssl_ticket_write_t(void *p_ticket, const mbedtls_ssl_session *session, unsigned char *start, const unsigned char *end, size_t *tlen, uint32_t *lifetime)
Callback type: generate and write session ticket.
Definition: ssl.h:2712
static int mbedtls_ssl_is_handshake_over(mbedtls_ssl_context *ssl)
After calling mbedtls_ssl_handshake() to start the SSL handshake you can call this function to check ...
Definition: ssl.h:5120
void mbedtls_ssl_conf_handshake_timeout(mbedtls_ssl_config *conf, uint32_t min, uint32_t max)
Set retransmit timeout values for the DTLS handshake. (DTLS only, no effect on TLS.)
Mbed TLS Platform time abstraction.
int mbedtls_ssl_config_defaults(mbedtls_ssl_config *conf, int endpoint, int transport, int preset)
Load reasonable default SSL configuration values. (You need to call mbedtls_ssl_config_init() first...
void mbedtls_ssl_conf_ca_chain(mbedtls_ssl_config *conf, mbedtls_x509_crt *ca_chain, mbedtls_x509_crl *ca_crl)
Set the data required to verify peer certificate.
static size_t mbedtls_ssl_session_get_id_len(const mbedtls_ssl_session *session)
Get the size of the session-id.
Definition: ssl.h:2816
int64_t mbedtls_ms_time_t
Definition: platform_time.h:35
void mbedtls_ssl_conf_dtls_badmac_limit(mbedtls_ssl_config *conf, unsigned limit)
Set a limit on the number of records with a bad MAC before terminating the connection. (DTLS only, no effect on TLS.) Default: 0 (disabled).
unsigned char _pms_psk[4+2 *MBEDTLS_PSK_MAX_LEN]
Definition: ssl.h:712
int mbedtls_ssl_handshake(mbedtls_ssl_context *ssl)
Perform the SSL handshake.
int mbedtls_ssl_export_keying_material(mbedtls_ssl_context *ssl, uint8_t *out, const size_t key_len, const char *label, const size_t label_len, const unsigned char *context, const size_t context_len, const int use_context)
TLS-Exporter to derive shared symmetric keys between server and client.
void mbedtls_ssl_set_hs_authmode(mbedtls_ssl_context *ssl, int authmode)
Set authmode for the current handshake.
mbedtls_md_type_t
Supported message digests.
Definition: md.h:47
int mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl)
Perform a single step of the SSL handshake.
const char * mbedtls_ssl_get_version(const mbedtls_ssl_context *ssl)
Return the current TLS version.
void mbedtls_ssl_conf_authmode(mbedtls_ssl_config *conf, int authmode)
Set the certificate verification mode Default: NONE on server, REQUIRED on client.
#define MBEDTLS_SSL_TLS1_3_TICKET_RESUMPTION_KEY_LEN
Definition: ssl.h:386
int mbedtls_ssl_session_reset(mbedtls_ssl_context *ssl)
Reset an already initialized SSL context for re-use while retaining application-set variables...
int mbedtls_ssl_set_hostname(mbedtls_ssl_context *ssl, const char *hostname)
Set or reset the hostname to check against the received peer certificate. On a client, this also sets the ServerName TLS extension, if that extension is enabled. On a TLS 1.3 client, this also sets the server name in the session resumption ticket, if that feature is enabled.
struct mbedtls_ssl_handshake_params mbedtls_ssl_handshake_params
Definition: ssl.h:919
static void mbedtls_ssl_conf_min_tls_version(mbedtls_ssl_config *conf, mbedtls_ssl_protocol_version tls_version)
Set the minimum supported version sent from the client side and/or accepted at the server side...
Definition: ssl.h:4484
static void mbedtls_ssl_conf_max_tls_version(mbedtls_ssl_config *conf, mbedtls_ssl_protocol_version tls_version)
Set the maximum supported version sent from the client side and/or accepted at the server side...
Definition: ssl.h:4427
#define MBEDTLS_ECP_MAX_BYTES
Definition: ecp.h:354
int mbedtls_ssl_session_load(mbedtls_ssl_session *session, const unsigned char *buf, size_t len)
Load serialized session data into a session structure. On client, this can be used for loading saved ...
int mbedtls_ssl_set_hs_psk(mbedtls_ssl_context *ssl, const unsigned char *psk, size_t psk_len)
Set the pre-shared Key (PSK) for the current handshake.
void MBEDTLS_DEPRECATED mbedtls_ssl_conf_min_version(mbedtls_ssl_config *conf, int major, int minor)
Set the minimum accepted SSL/TLS protocol version.
int mbedtls_ssl_get_session(const mbedtls_ssl_context *ssl, mbedtls_ssl_session *session)
Export a session in order to resume it later.
void mbedtls_ssl_conf_ciphersuites(mbedtls_ssl_config *conf, const int *ciphersuites)
Set the list of allowed ciphersuites and the preference order. First in the list has the highest pref...
#define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN
Definition: ssl.h:497
void mbedtls_ssl_set_hs_dn_hints(mbedtls_ssl_context *ssl, const mbedtls_x509_crt *crt)
Set DN hints sent to client in CertificateRequest message.
void mbedtls_ssl_conf_psk_cb(mbedtls_ssl_config *conf, int(*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t), void *p_psk)
Set the PSK callback (server-side only).
mbedtls_tls_prf_types
Definition: ssl.h:1384
int mbedtls_ssl_check_record(mbedtls_ssl_context const *ssl, unsigned char *buf, size_t buflen)
Check whether a buffer contains a valid and authentic record that has not been seen before...