Mbed TLS v4.1.1
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/* Dummy type used only for its size */
653 unsigned char dummy; /* Make the union non-empty even with SSL disabled */
654#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
655 defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
656 unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]; /* RFC 4492 5.10 */
657#endif
658#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
659 unsigned char _pms_psk[4 + 2 * MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 2 */
660#endif
661#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
662 unsigned char _pms_ecdhe_psk[4 + MBEDTLS_ECP_MAX_BYTES
663 + MBEDTLS_PSK_MAX_LEN]; /* RFC 5489 2 */
664#endif
665#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
666 unsigned char _pms_ecjpake[32]; /* Thread spec: SHA-256 output */
667#endif
668};
669
670#define MBEDTLS_PREMASTER_SIZE sizeof(union mbedtls_ssl_premaster_secret)
671
672#define MBEDTLS_TLS1_3_MD_MAX_SIZE PSA_HASH_MAX_SIZE
673
674
675/* Length in number of bytes of the TLS sequence number */
676#define MBEDTLS_SSL_SEQUENCE_NUMBER_LEN 8
677
678/* Helper to state that client_random and server_random need to be stored
679 * after the handshake is complete. This is required for context serialization
680 * and for the keying material exporter in TLS 1.2. */
681#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION) || \
682 (defined(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT) && defined(MBEDTLS_SSL_PROTO_TLS1_2))
683#define MBEDTLS_SSL_KEEP_RANDBYTES
684#endif
685
686#ifdef __cplusplus
687extern "C" {
688#endif
689
690/*
691 * SSL state machine
692 */
726
727/*
728 * Early data status, client side only.
729 */
730
731#if defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_CLI_C)
732typedef enum {
733/*
734 * See documentation of mbedtls_ssl_get_early_data_status().
735 */
736 MBEDTLS_SSL_EARLY_DATA_STATUS_NOT_INDICATED,
737 MBEDTLS_SSL_EARLY_DATA_STATUS_ACCEPTED,
738 MBEDTLS_SSL_EARLY_DATA_STATUS_REJECTED,
739} mbedtls_ssl_early_data_status;
740#endif /* MBEDTLS_SSL_EARLY_DATA && MBEDTLS_SSL_CLI_C */
741
759typedef int mbedtls_ssl_send_t(void *ctx,
760 const unsigned char *buf,
761 size_t len);
762
783typedef int mbedtls_ssl_recv_t(void *ctx,
784 unsigned char *buf,
785 size_t len);
786
809typedef int mbedtls_ssl_recv_timeout_t(void *ctx,
810 unsigned char *buf,
811 size_t len,
812 uint32_t timeout);
835typedef void mbedtls_ssl_set_timer_t(void *ctx,
836 uint32_t int_ms,
837 uint32_t fin_ms);
838
850typedef int mbedtls_ssl_get_timer_t(void *ctx);
851
852/* Defined below */
856
857/* Defined in library/ssl_misc.h */
860#if defined(MBEDTLS_X509_CRT_PARSE_C)
862#endif
863#if defined(MBEDTLS_SSL_PROTO_DTLS)
865#endif
866
867#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS)
868#define MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_PSK_RESUMPTION \
869 MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK /* 1U << 0 */
870#define MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_PSK_EPHEMERAL_RESUMPTION \
871 MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL /* 1U << 2 */
872#define MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_EARLY_DATA (1U << 3)
873
874#define MBEDTLS_SSL_TLS1_3_TICKET_FLAGS_MASK \
875 (MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_PSK_RESUMPTION | \
876 MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_PSK_EPHEMERAL_RESUMPTION | \
877 MBEDTLS_SSL_TLS1_3_TICKET_ALLOW_EARLY_DATA)
878#endif /* MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_SESSION_TICKETS */
879
903typedef int mbedtls_ssl_cache_get_t(void *data,
904 unsigned char const *session_id,
905 size_t session_id_len,
906 mbedtls_ssl_session *session);
925typedef int mbedtls_ssl_cache_set_t(void *data,
926 unsigned char const *session_id,
927 size_t session_id_len,
928 const mbedtls_ssl_session *session);
929
930#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
931#if defined(MBEDTLS_X509_CRT_PARSE_C)
993typedef int mbedtls_ssl_async_sign_t(mbedtls_ssl_context *ssl,
994 mbedtls_x509_crt *cert,
995 mbedtls_md_type_t md_alg,
996 const unsigned char *hash,
997 size_t hash_len);
998#endif /* MBEDTLS_X509_CRT_PARSE_C */
999
1041typedef int mbedtls_ssl_async_resume_t(mbedtls_ssl_context *ssl,
1042 unsigned char *output,
1043 size_t *output_len,
1044 size_t output_size);
1045
1063typedef void mbedtls_ssl_async_cancel_t(mbedtls_ssl_context *ssl);
1064#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
1065
1066#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) && \
1067 !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
1068#define MBEDTLS_SSL_PEER_CERT_DIGEST_MAX_LEN 48
1069#if defined(PSA_WANT_ALG_SHA_256)
1070#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA256
1071#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 32
1072#elif defined(PSA_WANT_ALG_SHA_384)
1073#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA384
1074#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 48
1075#elif defined(PSA_WANT_ALG_SHA_1)
1076#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA1
1077#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 20
1078#else
1079/* This is already checked in check_config.h, but be sure. */
1080#error "Bad configuration - need SHA-1, SHA-256 or SHA-512 enabled to compute digest of peer CRT."
1081#endif
1082#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED &&
1083 !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
1084
1091
1092#if defined(MBEDTLS_SSL_DTLS_SRTP)
1093
1094#define MBEDTLS_TLS_SRTP_MAX_MKI_LENGTH 255
1095#define MBEDTLS_TLS_SRTP_MAX_PROFILE_LIST_LENGTH 4
1096/*
1097 * For code readability use a typedef for DTLS-SRTP profiles
1098 *
1099 * Use_srtp extension protection profiles values as defined in
1100 * http://www.iana.org/assignments/srtp-protection/srtp-protection.xhtml
1101 *
1102 * Reminder: if this list is expanded mbedtls_ssl_check_srtp_profile_value
1103 * must be updated too.
1104 */
1105#define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80 ((uint16_t) 0x0001)
1106#define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32 ((uint16_t) 0x0002)
1107#define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80 ((uint16_t) 0x0005)
1108#define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32 ((uint16_t) 0x0006)
1109/* This one is not iana defined, but for code readability. */
1110#define MBEDTLS_TLS_SRTP_UNSET ((uint16_t) 0x0000)
1111
1113
1116 mbedtls_ssl_srtp_profile MBEDTLS_PRIVATE(chosen_dtls_srtp_profile);
1118 uint16_t MBEDTLS_PRIVATE(mki_len);
1120 unsigned char MBEDTLS_PRIVATE(mki_value)[MBEDTLS_TLS_SRTP_MAX_MKI_LENGTH];
1121}
1123
1124#endif /* MBEDTLS_SSL_DTLS_SRTP */
1125
1132
1133/*
1134 * This structure is used for storing current session data.
1135 *
1136 * Note: when changing this definition, we need to check and update:
1137 * - in tests/suites/test_suite_ssl.function:
1138 * ssl_populate_session() and ssl_serialize_session_save_load()
1139 * - in library/ssl_tls.c:
1140 * mbedtls_ssl_session_init() and mbedtls_ssl_session_free()
1141 * mbedtls_ssl_session_save() and ssl_session_load()
1142 * ssl_session_copy()
1143 */
1145#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
1146 unsigned char MBEDTLS_PRIVATE(mfl_code);
1147#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
1148
1150#if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT)
1151 uint16_t MBEDTLS_PRIVATE(record_size_limit);
1152#endif /* MBEDTLS_SSL_RECORD_SIZE_LIMIT */
1153
1154 unsigned char MBEDTLS_PRIVATE(exported);
1155 uint8_t MBEDTLS_PRIVATE(endpoint);
1156
1160 mbedtls_ssl_protocol_version MBEDTLS_PRIVATE(tls_version);
1161
1162#if defined(MBEDTLS_HAVE_TIME)
1163 mbedtls_time_t MBEDTLS_PRIVATE(start);
1164#endif
1165 int MBEDTLS_PRIVATE(ciphersuite);
1166 size_t MBEDTLS_PRIVATE(id_len);
1167 unsigned char MBEDTLS_PRIVATE(id)[32];
1168 unsigned char MBEDTLS_PRIVATE(master)[48];
1169
1170#if defined(MBEDTLS_X509_CRT_PARSE_C)
1171#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
1172 mbedtls_x509_crt *MBEDTLS_PRIVATE(peer_cert);
1173#else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
1176 unsigned char *MBEDTLS_PRIVATE(peer_cert_digest);
1177 size_t MBEDTLS_PRIVATE(peer_cert_digest_len);
1178 mbedtls_md_type_t MBEDTLS_PRIVATE(peer_cert_digest_type);
1179#endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
1180#endif /* MBEDTLS_X509_CRT_PARSE_C */
1181 uint32_t MBEDTLS_PRIVATE(verify_result);
1182
1183#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
1184 unsigned char *MBEDTLS_PRIVATE(ticket);
1185 size_t MBEDTLS_PRIVATE(ticket_len);
1186 uint32_t MBEDTLS_PRIVATE(ticket_lifetime);
1187#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
1188
1189#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C) && \
1190 defined(MBEDTLS_HAVE_TIME)
1207 mbedtls_ms_time_t MBEDTLS_PRIVATE(ticket_creation_time);
1208#endif
1209
1210#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS)
1211 uint32_t MBEDTLS_PRIVATE(ticket_age_add);
1212 uint8_t MBEDTLS_PRIVATE(ticket_flags);
1213 uint8_t MBEDTLS_PRIVATE(resumption_key_len);
1214 unsigned char MBEDTLS_PRIVATE(resumption_key)[MBEDTLS_SSL_TLS1_3_TICKET_RESUMPTION_KEY_LEN];
1215
1216#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) && defined(MBEDTLS_SSL_CLI_C)
1217 char *MBEDTLS_PRIVATE(hostname);
1218#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION && MBEDTLS_SSL_CLI_C */
1219
1220#if defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_ALPN) && defined(MBEDTLS_SSL_SRV_C)
1221 char *MBEDTLS_PRIVATE(ticket_alpn);
1223#endif
1224
1225#if defined(MBEDTLS_HAVE_TIME) && defined(MBEDTLS_SSL_CLI_C)
1227 mbedtls_ms_time_t MBEDTLS_PRIVATE(ticket_reception_time);
1228#endif
1229#endif /* MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_SESSION_TICKETS */
1230
1231#if defined(MBEDTLS_SSL_EARLY_DATA)
1232 uint32_t MBEDTLS_PRIVATE(max_early_data_size);
1233#endif
1234
1235#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1236 int MBEDTLS_PRIVATE(encrypt_then_mac);
1237#endif
1238
1239#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
1240 mbedtls_ssl_tls13_application_secrets MBEDTLS_PRIVATE(app_secrets);
1241#endif
1242
1243 /* Unused field reserved for future use */
1244 union {
1245 size_t number;
1246 void *ptr;
1247 } MBEDTLS_PRIVATE(unused);
1248};
1249
1250/*
1251 * Identifiers for PRFs used in various versions of TLS.
1252 */
1261
1273
1289typedef void mbedtls_ssl_export_keys_t(void *p_expkey,
1291 const unsigned char *secret,
1292 size_t secret_len,
1293 const unsigned char client_random[32],
1294 const unsigned char server_random[32],
1295 mbedtls_tls_prf_types tls_prf_type);
1296
1297#if defined(MBEDTLS_SSL_SRV_C)
1314#endif
1315
1316/* A type for storing user data in a library structure.
1317 *
1318 * The representation of type may change in future versions of the library.
1319 * Only the behaviors guaranteed by documented accessor functions are
1320 * guaranteed to remain stable.
1321 */
1322typedef union {
1323 uintptr_t n; /* typically a handle to an associated object */
1324 void *p; /* typically a pointer to extra data */
1326
1331typedef union {
1332 size_t number;
1333 void *ptr;
1335
1340 /* Group items mostly by size. This helps to reduce memory wasted to
1341 * padding. It also helps to keep smaller fields early in the structure,
1342 * so that elements tend to be in the 128-element direct access window
1343 * on Arm Thumb, which reduces the code size. */
1344
1345 mbedtls_ssl_protocol_version MBEDTLS_PRIVATE(max_tls_version);
1346 mbedtls_ssl_protocol_version MBEDTLS_PRIVATE(min_tls_version);
1347
1348 /*
1349 * Flags (could be bit-fields to save RAM, but separate bytes make
1350 * the code smaller on architectures with an instruction for direct
1351 * byte access).
1352 */
1353
1354 uint8_t MBEDTLS_PRIVATE(endpoint);
1355 uint8_t MBEDTLS_PRIVATE(transport);
1356 uint8_t MBEDTLS_PRIVATE(authmode);
1357 /* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */
1358 uint8_t MBEDTLS_PRIVATE(allow_legacy_renegotiation);
1359#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
1360 uint8_t MBEDTLS_PRIVATE(mfl_code);
1362#endif
1363#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1364 uint8_t MBEDTLS_PRIVATE(encrypt_then_mac);
1365#endif
1366#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
1367 uint8_t MBEDTLS_PRIVATE(extended_ms);
1368#endif
1369#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
1370 uint8_t MBEDTLS_PRIVATE(anti_replay);
1371#endif
1372#if defined(MBEDTLS_SSL_RENEGOTIATION)
1373 uint8_t MBEDTLS_PRIVATE(disable_renegotiation);
1374#endif
1375#if defined(MBEDTLS_SSL_SESSION_TICKETS) && \
1376 defined(MBEDTLS_SSL_CLI_C)
1377 uint8_t MBEDTLS_PRIVATE(session_tickets);
1378#endif
1379
1380#if defined(MBEDTLS_SSL_SESSION_TICKETS) && \
1381 defined(MBEDTLS_SSL_SRV_C) && \
1382 defined(MBEDTLS_SSL_PROTO_TLS1_3)
1383 uint16_t MBEDTLS_PRIVATE(new_session_tickets_count);
1384#endif
1385
1386#if defined(MBEDTLS_SSL_SRV_C)
1387 uint8_t MBEDTLS_PRIVATE(cert_req_ca_list);
1389 uint8_t MBEDTLS_PRIVATE(respect_cli_pref);
1392#endif
1393#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1394 uint8_t MBEDTLS_PRIVATE(ignore_unexpected_cid);
1397#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1398#if defined(MBEDTLS_SSL_DTLS_SRTP)
1399 uint8_t MBEDTLS_PRIVATE(dtls_srtp_mki_support); /* support having mki_value
1400 in the use_srtp extension? */
1401#endif
1402
1403 /*
1404 * Pointers
1405 */
1406
1408 const int *MBEDTLS_PRIVATE(ciphersuite_list);
1409
1410#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
1412 int MBEDTLS_PRIVATE(tls13_kex_modes);
1413#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
1414
1416 void(*MBEDTLS_PRIVATE(f_dbg))(void *, int, const char *, int, const char *);
1417 void *MBEDTLS_PRIVATE(p_dbg);
1418
1420 mbedtls_ssl_cache_get_t *MBEDTLS_PRIVATE(f_get_cache);
1422 mbedtls_ssl_cache_set_t *MBEDTLS_PRIVATE(f_set_cache);
1423 void *MBEDTLS_PRIVATE(p_cache);
1424
1425#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
1427 int(*MBEDTLS_PRIVATE(f_sni))(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
1428 void *MBEDTLS_PRIVATE(p_sni);
1429#endif
1430
1431#if defined(MBEDTLS_X509_CRT_PARSE_C)
1433 int(*MBEDTLS_PRIVATE(f_vrfy))(void *, mbedtls_x509_crt *, int, uint32_t *);
1434 void *MBEDTLS_PRIVATE(p_vrfy);
1435#endif
1436
1437#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
1438#if defined(MBEDTLS_SSL_SRV_C)
1440 int(*MBEDTLS_PRIVATE(f_psk))(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
1441 void *MBEDTLS_PRIVATE(p_psk);
1442#endif
1443#endif
1444
1445#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
1447 int(*MBEDTLS_PRIVATE(f_cookie_write))(void *, unsigned char **, unsigned char *,
1448 const unsigned char *, size_t);
1450 int(*MBEDTLS_PRIVATE(f_cookie_check))(void *, const unsigned char *, size_t,
1451 const unsigned char *, size_t);
1452 void *MBEDTLS_PRIVATE(p_cookie);
1453#endif
1454
1455#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
1457 int(*MBEDTLS_PRIVATE(f_ticket_write))(void *, const mbedtls_ssl_session *,
1458 unsigned char *, const unsigned char *, size_t *,
1459 uint32_t *);
1461 int(*MBEDTLS_PRIVATE(f_ticket_parse))(void *, mbedtls_ssl_session *, unsigned char *, size_t);
1462 void *MBEDTLS_PRIVATE(p_ticket);
1463#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
1464#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1465 size_t MBEDTLS_PRIVATE(cid_len);
1466#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1467
1468#if defined(MBEDTLS_X509_CRT_PARSE_C)
1469 const mbedtls_x509_crt_profile *MBEDTLS_PRIVATE(cert_profile);
1470 mbedtls_ssl_key_cert *MBEDTLS_PRIVATE(key_cert);
1471 mbedtls_x509_crt *MBEDTLS_PRIVATE(ca_chain);
1472 mbedtls_x509_crl *MBEDTLS_PRIVATE(ca_crl);
1473#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
1474 mbedtls_x509_crt_ca_cb_t MBEDTLS_PRIVATE(f_ca_cb);
1475 void *MBEDTLS_PRIVATE(p_ca_cb);
1476#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
1477#endif /* MBEDTLS_X509_CRT_PARSE_C */
1478
1479#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
1480#if defined(MBEDTLS_X509_CRT_PARSE_C)
1481 mbedtls_ssl_async_sign_t *MBEDTLS_PRIVATE(f_async_sign_start);
1482#endif /* MBEDTLS_X509_CRT_PARSE_C */
1483 mbedtls_ssl_async_resume_t *MBEDTLS_PRIVATE(f_async_resume);
1484 mbedtls_ssl_async_cancel_t *MBEDTLS_PRIVATE(f_async_cancel);
1485 void *MBEDTLS_PRIVATE(p_async_config_data);
1486#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
1487
1488#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
1489 const uint16_t *MBEDTLS_PRIVATE(sig_algs);
1490#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
1491
1492 const uint16_t *MBEDTLS_PRIVATE(group_list);
1493
1494#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
1495
1496 mbedtls_svc_key_id_t MBEDTLS_PRIVATE(psk_opaque);
1502 unsigned char *MBEDTLS_PRIVATE(psk);
1506 size_t MBEDTLS_PRIVATE(psk_len);
1511
1512 unsigned char *MBEDTLS_PRIVATE(psk_identity);
1517 size_t MBEDTLS_PRIVATE(psk_identity_len);
1523#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
1524
1525#if defined(MBEDTLS_SSL_EARLY_DATA)
1526 int MBEDTLS_PRIVATE(early_data_enabled);
1529
1530#if defined(MBEDTLS_SSL_SRV_C)
1531 /* The maximum amount of 0-RTT data. RFC 8446 section 4.6.1 */
1532 uint32_t MBEDTLS_PRIVATE(max_early_data_size);
1533#endif /* MBEDTLS_SSL_SRV_C */
1534
1535#endif /* MBEDTLS_SSL_EARLY_DATA */
1536
1537#if defined(MBEDTLS_SSL_ALPN)
1538 const char *const *MBEDTLS_PRIVATE(alpn_list);
1539#endif
1540
1541#if defined(MBEDTLS_SSL_DTLS_SRTP)
1543 const mbedtls_ssl_srtp_profile *MBEDTLS_PRIVATE(dtls_srtp_profile_list);
1545 size_t MBEDTLS_PRIVATE(dtls_srtp_profile_list_len);
1546#endif /* MBEDTLS_SSL_DTLS_SRTP */
1547
1548 /*
1549 * Numerical settings (int)
1550 */
1551
1552 uint32_t MBEDTLS_PRIVATE(read_timeout);
1553
1554#if defined(MBEDTLS_SSL_PROTO_DTLS)
1555 uint32_t MBEDTLS_PRIVATE(hs_timeout_min);
1557 uint32_t MBEDTLS_PRIVATE(hs_timeout_max);
1559#endif
1560
1561#if defined(MBEDTLS_SSL_RENEGOTIATION)
1562 int MBEDTLS_PRIVATE(renego_max_records);
1563 unsigned char MBEDTLS_PRIVATE(renego_period)[8];
1565#endif
1566
1567 unsigned int MBEDTLS_PRIVATE(badmac_limit);
1568
1574 mbedtls_ssl_user_data_t MBEDTLS_PRIVATE(user_data);
1575
1576#if defined(MBEDTLS_SSL_SRV_C)
1577 mbedtls_ssl_hs_cb_t MBEDTLS_PRIVATE(f_cert_cb);
1578#endif /* MBEDTLS_SSL_SRV_C */
1579
1580#if defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED)
1581 const mbedtls_x509_crt *MBEDTLS_PRIVATE(dn_hints);
1582#endif
1583
1584 mbedtls_ssl_unused_data_t MBEDTLS_PRIVATE(unused);
1585};
1586
1587/*
1588 * Warning: whenever a change is applied to "mbedtls_ssl_context" please re-run
1589 * the script "tests/scripts/generate_ssl_session_reset_check.py".
1590 * Please note that this script has some limitation that should be considered
1591 * when modifing "mbedtls_ssl_context":
1592 * - Parsed structure must start with struct "mbedtls_ssl_context {"
1593 * (not "typedef struct {").
1594 * - It must end with "}}" in column 0.
1595 * - Must not contain "#else" or "#elif" conditionals.
1596 * - Must not contain nested struct/union/enum definitions.
1597 */
1599 const mbedtls_ssl_config *MBEDTLS_PRIVATE(conf);
1600
1601 /*
1602 * Miscellaneous
1603 */
1604 int MBEDTLS_PRIVATE(state);
1605
1611 uint32_t MBEDTLS_PRIVATE(flags);
1612
1613#if defined(MBEDTLS_SSL_RENEGOTIATION)
1614 int MBEDTLS_PRIVATE(renego_status);
1615 int MBEDTLS_PRIVATE(renego_records_seen);
1618#endif /* MBEDTLS_SSL_RENEGOTIATION */
1619
1636 mbedtls_ssl_protocol_version MBEDTLS_PRIVATE(tls_version);
1637
1638#if defined(MBEDTLS_SSL_EARLY_DATA) && defined(MBEDTLS_SSL_CLI_C)
1643 int MBEDTLS_PRIVATE(early_data_state);
1644#endif
1645
1646 unsigned MBEDTLS_PRIVATE(badmac_seen);
1647
1648#if defined(MBEDTLS_X509_CRT_PARSE_C)
1650 int(*MBEDTLS_PRIVATE(f_vrfy))(void *, mbedtls_x509_crt *, int, uint32_t *);
1651 void *MBEDTLS_PRIVATE(p_vrfy);
1652#endif
1653
1654 mbedtls_ssl_send_t *MBEDTLS_PRIVATE(f_send);
1655 mbedtls_ssl_recv_t *MBEDTLS_PRIVATE(f_recv);
1656 mbedtls_ssl_recv_timeout_t *MBEDTLS_PRIVATE(f_recv_timeout);
1658
1659 void *MBEDTLS_PRIVATE(p_bio);
1660
1661 /*
1662 * Session layer
1663 */
1664 mbedtls_ssl_session *MBEDTLS_PRIVATE(session_in);
1665 mbedtls_ssl_session *MBEDTLS_PRIVATE(session_out);
1666 mbedtls_ssl_session *MBEDTLS_PRIVATE(session);
1667 mbedtls_ssl_session *MBEDTLS_PRIVATE(session_negotiate);
1668
1669 mbedtls_ssl_handshake_params *MBEDTLS_PRIVATE(handshake);
1671
1672 /*
1673 * Record layer transformations
1674 */
1675 mbedtls_ssl_transform *MBEDTLS_PRIVATE(transform_in);
1678 mbedtls_ssl_transform *MBEDTLS_PRIVATE(transform_out);
1681 mbedtls_ssl_transform *MBEDTLS_PRIVATE(transform);
1684#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
1685 mbedtls_ssl_transform *MBEDTLS_PRIVATE(transform_negotiate);
1688#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
1689
1690#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
1693 mbedtls_ssl_transform *MBEDTLS_PRIVATE(transform_application);
1694#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
1695
1696 /*
1697 * Timers
1698 */
1699 void *MBEDTLS_PRIVATE(p_timer);
1700
1701 mbedtls_ssl_set_timer_t *MBEDTLS_PRIVATE(f_set_timer);
1702 mbedtls_ssl_get_timer_t *MBEDTLS_PRIVATE(f_get_timer);
1703
1704 /*
1705 * Record layer (incoming data)
1706 */
1707 unsigned char *MBEDTLS_PRIVATE(in_buf);
1708 unsigned char *MBEDTLS_PRIVATE(in_ctr);
1711 unsigned char *MBEDTLS_PRIVATE(in_hdr);
1712#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1713 unsigned char *MBEDTLS_PRIVATE(in_cid);
1715#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1716 unsigned char *MBEDTLS_PRIVATE(in_len);
1717 unsigned char *MBEDTLS_PRIVATE(in_iv);
1718 unsigned char *MBEDTLS_PRIVATE(in_msg);
1719 unsigned char *MBEDTLS_PRIVATE(in_offt);
1720
1721 int MBEDTLS_PRIVATE(in_msgtype);
1722 size_t MBEDTLS_PRIVATE(in_msglen);
1723 size_t MBEDTLS_PRIVATE(in_left);
1724#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
1725 size_t MBEDTLS_PRIVATE(in_buf_len);
1726#endif
1727#if defined(MBEDTLS_SSL_PROTO_DTLS)
1728 uint16_t MBEDTLS_PRIVATE(in_epoch);
1729 size_t MBEDTLS_PRIVATE(next_record_offset);
1731#endif /* MBEDTLS_SSL_PROTO_DTLS */
1732#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
1733 uint64_t MBEDTLS_PRIVATE(in_window_top);
1734 uint64_t MBEDTLS_PRIVATE(in_window);
1735#endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
1736
1737 size_t MBEDTLS_PRIVATE(in_hslen);
1739 size_t MBEDTLS_PRIVATE(in_hsfraglen);
1741 int MBEDTLS_PRIVATE(nb_zero);
1742
1743 int MBEDTLS_PRIVATE(keep_current_message);
1745
1746 unsigned char MBEDTLS_PRIVATE(in_fatal_alert_recv);
1750 unsigned char MBEDTLS_PRIVATE(in_fatal_alert_type);
1752
1753 /* The following three variables indicate if and, if yes,
1754 * what kind of alert is pending to be sent.
1755 */
1756 unsigned char MBEDTLS_PRIVATE(send_alert);
1760 unsigned char MBEDTLS_PRIVATE(alert_type);
1762 int MBEDTLS_PRIVATE(alert_reason);
1765
1766#if defined(MBEDTLS_SSL_PROTO_DTLS)
1767 uint8_t MBEDTLS_PRIVATE(disable_datagram_packing);
1769#endif /* MBEDTLS_SSL_PROTO_DTLS */
1770
1771#if defined(MBEDTLS_SSL_EARLY_DATA)
1772#if defined(MBEDTLS_SSL_SRV_C)
1773 /*
1774 * One of:
1775 * MBEDTLS_SSL_EARLY_DATA_NO_DISCARD
1776 * MBEDTLS_SSL_EARLY_DATA_TRY_TO_DEPROTECT_AND_DISCARD
1777 * MBEDTLS_SSL_EARLY_DATA_DISCARD
1778 */
1779 uint8_t MBEDTLS_PRIVATE(discard_early_data_record);
1780#endif
1781 uint32_t MBEDTLS_PRIVATE(total_early_data_size);
1782#endif /* MBEDTLS_SSL_EARLY_DATA */
1783
1784 /*
1785 * Record layer (outgoing data)
1786 */
1787 unsigned char *MBEDTLS_PRIVATE(out_buf);
1788 unsigned char *MBEDTLS_PRIVATE(out_ctr);
1789 unsigned char *MBEDTLS_PRIVATE(out_hdr);
1790#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1791 unsigned char *MBEDTLS_PRIVATE(out_cid);
1793#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1794 unsigned char *MBEDTLS_PRIVATE(out_len);
1795 unsigned char *MBEDTLS_PRIVATE(out_iv);
1796 unsigned char *MBEDTLS_PRIVATE(out_msg);
1797
1798 int MBEDTLS_PRIVATE(out_msgtype);
1799 size_t MBEDTLS_PRIVATE(out_msglen);
1800 size_t MBEDTLS_PRIVATE(out_left);
1801#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
1802 size_t MBEDTLS_PRIVATE(out_buf_len);
1803#endif
1804
1805 unsigned char MBEDTLS_PRIVATE(cur_out_ctr)[MBEDTLS_SSL_SEQUENCE_NUMBER_LEN];
1806
1807#if defined(MBEDTLS_SSL_PROTO_DTLS)
1808 uint16_t MBEDTLS_PRIVATE(mtu);
1809#endif /* MBEDTLS_SSL_PROTO_DTLS */
1810
1811 /*
1812 * User settings
1813 */
1814#if defined(MBEDTLS_X509_CRT_PARSE_C)
1815 char *MBEDTLS_PRIVATE(hostname);
1817#endif /* MBEDTLS_X509_CRT_PARSE_C */
1818
1819#if defined(MBEDTLS_SSL_ALPN)
1820 const char *MBEDTLS_PRIVATE(alpn_chosen);
1821#endif /* MBEDTLS_SSL_ALPN */
1822
1823#if defined(MBEDTLS_SSL_DTLS_SRTP)
1824 /*
1825 * use_srtp extension
1826 */
1827 mbedtls_dtls_srtp_info MBEDTLS_PRIVATE(dtls_srtp_info);
1828#endif /* MBEDTLS_SSL_DTLS_SRTP */
1829
1830 /*
1831 * Information for DTLS hello verify
1832 */
1833#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
1834 unsigned char *MBEDTLS_PRIVATE(cli_id);
1835 size_t MBEDTLS_PRIVATE(cli_id_len);
1836#endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
1837
1838 /*
1839 * Secure renegotiation
1840 */
1841 /* needed to know when to send extension on server */
1842 int MBEDTLS_PRIVATE(secure_renegotiation);
1844#if defined(MBEDTLS_SSL_RENEGOTIATION)
1845 size_t MBEDTLS_PRIVATE(verify_data_len);
1846 char MBEDTLS_PRIVATE(own_verify_data)[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN];
1847 char MBEDTLS_PRIVATE(peer_verify_data)[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN];
1848#endif /* MBEDTLS_SSL_RENEGOTIATION */
1849
1850#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1851 /* CID configuration to use in subsequent handshakes. */
1852
1857 unsigned char MBEDTLS_PRIVATE(own_cid)[MBEDTLS_SSL_CID_IN_LEN_MAX];
1858 uint8_t MBEDTLS_PRIVATE(own_cid_len);
1859 uint8_t MBEDTLS_PRIVATE(negotiate_cid);
1863#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1864
1866 mbedtls_ssl_export_keys_t *MBEDTLS_PRIVATE(f_export_keys);
1867 void *MBEDTLS_PRIVATE(p_export_keys);
1868
1878 mbedtls_ssl_user_data_t MBEDTLS_PRIVATE(user_data);
1879
1880 mbedtls_ssl_unused_data_t MBEDTLS_PRIVATE(unused);
1881};
1882
1891const char *mbedtls_ssl_get_ciphersuite_name(const int ciphersuite_id);
1892
1901int mbedtls_ssl_get_ciphersuite_id(const char *ciphersuite_name);
1902
1911
1947 const mbedtls_ssl_config *conf);
1948
1959
1967
1977{
1978 return conf->MBEDTLS_PRIVATE(endpoint);
1979}
1980
1996
2024
2025#if defined(MBEDTLS_SSL_EARLY_DATA)
2052void mbedtls_ssl_conf_early_data(mbedtls_ssl_config *conf,
2053 int early_data_enabled);
2054
2055#if defined(MBEDTLS_SSL_SRV_C)
2080void mbedtls_ssl_conf_max_early_data_size(
2081 mbedtls_ssl_config *conf, uint32_t max_early_data_size);
2082#endif /* MBEDTLS_SSL_SRV_C */
2083
2084#endif /* MBEDTLS_SSL_EARLY_DATA */
2085
2086#if defined(MBEDTLS_X509_CRT_PARSE_C)
2103 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
2104 void *p_vrfy);
2105#endif /* MBEDTLS_X509_CRT_PARSE_C */
2106
2122 void (*f_dbg)(void *, int, const char *, int, const char *),
2123 void *p_dbg);
2124
2136 const mbedtls_ssl_context *ssl)
2137{
2138 return ssl->MBEDTLS_PRIVATE(conf);
2139}
2140
2172 void *p_bio,
2173 mbedtls_ssl_send_t *f_send,
2174 mbedtls_ssl_recv_t *f_recv,
2175 mbedtls_ssl_recv_timeout_t *f_recv_timeout);
2176
2177#if defined(MBEDTLS_SSL_PROTO_DTLS)
2178
2179#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
2180
2181
2267 int enable,
2268 unsigned char const *own_cid,
2269 size_t own_cid_len);
2270
2301 int *enabled,
2302 unsigned char own_cid[MBEDTLS_SSL_CID_IN_LEN_MAX],
2303 size_t *own_cid_len);
2304
2343 int *enabled,
2344 unsigned char peer_cid[MBEDTLS_SSL_CID_OUT_LEN_MAX],
2345 size_t *peer_cid_len);
2346
2347#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
2348
2389#endif /* MBEDTLS_SSL_PROTO_DTLS */
2390
2391#if defined(MBEDTLS_X509_CRT_PARSE_C)
2411 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
2412 void *p_vrfy);
2413#endif /* MBEDTLS_X509_CRT_PARSE_C */
2414
2432
2478 unsigned char *buf,
2479 size_t buflen);
2480
2502 void *p_timer,
2503 mbedtls_ssl_set_timer_t *f_set_timer,
2504 mbedtls_ssl_get_timer_t *f_get_timer);
2505
2506#if defined(MBEDTLS_SSL_SRV_C)
2518 mbedtls_ssl_hs_cb_t f_cert_cb)
2519{
2520 conf->MBEDTLS_PRIVATE(f_cert_cb) = f_cert_cb;
2521}
2522#endif /* MBEDTLS_SSL_SRV_C */
2523
2543typedef int mbedtls_ssl_ticket_write_t(void *p_ticket,
2544 const mbedtls_ssl_session *session,
2545 unsigned char *start,
2546 const unsigned char *end,
2547 size_t *tlen,
2548 uint32_t *lifetime);
2549
2573typedef int mbedtls_ssl_ticket_parse_t(void *p_ticket,
2574 mbedtls_ssl_session *session,
2575 unsigned char *buf,
2576 size_t len);
2577
2578#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
2594 mbedtls_ssl_ticket_write_t *f_ticket_write,
2595 mbedtls_ssl_ticket_parse_t *f_ticket_parse,
2596 void *p_ticket);
2597
2598#if defined(MBEDTLS_HAVE_TIME)
2613 mbedtls_ssl_session *session, mbedtls_ms_time_t *ticket_creation_time)
2614{
2615 if (session == NULL || ticket_creation_time == NULL ||
2616 session->MBEDTLS_PRIVATE(endpoint) != MBEDTLS_SSL_IS_SERVER) {
2618 }
2619
2620 *ticket_creation_time = session->MBEDTLS_PRIVATE(ticket_creation_time);
2621
2622 return 0;
2623}
2624#endif /* MBEDTLS_HAVE_TIME */
2625#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
2626
2634static inline unsigned const char (*mbedtls_ssl_session_get_id(const mbedtls_ssl_session *
2635 session))[32]
2636{
2637 return &session->MBEDTLS_PRIVATE(id);
2638}
2639
2647static inline size_t mbedtls_ssl_session_get_id_len(const mbedtls_ssl_session *session)
2648{
2649 return session->MBEDTLS_PRIVATE(id_len);
2650}
2651
2660{
2661 return session->MBEDTLS_PRIVATE(ciphersuite);
2662}
2663
2683 mbedtls_ssl_export_keys_t *f_export_keys,
2684 void *p_export_keys);
2685
2697 mbedtls_ssl_config *conf,
2698 void *p)
2699{
2700 conf->MBEDTLS_PRIVATE(user_data).p = p;
2701}
2702
2711 mbedtls_ssl_config *conf,
2712 uintptr_t n)
2713{
2714 conf->MBEDTLS_PRIVATE(user_data).n = n;
2715}
2716
2728 mbedtls_ssl_config *conf)
2729{
2730 return conf->MBEDTLS_PRIVATE(user_data).p;
2731}
2732
2743static inline uintptr_t mbedtls_ssl_conf_get_user_data_n(
2744 mbedtls_ssl_config *conf)
2745{
2746 return conf->MBEDTLS_PRIVATE(user_data).n;
2747}
2748
2761 void *p)
2762{
2763 ssl->MBEDTLS_PRIVATE(user_data).p = p;
2764}
2765
2775 uintptr_t n)
2776{
2777 ssl->MBEDTLS_PRIVATE(user_data).n = n;
2778}
2779
2792{
2793 return ssl->MBEDTLS_PRIVATE(user_data).p;
2794}
2795
2806static inline uintptr_t mbedtls_ssl_get_user_data_n(
2808{
2809 return ssl->MBEDTLS_PRIVATE(user_data).n;
2810}
2811
2812#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
2836void mbedtls_ssl_conf_async_private_cb(mbedtls_ssl_config *conf,
2837 mbedtls_ssl_async_sign_t *f_async_sign,
2838 mbedtls_ssl_async_resume_t *f_async_resume,
2839 mbedtls_ssl_async_cancel_t *f_async_cancel,
2840 void *config_data);
2841
2850void *mbedtls_ssl_conf_get_async_config_data(const mbedtls_ssl_config *conf);
2851
2866void *mbedtls_ssl_get_async_operation_data(const mbedtls_ssl_context *ssl);
2867
2879void mbedtls_ssl_set_async_operation_data(mbedtls_ssl_context *ssl,
2880 void *ctx);
2881#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
2882
2897typedef int mbedtls_ssl_cookie_write_t(void *ctx,
2898 unsigned char **p, unsigned char *end,
2899 const unsigned char *info, size_t ilen);
2900
2914typedef int mbedtls_ssl_cookie_check_t(void *ctx,
2915 const unsigned char *cookie, size_t clen,
2916 const unsigned char *info, size_t ilen);
2917
2918#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
2948 mbedtls_ssl_cookie_write_t *f_cookie_write,
2949 mbedtls_ssl_cookie_check_t *f_cookie_check,
2950 void *p_cookie);
2951
2972 const unsigned char *info,
2973 size_t ilen);
2974
2975#endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
2976
2977#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
2994#endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
2995
3020
3021#if defined(MBEDTLS_SSL_PROTO_DTLS)
3022
3052 unsigned allow_packing);
3053
3085void mbedtls_ssl_conf_handshake_timeout(mbedtls_ssl_config *conf, uint32_t min, uint32_t max);
3086#endif /* MBEDTLS_SSL_PROTO_DTLS */
3087
3088#if defined(MBEDTLS_SSL_SRV_C)
3127 void *p_cache,
3128 mbedtls_ssl_cache_get_t *f_get_cache,
3129 mbedtls_ssl_cache_set_t *f_set_cache);
3130#endif /* MBEDTLS_SSL_SRV_C */
3131
3132#if defined(MBEDTLS_SSL_CLI_C)
3180#endif /* MBEDTLS_SSL_CLI_C */
3181
3236 const unsigned char *buf,
3237 size_t len);
3238
3286 unsigned char *buf,
3287 size_t buf_len,
3288 size_t *olen);
3289
3332 const int *ciphersuites);
3333
3334#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
3376
3378 const int kex_modes);
3379#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
3380
3381#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
3382#define MBEDTLS_SSL_UNEXPECTED_CID_IGNORE 0
3383#define MBEDTLS_SSL_UNEXPECTED_CID_FAIL 1
3417 int ignore_other_cids);
3418#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
3419
3420#if defined(MBEDTLS_X509_CRT_PARSE_C)
3432 const mbedtls_x509_crt_profile *profile);
3433
3446 mbedtls_x509_crt *ca_chain,
3447 mbedtls_x509_crl *ca_crl);
3448
3449#if defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED)
3461static inline
3463 const mbedtls_x509_crt *crt)
3464{
3465 conf->MBEDTLS_PRIVATE(dn_hints) = crt;
3466}
3467#endif /* MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */
3468
3469#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
3521void mbedtls_ssl_conf_ca_cb(mbedtls_ssl_config *conf,
3523 void *p_ca_cb);
3524#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
3525
3563 mbedtls_x509_crt *own_cert,
3564 mbedtls_pk_context *pk_key);
3565#endif /* MBEDTLS_X509_CRT_PARSE_C */
3566
3567#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
3601 const unsigned char *psk, size_t psk_len,
3602 const unsigned char *psk_identity, size_t psk_identity_len);
3603
3643 const unsigned char *psk_identity,
3644 size_t psk_identity_len);
3645
3663 const unsigned char *psk, size_t psk_len);
3664
3687
3688#if defined(MBEDTLS_SSL_SRV_C)
3728 int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *,
3729 size_t),
3730 void *p_psk);
3731#endif /* MBEDTLS_SSL_SRV_C */
3732#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
3733
3739typedef struct {
3741 uint16_t tls_id;
3742
3744 const char *group_name;
3745
3749
3750/* Helpers to check which PSA_WANT_xxx symbols are defined for groups. */
3751#if defined(PSA_WANT_ECC_MONTGOMERY_255)
3752#define MBEDTLS_SSL_HAVE_GROUP_X25519 1
3753#else
3754#define MBEDTLS_SSL_HAVE_GROUP_X25519 0
3755#endif
3756#if defined(PSA_WANT_ECC_SECP_R1_256)
3757#define MBEDTLS_SSL_HAVE_GROUP_SECP256R1 1
3758#else
3759#define MBEDTLS_SSL_HAVE_GROUP_SECP256R1 0
3760#endif
3761#if defined(PSA_WANT_ECC_SECP_K1_256)
3762#define MBEDTLS_SSL_HAVE_GROUP_SECP256K1 1
3763#else
3764#define MBEDTLS_SSL_HAVE_GROUP_SECP256K1 0
3765#endif
3766#if defined(PSA_WANT_ECC_SECP_R1_384)
3767#define MBEDTLS_SSL_HAVE_GROUP_SECP384R1 1
3768#else
3769#define MBEDTLS_SSL_HAVE_GROUP_SECP384R1 0
3770#endif
3771#if defined(PSA_WANT_ECC_MONTGOMERY_448)
3772#define MBEDTLS_SSL_HAVE_GROUP_X448 1
3773#else
3774#define MBEDTLS_SSL_HAVE_GROUP_X448 0
3775#endif
3776#if defined(PSA_WANT_ECC_SECP_R1_521)
3777#define MBEDTLS_SSL_HAVE_GROUP_SECP521R1 1
3778#else
3779#define MBEDTLS_SSL_HAVE_GROUP_SECP521R1 0
3780#endif
3781#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
3782#define MBEDTLS_SSL_HAVE_GROUP_BP256R1 1
3783#else
3784#define MBEDTLS_SSL_HAVE_GROUP_BP256R1 0
3785#endif
3786#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_384)
3787#define MBEDTLS_SSL_HAVE_GROUP_BP384R1 1
3788#else
3789#define MBEDTLS_SSL_HAVE_GROUP_BP384R1 0
3790#endif
3791#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_512)
3792#define MBEDTLS_SSL_HAVE_GROUP_BP512R1 1
3793#else
3794#define MBEDTLS_SSL_HAVE_GROUP_BP512R1 0
3795#endif
3796#if defined(PSA_WANT_DH_RFC7919_2048)
3797#define MBEDTLS_SSL_HAVE_GROUP_FFDHE2048 1
3798#else
3799#define MBEDTLS_SSL_HAVE_GROUP_FFDHE2048 0
3800#endif
3801#if defined(PSA_WANT_DH_RFC7919_3072)
3802#define MBEDTLS_SSL_HAVE_GROUP_FFDHE3072 1
3803#else
3804#define MBEDTLS_SSL_HAVE_GROUP_FFDHE3072 0
3805#endif
3806#if defined(PSA_WANT_DH_RFC7919_4096)
3807#define MBEDTLS_SSL_HAVE_GROUP_FFDHE4096 1
3808#else
3809#define MBEDTLS_SSL_HAVE_GROUP_FFDHE4096 0
3810#endif
3811#if defined(PSA_WANT_DH_RFC7919_6144)
3812#define MBEDTLS_SSL_HAVE_GROUP_FFDHE6144 1
3813#else
3814#define MBEDTLS_SSL_HAVE_GROUP_FFDHE6144 0
3815#endif
3816#if defined(PSA_WANT_DH_RFC7919_8192)
3817#define MBEDTLS_SSL_HAVE_GROUP_FFDHE8192 1
3818#else
3819#define MBEDTLS_SSL_HAVE_GROUP_FFDHE8192 0
3820#endif
3821
3829#define MBEDTLS_SSL_IANA_TLS_GROUPS_INFO \
3830 { \
3831 { MBEDTLS_SSL_IANA_TLS_GROUP_X25519, "x25519", MBEDTLS_SSL_HAVE_GROUP_X25519 }, \
3832 { MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1, "secp256r1", MBEDTLS_SSL_HAVE_GROUP_SECP256R1 }, \
3833 { MBEDTLS_SSL_IANA_TLS_GROUP_SECP256K1, "secp256k1", MBEDTLS_SSL_HAVE_GROUP_SECP256K1 }, \
3834 { MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1, "secp384r1", MBEDTLS_SSL_HAVE_GROUP_SECP384R1 }, \
3835 { MBEDTLS_SSL_IANA_TLS_GROUP_X448, "x448", MBEDTLS_SSL_HAVE_GROUP_X448 }, \
3836 { MBEDTLS_SSL_IANA_TLS_GROUP_SECP521R1, "secp521r1", MBEDTLS_SSL_HAVE_GROUP_SECP521R1 }, \
3837 { MBEDTLS_SSL_IANA_TLS_GROUP_BP256R1, "brainpoolP256r1", MBEDTLS_SSL_HAVE_GROUP_BP256R1 }, \
3838 { MBEDTLS_SSL_IANA_TLS_GROUP_BP384R1, "brainpoolP384r1", MBEDTLS_SSL_HAVE_GROUP_BP384R1 }, \
3839 { MBEDTLS_SSL_IANA_TLS_GROUP_BP512R1, "brainpoolP512r1", MBEDTLS_SSL_HAVE_GROUP_BP512R1 }, \
3840 { MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE2048, "ffdhe2048", MBEDTLS_SSL_HAVE_GROUP_FFDHE2048 }, \
3841 { MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE3072, "ffdhe3072", MBEDTLS_SSL_HAVE_GROUP_FFDHE3072 }, \
3842 { MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE4096, "ffdhe4096", MBEDTLS_SSL_HAVE_GROUP_FFDHE4096 }, \
3843 { MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE6144, "ffdhe6144", MBEDTLS_SSL_HAVE_GROUP_FFDHE6144 }, \
3844 { MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE8192, "ffdhe8192", MBEDTLS_SSL_HAVE_GROUP_FFDHE8192 }, \
3845 { MBEDTLS_SSL_IANA_TLS_GROUP_NONE, NULL, 1 } \
3846 }
3847
3848#if defined(MBEDTLS_DEBUG_C)
3854#endif /* MBEDTLS_DEBUG_C */
3855
3873
3909 const uint16_t *groups);
3910
3911#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
3912
3931 const uint16_t *sig_algs);
3932#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
3933
3934#if defined(MBEDTLS_X509_CRT_PARSE_C)
3966int mbedtls_ssl_set_hostname(mbedtls_ssl_context *ssl, const char *hostname);
3967
3978static inline const char *mbedtls_ssl_get_hostname(mbedtls_ssl_context *ssl)
3979{
3980 return ssl->MBEDTLS_PRIVATE(hostname);
3981}
3982#endif /* MBEDTLS_X509_CRT_PARSE_C */
3983
3984#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
4004 size_t *name_len);
4005
4022 mbedtls_x509_crt *own_cert,
4023 mbedtls_pk_context *pk_key);
4024
4037 mbedtls_x509_crt *ca_chain,
4038 mbedtls_x509_crl *ca_crl);
4039
4040#if defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED)
4052 const mbedtls_x509_crt *crt);
4053#endif /* MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED */
4054
4066 int authmode);
4067
4091 int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *,
4092 size_t),
4093 void *p_sni);
4094#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
4095
4096#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
4115int mbedtls_ssl_set_hs_ecjpake_password(mbedtls_ssl_context *ssl,
4116 const unsigned char *pw,
4117 size_t pw_len);
4118
4133int mbedtls_ssl_set_hs_ecjpake_password_opaque(mbedtls_ssl_context *ssl,
4135#endif /*MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
4136
4137#if defined(MBEDTLS_SSL_ALPN)
4151 const char *const *protos);
4152
4163#endif /* MBEDTLS_SSL_ALPN */
4164
4165#if defined(MBEDTLS_SSL_DTLS_SRTP)
4166#if defined(MBEDTLS_DEBUG_C)
4168{
4169 switch (profile) {
4171 return "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80";
4173 return "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32";
4175 return "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80";
4177 return "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32";
4178 default: break;
4179 }
4180 return "";
4181}
4182#endif /* MBEDTLS_DEBUG_C */
4197 int support_mki_value);
4198
4219 (mbedtls_ssl_config *conf,
4220 const mbedtls_ssl_srtp_profile *profiles);
4221
4239 unsigned char *mki_value,
4240 uint16_t mki_len);
4260 mbedtls_dtls_srtp_info *dtls_srtp_info);
4261#endif /* MBEDTLS_SSL_DTLS_SRTP */
4262
4276 mbedtls_ssl_protocol_version tls_version)
4277{
4278 conf->MBEDTLS_PRIVATE(max_tls_version) = tls_version;
4279}
4280
4294 mbedtls_ssl_protocol_version tls_version)
4295{
4296 conf->MBEDTLS_PRIVATE(min_tls_version) = tls_version;
4297}
4298
4299#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
4312#endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
4313
4314#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
4327#endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */
4328
4329#if defined(MBEDTLS_SSL_SRV_C)
4340 char cert_req_ca_list);
4341#endif /* MBEDTLS_SSL_SRV_C */
4342
4343#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
4382int mbedtls_ssl_conf_max_frag_len(mbedtls_ssl_config *conf, unsigned char mfl_code);
4383#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
4384
4385#if defined(MBEDTLS_SSL_SRV_C)
4396#endif /* MBEDTLS_SSL_SRV_C */
4397
4398#if defined(MBEDTLS_SSL_SESSION_TICKETS) && \
4399 defined(MBEDTLS_SSL_CLI_C)
4411#endif /* MBEDTLS_SSL_SESSION_TICKETS &&
4412 MBEDTLS_SSL_CLI_C */
4413
4414#if defined(MBEDTLS_SSL_SESSION_TICKETS) && \
4415 defined(MBEDTLS_SSL_SRV_C) && \
4416 defined(MBEDTLS_SSL_PROTO_TLS1_3)
4435 uint16_t num_tickets);
4436#endif /* MBEDTLS_SSL_SESSION_TICKETS &&
4437 MBEDTLS_SSL_SRV_C &&
4438 MBEDTLS_SSL_PROTO_TLS1_3*/
4439
4440#if defined(MBEDTLS_SSL_RENEGOTIATION)
4459#endif /* MBEDTLS_SSL_RENEGOTIATION */
4460
4489
4490#if defined(MBEDTLS_SSL_RENEGOTIATION)
4529
4556 const unsigned char period[8]);
4557#endif /* MBEDTLS_SSL_RENEGOTIATION */
4558
4598
4615
4629
4638
4647
4648
4661 const mbedtls_ssl_context *ssl)
4662{
4663 return ssl->MBEDTLS_PRIVATE(tls_version);
4664}
4665
4674
4684
4711
4731
4732#if defined(MBEDTLS_X509_CRT_PARSE_C)
4764#endif /* MBEDTLS_X509_CRT_PARSE_C */
4765
4766#if defined(MBEDTLS_SSL_CLI_C)
4795 mbedtls_ssl_session *session);
4796#endif /* MBEDTLS_SSL_CLI_C */
4797
4871
4884{
4885 return ssl->MBEDTLS_PRIVATE(state) >= MBEDTLS_SSL_HANDSHAKE_OVER;
4886}
4887
4923
4924#if defined(MBEDTLS_SSL_RENEGOTIATION)
4949#endif /* MBEDTLS_SSL_RENEGOTIATION */
4950
5036int mbedtls_ssl_read(mbedtls_ssl_context *ssl, unsigned char *buf, size_t len);
5037
5106int mbedtls_ssl_write(mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len);
5107
5125 unsigned char level,
5126 unsigned char message);
5127
5142
5157
5158#if defined(MBEDTLS_SSL_EARLY_DATA)
5159
5160#if defined(MBEDTLS_SSL_SRV_C)
5208int mbedtls_ssl_read_early_data(mbedtls_ssl_context *ssl,
5209 unsigned char *buf, size_t len);
5210#endif /* MBEDTLS_SSL_SRV_C */
5211
5212#if defined(MBEDTLS_SSL_CLI_C)
5297int mbedtls_ssl_write_early_data(mbedtls_ssl_context *ssl,
5298 const unsigned char *buf, size_t len);
5299
5326int mbedtls_ssl_get_early_data_status(mbedtls_ssl_context *ssl);
5327#endif /* MBEDTLS_SSL_CLI_C */
5328
5329#endif /* MBEDTLS_SSL_EARLY_DATA */
5330
5337
5338#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION)
5409 unsigned char *buf,
5410 size_t buf_len,
5411 size_t *olen);
5412
5503 const unsigned char *buf,
5504 size_t len);
5505#endif /* MBEDTLS_SSL_CONTEXT_SERIALIZATION */
5506
5518
5535 int endpoint, int transport, int preset);
5536
5543
5550
5561
5578 const unsigned char *secret, size_t slen,
5579 const char *label,
5580 const unsigned char *random, size_t rlen,
5581 unsigned char *dstbuf, size_t dlen);
5582
5583#if defined(MBEDTLS_SSL_KEYING_MATERIAL_EXPORT)
5584/* Maximum value for key_len in mbedtls_ssl_export_keying material. Depending on the TLS
5585 * version and the negotiated ciphersuite, larger keys could in principle be exported,
5586 * but for simplicity, we define one limit that works in all cases. TLS 1.3 with SHA256
5587 * has the strictest limit: 255 blocks of SHA256 output, or 8160 bytes. */
5588#define MBEDTLS_SSL_EXPORT_MAX_KEY_LEN 8160
5589
5613 uint8_t *out, const size_t key_len,
5614 const char *label, const size_t label_len,
5615 const unsigned char *context, const size_t context_len,
5616 const int use_context);
5617#endif
5618#ifdef __cplusplus
5619}
5620#endif
5621
5622#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:783
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:3978
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:903
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:2543
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:1289
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:2727
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:2806
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:2710
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:858
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:1253
@ MBEDTLS_SSL_TLS_PRF_SHA384
Definition ssl.h:1255
@ MBEDTLS_SSL_HKDF_EXPAND_SHA256
Definition ssl.h:1258
@ MBEDTLS_SSL_TLS_PRF_SHA256
Definition ssl.h:1256
@ MBEDTLS_SSL_TLS_PRF_NONE
Definition ssl.h:1254
@ MBEDTLS_SSL_HKDF_EXPAND_SHA384
Definition ssl.h:1257
int mbedtls_ssl_send_t(void *ctx, const unsigned char *buf, size_t len)
Callback type: send data on the network.
Definition ssl.h:759
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:693
@ MBEDTLS_SSL_CERTIFICATE_VERIFY
Definition ssl.h:703
@ MBEDTLS_SSL_HANDSHAKE_OVER
Definition ssl.h:721
@ MBEDTLS_SSL_SERVER_HELLO_DONE
Definition ssl.h:700
@ MBEDTLS_SSL_END_OF_EARLY_DATA
Definition ssl.h:714
@ MBEDTLS_SSL_NEW_SESSION_TICKET
Definition ssl.h:710
@ MBEDTLS_SSL_SERVER_FINISHED
Definition ssl.h:707
@ MBEDTLS_SSL_SERVER_KEY_EXCHANGE
Definition ssl.h:698
@ MBEDTLS_SSL_ENCRYPTED_EXTENSIONS
Definition ssl.h:713
@ MBEDTLS_SSL_SERVER_HELLO
Definition ssl.h:696
@ MBEDTLS_SSL_SERVER_CCS_AFTER_HELLO_RETRY_REQUEST
Definition ssl.h:720
@ MBEDTLS_SSL_CLIENT_KEY_EXCHANGE
Definition ssl.h:702
@ MBEDTLS_SSL_CLIENT_CCS_BEFORE_2ND_CLIENT_HELLO
Definition ssl.h:717
@ MBEDTLS_SSL_CLIENT_HELLO
Definition ssl.h:695
@ MBEDTLS_SSL_SERVER_CERTIFICATE
Definition ssl.h:697
@ MBEDTLS_SSL_CERTIFICATE_REQUEST
Definition ssl.h:699
@ MBEDTLS_SSL_CLIENT_FINISHED
Definition ssl.h:705
@ MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC
Definition ssl.h:706
@ MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT
Definition ssl.h:711
@ MBEDTLS_SSL_HANDSHAKE_WRAPUP
Definition ssl.h:709
@ MBEDTLS_SSL_CLIENT_CCS_AFTER_SERVER_FINISHED
Definition ssl.h:716
@ MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC
Definition ssl.h:704
@ MBEDTLS_SSL_CLIENT_CERTIFICATE_VERIFY
Definition ssl.h:715
@ MBEDTLS_SSL_HELLO_REQUEST
Definition ssl.h:694
@ MBEDTLS_SSL_CLIENT_CERTIFICATE
Definition ssl.h:701
@ MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET_FLUSH
Definition ssl.h:723
@ MBEDTLS_SSL_FLUSH_BUFFERS
Definition ssl.h:708
@ MBEDTLS_SSL_CLIENT_CCS_AFTER_CLIENT_HELLO
Definition ssl.h:719
@ MBEDTLS_SSL_TLS1_3_NEW_SESSION_TICKET
Definition ssl.h:722
@ MBEDTLS_SSL_HELLO_RETRY_REQUEST
Definition ssl.h:712
@ MBEDTLS_SSL_SERVER_CCS_AFTER_SERVER_HELLO
Definition ssl.h:718
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.
#define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80
Definition ssl.h:1107
#define MBEDTLS_TLS_SRTP_MAX_MKI_LENGTH
Definition ssl.h:1094
int(* mbedtls_ssl_hs_cb_t)(mbedtls_ssl_context *ssl)
Callback type: generic handshake callback.
Definition ssl.h:1313
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:1127
@ MBEDTLS_SSL_VERSION_TLS1_2
Definition ssl.h:1129
@ MBEDTLS_SSL_VERSION_TLS1_3
Definition ssl.h:1130
@ MBEDTLS_SSL_VERSION_UNKNOWN
Definition ssl.h:1128
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:4883
#define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32
Definition ssl.h:1108
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:2573
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:2517
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:676
mbedtls_ssl_key_export_type
Definition ssl.h:1262
@ MBEDTLS_SSL_KEY_EXPORT_TLS1_3_CLIENT_APPLICATION_TRAFFIC_SECRET
Definition ssl.h:1269
@ MBEDTLS_SSL_KEY_EXPORT_TLS12_MASTER_SECRET
Definition ssl.h:1263
@ MBEDTLS_SSL_KEY_EXPORT_TLS1_3_SERVER_APPLICATION_TRAFFIC_SECRET
Definition ssl.h:1270
@ MBEDTLS_SSL_KEY_EXPORT_TLS1_3_SERVER_HANDSHAKE_TRAFFIC_SECRET
Definition ssl.h:1268
@ MBEDTLS_SSL_KEY_EXPORT_TLS1_3_CLIENT_HANDSHAKE_TRAFFIC_SECRET
Definition ssl.h:1267
@ MBEDTLS_SSL_KEY_EXPORT_TLS1_3_EARLY_EXPORTER_SECRET
Definition ssl.h:1266
@ MBEDTLS_SSL_KEY_EXPORT_TLS1_3_CLIENT_EARLY_SECRET
Definition ssl.h:1265
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:2897
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:4660
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:859
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...
int mbedtls_ssl_conf_dtls_srtp_protection_profiles(mbedtls_ssl_config *conf, const mbedtls_ssl_srtp_profile *profiles)
Set the supported DTLS-SRTP protection profiles.
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:835
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:2135
void mbedtls_ssl_conf_srtp_mki_value_supported(mbedtls_ssl_config *conf, int support_mki_value)
Manage support for mki(master key id) value in use_srtp extension. MKI is an optional part of SRTP us...
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:809
#define MBEDTLS_SSL_IS_SERVER
Definition ssl.h:295
void mbedtls_ssl_get_dtls_srtp_negotiation_result(const mbedtls_ssl_context *ssl, mbedtls_dtls_srtp_info *dtls_srtp_info)
Get the negotiated DTLS-SRTP information: Protection profile and MKI value.
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:3462
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:2743
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.
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:2914
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:2659
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....
static const char * mbedtls_ssl_get_srtp_profile_as_string(mbedtls_ssl_srtp_profile profile)
Definition ssl.h:4167
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:2612
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:925
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...
struct mbedtls_dtls_srtp_info_t mbedtls_dtls_srtp_info
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.
#define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32
Definition ssl.h:1106
#define MBEDTLS_TLS1_3_MD_MAX_SIZE
Definition ssl.h:672
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:4275
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:864
int mbedtls_ssl_recv_t(void *ctx, unsigned char *buf, size_t len)
Callback type: receive data from the network.
Definition ssl.h:783
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:2634
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_dtls_srtp_set_mki_value(mbedtls_ssl_context *ssl, unsigned char *mki_value, uint16_t mki_len)
Set the mki_value for the current DTLS-SRTP session.
int mbedtls_ssl_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_TLS_SRTP_AES128_CM_HMAC_SHA1_80
Definition ssl.h:1105
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.
uint16_t mbedtls_ssl_srtp_profile
Definition ssl.h:1112
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:2696
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:2790
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:850
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:2773
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:4293
struct mbedtls_ssl_key_cert mbedtls_ssl_key_cert
Definition ssl.h:861
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:2647
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:2759
static int mbedtls_ssl_conf_get_endpoint(const mbedtls_ssl_config *conf)
Get the current endpoint type.
Definition ssl.h:1976
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:1088
unsigned char resumption_master_secret[MBEDTLS_TLS1_3_MD_MAX_SIZE]
Definition ssl.h:1089
unsigned char server_application_traffic_secret_N[MBEDTLS_TLS1_3_MD_MAX_SIZE]
Definition ssl.h:1087
unsigned char client_application_traffic_secret_N[MBEDTLS_TLS1_3_MD_MAX_SIZE]
Definition ssl.h:1086
unsigned char _pms_ecdhe_psk[4+MBEDTLS_ECP_MAX_BYTES+MBEDTLS_PSK_MAX_LEN]
Definition ssl.h:663
unsigned char _pms_psk[4+2 *MBEDTLS_PSK_MAX_LEN]
Definition ssl.h:659
unsigned char dummy
Definition ssl.h:653
unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]
Definition ssl.h:656
X.509 certificate revocation list parsing.
X.509 certificate parsing and writing.