Mbed OS Reference
Loading...
Searching...
No Matches
ssl.h
Go to the documentation of this file.
1/**
2 * \file ssl.h
3 *
4 * \brief SSL/TLS functions.
5 */
6/*
7 * Copyright The Mbed TLS Contributors
8 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22#ifndef MBEDTLS_SSL_H
23#define MBEDTLS_SSL_H
24
25#if !defined(MBEDTLS_CONFIG_FILE)
26#include "mbedtls/config.h"
27#else
28#include MBEDTLS_CONFIG_FILE
29#endif
30
31/**
32 * \addtogroup mbedtls
33 * \{
34 * \defgroup mbedtls_ssl_module SSL/TLS
35 * \{
36 */
37
38#include "mbedtls/bignum.h"
39#include "mbedtls/ecp.h"
40
42
43#if defined(MBEDTLS_X509_CRT_PARSE_C)
44#include "mbedtls/x509_crt.h"
45#include "mbedtls/x509_crl.h"
46#endif
47
48#if defined(MBEDTLS_DHM_C)
49#include "mbedtls/dhm.h"
50#endif
51
52/* Adding guard for MBEDTLS_ECDSA_C to ensure no compile errors due
53 * to guards also being in ssl_srv.c and ssl_cli.c. There is a gap
54 * in functionality that access to ecdh_ctx structure is needed for
55 * MBEDTLS_ECDSA_C which does not seem correct.
56 */
57#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C)
58#include "mbedtls/ecdh.h"
59#endif
60
61#if defined(MBEDTLS_ZLIB_SUPPORT)
62
63#if defined(MBEDTLS_DEPRECATED_WARNING)
64#warning "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and will be removed in the next major revision of the library"
65#endif
66
67#if defined(MBEDTLS_DEPRECATED_REMOVED)
68#error "Record compression support via MBEDTLS_ZLIB_SUPPORT is deprecated and cannot be used if MBEDTLS_DEPRECATED_REMOVED is set"
69#endif
70
71#include "zlib.h"
72#endif
73
74#if defined(MBEDTLS_HAVE_TIME)
76#endif
77
78#if defined(MBEDTLS_USE_PSA_CRYPTO)
79#include "psa/crypto.h"
80#endif /* MBEDTLS_USE_PSA_CRYPTO */
81
82/*
83 * SSL Error codes
84 */
85#define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080 /**< The requested feature is not available. */
86#define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100 /**< Bad input parameters to function. */
87#define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180 /**< Verification of the message MAC failed. */
88#define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200 /**< An invalid SSL record was received. */
89#define MBEDTLS_ERR_SSL_CONN_EOF -0x7280 /**< The connection indicated an EOF. */
90#define MBEDTLS_ERR_SSL_UNKNOWN_CIPHER -0x7300 /**< An unknown cipher was received. */
91#define MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN -0x7380 /**< The server has no ciphersuites in common with the client. */
92#define MBEDTLS_ERR_SSL_NO_RNG -0x7400 /**< No RNG was provided to the SSL module. */
93#define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480 /**< No client certification received from the client, but required by the authentication mode. */
94#define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500 /**< Our own certificate(s) is/are too large to send in an SSL message. */
95#define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580 /**< The own certificate is not set, but needed by the server. */
96#define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600 /**< The own private key or pre-shared key is not set, but needed. */
97#define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680 /**< No CA Chain is set, but required to operate. */
98#define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700 /**< An unexpected message was received from our peer. */
99#define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780 /**< A fatal alert message was received from our peer. */
100#define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800 /**< Verification of our peer failed. */
101#define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880 /**< The peer notified us that the connection is going to be closed. */
102#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900 /**< Processing of the ClientHello handshake message failed. */
103#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980 /**< Processing of the ServerHello handshake message failed. */
104#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00 /**< Processing of the Certificate handshake message failed. */
105#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80 /**< Processing of the CertificateRequest handshake message failed. */
106#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00 /**< Processing of the ServerKeyExchange handshake message failed. */
107#define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80 /**< Processing of the ServerHelloDone handshake message failed. */
108#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00 /**< Processing of the ClientKeyExchange handshake message failed. */
109#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80 /**< Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Read Public. */
110#define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00 /**< Processing of the ClientKeyExchange handshake message failed in DHM / ECDH Calculate Secret. */
111#define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80 /**< Processing of the CertificateVerify handshake message failed. */
112#define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00 /**< Processing of the ChangeCipherSpec handshake message failed. */
113#define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80 /**< Processing of the Finished handshake message failed. */
114#define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00 /**< Memory allocation failed */
115#define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80 /**< Hardware acceleration function returned with error */
116#define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80 /**< Hardware acceleration function skipped / left alone data */
117#define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00 /**< Processing of the compression / decompression failed */
118#define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80 /**< Handshake protocol not within min/max boundaries */
119#define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00 /**< Processing of the NewSessionTicket handshake message failed. */
120#define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80 /**< Session ticket has expired. */
121#define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00 /**< Public key type mismatch (eg, asked for RSA key exchange and presented EC key) */
122#define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80 /**< Unknown identity received (eg, PSK identity) */
123#define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00 /**< Internal error (eg, unexpected failure in lower-level module) */
124#define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80 /**< A counter would wrap (eg, too many messages exchanged). */
125#define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00 /**< Unexpected message at ServerHello in renegotiation. */
126#define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80 /**< DTLS client must retry for hello verification */
127#define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00 /**< A buffer is too small to receive or write a message */
128#define MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6980 /**< None of the common ciphersuites is usable (eg, no suitable certificate, see debug messages). */
129#define MBEDTLS_ERR_SSL_WANT_READ -0x6900 /**< No data of requested type currently available on underlying transport. */
130#define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880 /**< Connection requires a write call. */
131#define MBEDTLS_ERR_SSL_TIMEOUT -0x6800 /**< The operation timed out. */
132#define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780 /**< The client initiated a reconnect from the same port. */
133#define MBEDTLS_ERR_SSL_UNEXPECTED_RECORD -0x6700 /**< Record header looks valid but is not expected. */
134#define MBEDTLS_ERR_SSL_NON_FATAL -0x6680 /**< The alert message received indicates a non-fatal error. */
135#define MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH -0x6600 /**< Couldn't set the hash for verifying CertificateVerify */
136#define MBEDTLS_ERR_SSL_CONTINUE_PROCESSING -0x6580 /**< Internal-only message signaling that further message-processing should be done */
137#define MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS -0x6500 /**< The asynchronous operation is not completed yet. */
138#define MBEDTLS_ERR_SSL_EARLY_MESSAGE -0x6480 /**< Internal-only message signaling that a message arrived early. */
139#define MBEDTLS_ERR_SSL_UNEXPECTED_CID -0x6000 /**< An encrypted DTLS-frame with an unexpected CID was received. */
140#define MBEDTLS_ERR_SSL_VERSION_MISMATCH -0x5F00 /**< An operation failed due to an unexpected version or configuration. */
141#define MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS -0x7000 /**< A cryptographic operation is in progress. Try again later. */
142#define MBEDTLS_ERR_SSL_BAD_CONFIG -0x5E80 /**< Invalid value in SSL config */
143
144/*
145 * Various constants
146 */
147#define MBEDTLS_SSL_MAJOR_VERSION_3 3
148#define MBEDTLS_SSL_MINOR_VERSION_0 0 /*!< SSL v3.0 */
149#define MBEDTLS_SSL_MINOR_VERSION_1 1 /*!< TLS v1.0 */
150#define MBEDTLS_SSL_MINOR_VERSION_2 2 /*!< TLS v1.1 */
151#define MBEDTLS_SSL_MINOR_VERSION_3 3 /*!< TLS v1.2 */
152#define MBEDTLS_SSL_MINOR_VERSION_4 4 /*!< TLS v1.3 (experimental) */
153
154#define MBEDTLS_SSL_TRANSPORT_STREAM 0 /*!< TLS */
155#define MBEDTLS_SSL_TRANSPORT_DATAGRAM 1 /*!< DTLS */
156
157#define MBEDTLS_SSL_MAX_HOST_NAME_LEN 255 /*!< Maximum host name defined in RFC 1035 */
158#define MBEDTLS_SSL_MAX_ALPN_NAME_LEN 255 /*!< Maximum size in bytes of a protocol name in alpn ext., RFC 7301 */
159
160#define MBEDTLS_SSL_MAX_ALPN_LIST_LEN 65535 /*!< Maximum size in bytes of list in alpn ext., RFC 7301 */
161
162/* RFC 6066 section 4, see also mfl_code_to_length in ssl_tls.c
163 * NONE must be zero so that memset()ing structure to zero works */
164#define MBEDTLS_SSL_MAX_FRAG_LEN_NONE 0 /*!< don't use this extension */
165#define MBEDTLS_SSL_MAX_FRAG_LEN_512 1 /*!< MaxFragmentLength 2^9 */
166#define MBEDTLS_SSL_MAX_FRAG_LEN_1024 2 /*!< MaxFragmentLength 2^10 */
167#define MBEDTLS_SSL_MAX_FRAG_LEN_2048 3 /*!< MaxFragmentLength 2^11 */
168#define MBEDTLS_SSL_MAX_FRAG_LEN_4096 4 /*!< MaxFragmentLength 2^12 */
169#define MBEDTLS_SSL_MAX_FRAG_LEN_INVALID 5 /*!< first invalid value */
170
171#define MBEDTLS_SSL_IS_CLIENT 0
172#define MBEDTLS_SSL_IS_SERVER 1
173
174#define MBEDTLS_SSL_IS_NOT_FALLBACK 0
175#define MBEDTLS_SSL_IS_FALLBACK 1
176
177#define MBEDTLS_SSL_EXTENDED_MS_DISABLED 0
178#define MBEDTLS_SSL_EXTENDED_MS_ENABLED 1
179
180#define MBEDTLS_SSL_CID_DISABLED 0
181#define MBEDTLS_SSL_CID_ENABLED 1
182
183#define MBEDTLS_SSL_ETM_DISABLED 0
184#define MBEDTLS_SSL_ETM_ENABLED 1
185
186#define MBEDTLS_SSL_COMPRESS_NULL 0
187#define MBEDTLS_SSL_COMPRESS_DEFLATE 1
188
189#define MBEDTLS_SSL_VERIFY_NONE 0
190#define MBEDTLS_SSL_VERIFY_OPTIONAL 1
191#define MBEDTLS_SSL_VERIFY_REQUIRED 2
192#define MBEDTLS_SSL_VERIFY_UNSET 3 /* Used only for sni_authmode */
193
194#define MBEDTLS_SSL_LEGACY_RENEGOTIATION 0
195#define MBEDTLS_SSL_SECURE_RENEGOTIATION 1
196
197#define MBEDTLS_SSL_RENEGOTIATION_DISABLED 0
198#define MBEDTLS_SSL_RENEGOTIATION_ENABLED 1
199
200#define MBEDTLS_SSL_ANTI_REPLAY_DISABLED 0
201#define MBEDTLS_SSL_ANTI_REPLAY_ENABLED 1
202
203#define MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED -1
204#define MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT 16
205
206#define MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION 0
207#define MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION 1
208#define MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE 2
209
210#define MBEDTLS_SSL_TRUNC_HMAC_DISABLED 0
211#define MBEDTLS_SSL_TRUNC_HMAC_ENABLED 1
212#define MBEDTLS_SSL_TRUNCATED_HMAC_LEN 10 /* 80 bits, rfc 6066 section 7 */
213
214#define MBEDTLS_SSL_SESSION_TICKETS_DISABLED 0
215#define MBEDTLS_SSL_SESSION_TICKETS_ENABLED 1
216
217#define MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED 0
218#define MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED 1
219
220#define MBEDTLS_SSL_ARC4_ENABLED 0
221#define MBEDTLS_SSL_ARC4_DISABLED 1
222
223#define MBEDTLS_SSL_PRESET_DEFAULT 0
224#define MBEDTLS_SSL_PRESET_SUITEB 2
225
226#define MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED 1
227#define MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED 0
228
229#define MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED 0
230#define MBEDTLS_SSL_DTLS_SRTP_MKI_SUPPORTED 1
231
232/*
233 * Default range for DTLS retransmission timer value, in milliseconds.
234 * RFC 6347 4.2.4.1 says from 1 second to 60 seconds.
235 */
236#define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN 1000
237#define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX 60000
238
239/**
240 * \name SECTION: Module settings
241 *
242 * The configuration options you can set for this module are in this section.
243 * Either change them in config.h or define them on the compiler command line.
244 * \{
245 */
246
247#if !defined(MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME)
248#define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400 /**< Lifetime of session tickets (if enabled) */
249#endif
250
251/*
252 * Maximum fragment length in bytes,
253 * determines the size of each of the two internal I/O buffers.
254 *
255 * Note: the RFC defines the default size of SSL / TLS messages. If you
256 * change the value here, other clients / servers may not be able to
257 * communicate with you anymore. Only change this value if you control
258 * both sides of the connection and have it reduced at both sides, or
259 * if you're using the Max Fragment Length extension and you know all your
260 * peers are using it too!
261 */
262#if !defined(MBEDTLS_SSL_MAX_CONTENT_LEN)
263#define MBEDTLS_SSL_MAX_CONTENT_LEN 16384 /**< Size of the input / output buffer */
264#endif
265
266#if !defined(MBEDTLS_SSL_IN_CONTENT_LEN)
267#define MBEDTLS_SSL_IN_CONTENT_LEN MBEDTLS_SSL_MAX_CONTENT_LEN
268#endif
269
270#if !defined(MBEDTLS_SSL_OUT_CONTENT_LEN)
271#define MBEDTLS_SSL_OUT_CONTENT_LEN MBEDTLS_SSL_MAX_CONTENT_LEN
272#endif
273
274/*
275 * Maximum number of heap-allocated bytes for the purpose of
276 * DTLS handshake message reassembly and future message buffering.
277 */
278#if !defined(MBEDTLS_SSL_DTLS_MAX_BUFFERING)
279#define MBEDTLS_SSL_DTLS_MAX_BUFFERING 32768
280#endif
281
282/*
283 * Maximum length of CIDs for incoming and outgoing messages.
284 */
285#if !defined(MBEDTLS_SSL_CID_IN_LEN_MAX)
286#define MBEDTLS_SSL_CID_IN_LEN_MAX 32
287#endif
288
289#if !defined(MBEDTLS_SSL_CID_OUT_LEN_MAX)
290#define MBEDTLS_SSL_CID_OUT_LEN_MAX 32
291#endif
292
293#if !defined(MBEDTLS_SSL_CID_PADDING_GRANULARITY)
294#define MBEDTLS_SSL_CID_PADDING_GRANULARITY 16
295#endif
296
297#if !defined(MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY)
298#define MBEDTLS_SSL_TLS1_3_PADDING_GRANULARITY 1
299#endif
300
301/** \} name SECTION: Module settings */
302
303/*
304 * Length of the verify data for secure renegotiation
305 */
306#if defined(MBEDTLS_SSL_PROTO_SSL3)
307#define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 36
308#else
309#define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 12
310#endif
311
312/*
313 * Signaling ciphersuite values (SCSV)
314 */
315#define MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO 0xFF /**< renegotiation info ext */
316#define MBEDTLS_SSL_FALLBACK_SCSV_VALUE 0x5600 /**< RFC 7507 section 2 */
317
318/*
319 * Supported Signature and Hash algorithms (For TLS 1.2)
320 * RFC 5246 section 7.4.1.4.1
321 */
322#define MBEDTLS_SSL_HASH_NONE 0
323#define MBEDTLS_SSL_HASH_MD5 1
324#define MBEDTLS_SSL_HASH_SHA1 2
325#define MBEDTLS_SSL_HASH_SHA224 3
326#define MBEDTLS_SSL_HASH_SHA256 4
327#define MBEDTLS_SSL_HASH_SHA384 5
328#define MBEDTLS_SSL_HASH_SHA512 6
329
330#define MBEDTLS_SSL_SIG_ANON 0
331#define MBEDTLS_SSL_SIG_RSA 1
332#define MBEDTLS_SSL_SIG_ECDSA 3
333
334/*
335 * Client Certificate Types
336 * RFC 5246 section 7.4.4 plus RFC 4492 section 5.5
337 */
338#define MBEDTLS_SSL_CERT_TYPE_RSA_SIGN 1
339#define MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN 64
340
341/*
342 * Message, alert and handshake types
343 */
344#define MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC 20
345#define MBEDTLS_SSL_MSG_ALERT 21
346#define MBEDTLS_SSL_MSG_HANDSHAKE 22
347#define MBEDTLS_SSL_MSG_APPLICATION_DATA 23
348#define MBEDTLS_SSL_MSG_CID 25
349
350#define MBEDTLS_SSL_ALERT_LEVEL_WARNING 1
351#define MBEDTLS_SSL_ALERT_LEVEL_FATAL 2
352
353#define MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY 0 /* 0x00 */
354#define MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10 /* 0x0A */
355#define MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC 20 /* 0x14 */
356#define MBEDTLS_SSL_ALERT_MSG_DECRYPTION_FAILED 21 /* 0x15 */
357#define MBEDTLS_SSL_ALERT_MSG_RECORD_OVERFLOW 22 /* 0x16 */
358#define MBEDTLS_SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30 /* 0x1E */
359#define MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE 40 /* 0x28 */
360#define MBEDTLS_SSL_ALERT_MSG_NO_CERT 41 /* 0x29 */
361#define MBEDTLS_SSL_ALERT_MSG_BAD_CERT 42 /* 0x2A */
362#define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT 43 /* 0x2B */
363#define MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED 44 /* 0x2C */
364#define MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED 45 /* 0x2D */
365#define MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN 46 /* 0x2E */
366#define MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER 47 /* 0x2F */
367#define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_CA 48 /* 0x30 */
368#define MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED 49 /* 0x31 */
369#define MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR 50 /* 0x32 */
370#define MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR 51 /* 0x33 */
371#define MBEDTLS_SSL_ALERT_MSG_EXPORT_RESTRICTION 60 /* 0x3C */
372#define MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION 70 /* 0x46 */
373#define MBEDTLS_SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71 /* 0x47 */
374#define MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR 80 /* 0x50 */
375#define MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK 86 /* 0x56 */
376#define MBEDTLS_SSL_ALERT_MSG_USER_CANCELED 90 /* 0x5A */
377#define MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION 100 /* 0x64 */
378#define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT 110 /* 0x6E */
379#define MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME 112 /* 0x70 */
380#define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY 115 /* 0x73 */
381#define MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL 120 /* 0x78 */
382
383#define MBEDTLS_SSL_HS_HELLO_REQUEST 0
384#define MBEDTLS_SSL_HS_CLIENT_HELLO 1
385#define MBEDTLS_SSL_HS_SERVER_HELLO 2
386#define MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST 3
387#define MBEDTLS_SSL_HS_NEW_SESSION_TICKET 4
388#define MBEDTLS_SSL_HS_CERTIFICATE 11
389#define MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE 12
390#define MBEDTLS_SSL_HS_CERTIFICATE_REQUEST 13
391#define MBEDTLS_SSL_HS_SERVER_HELLO_DONE 14
392#define MBEDTLS_SSL_HS_CERTIFICATE_VERIFY 15
393#define MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE 16
394#define MBEDTLS_SSL_HS_FINISHED 20
395
396/*
397 * TLS extensions
398 */
399#define MBEDTLS_TLS_EXT_SERVERNAME 0
400#define MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME 0
401
402#define MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH 1
403
404#define MBEDTLS_TLS_EXT_TRUNCATED_HMAC 4
405
406#define MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES 10
407#define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS 11
408
409#define MBEDTLS_TLS_EXT_SIG_ALG 13
410
411#define MBEDTLS_TLS_EXT_USE_SRTP 14
412
413#define MBEDTLS_TLS_EXT_ALPN 16
414
415#define MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC 22 /* 0x16 */
416#define MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET 0x0017 /* 23 */
417
418#define MBEDTLS_TLS_EXT_SESSION_TICKET 35
419
420/* The value of the CID extension is still TBD as of
421 * draft-ietf-tls-dtls-connection-id-05
422 * (https://tools.ietf.org/html/draft-ietf-tls-dtls-connection-id-05) */
423#define MBEDTLS_TLS_EXT_CID 254 /* TBD */
424
425#define MBEDTLS_TLS_EXT_ECJPAKE_KKPP 256 /* experimental */
426
427#define MBEDTLS_TLS_EXT_RENEGOTIATION_INFO 0xFF01
428
429/*
430 * Size defines
431 */
432#if !defined(MBEDTLS_PSK_MAX_LEN)
433#define MBEDTLS_PSK_MAX_LEN 32 /* 256 bits */
434#endif
435
436/* Dummy type used only for its size */
438{
439#if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
440 unsigned char _pms_rsa[48]; /* RFC 5246 8.1.1 */
441#endif
442#if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED)
443 unsigned char _pms_dhm[MBEDTLS_MPI_MAX_SIZE]; /* RFC 5246 8.1.2 */
444#endif
445#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
446 defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
447 defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
448 defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
449 unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]; /* RFC 4492 5.10 */
450#endif
451#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
452 unsigned char _pms_psk[4 + 2 * MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 2 */
453#endif
454#if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
455 unsigned char _pms_dhe_psk[4 + MBEDTLS_MPI_MAX_SIZE
456 + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 3 */
457#endif
458#if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)
459 unsigned char _pms_rsa_psk[52 + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 4 */
460#endif
461#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
462 unsigned char _pms_ecdhe_psk[4 + MBEDTLS_ECP_MAX_BYTES
463 + MBEDTLS_PSK_MAX_LEN]; /* RFC 5489 2 */
464#endif
465#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
466 unsigned char _pms_ecjpake[32]; /* Thread spec: SHA-256 output */
467#endif
468};
469
470#define MBEDTLS_PREMASTER_SIZE sizeof( union mbedtls_ssl_premaster_secret )
471
472#ifdef __cplusplus
473extern "C" {
474#endif
475
476/*
477 * SSL state machine
478 */
479typedef enum
480{
481 MBEDTLS_SSL_HELLO_REQUEST,
482 MBEDTLS_SSL_CLIENT_HELLO,
483 MBEDTLS_SSL_SERVER_HELLO,
484 MBEDTLS_SSL_SERVER_CERTIFICATE,
485 MBEDTLS_SSL_SERVER_KEY_EXCHANGE,
486 MBEDTLS_SSL_CERTIFICATE_REQUEST,
487 MBEDTLS_SSL_SERVER_HELLO_DONE,
488 MBEDTLS_SSL_CLIENT_CERTIFICATE,
489 MBEDTLS_SSL_CLIENT_KEY_EXCHANGE,
490 MBEDTLS_SSL_CERTIFICATE_VERIFY,
491 MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC,
492 MBEDTLS_SSL_CLIENT_FINISHED,
493 MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC,
494 MBEDTLS_SSL_SERVER_FINISHED,
495 MBEDTLS_SSL_FLUSH_BUFFERS,
496 MBEDTLS_SSL_HANDSHAKE_WRAPUP,
497 MBEDTLS_SSL_HANDSHAKE_OVER,
498 MBEDTLS_SSL_SERVER_NEW_SESSION_TICKET,
499 MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT,
500}
501mbedtls_ssl_states;
502
503/*
504 * The tls_prf function types.
505 */
506typedef enum
507{
508 MBEDTLS_SSL_TLS_PRF_NONE,
509 MBEDTLS_SSL_TLS_PRF_SSL3,
510 MBEDTLS_SSL_TLS_PRF_TLS1,
511 MBEDTLS_SSL_TLS_PRF_SHA384,
512 MBEDTLS_SSL_TLS_PRF_SHA256
513}
514mbedtls_tls_prf_types;
515/**
516 * \brief Callback type: send data on the network.
517 *
518 * \note That callback may be either blocking or non-blocking.
519 *
520 * \param ctx Context for the send callback (typically a file descriptor)
521 * \param buf Buffer holding the data to send
522 * \param len Length of the data to send
523 *
524 * \return The callback must return the number of bytes sent if any,
525 * or a non-zero error code.
526 * If performing non-blocking I/O, \c MBEDTLS_ERR_SSL_WANT_WRITE
527 * must be returned when the operation would block.
528 *
529 * \note The callback is allowed to send fewer bytes than requested.
530 * It must always return the number of bytes actually sent.
531 */
532typedef int mbedtls_ssl_send_t( void *ctx,
533 const unsigned char *buf,
534 size_t len );
535
536/**
537 * \brief Callback type: receive data from the network.
538 *
539 * \note That callback may be either blocking or non-blocking.
540 *
541 * \param ctx Context for the receive callback (typically a file
542 * descriptor)
543 * \param buf Buffer to write the received data to
544 * \param len Length of the receive buffer
545 *
546 * \return The callback must return the number of bytes received,
547 * or a non-zero error code.
548 * If performing non-blocking I/O, \c MBEDTLS_ERR_SSL_WANT_READ
549 * must be returned when the operation would block.
550 *
551 * \note The callback may receive fewer bytes than the length of the
552 * buffer. It must always return the number of bytes actually
553 * received and written to the buffer.
554 */
555typedef int mbedtls_ssl_recv_t( void *ctx,
556 unsigned char *buf,
557 size_t len );
558
559/**
560 * \brief Callback type: receive data from the network, with timeout
561 *
562 * \note That callback must block until data is received, or the
563 * timeout delay expires, or the operation is interrupted by a
564 * signal.
565 *
566 * \param ctx Context for the receive callback (typically a file descriptor)
567 * \param buf Buffer to write the received data to
568 * \param len Length of the receive buffer
569 * \param timeout Maximum nomber of millisecondes to wait for data
570 * 0 means no timeout (potentially waiting forever)
571 *
572 * \return The callback must return the number of bytes received,
573 * or a non-zero error code:
574 * \c MBEDTLS_ERR_SSL_TIMEOUT if the operation timed out,
575 * \c MBEDTLS_ERR_SSL_WANT_READ if interrupted by a signal.
576 *
577 * \note The callback may receive fewer bytes than the length of the
578 * buffer. It must always return the number of bytes actually
579 * received and written to the buffer.
580 */
581typedef int mbedtls_ssl_recv_timeout_t( void *ctx,
582 unsigned char *buf,
583 size_t len,
584 uint32_t timeout );
585/**
586 * \brief Callback type: set a pair of timers/delays to watch
587 *
588 * \param ctx Context pointer
589 * \param int_ms Intermediate delay in milliseconds
590 * \param fin_ms Final delay in milliseconds
591 * 0 cancels the current timer.
592 *
593 * \note This callback must at least store the necessary information
594 * for the associated \c mbedtls_ssl_get_timer_t callback to
595 * return correct information.
596 *
597 * \note If using a event-driven style of programming, an event must
598 * be generated when the final delay is passed. The event must
599 * cause a call to \c mbedtls_ssl_handshake() with the proper
600 * SSL context to be scheduled. Care must be taken to ensure
601 * that at most one such call happens at a time.
602 *
603 * \note Only one timer at a time must be running. Calling this
604 * function while a timer is running must cancel it. Cancelled
605 * timers must not generate any event.
606 */
607typedef void mbedtls_ssl_set_timer_t( void * ctx,
608 uint32_t int_ms,
609 uint32_t fin_ms );
610
611/**
612 * \brief Callback type: get status of timers/delays
613 *
614 * \param ctx Context pointer
615 *
616 * \return This callback must return:
617 * -1 if cancelled (fin_ms == 0),
618 * 0 if none of the delays have passed,
619 * 1 if only the intermediate delay has passed,
620 * 2 if the final delay has passed.
621 */
622typedef int mbedtls_ssl_get_timer_t( void * ctx );
623
624/* Defined below */
628
629/* Defined in ssl_internal.h */
632typedef struct mbedtls_ssl_sig_hash_set_t mbedtls_ssl_sig_hash_set_t;
633#if defined(MBEDTLS_X509_CRT_PARSE_C)
634typedef struct mbedtls_ssl_key_cert mbedtls_ssl_key_cert;
635#endif
636#if defined(MBEDTLS_SSL_PROTO_DTLS)
637typedef struct mbedtls_ssl_flight_item mbedtls_ssl_flight_item;
638#endif
639
640#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
641#if defined(MBEDTLS_X509_CRT_PARSE_C)
642/**
643 * \brief Callback type: start external signature operation.
644 *
645 * This callback is called during an SSL handshake to start
646 * a signature decryption operation using an
647 * external processor. The parameter \p cert contains
648 * the public key; it is up to the callback function to
649 * determine how to access the associated private key.
650 *
651 * This function typically sends or enqueues a request, and
652 * does not wait for the operation to complete. This allows
653 * the handshake step to be non-blocking.
654 *
655 * The parameters \p ssl and \p cert are guaranteed to remain
656 * valid throughout the handshake. On the other hand, this
657 * function must save the contents of \p hash if the value
658 * is needed for later processing, because the \p hash buffer
659 * is no longer valid after this function returns.
660 *
661 * This function may call mbedtls_ssl_set_async_operation_data()
662 * to store an operation context for later retrieval
663 * by the resume or cancel callback.
664 *
665 * \note For RSA signatures, this function must produce output
666 * that is consistent with PKCS#1 v1.5 in the same way as
667 * mbedtls_rsa_pkcs1_sign(). Before the private key operation,
668 * apply the padding steps described in RFC 8017, section 9.2
669 * "EMSA-PKCS1-v1_5" as follows.
670 * - If \p md_alg is #MBEDTLS_MD_NONE, apply the PKCS#1 v1.5
671 * encoding, treating \p hash as the DigestInfo to be
672 * padded. In other words, apply EMSA-PKCS1-v1_5 starting
673 * from step 3, with `T = hash` and `tLen = hash_len`.
674 * - If `md_alg != MBEDTLS_MD_NONE`, apply the PKCS#1 v1.5
675 * encoding, treating \p hash as the hash to be encoded and
676 * padded. In other words, apply EMSA-PKCS1-v1_5 starting
677 * from step 2, with `digestAlgorithm` obtained by calling
678 * mbedtls_oid_get_oid_by_md() on \p md_alg.
679 *
680 * \note For ECDSA signatures, the output format is the DER encoding
681 * `Ecdsa-Sig-Value` defined in
682 * [RFC 4492 section 5.4](https://tools.ietf.org/html/rfc4492#section-5.4).
683 *
684 * \param ssl The SSL connection instance. It should not be
685 * modified other than via
686 * mbedtls_ssl_set_async_operation_data().
687 * \param cert Certificate containing the public key.
688 * In simple cases, this is one of the pointers passed to
689 * mbedtls_ssl_conf_own_cert() when configuring the SSL
690 * connection. However, if other callbacks are used, this
691 * property may not hold. For example, if an SNI callback
692 * is registered with mbedtls_ssl_conf_sni(), then
693 * this callback determines what certificate is used.
694 * \param md_alg Hash algorithm.
695 * \param hash Buffer containing the hash. This buffer is
696 * no longer valid when the function returns.
697 * \param hash_len Size of the \c hash buffer in bytes.
698 *
699 * \return 0 if the operation was started successfully and the SSL
700 * stack should call the resume callback immediately.
701 * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if the operation
702 * was started successfully and the SSL stack should return
703 * immediately without calling the resume callback yet.
704 * \return #MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH if the external
705 * processor does not support this key. The SSL stack will
706 * use the private key object instead.
707 * \return Any other error indicates a fatal failure and is
708 * propagated up the call chain. The callback should
709 * use \c MBEDTLS_ERR_PK_xxx error codes, and <b>must not</b>
710 * use \c MBEDTLS_ERR_SSL_xxx error codes except as
711 * directed in the documentation of this callback.
712 */
713typedef int mbedtls_ssl_async_sign_t( mbedtls_ssl_context *ssl,
714 mbedtls_x509_crt *cert,
715 mbedtls_md_type_t md_alg,
716 const unsigned char *hash,
717 size_t hash_len );
718
719/**
720 * \brief Callback type: start external decryption operation.
721 *
722 * This callback is called during an SSL handshake to start
723 * an RSA decryption operation using an
724 * external processor. The parameter \p cert contains
725 * the public key; it is up to the callback function to
726 * determine how to access the associated private key.
727 *
728 * This function typically sends or enqueues a request, and
729 * does not wait for the operation to complete. This allows
730 * the handshake step to be non-blocking.
731 *
732 * The parameters \p ssl and \p cert are guaranteed to remain
733 * valid throughout the handshake. On the other hand, this
734 * function must save the contents of \p input if the value
735 * is needed for later processing, because the \p input buffer
736 * is no longer valid after this function returns.
737 *
738 * This function may call mbedtls_ssl_set_async_operation_data()
739 * to store an operation context for later retrieval
740 * by the resume or cancel callback.
741 *
742 * \warning RSA decryption as used in TLS is subject to a potential
743 * timing side channel attack first discovered by Bleichenbacher
744 * in 1998. This attack can be remotely exploitable
745 * in practice. To avoid this attack, you must ensure that
746 * if the callback performs an RSA decryption, the time it
747 * takes to execute and return the result does not depend
748 * on whether the RSA decryption succeeded or reported
749 * invalid padding.
750 *
751 * \param ssl The SSL connection instance. It should not be
752 * modified other than via
753 * mbedtls_ssl_set_async_operation_data().
754 * \param cert Certificate containing the public key.
755 * In simple cases, this is one of the pointers passed to
756 * mbedtls_ssl_conf_own_cert() when configuring the SSL
757 * connection. However, if other callbacks are used, this
758 * property may not hold. For example, if an SNI callback
759 * is registered with mbedtls_ssl_conf_sni(), then
760 * this callback determines what certificate is used.
761 * \param input Buffer containing the input ciphertext. This buffer
762 * is no longer valid when the function returns.
763 * \param input_len Size of the \p input buffer in bytes.
764 *
765 * \return 0 if the operation was started successfully and the SSL
766 * stack should call the resume callback immediately.
767 * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if the operation
768 * was started successfully and the SSL stack should return
769 * immediately without calling the resume callback yet.
770 * \return #MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH if the external
771 * processor does not support this key. The SSL stack will
772 * use the private key object instead.
773 * \return Any other error indicates a fatal failure and is
774 * propagated up the call chain. The callback should
775 * use \c MBEDTLS_ERR_PK_xxx error codes, and <b>must not</b>
776 * use \c MBEDTLS_ERR_SSL_xxx error codes except as
777 * directed in the documentation of this callback.
778 */
779typedef int mbedtls_ssl_async_decrypt_t( mbedtls_ssl_context *ssl,
780 mbedtls_x509_crt *cert,
781 const unsigned char *input,
782 size_t input_len );
783#endif /* MBEDTLS_X509_CRT_PARSE_C */
784
785/**
786 * \brief Callback type: resume external operation.
787 *
788 * This callback is called during an SSL handshake to resume
789 * an external operation started by the
790 * ::mbedtls_ssl_async_sign_t or
791 * ::mbedtls_ssl_async_decrypt_t callback.
792 *
793 * This function typically checks the status of a pending
794 * request or causes the request queue to make progress, and
795 * does not wait for the operation to complete. This allows
796 * the handshake step to be non-blocking.
797 *
798 * This function may call mbedtls_ssl_get_async_operation_data()
799 * to retrieve an operation context set by the start callback.
800 * It may call mbedtls_ssl_set_async_operation_data() to modify
801 * this context.
802 *
803 * Note that when this function returns a status other than
804 * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS, it must free any
805 * resources associated with the operation.
806 *
807 * \param ssl The SSL connection instance. It should not be
808 * modified other than via
809 * mbedtls_ssl_set_async_operation_data().
810 * \param output Buffer containing the output (signature or decrypted
811 * data) on success.
812 * \param output_len On success, number of bytes written to \p output.
813 * \param output_size Size of the \p output buffer in bytes.
814 *
815 * \return 0 if output of the operation is available in the
816 * \p output buffer.
817 * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if the operation
818 * is still in progress. Subsequent requests for progress
819 * on the SSL connection will call the resume callback
820 * again.
821 * \return Any other error means that the operation is aborted.
822 * The SSL handshake is aborted. The callback should
823 * use \c MBEDTLS_ERR_PK_xxx error codes, and <b>must not</b>
824 * use \c MBEDTLS_ERR_SSL_xxx error codes except as
825 * directed in the documentation of this callback.
826 */
827typedef int mbedtls_ssl_async_resume_t( mbedtls_ssl_context *ssl,
828 unsigned char *output,
829 size_t *output_len,
830 size_t output_size );
831
832/**
833 * \brief Callback type: cancel external operation.
834 *
835 * This callback is called if an SSL connection is closed
836 * while an asynchronous operation is in progress. Note that
837 * this callback is not called if the
838 * ::mbedtls_ssl_async_resume_t callback has run and has
839 * returned a value other than
840 * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS, since in that case
841 * the asynchronous operation has already completed.
842 *
843 * This function may call mbedtls_ssl_get_async_operation_data()
844 * to retrieve an operation context set by the start callback.
845 *
846 * \param ssl The SSL connection instance. It should not be
847 * modified.
848 */
849typedef void mbedtls_ssl_async_cancel_t( mbedtls_ssl_context *ssl );
850#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
851
852#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED) && \
853 !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
854#define MBEDTLS_SSL_PEER_CERT_DIGEST_MAX_LEN 48
855#if defined(MBEDTLS_SHA256_C)
856#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA256
857#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 32
858#elif defined(MBEDTLS_SHA512_C)
859#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA384
860#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 48
861#elif defined(MBEDTLS_SHA1_C)
862#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA1
863#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 20
864#else
865/* This is already checked in check_config.h, but be sure. */
866#error "Bad configuration - need SHA-1, SHA-256 or SHA-512 enabled to compute digest of peer CRT."
867#endif
868#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED &&
869 !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
870
871#if defined(MBEDTLS_SSL_DTLS_SRTP)
872
873#define MBEDTLS_TLS_SRTP_MAX_MKI_LENGTH 255
874#define MBEDTLS_TLS_SRTP_MAX_PROFILE_LIST_LENGTH 4
875/*
876 * For code readability use a typedef for DTLS-SRTP profiles
877 *
878 * Use_srtp extension protection profiles values as defined in
879 * http://www.iana.org/assignments/srtp-protection/srtp-protection.xhtml
880 *
881 * Reminder: if this list is expanded mbedtls_ssl_check_srtp_profile_value
882 * must be updated too.
883 */
884#define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80 ( (uint16_t) 0x0001)
885#define MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32 ( (uint16_t) 0x0002)
886#define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80 ( (uint16_t) 0x0005)
887#define MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32 ( (uint16_t) 0x0006)
888/* This one is not iana defined, but for code readability. */
889#define MBEDTLS_TLS_SRTP_UNSET ( (uint16_t) 0x0000)
890
891typedef uint16_t mbedtls_ssl_srtp_profile;
892
893typedef struct mbedtls_dtls_srtp_info_t
894{
895 /*! The SRTP profile that was negotiated. */
896 mbedtls_ssl_srtp_profile chosen_dtls_srtp_profile;
897 /*! The length of mki_value. */
898 uint16_t mki_len;
899 /*! The mki_value used, with max size of 256 bytes. */
900 unsigned char mki_value[MBEDTLS_TLS_SRTP_MAX_MKI_LENGTH];
901}
902mbedtls_dtls_srtp_info;
903
904#endif /* MBEDTLS_SSL_DTLS_SRTP */
905
906/*
907 * This structure is used for storing current session data.
908 *
909 * Note: when changing this definition, we need to check and update:
910 * - in tests/suites/test_suite_ssl.function:
911 * ssl_populate_session() and ssl_serialize_session_save_load()
912 * - in library/ssl_tls.c:
913 * mbedtls_ssl_session_init() and mbedtls_ssl_session_free()
914 * mbedtls_ssl_session_save() and ssl_session_load()
915 * ssl_session_copy()
916 */
918{
919#if defined(MBEDTLS_HAVE_TIME)
920 mbedtls_time_t start; /*!< starting time */
921#endif
922 int ciphersuite; /*!< chosen ciphersuite */
923 int compression; /*!< chosen compression */
924 size_t id_len; /*!< session id length */
925 unsigned char id[32]; /*!< session identifier */
926 unsigned char master[48]; /*!< the master secret */
927
928#if defined(MBEDTLS_X509_CRT_PARSE_C)
929#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
930 mbedtls_x509_crt *peer_cert; /*!< peer X.509 cert chain */
931#else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
932 /*! The digest of the peer's end-CRT. This must be kept to detect CRT
933 * changes during renegotiation, mitigating the triple handshake attack. */
934 unsigned char *peer_cert_digest;
935 size_t peer_cert_digest_len;
936 mbedtls_md_type_t peer_cert_digest_type;
937#endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
938#endif /* MBEDTLS_X509_CRT_PARSE_C */
939 uint32_t verify_result; /*!< verification result */
940
941#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
942 unsigned char *ticket; /*!< RFC 5077 session ticket */
943 size_t ticket_len; /*!< session ticket length */
944 uint32_t ticket_lifetime; /*!< ticket lifetime hint */
945#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
946
947#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
948 unsigned char mfl_code; /*!< MaxFragmentLength negotiated by peer */
949#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
950
951#if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
952 int trunc_hmac; /*!< flag for truncated hmac activation */
953#endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
954
955#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
956 int encrypt_then_mac; /*!< flag for EtM activation */
957#endif
958};
959
960/**
961 * SSL/TLS configuration to be shared between mbedtls_ssl_context structures.
962 */
964{
965 /* Group items by size (largest first) to minimize padding overhead */
966
967 /*
968 * Pointers
969 */
970
971 const int *ciphersuite_list[4]; /*!< allowed ciphersuites per version */
972
973 /** Callback for printing debug output */
974 void (*f_dbg)(void *, int, const char *, int, const char *);
975 void *p_dbg; /*!< context for the debug function */
976
977 /** Callback for getting (pseudo-)random numbers */
978 int (*f_rng)(void *, unsigned char *, size_t);
979 void *p_rng; /*!< context for the RNG function */
980
981 /** Callback to retrieve a session from the cache */
983 /** Callback to store a session into the cache */
984 int (*f_set_cache)(void *, const mbedtls_ssl_session *);
985 void *p_cache; /*!< context for cache callbacks */
986
987#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
988 /** Callback for setting cert according to SNI extension */
989 int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
990 void *p_sni; /*!< context for SNI callback */
991#endif
992
993#if defined(MBEDTLS_X509_CRT_PARSE_C)
994 /** Callback to customize X.509 certificate chain verification */
995 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *);
996 void *p_vrfy; /*!< context for X.509 verify calllback */
997#endif
998
999#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
1000 /** Callback to retrieve PSK key from identity */
1001 int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
1002 void *p_psk; /*!< context for PSK callback */
1003#endif
1004
1005#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
1006 /** Callback to create & write a cookie for ClientHello veirifcation */
1007 int (*f_cookie_write)( void *, unsigned char **, unsigned char *,
1008 const unsigned char *, size_t );
1009 /** Callback to verify validity of a ClientHello cookie */
1010 int (*f_cookie_check)( void *, const unsigned char *, size_t,
1011 const unsigned char *, size_t );
1012 void *p_cookie; /*!< context for the cookie callbacks */
1013#endif
1014
1015#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
1016 /** Callback to create & write a session ticket */
1017 int (*f_ticket_write)( void *, const mbedtls_ssl_session *,
1018 unsigned char *, const unsigned char *, size_t *, uint32_t * );
1019 /** Callback to parse a session ticket into a session structure */
1020 int (*f_ticket_parse)( void *, mbedtls_ssl_session *, unsigned char *, size_t);
1021 void *p_ticket; /*!< context for the ticket callbacks */
1022#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
1023
1024#if defined(MBEDTLS_SSL_EXPORT_KEYS)
1025 /** Callback to export key block and master secret */
1026 int (*f_export_keys)( void *, const unsigned char *,
1027 const unsigned char *, size_t, size_t, size_t );
1028 /** Callback to export key block, master secret,
1029 * tls_prf and random bytes. Should replace f_export_keys */
1030 int (*f_export_keys_ext)( void *, const unsigned char *,
1031 const unsigned char *, size_t, size_t, size_t,
1032 const unsigned char[32], const unsigned char[32],
1033 mbedtls_tls_prf_types );
1034 void *p_export_keys; /*!< context for key export callback */
1035#endif
1036
1037#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1038 size_t cid_len; /*!< The length of CIDs for incoming DTLS records. */
1039#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1040
1041#if defined(MBEDTLS_X509_CRT_PARSE_C)
1042 const mbedtls_x509_crt_profile *cert_profile; /*!< verification profile */
1043 mbedtls_ssl_key_cert *key_cert; /*!< own certificate/key pair(s) */
1044 mbedtls_x509_crt *ca_chain; /*!< trusted CAs */
1045 mbedtls_x509_crl *ca_crl; /*!< trusted CAs CRLs */
1046#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
1047 mbedtls_x509_crt_ca_cb_t f_ca_cb;
1048 void *p_ca_cb;
1049#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
1050#endif /* MBEDTLS_X509_CRT_PARSE_C */
1051
1052#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
1053#if defined(MBEDTLS_X509_CRT_PARSE_C)
1054 mbedtls_ssl_async_sign_t *f_async_sign_start; /*!< start asynchronous signature operation */
1055 mbedtls_ssl_async_decrypt_t *f_async_decrypt_start; /*!< start asynchronous decryption operation */
1056#endif /* MBEDTLS_X509_CRT_PARSE_C */
1057 mbedtls_ssl_async_resume_t *f_async_resume; /*!< resume asynchronous operation */
1058 mbedtls_ssl_async_cancel_t *f_async_cancel; /*!< cancel asynchronous operation */
1059 void *p_async_config_data; /*!< Configuration data set by mbedtls_ssl_conf_async_private_cb(). */
1060#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
1061
1062#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
1063 const int *sig_hashes; /*!< allowed signature hashes */
1064#endif
1065
1066#if defined(MBEDTLS_ECP_C)
1067 const mbedtls_ecp_group_id *curve_list; /*!< allowed curves */
1068#endif
1069
1070#if defined(MBEDTLS_DHM_C)
1071 mbedtls_mpi dhm_P; /*!< prime modulus for DHM */
1072 mbedtls_mpi dhm_G; /*!< generator for DHM */
1073#endif
1074
1075#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
1076
1077#if defined(MBEDTLS_USE_PSA_CRYPTO)
1078 psa_key_id_t psk_opaque; /*!< PSA key slot holding opaque PSK. This field
1079 * should only be set via
1080 * mbedtls_ssl_conf_psk_opaque().
1081 * If either no PSK or a raw PSK have been
1082 * configured, this has value \c 0.
1083 */
1084#endif /* MBEDTLS_USE_PSA_CRYPTO */
1085
1086 unsigned char *psk; /*!< The raw pre-shared key. This field should
1087 * only be set via mbedtls_ssl_conf_psk().
1088 * If either no PSK or an opaque PSK
1089 * have been configured, this has value NULL. */
1090 size_t psk_len; /*!< The length of the raw pre-shared key.
1091 * This field should only be set via
1092 * mbedtls_ssl_conf_psk().
1093 * Its value is non-zero if and only if
1094 * \c psk is not \c NULL. */
1095
1096 unsigned char *psk_identity; /*!< The PSK identity for PSK negotiation.
1097 * This field should only be set via
1098 * mbedtls_ssl_conf_psk().
1099 * This is set if and only if either
1100 * \c psk or \c psk_opaque are set. */
1101 size_t psk_identity_len;/*!< The length of PSK identity.
1102 * This field should only be set via
1103 * mbedtls_ssl_conf_psk().
1104 * Its value is non-zero if and only if
1105 * \c psk is not \c NULL or \c psk_opaque
1106 * is not \c 0. */
1107#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
1108
1109#if defined(MBEDTLS_SSL_ALPN)
1110 const char **alpn_list; /*!< ordered list of protocols */
1111#endif
1112
1113#if defined(MBEDTLS_SSL_DTLS_SRTP)
1114 /*! ordered list of supported srtp profile */
1115 const mbedtls_ssl_srtp_profile *dtls_srtp_profile_list;
1116 /*! number of supported profiles */
1117 size_t dtls_srtp_profile_list_len;
1118#endif /* MBEDTLS_SSL_DTLS_SRTP */
1119
1120 /*
1121 * Numerical settings (int then char)
1122 */
1123
1124 uint32_t read_timeout; /*!< timeout for mbedtls_ssl_read (ms) */
1125
1126#if defined(MBEDTLS_SSL_PROTO_DTLS)
1127 uint32_t hs_timeout_min; /*!< initial value of the handshake
1128 retransmission timeout (ms) */
1129 uint32_t hs_timeout_max; /*!< maximum value of the handshake
1130 retransmission timeout (ms) */
1131#endif
1132
1133#if defined(MBEDTLS_SSL_RENEGOTIATION)
1134 int renego_max_records; /*!< grace period for renegotiation */
1135 unsigned char renego_period[8]; /*!< value of the record counters
1136 that triggers renegotiation */
1137#endif
1138
1139#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
1140 unsigned int badmac_limit; /*!< limit of records with a bad MAC */
1141#endif
1142
1143#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
1144 unsigned int dhm_min_bitlen; /*!< min. bit length of the DHM prime */
1145#endif
1146
1147 unsigned char max_major_ver; /*!< max. major version used */
1148 unsigned char max_minor_ver; /*!< max. minor version used */
1149 unsigned char min_major_ver; /*!< min. major version used */
1150 unsigned char min_minor_ver; /*!< min. minor version used */
1151
1152 /*
1153 * Flags (bitfields)
1154 */
1155
1156 unsigned int endpoint : 1; /*!< 0: client, 1: server */
1157 unsigned int transport : 1; /*!< stream (TLS) or datagram (DTLS) */
1158 unsigned int authmode : 2; /*!< MBEDTLS_SSL_VERIFY_XXX */
1159 /* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */
1160 unsigned int allow_legacy_renegotiation : 2 ; /*!< MBEDTLS_LEGACY_XXX */
1161#if defined(MBEDTLS_ARC4_C)
1162 unsigned int arc4_disabled : 1; /*!< blacklist RC4 ciphersuites? */
1163#endif
1164#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
1165 unsigned int mfl_code : 3; /*!< desired fragment length */
1166#endif
1167#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1168 unsigned int encrypt_then_mac : 1 ; /*!< negotiate encrypt-then-mac? */
1169#endif
1170#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
1171 unsigned int extended_ms : 1; /*!< negotiate extended master secret? */
1172#endif
1173#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
1174 unsigned int anti_replay : 1; /*!< detect and prevent replay? */
1175#endif
1176#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
1177 unsigned int cbc_record_splitting : 1; /*!< do cbc record splitting */
1178#endif
1179#if defined(MBEDTLS_SSL_RENEGOTIATION)
1180 unsigned int disable_renegotiation : 1; /*!< disable renegotiation? */
1181#endif
1182#if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
1183 unsigned int trunc_hmac : 1; /*!< negotiate truncated hmac? */
1184#endif
1185#if defined(MBEDTLS_SSL_SESSION_TICKETS)
1186 unsigned int session_tickets : 1; /*!< use session tickets? */
1187#endif
1188#if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
1189 unsigned int fallback : 1; /*!< is this a fallback? */
1190#endif
1191#if defined(MBEDTLS_SSL_SRV_C)
1192 unsigned int cert_req_ca_list : 1; /*!< enable sending CA list in
1193 Certificate Request messages? */
1194#endif
1195#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1196 unsigned int ignore_unexpected_cid : 1; /*!< Determines whether DTLS
1197 * record with unexpected CID
1198 * should lead to failure. */
1199#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1200#if defined(MBEDTLS_SSL_DTLS_SRTP)
1201 unsigned int dtls_srtp_mki_support : 1; /* support having mki_value
1202 in the use_srtp extension */
1203#endif
1204};
1205
1207{
1208 const mbedtls_ssl_config *conf; /*!< configuration information */
1209
1210 /*
1211 * Miscellaneous
1212 */
1213 int state; /*!< SSL handshake: current state */
1214#if defined(MBEDTLS_SSL_RENEGOTIATION)
1215 int renego_status; /*!< Initial, in progress, pending? */
1216 int renego_records_seen; /*!< Records since renego request, or with DTLS,
1217 number of retransmissions of request if
1218 renego_max_records is < 0 */
1219#endif /* MBEDTLS_SSL_RENEGOTIATION */
1220
1221 int major_ver; /*!< equal to MBEDTLS_SSL_MAJOR_VERSION_3 */
1222 int minor_ver; /*!< either 0 (SSL3) or 1 (TLS1.0) */
1223
1224#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
1225 unsigned badmac_seen; /*!< records with a bad MAC received */
1226#endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
1227
1228#if defined(MBEDTLS_X509_CRT_PARSE_C)
1229 /** Callback to customize X.509 certificate chain verification */
1230 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *);
1231 void *p_vrfy; /*!< context for X.509 verify callback */
1232#endif
1233
1234 mbedtls_ssl_send_t *f_send; /*!< Callback for network send */
1235 mbedtls_ssl_recv_t *f_recv; /*!< Callback for network receive */
1237 /*!< Callback for network receive with timeout */
1238
1239 void *p_bio; /*!< context for I/O operations */
1240
1241 /*
1242 * Session layer
1243 */
1244 mbedtls_ssl_session *session_in; /*!< current session data (in) */
1245 mbedtls_ssl_session *session_out; /*!< current session data (out) */
1246 mbedtls_ssl_session *session; /*!< negotiated session data */
1247 mbedtls_ssl_session *session_negotiate; /*!< session data in negotiation */
1248
1249 mbedtls_ssl_handshake_params *handshake; /*!< params required only during
1250 the handshake process */
1251
1252 /*
1253 * Record layer transformations
1254 */
1255 mbedtls_ssl_transform *transform_in; /*!< current transform params (in) */
1256 mbedtls_ssl_transform *transform_out; /*!< current transform params (in) */
1257 mbedtls_ssl_transform *transform; /*!< negotiated transform params */
1258 mbedtls_ssl_transform *transform_negotiate; /*!< transform params in negotiation */
1259
1260 /*
1261 * Timers
1262 */
1263 void *p_timer; /*!< context for the timer callbacks */
1264
1265 mbedtls_ssl_set_timer_t *f_set_timer; /*!< set timer callback */
1266 mbedtls_ssl_get_timer_t *f_get_timer; /*!< get timer callback */
1267
1268 /*
1269 * Record layer (incoming data)
1270 */
1271 unsigned char *in_buf; /*!< input buffer */
1272 unsigned char *in_ctr; /*!< 64-bit incoming message counter
1273 TLS: maintained by us
1274 DTLS: read from peer */
1275 unsigned char *in_hdr; /*!< start of record header */
1276#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1277 unsigned char *in_cid; /*!< The start of the CID;
1278 * (the end is marked by in_len). */
1279#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1280 unsigned char *in_len; /*!< two-bytes message length field */
1281 unsigned char *in_iv; /*!< ivlen-byte IV */
1282 unsigned char *in_msg; /*!< message contents (in_iv+ivlen) */
1283 unsigned char *in_offt; /*!< read offset in application data */
1284
1285 int in_msgtype; /*!< record header: message type */
1286 size_t in_msglen; /*!< record header: message length */
1287 size_t in_left; /*!< amount of data read so far */
1288#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
1289 size_t in_buf_len; /*!< length of input buffer */
1290#endif
1291#if defined(MBEDTLS_SSL_PROTO_DTLS)
1292 uint16_t in_epoch; /*!< DTLS epoch for incoming records */
1293 size_t next_record_offset; /*!< offset of the next record in datagram
1294 (equal to in_left if none) */
1295#endif /* MBEDTLS_SSL_PROTO_DTLS */
1296#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
1297 uint64_t in_window_top; /*!< last validated record seq_num */
1298 uint64_t in_window; /*!< bitmask for replay detection */
1299#endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
1300
1301 size_t in_hslen; /*!< current handshake message length,
1302 including the handshake header */
1303 int nb_zero; /*!< # of 0-length encrypted messages */
1304
1305 int keep_current_message; /*!< drop or reuse current message
1306 on next call to record layer? */
1307
1308#if defined(MBEDTLS_SSL_PROTO_DTLS)
1309 uint8_t disable_datagram_packing; /*!< Disable packing multiple records
1310 * within a single datagram. */
1311#endif /* MBEDTLS_SSL_PROTO_DTLS */
1312
1313 /*
1314 * Record layer (outgoing data)
1315 */
1316 unsigned char *out_buf; /*!< output buffer */
1317 unsigned char *out_ctr; /*!< 64-bit outgoing message counter */
1318 unsigned char *out_hdr; /*!< start of record header */
1319#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1320 unsigned char *out_cid; /*!< The start of the CID;
1321 * (the end is marked by in_len). */
1322#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1323 unsigned char *out_len; /*!< two-bytes message length field */
1324 unsigned char *out_iv; /*!< ivlen-byte IV */
1325 unsigned char *out_msg; /*!< message contents (out_iv+ivlen) */
1326
1327 int out_msgtype; /*!< record header: message type */
1328 size_t out_msglen; /*!< record header: message length */
1329 size_t out_left; /*!< amount of data not yet written */
1330#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
1331 size_t out_buf_len; /*!< length of output buffer */
1332#endif
1333
1334 unsigned char cur_out_ctr[8]; /*!< Outgoing record sequence number. */
1335
1336#if defined(MBEDTLS_SSL_PROTO_DTLS)
1337 uint16_t mtu; /*!< path mtu, used to fragment outgoing messages */
1338#endif /* MBEDTLS_SSL_PROTO_DTLS */
1339
1340#if defined(MBEDTLS_ZLIB_SUPPORT)
1341 unsigned char *compress_buf; /*!< zlib data buffer */
1342#endif /* MBEDTLS_ZLIB_SUPPORT */
1343#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
1344 signed char split_done; /*!< current record already splitted? */
1345#endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */
1346
1347 /*
1348 * PKI layer
1349 */
1350 int client_auth; /*!< flag for client auth. */
1351
1352 /*
1353 * User settings
1354 */
1355#if defined(MBEDTLS_X509_CRT_PARSE_C)
1356 char *hostname; /*!< expected peer CN for verification
1357 (and SNI if available) */
1358#endif /* MBEDTLS_X509_CRT_PARSE_C */
1359
1360#if defined(MBEDTLS_SSL_ALPN)
1361 const char *alpn_chosen; /*!< negotiated protocol */
1362#endif /* MBEDTLS_SSL_ALPN */
1363
1364#if defined(MBEDTLS_SSL_DTLS_SRTP)
1365 /*
1366 * use_srtp extension
1367 */
1368 mbedtls_dtls_srtp_info dtls_srtp_info;
1369#endif /* MBEDTLS_SSL_DTLS_SRTP */
1370
1371 /*
1372 * Information for DTLS hello verify
1373 */
1374#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
1375 unsigned char *cli_id; /*!< transport-level ID of the client */
1376 size_t cli_id_len; /*!< length of cli_id */
1377#endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
1378
1379 /*
1380 * Secure renegotiation
1381 */
1382 /* needed to know when to send extension on server */
1383 int secure_renegotiation; /*!< does peer support legacy or
1384 secure renegotiation */
1385#if defined(MBEDTLS_SSL_RENEGOTIATION)
1386 size_t verify_data_len; /*!< length of verify data stored */
1387 char own_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */
1388 char peer_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]; /*!< previous handshake verify data */
1389#endif /* MBEDTLS_SSL_RENEGOTIATION */
1390
1391#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1392 /* CID configuration to use in subsequent handshakes. */
1393
1394 /*! The next incoming CID, chosen by the user and applying to
1395 * all subsequent handshakes. This may be different from the
1396 * CID currently used in case the user has re-configured the CID
1397 * after an initial handshake. */
1398 unsigned char own_cid[ MBEDTLS_SSL_CID_IN_LEN_MAX ];
1399 uint8_t own_cid_len; /*!< The length of \c own_cid. */
1400 uint8_t negotiate_cid; /*!< This indicates whether the CID extension should
1401 * be negotiated in the next handshake or not.
1402 * Possible values are #MBEDTLS_SSL_CID_ENABLED
1403 * and #MBEDTLS_SSL_CID_DISABLED. */
1404#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1405};
1406
1407#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
1408
1409#if !defined(MBEDTLS_DEPRECATED_REMOVED)
1410
1411#define MBEDTLS_SSL_CHANNEL_OUTBOUND MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( 0 )
1412#define MBEDTLS_SSL_CHANNEL_INBOUND MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( 1 )
1413
1414#if defined(MBEDTLS_DEPRECATED_WARNING)
1415#define MBEDTLS_DEPRECATED __attribute__((deprecated))
1416#else
1417#define MBEDTLS_DEPRECATED
1418#endif /* MBEDTLS_DEPRECATED_WARNING */
1419
1420MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_init)(
1422 const unsigned char *key_enc, const unsigned char *key_dec,
1423 size_t keylen,
1424 const unsigned char *iv_enc, const unsigned char *iv_dec,
1425 size_t ivlen,
1426 const unsigned char *mac_enc, const unsigned char *mac_dec,
1427 size_t maclen);
1428MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_activate)(
1430 int direction );
1431MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_reset)(
1432 mbedtls_ssl_context *ssl );
1433MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_write)(
1434 mbedtls_ssl_context *ssl );
1435MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_read)(
1436 mbedtls_ssl_context *ssl );
1437MBEDTLS_DEPRECATED extern int (*mbedtls_ssl_hw_record_finish)(
1438 mbedtls_ssl_context *ssl );
1439
1440#undef MBEDTLS_DEPRECATED
1441#endif /* !MBEDTLS_DEPRECATED_REMOVED */
1442
1443#endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
1444
1445/**
1446 * \brief Return the name of the ciphersuite associated with the
1447 * given ID
1448 *
1449 * \param ciphersuite_id SSL ciphersuite ID
1450 *
1451 * \return a string containing the ciphersuite name
1452 */
1453const char *mbedtls_ssl_get_ciphersuite_name( const int ciphersuite_id );
1454
1455/**
1456 * \brief Return the ID of the ciphersuite associated with the
1457 * given name
1458 *
1459 * \param ciphersuite_name SSL ciphersuite name
1460 *
1461 * \return the ID with the ciphersuite or 0 if not found
1462 */
1463int mbedtls_ssl_get_ciphersuite_id( const char *ciphersuite_name );
1464
1465/**
1466 * \brief Initialize an SSL context
1467 * Just makes the context ready for mbedtls_ssl_setup() or
1468 * mbedtls_ssl_free()
1469 *
1470 * \param ssl SSL context
1471 */
1473
1474/**
1475 * \brief Set up an SSL context for use
1476 *
1477 * \note No copy of the configuration context is made, it can be
1478 * shared by many mbedtls_ssl_context structures.
1479 *
1480 * \warning The conf structure will be accessed during the session.
1481 * It must not be modified or freed as long as the session
1482 * is active.
1483 *
1484 * \warning This function must be called exactly once per context.
1485 * Calling mbedtls_ssl_setup again is not supported, even
1486 * if no session is active.
1487 *
1488 * \param ssl SSL context
1489 * \param conf SSL configuration to use
1490 *
1491 * \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED if
1492 * memory allocation failed
1493 */
1495 const mbedtls_ssl_config *conf );
1496
1497/**
1498 * \brief Reset an already initialized SSL context for re-use
1499 * while retaining application-set variables, function
1500 * pointers and data.
1501 *
1502 * \param ssl SSL context
1503 * \return 0 if successful, or MBEDTLS_ERR_SSL_ALLOC_FAILED,
1504 MBEDTLS_ERR_SSL_HW_ACCEL_FAILED or
1505 * MBEDTLS_ERR_SSL_COMPRESSION_FAILED
1506 */
1508
1509/**
1510 * \brief Set the current endpoint type
1511 *
1512 * \param conf SSL configuration
1513 * \param endpoint must be MBEDTLS_SSL_IS_CLIENT or MBEDTLS_SSL_IS_SERVER
1514 */
1516
1517/**
1518 * \brief Set the transport type (TLS or DTLS).
1519 * Default: TLS
1520 *
1521 * \note For DTLS, you must either provide a recv callback that
1522 * doesn't block, or one that handles timeouts, see
1523 * \c mbedtls_ssl_set_bio(). You also need to provide timer
1524 * callbacks with \c mbedtls_ssl_set_timer_cb().
1525 *
1526 * \param conf SSL configuration
1527 * \param transport transport type:
1528 * MBEDTLS_SSL_TRANSPORT_STREAM for TLS,
1529 * MBEDTLS_SSL_TRANSPORT_DATAGRAM for DTLS.
1530 */
1532
1533/**
1534 * \brief Set the certificate verification mode
1535 * Default: NONE on server, REQUIRED on client
1536 *
1537 * \param conf SSL configuration
1538 * \param authmode can be:
1539 *
1540 * MBEDTLS_SSL_VERIFY_NONE: peer certificate is not checked
1541 * (default on server)
1542 * (insecure on client)
1543 *
1544 * MBEDTLS_SSL_VERIFY_OPTIONAL: peer certificate is checked, however the
1545 * handshake continues even if verification failed;
1546 * mbedtls_ssl_get_verify_result() can be called after the
1547 * handshake is complete.
1548 *
1549 * MBEDTLS_SSL_VERIFY_REQUIRED: peer *must* present a valid certificate,
1550 * handshake is aborted if verification failed.
1551 * (default on client)
1552 *
1553 * \note On client, MBEDTLS_SSL_VERIFY_REQUIRED is the recommended mode.
1554 * With MBEDTLS_SSL_VERIFY_OPTIONAL, the user needs to call mbedtls_ssl_get_verify_result() at
1555 * the right time(s), which may not be obvious, while REQUIRED always perform
1556 * the verification as soon as possible. For example, REQUIRED was protecting
1557 * against the "triple handshake" attack even before it was found.
1558 */
1560
1561#if defined(MBEDTLS_X509_CRT_PARSE_C)
1562/**
1563 * \brief Set the verification callback (Optional).
1564 *
1565 * If set, the provided verify callback is called for each
1566 * certificate in the peer's CRT chain, including the trusted
1567 * root. For more information, please see the documentation of
1568 * \c mbedtls_x509_crt_verify().
1569 *
1570 * \note For per context callbacks and contexts, please use
1571 * mbedtls_ssl_set_verify() instead.
1572 *
1573 * \param conf The SSL configuration to use.
1574 * \param f_vrfy The verification callback to use during CRT verification.
1575 * \param p_vrfy The opaque context to be passed to the callback.
1576 */
1577void mbedtls_ssl_conf_verify( mbedtls_ssl_config *conf,
1578 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
1579 void *p_vrfy );
1580#endif /* MBEDTLS_X509_CRT_PARSE_C */
1581
1582/**
1583 * \brief Set the random number generator callback
1584 *
1585 * \param conf SSL configuration
1586 * \param f_rng RNG function
1587 * \param p_rng RNG parameter
1588 */
1590 int (*f_rng)(void *, unsigned char *, size_t),
1591 void *p_rng );
1592
1593/**
1594 * \brief Set the debug callback
1595 *
1596 * The callback has the following argument:
1597 * void * opaque context for the callback
1598 * int debug level
1599 * const char * file name
1600 * int line number
1601 * const char * message
1602 *
1603 * \param conf SSL configuration
1604 * \param f_dbg debug function
1605 * \param p_dbg debug parameter
1606 */
1608 void (*f_dbg)(void *, int, const char *, int, const char *),
1609 void *p_dbg );
1610
1611/**
1612 * \brief Set the underlying BIO callbacks for write, read and
1613 * read-with-timeout.
1614 *
1615 * \param ssl SSL context
1616 * \param p_bio parameter (context) shared by BIO callbacks
1617 * \param f_send write callback
1618 * \param f_recv read callback
1619 * \param f_recv_timeout blocking read callback with timeout.
1620 *
1621 * \note One of f_recv or f_recv_timeout can be NULL, in which case
1622 * the other is used. If both are non-NULL, f_recv_timeout is
1623 * used and f_recv is ignored (as if it were NULL).
1624 *
1625 * \note The two most common use cases are:
1626 * - non-blocking I/O, f_recv != NULL, f_recv_timeout == NULL
1627 * - blocking I/O, f_recv == NULL, f_recv_timout != NULL
1628 *
1629 * \note For DTLS, you need to provide either a non-NULL
1630 * f_recv_timeout callback, or a f_recv that doesn't block.
1631 *
1632 * \note See the documentations of \c mbedtls_ssl_send_t,
1633 * \c mbedtls_ssl_recv_t and \c mbedtls_ssl_recv_timeout_t for
1634 * the conventions those callbacks must follow.
1635 *
1636 * \note On some platforms, net_sockets.c provides
1637 * \c mbedtls_net_send(), \c mbedtls_net_recv() and
1638 * \c mbedtls_net_recv_timeout() that are suitable to be used
1639 * here.
1640 */
1642 void *p_bio,
1643 mbedtls_ssl_send_t *f_send,
1644 mbedtls_ssl_recv_t *f_recv,
1645 mbedtls_ssl_recv_timeout_t *f_recv_timeout );
1646
1647#if defined(MBEDTLS_SSL_PROTO_DTLS)
1648
1649#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
1650
1651
1652/**
1653 * \brief Configure the use of the Connection ID (CID)
1654 * extension in the next handshake.
1655 *
1656 * Reference: draft-ietf-tls-dtls-connection-id-05
1657 * https://tools.ietf.org/html/draft-ietf-tls-dtls-connection-id-05
1658 *
1659 * The DTLS CID extension allows the reliable association of
1660 * DTLS records to DTLS connections across changes in the
1661 * underlying transport (changed IP and Port metadata) by
1662 * adding explicit connection identifiers (CIDs) to the
1663 * headers of encrypted DTLS records. The desired CIDs are
1664 * configured by the application layer and are exchanged in
1665 * new `ClientHello` / `ServerHello` extensions during the
1666 * handshake, where each side indicates the CID it wants the
1667 * peer to use when writing encrypted messages. The CIDs are
1668 * put to use once records get encrypted: the stack discards
1669 * any incoming records that don't include the configured CID
1670 * in their header, and adds the peer's requested CID to the
1671 * headers of outgoing messages.
1672 *
1673 * This API enables or disables the use of the CID extension
1674 * in the next handshake and sets the value of the CID to
1675 * be used for incoming messages.
1676 *
1677 * \param ssl The SSL context to configure. This must be initialized.
1678 * \param enable This value determines whether the CID extension should
1679 * be used or not. Possible values are:
1680 * - MBEDTLS_SSL_CID_ENABLED to enable the use of the CID.
1681 * - MBEDTLS_SSL_CID_DISABLED (default) to disable the use
1682 * of the CID.
1683 * \param own_cid The address of the readable buffer holding the CID we want
1684 * the peer to use when sending encrypted messages to us.
1685 * This may be \c NULL if \p own_cid_len is \c 0.
1686 * This parameter is unused if \p enabled is set to
1687 * MBEDTLS_SSL_CID_DISABLED.
1688 * \param own_cid_len The length of \p own_cid.
1689 * This parameter is unused if \p enabled is set to
1690 * MBEDTLS_SSL_CID_DISABLED.
1691 *
1692 * \note The value of \p own_cid_len must match the value of the
1693 * \c len parameter passed to mbedtls_ssl_conf_cid()
1694 * when configuring the ::mbedtls_ssl_config that \p ssl
1695 * is bound to.
1696 *
1697 * \note This CID configuration applies to subsequent handshakes
1698 * performed on the SSL context \p ssl, but does not trigger
1699 * one. You still have to call `mbedtls_ssl_handshake()`
1700 * (for the initial handshake) or `mbedtls_ssl_renegotiate()`
1701 * (for a renegotiation handshake) explicitly after a
1702 * successful call to this function to run the handshake.
1703 *
1704 * \note This call cannot guarantee that the use of the CID
1705 * will be successfully negotiated in the next handshake,
1706 * because the peer might not support it. Specifically:
1707 * - On the Client, enabling the use of the CID through
1708 * this call implies that the `ClientHello` in the next
1709 * handshake will include the CID extension, thereby
1710 * offering the use of the CID to the server. Only if
1711 * the `ServerHello` contains the CID extension, too,
1712 * the CID extension will actually be put to use.
1713 * - On the Server, enabling the use of the CID through
1714 * this call implies that that the server will look for
1715 * the CID extension in a `ClientHello` from the client,
1716 * and, if present, reply with a CID extension in its
1717 * `ServerHello`.
1718 *
1719 * \note To check whether the use of the CID was negotiated
1720 * after the subsequent handshake has completed, please
1721 * use the API mbedtls_ssl_get_peer_cid().
1722 *
1723 * \warning If the use of the CID extension is enabled in this call
1724 * and the subsequent handshake negotiates its use, Mbed TLS
1725 * will silently drop every packet whose CID does not match
1726 * the CID configured in \p own_cid. It is the responsibility
1727 * of the user to adapt the underlying transport to take care
1728 * of CID-based demultiplexing before handing datagrams to
1729 * Mbed TLS.
1730 *
1731 * \return \c 0 on success. In this case, the CID configuration
1732 * applies to the next handshake.
1733 * \return A negative error code on failure.
1734 */
1735int mbedtls_ssl_set_cid( mbedtls_ssl_context *ssl,
1736 int enable,
1737 unsigned char const *own_cid,
1738 size_t own_cid_len );
1739
1740/**
1741 * \brief Get information about the use of the CID extension
1742 * in the current connection.
1743 *
1744 * \param ssl The SSL context to query.
1745 * \param enabled The address at which to store whether the CID extension
1746 * is currently in use or not. If the CID is in use,
1747 * `*enabled` is set to MBEDTLS_SSL_CID_ENABLED;
1748 * otherwise, it is set to MBEDTLS_SSL_CID_DISABLED.
1749 * \param peer_cid The address of the buffer in which to store the CID
1750 * chosen by the peer (if the CID extension is used).
1751 * This may be \c NULL in case the value of peer CID
1752 * isn't needed. If it is not \c NULL, \p peer_cid_len
1753 * must not be \c NULL.
1754 * \param peer_cid_len The address at which to store the size of the CID
1755 * chosen by the peer (if the CID extension is used).
1756 * This is also the number of Bytes in \p peer_cid that
1757 * have been written.
1758 * This may be \c NULL in case the length of the peer CID
1759 * isn't needed. If it is \c NULL, \p peer_cid must be
1760 * \c NULL, too.
1761 *
1762 * \note This applies to the state of the CID negotiated in
1763 * the last complete handshake. If a handshake is in
1764 * progress, this function will attempt to complete
1765 * the handshake first.
1766 *
1767 * \note If CID extensions have been exchanged but both client
1768 * and server chose to use an empty CID, this function
1769 * sets `*enabled` to #MBEDTLS_SSL_CID_DISABLED
1770 * (the rationale for this is that the resulting
1771 * communication is the same as if the CID extensions
1772 * hadn't been used).
1773 *
1774 * \return \c 0 on success.
1775 * \return A negative error code on failure.
1776 */
1777int mbedtls_ssl_get_peer_cid( mbedtls_ssl_context *ssl,
1778 int *enabled,
1779 unsigned char peer_cid[ MBEDTLS_SSL_CID_OUT_LEN_MAX ],
1780 size_t *peer_cid_len );
1781
1782#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
1783
1784/**
1785 * \brief Set the Maximum Tranport Unit (MTU).
1786 * Special value: 0 means unset (no limit).
1787 * This represents the maximum size of a datagram payload
1788 * handled by the transport layer (usually UDP) as determined
1789 * by the network link and stack. In practice, this controls
1790 * the maximum size datagram the DTLS layer will pass to the
1791 * \c f_send() callback set using \c mbedtls_ssl_set_bio().
1792 *
1793 * \note The limit on datagram size is converted to a limit on
1794 * record payload by subtracting the current overhead of
1795 * encapsulation and encryption/authentication if any.
1796 *
1797 * \note This can be called at any point during the connection, for
1798 * example when a Path Maximum Transfer Unit (PMTU)
1799 * estimate becomes available from other sources,
1800 * such as lower (or higher) protocol layers.
1801 *
1802 * \note This setting only controls the size of the packets we send,
1803 * and does not restrict the size of the datagrams we're
1804 * willing to receive. Client-side, you can request the
1805 * server to use smaller records with \c
1806 * mbedtls_ssl_conf_max_frag_len().
1807 *
1808 * \note If both a MTU and a maximum fragment length have been
1809 * configured (or negotiated with the peer), the resulting
1810 * lower limit on record payload (see first note) is used.
1811 *
1812 * \note This can only be used to decrease the maximum size
1813 * of datagrams (hence records, see first note) sent. It
1814 * cannot be used to increase the maximum size of records over
1815 * the limit set by #MBEDTLS_SSL_OUT_CONTENT_LEN.
1816 *
1817 * \note Values lower than the current record layer expansion will
1818 * result in an error when trying to send data.
1819 *
1820 * \note Using record compression together with a non-zero MTU value
1821 * will result in an error when trying to send data.
1822 *
1823 * \param ssl SSL context
1824 * \param mtu Value of the path MTU in bytes
1825 */
1826void mbedtls_ssl_set_mtu( mbedtls_ssl_context *ssl, uint16_t mtu );
1827#endif /* MBEDTLS_SSL_PROTO_DTLS */
1828
1829#if defined(MBEDTLS_X509_CRT_PARSE_C)
1830/**
1831 * \brief Set a connection-specific verification callback (optional).
1832 *
1833 * If set, the provided verify callback is called for each
1834 * certificate in the peer's CRT chain, including the trusted
1835 * root. For more information, please see the documentation of
1836 * \c mbedtls_x509_crt_verify().
1837 *
1838 * \note This call is analogous to mbedtls_ssl_conf_verify() but
1839 * binds the verification callback and context to an SSL context
1840 * as opposed to an SSL configuration.
1841 * If mbedtls_ssl_conf_verify() and mbedtls_ssl_set_verify()
1842 * are both used, mbedtls_ssl_set_verify() takes precedence.
1843 *
1844 * \param ssl The SSL context to use.
1845 * \param f_vrfy The verification callback to use during CRT verification.
1846 * \param p_vrfy The opaque context to be passed to the callback.
1847 */
1848void mbedtls_ssl_set_verify( mbedtls_ssl_context *ssl,
1849 int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
1850 void *p_vrfy );
1851#endif /* MBEDTLS_X509_CRT_PARSE_C */
1852
1853/**
1854 * \brief Set the timeout period for mbedtls_ssl_read()
1855 * (Default: no timeout.)
1856 *
1857 * \param conf SSL configuration context
1858 * \param timeout Timeout value in milliseconds.
1859 * Use 0 for no timeout (default).
1860 *
1861 * \note With blocking I/O, this will only work if a non-NULL
1862 * \c f_recv_timeout was set with \c mbedtls_ssl_set_bio().
1863 * With non-blocking I/O, this will only work if timer
1864 * callbacks were set with \c mbedtls_ssl_set_timer_cb().
1865 *
1866 * \note With non-blocking I/O, you may also skip this function
1867 * altogether and handle timeouts at the application layer.
1868 */
1870
1871#if defined(MBEDTLS_SSL_RECORD_CHECKING)
1872/**
1873 * \brief Check whether a buffer contains a valid and authentic record
1874 * that has not been seen before. (DTLS only).
1875 *
1876 * This function does not change the user-visible state
1877 * of the SSL context. Its sole purpose is to provide
1878 * an indication of the legitimacy of an incoming record.
1879 *
1880 * This can be useful e.g. in distributed server environments
1881 * using the DTLS Connection ID feature, in which connections
1882 * might need to be passed between service instances on a change
1883 * of peer address, but where such disruptive operations should
1884 * only happen after the validity of incoming records has been
1885 * confirmed.
1886 *
1887 * \param ssl The SSL context to use.
1888 * \param buf The address of the buffer holding the record to be checked.
1889 * This must be a read/write buffer of length \p buflen Bytes.
1890 * \param buflen The length of \p buf in Bytes.
1891 *
1892 * \note This routine only checks whether the provided buffer begins
1893 * with a valid and authentic record that has not been seen
1894 * before, but does not check potential data following the
1895 * initial record. In particular, it is possible to pass DTLS
1896 * datagrams containing multiple records, in which case only
1897 * the first record is checked.
1898 *
1899 * \note This function modifies the input buffer \p buf. If you need
1900 * to preserve the original record, you have to maintain a copy.
1901 *
1902 * \return \c 0 if the record is valid and authentic and has not been
1903 * seen before.
1904 * \return MBEDTLS_ERR_SSL_INVALID_MAC if the check completed
1905 * successfully but the record was found to be not authentic.
1906 * \return MBEDTLS_ERR_SSL_INVALID_RECORD if the check completed
1907 * successfully but the record was found to be invalid for
1908 * a reason different from authenticity checking.
1909 * \return MBEDTLS_ERR_SSL_UNEXPECTED_RECORD if the check completed
1910 * successfully but the record was found to be unexpected
1911 * in the state of the SSL context, including replayed records.
1912 * \return Another negative error code on different kinds of failure.
1913 * In this case, the SSL context becomes unusable and needs
1914 * to be freed or reset before reuse.
1915 */
1916int mbedtls_ssl_check_record( mbedtls_ssl_context const *ssl,
1917 unsigned char *buf,
1918 size_t buflen );
1919#endif /* MBEDTLS_SSL_RECORD_CHECKING */
1920
1921/**
1922 * \brief Set the timer callbacks (Mandatory for DTLS.)
1923 *
1924 * \param ssl SSL context
1925 * \param p_timer parameter (context) shared by timer callbacks
1926 * \param f_set_timer set timer callback
1927 * \param f_get_timer get timer callback. Must return:
1928 *
1929 * \note See the documentation of \c mbedtls_ssl_set_timer_t and
1930 * \c mbedtls_ssl_get_timer_t for the conventions this pair of
1931 * callbacks must follow.
1932 *
1933 * \note On some platforms, timing.c provides
1934 * \c mbedtls_timing_set_delay() and
1935 * \c mbedtls_timing_get_delay() that are suitable for using
1936 * here, except if using an event-driven style.
1937 *
1938 * \note See also the "DTLS tutorial" article in our knowledge base.
1939 * https://tls.mbed.org/kb/how-to/dtls-tutorial
1940 */
1942 void *p_timer,
1943 mbedtls_ssl_set_timer_t *f_set_timer,
1944 mbedtls_ssl_get_timer_t *f_get_timer );
1945
1946/**
1947 * \brief Callback type: generate and write session ticket
1948 *
1949 * \note This describes what a callback implementation should do.
1950 * This callback should generate an encrypted and
1951 * authenticated ticket for the session and write it to the
1952 * output buffer. Here, ticket means the opaque ticket part
1953 * of the NewSessionTicket structure of RFC 5077.
1954 *
1955 * \param p_ticket Context for the callback
1956 * \param session SSL session to be written in the ticket
1957 * \param start Start of the output buffer
1958 * \param end End of the output buffer
1959 * \param tlen On exit, holds the length written
1960 * \param lifetime On exit, holds the lifetime of the ticket in seconds
1961 *
1962 * \return 0 if successful, or
1963 * a specific MBEDTLS_ERR_XXX code.
1964 */
1965typedef int mbedtls_ssl_ticket_write_t( void *p_ticket,
1966 const mbedtls_ssl_session *session,
1967 unsigned char *start,
1968 const unsigned char *end,
1969 size_t *tlen,
1970 uint32_t *lifetime );
1971
1972#if defined(MBEDTLS_SSL_EXPORT_KEYS)
1973/**
1974 * \brief Callback type: Export key block and master secret
1975 *
1976 * \note This is required for certain uses of TLS, e.g. EAP-TLS
1977 * (RFC 5216) and Thread. The key pointers are ephemeral and
1978 * therefore must not be stored. The master secret and keys
1979 * should not be used directly except as an input to a key
1980 * derivation function.
1981 *
1982 * \param p_expkey Context for the callback
1983 * \param ms Pointer to master secret (fixed length: 48 bytes)
1984 * \param kb Pointer to key block, see RFC 5246 section 6.3
1985 * (variable length: 2 * maclen + 2 * keylen + 2 * ivlen).
1986 * \param maclen MAC length
1987 * \param keylen Key length
1988 * \param ivlen IV length
1989 *
1990 * \return 0 if successful, or
1991 * a specific MBEDTLS_ERR_XXX code.
1992 */
1993typedef int mbedtls_ssl_export_keys_t( void *p_expkey,
1994 const unsigned char *ms,
1995 const unsigned char *kb,
1996 size_t maclen,
1997 size_t keylen,
1998 size_t ivlen );
1999
2000/**
2001 * \brief Callback type: Export key block, master secret,
2002 * handshake randbytes and the tls_prf function
2003 * used to derive keys.
2004 *
2005 * \note This is required for certain uses of TLS, e.g. EAP-TLS
2006 * (RFC 5216) and Thread. The key pointers are ephemeral and
2007 * therefore must not be stored. The master secret and keys
2008 * should not be used directly except as an input to a key
2009 * derivation function.
2010 *
2011 * \param p_expkey Context for the callback.
2012 * \param ms Pointer to master secret (fixed length: 48 bytes).
2013 * \param kb Pointer to key block, see RFC 5246 section 6.3.
2014 * (variable length: 2 * maclen + 2 * keylen + 2 * ivlen).
2015 * \param maclen MAC length.
2016 * \param keylen Key length.
2017 * \param ivlen IV length.
2018 * \param client_random The client random bytes.
2019 * \param server_random The server random bytes.
2020 * \param tls_prf_type The tls_prf enum type.
2021 *
2022 * \return 0 if successful, or
2023 * a specific MBEDTLS_ERR_XXX code.
2024 */
2025typedef int mbedtls_ssl_export_keys_ext_t( void *p_expkey,
2026 const unsigned char *ms,
2027 const unsigned char *kb,
2028 size_t maclen,
2029 size_t keylen,
2030 size_t ivlen,
2031 const unsigned char client_random[32],
2032 const unsigned char server_random[32],
2033 mbedtls_tls_prf_types tls_prf_type );
2034#endif /* MBEDTLS_SSL_EXPORT_KEYS */
2035
2036/**
2037 * \brief Callback type: parse and load session ticket
2038 *
2039 * \note This describes what a callback implementation should do.
2040 * This callback should parse a session ticket as generated
2041 * by the corresponding mbedtls_ssl_ticket_write_t function,
2042 * and, if the ticket is authentic and valid, load the
2043 * session.
2044 *
2045 * \note The implementation is allowed to modify the first len
2046 * bytes of the input buffer, eg to use it as a temporary
2047 * area for the decrypted ticket contents.
2048 *
2049 * \param p_ticket Context for the callback
2050 * \param session SSL session to be loaded
2051 * \param buf Start of the buffer containing the ticket
2052 * \param len Length of the ticket.
2053 *
2054 * \return 0 if successful, or
2055 * MBEDTLS_ERR_SSL_INVALID_MAC if not authentic, or
2056 * MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED if expired, or
2057 * any other non-zero code for other failures.
2058 */
2059typedef int mbedtls_ssl_ticket_parse_t( void *p_ticket,
2060 mbedtls_ssl_session *session,
2061 unsigned char *buf,
2062 size_t len );
2063
2064#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
2065/**
2066 * \brief Configure SSL session ticket callbacks (server only).
2067 * (Default: none.)
2068 *
2069 * \note On server, session tickets are enabled by providing
2070 * non-NULL callbacks.
2071 *
2072 * \note On client, use \c mbedtls_ssl_conf_session_tickets().
2073 *
2074 * \param conf SSL configuration context
2075 * \param f_ticket_write Callback for writing a ticket
2076 * \param f_ticket_parse Callback for parsing a ticket
2077 * \param p_ticket Context shared by the two callbacks
2078 */
2079void mbedtls_ssl_conf_session_tickets_cb( mbedtls_ssl_config *conf,
2080 mbedtls_ssl_ticket_write_t *f_ticket_write,
2081 mbedtls_ssl_ticket_parse_t *f_ticket_parse,
2082 void *p_ticket );
2083#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
2084
2085#if defined(MBEDTLS_SSL_EXPORT_KEYS)
2086/**
2087 * \brief Configure key export callback.
2088 * (Default: none.)
2089 *
2090 * \note See \c mbedtls_ssl_export_keys_t.
2091 *
2092 * \param conf SSL configuration context
2093 * \param f_export_keys Callback for exporting keys
2094 * \param p_export_keys Context for the callback
2095 */
2096void mbedtls_ssl_conf_export_keys_cb( mbedtls_ssl_config *conf,
2097 mbedtls_ssl_export_keys_t *f_export_keys,
2098 void *p_export_keys );
2099
2100/**
2101 * \brief Configure extended key export callback.
2102 * (Default: none.)
2103 *
2104 * \note See \c mbedtls_ssl_export_keys_ext_t.
2105 * \warning Exported key material must not be used for any purpose
2106 * before the (D)TLS handshake is completed
2107 *
2108 * \param conf SSL configuration context
2109 * \param f_export_keys_ext Callback for exporting keys
2110 * \param p_export_keys Context for the callback
2111 */
2112void mbedtls_ssl_conf_export_keys_ext_cb( mbedtls_ssl_config *conf,
2113 mbedtls_ssl_export_keys_ext_t *f_export_keys_ext,
2114 void *p_export_keys );
2115#endif /* MBEDTLS_SSL_EXPORT_KEYS */
2116
2117#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
2118/**
2119 * \brief Configure asynchronous private key operation callbacks.
2120 *
2121 * \param conf SSL configuration context
2122 * \param f_async_sign Callback to start a signature operation. See
2123 * the description of ::mbedtls_ssl_async_sign_t
2124 * for more information. This may be \c NULL if the
2125 * external processor does not support any signature
2126 * operation; in this case the private key object
2127 * associated with the certificate will be used.
2128 * \param f_async_decrypt Callback to start a decryption operation. See
2129 * the description of ::mbedtls_ssl_async_decrypt_t
2130 * for more information. This may be \c NULL if the
2131 * external processor does not support any decryption
2132 * operation; in this case the private key object
2133 * associated with the certificate will be used.
2134 * \param f_async_resume Callback to resume an asynchronous operation. See
2135 * the description of ::mbedtls_ssl_async_resume_t
2136 * for more information. This may not be \c NULL unless
2137 * \p f_async_sign and \p f_async_decrypt are both
2138 * \c NULL.
2139 * \param f_async_cancel Callback to cancel an asynchronous operation. See
2140 * the description of ::mbedtls_ssl_async_cancel_t
2141 * for more information. This may be \c NULL if
2142 * no cleanup is needed.
2143 * \param config_data A pointer to configuration data which can be
2144 * retrieved with
2145 * mbedtls_ssl_conf_get_async_config_data(). The
2146 * library stores this value without dereferencing it.
2147 */
2148void mbedtls_ssl_conf_async_private_cb( mbedtls_ssl_config *conf,
2149 mbedtls_ssl_async_sign_t *f_async_sign,
2150 mbedtls_ssl_async_decrypt_t *f_async_decrypt,
2151 mbedtls_ssl_async_resume_t *f_async_resume,
2152 mbedtls_ssl_async_cancel_t *f_async_cancel,
2153 void *config_data );
2154
2155/**
2156 * \brief Retrieve the configuration data set by
2157 * mbedtls_ssl_conf_async_private_cb().
2158 *
2159 * \param conf SSL configuration context
2160 * \return The configuration data set by
2161 * mbedtls_ssl_conf_async_private_cb().
2162 */
2163void *mbedtls_ssl_conf_get_async_config_data( const mbedtls_ssl_config *conf );
2164
2165/**
2166 * \brief Retrieve the asynchronous operation user context.
2167 *
2168 * \note This function may only be called while a handshake
2169 * is in progress.
2170 *
2171 * \param ssl The SSL context to access.
2172 *
2173 * \return The asynchronous operation user context that was last
2174 * set during the current handshake. If
2175 * mbedtls_ssl_set_async_operation_data() has not yet been
2176 * called during the current handshake, this function returns
2177 * \c NULL.
2178 */
2179void *mbedtls_ssl_get_async_operation_data( const mbedtls_ssl_context *ssl );
2180
2181/**
2182 * \brief Retrieve the asynchronous operation user context.
2183 *
2184 * \note This function may only be called while a handshake
2185 * is in progress.
2186 *
2187 * \param ssl The SSL context to access.
2188 * \param ctx The new value of the asynchronous operation user context.
2189 * Call mbedtls_ssl_get_async_operation_data() later during the
2190 * same handshake to retrieve this value.
2191 */
2192void mbedtls_ssl_set_async_operation_data( mbedtls_ssl_context *ssl,
2193 void *ctx );
2194#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
2195
2196/**
2197 * \brief Callback type: generate a cookie
2198 *
2199 * \param ctx Context for the callback
2200 * \param p Buffer to write to,
2201 * must be updated to point right after the cookie
2202 * \param end Pointer to one past the end of the output buffer
2203 * \param info Client ID info that was passed to
2204 * \c mbedtls_ssl_set_client_transport_id()
2205 * \param ilen Length of info in bytes
2206 *
2207 * \return The callback must return 0 on success,
2208 * or a negative error code.
2209 */
2210typedef int mbedtls_ssl_cookie_write_t( void *ctx,
2211 unsigned char **p, unsigned char *end,
2212 const unsigned char *info, size_t ilen );
2213
2214/**
2215 * \brief Callback type: verify a cookie
2216 *
2217 * \param ctx Context for the callback
2218 * \param cookie Cookie to verify
2219 * \param clen Length of cookie
2220 * \param info Client ID info that was passed to
2221 * \c mbedtls_ssl_set_client_transport_id()
2222 * \param ilen Length of info in bytes
2223 *
2224 * \return The callback must return 0 if cookie is valid,
2225 * or a negative error code.
2226 */
2227typedef int mbedtls_ssl_cookie_check_t( void *ctx,
2228 const unsigned char *cookie, size_t clen,
2229 const unsigned char *info, size_t ilen );
2230
2231#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
2232/**
2233 * \brief Register callbacks for DTLS cookies
2234 * (Server only. DTLS only.)
2235 *
2236 * Default: dummy callbacks that fail, in order to force you to
2237 * register working callbacks (and initialize their context).
2238 *
2239 * To disable HelloVerifyRequest, register NULL callbacks.
2240 *
2241 * \warning Disabling hello verification allows your server to be used
2242 * for amplification in DoS attacks against other hosts.
2243 * Only disable if you known this can't happen in your
2244 * particular environment.
2245 *
2246 * \note See comments on \c mbedtls_ssl_handshake() about handling
2247 * the MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED that is expected
2248 * on the first handshake attempt when this is enabled.
2249 *
2250 * \note This is also necessary to handle client reconnection from
2251 * the same port as described in RFC 6347 section 4.2.8 (only
2252 * the variant with cookies is supported currently). See
2253 * comments on \c mbedtls_ssl_read() for details.
2254 *
2255 * \param conf SSL configuration
2256 * \param f_cookie_write Cookie write callback
2257 * \param f_cookie_check Cookie check callback
2258 * \param p_cookie Context for both callbacks
2259 */
2260void mbedtls_ssl_conf_dtls_cookies( mbedtls_ssl_config *conf,
2261 mbedtls_ssl_cookie_write_t *f_cookie_write,
2262 mbedtls_ssl_cookie_check_t *f_cookie_check,
2263 void *p_cookie );
2264
2265/**
2266 * \brief Set client's transport-level identification info.
2267 * (Server only. DTLS only.)
2268 *
2269 * This is usually the IP address (and port), but could be
2270 * anything identify the client depending on the underlying
2271 * network stack. Used for HelloVerifyRequest with DTLS.
2272 * This is *not* used to route the actual packets.
2273 *
2274 * \param ssl SSL context
2275 * \param info Transport-level info identifying the client (eg IP + port)
2276 * \param ilen Length of info in bytes
2277 *
2278 * \note An internal copy is made, so the info buffer can be reused.
2279 *
2280 * \return 0 on success,
2281 * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used on client,
2282 * MBEDTLS_ERR_SSL_ALLOC_FAILED if out of memory.
2283 */
2284int mbedtls_ssl_set_client_transport_id( mbedtls_ssl_context *ssl,
2285 const unsigned char *info,
2286 size_t ilen );
2287
2288#endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
2289
2290#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
2291/**
2292 * \brief Enable or disable anti-replay protection for DTLS.
2293 * (DTLS only, no effect on TLS.)
2294 * Default: enabled.
2295 *
2296 * \param conf SSL configuration
2297 * \param mode MBEDTLS_SSL_ANTI_REPLAY_ENABLED or MBEDTLS_SSL_ANTI_REPLAY_DISABLED.
2298 *
2299 * \warning Disabling this is a security risk unless the application
2300 * protocol handles duplicated packets in a safe way. You
2301 * should not disable this without careful consideration.
2302 * However, if your application already detects duplicated
2303 * packets and needs information about them to adjust its
2304 * transmission strategy, then you'll want to disable this.
2305 */
2306void mbedtls_ssl_conf_dtls_anti_replay( mbedtls_ssl_config *conf, char mode );
2307#endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
2308
2309#if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
2310/**
2311 * \brief Set a limit on the number of records with a bad MAC
2312 * before terminating the connection.
2313 * (DTLS only, no effect on TLS.)
2314 * Default: 0 (disabled).
2315 *
2316 * \param conf SSL configuration
2317 * \param limit Limit, or 0 to disable.
2318 *
2319 * \note If the limit is N, then the connection is terminated when
2320 * the Nth non-authentic record is seen.
2321 *
2322 * \note Records with an invalid header are not counted, only the
2323 * ones going through the authentication-decryption phase.
2324 *
2325 * \note This is a security trade-off related to the fact that it's
2326 * often relatively easy for an active attacker ot inject UDP
2327 * datagrams. On one hand, setting a low limit here makes it
2328 * easier for such an attacker to forcibly terminated a
2329 * connection. On the other hand, a high limit or no limit
2330 * might make us waste resources checking authentication on
2331 * many bogus packets.
2332 */
2333void mbedtls_ssl_conf_dtls_badmac_limit( mbedtls_ssl_config *conf, unsigned limit );
2334#endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
2335
2336#if defined(MBEDTLS_SSL_PROTO_DTLS)
2337
2338/**
2339 * \brief Allow or disallow packing of multiple handshake records
2340 * within a single datagram.
2341 *
2342 * \param ssl The SSL context to configure.
2343 * \param allow_packing This determines whether datagram packing may
2344 * be used or not. A value of \c 0 means that every
2345 * record will be sent in a separate datagram; a
2346 * value of \c 1 means that, if space permits,
2347 * multiple handshake messages (including CCS) belonging to
2348 * a single flight may be packed within a single datagram.
2349 *
2350 * \note This is enabled by default and should only be disabled
2351 * for test purposes, or if datagram packing causes
2352 * interoperability issues with peers that don't support it.
2353 *
2354 * \note Allowing datagram packing reduces the network load since
2355 * there's less overhead if multiple messages share the same
2356 * datagram. Also, it increases the handshake efficiency
2357 * since messages belonging to a single datagram will not
2358 * be reordered in transit, and so future message buffering
2359 * or flight retransmission (if no buffering is used) as
2360 * means to deal with reordering are needed less frequently.
2361 *
2362 * \note Application records are not affected by this option and
2363 * are currently always sent in separate datagrams.
2364 *
2365 */
2366void mbedtls_ssl_set_datagram_packing( mbedtls_ssl_context *ssl,
2367 unsigned allow_packing );
2368
2369/**
2370 * \brief Set retransmit timeout values for the DTLS handshake.
2371 * (DTLS only, no effect on TLS.)
2372 *
2373 * \param conf SSL configuration
2374 * \param min Initial timeout value in milliseconds.
2375 * Default: 1000 (1 second).
2376 * \param max Maximum timeout value in milliseconds.
2377 * Default: 60000 (60 seconds).
2378 *
2379 * \note Default values are from RFC 6347 section 4.2.4.1.
2380 *
2381 * \note The 'min' value should typically be slightly above the
2382 * expected round-trip time to your peer, plus whatever time
2383 * it takes for the peer to process the message. For example,
2384 * if your RTT is about 600ms and you peer needs up to 1s to
2385 * do the cryptographic operations in the handshake, then you
2386 * should set 'min' slightly above 1600. Lower values of 'min'
2387 * might cause spurious resends which waste network resources,
2388 * while larger value of 'min' will increase overall latency
2389 * on unreliable network links.
2390 *
2391 * \note The more unreliable your network connection is, the larger
2392 * your max / min ratio needs to be in order to achieve
2393 * reliable handshakes.
2394 *
2395 * \note Messages are retransmitted up to log2(ceil(max/min)) times.
2396 * For example, if min = 1s and max = 5s, the retransmit plan
2397 * goes: send ... 1s -> resend ... 2s -> resend ... 4s ->
2398 * resend ... 5s -> give up and return a timeout error.
2399 */
2400void mbedtls_ssl_conf_handshake_timeout( mbedtls_ssl_config *conf, uint32_t min, uint32_t max );
2401#endif /* MBEDTLS_SSL_PROTO_DTLS */
2402
2403#if defined(MBEDTLS_SSL_SRV_C)
2404/**
2405 * \brief Set the session cache callbacks (server-side only)
2406 * If not set, no session resuming is done (except if session
2407 * tickets are enabled too).
2408 *
2409 * The session cache has the responsibility to check for stale
2410 * entries based on timeout. See RFC 5246 for recommendations.
2411 *
2412 * Warning: session.peer_cert is cleared by the SSL/TLS layer on
2413 * connection shutdown, so do not cache the pointer! Either set
2414 * it to NULL or make a full copy of the certificate.
2415 *
2416 * The get callback is called once during the initial handshake
2417 * to enable session resuming. The get function has the
2418 * following parameters: (void *parameter, mbedtls_ssl_session *session)
2419 * If a valid entry is found, it should fill the master of
2420 * the session object with the cached values and return 0,
2421 * return 1 otherwise. Optionally peer_cert can be set as well
2422 * if it is properly present in cache entry.
2423 *
2424 * The set callback is called once during the initial handshake
2425 * to enable session resuming after the entire handshake has
2426 * been finished. The set function has the following parameters:
2427 * (void *parameter, const mbedtls_ssl_session *session). The function
2428 * should create a cache entry for future retrieval based on
2429 * the data in the session structure and should keep in mind
2430 * that the mbedtls_ssl_session object presented (and all its referenced
2431 * data) is cleared by the SSL/TLS layer when the connection is
2432 * terminated. It is recommended to add metadata to determine if
2433 * an entry is still valid in the future. Return 0 if
2434 * successfully cached, return 1 otherwise.
2435 *
2436 * \param conf SSL configuration
2437 * \param p_cache parmater (context) for both callbacks
2438 * \param f_get_cache session get callback
2439 * \param f_set_cache session set callback
2440 */
2441void mbedtls_ssl_conf_session_cache( mbedtls_ssl_config *conf,
2442 void *p_cache,
2443 int (*f_get_cache)(void *, mbedtls_ssl_session *),
2444 int (*f_set_cache)(void *, const mbedtls_ssl_session *) );
2445#endif /* MBEDTLS_SSL_SRV_C */
2446
2447#if defined(MBEDTLS_SSL_CLI_C)
2448/**
2449 * \brief Request resumption of session (client-side only)
2450 * Session data is copied from presented session structure.
2451 *
2452 * \param ssl SSL context
2453 * \param session session context
2454 *
2455 * \return 0 if successful,
2456 * MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed,
2457 * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used server-side or
2458 * arguments are otherwise invalid
2459 *
2460 * \sa mbedtls_ssl_get_session()
2461 */
2462int mbedtls_ssl_set_session( mbedtls_ssl_context *ssl, const mbedtls_ssl_session *session );
2463#endif /* MBEDTLS_SSL_CLI_C */
2464
2465/**
2466 * \brief Load serialized session data into a session structure.
2467 * On client, this can be used for loading saved sessions
2468 * before resuming them with mbedstls_ssl_set_session().
2469 * On server, this can be used for alternative implementations
2470 * of session cache or session tickets.
2471 *
2472 * \warning If a peer certificate chain is associated with the session,
2473 * the serialized state will only contain the peer's
2474 * end-entity certificate and the result of the chain
2475 * verification (unless verification was disabled), but not
2476 * the rest of the chain.
2477 *
2478 * \see mbedtls_ssl_session_save()
2479 * \see mbedtls_ssl_set_session()
2480 *
2481 * \param session The session structure to be populated. It must have been
2482 * initialised with mbedtls_ssl_session_init() but not
2483 * populated yet.
2484 * \param buf The buffer holding the serialized session data. It must be a
2485 * readable buffer of at least \p len bytes.
2486 * \param len The size of the serialized data in bytes.
2487 *
2488 * \return \c 0 if successful.
2489 * \return #MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed.
2490 * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if input data is invalid.
2491 * \return #MBEDTLS_ERR_SSL_VERSION_MISMATCH if the serialized data
2492 * was generated in a different version or configuration of
2493 * Mbed TLS.
2494 * \return Another negative value for other kinds of errors (for
2495 * example, unsupported features in the embedded certificate).
2496 */
2498 const unsigned char *buf,
2499 size_t len );
2500
2501/**
2502 * \brief Save session structure as serialized data in a buffer.
2503 * On client, this can be used for saving session data,
2504 * potentially in non-volatile storage, for resuming later.
2505 * On server, this can be used for alternative implementations
2506 * of session cache or session tickets.
2507 *
2508 * \see mbedtls_ssl_session_load()
2509 * \see mbedtls_ssl_get_session_pointer()
2510 *
2511 * \param session The session structure to be saved.
2512 * \param buf The buffer to write the serialized data to. It must be a
2513 * writeable buffer of at least \p len bytes, or may be \c
2514 * NULL if \p len is \c 0.
2515 * \param buf_len The number of bytes available for writing in \p buf.
2516 * \param olen The size in bytes of the data that has been or would have
2517 * been written. It must point to a valid \c size_t.
2518 *
2519 * \note \p olen is updated to the correct value regardless of
2520 * whether \p buf_len was large enough. This makes it possible
2521 * to determine the necessary size by calling this function
2522 * with \p buf set to \c NULL and \p buf_len to \c 0.
2523 *
2524 * \return \c 0 if successful.
2525 * \return #MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL if \p buf is too small.
2526 */
2528 unsigned char *buf,
2529 size_t buf_len,
2530 size_t *olen );
2531
2532/**
2533 * \brief Get a pointer to the current session structure, for example
2534 * to serialize it.
2535 *
2536 * \warning Ownership of the session remains with the SSL context, and
2537 * the returned pointer is only guaranteed to be valid until
2538 * the next API call operating on the same \p ssl context.
2539 *
2540 * \see mbedtls_ssl_session_save()
2541 *
2542 * \param ssl The SSL context.
2543 *
2544 * \return A pointer to the current session if successful.
2545 * \return \c NULL if no session is active.
2546 */
2548
2549/**
2550 * \brief Set the list of allowed ciphersuites and the preference
2551 * order. First in the list has the highest preference.
2552 * (Overrides all version-specific lists)
2553 *
2554 * The ciphersuites array is not copied, and must remain
2555 * valid for the lifetime of the ssl_config.
2556 *
2557 * Note: The server uses its own preferences
2558 * over the preference of the client unless
2559 * MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE is defined!
2560 *
2561 * \param conf SSL configuration
2562 * \param ciphersuites 0-terminated list of allowed ciphersuites
2563 */
2565 const int *ciphersuites );
2566
2567#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
2568#define MBEDTLS_SSL_UNEXPECTED_CID_IGNORE 0
2569#define MBEDTLS_SSL_UNEXPECTED_CID_FAIL 1
2570/**
2571 * \brief Specify the length of Connection IDs for incoming
2572 * encrypted DTLS records, as well as the behaviour
2573 * on unexpected CIDs.
2574 *
2575 * By default, the CID length is set to \c 0,
2576 * and unexpected CIDs are silently ignored.
2577 *
2578 * \param conf The SSL configuration to modify.
2579 * \param len The length in Bytes of the CID fields in encrypted
2580 * DTLS records using the CID mechanism. This must
2581 * not be larger than #MBEDTLS_SSL_CID_OUT_LEN_MAX.
2582 * \param ignore_other_cids This determines the stack's behaviour when
2583 * receiving a record with an unexpected CID.
2584 * Possible values are:
2585 * - #MBEDTLS_SSL_UNEXPECTED_CID_IGNORE
2586 * In this case, the record is silently ignored.
2587 * - #MBEDTLS_SSL_UNEXPECTED_CID_FAIL
2588 * In this case, the stack fails with the specific
2589 * error code #MBEDTLS_ERR_SSL_UNEXPECTED_CID.
2590 *
2591 * \note The CID specification allows implementations to either
2592 * use a common length for all incoming connection IDs or
2593 * allow variable-length incoming IDs. Mbed TLS currently
2594 * requires a common length for all connections sharing the
2595 * same SSL configuration; this allows simpler parsing of
2596 * record headers.
2597 *
2598 * \return \c 0 on success.
2599 * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if \p own_cid_len
2600 * is too large.
2601 */
2602int mbedtls_ssl_conf_cid( mbedtls_ssl_config *conf, size_t len,
2603 int ignore_other_cids );
2604#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
2605
2606/**
2607 * \brief Set the list of allowed ciphersuites and the
2608 * preference order for a specific version of the protocol.
2609 * (Only useful on the server side)
2610 *
2611 * The ciphersuites array is not copied, and must remain
2612 * valid for the lifetime of the ssl_config.
2613 *
2614 * \param conf SSL configuration
2615 * \param ciphersuites 0-terminated list of allowed ciphersuites
2616 * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3
2617 * supported)
2618 * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
2619 * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
2620 * MBEDTLS_SSL_MINOR_VERSION_3 supported)
2621 *
2622 * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0
2623 * and MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
2624 */
2626 const int *ciphersuites,
2627 int major, int minor );
2628
2629#if defined(MBEDTLS_X509_CRT_PARSE_C)
2630/**
2631 * \brief Set the X.509 security profile used for verification
2632 *
2633 * \note The restrictions are enforced for all certificates in the
2634 * chain. However, signatures in the handshake are not covered
2635 * by this setting but by \b mbedtls_ssl_conf_sig_hashes().
2636 *
2637 * \param conf SSL configuration
2638 * \param profile Profile to use
2639 */
2640void mbedtls_ssl_conf_cert_profile( mbedtls_ssl_config *conf,
2641 const mbedtls_x509_crt_profile *profile );
2642
2643/**
2644 * \brief Set the data required to verify peer certificate
2645 *
2646 * \note See \c mbedtls_x509_crt_verify() for notes regarding the
2647 * parameters ca_chain (maps to trust_ca for that function)
2648 * and ca_crl.
2649 *
2650 * \param conf SSL configuration
2651 * \param ca_chain trusted CA chain (meaning all fully trusted top-level CAs)
2652 * \param ca_crl trusted CA CRLs
2653 */
2654void mbedtls_ssl_conf_ca_chain( mbedtls_ssl_config *conf,
2655 mbedtls_x509_crt *ca_chain,
2656 mbedtls_x509_crl *ca_crl );
2657
2658#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK)
2659/**
2660 * \brief Set the trusted certificate callback.
2661 *
2662 * This API allows to register the set of trusted certificates
2663 * through a callback, instead of a linked list as configured
2664 * by mbedtls_ssl_conf_ca_chain().
2665 *
2666 * This is useful for example in contexts where a large number
2667 * of CAs are used, and the inefficiency of maintaining them
2668 * in a linked list cannot be tolerated. It is also useful when
2669 * the set of trusted CAs needs to be modified frequently.
2670 *
2671 * See the documentation of `mbedtls_x509_crt_ca_cb_t` for
2672 * more information.
2673 *
2674 * \param conf The SSL configuration to register the callback with.
2675 * \param f_ca_cb The trusted certificate callback to use when verifying
2676 * certificate chains.
2677 * \param p_ca_cb The context to be passed to \p f_ca_cb (for example,
2678 * a reference to a trusted CA database).
2679 *
2680 * \note This API is incompatible with mbedtls_ssl_conf_ca_chain():
2681 * Any call to this function overwrites the values set through
2682 * earlier calls to mbedtls_ssl_conf_ca_chain() or
2683 * mbedtls_ssl_conf_ca_cb().
2684 *
2685 * \note This API is incompatible with CA indication in
2686 * CertificateRequest messages: A server-side SSL context which
2687 * is bound to an SSL configuration that uses a CA callback
2688 * configured via mbedtls_ssl_conf_ca_cb(), and which requires
2689 * client authentication, will send an empty CA list in the
2690 * corresponding CertificateRequest message.
2691 *
2692 * \note This API is incompatible with mbedtls_ssl_set_hs_ca_chain():
2693 * If an SSL context is bound to an SSL configuration which uses
2694 * CA callbacks configured via mbedtls_ssl_conf_ca_cb(), then
2695 * calls to mbedtls_ssl_set_hs_ca_chain() have no effect.
2696 *
2697 * \note The use of this API disables the use of restartable ECC
2698 * during X.509 CRT signature verification (but doesn't affect
2699 * other uses).
2700 *
2701 * \warning This API is incompatible with the use of CRLs. Any call to
2702 * mbedtls_ssl_conf_ca_cb() unsets CRLs configured through
2703 * earlier calls to mbedtls_ssl_conf_ca_chain().
2704 *
2705 * \warning In multi-threaded environments, the callback \p f_ca_cb
2706 * must be thread-safe, and it is the user's responsibility
2707 * to guarantee this (for example through a mutex
2708 * contained in the callback context pointed to by \p p_ca_cb).
2709 */
2710void mbedtls_ssl_conf_ca_cb( mbedtls_ssl_config *conf,
2711 mbedtls_x509_crt_ca_cb_t f_ca_cb,
2712 void *p_ca_cb );
2713#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */
2714
2715/**
2716 * \brief Set own certificate chain and private key
2717 *
2718 * \note own_cert should contain in order from the bottom up your
2719 * certificate chain. The top certificate (self-signed)
2720 * can be omitted.
2721 *
2722 * \note On server, this function can be called multiple times to
2723 * provision more than one cert/key pair (eg one ECDSA, one
2724 * RSA with SHA-256, one RSA with SHA-1). An adequate
2725 * certificate will be selected according to the client's
2726 * advertised capabilities. In case multiple certificates are
2727 * adequate, preference is given to the one set by the first
2728 * call to this function, then second, etc.
2729 *
2730 * \note On client, only the first call has any effect. That is,
2731 * only one client certificate can be provisioned. The
2732 * server's preferences in its CertficateRequest message will
2733 * be ignored and our only cert will be sent regardless of
2734 * whether it matches those preferences - the server can then
2735 * decide what it wants to do with it.
2736 *
2737 * \note The provided \p pk_key needs to match the public key in the
2738 * first certificate in \p own_cert, or all handshakes using
2739 * that certificate will fail. It is your responsibility
2740 * to ensure that; this function will not perform any check.
2741 * You may use mbedtls_pk_check_pair() in order to perform
2742 * this check yourself, but be aware that this function can
2743 * be computationally expensive on some key types.
2744 *
2745 * \param conf SSL configuration
2746 * \param own_cert own public certificate chain
2747 * \param pk_key own private key
2748 *
2749 * \return 0 on success or MBEDTLS_ERR_SSL_ALLOC_FAILED
2750 */
2751int mbedtls_ssl_conf_own_cert( mbedtls_ssl_config *conf,
2752 mbedtls_x509_crt *own_cert,
2753 mbedtls_pk_context *pk_key );
2754#endif /* MBEDTLS_X509_CRT_PARSE_C */
2755
2756#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
2757/**
2758 * \brief Configure a pre-shared key (PSK) and identity
2759 * to be used in PSK-based ciphersuites.
2760 *
2761 * \note This is mainly useful for clients. Servers will usually
2762 * want to use \c mbedtls_ssl_conf_psk_cb() instead.
2763 *
2764 * \note A PSK set by \c mbedtls_ssl_set_hs_psk() in the PSK callback
2765 * takes precedence over a PSK configured by this function.
2766 *
2767 * \warning Currently, clients can only register a single pre-shared key.
2768 * Calling this function or mbedtls_ssl_conf_psk_opaque() more
2769 * than once will overwrite values configured in previous calls.
2770 * Support for setting multiple PSKs on clients and selecting
2771 * one based on the identity hint is not a planned feature,
2772 * but feedback is welcomed.
2773 *
2774 * \param conf The SSL configuration to register the PSK with.
2775 * \param psk The pointer to the pre-shared key to use.
2776 * \param psk_len The length of the pre-shared key in bytes.
2777 * \param psk_identity The pointer to the pre-shared key identity.
2778 * \param psk_identity_len The length of the pre-shared key identity
2779 * in bytes.
2780 *
2781 * \note The PSK and its identity are copied internally and
2782 * hence need not be preserved by the caller for the lifetime
2783 * of the SSL configuration.
2784 *
2785 * \return \c 0 if successful.
2786 * \return An \c MBEDTLS_ERR_SSL_XXX error code on failure.
2787 */
2788int mbedtls_ssl_conf_psk( mbedtls_ssl_config *conf,
2789 const unsigned char *psk, size_t psk_len,
2790 const unsigned char *psk_identity, size_t psk_identity_len );
2791
2792#if defined(MBEDTLS_USE_PSA_CRYPTO)
2793/**
2794 * \brief Configure an opaque pre-shared key (PSK) and identity
2795 * to be used in PSK-based ciphersuites.
2796 *
2797 * \note This is mainly useful for clients. Servers will usually
2798 * want to use \c mbedtls_ssl_conf_psk_cb() instead.
2799 *
2800 * \note An opaque PSK set by \c mbedtls_ssl_set_hs_psk_opaque() in
2801 * the PSK callback takes precedence over an opaque PSK
2802 * configured by this function.
2803 *
2804 * \warning Currently, clients can only register a single pre-shared key.
2805 * Calling this function or mbedtls_ssl_conf_psk() more than
2806 * once will overwrite values configured in previous calls.
2807 * Support for setting multiple PSKs on clients and selecting
2808 * one based on the identity hint is not a planned feature,
2809 * but feedback is welcomed.
2810 *
2811 * \param conf The SSL configuration to register the PSK with.
2812 * \param psk The identifier of the key slot holding the PSK.
2813 * Until \p conf is destroyed or this function is successfully
2814 * called again, the key slot \p psk must be populated with a
2815 * key of type PSA_ALG_CATEGORY_KEY_DERIVATION whose policy
2816 * allows its use for the key derivation algorithm applied
2817 * in the handshake.
2818 * \param psk_identity The pointer to the pre-shared key identity.
2819 * \param psk_identity_len The length of the pre-shared key identity
2820 * in bytes.
2821 *
2822 * \note The PSK identity hint is copied internally and hence need
2823 * not be preserved by the caller for the lifetime of the
2824 * SSL configuration.
2825 *
2826 * \return \c 0 if successful.
2827 * \return An \c MBEDTLS_ERR_SSL_XXX error code on failure.
2828 */
2829int mbedtls_ssl_conf_psk_opaque( mbedtls_ssl_config *conf,
2830 psa_key_id_t psk,
2831 const unsigned char *psk_identity,
2832 size_t psk_identity_len );
2833#endif /* MBEDTLS_USE_PSA_CRYPTO */
2834
2835/**
2836 * \brief Set the pre-shared Key (PSK) for the current handshake.
2837 *
2838 * \note This should only be called inside the PSK callback,
2839 * i.e. the function passed to \c mbedtls_ssl_conf_psk_cb().
2840 *
2841 * \note A PSK set by this function takes precedence over a PSK
2842 * configured by \c mbedtls_ssl_conf_psk().
2843 *
2844 * \param ssl The SSL context to configure a PSK for.
2845 * \param psk The pointer to the pre-shared key.
2846 * \param psk_len The length of the pre-shared key in bytes.
2847 *
2848 * \return \c 0 if successful.
2849 * \return An \c MBEDTLS_ERR_SSL_XXX error code on failure.
2850 */
2851int mbedtls_ssl_set_hs_psk( mbedtls_ssl_context *ssl,
2852 const unsigned char *psk, size_t psk_len );
2853
2854#if defined(MBEDTLS_USE_PSA_CRYPTO)
2855/**
2856 * \brief Set an opaque pre-shared Key (PSK) for the current handshake.
2857 *
2858 * \note This should only be called inside the PSK callback,
2859 * i.e. the function passed to \c mbedtls_ssl_conf_psk_cb().
2860 *
2861 * \note An opaque PSK set by this function takes precedence over an
2862 * opaque PSK configured by \c mbedtls_ssl_conf_psk_opaque().
2863 *
2864 * \param ssl The SSL context to configure a PSK for.
2865 * \param psk The identifier of the key slot holding the PSK.
2866 * For the duration of the current handshake, the key slot
2867 * must be populated with a key of type
2868 * PSA_ALG_CATEGORY_KEY_DERIVATION whose policy allows its
2869 * use for the key derivation algorithm
2870 * applied in the handshake.
2871 *
2872 * \return \c 0 if successful.
2873 * \return An \c MBEDTLS_ERR_SSL_XXX error code on failure.
2874 */
2875int mbedtls_ssl_set_hs_psk_opaque( mbedtls_ssl_context *ssl,
2876 psa_key_id_t psk );
2877#endif /* MBEDTLS_USE_PSA_CRYPTO */
2878
2879/**
2880 * \brief Set the PSK callback (server-side only).
2881 *
2882 * If set, the PSK callback is called for each
2883 * handshake where a PSK-based ciphersuite was negotiated.
2884 * The caller provides the identity received and wants to
2885 * receive the actual PSK data and length.
2886 *
2887 * The callback has the following parameters:
2888 * - \c void*: The opaque pointer \p p_psk.
2889 * - \c mbedtls_ssl_context*: The SSL context to which
2890 * the operation applies.
2891 * - \c const unsigned char*: The PSK identity
2892 * selected by the client.
2893 * - \c size_t: The length of the PSK identity
2894 * selected by the client.
2895 *
2896 * If a valid PSK identity is found, the callback should use
2897 * \c mbedtls_ssl_set_hs_psk() or
2898 * \c mbedtls_ssl_set_hs_psk_opaque()
2899 * on the SSL context to set the correct PSK and return \c 0.
2900 * Any other return value will result in a denied PSK identity.
2901 *
2902 * \note A dynamic PSK (i.e. set by the PSK callback) takes
2903 * precedence over a static PSK (i.e. set by
2904 * \c mbedtls_ssl_conf_psk() or
2905 * \c mbedtls_ssl_conf_psk_opaque()).
2906 * This means that if you set a PSK callback using this
2907 * function, you don't need to set a PSK using
2908 * \c mbedtls_ssl_conf_psk() or
2909 * \c mbedtls_ssl_conf_psk_opaque()).
2910 *
2911 * \param conf The SSL configuration to register the callback with.
2912 * \param f_psk The callback for selecting and setting the PSK based
2913 * in the PSK identity chosen by the client.
2914 * \param p_psk A pointer to an opaque structure to be passed to
2915 * the callback, for example a PSK store.
2916 */
2917void mbedtls_ssl_conf_psk_cb( mbedtls_ssl_config *conf,
2918 int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *,
2919 size_t),
2920 void *p_psk );
2921#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
2922
2923#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C)
2924
2925#if !defined(MBEDTLS_DEPRECATED_REMOVED)
2926
2927#if defined(MBEDTLS_DEPRECATED_WARNING)
2928#define MBEDTLS_DEPRECATED __attribute__((deprecated))
2929#else
2930#define MBEDTLS_DEPRECATED
2931#endif
2932
2933/**
2934 * \brief Set the Diffie-Hellman public P and G values,
2935 * read as hexadecimal strings (server-side only)
2936 * (Default values: MBEDTLS_DHM_RFC3526_MODP_2048_[PG])
2937 *
2938 * \param conf SSL configuration
2939 * \param dhm_P Diffie-Hellman-Merkle modulus
2940 * \param dhm_G Diffie-Hellman-Merkle generator
2941 *
2942 * \deprecated Superseded by \c mbedtls_ssl_conf_dh_param_bin.
2943 *
2944 * \return 0 if successful
2945 */
2946MBEDTLS_DEPRECATED int mbedtls_ssl_conf_dh_param( mbedtls_ssl_config *conf,
2947 const char *dhm_P,
2948 const char *dhm_G );
2949
2950#endif /* MBEDTLS_DEPRECATED_REMOVED */
2951
2952/**
2953 * \brief Set the Diffie-Hellman public P and G values
2954 * from big-endian binary presentations.
2955 * (Default values: MBEDTLS_DHM_RFC3526_MODP_2048_[PG]_BIN)
2956 *
2957 * \param conf SSL configuration
2958 * \param dhm_P Diffie-Hellman-Merkle modulus in big-endian binary form
2959 * \param P_len Length of DHM modulus
2960 * \param dhm_G Diffie-Hellman-Merkle generator in big-endian binary form
2961 * \param G_len Length of DHM generator
2962 *
2963 * \return 0 if successful
2964 */
2965int mbedtls_ssl_conf_dh_param_bin( mbedtls_ssl_config *conf,
2966 const unsigned char *dhm_P, size_t P_len,
2967 const unsigned char *dhm_G, size_t G_len );
2968
2969/**
2970 * \brief Set the Diffie-Hellman public P and G values,
2971 * read from existing context (server-side only)
2972 *
2973 * \param conf SSL configuration
2974 * \param dhm_ctx Diffie-Hellman-Merkle context
2975 *
2976 * \return 0 if successful
2977 */
2978int mbedtls_ssl_conf_dh_param_ctx( mbedtls_ssl_config *conf, mbedtls_dhm_context *dhm_ctx );
2979#endif /* MBEDTLS_DHM_C && defined(MBEDTLS_SSL_SRV_C) */
2980
2981#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
2982/**
2983 * \brief Set the minimum length for Diffie-Hellman parameters.
2984 * (Client-side only.)
2985 * (Default: 1024 bits.)
2986 *
2987 * \param conf SSL configuration
2988 * \param bitlen Minimum bit length of the DHM prime
2989 */
2990void mbedtls_ssl_conf_dhm_min_bitlen( mbedtls_ssl_config *conf,
2991 unsigned int bitlen );
2992#endif /* MBEDTLS_DHM_C && MBEDTLS_SSL_CLI_C */
2993
2994#if defined(MBEDTLS_ECP_C)
2995/**
2996 * \brief Set the allowed curves in order of preference.
2997 * (Default: all defined curves.)
2998 *
2999 * On server: this only affects selection of the ECDHE curve;
3000 * the curves used for ECDH and ECDSA are determined by the
3001 * list of available certificates instead.
3002 *
3003 * On client: this affects the list of curves offered for any
3004 * use. The server can override our preference order.
3005 *
3006 * Both sides: limits the set of curves accepted for use in
3007 * ECDHE and in the peer's end-entity certificate.
3008 *
3009 * \note This has no influence on which curves are allowed inside the
3010 * certificate chains, see \c mbedtls_ssl_conf_cert_profile()
3011 * for that. For the end-entity certificate however, the key
3012 * will be accepted only if it is allowed both by this list
3013 * and by the cert profile.
3014 *
3015 * \note This list should be ordered by decreasing preference
3016 * (preferred curve first).
3017 *
3018 * \param conf SSL configuration
3019 * \param curves Ordered list of allowed curves,
3020 * terminated by MBEDTLS_ECP_DP_NONE.
3021 */
3022void mbedtls_ssl_conf_curves( mbedtls_ssl_config *conf,
3023 const mbedtls_ecp_group_id *curves );
3024#endif /* MBEDTLS_ECP_C */
3025
3026#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
3027/**
3028 * \brief Set the allowed hashes for signatures during the handshake.
3029 * (Default: all available hashes except MD5.)
3030 *
3031 * \note This only affects which hashes are offered and can be used
3032 * for signatures during the handshake. Hashes for message
3033 * authentication and the TLS PRF are controlled by the
3034 * ciphersuite, see \c mbedtls_ssl_conf_ciphersuites(). Hashes
3035 * used for certificate signature are controlled by the
3036 * verification profile, see \c mbedtls_ssl_conf_cert_profile().
3037 *
3038 * \note This list should be ordered by decreasing preference
3039 * (preferred hash first).
3040 *
3041 * \param conf SSL configuration
3042 * \param hashes Ordered list of allowed signature hashes,
3043 * terminated by \c MBEDTLS_MD_NONE.
3044 */
3045void mbedtls_ssl_conf_sig_hashes( mbedtls_ssl_config *conf,
3046 const int *hashes );
3047#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
3048
3049#if defined(MBEDTLS_X509_CRT_PARSE_C)
3050/**
3051 * \brief Set or reset the hostname to check against the received
3052 * server certificate. It sets the ServerName TLS extension,
3053 * too, if that extension is enabled. (client-side only)
3054 *
3055 * \param ssl SSL context
3056 * \param hostname the server hostname, may be NULL to clear hostname
3057
3058 * \note Maximum hostname length MBEDTLS_SSL_MAX_HOST_NAME_LEN.
3059 *
3060 * \return 0 if successful, MBEDTLS_ERR_SSL_ALLOC_FAILED on
3061 * allocation failure, MBEDTLS_ERR_SSL_BAD_INPUT_DATA on
3062 * too long input hostname.
3063 *
3064 * Hostname set to the one provided on success (cleared
3065 * when NULL). On allocation failure hostname is cleared.
3066 * On too long input failure, old hostname is unchanged.
3067 */
3068int mbedtls_ssl_set_hostname( mbedtls_ssl_context *ssl, const char *hostname );
3069#endif /* MBEDTLS_X509_CRT_PARSE_C */
3070
3071#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
3072/**
3073 * \brief Set own certificate and key for the current handshake
3074 *
3075 * \note Same as \c mbedtls_ssl_conf_own_cert() but for use within
3076 * the SNI callback.
3077 *
3078 * \param ssl SSL context
3079 * \param own_cert own public certificate chain
3080 * \param pk_key own private key
3081 *
3082 * \return 0 on success or MBEDTLS_ERR_SSL_ALLOC_FAILED
3083 */
3084int mbedtls_ssl_set_hs_own_cert( mbedtls_ssl_context *ssl,
3085 mbedtls_x509_crt *own_cert,
3086 mbedtls_pk_context *pk_key );
3087
3088/**
3089 * \brief Set the data required to verify peer certificate for the
3090 * current handshake
3091 *
3092 * \note Same as \c mbedtls_ssl_conf_ca_chain() but for use within
3093 * the SNI callback.
3094 *
3095 * \param ssl SSL context
3096 * \param ca_chain trusted CA chain (meaning all fully trusted top-level CAs)
3097 * \param ca_crl trusted CA CRLs
3098 */
3099void mbedtls_ssl_set_hs_ca_chain( mbedtls_ssl_context *ssl,
3100 mbedtls_x509_crt *ca_chain,
3101 mbedtls_x509_crl *ca_crl );
3102
3103/**
3104 * \brief Set authmode for the current handshake.
3105 *
3106 * \note Same as \c mbedtls_ssl_conf_authmode() but for use within
3107 * the SNI callback.
3108 *
3109 * \param ssl SSL context
3110 * \param authmode MBEDTLS_SSL_VERIFY_NONE, MBEDTLS_SSL_VERIFY_OPTIONAL or
3111 * MBEDTLS_SSL_VERIFY_REQUIRED
3112 */
3113void mbedtls_ssl_set_hs_authmode( mbedtls_ssl_context *ssl,
3114 int authmode );
3115
3116/**
3117 * \brief Set server side ServerName TLS extension callback
3118 * (optional, server-side only).
3119 *
3120 * If set, the ServerName callback is called whenever the
3121 * server receives a ServerName TLS extension from the client
3122 * during a handshake. The ServerName callback has the
3123 * following parameters: (void *parameter, mbedtls_ssl_context *ssl,
3124 * const unsigned char *hostname, size_t len). If a suitable
3125 * certificate is found, the callback must set the
3126 * certificate(s) and key(s) to use with \c
3127 * mbedtls_ssl_set_hs_own_cert() (can be called repeatedly),
3128 * and may optionally adjust the CA and associated CRL with \c
3129 * mbedtls_ssl_set_hs_ca_chain() as well as the client
3130 * authentication mode with \c mbedtls_ssl_set_hs_authmode(),
3131 * then must return 0. If no matching name is found, the
3132 * callback must either set a default cert, or
3133 * return non-zero to abort the handshake at this point.
3134 *
3135 * \param conf SSL configuration
3136 * \param f_sni verification function
3137 * \param p_sni verification parameter
3138 */
3139void mbedtls_ssl_conf_sni( mbedtls_ssl_config *conf,
3140 int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *,
3141 size_t),
3142 void *p_sni );
3143#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
3144
3145#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
3146/**
3147 * \brief Set the EC J-PAKE password for current handshake.
3148 *
3149 * \note An internal copy is made, and destroyed as soon as the
3150 * handshake is completed, or when the SSL context is reset or
3151 * freed.
3152 *
3153 * \note The SSL context needs to be already set up. The right place
3154 * to call this function is between \c mbedtls_ssl_setup() or
3155 * \c mbedtls_ssl_reset() and \c mbedtls_ssl_handshake().
3156 *
3157 * \param ssl SSL context
3158 * \param pw EC J-PAKE password (pre-shared secret)
3159 * \param pw_len length of pw in bytes
3160 *
3161 * \return 0 on success, or a negative error code.
3162 */
3163int mbedtls_ssl_set_hs_ecjpake_password( mbedtls_ssl_context *ssl,
3164 const unsigned char *pw,
3165 size_t pw_len );
3166#endif /*MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
3167
3168#if defined(MBEDTLS_SSL_ALPN)
3169/**
3170 * \brief Set the supported Application Layer Protocols.
3171 *
3172 * \param conf SSL configuration
3173 * \param protos Pointer to a NULL-terminated list of supported protocols,
3174 * in decreasing preference order. The pointer to the list is
3175 * recorded by the library for later reference as required, so
3176 * the lifetime of the table must be atleast as long as the
3177 * lifetime of the SSL configuration structure.
3178 *
3179 * \return 0 on success, or MBEDTLS_ERR_SSL_BAD_INPUT_DATA.
3180 */
3181int mbedtls_ssl_conf_alpn_protocols( mbedtls_ssl_config *conf, const char **protos );
3182
3183/**
3184 * \brief Get the name of the negotiated Application Layer Protocol.
3185 * This function should be called after the handshake is
3186 * completed.
3187 *
3188 * \param ssl SSL context
3189 *
3190 * \return Protcol name, or NULL if no protocol was negotiated.
3191 */
3192const char *mbedtls_ssl_get_alpn_protocol( const mbedtls_ssl_context *ssl );
3193#endif /* MBEDTLS_SSL_ALPN */
3194
3195#if defined(MBEDTLS_SSL_DTLS_SRTP)
3196#if defined(MBEDTLS_DEBUG_C)
3197static inline const char *mbedtls_ssl_get_srtp_profile_as_string( mbedtls_ssl_srtp_profile profile )
3198{
3199 switch( profile )
3200 {
3201 case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80:
3202 return( "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80" );
3203 case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32:
3204 return( "MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32" );
3205 case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80:
3206 return( "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80" );
3207 case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32:
3208 return( "MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32" );
3209 default: break;
3210 }
3211 return( "" );
3212}
3213#endif /* MBEDTLS_DEBUG_C */
3214/**
3215 * \brief Manage support for mki(master key id) value
3216 * in use_srtp extension.
3217 * MKI is an optional part of SRTP used for key management
3218 * and re-keying. See RFC3711 section 3.1 for details.
3219 * The default value is
3220 * #MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED.
3221 *
3222 * \param conf The SSL configuration to manage mki support.
3223 * \param support_mki_value Enable or disable mki usage. Values are
3224 * #MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED
3225 * or #MBEDTLS_SSL_DTLS_SRTP_MKI_SUPPORTED.
3226 */
3227void mbedtls_ssl_conf_srtp_mki_value_supported( mbedtls_ssl_config *conf,
3228 int support_mki_value );
3229
3230/**
3231 * \brief Set the supported DTLS-SRTP protection profiles.
3232 *
3233 * \param conf SSL configuration
3234 * \param profiles Pointer to a List of MBEDTLS_TLS_SRTP_UNSET terminated
3235 * supported protection profiles
3236 * in decreasing preference order.
3237 * The pointer to the list is recorded by the library
3238 * for later reference as required, so the lifetime
3239 * of the table must be at least as long as the lifetime
3240 * of the SSL configuration structure.
3241 * The list must not hold more than
3242 * MBEDTLS_TLS_SRTP_MAX_PROFILE_LIST_LENGTH elements
3243 * (excluding the terminating MBEDTLS_TLS_SRTP_UNSET).
3244 *
3245 * \return 0 on success
3246 * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA when the list of
3247 * protection profiles is incorrect.
3248 */
3249int mbedtls_ssl_conf_dtls_srtp_protection_profiles
3250 ( mbedtls_ssl_config *conf,
3251 const mbedtls_ssl_srtp_profile *profiles );
3252
3253/**
3254 * \brief Set the mki_value for the current DTLS-SRTP session.
3255 *
3256 * \param ssl SSL context to use.
3257 * \param mki_value The MKI value to set.
3258 * \param mki_len The length of the MKI value.
3259 *
3260 * \note This function is relevant on client side only.
3261 * The server discovers the mki value during handshake.
3262 * A mki value set on server side using this function
3263 * is ignored.
3264 *
3265 * \return 0 on success
3266 * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA
3267 * \return #MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE
3268 */
3269int mbedtls_ssl_dtls_srtp_set_mki_value( mbedtls_ssl_context *ssl,
3270 unsigned char *mki_value,
3271 uint16_t mki_len );
3272/**
3273 * \brief Get the negotiated DTLS-SRTP informations:
3274 * Protection profile and MKI value.
3275 *
3276 * \warning This function must be called after the handshake is
3277 * completed. The value returned by this function must
3278 * not be trusted or acted upon before the handshake completes.
3279 *
3280 * \param ssl The SSL context to query.
3281 * \param dtls_srtp_info The negotiated DTLS-SRTP informations:
3282 * - Protection profile in use.
3283 * A direct mapping of the iana defined value for protection
3284 * profile on an uint16_t.
3285 http://www.iana.org/assignments/srtp-protection/srtp-protection.xhtml
3286 * #MBEDTLS_TLS_SRTP_UNSET if the use of SRTP was not negotiated
3287 * or peer's Hello packet was not parsed yet.
3288 * - mki size and value( if size is > 0 ).
3289 */
3290void mbedtls_ssl_get_dtls_srtp_negotiation_result( const mbedtls_ssl_context *ssl,
3291 mbedtls_dtls_srtp_info *dtls_srtp_info );
3292#endif /* MBEDTLS_SSL_DTLS_SRTP */
3293
3294/**
3295 * \brief Set the maximum supported version sent from the client side
3296 * and/or accepted at the server side
3297 * (Default: MBEDTLS_SSL_MAX_MAJOR_VERSION, MBEDTLS_SSL_MAX_MINOR_VERSION)
3298 *
3299 * \note This ignores ciphersuites from higher versions.
3300 *
3301 * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0 and
3302 * MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
3303 *
3304 * \param conf SSL configuration
3305 * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported)
3306 * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
3307 * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
3308 * MBEDTLS_SSL_MINOR_VERSION_3 supported)
3309 */
3310void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int minor );
3311
3312/**
3313 * \brief Set the minimum accepted SSL/TLS protocol version
3314 * (Default: TLS 1.0)
3315 *
3316 * \note Input outside of the SSL_MAX_XXXXX_VERSION and
3317 * SSL_MIN_XXXXX_VERSION range is ignored.
3318 *
3319 * \note MBEDTLS_SSL_MINOR_VERSION_0 (SSL v3) should be avoided.
3320 *
3321 * \note With DTLS, use MBEDTLS_SSL_MINOR_VERSION_2 for DTLS 1.0 and
3322 * MBEDTLS_SSL_MINOR_VERSION_3 for DTLS 1.2
3323 *
3324 * \param conf SSL configuration
3325 * \param major Major version number (only MBEDTLS_SSL_MAJOR_VERSION_3 supported)
3326 * \param minor Minor version number (MBEDTLS_SSL_MINOR_VERSION_0,
3327 * MBEDTLS_SSL_MINOR_VERSION_1 and MBEDTLS_SSL_MINOR_VERSION_2,
3328 * MBEDTLS_SSL_MINOR_VERSION_3 supported)
3329 */
3330void mbedtls_ssl_conf_min_version( mbedtls_ssl_config *conf, int major, int minor );
3331
3332#if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
3333/**
3334 * \brief Set the fallback flag (client-side only).
3335 * (Default: MBEDTLS_SSL_IS_NOT_FALLBACK).
3336 *
3337 * \note Set to MBEDTLS_SSL_IS_FALLBACK when preparing a fallback
3338 * connection, that is a connection with max_version set to a
3339 * lower value than the value you're willing to use. Such
3340 * fallback connections are not recommended but are sometimes
3341 * necessary to interoperate with buggy (version-intolerant)
3342 * servers.
3343 *
3344 * \warning You should NOT set this to MBEDTLS_SSL_IS_FALLBACK for
3345 * non-fallback connections! This would appear to work for a
3346 * while, then cause failures when the server is upgraded to
3347 * support a newer TLS version.
3348 *
3349 * \param conf SSL configuration
3350 * \param fallback MBEDTLS_SSL_IS_NOT_FALLBACK or MBEDTLS_SSL_IS_FALLBACK
3351 */
3352void mbedtls_ssl_conf_fallback( mbedtls_ssl_config *conf, char fallback );
3353#endif /* MBEDTLS_SSL_FALLBACK_SCSV && MBEDTLS_SSL_CLI_C */
3354
3355#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
3356/**
3357 * \brief Enable or disable Encrypt-then-MAC
3358 * (Default: MBEDTLS_SSL_ETM_ENABLED)
3359 *
3360 * \note This should always be enabled, it is a security
3361 * improvement, and should not cause any interoperability
3362 * issue (used only if the peer supports it too).
3363 *
3364 * \param conf SSL configuration
3365 * \param etm MBEDTLS_SSL_ETM_ENABLED or MBEDTLS_SSL_ETM_DISABLED
3366 */
3367void mbedtls_ssl_conf_encrypt_then_mac( mbedtls_ssl_config *conf, char etm );
3368#endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
3369
3370#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
3371/**
3372 * \brief Enable or disable Extended Master Secret negotiation.
3373 * (Default: MBEDTLS_SSL_EXTENDED_MS_ENABLED)
3374 *
3375 * \note This should always be enabled, it is a security fix to the
3376 * protocol, and should not cause any interoperability issue
3377 * (used only if the peer supports it too).
3378 *
3379 * \param conf SSL configuration
3380 * \param ems MBEDTLS_SSL_EXTENDED_MS_ENABLED or MBEDTLS_SSL_EXTENDED_MS_DISABLED
3381 */
3382void mbedtls_ssl_conf_extended_master_secret( mbedtls_ssl_config *conf, char ems );
3383#endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */
3384
3385#if defined(MBEDTLS_ARC4_C)
3386/**
3387 * \brief Disable or enable support for RC4
3388 * (Default: MBEDTLS_SSL_ARC4_DISABLED)
3389 *
3390 * \warning Use of RC4 in DTLS/TLS has been prohibited by RFC 7465
3391 * for security reasons. Use at your own risk.
3392 *
3393 * \note This function is deprecated and will be removed in
3394 * a future version of the library.
3395 * RC4 is disabled by default at compile time and needs to be
3396 * actively enabled for use with legacy systems.
3397 *
3398 * \param conf SSL configuration
3399 * \param arc4 MBEDTLS_SSL_ARC4_ENABLED or MBEDTLS_SSL_ARC4_DISABLED
3400 */
3401void mbedtls_ssl_conf_arc4_support( mbedtls_ssl_config *conf, char arc4 );
3402#endif /* MBEDTLS_ARC4_C */
3403
3404#if defined(MBEDTLS_SSL_SRV_C)
3405/**
3406 * \brief Whether to send a list of acceptable CAs in
3407 * CertificateRequest messages.
3408 * (Default: do send)
3409 *
3410 * \param conf SSL configuration
3411 * \param cert_req_ca_list MBEDTLS_SSL_CERT_REQ_CA_LIST_ENABLED or
3412 * MBEDTLS_SSL_CERT_REQ_CA_LIST_DISABLED
3413 */
3414void mbedtls_ssl_conf_cert_req_ca_list( mbedtls_ssl_config *conf,
3415 char cert_req_ca_list );
3416#endif /* MBEDTLS_SSL_SRV_C */
3417
3418#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
3419/**
3420 * \brief Set the maximum fragment length to emit and/or negotiate.
3421 * (Typical: the smaller of #MBEDTLS_SSL_IN_CONTENT_LEN and
3422 * #MBEDTLS_SSL_OUT_CONTENT_LEN, usually `2^14` bytes)
3423 * (Server: set maximum fragment length to emit,
3424 * usually negotiated by the client during handshake)
3425 * (Client: set maximum fragment length to emit *and*
3426 * negotiate with the server during handshake)
3427 * (Default: #MBEDTLS_SSL_MAX_FRAG_LEN_NONE)
3428 *
3429 * \note On the client side, the maximum fragment length extension
3430 * *will not* be used, unless the maximum fragment length has
3431 * been set via this function to a value different than
3432 * #MBEDTLS_SSL_MAX_FRAG_LEN_NONE.
3433 *
3434 * \note With TLS, this currently only affects ApplicationData (sent
3435 * with \c mbedtls_ssl_read()), not handshake messages.
3436 * With DTLS, this affects both ApplicationData and handshake.
3437 *
3438 * \note This sets the maximum length for a record's payload,
3439 * excluding record overhead that will be added to it, see
3440 * \c mbedtls_ssl_get_record_expansion().
3441 *
3442 * \note For DTLS, it is also possible to set a limit for the total
3443 * size of daragrams passed to the transport layer, including
3444 * record overhead, see \c mbedtls_ssl_set_mtu().
3445 *
3446 * \param conf SSL configuration
3447 * \param mfl_code Code for maximum fragment length (allowed values:
3448 * MBEDTLS_SSL_MAX_FRAG_LEN_512, MBEDTLS_SSL_MAX_FRAG_LEN_1024,
3449 * MBEDTLS_SSL_MAX_FRAG_LEN_2048, MBEDTLS_SSL_MAX_FRAG_LEN_4096)
3450 *
3451 * \return 0 if successful or MBEDTLS_ERR_SSL_BAD_INPUT_DATA
3452 */
3453int mbedtls_ssl_conf_max_frag_len( mbedtls_ssl_config *conf, unsigned char mfl_code );
3454#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
3455
3456#if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
3457/**
3458 * \brief Activate negotiation of truncated HMAC
3459 * (Default: MBEDTLS_SSL_TRUNC_HMAC_DISABLED)
3460 *
3461 * \param conf SSL configuration
3462 * \param truncate Enable or disable (MBEDTLS_SSL_TRUNC_HMAC_ENABLED or
3463 * MBEDTLS_SSL_TRUNC_HMAC_DISABLED)
3464 */
3465void mbedtls_ssl_conf_truncated_hmac( mbedtls_ssl_config *conf, int truncate );
3466#endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
3467
3468#if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
3469/**
3470 * \brief Enable / Disable 1/n-1 record splitting
3471 * (Default: MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED)
3472 *
3473 * \note Only affects SSLv3 and TLS 1.0, not higher versions.
3474 * Does not affect non-CBC ciphersuites in any version.
3475 *
3476 * \param conf SSL configuration
3477 * \param split MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED or
3478 * MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED
3479 */
3480void mbedtls_ssl_conf_cbc_record_splitting( mbedtls_ssl_config *conf, char split );
3481#endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */
3482
3483#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
3484/**
3485 * \brief Enable / Disable session tickets (client only).
3486 * (Default: MBEDTLS_SSL_SESSION_TICKETS_ENABLED.)
3487 *
3488 * \note On server, use \c mbedtls_ssl_conf_session_tickets_cb().
3489 *
3490 * \param conf SSL configuration
3491 * \param use_tickets Enable or disable (MBEDTLS_SSL_SESSION_TICKETS_ENABLED or
3492 * MBEDTLS_SSL_SESSION_TICKETS_DISABLED)
3493 */
3494void mbedtls_ssl_conf_session_tickets( mbedtls_ssl_config *conf, int use_tickets );
3495#endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
3496
3497#if defined(MBEDTLS_SSL_RENEGOTIATION)
3498/**
3499 * \brief Enable / Disable renegotiation support for connection when
3500 * initiated by peer
3501 * (Default: MBEDTLS_SSL_RENEGOTIATION_DISABLED)
3502 *
3503 * \warning It is recommended to always disable renegotation unless you
3504 * know you need it and you know what you're doing. In the
3505 * past, there have been several issues associated with
3506 * renegotiation or a poor understanding of its properties.
3507 *
3508 * \note Server-side, enabling renegotiation also makes the server
3509 * susceptible to a resource DoS by a malicious client.
3510 *
3511 * \param conf SSL configuration
3512 * \param renegotiation Enable or disable (MBEDTLS_SSL_RENEGOTIATION_ENABLED or
3513 * MBEDTLS_SSL_RENEGOTIATION_DISABLED)
3514 */
3515void mbedtls_ssl_conf_renegotiation( mbedtls_ssl_config *conf, int renegotiation );
3516#endif /* MBEDTLS_SSL_RENEGOTIATION */
3517
3518/**
3519 * \brief Prevent or allow legacy renegotiation.
3520 * (Default: MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION)
3521 *
3522 * MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION allows connections to
3523 * be established even if the peer does not support
3524 * secure renegotiation, but does not allow renegotiation
3525 * to take place if not secure.
3526 * (Interoperable and secure option)
3527 *
3528 * MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION allows renegotiations
3529 * with non-upgraded peers. Allowing legacy renegotiation
3530 * makes the connection vulnerable to specific man in the
3531 * middle attacks. (See RFC 5746)
3532 * (Most interoperable and least secure option)
3533 *
3534 * MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE breaks off connections
3535 * if peer does not support secure renegotiation. Results
3536 * in interoperability issues with non-upgraded peers
3537 * that do not support renegotiation altogether.
3538 * (Most secure option, interoperability issues)
3539 *
3540 * \param conf SSL configuration
3541 * \param allow_legacy Prevent or allow (SSL_NO_LEGACY_RENEGOTIATION,
3542 * SSL_ALLOW_LEGACY_RENEGOTIATION or
3543 * MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE)
3544 */
3546
3547#if defined(MBEDTLS_SSL_RENEGOTIATION)
3548/**
3549 * \brief Enforce renegotiation requests.
3550 * (Default: enforced, max_records = 16)
3551 *
3552 * When we request a renegotiation, the peer can comply or
3553 * ignore the request. This function allows us to decide
3554 * whether to enforce our renegotiation requests by closing
3555 * the connection if the peer doesn't comply.
3556 *
3557 * However, records could already be in transit from the peer
3558 * when the request is emitted. In order to increase
3559 * reliability, we can accept a number of records before the
3560 * expected handshake records.
3561 *
3562 * The optimal value is highly dependent on the specific usage
3563 * scenario.
3564 *
3565 * \note With DTLS and server-initiated renegotiation, the
3566 * HelloRequest is retransmited every time mbedtls_ssl_read() times
3567 * out or receives Application Data, until:
3568 * - max_records records have beens seen, if it is >= 0, or
3569 * - the number of retransmits that would happen during an
3570 * actual handshake has been reached.
3571 * Please remember the request might be lost a few times
3572 * if you consider setting max_records to a really low value.
3573 *
3574 * \warning On client, the grace period can only happen during
3575 * mbedtls_ssl_read(), as opposed to mbedtls_ssl_write() and mbedtls_ssl_renegotiate()
3576 * which always behave as if max_record was 0. The reason is,
3577 * if we receive application data from the server, we need a
3578 * place to write it, which only happens during mbedtls_ssl_read().
3579 *
3580 * \param conf SSL configuration
3581 * \param max_records Use MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED if you don't want to
3582 * enforce renegotiation, or a non-negative value to enforce
3583 * it but allow for a grace period of max_records records.
3584 */
3585void mbedtls_ssl_conf_renegotiation_enforced( mbedtls_ssl_config *conf, int max_records );
3586
3587/**
3588 * \brief Set record counter threshold for periodic renegotiation.
3589 * (Default: 2^48 - 1)
3590 *
3591 * Renegotiation is automatically triggered when a record
3592 * counter (outgoing or incoming) crosses the defined
3593 * threshold. The default value is meant to prevent the
3594 * connection from being closed when the counter is about to
3595 * reached its maximal value (it is not allowed to wrap).
3596 *
3597 * Lower values can be used to enforce policies such as "keys
3598 * must be refreshed every N packets with cipher X".
3599 *
3600 * The renegotiation period can be disabled by setting
3601 * conf->disable_renegotiation to
3602 * MBEDTLS_SSL_RENEGOTIATION_DISABLED.
3603 *
3604 * \note When the configured transport is
3605 * MBEDTLS_SSL_TRANSPORT_DATAGRAM the maximum renegotiation
3606 * period is 2^48 - 1, and for MBEDTLS_SSL_TRANSPORT_STREAM,
3607 * the maximum renegotiation period is 2^64 - 1.
3608 *
3609 * \param conf SSL configuration
3610 * \param period The threshold value: a big-endian 64-bit number.
3611 */
3612void mbedtls_ssl_conf_renegotiation_period( mbedtls_ssl_config *conf,
3613 const unsigned char period[8] );
3614#endif /* MBEDTLS_SSL_RENEGOTIATION */
3615
3616/**
3617 * \brief Check if there is data already read from the
3618 * underlying transport but not yet processed.
3619 *
3620 * \param ssl SSL context
3621 *
3622 * \return 0 if nothing's pending, 1 otherwise.
3623 *
3624 * \note This is different in purpose and behaviour from
3625 * \c mbedtls_ssl_get_bytes_avail in that it considers
3626 * any kind of unprocessed data, not only unread
3627 * application data. If \c mbedtls_ssl_get_bytes
3628 * returns a non-zero value, this function will
3629 * also signal pending data, but the converse does
3630 * not hold. For example, in DTLS there might be
3631 * further records waiting to be processed from
3632 * the current underlying transport's datagram.
3633 *
3634 * \note If this function returns 1 (data pending), this
3635 * does not imply that a subsequent call to
3636 * \c mbedtls_ssl_read will provide any data;
3637 * e.g., the unprocessed data might turn out
3638 * to be an alert or a handshake message.
3639 *
3640 * \note This function is useful in the following situation:
3641 * If the SSL/TLS module successfully returns from an
3642 * operation - e.g. a handshake or an application record
3643 * read - and you're awaiting incoming data next, you
3644 * must not immediately idle on the underlying transport
3645 * to have data ready, but you need to check the value
3646 * of this function first. The reason is that the desired
3647 * data might already be read but not yet processed.
3648 * If, in contrast, a previous call to the SSL/TLS module
3649 * returned MBEDTLS_ERR_SSL_WANT_READ, it is not necessary
3650 * to call this function, as the latter error code entails
3651 * that all internal data has been processed.
3652 *
3653 */
3655
3656/**
3657 * \brief Return the number of application data bytes
3658 * remaining to be read from the current record.
3659 *
3660 * \param ssl SSL context
3661 *
3662 * \return How many bytes are available in the application
3663 * data record read buffer.
3664 *
3665 * \note When working over a datagram transport, this is
3666 * useful to detect the current datagram's boundary
3667 * in case \c mbedtls_ssl_read has written the maximal
3668 * amount of data fitting into the input buffer.
3669 *
3670 */
3672
3673/**
3674 * \brief Return the result of the certificate verification
3675 *
3676 * \param ssl The SSL context to use.
3677 *
3678 * \return \c 0 if the certificate verification was successful.
3679 * \return \c -1u if the result is not available. This may happen
3680 * e.g. if the handshake aborts early, or a verification
3681 * callback returned a fatal error.
3682 * \return A bitwise combination of \c MBEDTLS_X509_BADCERT_XXX
3683 * and \c MBEDTLS_X509_BADCRL_XXX failure flags; see x509.h.
3684 */
3686
3687/**
3688 * \brief Return the name of the current ciphersuite
3689 *
3690 * \param ssl SSL context
3691 *
3692 * \return a string containing the ciphersuite name
3693 */
3695
3696/**
3697 * \brief Return the current SSL version (SSLv3/TLSv1/etc)
3698 *
3699 * \param ssl SSL context
3700 *
3701 * \return a string containing the SSL version
3702 */
3704
3705/**
3706 * \brief Return the (maximum) number of bytes added by the record
3707 * layer: header + encryption/MAC overhead (inc. padding)
3708 *
3709 * \note This function is not available (always returns an error)
3710 * when record compression is enabled.
3711 *
3712 * \param ssl SSL context
3713 *
3714 * \return Current maximum record expansion in bytes, or
3715 * MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE if compression is
3716 * enabled, which makes expansion much less predictable
3717 */
3719
3720#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
3721/**
3722 * \brief Return the maximum fragment length (payload, in bytes) for
3723 * the output buffer. For the client, this is the configured
3724 * value. For the server, it is the minimum of two - the
3725 * configured value and the negotiated one.
3726 *
3727 * \sa mbedtls_ssl_conf_max_frag_len()
3728 * \sa mbedtls_ssl_get_max_record_payload()
3729 *
3730 * \param ssl SSL context
3731 *
3732 * \return Current maximum fragment length for the output buffer.
3733 */
3734size_t mbedtls_ssl_get_output_max_frag_len( const mbedtls_ssl_context *ssl );
3735
3736/**
3737 * \brief Return the maximum fragment length (payload, in bytes) for
3738 * the input buffer. This is the negotiated maximum fragment
3739 * length, or, if there is none, MBEDTLS_SSL_MAX_CONTENT_LEN.
3740 * If it is not defined either, the value is 2^14. This function
3741 * works as its predecessor, \c mbedtls_ssl_get_max_frag_len().
3742 *
3743 * \sa mbedtls_ssl_conf_max_frag_len()
3744 * \sa mbedtls_ssl_get_max_record_payload()
3745 *
3746 * \param ssl SSL context
3747 *
3748 * \return Current maximum fragment length for the output buffer.
3749 */
3750size_t mbedtls_ssl_get_input_max_frag_len( const mbedtls_ssl_context *ssl );
3751
3752#if !defined(MBEDTLS_DEPRECATED_REMOVED)
3753
3754#if defined(MBEDTLS_DEPRECATED_WARNING)
3755#define MBEDTLS_DEPRECATED __attribute__((deprecated))
3756#else
3757#define MBEDTLS_DEPRECATED
3758#endif
3759
3760/**
3761 * \brief This function is a deprecated approach to getting the max
3762 * fragment length. Its an alias for
3763 * \c mbedtls_ssl_get_output_max_frag_len(), as the behaviour
3764 * is the same. See \c mbedtls_ssl_get_output_max_frag_len() for
3765 * more detail.
3766 *
3767 * \sa mbedtls_ssl_get_input_max_frag_len()
3768 * \sa mbedtls_ssl_get_output_max_frag_len()
3769 *
3770 * \param ssl SSL context
3771 *
3772 * \return Current maximum fragment length for the output buffer.
3773 */
3774MBEDTLS_DEPRECATED size_t mbedtls_ssl_get_max_frag_len(
3775 const mbedtls_ssl_context *ssl );
3776#endif /* MBEDTLS_DEPRECATED_REMOVED */
3777#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
3778
3779/**
3780 * \brief Return the current maximum outgoing record payload in bytes.
3781 * This takes into account the config.h setting \c
3782 * MBEDTLS_SSL_OUT_CONTENT_LEN, the configured and negotiated
3783 * max fragment length extension if used, and for DTLS the
3784 * path MTU as configured and current record expansion.
3785 *
3786 * \note With DTLS, \c mbedtls_ssl_write() will return an error if
3787 * called with a larger length value.
3788 * With TLS, \c mbedtls_ssl_write() will fragment the input if
3789 * necessary and return the number of bytes written; it is up
3790 * to the caller to call \c mbedtls_ssl_write() again in
3791 * order to send the remaining bytes if any.
3792 *
3793 * \note This function is not available (always returns an error)
3794 * when record compression is enabled.
3795 *
3796 * \sa mbedtls_ssl_set_mtu()
3797 * \sa mbedtls_ssl_get_output_max_frag_len()
3798 * \sa mbedtls_ssl_get_input_max_frag_len()
3799 * \sa mbedtls_ssl_get_record_expansion()
3800 *
3801 * \param ssl SSL context
3802 *
3803 * \return Current maximum payload for an outgoing record,
3804 * or a negative error code.
3805 */
3807
3808#if defined(MBEDTLS_X509_CRT_PARSE_C)
3809/**
3810 * \brief Return the peer certificate from the current connection.
3811 *
3812 * \param ssl The SSL context to use. This must be initialized and setup.
3813 *
3814 * \return The current peer certificate, if available.
3815 * The returned certificate is owned by the SSL context and
3816 * is valid only until the next call to the SSL API.
3817 * \return \c NULL if no peer certificate is available. This might
3818 * be because the chosen ciphersuite doesn't use CRTs
3819 * (PSK-based ciphersuites, for example), or because
3820 * #MBEDTLS_SSL_KEEP_PEER_CERTIFICATE has been disabled,
3821 * allowing the stack to free the peer's CRT to save memory.
3822 *
3823 * \note For one-time inspection of the peer's certificate during
3824 * the handshake, consider registering an X.509 CRT verification
3825 * callback through mbedtls_ssl_conf_verify() instead of calling
3826 * this function. Using mbedtls_ssl_conf_verify() also comes at
3827 * the benefit of allowing you to influence the verification
3828 * process, for example by masking expected and tolerated
3829 * verification failures.
3830 *
3831 * \warning You must not use the pointer returned by this function
3832 * after any further call to the SSL API, including
3833 * mbedtls_ssl_read() and mbedtls_ssl_write(); this is
3834 * because the pointer might change during renegotiation,
3835 * which happens transparently to the user.
3836 * If you want to use the certificate across API calls,
3837 * you must make a copy.
3838 */
3839const mbedtls_x509_crt *mbedtls_ssl_get_peer_cert( const mbedtls_ssl_context *ssl );
3840#endif /* MBEDTLS_X509_CRT_PARSE_C */
3841
3842#if defined(MBEDTLS_SSL_CLI_C)
3843/**
3844 * \brief Save session in order to resume it later (client-side only)
3845 * Session data is copied to presented session structure.
3846 *
3847 *
3848 * \param ssl SSL context
3849 * \param session session context
3850 *
3851 * \return 0 if successful,
3852 * MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed,
3853 * MBEDTLS_ERR_SSL_BAD_INPUT_DATA if used server-side or
3854 * arguments are otherwise invalid.
3855 *
3856 * \note Only the server certificate is copied, and not the full chain,
3857 * so you should not attempt to validate the certificate again
3858 * by calling \c mbedtls_x509_crt_verify() on it.
3859 * Instead, you should use the results from the verification
3860 * in the original handshake by calling \c mbedtls_ssl_get_verify_result()
3861 * after loading the session again into a new SSL context
3862 * using \c mbedtls_ssl_set_session().
3863 *
3864 * \note Once the session object is not needed anymore, you should
3865 * free it by calling \c mbedtls_ssl_session_free().
3866 *
3867 * \sa mbedtls_ssl_set_session()
3868 */
3869int mbedtls_ssl_get_session( const mbedtls_ssl_context *ssl, mbedtls_ssl_session *session );
3870#endif /* MBEDTLS_SSL_CLI_C */
3871
3872/**
3873 * \brief Perform the SSL handshake
3874 *
3875 * \param ssl SSL context
3876 *
3877 * \return \c 0 if successful.
3878 * \return #MBEDTLS_ERR_SSL_WANT_READ or #MBEDTLS_ERR_SSL_WANT_WRITE
3879 * if the handshake is incomplete and waiting for data to
3880 * be available for reading from or writing to the underlying
3881 * transport - in this case you must call this function again
3882 * when the underlying transport is ready for the operation.
3883 * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if an asynchronous
3884 * operation is in progress (see
3885 * mbedtls_ssl_conf_async_private_cb()) - in this case you
3886 * must call this function again when the operation is ready.
3887 * \return #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS if a cryptographic
3888 * operation is in progress (see mbedtls_ecp_set_max_ops()) -
3889 * in this case you must call this function again to complete
3890 * the handshake when you're done attending other tasks.
3891 * \return #MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED if DTLS is in use
3892 * and the client did not demonstrate reachability yet - in
3893 * this case you must stop using the context (see below).
3894 * \return Another SSL error code - in this case you must stop using
3895 * the context (see below).
3896 *
3897 * \warning If this function returns something other than
3898 * \c 0,
3899 * #MBEDTLS_ERR_SSL_WANT_READ,
3900 * #MBEDTLS_ERR_SSL_WANT_WRITE,
3901 * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS or
3902 * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS,
3903 * you must stop using the SSL context for reading or writing,
3904 * and either free it or call \c mbedtls_ssl_session_reset()
3905 * on it before re-using it for a new connection; the current
3906 * connection must be closed.
3907 *
3908 * \note If DTLS is in use, then you may choose to handle
3909 * #MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED specially for logging
3910 * purposes, as it is an expected return value rather than an
3911 * actual error, but you still need to reset/free the context.
3912 *
3913 * \note Remarks regarding event-driven DTLS:
3914 * If the function returns #MBEDTLS_ERR_SSL_WANT_READ, no datagram
3915 * from the underlying transport layer is currently being processed,
3916 * and it is safe to idle until the timer or the underlying transport
3917 * signal a new event. This is not true for a successful handshake,
3918 * in which case the datagram of the underlying transport that is
3919 * currently being processed might or might not contain further
3920 * DTLS records.
3921 */
3923
3924/**
3925 * \brief Perform a single step of the SSL handshake
3926 *
3927 * \note The state of the context (ssl->state) will be at
3928 * the next state after this function returns \c 0. Do not
3929 * call this function if state is MBEDTLS_SSL_HANDSHAKE_OVER.
3930 *
3931 * \param ssl SSL context
3932 *
3933 * \return See mbedtls_ssl_handshake().
3934 *
3935 * \warning If this function returns something other than \c 0,
3936 * #MBEDTLS_ERR_SSL_WANT_READ, #MBEDTLS_ERR_SSL_WANT_WRITE,
3937 * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS or
3938 * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS, you must stop using
3939 * the SSL context for reading or writing, and either free it
3940 * or call \c mbedtls_ssl_session_reset() on it before
3941 * re-using it for a new connection; the current connection
3942 * must be closed.
3943 */
3945
3946#if defined(MBEDTLS_SSL_RENEGOTIATION)
3947/**
3948 * \brief Initiate an SSL renegotiation on the running connection.
3949 * Client: perform the renegotiation right now.
3950 * Server: request renegotiation, which will be performed
3951 * during the next call to mbedtls_ssl_read() if honored by
3952 * client.
3953 *
3954 * \param ssl SSL context
3955 *
3956 * \return 0 if successful, or any mbedtls_ssl_handshake() return
3957 * value except #MBEDTLS_ERR_SSL_CLIENT_RECONNECT that can't
3958 * happen during a renegotiation.
3959 *
3960 * \warning If this function returns something other than \c 0,
3961 * #MBEDTLS_ERR_SSL_WANT_READ, #MBEDTLS_ERR_SSL_WANT_WRITE,
3962 * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS or
3963 * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS, you must stop using
3964 * the SSL context for reading or writing, and either free it
3965 * or call \c mbedtls_ssl_session_reset() on it before
3966 * re-using it for a new connection; the current connection
3967 * must be closed.
3968 *
3969 */
3970int mbedtls_ssl_renegotiate( mbedtls_ssl_context *ssl );
3971#endif /* MBEDTLS_SSL_RENEGOTIATION */
3972
3973/**
3974 * \brief Read at most 'len' application data bytes
3975 *
3976 * \param ssl SSL context
3977 * \param buf buffer that will hold the data
3978 * \param len maximum number of bytes to read
3979 *
3980 * \return The (positive) number of bytes read if successful.
3981 * \return \c 0 if the read end of the underlying transport was closed
3982 * without sending a CloseNotify beforehand, which might happen
3983 * because of various reasons (internal error of an underlying
3984 * stack, non-conformant peer not sending a CloseNotify and
3985 * such) - in this case you must stop using the context
3986 * (see below).
3987 * \return #MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY if the underlying
3988 * transport is still functional, but the peer has
3989 * acknowledged to not send anything anymore.
3990 * \return #MBEDTLS_ERR_SSL_WANT_READ or #MBEDTLS_ERR_SSL_WANT_WRITE
3991 * if the handshake is incomplete and waiting for data to
3992 * be available for reading from or writing to the underlying
3993 * transport - in this case you must call this function again
3994 * when the underlying transport is ready for the operation.
3995 * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if an asynchronous
3996 * operation is in progress (see
3997 * mbedtls_ssl_conf_async_private_cb()) - in this case you
3998 * must call this function again when the operation is ready.
3999 * \return #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS if a cryptographic
4000 * operation is in progress (see mbedtls_ecp_set_max_ops()) -
4001 * in this case you must call this function again to complete
4002 * the handshake when you're done attending other tasks.
4003 * \return #MBEDTLS_ERR_SSL_CLIENT_RECONNECT if we're at the server
4004 * side of a DTLS connection and the client is initiating a
4005 * new connection using the same source port. See below.
4006 * \return Another SSL error code - in this case you must stop using
4007 * the context (see below).
4008 *
4009 * \warning If this function returns something other than
4010 * a positive value,
4011 * #MBEDTLS_ERR_SSL_WANT_READ,
4012 * #MBEDTLS_ERR_SSL_WANT_WRITE,
4013 * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS,
4014 * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS or
4015 * #MBEDTLS_ERR_SSL_CLIENT_RECONNECT,
4016 * you must stop using the SSL context for reading or writing,
4017 * and either free it or call \c mbedtls_ssl_session_reset()
4018 * on it before re-using it for a new connection; the current
4019 * connection must be closed.
4020 *
4021 * \note When this function returns #MBEDTLS_ERR_SSL_CLIENT_RECONNECT
4022 * (which can only happen server-side), it means that a client
4023 * is initiating a new connection using the same source port.
4024 * You can either treat that as a connection close and wait
4025 * for the client to resend a ClientHello, or directly
4026 * continue with \c mbedtls_ssl_handshake() with the same
4027 * context (as it has been reset internally). Either way, you
4028 * must make sure this is seen by the application as a new
4029 * connection: application state, if any, should be reset, and
4030 * most importantly the identity of the client must be checked
4031 * again. WARNING: not validating the identity of the client
4032 * again, or not transmitting the new identity to the
4033 * application layer, would allow authentication bypass!
4034 *
4035 * \note Remarks regarding event-driven DTLS:
4036 * - If the function returns #MBEDTLS_ERR_SSL_WANT_READ, no datagram
4037 * from the underlying transport layer is currently being processed,
4038 * and it is safe to idle until the timer or the underlying transport
4039 * signal a new event.
4040 * - This function may return MBEDTLS_ERR_SSL_WANT_READ even if data was
4041 * initially available on the underlying transport, as this data may have
4042 * been only e.g. duplicated messages or a renegotiation request.
4043 * Therefore, you must be prepared to receive MBEDTLS_ERR_SSL_WANT_READ even
4044 * when reacting to an incoming-data event from the underlying transport.
4045 * - On success, the datagram of the underlying transport that is currently
4046 * being processed may contain further DTLS records. You should call
4047 * \c mbedtls_ssl_check_pending to check for remaining records.
4048 *
4049 */
4050int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len );
4051
4052/**
4053 * \brief Try to write exactly 'len' application data bytes
4054 *
4055 * \warning This function will do partial writes in some cases. If the
4056 * return value is non-negative but less than length, the
4057 * function must be called again with updated arguments:
4058 * buf + ret, len - ret (if ret is the return value) until
4059 * it returns a value equal to the last 'len' argument.
4060 *
4061 * \param ssl SSL context
4062 * \param buf buffer holding the data
4063 * \param len how many bytes must be written
4064 *
4065 * \return The (non-negative) number of bytes actually written if
4066 * successful (may be less than \p len).
4067 * \return #MBEDTLS_ERR_SSL_WANT_READ or #MBEDTLS_ERR_SSL_WANT_WRITE
4068 * if the handshake is incomplete and waiting for data to
4069 * be available for reading from or writing to the underlying
4070 * transport - in this case you must call this function again
4071 * when the underlying transport is ready for the operation.
4072 * \return #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS if an asynchronous
4073 * operation is in progress (see
4074 * mbedtls_ssl_conf_async_private_cb()) - in this case you
4075 * must call this function again when the operation is ready.
4076 * \return #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS if a cryptographic
4077 * operation is in progress (see mbedtls_ecp_set_max_ops()) -
4078 * in this case you must call this function again to complete
4079 * the handshake when you're done attending other tasks.
4080 * \return Another SSL error code - in this case you must stop using
4081 * the context (see below).
4082 *
4083 * \warning If this function returns something other than
4084 * a non-negative value,
4085 * #MBEDTLS_ERR_SSL_WANT_READ,
4086 * #MBEDTLS_ERR_SSL_WANT_WRITE,
4087 * #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS or
4088 * #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS,
4089 * you must stop using the SSL context for reading or writing,
4090 * and either free it or call \c mbedtls_ssl_session_reset()
4091 * on it before re-using it for a new connection; the current
4092 * connection must be closed.
4093 *
4094 * \note When this function returns #MBEDTLS_ERR_SSL_WANT_WRITE/READ,
4095 * it must be called later with the *same* arguments,
4096 * until it returns a value greater that or equal to 0. When
4097 * the function returns #MBEDTLS_ERR_SSL_WANT_WRITE there may be
4098 * some partial data in the output buffer, however this is not
4099 * yet sent.
4100 *
4101 * \note If the requested length is greater than the maximum
4102 * fragment length (either the built-in limit or the one set
4103 * or negotiated with the peer), then:
4104 * - with TLS, less bytes than requested are written.
4105 * - with DTLS, MBEDTLS_ERR_SSL_BAD_INPUT_DATA is returned.
4106 * \c mbedtls_ssl_get_output_max_frag_len() may be used to
4107 * query the active maximum fragment length.
4108 *
4109 * \note Attempting to write 0 bytes will result in an empty TLS
4110 * application record being sent.
4111 */
4112int mbedtls_ssl_write( mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len );
4113
4114/**
4115 * \brief Send an alert message
4116 *
4117 * \param ssl SSL context
4118 * \param level The alert level of the message
4119 * (MBEDTLS_SSL_ALERT_LEVEL_WARNING or MBEDTLS_SSL_ALERT_LEVEL_FATAL)
4120 * \param message The alert message (SSL_ALERT_MSG_*)
4121 *
4122 * \return 0 if successful, or a specific SSL error code.
4123 *
4124 * \note If this function returns something other than 0 or
4125 * MBEDTLS_ERR_SSL_WANT_READ/WRITE, you must stop using
4126 * the SSL context for reading or writing, and either free it or
4127 * call \c mbedtls_ssl_session_reset() on it before re-using it
4128 * for a new connection; the current connection must be closed.
4129 */
4131 unsigned char level,
4132 unsigned char message );
4133/**
4134 * \brief Notify the peer that the connection is being closed
4135 *
4136 * \param ssl SSL context
4137 *
4138 * \return 0 if successful, or a specific SSL error code.
4139 *
4140 * \note If this function returns something other than 0 or
4141 * MBEDTLS_ERR_SSL_WANT_READ/WRITE, you must stop using
4142 * the SSL context for reading or writing, and either free it or
4143 * call \c mbedtls_ssl_session_reset() on it before re-using it
4144 * for a new connection; the current connection must be closed.
4145 */
4147
4148/**
4149 * \brief Free referenced items in an SSL context and clear memory
4150 *
4151 * \param ssl SSL context
4152 */
4154
4155#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION)
4156/**
4157 * \brief Save an active connection as serialized data in a buffer.
4158 * This allows the freeing or re-using of the SSL context
4159 * while still picking up the connection later in a way that
4160 * it entirely transparent to the peer.
4161 *
4162 * \see mbedtls_ssl_context_load()
4163 *
4164 * \note This feature is currently only available under certain
4165 * conditions, see the documentation of the return value
4166 * #MBEDTLS_ERR_SSL_BAD_INPUT_DATA for details.
4167 *
4168 * \note When this function succeeds, it calls
4169 * mbedtls_ssl_session_reset() on \p ssl which as a result is
4170 * no longer associated with the connection that has been
4171 * serialized. This avoids creating copies of the connection
4172 * state. You're then free to either re-use the context
4173 * structure for a different connection, or call
4174 * mbedtls_ssl_free() on it. See the documentation of
4175 * mbedtls_ssl_session_reset() for more details.
4176 *
4177 * \param ssl The SSL context to save. On success, it is no longer
4178 * associated with the connection that has been serialized.
4179 * \param buf The buffer to write the serialized data to. It must be a
4180 * writeable buffer of at least \p buf_len bytes, or may be \c
4181 * NULL if \p buf_len is \c 0.
4182 * \param buf_len The number of bytes available for writing in \p buf.
4183 * \param olen The size in bytes of the data that has been or would have
4184 * been written. It must point to a valid \c size_t.
4185 *
4186 * \note \p olen is updated to the correct value regardless of
4187 * whether \p buf_len was large enough. This makes it possible
4188 * to determine the necessary size by calling this function
4189 * with \p buf set to \c NULL and \p buf_len to \c 0. However,
4190 * the value of \p olen is only guaranteed to be correct when
4191 * the function returns #MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL or
4192 * \c 0. If the return value is different, then the value of
4193 * \p olen is undefined.
4194 *
4195 * \return \c 0 if successful.
4196 * \return #MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL if \p buf is too small.
4197 * \return #MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed
4198 * while reseting the context.
4199 * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if a handshake is in
4200 * progress, or there is pending data for reading or sending,
4201 * or the connection does not use DTLS 1.2 with an AEAD
4202 * ciphersuite, or renegotiation is enabled.
4203 */
4204int mbedtls_ssl_context_save( mbedtls_ssl_context *ssl,
4205 unsigned char *buf,
4206 size_t buf_len,
4207 size_t *olen );
4208
4209/**
4210 * \brief Load serialized connection data to an SSL context.
4211 *
4212 * \see mbedtls_ssl_context_save()
4213 *
4214 * \warning The same serialized data must never be loaded into more
4215 * that one context. In order to ensure that, after
4216 * successfully loading serialized data to an SSL context, you
4217 * should immediately destroy or invalidate all copies of the
4218 * serialized data that was loaded. Loading the same data in
4219 * more than one context would cause severe security failures
4220 * including but not limited to loss of confidentiality.
4221 *
4222 * \note Before calling this function, the SSL context must be
4223 * prepared in one of the two following ways. The first way is
4224 * to take a context freshly initialised with
4225 * mbedtls_ssl_init() and call mbedtls_ssl_setup() on it with
4226 * the same ::mbedtls_ssl_config structure that was used in
4227 * the original connection. The second way is to
4228 * call mbedtls_ssl_session_reset() on a context that was
4229 * previously prepared as above but used in the meantime.
4230 * Either way, you must not use the context to perform a
4231 * handshake between calling mbedtls_ssl_setup() or
4232 * mbedtls_ssl_session_reset() and calling this function. You
4233 * may however call other setter functions in that time frame
4234 * as indicated in the note below.
4235 *
4236 * \note Before or after calling this function successfully, you
4237 * also need to configure some connection-specific callbacks
4238 * and settings before you can use the connection again
4239 * (unless they were already set before calling
4240 * mbedtls_ssl_session_reset() and the values are suitable for
4241 * the present connection). Specifically, you want to call
4242 * at least mbedtls_ssl_set_bio() and
4243 * mbedtls_ssl_set_timer_cb(). All other SSL setter functions
4244 * are not necessary to call, either because they're only used
4245 * in handshakes, or because the setting is already saved. You
4246 * might choose to call them anyway, for example in order to
4247 * share code between the cases of establishing a new
4248 * connection and the case of loading an already-established
4249 * connection.
4250 *
4251 * \note If you have new information about the path MTU, you want to
4252 * call mbedtls_ssl_set_mtu() after calling this function, as
4253 * otherwise this function would overwrite your
4254 * newly-configured value with the value that was active when
4255 * the context was saved.
4256 *
4257 * \note When this function returns an error code, it calls
4258 * mbedtls_ssl_free() on \p ssl. In this case, you need to
4259 * prepare the context with the usual sequence starting with a
4260 * call to mbedtls_ssl_init() if you want to use it again.
4261 *
4262 * \param ssl The SSL context structure to be populated. It must have
4263 * been prepared as described in the note above.
4264 * \param buf The buffer holding the serialized connection data. It must
4265 * be a readable buffer of at least \p len bytes.
4266 * \param len The size of the serialized data in bytes.
4267 *
4268 * \return \c 0 if successful.
4269 * \return #MBEDTLS_ERR_SSL_ALLOC_FAILED if memory allocation failed.
4270 * \return #MBEDTLS_ERR_SSL_VERSION_MISMATCH if the serialized data
4271 * comes from a different Mbed TLS version or build.
4272 * \return #MBEDTLS_ERR_SSL_BAD_INPUT_DATA if input data is invalid.
4273 */
4274int mbedtls_ssl_context_load( mbedtls_ssl_context *ssl,
4275 const unsigned char *buf,
4276 size_t len );
4277#endif /* MBEDTLS_SSL_CONTEXT_SERIALIZATION */
4278
4279/**
4280 * \brief Initialize an SSL configuration context
4281 * Just makes the context ready for
4282 * mbedtls_ssl_config_defaults() or mbedtls_ssl_config_free().
4283 *
4284 * \note You need to call mbedtls_ssl_config_defaults() unless you
4285 * manually set all of the relevant fields yourself.
4286 *
4287 * \param conf SSL configuration context
4288 */
4290
4291/**
4292 * \brief Load reasonnable default SSL configuration values.
4293 * (You need to call mbedtls_ssl_config_init() first.)
4294 *
4295 * \param conf SSL configuration context
4296 * \param endpoint MBEDTLS_SSL_IS_CLIENT or MBEDTLS_SSL_IS_SERVER
4297 * \param transport MBEDTLS_SSL_TRANSPORT_STREAM for TLS, or
4298 * MBEDTLS_SSL_TRANSPORT_DATAGRAM for DTLS
4299 * \param preset a MBEDTLS_SSL_PRESET_XXX value
4300 *
4301 * \note See \c mbedtls_ssl_conf_transport() for notes on DTLS.
4302 *
4303 * \return 0 if successful, or
4304 * MBEDTLS_ERR_XXX_ALLOC_FAILED on memory allocation error.
4305 */
4307 int endpoint, int transport, int preset );
4308
4309/**
4310 * \brief Free an SSL configuration context
4311 *
4312 * \param conf SSL configuration context
4313 */
4315
4316/**
4317 * \brief Initialize SSL session structure
4318 *
4319 * \param session SSL session
4320 */
4322
4323/**
4324 * \brief Free referenced items in an SSL session including the
4325 * peer certificate and clear memory
4326 *
4327 * \note A session object can be freed even if the SSL context
4328 * that was used to retrieve the session is still in use.
4329 *
4330 * \param session SSL session
4331 */
4333
4334/**
4335 * \brief TLS-PRF function for key derivation.
4336 *
4337 * \param prf The tls_prf type funtion type to be used.
4338 * \param secret Secret for the key derivation function.
4339 * \param slen Length of the secret.
4340 * \param label String label for the key derivation function,
4341 * terminated with null character.
4342 * \param random Random bytes.
4343 * \param rlen Length of the random bytes buffer.
4344 * \param dstbuf The buffer holding the derived key.
4345 * \param dlen Length of the output buffer.
4346 *
4347 * \return 0 on sucess. An SSL specific error on failure.
4348 */
4349int mbedtls_ssl_tls_prf( const mbedtls_tls_prf_types prf,
4350 const unsigned char *secret, size_t slen,
4351 const char *label,
4352 const unsigned char *random, size_t rlen,
4353 unsigned char *dstbuf, size_t dlen );
4354
4355#ifdef __cplusplus
4356}
4357#endif
4358
4359/// \}
4360/// \}
4361
4362#endif /* ssl.h */
Multi-precision integer library.
#define MBEDTLS_MPI_MAX_SIZE
Maximum number of bytes for usable MPIs.
Definition: bignum.h:80
Configuration options (set of defines)
Platform Security Architecture cryptography module.
This file contains Diffie-Hellman-Merkle (DHM) key exchange definitions and functions.
This file contains ECDH definitions and functions.
uint32_t psa_key_id_t
Encoding of identifiers of persistent keys.
Definition: crypto_types.h:231
mbedtls_ecp_group_id
Domain-parameter identifiers: curve, subgroup, and generator.
mbedtls_md_type_t
Supported message digests.
Definition: md.h:64
void mbedtls_ssl_conf_read_timeout(mbedtls_ssl_config *conf, uint32_t timeout)
Set the timeout period for mbedtls_ssl_read() (Default: no timeout.)
void mbedtls_ssl_conf_min_version(mbedtls_ssl_config *conf, int major, int minor)
Set the minimum accepted SSL/TLS protocol version (Default: TLS 1.0)
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:1965
void mbedtls_ssl_conf_legacy_renegotiation(mbedtls_ssl_config *conf, int allow_legacy)
Prevent or allow legacy renegotiation.
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.
int mbedtls_ssl_session_reset(mbedtls_ssl_context *ssl)
Reset an already initialized SSL context for re-use while retaining application-set variables,...
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).
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.)
int mbedtls_ssl_send_t(void *ctx, const unsigned char *buf, size_t len)
Callback type: send data on the network.
Definition: ssl.h:532
void mbedtls_ssl_conf_endpoint(mbedtls_ssl_config *conf, int endpoint)
Set the current endpoint type.
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.
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 SSL version (SSLv3/TLSv1/etc)
void mbedtls_ssl_conf_rng(mbedtls_ssl_config *conf, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Set the random number generator callback.
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:2059
int mbedtls_ssl_handshake(mbedtls_ssl_context *ssl)
Perform the SSL handshake.
uint32_t mbedtls_ssl_get_verify_result(const mbedtls_ssl_context *ssl)
Return the result of the certificate verification.
int mbedtls_ssl_session_load(mbedtls_ssl_session *session, const unsigned char *buf, size_t len)
Load serialized session data into a session structure.
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:2210
void mbedtls_ssl_conf_authmode(mbedtls_ssl_config *conf, int authmode)
Set the certificate verification mode Default: NONE on server, REQUIRED on client.
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.
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:607
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:581
void mbedtls_ssl_config_free(mbedtls_ssl_config *conf)
Free an SSL configuration context.
void mbedtls_ssl_session_init(mbedtls_ssl_session *session)
Initialize SSL session structure.
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_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_get_record_expansion(const mbedtls_ssl_context *ssl)
Return the (maximum) number of bytes added by the record layer: header + encryption/MAC overhead (inc...
int mbedtls_ssl_get_ciphersuite_id(const char *ciphersuite_name)
Return the ID of the ciphersuite associated with the given name.
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:2227
int mbedtls_ssl_config_defaults(mbedtls_ssl_config *conf, int endpoint, int transport, int preset)
Load reasonnable default SSL configuration values.
int mbedtls_ssl_read(mbedtls_ssl_context *ssl, unsigned char *buf, size_t len)
Read at most 'len' application data bytes.
void mbedtls_ssl_conf_ciphersuites_for_version(mbedtls_ssl_config *conf, const int *ciphersuites, int major, int minor)
Set the list of allowed ciphersuites and the preference order for a specific version of the protocol.
int mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl)
Perform a single step of the SSL handshake.
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_config_init(mbedtls_ssl_config *conf)
Initialize an SSL configuration context Just makes the context ready for mbedtls_ssl_config_defaults(...
const mbedtls_ssl_session * mbedtls_ssl_get_session_pointer(const mbedtls_ssl_context *ssl)
Get a pointer to the current session structure, for example to serialize it.
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.
int mbedtls_ssl_recv_t(void *ctx, unsigned char *buf, size_t len)
Callback type: receive data from the network.
Definition: ssl.h:555
void mbedtls_ssl_session_free(mbedtls_ssl_session *session)
Free referenced items in an SSL session including the peer certificate and clear memory.
int mbedtls_ssl_close_notify(mbedtls_ssl_context *ssl)
Notify the peer that the connection is being closed.
void mbedtls_ssl_conf_ciphersuites(mbedtls_ssl_config *conf, const int *ciphersuites)
Set the list of allowed ciphersuites and the preference order.
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_timer_t(void *ctx)
Callback type: get status of timers/delays.
Definition: ssl.h:622
int mbedtls_ssl_setup(mbedtls_ssl_context *ssl, const mbedtls_ssl_config *conf)
Set up an SSL context for use.
void mbedtls_ssl_conf_max_version(mbedtls_ssl_config *conf, int major, int minor)
Set the maximum supported version sent from the client side and/or accepted at the server side (Defau...
This file provides an API for Elliptic Curves over GF(P) (ECP).
mbed TLS Platform time abstraction
SSL Ciphersuites for mbed TLS.
The key size.
The DHM context structure.
Definition: dhm.h:109
MPI structure.
Definition: bignum.h:185
Public key container.
Definition: pk.h:186
SSL/TLS configuration to be shared between mbedtls_ssl_context structures.
Definition: ssl.h:964
unsigned char min_major_ver
Definition: ssl.h:1149
void * p_rng
Definition: ssl.h:979
unsigned char max_minor_ver
Definition: ssl.h:1148
unsigned int transport
Definition: ssl.h:1157
unsigned char max_major_ver
Definition: ssl.h:1147
uint32_t read_timeout
Definition: ssl.h:1124
int(* f_set_cache)(void *, const mbedtls_ssl_session *)
Callback to store a session into the cache
Definition: ssl.h:984
const int * ciphersuite_list[4]
Definition: ssl.h:971
void(* f_dbg)(void *, int, const char *, int, const char *)
Callback for printing debug output
Definition: ssl.h:974
int(* f_rng)(void *, unsigned char *, size_t)
Callback for getting (pseudo-)random numbers
Definition: ssl.h:978
unsigned char min_minor_ver
Definition: ssl.h:1150
unsigned int authmode
Definition: ssl.h:1158
void * p_dbg
Definition: ssl.h:975
unsigned int endpoint
Definition: ssl.h:1156
void * p_cache
Definition: ssl.h:985
int(* f_get_cache)(void *, mbedtls_ssl_session *)
Callback to retrieve a session from the cache
Definition: ssl.h:982
unsigned int allow_legacy_renegotiation
Definition: ssl.h:1160
mbedtls_ssl_set_timer_t * f_set_timer
Definition: ssl.h:1265
mbedtls_ssl_recv_timeout_t * f_recv_timeout
Definition: ssl.h:1236
mbedtls_ssl_session * session_negotiate
Definition: ssl.h:1247
size_t in_hslen
Definition: ssl.h:1301
unsigned char cur_out_ctr[8]
Definition: ssl.h:1334
size_t in_left
Definition: ssl.h:1287
mbedtls_ssl_transform * transform
Definition: ssl.h:1257
mbedtls_ssl_recv_t * f_recv
Definition: ssl.h:1235
mbedtls_ssl_transform * transform_negotiate
Definition: ssl.h:1258
mbedtls_ssl_get_timer_t * f_get_timer
Definition: ssl.h:1266
unsigned char * out_hdr
Definition: ssl.h:1318
int secure_renegotiation
Definition: ssl.h:1383
unsigned char * in_len
Definition: ssl.h:1280
mbedtls_ssl_session * session_in
Definition: ssl.h:1244
unsigned char * out_buf
Definition: ssl.h:1316
unsigned char * in_hdr
Definition: ssl.h:1275
int keep_current_message
Definition: ssl.h:1305
size_t out_msglen
Definition: ssl.h:1328
unsigned char * in_msg
Definition: ssl.h:1282
mbedtls_ssl_handshake_params * handshake
Definition: ssl.h:1249
mbedtls_ssl_session * session_out
Definition: ssl.h:1245
unsigned char * in_offt
Definition: ssl.h:1283
mbedtls_ssl_send_t * f_send
Definition: ssl.h:1234
unsigned char * out_ctr
Definition: ssl.h:1317
unsigned char * out_len
Definition: ssl.h:1323
mbedtls_ssl_transform * transform_out
Definition: ssl.h:1256
mbedtls_ssl_transform * transform_in
Definition: ssl.h:1255
size_t in_msglen
Definition: ssl.h:1286
unsigned char * in_iv
Definition: ssl.h:1281
unsigned char * out_iv
Definition: ssl.h:1324
void * p_timer
Definition: ssl.h:1263
mbedtls_ssl_session * session
Definition: ssl.h:1246
const mbedtls_ssl_config * conf
Definition: ssl.h:1208
void * p_bio
Definition: ssl.h:1239
unsigned char * in_ctr
Definition: ssl.h:1272
unsigned char * out_msg
Definition: ssl.h:1325
unsigned char * in_buf
Definition: ssl.h:1271
size_t out_left
Definition: ssl.h:1329
unsigned char master[48]
Definition: ssl.h:926
uint32_t verify_result
Definition: ssl.h:939
size_t id_len
Definition: ssl.h:924
Certificate revocation list structure.
Definition: x509_crl.h:69
Security profile for certificate verification.
Definition: x509_crt.h:160
Container for an X.509 certificate.
Definition: x509_crt.h:53
X.509 certificate revocation list parsing.
X.509 certificate parsing and writing.