mbed TLS v2.0.0
ssl.h
Go to the documentation of this file.
1 
24 #ifndef MBEDTLS_SSL_H
25 #define MBEDTLS_SSL_H
26 
27 #if !defined(MBEDTLS_CONFIG_FILE)
28 #include "config.h"
29 #else
30 #include MBEDTLS_CONFIG_FILE
31 #endif
32 
33 #include "bignum.h"
34 #include "ecp.h"
35 
36 #include "ssl_ciphersuites.h"
37 
38 #if defined(MBEDTLS_X509_CRT_PARSE_C)
39 #include "x509_crt.h"
40 #include "x509_crl.h"
41 #endif
42 
43 #if defined(MBEDTLS_DHM_C)
44 #include "dhm.h"
45 #endif
46 
47 #if defined(MBEDTLS_ECDH_C)
48 #include "ecdh.h"
49 #endif
50 
51 #if defined(MBEDTLS_ZLIB_SUPPORT)
52 #include "zlib.h"
53 #endif
54 
55 #if defined(MBEDTLS_HAVE_TIME)
56 #include <time.h>
57 #endif
58 
59 /* For convenience below and in programs */
60 #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || \
61  defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
62  defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
63  defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
64 #define MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED
65 #endif
66 
67 #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
68  defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
69  defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
70 #define MBEDTLS_KEY_EXCHANGE__SOME__ECDHE_ENABLED
71 #endif
72 
73 #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
74  defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
75  defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
76 #define MBEDTLS_KEY_EXCHANGE__SOME__SIGNATURE_ENABLED
77 #endif
78 
79 /*
80  * SSL Error codes
81  */
82 #define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080
83 #define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100
84 #define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180
85 #define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200
86 #define MBEDTLS_ERR_SSL_CONN_EOF -0x7280
87 #define MBEDTLS_ERR_SSL_UNKNOWN_CIPHER -0x7300
88 #define MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN -0x7380
89 #define MBEDTLS_ERR_SSL_NO_RNG -0x7400
90 #define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480
91 #define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500
92 #define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580
93 #define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600
94 #define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680
95 #define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700
96 #define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780
97 #define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800
98 #define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880
99 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900
100 #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980
101 #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00
102 #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80
103 #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00
104 #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80
105 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00
106 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80
107 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00
108 #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80
109 #define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00
110 #define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80
111 #define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00
112 #define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80
113 #define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80
114 #define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00
115 #define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80
116 #define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00
117 #define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80
118 #define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00
119 #define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80
120 #define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00
121 #define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80
122 #define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00
123 #define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80
124 #define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00
125 #define MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6980
126 #define MBEDTLS_ERR_SSL_WANT_READ -0x6900
127 #define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880
128 #define MBEDTLS_ERR_SSL_TIMEOUT -0x6800
130 /*
131  * Various constants
132  */
133 #define MBEDTLS_SSL_MAJOR_VERSION_3 3
134 #define MBEDTLS_SSL_MINOR_VERSION_0 0
135 #define MBEDTLS_SSL_MINOR_VERSION_1 1
136 #define MBEDTLS_SSL_MINOR_VERSION_2 2
137 #define MBEDTLS_SSL_MINOR_VERSION_3 3
139 #define MBEDTLS_SSL_TRANSPORT_STREAM 0
140 #define MBEDTLS_SSL_TRANSPORT_DATAGRAM 1
142 /* RFC 6066 section 4, see also mfl_code_to_length in ssl_tls.c
143  * NONE must be zero so that memset()ing structure to zero works */
144 #define MBEDTLS_SSL_MAX_FRAG_LEN_NONE 0
145 #define MBEDTLS_SSL_MAX_FRAG_LEN_512 1
146 #define MBEDTLS_SSL_MAX_FRAG_LEN_1024 2
147 #define MBEDTLS_SSL_MAX_FRAG_LEN_2048 3
148 #define MBEDTLS_SSL_MAX_FRAG_LEN_4096 4
149 #define MBEDTLS_SSL_MAX_FRAG_LEN_INVALID 5
151 #define MBEDTLS_SSL_IS_CLIENT 0
152 #define MBEDTLS_SSL_IS_SERVER 1
153 
154 #define MBEDTLS_SSL_IS_NOT_FALLBACK 0
155 #define MBEDTLS_SSL_IS_FALLBACK 1
156 
157 #define MBEDTLS_SSL_EXTENDED_MS_DISABLED 0
158 #define MBEDTLS_SSL_EXTENDED_MS_ENABLED 1
159 
160 #define MBEDTLS_SSL_ETM_DISABLED 0
161 #define MBEDTLS_SSL_ETM_ENABLED 1
162 
163 #define MBEDTLS_SSL_COMPRESS_NULL 0
164 #define MBEDTLS_SSL_COMPRESS_DEFLATE 1
165 
166 #define MBEDTLS_SSL_VERIFY_NONE 0
167 #define MBEDTLS_SSL_VERIFY_OPTIONAL 1
168 #define MBEDTLS_SSL_VERIFY_REQUIRED 2
169 #define MBEDTLS_SSL_VERIFY_UNSET 3 /* Used only for sni_authmode */
170 
171 #define MBEDTLS_SSL_LEGACY_RENEGOTIATION 0
172 #define MBEDTLS_SSL_SECURE_RENEGOTIATION 1
173 
174 #define MBEDTLS_SSL_RENEGOTIATION_DISABLED 0
175 #define MBEDTLS_SSL_RENEGOTIATION_ENABLED 1
176 
177 #define MBEDTLS_SSL_ANTI_REPLAY_DISABLED 0
178 #define MBEDTLS_SSL_ANTI_REPLAY_ENABLED 1
179 
180 #define MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED -1
181 #define MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT 16
182 
183 #define MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION 0
184 #define MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION 1
185 #define MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE 2
186 
187 #define MBEDTLS_SSL_TRUNC_HMAC_DISABLED 0
188 #define MBEDTLS_SSL_TRUNC_HMAC_ENABLED 1
189 #define MBEDTLS_SSL_TRUNCATED_HMAC_LEN 10 /* 80 bits, rfc 6066 section 7 */
190 
191 #define MBEDTLS_SSL_SESSION_TICKETS_DISABLED 0
192 #define MBEDTLS_SSL_SESSION_TICKETS_ENABLED 1
193 
194 #define MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED 0
195 #define MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED 1
196 
197 #define MBEDTLS_SSL_ARC4_ENABLED 0
198 #define MBEDTLS_SSL_ARC4_DISABLED 1
199 
200 #define MBEDTLS_SSL_PRESET_DEFAULT 0
201 #define MBEDTLS_SSL_PRESET_SUITEB 2
202 
203 /*
204  * Default range for DTLS retransmission timer value, in milliseconds.
205  * RFC 6347 4.2.4.1 says from 1 second to 60 seconds.
206  */
207 #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN 1000
208 #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX 60000
209 
218 #if !defined(MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME)
219 #define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400
220 #endif
221 
222 /*
223  * Size of the input / output buffer.
224  * Note: the RFC defines the default size of SSL / TLS messages. If you
225  * change the value here, other clients / servers may not be able to
226  * communicate with you anymore. Only change this value if you control
227  * both sides of the connection and have it reduced at both sides, or
228  * if you're using the Max Fragment Length extension and you know all your
229  * peers are using it too!
230  */
231 #if !defined(MBEDTLS_SSL_MAX_CONTENT_LEN)
232 #define MBEDTLS_SSL_MAX_CONTENT_LEN 16384
233 #endif
234 
235 /* \} name SECTION: Module settings */
236 
237 /*
238  * Length of the verify data for secure renegotiation
239  */
240 #if defined(MBEDTLS_SSL_PROTO_SSL3)
241 #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 36
242 #else
243 #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 12
244 #endif
245 
246 /*
247  * Signaling ciphersuite values (SCSV)
248  */
249 #define MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO 0xFF
250 #define MBEDTLS_SSL_FALLBACK_SCSV_VALUE 0x5600
252 /*
253  * Supported Signature and Hash algorithms (For TLS 1.2)
254  * RFC 5246 section 7.4.1.4.1
255  */
256 #define MBEDTLS_SSL_HASH_NONE 0
257 #define MBEDTLS_SSL_HASH_MD5 1
258 #define MBEDTLS_SSL_HASH_SHA1 2
259 #define MBEDTLS_SSL_HASH_SHA224 3
260 #define MBEDTLS_SSL_HASH_SHA256 4
261 #define MBEDTLS_SSL_HASH_SHA384 5
262 #define MBEDTLS_SSL_HASH_SHA512 6
263 
264 #define MBEDTLS_SSL_SIG_ANON 0
265 #define MBEDTLS_SSL_SIG_RSA 1
266 #define MBEDTLS_SSL_SIG_ECDSA 3
267 
268 /*
269  * Client Certificate Types
270  * RFC 5246 section 7.4.4 plus RFC 4492 section 5.5
271  */
272 #define MBEDTLS_SSL_CERT_TYPE_RSA_SIGN 1
273 #define MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN 64
274 
275 /*
276  * Message, alert and handshake types
277  */
278 #define MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC 20
279 #define MBEDTLS_SSL_MSG_ALERT 21
280 #define MBEDTLS_SSL_MSG_HANDSHAKE 22
281 #define MBEDTLS_SSL_MSG_APPLICATION_DATA 23
282 
283 #define MBEDTLS_SSL_ALERT_LEVEL_WARNING 1
284 #define MBEDTLS_SSL_ALERT_LEVEL_FATAL 2
285 
286 #define MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY 0 /* 0x00 */
287 #define MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10 /* 0x0A */
288 #define MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC 20 /* 0x14 */
289 #define MBEDTLS_SSL_ALERT_MSG_DECRYPTION_FAILED 21 /* 0x15 */
290 #define MBEDTLS_SSL_ALERT_MSG_RECORD_OVERFLOW 22 /* 0x16 */
291 #define MBEDTLS_SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30 /* 0x1E */
292 #define MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE 40 /* 0x28 */
293 #define MBEDTLS_SSL_ALERT_MSG_NO_CERT 41 /* 0x29 */
294 #define MBEDTLS_SSL_ALERT_MSG_BAD_CERT 42 /* 0x2A */
295 #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT 43 /* 0x2B */
296 #define MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED 44 /* 0x2C */
297 #define MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED 45 /* 0x2D */
298 #define MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN 46 /* 0x2E */
299 #define MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER 47 /* 0x2F */
300 #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_CA 48 /* 0x30 */
301 #define MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED 49 /* 0x31 */
302 #define MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR 50 /* 0x32 */
303 #define MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR 51 /* 0x33 */
304 #define MBEDTLS_SSL_ALERT_MSG_EXPORT_RESTRICTION 60 /* 0x3C */
305 #define MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION 70 /* 0x46 */
306 #define MBEDTLS_SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71 /* 0x47 */
307 #define MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR 80 /* 0x50 */
308 #define MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK 86 /* 0x56 */
309 #define MBEDTLS_SSL_ALERT_MSG_USER_CANCELED 90 /* 0x5A */
310 #define MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION 100 /* 0x64 */
311 #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT 110 /* 0x6E */
312 #define MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME 112 /* 0x70 */
313 #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY 115 /* 0x73 */
314 #define MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL 120 /* 0x78 */
315 
316 #define MBEDTLS_SSL_HS_HELLO_REQUEST 0
317 #define MBEDTLS_SSL_HS_CLIENT_HELLO 1
318 #define MBEDTLS_SSL_HS_SERVER_HELLO 2
319 #define MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST 3
320 #define MBEDTLS_SSL_HS_NEW_SESSION_TICKET 4
321 #define MBEDTLS_SSL_HS_CERTIFICATE 11
322 #define MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE 12
323 #define MBEDTLS_SSL_HS_CERTIFICATE_REQUEST 13
324 #define MBEDTLS_SSL_HS_SERVER_HELLO_DONE 14
325 #define MBEDTLS_SSL_HS_CERTIFICATE_VERIFY 15
326 #define MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE 16
327 #define MBEDTLS_SSL_HS_FINISHED 20
328 
329 /*
330  * TLS extensions
331  */
332 #define MBEDTLS_TLS_EXT_SERVERNAME 0
333 #define MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME 0
334 
335 #define MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH 1
336 
337 #define MBEDTLS_TLS_EXT_TRUNCATED_HMAC 4
338 
339 #define MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES 10
340 #define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS 11
341 
342 #define MBEDTLS_TLS_EXT_SIG_ALG 13
343 
344 #define MBEDTLS_TLS_EXT_ALPN 16
345 
346 #define MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC 22 /* 0x16 */
347 #define MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET 0x0017 /* 23 */
348 
349 #define MBEDTLS_TLS_EXT_SESSION_TICKET 35
350 
351 #define MBEDTLS_TLS_EXT_RENEGOTIATION_INFO 0xFF01
352 
353 /*
354  * Size defines
355  */
356 #if !defined(MBEDTLS_PSK_MAX_LEN)
357 #define MBEDTLS_PSK_MAX_LEN 32 /* 256 bits */
358 #endif
359 
360 /* Dummy type used only for its size */
362 {
363 #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
364  unsigned char _pms_rsa[48]; /* RFC 5246 8.1.1 */
365 #endif
366 #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED)
367  unsigned char _pms_dhm[MBEDTLS_MPI_MAX_SIZE]; /* RFC 5246 8.1.2 */
368 #endif
369 #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
370  defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
371  defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
372  defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
373  unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]; /* RFC 4492 5.10 */
374 #endif
375 #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
376  unsigned char _pms_psk[4 + 2 * MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 2 */
377 #endif
378 #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
379  unsigned char _pms_dhe_psk[4 + MBEDTLS_MPI_MAX_SIZE
380  + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 3 */
381 #endif
382 #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)
383  unsigned char _pms_rsa_psk[52 + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 4 */
384 #endif
385 #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
386  unsigned char _pms_ecdhe_psk[4 + MBEDTLS_ECP_MAX_BYTES
387  + MBEDTLS_PSK_MAX_LEN]; /* RFC 5489 2 */
388 #endif
389 };
390 
391 #define MBEDTLS_PREMASTER_SIZE sizeof( union mbedtls_ssl_premaster_secret )
392 
393 #ifdef __cplusplus
394 extern "C" {
395 #endif
396 
397 /*
398  * SSL state machine
399  */
400 typedef enum
401 {
421 }
423 
424 /* Defined below */
428 
429 /* Defined in ssl_internal.h */
432 #if defined(MBEDTLS_X509_CRT_PARSE_C)
434 #endif
435 #if defined(MBEDTLS_SSL_PROTO_DTLS)
437 #endif
438 
439 /*
440  * This structure is used for storing current session data.
441  */
443 {
444 #if defined(MBEDTLS_HAVE_TIME)
445  time_t start;
446 #endif
449  size_t id_len;
450  unsigned char id[32];
451  unsigned char master[48];
453 #if defined(MBEDTLS_X509_CRT_PARSE_C)
455 #endif /* MBEDTLS_X509_CRT_PARSE_C */
456  uint32_t verify_result;
458 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
459  unsigned char *ticket;
460  size_t ticket_len;
461  uint32_t ticket_lifetime;
462 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
463 
464 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
465  unsigned char mfl_code;
466 #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
467 
468 #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
470 #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
471 
472 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
474 #endif
475 };
476 
481 {
482  /* Group items by size (largest first) to minimize padding overhead */
483 
484  /*
485  * Pointers
486  */
487 
488  const int *ciphersuite_list[4];
491  void (*f_dbg)(void *, int, const char *, int, const char *);
492  void *p_dbg;
495  int (*f_rng)(void *, unsigned char *, size_t);
496  void *p_rng;
499  int (*f_get_cache)(void *, mbedtls_ssl_session *);
501  int (*f_set_cache)(void *, const mbedtls_ssl_session *);
502  void *p_cache;
504 #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
505 
506  int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
507  void *p_sni;
508 #endif
509 
510 #if defined(MBEDTLS_X509_CRT_PARSE_C)
511 
512  int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *);
513  void *p_vrfy;
514 #endif
515 
516 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
517 
518  int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
519  void *p_psk;
520 #endif
521 
522 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
523 
524  int (*f_cookie_write)( void *, unsigned char **, unsigned char *,
525  const unsigned char *, size_t );
527  int (*f_cookie_check)( void *, const unsigned char *, size_t,
528  const unsigned char *, size_t );
529  void *p_cookie;
530 #endif
531 
532 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
533 
534  int (*f_ticket_write)( void *, const mbedtls_ssl_session *,
535  unsigned char *, const unsigned char *, size_t *, uint32_t * );
537  int (*f_ticket_parse)( void *, mbedtls_ssl_session *, unsigned char *, size_t);
538  void *p_ticket;
539 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
540 
541 #if defined(MBEDTLS_X509_CRT_PARSE_C)
544  mbedtls_x509_crt *ca_chain;
546 #endif /* MBEDTLS_X509_CRT_PARSE_C */
547 
548 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__SIGNATURE_ENABLED)
549  const int *sig_hashes;
550 #endif
551 
552 #if defined(MBEDTLS_ECP_C)
554 #endif
555 
556 #if defined(MBEDTLS_DHM_C)
559 #endif
560 
561 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
562  unsigned char *psk;
563  size_t psk_len;
564  unsigned char *psk_identity;
566 #endif
567 
568 #if defined(MBEDTLS_SSL_ALPN)
569  const char **alpn_list;
570 #endif
571 
572  /*
573  * Numerical settings (int then char)
574  */
575 
576  uint32_t read_timeout;
578 #if defined(MBEDTLS_SSL_PROTO_DTLS)
579  uint32_t hs_timeout_min;
581  uint32_t hs_timeout_max;
583 #endif
584 
585 #if defined(MBEDTLS_SSL_RENEGOTIATION)
587  unsigned char renego_period[8];
589 #endif
590 
591 #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
592  unsigned int badmac_limit;
593 #endif
594 
595 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
596  unsigned int dhm_min_bitlen;
597 #endif
598 
599  unsigned char max_major_ver;
600  unsigned char max_minor_ver;
601  unsigned char min_major_ver;
602  unsigned char min_minor_ver;
604  /*
605  * Flags (bitfields)
606  */
607 
608  unsigned int endpoint : 1;
609  unsigned int transport : 1;
610  unsigned int authmode : 2;
611  /* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */
612  unsigned int allow_legacy_renegotiation : 2 ;
613 #if defined(MBEDTLS_ARC4_C)
614  unsigned int arc4_disabled : 1;
615 #endif
616 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
617  unsigned int mfl_code : 3;
618 #endif
619 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
620  unsigned int encrypt_then_mac : 1 ;
621 #endif
622 #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
623  unsigned int extended_ms : 1;
624 #endif
625 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
626  unsigned int anti_replay : 1;
627 #endif
628 #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
629  unsigned int cbc_record_splitting : 1;
630 #endif
631 #if defined(MBEDTLS_SSL_RENEGOTIATION)
632  unsigned int disable_renegotiation : 1;
633 #endif
634 #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
635  unsigned int trunc_hmac : 1;
636 #endif
637 #if defined(MBEDTLS_SSL_SESSION_TICKETS)
638  unsigned int session_tickets : 1;
639 #endif
640 #if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
641  unsigned int fallback : 1;
642 #endif
643 };
644 
645 
647 {
650  /*
651  * Miscellaneous
652  */
653  int state;
654 #if defined(MBEDTLS_SSL_RENEGOTIATION)
659 #endif
660 
661  int major_ver;
662  int minor_ver;
664 #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
665  unsigned badmac_seen;
666 #endif
667 
668  /*
669  * Callbacks
670  */
671  int (*f_send)(void *, const unsigned char *, size_t);
672  int (*f_recv)(void *, unsigned char *, size_t);
673  int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t);
674  void *p_bio;
676  /*
677  * Session layer
678  */
687  /*
688  * Record layer transformations
689  */
695  /*
696  * Timers
697  */
698  void *p_timer;
699  void (*f_set_timer)(void *, uint32_t, uint32_t);
700  int (*f_get_timer)(void *);
702  /*
703  * Record layer (incoming data)
704  */
705  unsigned char *in_buf;
706  unsigned char *in_ctr;
709  unsigned char *in_hdr;
710  unsigned char *in_len;
711  unsigned char *in_iv;
712  unsigned char *in_msg;
713  unsigned char *in_offt;
716  size_t in_msglen;
717  size_t in_left;
718 #if defined(MBEDTLS_SSL_PROTO_DTLS)
719  uint16_t in_epoch;
722 #endif
723 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
724  uint64_t in_window_top;
725  uint64_t in_window;
726 #endif
727 
728  size_t in_hslen;
730  int nb_zero;
733  /*
734  * Record layer (outgoing data)
735  */
736  unsigned char *out_buf;
737  unsigned char *out_ctr;
738  unsigned char *out_hdr;
739  unsigned char *out_len;
740  unsigned char *out_iv;
741  unsigned char *out_msg;
744  size_t out_msglen;
745  size_t out_left;
747 #if defined(MBEDTLS_ZLIB_SUPPORT)
748  unsigned char *compress_buf;
749 #endif
750 #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
751  signed char split_done;
752 #endif
753 
754  /*
755  * PKI layer
756  */
759  /*
760  * User settings
761  */
762 #if defined(MBEDTLS_X509_CRT_PARSE_C)
763  char *hostname;
765 #endif
766 
767 #if defined(MBEDTLS_SSL_ALPN)
768  const char *alpn_chosen;
769 #endif
770 
771  /*
772  * Information for DTLS hello verify
773  */
774 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
775  unsigned char *cli_id;
776  size_t cli_id_len;
777 #endif
778 
779  /*
780  * Secure renegotiation
781  */
782  /* needed to know when to send extension on server */
785 #if defined(MBEDTLS_SSL_RENEGOTIATION)
789 #endif
790 };
791 
792 #if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
793 
794 #define MBEDTLS_SSL_CHANNEL_OUTBOUND 0
795 #define MBEDTLS_SSL_CHANNEL_INBOUND 1
796 
797 extern int (*mbedtls_ssl_hw_record_init)(mbedtls_ssl_context *ssl,
798  const unsigned char *key_enc, const unsigned char *key_dec,
799  size_t keylen,
800  const unsigned char *iv_enc, const unsigned char *iv_dec,
801  size_t ivlen,
802  const unsigned char *mac_enc, const unsigned char *mac_dec,
803  size_t maclen);
804 extern int (*mbedtls_ssl_hw_record_activate)(mbedtls_ssl_context *ssl, int direction);
805 extern int (*mbedtls_ssl_hw_record_reset)(mbedtls_ssl_context *ssl);
806 extern int (*mbedtls_ssl_hw_record_write)(mbedtls_ssl_context *ssl);
807 extern int (*mbedtls_ssl_hw_record_read)(mbedtls_ssl_context *ssl);
808 extern int (*mbedtls_ssl_hw_record_finish)(mbedtls_ssl_context *ssl);
809 #endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
810 
817 const int *mbedtls_ssl_list_ciphersuites( void );
818 
827 const char *mbedtls_ssl_get_ciphersuite_name( const int ciphersuite_id );
828 
837 int mbedtls_ssl_get_ciphersuite_id( const char *ciphersuite_name );
838 
847 
864  const mbedtls_ssl_config *conf );
865 
877 
884 void mbedtls_ssl_conf_endpoint( mbedtls_ssl_config *conf, int endpoint );
885 
900 void mbedtls_ssl_conf_transport( mbedtls_ssl_config *conf, int transport );
901 
927 void mbedtls_ssl_conf_authmode( mbedtls_ssl_config *conf, int authmode );
928 
929 #if defined(MBEDTLS_X509_CRT_PARSE_C)
930 
942  int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
943  void *p_vrfy );
944 #endif /* MBEDTLS_X509_CRT_PARSE_C */
945 
954  int (*f_rng)(void *, unsigned char *, size_t),
955  void *p_rng );
956 
972  void (*f_dbg)(void *, int, const char *, int, const char *),
973  void *p_dbg );
974 
999  void *p_bio,
1000  int (*f_send)(void *, const unsigned char *, size_t),
1001  int (*f_recv)(void *, unsigned char *, size_t),
1002  int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t) );
1003 
1020 void mbedtls_ssl_conf_read_timeout( mbedtls_ssl_config *conf, uint32_t timeout );
1021 
1038  void *p_timer,
1039  void (*f_set_timer)(void *, uint32_t int_ms, uint32_t fin_ms),
1040  int (*f_get_timer)(void *) );
1041 
1061 typedef int mbedtls_ssl_ticket_write_t( void *p_ticket,
1062  const mbedtls_ssl_session *session,
1063  unsigned char *start,
1064  const unsigned char *end,
1065  size_t *tlen,
1066  uint32_t *lifetime );
1067 
1091 typedef int mbedtls_ssl_ticket_parse_t( void *p_ticket,
1092  mbedtls_ssl_session *session,
1093  unsigned char *buf,
1094  size_t len );
1095 
1096 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
1097 
1112  mbedtls_ssl_ticket_write_t *f_ticket_write,
1113  mbedtls_ssl_ticket_parse_t *f_ticket_parse,
1114  void *p_ticket );
1115 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
1116 
1131 typedef int mbedtls_ssl_cookie_write_t( void *ctx,
1132  unsigned char **p, unsigned char *end,
1133  const unsigned char *info, size_t ilen );
1134 
1148 typedef int mbedtls_ssl_cookie_check_t( void *ctx,
1149  const unsigned char *cookie, size_t clen,
1150  const unsigned char *info, size_t ilen );
1151 
1152 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
1153 
1177  mbedtls_ssl_cookie_write_t *f_cookie_write,
1178  mbedtls_ssl_cookie_check_t *f_cookie_check,
1179  void *p_cookie );
1180 
1201  const unsigned char *info,
1202  size_t ilen );
1203 
1204 #endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
1205 
1206 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
1207 
1222 void mbedtls_ssl_conf_dtls_anti_replay( mbedtls_ssl_config *conf, char mode );
1223 #endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
1224 
1225 #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
1226 
1249 void mbedtls_ssl_conf_dtls_badmac_limit( mbedtls_ssl_config *conf, unsigned limit );
1250 #endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
1251 
1252 #if defined(MBEDTLS_SSL_PROTO_DTLS)
1253 
1269 void mbedtls_ssl_conf_handshake_timeout( mbedtls_ssl_config *conf, uint32_t min, uint32_t max );
1270 #endif /* MBEDTLS_SSL_PROTO_DTLS */
1271 
1272 #if defined(MBEDTLS_SSL_SRV_C)
1273 
1311  void *p_cache,
1312  int (*f_get_cache)(void *, mbedtls_ssl_session *),
1313  int (*f_set_cache)(void *, const mbedtls_ssl_session *) );
1314 #endif /* MBEDTLS_SSL_SRV_C */
1315 
1316 #if defined(MBEDTLS_SSL_CLI_C)
1317 
1332 #endif /* MBEDTLS_SSL_CLI_C */
1333 
1350  const int *ciphersuites );
1351 
1372  const int *ciphersuites,
1373  int major, int minor );
1374 
1375 #if defined(MBEDTLS_X509_CRT_PARSE_C)
1376 
1383  mbedtls_x509_crt_profile *profile );
1384 
1393  mbedtls_x509_crt *ca_chain,
1394  mbedtls_x509_crl *ca_crl );
1395 
1420  mbedtls_x509_crt *own_cert,
1421  mbedtls_pk_context *pk_key );
1422 #endif /* MBEDTLS_X509_CRT_PARSE_C */
1423 
1424 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
1425 
1440  const unsigned char *psk, size_t psk_len,
1441  const unsigned char *psk_identity, size_t psk_identity_len );
1442 
1443 
1457  const unsigned char *psk, size_t psk_len );
1458 
1484  int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *,
1485  size_t),
1486  void *p_psk );
1487 #endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */
1488 
1489 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C)
1490 
1501 int mbedtls_ssl_conf_dh_param( mbedtls_ssl_config *conf, const char *dhm_P, const char *dhm_G );
1502 
1513 #endif /* MBEDTLS_DHM_C && defined(MBEDTLS_SSL_SRV_C) */
1514 
1515 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
1516 
1525  unsigned int bitlen );
1526 #endif /* MBEDTLS_DHM_C && MBEDTLS_SSL_CLI_C */
1527 
1528 #if defined(MBEDTLS_ECP_C)
1529 
1559  const mbedtls_ecp_group_id *curves );
1560 #endif /* MBEDTLS_ECP_C */
1561 
1562 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__SIGNATURE_ENABLED)
1563 
1582  const int *hashes );
1583 #endif /* MBEDTLS_KEY_EXCHANGE__SOME__SIGNATURE_ENABLED */
1584 
1585 #if defined(MBEDTLS_X509_CRT_PARSE_C)
1586 
1596 int mbedtls_ssl_set_hostname( mbedtls_ssl_context *ssl, const char *hostname );
1597 #endif /* MBEDTLS_X509_CRT_PARSE_C */
1598 
1599 #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
1600 
1613  mbedtls_x509_crt *own_cert,
1614  mbedtls_pk_context *pk_key );
1615 
1628  mbedtls_x509_crt *ca_chain,
1629  mbedtls_x509_crl *ca_crl );
1630 
1642  int authmode );
1643 
1668  int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *,
1669  size_t),
1670  void *p_sni );
1671 #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
1672 
1673 #if defined(MBEDTLS_SSL_ALPN)
1674 
1683 int mbedtls_ssl_conf_alpn_protocols( mbedtls_ssl_config *conf, const char **protos );
1684 
1694 const char *mbedtls_ssl_get_alpn_protocol( const mbedtls_ssl_context *ssl );
1695 #endif /* MBEDTLS_SSL_ALPN */
1696 
1713 void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int minor );
1714 
1733 void mbedtls_ssl_conf_min_version( mbedtls_ssl_config *conf, int major, int minor );
1734 
1735 #if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
1736 
1755 void mbedtls_ssl_conf_fallback( mbedtls_ssl_config *conf, char fallback );
1756 #endif /* MBEDTLS_SSL_FALLBACK_SCSV && MBEDTLS_SSL_CLI_C */
1757 
1758 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1759 
1771 #endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
1772 
1773 #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
1774 
1786 #endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */
1787 
1788 #if defined(MBEDTLS_ARC4_C)
1789 
1802 void mbedtls_ssl_conf_arc4_support( mbedtls_ssl_config *conf, char arc4 );
1803 #endif /* MBEDTLS_ARC4_C */
1804 
1805 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
1806 
1821 int mbedtls_ssl_conf_max_frag_len( mbedtls_ssl_config *conf, unsigned char mfl_code );
1822 #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
1823 
1824 #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
1825 
1833 void mbedtls_ssl_conf_truncated_hmac( mbedtls_ssl_config *conf, int truncate );
1834 #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
1835 
1836 #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
1837 
1849 #endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */
1850 
1851 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
1852 
1862 void mbedtls_ssl_conf_session_tickets( mbedtls_ssl_config *conf, int use_tickets );
1863 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
1864 
1865 #if defined(MBEDTLS_SSL_RENEGOTIATION)
1866 
1883 void mbedtls_ssl_conf_renegotiation( mbedtls_ssl_config *conf, int renegotiation );
1884 #endif /* MBEDTLS_SSL_RENEGOTIATION */
1885 
1913 void mbedtls_ssl_conf_legacy_renegotiation( mbedtls_ssl_config *conf, int allow_legacy );
1914 
1915 #if defined(MBEDTLS_SSL_RENEGOTIATION)
1916 
1953 void mbedtls_ssl_conf_renegotiation_enforced( mbedtls_ssl_config *conf, int max_records );
1954 
1973  const unsigned char period[8] );
1974 #endif /* MBEDTLS_SSL_RENEGOTIATION */
1975 
1984 
1996 uint32_t mbedtls_ssl_get_verify_result( const mbedtls_ssl_context *ssl );
1997 
2005 const char *mbedtls_ssl_get_ciphersuite( const mbedtls_ssl_context *ssl );
2006 
2014 const char *mbedtls_ssl_get_version( const mbedtls_ssl_context *ssl );
2015 
2027 
2028 #if defined(MBEDTLS_X509_CRT_PARSE_C)
2029 
2044 #endif /* MBEDTLS_X509_CRT_PARSE_C */
2045 
2046 #if defined(MBEDTLS_SSL_CLI_C)
2047 
2064 #endif /* MBEDTLS_SSL_CLI_C */
2065 
2082 
2096 
2097 #if defined(MBEDTLS_SSL_RENEGOTIATION)
2098 
2109 #endif /* MBEDTLS_SSL_RENEGOTIATION */
2110 
2122 int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len );
2123 
2146 int mbedtls_ssl_write( mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len );
2147 
2159  unsigned char level,
2160  unsigned char message );
2167 
2174 
2186 
2204  int endpoint, int transport, int preset );
2205 
2212 
2219 
2227 
2228 #ifdef __cplusplus
2229 }
2230 #endif
2231 
2232 #endif /* ssl.h */
uint64_t in_window_top
Definition: ssl.h:724
time_t start
Definition: ssl.h:445
void * p_rng
Definition: ssl.h:496
const char ** alpn_list
Definition: ssl.h:569
unsigned int transport
Definition: ssl.h:609
unsigned char * in_ctr
Definition: ssl.h:706
mbedtls_x509_crt * peer_cert
Definition: ssl.h:454
unsigned char * out_msg
Definition: ssl.h:741
unsigned char master[48]
Definition: ssl.h:451
unsigned int trunc_hmac
Definition: ssl.h:635
unsigned char * in_len
Definition: ssl.h:710
unsigned char * in_buf
Definition: ssl.h:705
unsigned int endpoint
Definition: ssl.h:608
Public key container.
Definition: pk.h:123
void mbedtls_ssl_set_hs_ca_chain(mbedtls_ssl_context *ssl, mbedtls_x509_crt *ca_chain, mbedtls_x509_crl *ca_crl)
Set the data required to verify peer certificate for the current handshake.
int mbedtls_ssl_ticket_parse_t(void *p_ticket, mbedtls_ssl_session *session, unsigned char *buf, size_t len)
Callback type: parse and load session ticket.
Definition: ssl.h:1091
mbedtls_mpi dhm_P
Definition: ssl.h:557
char peer_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]
Definition: ssl.h:788
unsigned char max_minor_ver
Definition: ssl.h:600
const char * mbedtls_ssl_get_ciphersuite_name(const int ciphersuite_id)
Return the name of the ciphersuite associated with the given ID.
void mbedtls_ssl_conf_encrypt_then_mac(mbedtls_ssl_config *conf, char etm)
Enable or disable Encrypt-then-MAC (Default: MBEDTLS_SSL_ETM_ENABLED)
unsigned char min_minor_ver
Definition: ssl.h:602
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:1131
unsigned char * in_hdr
Definition: ssl.h:709
size_t psk_identity_len
Definition: ssl.h:565
unsigned int dhm_min_bitlen
Definition: ssl.h:596
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:1148
void * p_sni
Definition: ssl.h:507
int(* f_recv)(void *, unsigned char *, size_t)
Definition: ssl.h:672
unsigned char * ticket
Definition: ssl.h:459
size_t ticket_len
Definition: ssl.h:460
void mbedtls_ssl_conf_extended_master_secret(mbedtls_ssl_config *conf, char ems)
Enable or disable Extended Master Secret negotiation.
unsigned char * out_iv
Definition: ssl.h:740
mbedtls_ssl_transform * transform_in
Definition: ssl.h:690
size_t in_left
Definition: ssl.h:717
unsigned int authmode
Definition: ssl.h:610
unsigned int badmac_limit
Definition: ssl.h:592
void * p_psk
Definition: ssl.h:519
void mbedtls_ssl_conf_fallback(mbedtls_ssl_config *conf, char fallback)
Set the fallback flag (client-side only).
unsigned int anti_replay
Definition: ssl.h:626
unsigned int fallback
Definition: ssl.h:641
const mbedtls_ecp_group_id * curve_list
Definition: ssl.h:553
Elliptic curves over GF(p)
void mbedtls_ssl_conf_cbc_record_splitting(mbedtls_ssl_config *conf, char split)
Enable / Disable 1/n-1 record splitting (Default: MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED) ...
Certificate revocation list structure.
Definition: x509_crl.h:70
void(* f_dbg)(void *, int, const char *, int, const char *)
Callback for printing debug output.
Definition: ssl.h:491
unsigned char _pms_dhm[MBEDTLS_MPI_MAX_SIZE]
Definition: ssl.h:367
void * p_cache
Definition: ssl.h:502
void mbedtls_ssl_conf_verify(mbedtls_ssl_config *conf, int(*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *), void *p_vrfy)
Set the verification callback (Optional).
unsigned char _pms_rsa[48]
Definition: ssl.h:364
unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]
Definition: ssl.h:373
unsigned char renego_period[8]
Definition: ssl.h:587
uint32_t ticket_lifetime
Definition: ssl.h:461
void mbedtls_ssl_conf_renegotiation(mbedtls_ssl_config *conf, int renegotiation)
Enable / Disable renegotiation support for connection when initiated by peer (Default: MBEDTLS_SSL_RE...
mbedtls_ssl_session * session_in
Definition: ssl.h:679
unsigned badmac_seen
Definition: ssl.h:665
void mbedtls_ssl_conf_dtls_anti_replay(mbedtls_ssl_config *conf, char mode)
Enable or disable anti-replay protection for DTLS.
int(* f_cookie_check)(void *, const unsigned char *, size_t, const unsigned char *, size_t)
Callback to verify validity of a ClientHello cookie.
Definition: ssl.h:527
Compatibility names (set of defines)
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...
uint32_t mbedtls_ssl_get_verify_result(const mbedtls_ssl_context *ssl)
Return the result of the certificate verification.
void mbedtls_ssl_conf_session_tickets_cb(mbedtls_ssl_config *conf, mbedtls_ssl_ticket_write_t *f_ticket_write, mbedtls_ssl_ticket_parse_t *f_ticket_parse, void *p_ticket)
Configure SSL session ticket callbacks (server only).
mbedtls_x509_crl * ca_crl
Definition: ssl.h:545
mbedtls_ssl_session * session_out
Definition: ssl.h:680
const mbedtls_x509_crt * mbedtls_ssl_get_peer_cert(const mbedtls_ssl_context *ssl)
Return the peer certificate from the current connection.
int mbedtls_ssl_send_alert_message(mbedtls_ssl_context *ssl, unsigned char level, unsigned char message)
Send an alert message.
SSL Ciphersuites for mbed TLS.
mbedtls_ssl_transform * transform_out
Definition: ssl.h:691
unsigned char mfl_code
Definition: ssl.h:465
void mbedtls_ssl_conf_renegotiation_period(mbedtls_ssl_config *conf, const unsigned char period[8])
Set record counter threshold for periodic renegotiation.
unsigned int mfl_code
Definition: ssl.h:617
Multi-precision integer library.
int encrypt_then_mac
Definition: ssl.h:473
size_t in_hslen
Definition: ssl.h:728
int mbedtls_ssl_conf_psk(mbedtls_ssl_config *conf, const unsigned char *psk, size_t psk_len, const unsigned char *psk_identity, size_t psk_identity_len)
Set the Pre Shared Key (PSK) and the expected identity name.
int mbedtls_ssl_conf_max_frag_len(mbedtls_ssl_config *conf, unsigned char mfl_code)
Set the maximum fragment length to emit and/or negotiate (Default: MBEDTLS_SSL_MAX_CONTENT_LEN, usually 2^14 bytes) (Server: set maximum fragment length to emit, usually negotiated by the client during handshake (Client: set maximum fragment length to emit and negotiate with the server during handshake)
int(* f_sni)(void *, mbedtls_ssl_context *, const unsigned char *, size_t)
Callback for setting cert according to SNI extension.
Definition: ssl.h:506
int mbedtls_ssl_write(mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len)
Write exactly 'len' application data bytes.
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)
uint64_t in_window
Definition: ssl.h:725
int(* f_recv_timeout)(void *, unsigned char *, size_t, uint32_t)
Definition: ssl.h:673
int mbedtls_ssl_close_notify(mbedtls_ssl_context *ssl)
Notify the peer that the connection is being closed.
void * p_cookie
Definition: ssl.h:529
void mbedtls_ssl_conf_session_tickets(mbedtls_ssl_config *conf, int use_tickets)
Enable / Disable session tickets (client only).
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...
mbedtls_ssl_transform * transform
Definition: ssl.h:692
uint32_t hs_timeout_min
Definition: ssl.h:579
mbedtls_ssl_handshake_params * handshake
Definition: ssl.h:684
void mbedtls_ssl_free(mbedtls_ssl_context *ssl)
Free referenced items in an SSL context and clear memory.
void mbedtls_ssl_conf_cert_profile(mbedtls_ssl_config *conf, mbedtls_x509_crt_profile *profile)
Set the X.509 security profile used for verification.
void mbedtls_ssl_conf_endpoint(mbedtls_ssl_config *conf, int endpoint)
Set the current endpoint type.
size_t out_left
Definition: ssl.h:745
void mbedtls_ssl_session_free(mbedtls_ssl_session *session)
Free referenced items in an SSL session including the peer certificate and clear memory.
void mbedtls_ssl_conf_arc4_support(mbedtls_ssl_config *conf, char arc4)
Disable or enable support for RC4 (Default: MBEDTLS_SSL_ARC4_DISABLED)
unsigned char * in_msg
Definition: ssl.h:712
void mbedtls_ssl_conf_sig_hashes(mbedtls_ssl_config *conf, const int *hashes)
Set the allowed hashes for signatures during the handshake.
unsigned char min_major_ver
Definition: ssl.h:601
const char * mbedtls_ssl_get_alpn_protocol(const mbedtls_ssl_context *ssl)
Get the name of the negotiated Application Layer Protocol.
int(* f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *)
Callback to customize X.509 certificate chain verification.
Definition: ssl.h:512
int(* f_set_cache)(void *, const mbedtls_ssl_session *)
Callback to store a session into the cache.
Definition: ssl.h:501
const int * ciphersuite_list[4]
Definition: ssl.h:488
void mbedtls_ssl_conf_dhm_min_bitlen(mbedtls_ssl_config *conf, unsigned int bitlen)
Set the minimum length for Diffie-Hellman parameters.
int(* f_cookie_write)(void *, unsigned char **, unsigned char *, const unsigned char *, size_t)
Callback to create & write a cookie for ClientHello veirifcation.
Definition: ssl.h:524
void mbedtls_ssl_conf_dtls_cookies(mbedtls_ssl_config *conf, mbedtls_ssl_cookie_write_t *f_cookie_write, mbedtls_ssl_cookie_check_t *f_cookie_check, void *p_cookie)
Register callbacks for DTLS cookies (Server only.
mbedtls_ssl_key_cert * key_cert
Definition: ssl.h:543
int mbedtls_ssl_get_ciphersuite_id(const char *ciphersuite_name)
Return the ID of the ciphersuite associated with the given name.
void mbedtls_ssl_conf_transport(mbedtls_ssl_config *conf, int transport)
Set the transport type (TLS or DTLS).
mbedtls_ssl_session * session_negotiate
Definition: ssl.h:682
mbedtls_ssl_states
Definition: ssl.h:400
int(* f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t)
Callback to retrieve PSK key from identity.
Definition: ssl.h:518
void mbedtls_ssl_conf_sni(mbedtls_ssl_config *conf, int(*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *, size_t), void *p_sni)
Set server side ServerName TLS extension callback (optional, server-side only).
const int * sig_hashes
Definition: ssl.h:549
const int * mbedtls_ssl_list_ciphersuites(void)
Returns the list of ciphersuites supported by the SSL/TLS module.
void mbedtls_ssl_conf_renegotiation_enforced(mbedtls_ssl_config *conf, int max_records)
Enforce renegotiation requests.
int mbedtls_ssl_set_client_transport_id(mbedtls_ssl_context *ssl, const unsigned char *info, size_t ilen)
Set client's transport-level identification info.
size_t id_len
Definition: ssl.h:449
unsigned int encrypt_then_mac
Definition: ssl.h:620
int(* f_send)(void *, const unsigned char *, size_t)
Definition: ssl.h:671
void * p_bio
Definition: ssl.h:674
unsigned int cbc_record_splitting
Definition: ssl.h:629
int(* f_ticket_write)(void *, const mbedtls_ssl_session *, unsigned char *, const unsigned char *, size_t *, uint32_t *)
Callback to create & write a session ticket.
Definition: ssl.h:534
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 renego_status
Definition: ssl.h:655
int mbedtls_ssl_conf_alpn_protocols(mbedtls_ssl_config *conf, const char **protos)
Set the supported Application Layer Protocols.
unsigned char _pms_ecdhe_psk[4+MBEDTLS_ECP_MAX_BYTES+MBEDTLS_PSK_MAX_LEN]
Definition: ssl.h:387
void * p_vrfy
Definition: ssl.h:513
const mbedtls_x509_crt_profile * cert_profile
Definition: ssl.h:542
void * p_timer
Definition: ssl.h:698
Diffie-Hellman-Merkle key exchange.
void mbedtls_ssl_conf_session_cache(mbedtls_ssl_config *conf, void *p_cache, int(*f_get_cache)(void *, mbedtls_ssl_session *), int(*f_set_cache)(void *, const mbedtls_ssl_session *))
Set the session cache callbacks (server-side only) If not set, no session resuming is done (except if...
void(* f_set_timer)(void *, uint32_t, uint32_t)
Definition: ssl.h:699
#define MBEDTLS_PSK_MAX_LEN
Definition: ssl.h:357
unsigned int session_tickets
Definition: ssl.h:638
void mbedtls_ssl_conf_truncated_hmac(mbedtls_ssl_config *conf, int truncate)
Activate negotiation of truncated HMAC (Default: MBEDTLS_SSL_TRUNC_HMAC_DISABLED) ...
mbedtls_ssl_session * session
Definition: ssl.h:681
unsigned char * in_iv
Definition: ssl.h:711
char own_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]
Definition: ssl.h:787
void mbedtls_ssl_init(mbedtls_ssl_context *ssl)
Initialize an SSL context Just makes the context ready for mbetls_ssl_setup() or mbedtls_ssl_free() ...
mbedtls_ssl_transform * transform_negotiate
Definition: ssl.h:693
const char * mbedtls_ssl_get_ciphersuite(const mbedtls_ssl_context *ssl)
Return the name of the current ciphersuite.
mbedtls_ecp_group_id
Domain parameters (curve, subgroup and generator) identifiers.
Definition: ecp.h:54
unsigned char * out_ctr
Definition: ssl.h:737
int secure_renegotiation
Definition: ssl.h:783
DHM context structure.
Definition: dhm.h:150
const mbedtls_ssl_config * conf
Definition: ssl.h:648
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.
unsigned char * in_offt
Definition: ssl.h:713
unsigned int extended_ms
Definition: ssl.h:623
unsigned char max_major_ver
Definition: ssl.h:599
unsigned char * psk
Definition: ssl.h:562
void mbedtls_ssl_config_init(mbedtls_ssl_config *conf)
Initialize an SSL configuration context Just makes the context ready for mbedtls_ssl_config_defaults(...
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...
const char * alpn_chosen
Definition: ssl.h:768
Elliptic curve Diffie-Hellman.
int mbedtls_ssl_conf_dh_param_ctx(mbedtls_ssl_config *conf, mbedtls_dhm_context *dhm_ctx)
Set the Diffie-Hellman public P and G values, read from existing context (server-side only) ...
mbedtls_mpi dhm_G
Definition: ssl.h:558
int mbedtls_ssl_set_session(mbedtls_ssl_context *ssl, const mbedtls_ssl_session *session)
Request resumption of session (client-side only) Session data is copied from presented session struct...
#define MBEDTLS_MPI_MAX_SIZE
Maximum number of bytes for usable MPIs.
Definition: bignum.h:77
unsigned int disable_renegotiation
Definition: ssl.h:632
char * hostname
Definition: ssl.h:763
int mbedtls_ssl_set_hs_own_cert(mbedtls_ssl_context *ssl, mbedtls_x509_crt *own_cert, mbedtls_pk_context *pk_key)
Set own certificate and key for the current handshake.
int mbedtls_ssl_conf_dh_param(mbedtls_ssl_config *conf, const char *dhm_P, const char *dhm_G)
Set the Diffie-Hellman public P and G values, read as hexadecimal strings (server-side only) (Default...
void mbedtls_ssl_set_timer_cb(mbedtls_ssl_context *ssl, void *p_timer, void(*f_set_timer)(void *, uint32_t int_ms, uint32_t fin_ms), int(*f_get_timer)(void *))
Set the timer callbacks (Mandatory for DTLS.)
int mbedtls_ssl_conf_own_cert(mbedtls_ssl_config *conf, mbedtls_x509_crt *own_cert, mbedtls_pk_context *pk_key)
Set own certificate chain and private key.
int mbedtls_ssl_setup(mbedtls_ssl_context *ssl, const mbedtls_ssl_config *conf)
Set up an SSL context for use.
size_t out_msglen
Definition: ssl.h:744
uint32_t read_timeout
Definition: ssl.h:576
void mbedtls_ssl_conf_legacy_renegotiation(mbedtls_ssl_config *conf, int allow_legacy)
Prevent or allow legacy renegotiation.
unsigned char _pms_rsa_psk[52+MBEDTLS_PSK_MAX_LEN]
Definition: ssl.h:383
int mbedtls_ssl_renegotiate(mbedtls_ssl_context *ssl)
Initiate an SSL renegotiation on the running connection.
unsigned char * out_len
Definition: ssl.h:739
unsigned int arc4_disabled
Definition: ssl.h:614
int(* f_rng)(void *, unsigned char *, size_t)
Callback for getting (pseudo-)random numbers.
Definition: ssl.h:495
uint32_t hs_timeout_max
Definition: ssl.h:581
MPI structure.
Definition: bignum.h:144
int(* f_get_timer)(void *)
Definition: ssl.h:700
SSL/TLS configuration to be shared between mbedtls_ssl_context structures.
Definition: ssl.h:480
void mbedtls_ssl_conf_psk_cb(mbedtls_ssl_config *conf, int(*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t), void *p_psk)
Set the PSK callback (server-side only).
Container for an X.509 certificate.
Definition: x509_crt.h:53
int(* f_ticket_parse)(void *, mbedtls_ssl_session *, unsigned char *, size_t)
Callback to parse a session ticket into a session structure.
Definition: ssl.h:537
unsigned char * cli_id
Definition: ssl.h:775
int renego_max_records
Definition: ssl.h:586
mbedtls_x509_crt * ca_chain
Definition: ssl.h:544
void mbedtls_ssl_conf_read_timeout(mbedtls_ssl_config *conf, uint32_t timeout)
Set the timeout period for mbedtls_ssl_read() (Default: no timeout.)
size_t verify_data_len
Definition: ssl.h:786
void mbedtls_ssl_config_free(mbedtls_ssl_config *conf)
Free an SSL configuration context.
unsigned char * psk_identity
Definition: ssl.h:564
int mbedtls_ssl_read(mbedtls_ssl_context *ssl, unsigned char *buf, size_t len)
Read at most 'len' application data bytes.
size_t mbedtls_ssl_get_bytes_avail(const mbedtls_ssl_context *ssl)
Return the number of data bytes available to read.
unsigned char _pms_dhe_psk[4+MBEDTLS_MPI_MAX_SIZE+MBEDTLS_PSK_MAX_LEN]
Definition: ssl.h:380
size_t next_record_offset
Definition: ssl.h:720
unsigned char * out_buf
Definition: ssl.h:736
size_t psk_len
Definition: ssl.h:563
int(* f_get_cache)(void *, mbedtls_ssl_session *)
Callback to retrieve a session from the cache.
Definition: ssl.h:499
void mbedtls_ssl_session_init(mbedtls_ssl_session *session)
Initialize SSL session structure.
Security profile for certificate verification.
Definition: x509_crt.h:108
void * p_dbg
Definition: ssl.h:492
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:1061
size_t cli_id_len
Definition: ssl.h:776
void mbedtls_ssl_conf_handshake_timeout(mbedtls_ssl_config *conf, uint32_t min, uint32_t max)
Set retransmit timeout values for the DTLS handshale.
int mbedtls_ssl_config_defaults(mbedtls_ssl_config *conf, int endpoint, int transport, int preset)
Load reasonnable default SSL configuration values.
void mbedtls_ssl_conf_ca_chain(mbedtls_ssl_config *conf, mbedtls_x509_crt *ca_chain, mbedtls_x509_crl *ca_crl)
Set the data required to verify peer certificate.
void mbedtls_ssl_conf_curves(mbedtls_ssl_config *conf, const mbedtls_ecp_group_id *curves)
Set the allowed curves in order of preference.
int renego_records_seen
Definition: ssl.h:656
unsigned char * out_hdr
Definition: ssl.h:738
void mbedtls_ssl_conf_dtls_badmac_limit(mbedtls_ssl_config *conf, unsigned limit)
Set a limit on the number of records with a bad MAC before terminating the connection.
unsigned char _pms_psk[4+2 *MBEDTLS_PSK_MAX_LEN]
Definition: ssl.h:376
uint32_t verify_result
Definition: ssl.h:456
int mbedtls_ssl_handshake(mbedtls_ssl_context *ssl)
Perform the SSL handshake.
void mbedtls_ssl_set_hs_authmode(mbedtls_ssl_context *ssl, int authmode)
Set authmode for the current handshake.
unsigned int allow_legacy_renegotiation
Definition: ssl.h:612
signed char split_done
Definition: ssl.h:751
int mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl)
Perform a single step of the SSL handshake.
void mbedtls_ssl_set_bio(mbedtls_ssl_context *ssl, void *p_bio, int(*f_send)(void *, const unsigned char *, size_t), int(*f_recv)(void *, unsigned char *, size_t), int(*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t))
Set the underlying BIO callbacks for write, read and read-with-timeout.
const char * mbedtls_ssl_get_version(const mbedtls_ssl_context *ssl)
Return the current SSL version (SSLv3/TLSv1/etc)
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_session_reset(mbedtls_ssl_context *ssl)
Reset an already initialized SSL context for re-use while retaining application-set variables...
int mbedtls_ssl_set_hostname(mbedtls_ssl_context *ssl, const char *hostname)
Set hostname for ServerName TLS extension (client-side only)
#define MBEDTLS_ECP_MAX_BYTES
Definition: ecp.h:180
int mbedtls_ssl_set_hs_psk(mbedtls_ssl_context *ssl, const unsigned char *psk, size_t psk_len)
Set the Pre Shared Key (PSK) for the current handshake.
int mbedtls_ssl_get_session(const mbedtls_ssl_context *ssl, mbedtls_ssl_session *session)
Save session in order to resume it later (client-side only) Session data is copied to presented sessi...
void * p_ticket
Definition: ssl.h:538
void mbedtls_ssl_conf_ciphersuites(mbedtls_ssl_config *conf, const int *ciphersuites)
Set the list of allowed ciphersuites and the preference order.
#define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN
Definition: ssl.h:241
size_t in_msglen
Definition: ssl.h:716
uint16_t in_epoch
Definition: ssl.h:719