Mbed TLS v4.1.2
Loading...
Searching...
No Matches
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
13#include "mbedtls/private_access.h"
14
15#include "mbedtls/build_info.h"
16
18
19#if defined(MBEDTLS_X509_CRT_PARSE_C)
20#include "mbedtls/x509_crt.h"
21#include "mbedtls/x509_crl.h"
22#endif
23
24#include "mbedtls/md.h"
25
26#if defined(MBEDTLS_HAVE_TIME)
28#endif
29
30#include "psa/crypto.h"
31
32/*
33 * SSL Error codes
34 */
36#define MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS -0x7000
38#define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080
40#define MBEDTLS_ERR_SSL_BAD_INPUT_DATA PSA_ERROR_INVALID_ARGUMENT
42#define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180
44#define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200
46#define MBEDTLS_ERR_SSL_CONN_EOF -0x7280
48#define MBEDTLS_ERR_SSL_DECODE_ERROR -0x7300
49/* Error space gap */
51#define MBEDTLS_ERR_SSL_NO_RNG -0x7400
53#define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480
55#define MBEDTLS_ERR_SSL_UNSUPPORTED_EXTENSION -0x7500
57#define MBEDTLS_ERR_SSL_NO_APPLICATION_PROTOCOL -0x7580
59#define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600
61#define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680
63#define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700
65#define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780
67#define MBEDTLS_ERR_SSL_UNRECOGNIZED_NAME -0x7800
69#define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880
70/* Error space gap */
71/* Error space gap */
73#define MBEDTLS_ERR_SSL_BAD_CERTIFICATE -0x7A00
74/* Error space gap */
79#define MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET -0x7B00
81#define MBEDTLS_ERR_SSL_CANNOT_READ_EARLY_DATA -0x7B80
91#define MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA -0x7C00
93#define MBEDTLS_ERR_SSL_CANNOT_WRITE_EARLY_DATA -0x7C80
94/* Error space gap */
95/* Error space gap */
96/* Error space gap */
97/* Error space gap */
99#define MBEDTLS_ERR_SSL_CACHE_ENTRY_NOT_FOUND -0x7E80
101#define MBEDTLS_ERR_SSL_ALLOC_FAILED PSA_ERROR_INSUFFICIENT_MEMORY
103#define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80
105#define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80
107#define MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION -0x6E80
109#define MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE -0x6E00
111#define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80
113#define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00
115#define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80
117#define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00
119#define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80
121#define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00
123#define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80
125#define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL PSA_ERROR_BUFFER_TOO_SMALL
126/* Error space gap */
128#define MBEDTLS_ERR_SSL_WANT_READ -0x6900
130#define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880
132#define MBEDTLS_ERR_SSL_TIMEOUT -0x6800
134#define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780
136#define MBEDTLS_ERR_SSL_UNEXPECTED_RECORD -0x6700
138#define MBEDTLS_ERR_SSL_NON_FATAL -0x6680
140#define MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER -0x6600
142#define MBEDTLS_ERR_SSL_CONTINUE_PROCESSING -0x6580
144#define MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS -0x6500
146#define MBEDTLS_ERR_SSL_EARLY_MESSAGE -0x6480
147/* Error space gap */
148/* Error space gap */
149/* Error space gap */
150/* Error space gap */
151/* Error space gap */
152/* Error space gap */
153/* Error space gap */
154/* Error space gap */
156#define MBEDTLS_ERR_SSL_UNEXPECTED_CID -0x6000
158#define MBEDTLS_ERR_SSL_VERSION_MISMATCH -0x5F00
160#define MBEDTLS_ERR_SSL_BAD_CONFIG -0x5E80
161/* Error space gap */
193#define MBEDTLS_ERR_SSL_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME -0x5D80
194
195/*
196 * Constants from RFC 8446 for TLS 1.3 PSK modes
197 *
198 * Those are used in the Pre-Shared Key Exchange Modes extension.
199 * See Section 4.2.9 in RFC 8446.
200 */
201#define MBEDTLS_SSL_TLS1_3_PSK_MODE_PURE 0 /* Pure PSK-based exchange */
202#define MBEDTLS_SSL_TLS1_3_PSK_MODE_ECDHE 1 /* PSK+ECDHE-based exchange */
203
204/*
205 * TLS 1.3 NamedGroup values
206 *
207 * From RF 8446
208 * enum {
209 * // Elliptic Curve Groups (ECDHE)
210 * secp256r1(0x0017), secp384r1(0x0018), secp521r1(0x0019),
211 * x25519(0x001D), x448(0x001E),
212 * // Finite Field Groups (DHE)
213 * ffdhe2048(0x0100), ffdhe3072(0x0101), ffdhe4096(0x0102),
214 * ffdhe6144(0x0103), ffdhe8192(0x0104),
215 * // Reserved Code Points
216 * ffdhe_private_use(0x01FC..0x01FF),
217 * ecdhe_private_use(0xFE00..0xFEFF),
218 * (0xFFFF)
219 * } NamedGroup;
220 *
221 */
222
223/* Elliptic Curve Groups (ECDHE) */
224#define MBEDTLS_SSL_IANA_TLS_GROUP_NONE 0
225#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP256K1 0x0016
226#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1 0x0017
227#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1 0x0018
228#define MBEDTLS_SSL_IANA_TLS_GROUP_SECP521R1 0x0019
229#define MBEDTLS_SSL_IANA_TLS_GROUP_BP256R1 0x001A
230#define MBEDTLS_SSL_IANA_TLS_GROUP_BP384R1 0x001B
231#define MBEDTLS_SSL_IANA_TLS_GROUP_BP512R1 0x001C
232#define MBEDTLS_SSL_IANA_TLS_GROUP_X25519 0x001D
233#define MBEDTLS_SSL_IANA_TLS_GROUP_X448 0x001E
234/* Finite Field Groups (DHE) */
235#define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE2048 0x0100
236#define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE3072 0x0101
237#define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE4096 0x0102
238#define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE6144 0x0103
239#define MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE8192 0x0104
240
241/*
242 * TLS 1.3 Key Exchange Modes
243 *
244 * Mbed TLS internal identifiers for use with the SSL configuration API
245 * mbedtls_ssl_conf_tls13_key_exchange_modes().
246 */
247
248#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK (1u << 0)
251#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL (1u << 1)
254#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL (1u << 2)
257
258/* Convenience macros for sets of key exchanges. */
259#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_ALL \
260 (MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK | \
261 MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL | \
262 MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL)
263#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ALL \
264 (MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK | \
265 MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL)
266#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ALL \
267 (MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL | \
268 MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL)
269
270#define MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_NONE (0)
271
272/*
273 * Various constants
274 */
275
276
277#define MBEDTLS_SSL_TRANSPORT_STREAM 0
278#define MBEDTLS_SSL_TRANSPORT_DATAGRAM 1
279
280#define MBEDTLS_SSL_MAX_HOST_NAME_LEN 255
281#define MBEDTLS_SSL_MAX_ALPN_NAME_LEN 255
282
283#define MBEDTLS_SSL_MAX_ALPN_LIST_LEN 65535
284
285/* RFC 6066 section 4, see also mfl_code_to_length in ssl_tls.c
286 * NONE must be zero so that memset()ing structure to zero works */
287#define MBEDTLS_SSL_MAX_FRAG_LEN_NONE 0
288#define MBEDTLS_SSL_MAX_FRAG_LEN_512 1
289#define MBEDTLS_SSL_MAX_FRAG_LEN_1024 2
290#define MBEDTLS_SSL_MAX_FRAG_LEN_2048 3
291#define MBEDTLS_SSL_MAX_FRAG_LEN_4096 4
292#define MBEDTLS_SSL_MAX_FRAG_LEN_INVALID 5
293
294#define MBEDTLS_SSL_IS_CLIENT 0
295#define MBEDTLS_SSL_IS_SERVER 1
296
297#define MBEDTLS_SSL_EXTENDED_MS_DISABLED 0
298#define MBEDTLS_SSL_EXTENDED_MS_ENABLED 1
299
300#define MBEDTLS_SSL_CID_DISABLED 0
301#define MBEDTLS_SSL_CID_ENABLED 1
302
303#define MBEDTLS_SSL_ETM_DISABLED 0
304#define MBEDTLS_SSL_ETM_ENABLED 1
305
306#define MBEDTLS_SSL_COMPRESS_NULL 0
307
308#define MBEDTLS_SSL_VERIFY_NONE 0
309#define MBEDTLS_SSL_VERIFY_OPTIONAL 1
310#define MBEDTLS_SSL_VERIFY_REQUIRED 2
311#define MBEDTLS_SSL_VERIFY_UNSET 3 /* Used only for sni_authmode */
312
313#define MBEDTLS_SSL_LEGACY_RENEGOTIATION 0
314#define MBEDTLS_SSL_SECURE_RENEGOTIATION 1
315
316#define MBEDTLS_SSL_RENEGOTIATION_DISABLED 0
317#define MBEDTLS_SSL_RENEGOTIATION_ENABLED 1
318
319#define MBEDTLS_SSL_ANTI_REPLAY_DISABLED 0
320#define MBEDTLS_SSL_ANTI_REPLAY_ENABLED 1
321
322#define MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED -1
323#define MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT 16
324
325#define MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION 0
326#define MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION 1
327#define MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE 2
328
329#define MBEDTLS_SSL_TRUNC_HMAC_DISABLED 0
330#define MBEDTLS_SSL_TRUNC_HMAC_ENABLED 1
331#define MBEDTLS_SSL_TRUNCATED_HMAC_LEN 10 /* 80 bits, rfc 6066 section 7 */
332
333#define MBEDTLS_SSL_SESSION_TICKETS_DISABLED 0
334#define MBEDTLS_SSL_SESSION_TICKETS_ENABLED 1
335
336#define MBEDTLS_SSL_PRESET_DEFAULT 0
337#define MBEDTLS_SSL_PRESET_SUITEB 2
338
339#define MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED 1
340#define MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED 0
341
342#define MBEDTLS_SSL_EARLY_DATA_DISABLED 0
343#define MBEDTLS_SSL_EARLY_DATA_ENABLED 1
344
345#define MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED 0
346#define MBEDTLS_SSL_DTLS_SRTP_MKI_SUPPORTED 1
347
348#define MBEDTLS_SSL_SRV_CIPHERSUITE_ORDER_CLIENT 1
349#define MBEDTLS_SSL_SRV_CIPHERSUITE_ORDER_SERVER 0
350
351#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS)
352#if defined(PSA_WANT_ALG_SHA_384)
353#define MBEDTLS_SSL_TLS1_3_TICKET_RESUMPTION_KEY_LEN 48
354#elif defined(PSA_WANT_ALG_SHA_256)
355#define MBEDTLS_SSL_TLS1_3_TICKET_RESUMPTION_KEY_LEN 32
356#endif
357#endif /* MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_SESSION_TICKETS */
358/*
359 * Default range for DTLS retransmission timer value, in milliseconds.
360 * RFC 6347 4.2.4.1 says from 1 second to 60 seconds.
361 */
362#define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN 1000
363#define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX 60000
364
365/*
366 * Whether early data record should be discarded or not and how.
367 *
368 * The client has indicated early data and the server has rejected them.
369 * The server has then to skip past early data by either:
370 * - attempting to deprotect received records using the handshake traffic
371 * key, discarding records which fail deprotection (up to the configured
372 * max_early_data_size). Once a record is deprotected successfully,
373 * it is treated as the start of the client's second flight and the
374 * server proceeds as with an ordinary 1-RTT handshake.
375 * - skipping all records with an external content type of
376 * "application_data" (indicating that they are encrypted), up to the
377 * configured max_early_data_size. This is the expected behavior if the
378 * server has sent an HelloRetryRequest message. The server ignores
379 * application data message before 2nd ClientHello.
380 */
381#define MBEDTLS_SSL_EARLY_DATA_NO_DISCARD 0
382#define MBEDTLS_SSL_EARLY_DATA_TRY_TO_DEPROTECT_AND_DISCARD 1
383#define MBEDTLS_SSL_EARLY_DATA_DISCARD 2
384
392
393/*
394 * Maximum fragment length in bytes,
395 * determines the size of each of the two internal I/O buffers.
396 *
397 * Note: the RFC defines the default size of SSL / TLS messages. If you
398 * change the value here, other clients / servers may not be able to
399 * communicate with you anymore. Only change this value if you control
400 * both sides of the connection and have it reduced at both sides, or
401 * if you're using the Max Fragment Length extension and you know all your
402 * peers are using it too!
403 */
404#if !defined(MBEDTLS_SSL_IN_CONTENT_LEN)
405#define MBEDTLS_SSL_IN_CONTENT_LEN 16384
406#endif
407
408#if !defined(MBEDTLS_SSL_OUT_CONTENT_LEN)
409#define MBEDTLS_SSL_OUT_CONTENT_LEN 16384
410#endif
411
412/*
413 * Maximum number of heap-allocated bytes for the purpose of
414 * DTLS handshake message reassembly and future message buffering.
415 */
416#if !defined(MBEDTLS_SSL_DTLS_MAX_BUFFERING)
417#define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768
418#endif
419
420/*
421 * Maximum length of CIDs for incoming and outgoing messages.
422 */
423#if !defined(MBEDTLS_SSL_CID_IN_LEN_MAX)
424#define MBEDTLS_SSL_CID_IN_LEN_MAX 32
425#endif
426
427#if !defined(MBEDTLS_SSL_CID_OUT_LEN_MAX)
428#define MBEDTLS_SSL_CID_OUT_LEN_MAX 32
429#endif
430
431#if !defined(MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY)
432#define MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY 16
433#endif
434
435#if !defined(MBEDTLS_SSL_MAX_EARLY_DATA_SIZE)
436#define MBEDTLS_SSL_MAX_EARLY_DATA_SIZE 1024
437#endif
438
439#if !defined(MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE)
440#define MBEDTLS_SSL_TLS1_3_TICKET_AGE_TOLERANCE 6000
441#endif
442
443#if !defined(MBEDTLS_SSL_TLS1_3_TICKET_NONCE_LENGTH)
444#define MBEDTLS_SSL_TLS1_3_TICKET_NONCE_LENGTH 32
445#endif
446
447#if !defined(MBEDTLS_SSL_TLS1_3_DEFAULT_NEW_SESSION_TICKETS)
448#define MBEDTLS_SSL_TLS1_3_DEFAULT_NEW_SESSION_TICKETS 1
449#endif
450
452
453/*
454 * Length of the verify data for secure renegotiation
455 */
456#define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 12
457
458/*
459 * Signaling ciphersuite values (SCSV)
460 */
461#define MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO 0xFF
462
463/*
464 * Supported Signature and Hash algorithms (For TLS 1.2)
465 * RFC 5246 section 7.4.1.4.1
466 */
467#define MBEDTLS_SSL_HASH_NONE 0
468#define MBEDTLS_SSL_HASH_MD5 1
469#define MBEDTLS_SSL_HASH_SHA1 2
470#define MBEDTLS_SSL_HASH_SHA224 3
471#define MBEDTLS_SSL_HASH_SHA256 4
472#define MBEDTLS_SSL_HASH_SHA384 5
473#define MBEDTLS_SSL_HASH_SHA512 6
474
475#define MBEDTLS_SSL_SIG_ANON 0
476#define MBEDTLS_SSL_SIG_RSA 1
477#define MBEDTLS_SSL_SIG_ECDSA 3
478
479/*
480 * TLS 1.3 signature algorithms
481 * RFC 8446, Section 4.2.3
482 */
483
484/* RSASSA-PKCS1-v1_5 algorithms */
485#define MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA256 0x0401
486#define MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA384 0x0501
487#define MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA512 0x0601
488
489/* ECDSA algorithms */
490#define MBEDTLS_TLS1_3_SIG_ECDSA_SECP256R1_SHA256 0x0403
491#define MBEDTLS_TLS1_3_SIG_ECDSA_SECP384R1_SHA384 0x0503
492#define MBEDTLS_TLS1_3_SIG_ECDSA_SECP521R1_SHA512 0x0603
493
494/* RSASSA-PSS algorithms with public key OID rsaEncryption */
495#define MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256 0x0804
496#define MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384 0x0805
497#define MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512 0x0806
498
499/* EdDSA algorithms */
500#define MBEDTLS_TLS1_3_SIG_ED25519 0x0807
501#define MBEDTLS_TLS1_3_SIG_ED448 0x0808
502
503/* RSASSA-PSS algorithms with public key OID RSASSA-PSS */
504#define MBEDTLS_TLS1_3_SIG_RSA_PSS_PSS_SHA256 0x0809
505#define MBEDTLS_TLS1_3_SIG_RSA_PSS_PSS_SHA384 0x080A
506#define MBEDTLS_TLS1_3_SIG_RSA_PSS_PSS_SHA512 0x080B
507
508/* LEGACY ALGORITHMS */
509#define MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA1 0x0201
510#define MBEDTLS_TLS1_3_SIG_ECDSA_SHA1 0x0203
511
512#define MBEDTLS_TLS1_3_SIG_NONE 0x0
513
514/*
515 * Client Certificate Types
516 * RFC 5246 section 7.4.4 plus RFC 4492 section 5.5
517 */
518#define MBEDTLS_SSL_CERT_TYPE_RSA_SIGN 1
519#define MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN 64
520
521/*
522 * Message, alert and handshake types
523 */
524#define MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC 20
525#define MBEDTLS_SSL_MSG_ALERT 21
526#define MBEDTLS_SSL_MSG_HANDSHAKE 22
527#define MBEDTLS_SSL_MSG_APPLICATION_DATA 23
528#define MBEDTLS_SSL_MSG_CID 25
529
530#define MBEDTLS_SSL_ALERT_LEVEL_WARNING 1
531#define MBEDTLS_SSL_ALERT_LEVEL_FATAL 2
532
533#define MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY 0 /* 0x00 */
534#define MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10 /* 0x0A */
535#define MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC 20 /* 0x14 */
536#define MBEDTLS_SSL_ALERT_MSG_DECRYPTION_FAILED 21 /* 0x15 */
537#define MBEDTLS_SSL_ALERT_MSG_RECORD_OVERFLOW 22 /* 0x16 */
538#define MBEDTLS_SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30 /* 0x1E */
539#define MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE 40 /* 0x28 */
540#define MBEDTLS_SSL_ALERT_MSG_NO_CERT 41 /* 0x29 */
541#define MBEDTLS_SSL_ALERT_MSG_BAD_CERT 42 /* 0x2A */
542#define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT 43 /* 0x2B */
543#define MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED 44 /* 0x2C */
544#define MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED 45 /* 0x2D */
545#define MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN 46 /* 0x2E */
546#define MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER 47 /* 0x2F */
547#define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_CA 48 /* 0x30 */
548#define MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED 49 /* 0x31 */
549#define MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR 50 /* 0x32 */
550#define MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR 51 /* 0x33 */
551#define MBEDTLS_SSL_ALERT_MSG_EXPORT_RESTRICTION 60 /* 0x3C */
552#define MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION 70 /* 0x46 */
553#define MBEDTLS_SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71 /* 0x47 */
554#define MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR 80 /* 0x50 */
555#define MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK 86 /* 0x56 */
556#define MBEDTLS_SSL_ALERT_MSG_USER_CANCELED 90 /* 0x5A */
557#define MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION 100 /* 0x64 */
558#define MBEDTLS_SSL_ALERT_MSG_MISSING_EXTENSION 109 /* 0x6d -- new in TLS 1.3 */
559#define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT 110 /* 0x6E */
560#define MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME 112 /* 0x70 */
561#define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY 115 /* 0x73 */
562#define MBEDTLS_SSL_ALERT_MSG_CERT_REQUIRED 116 /* 0x74 */
563#define MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL 120 /* 0x78 */
564
565#define MBEDTLS_SSL_HS_HELLO_REQUEST 0
566#define MBEDTLS_SSL_HS_CLIENT_HELLO 1
567#define MBEDTLS_SSL_HS_SERVER_HELLO 2
568#define MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST 3
569#define MBEDTLS_SSL_HS_NEW_SESSION_TICKET 4
570#define MBEDTLS_SSL_HS_END_OF_EARLY_DATA 5
571#define MBEDTLS_SSL_HS_ENCRYPTED_EXTENSIONS 8
572#define MBEDTLS_SSL_HS_CERTIFICATE 11
573#define MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE 12
574#define MBEDTLS_SSL_HS_CERTIFICATE_REQUEST 13
575#define MBEDTLS_SSL_HS_SERVER_HELLO_DONE 14
576#define MBEDTLS_SSL_HS_CERTIFICATE_VERIFY 15
577#define MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE 16
578#define MBEDTLS_SSL_HS_FINISHED 20
579#define MBEDTLS_SSL_HS_MESSAGE_HASH 254
580
581/*
582 * TLS extensions
583 */
584#define MBEDTLS_TLS_EXT_SERVERNAME 0
585#define MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME 0
586
587#define MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH 1
588
589#define MBEDTLS_TLS_EXT_TRUNCATED_HMAC 4
590#define MBEDTLS_TLS_EXT_STATUS_REQUEST 5 /* RFC 6066 TLS 1.2 and 1.3 */
591
592#define MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES 10
593#define MBEDTLS_TLS_EXT_SUPPORTED_GROUPS 10 /* RFC 8422,7919 TLS 1.2 and 1.3 */
594#define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS 11
595
596#define MBEDTLS_TLS_EXT_SIG_ALG 13 /* RFC 8446 TLS 1.3 */
597#define MBEDTLS_TLS_EXT_USE_SRTP 14
598#define MBEDTLS_TLS_EXT_HEARTBEAT 15 /* RFC 6520 TLS 1.2 and 1.3 */
599#define MBEDTLS_TLS_EXT_ALPN 16
600
601#define MBEDTLS_TLS_EXT_SCT 18 /* RFC 6962 TLS 1.2 and 1.3 */
602#define MBEDTLS_TLS_EXT_CLI_CERT_TYPE 19 /* RFC 7250 TLS 1.2 and 1.3 */
603#define MBEDTLS_TLS_EXT_SERV_CERT_TYPE 20 /* RFC 7250 TLS 1.2 and 1.3 */
604#define MBEDTLS_TLS_EXT_PADDING 21 /* RFC 7685 TLS 1.2 and 1.3 */
605#define MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC 22 /* 0x16 */
606#define MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET 0x0017 /* 23 */
607
608#define MBEDTLS_TLS_EXT_RECORD_SIZE_LIMIT 28 /* RFC 8449 (implemented for TLS 1.3 only) */
609
610#define MBEDTLS_TLS_EXT_SESSION_TICKET 35
611
612#define MBEDTLS_TLS_EXT_PRE_SHARED_KEY 41 /* RFC 8446 TLS 1.3 */
613#define MBEDTLS_TLS_EXT_EARLY_DATA 42 /* RFC 8446 TLS 1.3 */
614#define MBEDTLS_TLS_EXT_SUPPORTED_VERSIONS 43 /* RFC 8446 TLS 1.3 */
615#define MBEDTLS_TLS_EXT_COOKIE 44 /* RFC 8446 TLS 1.3 */
616#define MBEDTLS_TLS_EXT_PSK_KEY_EXCHANGE_MODES 45 /* RFC 8446 TLS 1.3 */
617
618#define MBEDTLS_TLS_EXT_CERT_AUTH 47 /* RFC 8446 TLS 1.3 */
619#define MBEDTLS_TLS_EXT_OID_FILTERS 48 /* RFC 8446 TLS 1.3 */
620#define MBEDTLS_TLS_EXT_POST_HANDSHAKE_AUTH 49 /* RFC 8446 TLS 1.3 */
621#define MBEDTLS_TLS_EXT_SIG_ALG_CERT 50 /* RFC 8446 TLS 1.3 */
622#define MBEDTLS_TLS_EXT_KEY_SHARE 51 /* RFC 8446 TLS 1.3 */
623
624#define MBEDTLS_TLS_EXT_CID 54 /* RFC 9146 DTLS 1.2 CID */
625
626#define MBEDTLS_TLS_EXT_ECJPAKE_KKPP 256 /* experimental */
627
628#define MBEDTLS_TLS_EXT_RENEGOTIATION_INFO 0xFF01
629
630/*
631 * Size defines
632 */
633#if !defined(MBEDTLS_PSK_MAX_LEN)
634/*
635 * If the library supports TLS 1.3 tickets and the cipher suite
636 * TLS1-3-AES-256-GCM-SHA384, set the PSK maximum length to 48 instead of 32.
637 * That way, the TLS 1.3 client and server are able to resume sessions where
638 * the cipher suite is TLS1-3-AES-256-GCM-SHA384 (pre-shared keys are 48
639 * bytes long in that case).
640 */
641#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && \
642 defined(MBEDTLS_SSL_SESSION_TICKETS) && \
643 defined(PSA_WANT_KEY_TYPE_AES) && defined(PSA_WANT_ALG_GCM) && \
644 defined(PSA_WANT_ALG_SHA_384)
645#define MBEDTLS_PSK_MAX_LEN 48 /* 384 bits */
646#else
647#define MBEDTLS_PSK_MAX_LEN 32 /* 256 bits */
648#endif
649#endif /* !MBEDTLS_PSK_MAX_LEN */
650
651#define MBEDTLS_SSL_TLS1_2_MASTER_SECRET_LEN 48
652
653#define MBEDTLS_SSL_SESSION_SECRET_LEN MBEDTLS_SSL_TLS1_2_MASTER_SECRET_LEN
654
655#if defined(MBEDTLS_SSL_TLS1_3_TICKET_RESUMPTION_KEY_LEN) && \
656 MBEDTLS_SSL_SESSION_SECRET_LEN < \
657 MBEDTLS_SSL_TLS1_3_TICKET_RESUMPTION_KEY_LEN
658#error "MBEDTLS_SSL_SESSION_SECRET_LEN is too small for the TLS 1.3 ticket resumption key"
659#endif
660
661/* Dummy type used only for its size */
663 unsigned char dummy; /* Make the union non-empty even with SSL disabled */
664#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
665 defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
666 unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]; /* RFC 4492 5.10 */
667#endif
668#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
669 unsigned char _pms_psk[4 + 2 * MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 2 */
670#endif
671#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
672 unsigned char _pms_ecdhe_psk[4 + MBEDTLS_ECP_MAX_BYTES
673 + MBEDTLS_PSK_MAX_LEN]; /* RFC 5489 2 */
674#endif
675#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
676 unsigned char _pms_ecjpake[32]; /* Thread spec: SHA-256 output */
677#endif
678};
679
680#define MBEDTLS_PREMASTER_SIZE sizeof(union mbedtls_ssl_premaster_secret)
681
682#define MBEDTLS_TLS1_3_MD_MAX_SIZE PSA_HASH_MAX_SIZE
683
684
685/* Length in number of bytes of the TLS sequence number */
686#define MBEDTLS_SSL_SEQUENCE_NUMBER_LEN 8
687
688/* Helper to state that client_random and server_random need to be stored
689 * after the handshake is complete. This is required for context serialization
690 * and for the keying material exporter in TLS 1.2. */
691#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION) || \
692 (defined(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT) && defined(MBEDTLS_SSL_PROTO_TLS1_2))
693#define MBEDTLS_SSL_KEEP_RANDBYTES
694#endif
695
696#ifdef __cplusplus
697extern "C" {
698#endif
699
700/*
701 * SSL state machine
702 */
736
737/*
738 * Early data status, client side only.
739 */
740
741#if defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_CLI_C)
742typedef enum {
743/*
744 * See documentation of mbedtls_ssl_get_early_data_status().
745 */
746 MBEDTLS_SSL_EARLY_DATA_STATUS_NOT_INDICATED,
747 MBEDTLS_SSL_EARLY_DATA_STATUS_ACCEPTED,
748 MBEDTLS_SSL_EARLY_DATA_STATUS_REJECTED,
749} mbedtls_ssl_early_data_status;
750#endif /* MBEDTLS_SSL_EARLY_DATA && MBEDTLS_SSL_CLI_C */
751
769typedef int mbedtls_ssl_send_t(void *ctx,
770 const unsigned char *buf,
771 size_t len);
772
793typedef int mbedtls_ssl_recv_t(void *ctx,
794 unsigned char *buf,
795 size_t len);
796
819typedef int mbedtls_ssl_recv_timeout_t(void *ctx,
820 unsigned char *buf,
821 size_t len,
822 uint32_t timeout);
845typedef void mbedtls_ssl_set_timer_t(void *ctx,
846 uint32_t int_ms,
847 uint32_t fin_ms);
848
860typedef int mbedtls_ssl_get_timer_t(void *ctx);
861
862/* Defined below */
866
867/* Defined in library/ssl_misc.h */
870#if defined(MBEDTLS_X509_CRT_PARSE_C)
872#endif
873#if defined(MBEDTLS_SSL_PROTO_DTLS)
875#endif
876
877#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS)
878#define MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_PSK_RESUMPTION \
879 MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK /* 1U << 0 */
880#define MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_PSK_EPHEMERAL_RESUMPTION \
881 MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL /* 1U << 2 */
882#define MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_EARLY_DATA (1U << 3)
883
884#define MBEDTLS_SSL_TLS1_3_TICKET_FLAGS_MASK \
885 (MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_PSK_RESUMPTION | \
886 MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_PSK_EPHEMERAL_RESUMPTION | \
887 MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_EARLY_DATA)
888#endif /* MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_SESSION_TICKETS */
889
913typedef int mbedtls_ssl_cache_get_t(void *data,
914 unsigned char const *session_id,
915 size_t session_id_len,
916 mbedtls_ssl_session *session);
935typedef int mbedtls_ssl_cache_set_t(void *data,
936 unsigned char const *session_id,
937 size_t session_id_len,
938 const mbedtls_ssl_session *session);
939
940#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
941#if defined(MBEDTLS_X509_CRT_PARSE_C)
1003typedef int mbedtls_ssl_async_sign_t(mbedtls_ssl_context *ssl,
1004 mbedtls_x509_crt *cert,
1005 mbedtls_md_type_t md_alg,
1006 const unsigned char *hash,
1007 size_t hash_len);
1008#endif /* MBEDTLS_X509_CRT_PARSE_C */
1009
1051typedef int mbedtls_ssl_async_resume_t(mbedtls_ssl_context *ssl,
1052 unsigned char *output,
1053 size_t *output_len,
1054 size_t output_size);
1055
1073typedef void mbedtls_ssl_async_cancel_t(mbedtls_ssl_context *ssl);
1074#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
1075
1076#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) && \
1077 !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
1078#define MBEDTLS_SSL_PEER_CERT_DIGEST_MAX_LEN 48
1079#if defined(PSA_WANT_ALG_SHA_256)
1080#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA256
1081#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 32
1082#elif defined(PSA_WANT_ALG_SHA_384)
1083#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA384
1084#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 48
1085#elif defined(PSA_WANT_ALG_SHA_1)
1086#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA1
1087#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 20
1088#else
1089/* This is already checked in check_config.h, but be sure. */
1090#error "Bad configuration - need SHA-1, SHA-256 or SHA-512 enabled to compute digest of peer CRT."
1091#endif
1092#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED &&
1093 !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
1094
1101
1102#if defined(MBEDTLS_SSL_DTLS_SRTP)
1103
1104#define MBEDTLS_TLS_SRTP_MAX_MKI_LENGTH 255
1105#define MBEDTLS_TLS_SRTP_MAX_PROFILE_LIST_LENGTH 4
1106/*
1107 * For code readability use a typedef for DTLS-SRTP profiles
1108 *
1109 * Use_srtp extension protection profiles values as defined in
1110 * http://www.iana.org/assignments/srtp-protection/srtp-protection.xhtml
1111 *
1112 * Reminder: if this list is expanded mbedtls_ssl_check_srtp_profile_value
1113 * must be updated too.
1114 */
1115#define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80 ((uint16_t) 0x0001)
1116#define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32 ((uint16_t) 0x0002)
1117#define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80 ((uint16_t) 0x0005)
1118#define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32 ((uint16_t) 0x0006)
1119/* This one is not iana defined, but for code readability. */
1120#define MBEDTLS_TLS_SRTP_UNSET ((uint16_t) 0x0000)
1121
1122typedef uint16_t mbedtls_ssl_srtp_profile;
1123
1124typedef struct mbedtls_dtls_srtp_info_t {
1126 mbedtls_ssl_srtp_profile MBEDTLS_PRIVATE(chosen_dtls_srtp_profile);
1128 uint16_t MBEDTLS_PRIVATE(mki_len);
1130 unsigned char MBEDTLS_PRIVATE(mki_value)[MBEDTLS_TLS_SRTP_MAX_MKI_LENGTH];
1131}
1132mbedtls_dtls_srtp_info;
1133
1134#endif /* MBEDTLS_SSL_DTLS_SRTP */
1135
1142
1143/*
1144 * This structure is used for storing current session data.
1145 *
1146 * Note: when changing this definition, we need to check and update:
1147 * - in tests/suites/test_suite_ssl.function:
1148 * ssl_populate_session() and ssl_serialize_session_save_load()
1149 * - in library/ssl_tls.c:
1150 * mbedtls_ssl_session_init() and mbedtls_ssl_session_free()
1151 * mbedtls_ssl_session_save() and ssl_session_load()
1152 * ssl_session_copy()
1153 */
1155#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
1156 unsigned char MBEDTLS_PRIVATE(mfl_code);
1157#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
1158
1160#if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT)
1161 uint16_t MBEDTLS_PRIVATE(record_size_limit);
1162#endif /* MBEDTLS_SSL_RECORD_SIZE_LIMIT */
1163
1164 unsigned char MBEDTLS_PRIVATE(exported);
1165 uint8_t MBEDTLS_PRIVATE(endpoint);
1166
1170 mbedtls_ssl_protocol_version MBEDTLS_PRIVATE(tls_version);
1171
1172#if defined(MBEDTLS_HAVE_TIME)
1173 mbedtls_time_t MBEDTLS_PRIVATE(start);
1174#endif
1175 int MBEDTLS_PRIVATE(ciphersuite);
1176 size_t MBEDTLS_PRIVATE(id_len);
1177 unsigned char MBEDTLS_PRIVATE(id)[32];
1181 unsigned char MBEDTLS_PRIVATE(secret)[MBEDTLS_SSL_SESSION_SECRET_LEN];
1182
1183#if defined(MBEDTLS_X509_CRT_PARSE_C)
1184#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
1185 mbedtls_x509_crt *MBEDTLS_PRIVATE(peer_cert);
1186#else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
1189 unsigned char *MBEDTLS_PRIVATE(peer_cert_digest);
1190 size_t MBEDTLS_PRIVATE(peer_cert_digest_len);
1191 mbedtls_md_type_t MBEDTLS_PRIVATE(peer_cert_digest_type);
1192#endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
1193#endif /* MBEDTLS_X509_CRT_PARSE_C */
1194 uint32_t MBEDTLS_PRIVATE(verify_result);
1195
1196#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
1197 unsigned char *MBEDTLS_PRIVATE(ticket);
1198 size_t MBEDTLS_PRIVATE(ticket_len);
1199 uint32_t MBEDTLS_PRIVATE(ticket_lifetime);
1200#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
1201
1202#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C) && \
1203 defined(MBEDTLS_HAVE_TIME)
1220 mbedtls_ms_time_t MBEDTLS_PRIVATE(ticket_creation_time);
1221#endif
1222
1223#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS)
1224 uint32_t MBEDTLS_PRIVATE(ticket_age_add);
1225 uint8_t MBEDTLS_PRIVATE(ticket_flags);
1226 uint8_t MBEDTLS_PRIVATE(resumption_key_len);
1227 unsigned char MBEDTLS_PRIVATE(resumption_key_unused)[
1229
1230#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) && defined(MBEDTLS_SSL_CLI_C)
1231 char *MBEDTLS_PRIVATE(hostname);
1232#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION && MBEDTLS_SSL_CLI_C */
1233
1234#if defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_ALPN) && defined(MBEDTLS_SSL_SRV_C)
1235 char *MBEDTLS_PRIVATE(ticket_alpn);
1237#endif
1238
1239#if defined(MBEDTLS_HAVE_TIME) && defined(MBEDTLS_SSL_CLI_C)
1241 mbedtls_ms_time_t MBEDTLS_PRIVATE(ticket_reception_time);
1242#endif
1243#endif /* MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_SESSION_TICKETS */
1244
1245#if defined(MBEDTLS_SSL_EARLY_DATA)
1246 uint32_t MBEDTLS_PRIVATE(max_early_data_size);
1247#endif
1248
1249#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1250 int MBEDTLS_PRIVATE(encrypt_then_mac);
1251#endif
1252
1253#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
1254 mbedtls_ssl_tls13_application_secrets MBEDTLS_PRIVATE(app_secrets);
1255#endif
1256
1257 /* Unused field reserved for future use */
1258 union {
1259 size_t number;
1260 void *ptr;
1261 } MBEDTLS_PRIVATE(unused);
1262};
1263
1264/*
1265 * Identifiers for PRFs used in various versions of TLS.
1266 */
1275
1287
1303typedef void mbedtls_ssl_export_keys_t(void *p_expkey,
1305 const unsigned char *secret,
1306 size_t secret_len,
1307 const unsigned char client_random[32],
1308 const unsigned char server_random[32],
1309 mbedtls_tls_prf_types tls_prf_type);
1310
1311#if defined(MBEDTLS_SSL_SRV_C)
1328#endif
1329
1330/* A type for storing user data in a library structure.
1331 *
1332 * The representation of type may change in future versions of the library.
1333 * Only the behaviors guaranteed by documented accessor functions are
1334 * guaranteed to remain stable.
1335 */
1336typedef union {
1337 uintptr_t n; /* typically a handle to an associated object */
1338 void *p; /* typically a pointer to extra data */
1340
1345typedef union {
1346 size_t number;
1347 void *ptr;
1349
1354 /* Group items mostly by size. This helps to reduce memory wasted to
1355 * padding. It also helps to keep smaller fields early in the structure,
1356 * so that elements tend to be in the 128-element direct access window
1357 * on Arm Thumb, which reduces the code size. */
1358
1359 mbedtls_ssl_protocol_version MBEDTLS_PRIVATE(max_tls_version);
1360 mbedtls_ssl_protocol_version MBEDTLS_PRIVATE(min_tls_version);
1361
1362 /*
1363 * Flags (could be bit-fields to save RAM, but separate bytes make
1364 * the code smaller on architectures with an instruction for direct
1365 * byte access).
1366 */
1367
1368 uint8_t MBEDTLS_PRIVATE(endpoint);
1369 uint8_t MBEDTLS_PRIVATE(transport);
1370 uint8_t MBEDTLS_PRIVATE(authmode);
1371 /* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */
1372 uint8_t MBEDTLS_PRIVATE(allow_legacy_renegotiation);
1373#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
1374 uint8_t MBEDTLS_PRIVATE(mfl_code);
1376#endif
1377#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1378 uint8_t MBEDTLS_PRIVATE(encrypt_then_mac);
1379#endif
1380#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
1381 uint8_t MBEDTLS_PRIVATE(extended_ms);
1382#endif
1383#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
1384 uint8_t MBEDTLS_PRIVATE(anti_replay);
1385#endif
1386#if defined(MBEDTLS_SSL_RENEGOTIATION)
1387 uint8_t MBEDTLS_PRIVATE(disable_renegotiation);
1388#endif
1389#if defined(MBEDTLS_SSL_SESSION_TICKETS) && \
1390 defined(MBEDTLS_SSL_CLI_C)
1391 uint8_t MBEDTLS_PRIVATE(session_tickets);
1392#endif
1393
1394#if defined(MBEDTLS_SSL_SESSION_TICKETS) && \
1395 defined(MBEDTLS_SSL_SRV_C) && \
1396 defined(MBEDTLS_SSL_PROTO_TLS1_3)
1397 uint16_t MBEDTLS_PRIVATE(new_session_tickets_count);
1398#endif
1399
1400#if defined(MBEDTLS_SSL_SRV_C)
1401 uint8_t MBEDTLS_PRIVATE(cert_req_ca_list);
1403 uint8_t MBEDTLS_PRIVATE(respect_cli_pref);
1406#endif
1407#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1408 uint8_t MBEDTLS_PRIVATE(ignore_unexpected_cid);
1411#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1412#if defined(MBEDTLS_SSL_DTLS_SRTP)
1413 uint8_t MBEDTLS_PRIVATE(dtls_srtp_mki_support); /* support having mki_value
1414 in the use_srtp extension? */
1415#endif
1416
1417 /*
1418 * Pointers
1419 */
1420
1422 const int *MBEDTLS_PRIVATE(ciphersuite_list);
1423
1424#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
1426 int MBEDTLS_PRIVATE(tls13_kex_modes);
1427#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
1428
1430 void(*MBEDTLS_PRIVATE(f_dbg))(void *, int, const char *, int, const char *);
1431 void *MBEDTLS_PRIVATE(p_dbg);
1432
1434 mbedtls_ssl_cache_get_t *MBEDTLS_PRIVATE(f_get_cache);
1436 mbedtls_ssl_cache_set_t *MBEDTLS_PRIVATE(f_set_cache);
1437 void *MBEDTLS_PRIVATE(p_cache);
1438
1439#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
1441 int(*MBEDTLS_PRIVATE(f_sni))(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
1442 void *MBEDTLS_PRIVATE(p_sni);
1443#endif
1444
1445#if defined(MBEDTLS_X509_CRT_PARSE_C)
1447 int(*MBEDTLS_PRIVATE(f_vrfy))(void *, mbedtls_x509_crt *, int, uint32_t *);
1448 void *MBEDTLS_PRIVATE(p_vrfy);
1449#endif
1450
1451#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
1452#if defined(MBEDTLS_SSL_SRV_C)
1454 int(*MBEDTLS_PRIVATE(f_psk))(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
1455 void *MBEDTLS_PRIVATE(p_psk);
1456#endif
1457#endif
1458
1459#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
1461 int(*MBEDTLS_PRIVATE(f_cookie_write))(void *, unsigned char **, unsigned char *,
1462 const unsigned char *, size_t);
1464 int(*MBEDTLS_PRIVATE(f_cookie_check))(void *, const unsigned char *, size_t,
1465 const unsigned char *, size_t);
1466 void *MBEDTLS_PRIVATE(p_cookie);
1467#endif
1468
1469#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
1471 int(*MBEDTLS_PRIVATE(f_ticket_write))(void *, const mbedtls_ssl_session *,
1472 unsigned char *, const unsigned char *, size_t *,
1473 uint32_t *);
1475 int(*MBEDTLS_PRIVATE(f_ticket_parse))(void *, mbedtls_ssl_session *, unsigned char *, size_t);
1476 void *MBEDTLS_PRIVATE(p_ticket);
1477#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
1478#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1479 size_t MBEDTLS_PRIVATE(cid_len);
1480#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1481
1482#if defined(MBEDTLS_X509_CRT_PARSE_C)
1483 const mbedtls_x509_crt_profile *MBEDTLS_PRIVATE(cert_profile);
1484 mbedtls_ssl_key_cert *MBEDTLS_PRIVATE(key_cert);
1485 mbedtls_x509_crt *MBEDTLS_PRIVATE(ca_chain);
1486 mbedtls_x509_crl *MBEDTLS_PRIVATE(ca_crl);
1487#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
1488 mbedtls_x509_crt_ca_cb_t MBEDTLS_PRIVATE(f_ca_cb);
1489 void *MBEDTLS_PRIVATE(p_ca_cb);
1490#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
1491#endif /* MBEDTLS_X509_CRT_PARSE_C */
1492
1493#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
1494#if defined(MBEDTLS_X509_CRT_PARSE_C)
1495 mbedtls_ssl_async_sign_t *MBEDTLS_PRIVATE(f_async_sign_start);
1496#endif /* MBEDTLS_X509_CRT_PARSE_C */
1497 mbedtls_ssl_async_resume_t *MBEDTLS_PRIVATE(f_async_resume);
1498 mbedtls_ssl_async_cancel_t *MBEDTLS_PRIVATE(f_async_cancel);
1499 void *MBEDTLS_PRIVATE(p_async_config_data);
1500#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
1501
1502#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
1503 const uint16_t *MBEDTLS_PRIVATE(sig_algs);
1504#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
1505
1506 const uint16_t *MBEDTLS_PRIVATE(group_list);
1507
1508#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
1509
1510 mbedtls_svc_key_id_t MBEDTLS_PRIVATE(psk_opaque);
1516 unsigned char *MBEDTLS_PRIVATE(psk);
1520 size_t MBEDTLS_PRIVATE(psk_len);
1525
1526 unsigned char *MBEDTLS_PRIVATE(psk_identity);
1531 size_t MBEDTLS_PRIVATE(psk_identity_len);
1537#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
1538
1539#if defined(MBEDTLS_SSL_EARLY_DATA)
1540 int MBEDTLS_PRIVATE(early_data_enabled);
1543
1544#if defined(MBEDTLS_SSL_SRV_C)
1545 /* The maximum amount of 0-RTT data. RFC 8446 section 4.6.1 */
1546 uint32_t MBEDTLS_PRIVATE(max_early_data_size);
1547#endif /* MBEDTLS_SSL_SRV_C */
1548
1549#endif /* MBEDTLS_SSL_EARLY_DATA */
1550
1551#if defined(MBEDTLS_SSL_ALPN)
1552 const char *const *MBEDTLS_PRIVATE(alpn_list);
1553#endif
1554
1555#if defined(MBEDTLS_SSL_DTLS_SRTP)
1557 const mbedtls_ssl_srtp_profile *MBEDTLS_PRIVATE(dtls_srtp_profile_list);
1559 size_t MBEDTLS_PRIVATE(dtls_srtp_profile_list_len);
1560#endif /* MBEDTLS_SSL_DTLS_SRTP */
1561
1562 /*
1563 * Numerical settings (int)
1564 */
1565
1566 uint32_t MBEDTLS_PRIVATE(read_timeout);
1567
1568#if defined(MBEDTLS_SSL_PROTO_DTLS)
1569 uint32_t MBEDTLS_PRIVATE(hs_timeout_min);
1571 uint32_t MBEDTLS_PRIVATE(hs_timeout_max);
1573#endif
1574
1575#if defined(MBEDTLS_SSL_RENEGOTIATION)
1576 int MBEDTLS_PRIVATE(renego_max_records);
1577 unsigned char MBEDTLS_PRIVATE(renego_period)[8];
1579#endif
1580
1581 unsigned int MBEDTLS_PRIVATE(badmac_limit);
1582
1588 mbedtls_ssl_user_data_t MBEDTLS_PRIVATE(user_data);
1589
1590#if defined(MBEDTLS_SSL_SRV_C)
1591 mbedtls_ssl_hs_cb_t MBEDTLS_PRIVATE(f_cert_cb);
1592#endif /* MBEDTLS_SSL_SRV_C */
1593
1594#if defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED)
1595 const mbedtls_x509_crt *MBEDTLS_PRIVATE(dn_hints);
1596#endif
1597
1598 mbedtls_ssl_unused_data_t MBEDTLS_PRIVATE(unused);
1599};
1600
1601/*
1602 * Warning: whenever a change is applied to "mbedtls_ssl_context" please re-run
1603 * the script "tests/scripts/generate_ssl_session_reset_check.py".
1604 * Please note that this script has some limitation that should be considered
1605 * when modifing "mbedtls_ssl_context":
1606 * - Parsed structure must start with struct "mbedtls_ssl_context {"
1607 * (not "typedef struct {").
1608 * - It must end with "}}" in column 0.
1609 * - Must not contain "#else" or "#elif" conditionals.
1610 * - Must not contain nested struct/union/enum definitions.
1611 */
1613 const mbedtls_ssl_config *MBEDTLS_PRIVATE(conf);
1614
1615 /*
1616 * Miscellaneous
1617 */
1618 int MBEDTLS_PRIVATE(state);
1619
1625 uint32_t MBEDTLS_PRIVATE(flags);
1626
1627#if defined(MBEDTLS_SSL_RENEGOTIATION)
1628 int MBEDTLS_PRIVATE(renego_status);
1629 int MBEDTLS_PRIVATE(renego_records_seen);
1632#endif /* MBEDTLS_SSL_RENEGOTIATION */
1633
1650 mbedtls_ssl_protocol_version MBEDTLS_PRIVATE(tls_version);
1651
1652#if defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_CLI_C)
1657 int MBEDTLS_PRIVATE(early_data_state);
1658#endif
1659
1660 unsigned MBEDTLS_PRIVATE(badmac_seen);
1661
1662#if defined(MBEDTLS_X509_CRT_PARSE_C)
1664 int(*MBEDTLS_PRIVATE(f_vrfy))(void *, mbedtls_x509_crt *, int, uint32_t *);
1665 void *MBEDTLS_PRIVATE(p_vrfy);
1666#endif
1667
1668 mbedtls_ssl_send_t *MBEDTLS_PRIVATE(f_send);
1669 mbedtls_ssl_recv_t *MBEDTLS_PRIVATE(f_recv);
1670 mbedtls_ssl_recv_timeout_t *MBEDTLS_PRIVATE(f_recv_timeout);
1672
1673 void *MBEDTLS_PRIVATE(p_bio);
1674
1675 /*
1676 * Session layer
1677 */
1678 mbedtls_ssl_session *MBEDTLS_PRIVATE(session_in);
1679 mbedtls_ssl_session *MBEDTLS_PRIVATE(session_out);
1680 mbedtls_ssl_session *MBEDTLS_PRIVATE(session);
1681 mbedtls_ssl_session *MBEDTLS_PRIVATE(session_negotiate);
1682
1683 mbedtls_ssl_handshake_params *MBEDTLS_PRIVATE(handshake);
1685
1686 /*
1687 * Record layer transformations
1688 */
1689 mbedtls_ssl_transform *MBEDTLS_PRIVATE(transform_in);
1692 mbedtls_ssl_transform *MBEDTLS_PRIVATE(transform_out);
1695 mbedtls_ssl_transform *MBEDTLS_PRIVATE(transform);
1698#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
1699 mbedtls_ssl_transform *MBEDTLS_PRIVATE(transform_negotiate);
1702#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
1703
1704#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
1707 mbedtls_ssl_transform *MBEDTLS_PRIVATE(transform_application);
1708#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
1709
1710 /*
1711 * Timers
1712 */
1713 void *MBEDTLS_PRIVATE(p_timer);
1714
1715 mbedtls_ssl_set_timer_t *MBEDTLS_PRIVATE(f_set_timer);
1716 mbedtls_ssl_get_timer_t *MBEDTLS_PRIVATE(f_get_timer);
1717
1718 /*
1719 * Record layer (incoming data)
1720 */
1721 unsigned char *MBEDTLS_PRIVATE(in_buf);
1722 unsigned char *MBEDTLS_PRIVATE(in_ctr);
1725 unsigned char *MBEDTLS_PRIVATE(in_hdr);
1726#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1727 unsigned char *MBEDTLS_PRIVATE(in_cid);
1729#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1730 unsigned char *MBEDTLS_PRIVATE(in_len);
1731 unsigned char *MBEDTLS_PRIVATE(in_iv);
1732 unsigned char *MBEDTLS_PRIVATE(in_msg);
1733 unsigned char *MBEDTLS_PRIVATE(in_offt);
1734
1735 int MBEDTLS_PRIVATE(in_msgtype);
1736 size_t MBEDTLS_PRIVATE(in_msglen);
1737 size_t MBEDTLS_PRIVATE(in_left);
1738#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
1739 size_t MBEDTLS_PRIVATE(in_buf_len);
1740#endif
1741#if defined(MBEDTLS_SSL_PROTO_DTLS)
1742 uint16_t MBEDTLS_PRIVATE(in_epoch);
1743 size_t MBEDTLS_PRIVATE(next_record_offset);
1745#endif /* MBEDTLS_SSL_PROTO_DTLS */
1746#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
1747 uint64_t MBEDTLS_PRIVATE(in_window_top);
1748 uint64_t MBEDTLS_PRIVATE(in_window);
1749#endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
1750
1751 size_t MBEDTLS_PRIVATE(in_hslen);
1753 size_t MBEDTLS_PRIVATE(in_hsfraglen);
1755 int MBEDTLS_PRIVATE(nb_zero);
1756
1757 int MBEDTLS_PRIVATE(keep_current_message);
1759
1760 unsigned char MBEDTLS_PRIVATE(in_fatal_alert_recv);
1764 unsigned char MBEDTLS_PRIVATE(in_fatal_alert_type);
1766
1767 /* The following three variables indicate if and, if yes,
1768 * what kind of alert is pending to be sent.
1769 */
1770 unsigned char MBEDTLS_PRIVATE(send_alert);
1774 unsigned char MBEDTLS_PRIVATE(alert_type);
1776 int MBEDTLS_PRIVATE(alert_reason);
1779
1780#if defined(MBEDTLS_SSL_PROTO_DTLS)
1781 uint8_t MBEDTLS_PRIVATE(disable_datagram_packing);
1783#endif /* MBEDTLS_SSL_PROTO_DTLS */
1784
1785#if defined(MBEDTLS_SSL_EARLY_DATA)
1786#if defined(MBEDTLS_SSL_SRV_C)
1787 /*
1788 * One of:
1789 * MBEDTLS_SSL_EARLY_DATA_NO_DISCARD
1790 * MBEDTLS_SSL_EARLY_DATA_TRY_TO_DEPROTECT_AND_DISCARD
1791 * MBEDTLS_SSL_EARLY_DATA_DISCARD
1792 */
1793 uint8_t MBEDTLS_PRIVATE(discard_early_data_record);
1794#endif
1795 uint32_t MBEDTLS_PRIVATE(total_early_data_size);
1796#endif /* MBEDTLS_SSL_EARLY_DATA */
1797
1798 /*
1799 * Record layer (outgoing data)
1800 */
1801 unsigned char *MBEDTLS_PRIVATE(out_buf);
1802 unsigned char *MBEDTLS_PRIVATE(out_ctr);
1803 unsigned char *MBEDTLS_PRIVATE(out_hdr);
1804#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1805 unsigned char *MBEDTLS_PRIVATE(out_cid);
1807#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1808 unsigned char *MBEDTLS_PRIVATE(out_len);
1809 unsigned char *MBEDTLS_PRIVATE(out_iv);
1810 unsigned char *MBEDTLS_PRIVATE(out_msg);
1811
1812 int MBEDTLS_PRIVATE(out_msgtype);
1813 size_t MBEDTLS_PRIVATE(out_msglen);
1814 size_t MBEDTLS_PRIVATE(out_left);
1815#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
1816 size_t MBEDTLS_PRIVATE(out_buf_len);
1817#endif
1818
1819 unsigned char MBEDTLS_PRIVATE(cur_out_ctr)[MBEDTLS_SSL_SEQUENCE_NUMBER_LEN];
1820
1821#if defined(MBEDTLS_SSL_PROTO_DTLS)
1822 uint16_t MBEDTLS_PRIVATE(mtu);
1823#endif /* MBEDTLS_SSL_PROTO_DTLS */
1824
1825 /*
1826 * User settings
1827 */
1828#if defined(MBEDTLS_X509_CRT_PARSE_C)
1829 char *MBEDTLS_PRIVATE(hostname);
1831#endif /* MBEDTLS_X509_CRT_PARSE_C */
1832
1833#if defined(MBEDTLS_SSL_ALPN)
1834 const char *MBEDTLS_PRIVATE(alpn_chosen);
1835#endif /* MBEDTLS_SSL_ALPN */
1836
1837#if defined(MBEDTLS_SSL_DTLS_SRTP)
1838 /*
1839 * use_srtp extension
1840 */
1841 mbedtls_dtls_srtp_info MBEDTLS_PRIVATE(dtls_srtp_info);
1842#endif /* MBEDTLS_SSL_DTLS_SRTP */
1843
1844 /*
1845 * Information for DTLS hello verify
1846 */
1847#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
1848 unsigned char *MBEDTLS_PRIVATE(cli_id);
1849 size_t MBEDTLS_PRIVATE(cli_id_len);
1850#endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
1851
1852 /*
1853 * Secure renegotiation
1854 */
1855 /* needed to know when to send extension on server */
1856 int MBEDTLS_PRIVATE(secure_renegotiation);
1858#if defined(MBEDTLS_SSL_RENEGOTIATION)
1859 size_t MBEDTLS_PRIVATE(verify_data_len);
1860 char MBEDTLS_PRIVATE(own_verify_data)[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN];
1861 char MBEDTLS_PRIVATE(peer_verify_data)[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN];
1862#endif /* MBEDTLS_SSL_RENEGOTIATION */
1863
1864#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1865 /* CID configuration to use in subsequent handshakes. */
1866
1871 unsigned char MBEDTLS_PRIVATE(own_cid)[MBEDTLS_SSL_CID_IN_LEN_MAX];
1872 uint8_t MBEDTLS_PRIVATE(own_cid_len);
1873 uint8_t MBEDTLS_PRIVATE(negotiate_cid);
1877#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1878
1880 mbedtls_ssl_export_keys_t *MBEDTLS_PRIVATE(f_export_keys);
1881 void *MBEDTLS_PRIVATE(p_export_keys);
1882
1892 mbedtls_ssl_user_data_t MBEDTLS_PRIVATE(user_data);
1893
1894 mbedtls_ssl_unused_data_t MBEDTLS_PRIVATE(unused);
1895};
1896
1905const char *mbedtls_ssl_get_ciphersuite_name(const int ciphersuite_id);
1906
1915int mbedtls_ssl_get_ciphersuite_id(const char *ciphersuite_name);
1916
1925
1961 const mbedtls_ssl_config *conf);
1962
1973
1981
1991{
1992 return conf->MBEDTLS_PRIVATE(endpoint);
1993}
1994
2010
2045
2046#if defined(MBEDTLS_SSL_EARLY_DATA)
2073void mbedtls_ssl_conf_early_data(mbedtls_ssl_config *conf,
2074 int early_data_enabled);
2075
2076#if defined(MBEDTLS_SSL_SRV_C)
2101void mbedtls_ssl_conf_max_early_data_size(
2102 mbedtls_ssl_config *conf, uint32_t max_early_data_size);
2103#endif /* MBEDTLS_SSL_SRV_C */
2104
2105#endif /* MBEDTLS_SSL_EARLY_DATA */
2106
2107#if defined(MBEDTLS_X509_CRT_PARSE_C)
2131 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
2132 void *p_vrfy);
2133#endif /* MBEDTLS_X509_CRT_PARSE_C */
2134
2150 void (*f_dbg)(void *, int, const char *, int, const char *),
2151 void *p_dbg);
2152
2164 const mbedtls_ssl_context *ssl)
2165{
2166 return ssl->MBEDTLS_PRIVATE(conf);
2167}
2168
2200 void *p_bio,
2201 mbedtls_ssl_send_t *f_send,
2202 mbedtls_ssl_recv_t *f_recv,
2203 mbedtls_ssl_recv_timeout_t *f_recv_timeout);
2204
2205#if defined(MBEDTLS_SSL_PROTO_DTLS)
2206
2207#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
2208
2209
2295 int enable,
2296 unsigned char const *own_cid,
2297 size_t own_cid_len);
2298
2329 int *enabled,
2330 unsigned char own_cid[MBEDTLS_SSL_CID_IN_LEN_MAX],
2331 size_t *own_cid_len);
2332
2371 int *enabled,
2372 unsigned char peer_cid[MBEDTLS_SSL_CID_OUT_LEN_MAX],
2373 size_t *peer_cid_len);
2374
2375#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
2376
2417#endif /* MBEDTLS_SSL_PROTO_DTLS */
2418
2419#if defined(MBEDTLS_X509_CRT_PARSE_C)
2445 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
2446 void *p_vrfy);
2447#endif /* MBEDTLS_X509_CRT_PARSE_C */
2448
2466
2512 unsigned char *buf,
2513 size_t buflen);
2514
2536 void *p_timer,
2537 mbedtls_ssl_set_timer_t *f_set_timer,
2538 mbedtls_ssl_get_timer_t *f_get_timer);
2539
2540#if defined(MBEDTLS_SSL_SRV_C)
2561 mbedtls_ssl_hs_cb_t f_cert_cb)
2562{
2563 conf->MBEDTLS_PRIVATE(f_cert_cb) = f_cert_cb;
2564}
2565#endif /* MBEDTLS_SSL_SRV_C */
2566
2586typedef int mbedtls_ssl_ticket_write_t(void *p_ticket,
2587 const mbedtls_ssl_session *session,
2588 unsigned char *start,
2589 const unsigned char *end,
2590 size_t *tlen,
2591 uint32_t *lifetime);
2592
2616typedef int mbedtls_ssl_ticket_parse_t(void *p_ticket,
2617 mbedtls_ssl_session *session,
2618 unsigned char *buf,
2619 size_t len);
2620
2621#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
2661 mbedtls_ssl_ticket_write_t *f_ticket_write,
2662 mbedtls_ssl_ticket_parse_t *f_ticket_parse,
2663 void *p_ticket);
2664
2665#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
2685 void *p_ticket);
2686#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
2687
2688#if defined(MBEDTLS_HAVE_TIME)
2703 mbedtls_ssl_session *session, mbedtls_ms_time_t *ticket_creation_time)
2704{
2705 if (session == NULL || ticket_creation_time == NULL ||
2706 session->MBEDTLS_PRIVATE(endpoint) != MBEDTLS_SSL_IS_SERVER) {
2708 }
2709
2710 *ticket_creation_time = session->MBEDTLS_PRIVATE(ticket_creation_time);
2711
2712 return 0;
2713}
2714#endif /* MBEDTLS_HAVE_TIME */
2715#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
2716
2724static inline unsigned const char (*mbedtls_ssl_session_get_id(const mbedtls_ssl_session *
2725 session))[32]
2726{
2727 return &session->MBEDTLS_PRIVATE(id);
2728}
2729
2737static inline size_t mbedtls_ssl_session_get_id_len(const mbedtls_ssl_session *session)
2738{
2739 return session->MBEDTLS_PRIVATE(id_len);
2740}
2741
2750{
2751 return session->MBEDTLS_PRIVATE(ciphersuite);
2752}
2753
2773 mbedtls_ssl_export_keys_t *f_export_keys,
2774 void *p_export_keys);
2775
2787 mbedtls_ssl_config *conf,
2788 void *p)
2789{
2790 conf->MBEDTLS_PRIVATE(user_data).p = p;
2791}
2792
2801 mbedtls_ssl_config *conf,
2802 uintptr_t n)
2803{
2804 conf->MBEDTLS_PRIVATE(user_data).n = n;
2805}
2806
2818 mbedtls_ssl_config *conf)
2819{
2820 return conf->MBEDTLS_PRIVATE(user_data).p;
2821}
2822
2833static inline uintptr_t mbedtls_ssl_conf_get_user_data_n(
2834 mbedtls_ssl_config *conf)
2835{
2836 return conf->MBEDTLS_PRIVATE(user_data).n;
2837}
2838
2851 void *p)
2852{
2853 ssl->MBEDTLS_PRIVATE(user_data).p = p;
2854}
2855
2865 uintptr_t n)
2866{
2867 ssl->MBEDTLS_PRIVATE(user_data).n = n;
2868}
2869
2882{
2883 return ssl->MBEDTLS_PRIVATE(user_data).p;
2884}
2885
2896static inline uintptr_t mbedtls_ssl_get_user_data_n(
2898{
2899 return ssl->MBEDTLS_PRIVATE(user_data).n;
2900}
2901
2902#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
2926void mbedtls_ssl_conf_async_private_cb(mbedtls_ssl_config *conf,
2927 mbedtls_ssl_async_sign_t *f_async_sign,
2928 mbedtls_ssl_async_resume_t *f_async_resume,
2929 mbedtls_ssl_async_cancel_t *f_async_cancel,
2930 void *config_data);
2931
2940void *mbedtls_ssl_conf_get_async_config_data(const mbedtls_ssl_config *conf);
2941
2956void *mbedtls_ssl_get_async_operation_data(const mbedtls_ssl_context *ssl);
2957
2969void mbedtls_ssl_set_async_operation_data(mbedtls_ssl_context *ssl,
2970 void *ctx);
2971#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
2972
2987typedef int mbedtls_ssl_cookie_write_t(void *ctx,
2988 unsigned char **p, unsigned char *end,
2989 const unsigned char *info, size_t ilen);
2990
3004typedef int mbedtls_ssl_cookie_check_t(void *ctx,
3005 const unsigned char *cookie, size_t clen,
3006 const unsigned char *info, size_t ilen);
3007
3008#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
3038 mbedtls_ssl_cookie_write_t *f_cookie_write,
3039 mbedtls_ssl_cookie_check_t *f_cookie_check,
3040 void *p_cookie);
3041
3062 const unsigned char *info,
3063 size_t ilen);
3064
3065#endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
3066
3067#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
3084#endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
3085
3110
3111#if defined(MBEDTLS_SSL_PROTO_DTLS)
3112
3142 unsigned allow_packing);
3143
3175void mbedtls_ssl_conf_handshake_timeout(mbedtls_ssl_config *conf, uint32_t min, uint32_t max);
3176#endif /* MBEDTLS_SSL_PROTO_DTLS */
3177
3178#if defined(MBEDTLS_SSL_SRV_C)
3237 void *p_cache,
3238 mbedtls_ssl_cache_get_t *f_get_cache,
3239 mbedtls_ssl_cache_set_t *f_set_cache);
3240
3241#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
3261 void *p_cache);
3262#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
3263#endif /* MBEDTLS_SSL_SRV_C */
3264
3265#if defined(MBEDTLS_SSL_CLI_C)
3321#endif /* MBEDTLS_SSL_CLI_C */
3322
3377 const unsigned char *buf,
3378 size_t len);
3379
3427 unsigned char *buf,
3428 size_t buf_len,
3429 size_t *olen);
3430
3473 const int *ciphersuites);
3474
3475#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
3517
3519 const int kex_modes);
3520#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
3521
3522#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
3523#define MBEDTLS_SSL_UNEXPECTED_CID_IGNORE 0
3524#define MBEDTLS_SSL_UNEXPECTED_CID_FAIL 1
3558 int ignore_other_cids);
3559#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
3560
3561#if defined(MBEDTLS_X509_CRT_PARSE_C)
3580 const mbedtls_x509_crt_profile *profile);
3581
3601 mbedtls_x509_crt *ca_chain,
3602 mbedtls_x509_crl *ca_crl);
3603
3604#if defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED)
3616static inline
3618 const mbedtls_x509_crt *crt)
3619{
3620 conf->MBEDTLS_PRIVATE(dn_hints) = crt;
3621}
3622#endif /* MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */
3623
3624#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
3683void mbedtls_ssl_conf_ca_cb(mbedtls_ssl_config *conf,
3685 void *p_ca_cb);
3686#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
3687
3725 mbedtls_x509_crt *own_cert,
3726 mbedtls_pk_context *pk_key);
3727#endif /* MBEDTLS_X509_CRT_PARSE_C */
3728
3729#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
3768 const unsigned char *psk, size_t psk_len,
3769 const unsigned char *psk_identity, size_t psk_identity_len);
3770
3815 const unsigned char *psk_identity,
3816 size_t psk_identity_len);
3817
3835 const unsigned char *psk, size_t psk_len);
3836
3859
3860#if defined(MBEDTLS_SSL_SRV_C)
3905 int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *,
3906 size_t),
3907 void *p_psk);
3908#endif /* MBEDTLS_SSL_SRV_C */
3909#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
3910
3916typedef struct {
3918 uint16_t tls_id;
3919
3921 const char *group_name;
3922
3926
3927/* Helpers to check which PSA_WANT_xxx symbols are defined for groups. */
3928#if defined(PSA_WANT_ECC_MONTGOMERY_255)
3929#define MBEDTLS_SSL_HAVE_GROUP_X25519 1
3930#else
3931#define MBEDTLS_SSL_HAVE_GROUP_X25519 0
3932#endif
3933#if defined(PSA_WANT_ECC_SECP_R1_256)
3934#define MBEDTLS_SSL_HAVE_GROUP_SECP256R1 1
3935#else
3936#define MBEDTLS_SSL_HAVE_GROUP_SECP256R1 0
3937#endif
3938#if defined(PSA_WANT_ECC_SECP_K1_256)
3939#define MBEDTLS_SSL_HAVE_GROUP_SECP256K1 1
3940#else
3941#define MBEDTLS_SSL_HAVE_GROUP_SECP256K1 0
3942#endif
3943#if defined(PSA_WANT_ECC_SECP_R1_384)
3944#define MBEDTLS_SSL_HAVE_GROUP_SECP384R1 1
3945#else
3946#define MBEDTLS_SSL_HAVE_GROUP_SECP384R1 0
3947#endif
3948#if defined(PSA_WANT_ECC_MONTGOMERY_448)
3949#define MBEDTLS_SSL_HAVE_GROUP_X448 1
3950#else
3951#define MBEDTLS_SSL_HAVE_GROUP_X448 0
3952#endif
3953#if defined(PSA_WANT_ECC_SECP_R1_521)
3954#define MBEDTLS_SSL_HAVE_GROUP_SECP521R1 1
3955#else
3956#define MBEDTLS_SSL_HAVE_GROUP_SECP521R1 0
3957#endif
3958#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
3959#define MBEDTLS_SSL_HAVE_GROUP_BP256R1 1
3960#else
3961#define MBEDTLS_SSL_HAVE_GROUP_BP256R1 0
3962#endif
3963#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_384)
3964#define MBEDTLS_SSL_HAVE_GROUP_BP384R1 1
3965#else
3966#define MBEDTLS_SSL_HAVE_GROUP_BP384R1 0
3967#endif
3968#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_512)
3969#define MBEDTLS_SSL_HAVE_GROUP_BP512R1 1
3970#else
3971#define MBEDTLS_SSL_HAVE_GROUP_BP512R1 0
3972#endif
3973#if defined(PSA_WANT_DH_RFC7919_2048)
3974#define MBEDTLS_SSL_HAVE_GROUP_FFDHE2048 1
3975#else
3976#define MBEDTLS_SSL_HAVE_GROUP_FFDHE2048 0
3977#endif
3978#if defined(PSA_WANT_DH_RFC7919_3072)
3979#define MBEDTLS_SSL_HAVE_GROUP_FFDHE3072 1
3980#else
3981#define MBEDTLS_SSL_HAVE_GROUP_FFDHE3072 0
3982#endif
3983#if defined(PSA_WANT_DH_RFC7919_4096)
3984#define MBEDTLS_SSL_HAVE_GROUP_FFDHE4096 1
3985#else
3986#define MBEDTLS_SSL_HAVE_GROUP_FFDHE4096 0
3987#endif
3988#if defined(PSA_WANT_DH_RFC7919_6144)
3989#define MBEDTLS_SSL_HAVE_GROUP_FFDHE6144 1
3990#else
3991#define MBEDTLS_SSL_HAVE_GROUP_FFDHE6144 0
3992#endif
3993#if defined(PSA_WANT_DH_RFC7919_8192)
3994#define MBEDTLS_SSL_HAVE_GROUP_FFDHE8192 1
3995#else
3996#define MBEDTLS_SSL_HAVE_GROUP_FFDHE8192 0
3997#endif
3998
4006#define MBEDTLS_SSL_IANA_TLS_GROUPS_INFO \
4007 { \
4008 { MBEDTLS_SSL_IANA_TLS_GROUP_X25519, "x25519", MBEDTLS_SSL_HAVE_GROUP_X25519 }, \
4009 { MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1, "secp256r1", MBEDTLS_SSL_HAVE_GROUP_SECP256R1 }, \
4010 { MBEDTLS_SSL_IANA_TLS_GROUP_SECP256K1, "secp256k1", MBEDTLS_SSL_HAVE_GROUP_SECP256K1 }, \
4011 { MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1, "secp384r1", MBEDTLS_SSL_HAVE_GROUP_SECP384R1 }, \
4012 { MBEDTLS_SSL_IANA_TLS_GROUP_X448, "x448", MBEDTLS_SSL_HAVE_GROUP_X448 }, \
4013 { MBEDTLS_SSL_IANA_TLS_GROUP_SECP521R1, "secp521r1", MBEDTLS_SSL_HAVE_GROUP_SECP521R1 }, \
4014 { MBEDTLS_SSL_IANA_TLS_GROUP_BP256R1, "brainpoolP256r1", MBEDTLS_SSL_HAVE_GROUP_BP256R1 }, \
4015 { MBEDTLS_SSL_IANA_TLS_GROUP_BP384R1, "brainpoolP384r1", MBEDTLS_SSL_HAVE_GROUP_BP384R1 }, \
4016 { MBEDTLS_SSL_IANA_TLS_GROUP_BP512R1, "brainpoolP512r1", MBEDTLS_SSL_HAVE_GROUP_BP512R1 }, \
4017 { MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE2048, "ffdhe2048", MBEDTLS_SSL_HAVE_GROUP_FFDHE2048 }, \
4018 { MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE3072, "ffdhe3072", MBEDTLS_SSL_HAVE_GROUP_FFDHE3072 }, \
4019 { MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE4096, "ffdhe4096", MBEDTLS_SSL_HAVE_GROUP_FFDHE4096 }, \
4020 { MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE6144, "ffdhe6144", MBEDTLS_SSL_HAVE_GROUP_FFDHE6144 }, \
4021 { MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE8192, "ffdhe8192", MBEDTLS_SSL_HAVE_GROUP_FFDHE8192 }, \
4022 { MBEDTLS_SSL_IANA_TLS_GROUP_NONE, NULL, 1 } \
4023 }
4024
4025#if defined(MBEDTLS_DEBUG_C)
4031#endif /* MBEDTLS_DEBUG_C */
4032
4050
4086 const uint16_t *groups);
4087
4088#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
4089
4108 const uint16_t *sig_algs);
4109#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
4110
4111#if defined(MBEDTLS_X509_CRT_PARSE_C)
4143int mbedtls_ssl_set_hostname(mbedtls_ssl_context *ssl, const char *hostname);
4144
4155static inline const char *mbedtls_ssl_get_hostname(mbedtls_ssl_context *ssl)
4156{
4157 return ssl->MBEDTLS_PRIVATE(hostname);
4158}
4159#endif /* MBEDTLS_X509_CRT_PARSE_C */
4160
4161#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
4181 size_t *name_len);
4182
4199 mbedtls_x509_crt *own_cert,
4200 mbedtls_pk_context *pk_key);
4201
4214 mbedtls_x509_crt *ca_chain,
4215 mbedtls_x509_crl *ca_crl);
4216
4217#if defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED)
4229 const mbedtls_x509_crt *crt);
4230#endif /* MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */
4231
4243 int authmode);
4244
4287 int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *,
4288 size_t),
4289 void *p_sni);
4290#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
4291
4292#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
4311int mbedtls_ssl_set_hs_ecjpake_password(mbedtls_ssl_context *ssl,
4312 const unsigned char *pw,
4313 size_t pw_len);
4314
4329int mbedtls_ssl_set_hs_ecjpake_password_opaque(mbedtls_ssl_context *ssl,
4331#endif /*MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
4332
4333#if defined(MBEDTLS_SSL_ALPN)
4347 const char *const *protos);
4348
4359#endif /* MBEDTLS_SSL_ALPN */
4360
4361#if defined(MBEDTLS_SSL_DTLS_SRTP)
4362#if defined(MBEDTLS_DEBUG_C)
4363static inline const char *mbedtls_ssl_get_srtp_profile_as_string(mbedtls_ssl_srtp_profile profile)
4364{
4365 switch (profile) {
4366 case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80:
4367 return "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80";
4368 case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32:
4369 return "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32";
4370 case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80:
4371 return "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80";
4372 case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32:
4373 return "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32";
4374 default: break;
4375 }
4376 return "";
4377}
4378#endif /* MBEDTLS_DEBUG_C */
4392void mbedtls_ssl_conf_srtp_mki_value_supported(mbedtls_ssl_config *conf,
4393 int support_mki_value);
4394
4414int mbedtls_ssl_conf_dtls_srtp_protection_profiles
4415 (mbedtls_ssl_config *conf,
4416 const mbedtls_ssl_srtp_profile *profiles);
4417
4434int mbedtls_ssl_dtls_srtp_set_mki_value(mbedtls_ssl_context *ssl,
4435 unsigned char *mki_value,
4436 uint16_t mki_len);
4455void mbedtls_ssl_get_dtls_srtp_negotiation_result(const mbedtls_ssl_context *ssl,
4456 mbedtls_dtls_srtp_info *dtls_srtp_info);
4457#endif /* MBEDTLS_SSL_DTLS_SRTP */
4458
4472 mbedtls_ssl_protocol_version tls_version)
4473{
4474 conf->MBEDTLS_PRIVATE(max_tls_version) = tls_version;
4475}
4476
4490 mbedtls_ssl_protocol_version tls_version)
4491{
4492 conf->MBEDTLS_PRIVATE(min_tls_version) = tls_version;
4493}
4494
4495#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
4508#endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
4509
4510#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
4523#endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */
4524
4525#if defined(MBEDTLS_SSL_SRV_C)
4536 char cert_req_ca_list);
4537#endif /* MBEDTLS_SSL_SRV_C */
4538
4539#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
4578int mbedtls_ssl_conf_max_frag_len(mbedtls_ssl_config *conf, unsigned char mfl_code);
4579#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
4580
4581#if defined(MBEDTLS_SSL_SRV_C)
4592#endif /* MBEDTLS_SSL_SRV_C */
4593
4594#if defined(MBEDTLS_SSL_SESSION_TICKETS) && \
4595 defined(MBEDTLS_SSL_CLI_C)
4607#endif /* MBEDTLS_SSL_SESSION_TICKETS &&
4608 MBEDTLS_SSL_CLI_C */
4609
4610#if defined(MBEDTLS_SSL_SESSION_TICKETS) && \
4611 defined(MBEDTLS_SSL_SRV_C) && \
4612 defined(MBEDTLS_SSL_PROTO_TLS1_3)
4631 uint16_t num_tickets);
4632#endif /* MBEDTLS_SSL_SESSION_TICKETS &&
4633 MBEDTLS_SSL_SRV_C &&
4634 MBEDTLS_SSL_PROTO_TLS1_3*/
4635
4636#if defined(MBEDTLS_SSL_RENEGOTIATION)
4655#endif /* MBEDTLS_SSL_RENEGOTIATION */
4656
4685
4686#if defined(MBEDTLS_SSL_RENEGOTIATION)
4725
4752 const unsigned char period[8]);
4753#endif /* MBEDTLS_SSL_RENEGOTIATION */
4754
4794
4811
4825
4834
4843
4844
4857 const mbedtls_ssl_context *ssl)
4858{
4859 return ssl->MBEDTLS_PRIVATE(tls_version);
4860}
4861
4870
4880
4907
4927
4928#if defined(MBEDTLS_X509_CRT_PARSE_C)
4960#endif /* MBEDTLS_X509_CRT_PARSE_C */
4961
4962#if defined(MBEDTLS_SSL_CLI_C)
4997 mbedtls_ssl_session *session);
4998#endif /* MBEDTLS_SSL_CLI_C */
4999
5078
5091{
5092 return ssl->MBEDTLS_PRIVATE(state) >= MBEDTLS_SSL_HANDSHAKE_OVER;
5093}
5094
5132
5133#if defined(MBEDTLS_SSL_RENEGOTIATION)
5161#endif /* MBEDTLS_SSL_RENEGOTIATION */
5162
5248int mbedtls_ssl_read(mbedtls_ssl_context *ssl, unsigned char *buf, size_t len);
5249
5323int mbedtls_ssl_write(mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len);
5324
5342 unsigned char level,
5343 unsigned char message);
5344
5359
5374
5375#if defined(MBEDTLS_SSL_EARLY_DATA)
5376
5377#if defined(MBEDTLS_SSL_SRV_C)
5425int mbedtls_ssl_read_early_data(mbedtls_ssl_context *ssl,
5426 unsigned char *buf, size_t len);
5427#endif /* MBEDTLS_SSL_SRV_C */
5428
5429#if defined(MBEDTLS_SSL_CLI_C)
5514int mbedtls_ssl_write_early_data(mbedtls_ssl_context *ssl,
5515 const unsigned char *buf, size_t len);
5516
5543int mbedtls_ssl_get_early_data_status(mbedtls_ssl_context *ssl);
5544#endif /* MBEDTLS_SSL_CLI_C */
5545
5546#endif /* MBEDTLS_SSL_EARLY_DATA */
5547
5554
5555#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION)
5626 unsigned char *buf,
5627 size_t buf_len,
5628 size_t *olen);
5629
5720 const unsigned char *buf,
5721 size_t len);
5722#endif /* MBEDTLS_SSL_CONTEXT_SERIALIZATION */
5723
5735
5752 int endpoint, int transport, int preset);
5753
5760
5767
5778
5795 const unsigned char *secret, size_t slen,
5796 const char *label,
5797 const unsigned char *random, size_t rlen,
5798 unsigned char *dstbuf, size_t dlen);
5799
5800#if defined(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT)
5801/* Maximum value for key_len in mbedtls_ssl_export_keying material. Depending on the TLS
5802 * version and the negotiated ciphersuite, larger keys could in principle be exported,
5803 * but for simplicity, we define one limit that works in all cases. TLS 1.3 with SHA256
5804 * has the strictest limit: 255 blocks of SHA256 output, or 8160 bytes. */
5805#define MBEDTLS_SSL_EXPORT_MAX_KEY_LEN 8160
5806
5830 uint8_t *out, const size_t key_len,
5831 const char *label, const size_t label_len,
5832 const unsigned char *context, const size_t context_len,
5833 const int use_context);
5834#endif
5835#ifdef __cplusplus
5836}
5837#endif
5838
5839#endif /* ssl.h */
Platform Security Architecture cryptography module.
#define PSA_ERROR_INVALID_ARGUMENT
psa_key_id_t mbedtls_svc_key_id_t
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:836
Build-time configuration info.
This file contains the generic functions for message-digest (hashing) and HMAC.
mbedtls_md_type_t
Supported message digests.
Definition md.h:50
Mbed TLS Platform time abstraction.
int64_t mbedtls_ms_time_t
time_t mbedtls_time_t
Common and shared functions used by multiple modules in the Mbed TLS library.
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:4155
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).
int mbedtls_ssl_set_hs_psk_opaque(mbedtls_ssl_context *ssl, mbedtls_svc_key_id_t psk)
Set an opaque pre-shared Key (PSK) for the current handshake.
#define MBEDTLS_PSK_MAX_LEN
Definition ssl.h:645
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.
const mbedtls_x509_crt * mbedtls_ssl_get_peer_cert(const mbedtls_ssl_context *ssl)
Return the peer certificate from the current connection.
void mbedtls_ssl_conf_read_timeout(mbedtls_ssl_config *conf, uint32_t timeout)
Set the timeout period for mbedtls_ssl_read() (Default: no timeout.).
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:913
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:2586
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).
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_conf_renegotiation_period(mbedtls_ssl_config *conf, const unsigned char period[8])
Set record counter threshold for periodic renegotiation. (Default: 2^48 - 1).
#define MBEDTLS_SSL_CID_OUT_LEN_MAX
Definition ssl.h:428
void mbedtls_ssl_conf_legacy_renegotiation(mbedtls_ssl_config *conf, int allow_legacy)
Prevent or allow legacy renegotiation. (Default: MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION).
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).
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:1303
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_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...
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:2817
int mbedtls_ssl_session_reset(mbedtls_ssl_context *ssl)
Reset an already initialized SSL context for re-use while retaining application-set variables,...
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:2896
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:2800
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....
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...
struct mbedtls_ssl_transform mbedtls_ssl_transform
Definition ssl.h:868
void mbedtls_ssl_conf_renegotiation_enforced(mbedtls_ssl_config *conf, int max_records)
Enforce renegotiation requests. (Default: enforced, max_records = 16).
void mbedtls_ssl_free(mbedtls_ssl_context *ssl)
Free referenced items in an SSL context and clear memory.
void mbedtls_ssl_conf_transport(mbedtls_ssl_config *conf, int transport)
Set the transport type (TLS or DTLS). Default: TLS.
#define MBEDTLS_SSL_CID_IN_LEN_MAX
Definition ssl.h:424
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.).
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.
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...
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.
mbedtls_tls_prf_types
Definition ssl.h:1267
@ MBEDTLS_SSL_TLS_PRF_SHA384
Definition ssl.h:1269
@ MBEDTLS_SSL_HKDF_EXPAND_SHA256
Definition ssl.h:1272
@ MBEDTLS_SSL_TLS_PRF_SHA256
Definition ssl.h:1270
@ MBEDTLS_SSL_TLS_PRF_NONE
Definition ssl.h:1268
@ MBEDTLS_SSL_HKDF_EXPAND_SHA384
Definition ssl.h:1271
int mbedtls_ssl_send_t(void *ctx, const unsigned char *buf, size_t len)
Callback type: send data on the network.
Definition ssl.h:769
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).
mbedtls_ssl_states
Definition ssl.h:703
@ MBEDTLS_SSL_CERTIFICATE_VERIFY
Definition ssl.h:713
@ MBEDTLS_SSL_HANDSHAKE_OVER
Definition ssl.h:731
@ MBEDTLS_SSL_SERVER_HELLO_DONE
Definition ssl.h:710
@ MBEDTLS_SSL_END_OF_EARLY_DATA
Definition ssl.h:724
@ MBEDTLS_SSL_NEW_SESSION_TICKET
Definition ssl.h:720
@ MBEDTLS_SSL_SERVER_FINISHED
Definition ssl.h:717
@ MBEDTLS_SSL_SERVER_KEY_EXCHANGE
Definition ssl.h:708
@ MBEDTLS_SSL_ENCRYPTED_EXTENSIONS
Definition ssl.h:723
@ MBEDTLS_SSL_SERVER_HELLO
Definition ssl.h:706
@ MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST
Definition ssl.h:730
@ MBEDTLS_SSL_CLIENT_KEY_EXCHANGE
Definition ssl.h:712
@ MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO
Definition ssl.h:727
@ MBEDTLS_SSL_CLIENT_HELLO
Definition ssl.h:705
@ MBEDTLS_SSL_SERVER_CERTIFICATE
Definition ssl.h:707
@ MBEDTLS_SSL_CERTIFICATE_REQUEST
Definition ssl.h:709
@ MBEDTLS_SSL_CLIENT_FINISHED
Definition ssl.h:715
@ MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC
Definition ssl.h:716
@ MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT
Definition ssl.h:721
@ MBEDTLS_SSL_HANDSHAKE_WRAPUP
Definition ssl.h:719
@ MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED
Definition ssl.h:726
@ MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC
Definition ssl.h:714
@ MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY
Definition ssl.h:725
@ MBEDTLS_SSL_HELLO_REQUEST
Definition ssl.h:704
@ MBEDTLS_SSL_CLIENT_CERTIFICATE
Definition ssl.h:711
@ MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH
Definition ssl.h:733
@ MBEDTLS_SSL_FLUSH_BUFFERS
Definition ssl.h:718
@ MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO
Definition ssl.h:729
@ MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET
Definition ssl.h:732
@ MBEDTLS_SSL_HELLO_RETRY_REQUEST
Definition ssl.h:722
@ MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO
Definition ssl.h:728
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).
const uint16_t * mbedtls_ssl_get_supported_group_list(void)
Return the list of supported groups (curves and finite fields).
void mbedtls_ssl_conf_endpoint(mbedtls_ssl_config *conf, int endpoint)
Set the current endpoint type.
int(* mbedtls_ssl_hs_cb_t)(mbedtls_ssl_context *ssl)
Callback type: generic handshake callback.
Definition ssl.h:1327
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.
mbedtls_ssl_protocol_version
Definition ssl.h:1137
@ MBEDTLS_SSL_VERSION_TLS1_2
Definition ssl.h:1139
@ MBEDTLS_SSL_VERSION_TLS1_3
Definition ssl.h:1140
@ MBEDTLS_SSL_VERSION_UNKNOWN
Definition ssl.h:1138
int mbedtls_ssl_get_fatal_alert(const mbedtls_ssl_context *ssl)
Get the last received fatal alert.
int mbedtls_ssl_send_alert_message(mbedtls_ssl_context *ssl, unsigned char level, unsigned char message)
Send an alert message.
const char * mbedtls_ssl_get_version(const mbedtls_ssl_context *ssl)
Return the current TLS version.
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:5090
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_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:2616
int mbedtls_ssl_renegotiate(mbedtls_ssl_context *ssl)
Initiate an SSL renegotiation on the running connection. Client: perform the renegotiation right now....
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:2560
int mbedtls_ssl_handshake(mbedtls_ssl_context *ssl)
Perform the SSL handshake.
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.
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_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.
uint32_t mbedtls_ssl_get_verify_result(const mbedtls_ssl_context *ssl)
Return the result of the certificate verification.
#define MBEDTLS_SSL_SEQUENCE_NUMBER_LEN
Definition ssl.h:686
mbedtls_ssl_key_export_type
Definition ssl.h:1276
@ MBEDTLS_SSL_KEY_EXPORT_TLS1_3_CLIENT_APPLICATION_TRAFFIC_SECRET
Definition ssl.h:1283
@ MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET
Definition ssl.h:1277
@ MBEDTLS_SSL_KEY_EXPORT_TLS1_3_SERVER_APPLICATION_TRAFFIC_SECRET
Definition ssl.h:1284
@ MBEDTLS_SSL_KEY_EXPORT_TLS1_3_SERVER_HANDSHAKE_TRAFFIC_SECRET
Definition ssl.h:1282
@ MBEDTLS_SSL_KEY_EXPORT_TLS1_3_CLIENT_HANDSHAKE_TRAFFIC_SECRET
Definition ssl.h:1281
@ MBEDTLS_SSL_KEY_EXPORT_TLS1_3_EARLY_EXPORTER_SECRET
Definition ssl.h:1280
@ MBEDTLS_SSL_KEY_EXPORT_TLS1_3_CLIENT_EARLY_SECRET
Definition ssl.h:1279
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_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:2987
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:4856
void mbedtls_ssl_conf_authmode(mbedtls_ssl_config *conf, int authmode)
Set the certificate verification mode Default: NONE on server, REQUIRED on client.
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_get_max_out_record_payload(const mbedtls_ssl_context *ssl)
Return the current maximum outgoing record payload in bytes.
int mbedtls_ssl_write(mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len)
Try to write exactly 'len' application data bytes.
struct mbedtls_ssl_handshake_params mbedtls_ssl_handshake_params
Definition ssl.h:869
int mbedtls_ssl_get_max_in_record_payload(const mbedtls_ssl_context *ssl)
Return the current maximum incoming record payload in bytes.
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_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:845
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....
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:2163
void mbedtls_ssl_conf_sig_algs(mbedtls_ssl_config *conf, const uint16_t *sig_algs)
Configure allowed signature algorithms for use in TLS key exchange.
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:819
#define MBEDTLS_SSL_IS_SERVER
Definition ssl.h:295
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.).
void mbedtls_ssl_config_free(mbedtls_ssl_config *conf)
Free an SSL configuration context.
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:3617
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.
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_session_init(mbedtls_ssl_session *session)
Initialize SSL session structure.
#define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN
Definition ssl.h:456
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.
int mbedtls_ssl_context_load(mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len)
Load serialized connection data to an SSL context.
void mbedtls_ssl_set_hs_authmode(mbedtls_ssl_context *ssl, int authmode)
Set authmode for the current 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.
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().
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 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:2833
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...
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.
void mbedtls_ssl_set_hs_session_cache_context(mbedtls_ssl_context *ssl, void *p_cache)
Set the session cache callback context for the current handshake (server only).
const char * mbedtls_ssl_get_ciphersuite(const mbedtls_ssl_context *ssl)
Return the name of the current ciphersuite.
int mbedtls_ssl_set_session(mbedtls_ssl_context *ssl, const mbedtls_ssl_session *session)
Load a session for session resumption.
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...
#define MBEDTLS_SSL_TLS1_3_TICKET_RESUMPTION_KEY_LEN
Definition ssl.h:353
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_session_tickets(mbedtls_ssl_config *conf, int use_tickets)
Enable / Disable session tickets (client only). (Default: MBEDTLS_SSL_SESSION_TICKETS_ENABLED....
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_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....
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:3004
int mbedtls_ssl_conf_alpn_protocols(mbedtls_ssl_config *conf, const char *const *protos)
Set the supported Application Layer Protocols.
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.
static int mbedtls_ssl_session_get_ciphersuite_id(const mbedtls_ssl_session *session)
Get the ciphersuite-id.
Definition ssl.h:2749
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....
int mbedtls_ssl_read(mbedtls_ssl_context *ssl, unsigned char *buf, size_t len)
Read at most 'len' application data bytes.
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,...
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:2702
void mbedtls_ssl_conf_groups(mbedtls_ssl_config *conf, const uint16_t *groups)
Set the allowed groups in order of preference.
int mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl)
Perform a single step of the SSL handshake.
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:935
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...
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.
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_set_hs_session_ticket_context(mbedtls_ssl_context *ssl, void *p_ticket)
Set the SSL session ticket context for the current handshake (server only).
#define MBEDTLS_TLS1_3_MD_MAX_SIZE
Definition ssl.h:682
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_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:4471
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_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.
struct mbedtls_ssl_flight_item mbedtls_ssl_flight_item
Definition ssl.h:874
int mbedtls_ssl_recv_t(void *ctx, unsigned char *buf, size_t len)
Callback type: receive data from the network.
Definition ssl.h:793
void mbedtls_ssl_session_free(mbedtls_ssl_session *session)
Free referenced items in an SSL session including the peer certificate and clear memory.
static unsigned const char(* mbedtls_ssl_session_get_id(const mbedtls_ssl_session *session))[32]
Get the session-id buffer.
Definition ssl.h:2724
int mbedtls_ssl_close_notify(mbedtls_ssl_context *ssl)
Notify the peer that the connection is being closed.
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...
int mbedtls_ssl_get_ciphersuite_id_from_ssl(const mbedtls_ssl_context *ssl)
Return the id of the current ciphersuite.
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_SESSION_SECRET_LEN
Definition ssl.h:653
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.
int mbedtls_ssl_get_session(const mbedtls_ssl_context *ssl, mbedtls_ssl_session *session)
Export a session in order to resume it later.
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:2786
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:2880
int mbedtls_ssl_conf_psk_opaque(mbedtls_ssl_config *conf, mbedtls_svc_key_id_t psk, const unsigned char *psk_identity, size_t psk_identity_len)
Configure one or more opaque pre-shared keys (PSKs) and their identities to be used in PSK-based ciph...
int mbedtls_ssl_get_timer_t(void *ctx)
Callback type: get status of timers/delays.
Definition ssl.h:860
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:2863
mbedtls_ssl_iana_tls_group_info_t mbedtls_ssl_iana_tls_group_info[]
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:4489
struct mbedtls_ssl_key_cert mbedtls_ssl_key_cert
Definition ssl.h:871
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.
static size_t mbedtls_ssl_session_get_id_len(const mbedtls_ssl_session *session)
Get the size of the session-id.
Definition ssl.h:2737
int mbedtls_ssl_setup(mbedtls_ssl_context *ssl, const mbedtls_ssl_config *conf)
Set up an SSL context for use.
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:2849
static int mbedtls_ssl_conf_get_endpoint(const mbedtls_ssl_config *conf)
Get the current endpoint type.
Definition ssl.h:1990
void mbedtls_ssl_conf_encrypt_then_mac(mbedtls_ssl_config *conf, char etm)
Enable or disable Encrypt-then-MAC (Default: MBEDTLS_SSL_ETM_ENABLED).
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).
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.).
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 subsequent handshakes.
SSL Ciphersuites for Mbed TLS.
Public key container.
Definition pk.h:106
unsigned char exporter_master_secret[MBEDTLS_TLS1_3_MD_MAX_SIZE]
Definition ssl.h:1098
unsigned char resumption_master_secret[MBEDTLS_TLS1_3_MD_MAX_SIZE]
Definition ssl.h:1099
unsigned char server_application_traffic_secret_N[MBEDTLS_TLS1_3_MD_MAX_SIZE]
Definition ssl.h:1097
unsigned char client_application_traffic_secret_N[MBEDTLS_TLS1_3_MD_MAX_SIZE]
Definition ssl.h:1096
unsigned char _pms_ecdhe_psk[4+MBEDTLS_ECP_MAX_BYTES+MBEDTLS_PSK_MAX_LEN]
Definition ssl.h:673
unsigned char _pms_psk[4+2 *MBEDTLS_PSK_MAX_LEN]
Definition ssl.h:669
unsigned char dummy
Definition ssl.h:663
unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]
Definition ssl.h:666
X.509 certificate revocation list parsing.
X.509 certificate parsing and writing.