mbed TLS v2.3.0
ssl.h
Go to the documentation of this file.
1 
23 #ifndef MBEDTLS_SSL_H
24 #define MBEDTLS_SSL_H
25 
26 #if !defined(MBEDTLS_CONFIG_FILE)
27 #include "config.h"
28 #else
29 #include MBEDTLS_CONFIG_FILE
30 #endif
31 
32 #include "bignum.h"
33 #include "ecp.h"
34 
35 #include "ssl_ciphersuites.h"
36 
37 #if defined(MBEDTLS_X509_CRT_PARSE_C)
38 #include "x509_crt.h"
39 #include "x509_crl.h"
40 #endif
41 
42 #if defined(MBEDTLS_DHM_C)
43 #include "dhm.h"
44 #endif
45 
46 #if defined(MBEDTLS_ECDH_C)
47 #include "ecdh.h"
48 #endif
49 
50 #if defined(MBEDTLS_ZLIB_SUPPORT)
51 #include "zlib.h"
52 #endif
53 
54 #if defined(MBEDTLS_HAVE_TIME)
55 #include <time.h>
56 #endif
57 
58 /*
59  * SSL Error codes
60  */
61 #define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080
62 #define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100
63 #define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180
64 #define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200
65 #define MBEDTLS_ERR_SSL_CONN_EOF -0x7280
66 #define MBEDTLS_ERR_SSL_UNKNOWN_CIPHER -0x7300
67 #define MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN -0x7380
68 #define MBEDTLS_ERR_SSL_NO_RNG -0x7400
69 #define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480
70 #define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500
71 #define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580
72 #define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600
73 #define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680
74 #define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700
75 #define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780
76 #define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800
77 #define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880
78 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900
79 #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980
80 #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00
81 #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80
82 #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00
83 #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80
84 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00
85 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80
86 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00
87 #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80
88 #define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00
89 #define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80
90 #define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00
91 #define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80
92 #define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80
93 #define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00
94 #define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80
95 #define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00
96 #define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80
97 #define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00
98 #define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80
99 #define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00
100 #define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80
101 #define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00
102 #define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80
103 #define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00
104 #define MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6980
105 #define MBEDTLS_ERR_SSL_WANT_READ -0x6900
106 #define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880
107 #define MBEDTLS_ERR_SSL_TIMEOUT -0x6800
108 #define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780
109 #define MBEDTLS_ERR_SSL_UNEXPECTED_RECORD -0x6700
111 /*
112  * Various constants
113  */
114 #define MBEDTLS_SSL_MAJOR_VERSION_3 3
115 #define MBEDTLS_SSL_MINOR_VERSION_0 0
116 #define MBEDTLS_SSL_MINOR_VERSION_1 1
117 #define MBEDTLS_SSL_MINOR_VERSION_2 2
118 #define MBEDTLS_SSL_MINOR_VERSION_3 3
120 #define MBEDTLS_SSL_TRANSPORT_STREAM 0
121 #define MBEDTLS_SSL_TRANSPORT_DATAGRAM 1
123 #define MBEDTLS_SSL_MAX_HOST_NAME_LEN 255
125 /* RFC 6066 section 4, see also mfl_code_to_length in ssl_tls.c
126  * NONE must be zero so that memset()ing structure to zero works */
127 #define MBEDTLS_SSL_MAX_FRAG_LEN_NONE 0
128 #define MBEDTLS_SSL_MAX_FRAG_LEN_512 1
129 #define MBEDTLS_SSL_MAX_FRAG_LEN_1024 2
130 #define MBEDTLS_SSL_MAX_FRAG_LEN_2048 3
131 #define MBEDTLS_SSL_MAX_FRAG_LEN_4096 4
132 #define MBEDTLS_SSL_MAX_FRAG_LEN_INVALID 5
134 #define MBEDTLS_SSL_IS_CLIENT 0
135 #define MBEDTLS_SSL_IS_SERVER 1
136 
137 #define MBEDTLS_SSL_IS_NOT_FALLBACK 0
138 #define MBEDTLS_SSL_IS_FALLBACK 1
139 
140 #define MBEDTLS_SSL_EXTENDED_MS_DISABLED 0
141 #define MBEDTLS_SSL_EXTENDED_MS_ENABLED 1
142 
143 #define MBEDTLS_SSL_ETM_DISABLED 0
144 #define MBEDTLS_SSL_ETM_ENABLED 1
145 
146 #define MBEDTLS_SSL_COMPRESS_NULL 0
147 #define MBEDTLS_SSL_COMPRESS_DEFLATE 1
148 
149 #define MBEDTLS_SSL_VERIFY_NONE 0
150 #define MBEDTLS_SSL_VERIFY_OPTIONAL 1
151 #define MBEDTLS_SSL_VERIFY_REQUIRED 2
152 #define MBEDTLS_SSL_VERIFY_UNSET 3 /* Used only for sni_authmode */
153 
154 #define MBEDTLS_SSL_LEGACY_RENEGOTIATION 0
155 #define MBEDTLS_SSL_SECURE_RENEGOTIATION 1
156 
157 #define MBEDTLS_SSL_RENEGOTIATION_DISABLED 0
158 #define MBEDTLS_SSL_RENEGOTIATION_ENABLED 1
159 
160 #define MBEDTLS_SSL_ANTI_REPLAY_DISABLED 0
161 #define MBEDTLS_SSL_ANTI_REPLAY_ENABLED 1
162 
163 #define MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED -1
164 #define MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT 16
165 
166 #define MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION 0
167 #define MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION 1
168 #define MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE 2
169 
170 #define MBEDTLS_SSL_TRUNC_HMAC_DISABLED 0
171 #define MBEDTLS_SSL_TRUNC_HMAC_ENABLED 1
172 #define MBEDTLS_SSL_TRUNCATED_HMAC_LEN 10 /* 80 bits, rfc 6066 section 7 */
173 
174 #define MBEDTLS_SSL_SESSION_TICKETS_DISABLED 0
175 #define MBEDTLS_SSL_SESSION_TICKETS_ENABLED 1
176 
177 #define MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED 0
178 #define MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED 1
179 
180 #define MBEDTLS_SSL_ARC4_ENABLED 0
181 #define MBEDTLS_SSL_ARC4_DISABLED 1
182 
183 #define MBEDTLS_SSL_PRESET_DEFAULT 0
184 #define MBEDTLS_SSL_PRESET_SUITEB 2
185 
186 /*
187  * Default range for DTLS retransmission timer value, in milliseconds.
188  * RFC 6347 4.2.4.1 says from 1 second to 60 seconds.
189  */
190 #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN 1000
191 #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX 60000
192 
201 #if !defined(MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME)
202 #define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400
203 #endif
204 
205 /*
206  * Maxium fragment length in bytes,
207  * determines the size of each of the two internal I/O buffers.
208  *
209  * Note: the RFC defines the default size of SSL / TLS messages. If you
210  * change the value here, other clients / servers may not be able to
211  * communicate with you anymore. Only change this value if you control
212  * both sides of the connection and have it reduced at both sides, or
213  * if you're using the Max Fragment Length extension and you know all your
214  * peers are using it too!
215  */
216 #if !defined(MBEDTLS_SSL_MAX_CONTENT_LEN)
217 #define MBEDTLS_SSL_MAX_CONTENT_LEN 16384
218 #endif
219 
220 /* \} name SECTION: Module settings */
221 
222 /*
223  * Length of the verify data for secure renegotiation
224  */
225 #if defined(MBEDTLS_SSL_PROTO_SSL3)
226 #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 36
227 #else
228 #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 12
229 #endif
230 
231 /*
232  * Signaling ciphersuite values (SCSV)
233  */
234 #define MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO 0xFF
235 #define MBEDTLS_SSL_FALLBACK_SCSV_VALUE 0x5600
237 /*
238  * Supported Signature and Hash algorithms (For TLS 1.2)
239  * RFC 5246 section 7.4.1.4.1
240  */
241 #define MBEDTLS_SSL_HASH_NONE 0
242 #define MBEDTLS_SSL_HASH_MD5 1
243 #define MBEDTLS_SSL_HASH_SHA1 2
244 #define MBEDTLS_SSL_HASH_SHA224 3
245 #define MBEDTLS_SSL_HASH_SHA256 4
246 #define MBEDTLS_SSL_HASH_SHA384 5
247 #define MBEDTLS_SSL_HASH_SHA512 6
248 
249 #define MBEDTLS_SSL_SIG_ANON 0
250 #define MBEDTLS_SSL_SIG_RSA 1
251 #define MBEDTLS_SSL_SIG_ECDSA 3
252 
253 /*
254  * Client Certificate Types
255  * RFC 5246 section 7.4.4 plus RFC 4492 section 5.5
256  */
257 #define MBEDTLS_SSL_CERT_TYPE_RSA_SIGN 1
258 #define MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN 64
259 
260 /*
261  * Message, alert and handshake types
262  */
263 #define MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC 20
264 #define MBEDTLS_SSL_MSG_ALERT 21
265 #define MBEDTLS_SSL_MSG_HANDSHAKE 22
266 #define MBEDTLS_SSL_MSG_APPLICATION_DATA 23
267 
268 #define MBEDTLS_SSL_ALERT_LEVEL_WARNING 1
269 #define MBEDTLS_SSL_ALERT_LEVEL_FATAL 2
270 
271 #define MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY 0 /* 0x00 */
272 #define MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10 /* 0x0A */
273 #define MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC 20 /* 0x14 */
274 #define MBEDTLS_SSL_ALERT_MSG_DECRYPTION_FAILED 21 /* 0x15 */
275 #define MBEDTLS_SSL_ALERT_MSG_RECORD_OVERFLOW 22 /* 0x16 */
276 #define MBEDTLS_SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30 /* 0x1E */
277 #define MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE 40 /* 0x28 */
278 #define MBEDTLS_SSL_ALERT_MSG_NO_CERT 41 /* 0x29 */
279 #define MBEDTLS_SSL_ALERT_MSG_BAD_CERT 42 /* 0x2A */
280 #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT 43 /* 0x2B */
281 #define MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED 44 /* 0x2C */
282 #define MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED 45 /* 0x2D */
283 #define MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN 46 /* 0x2E */
284 #define MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER 47 /* 0x2F */
285 #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_CA 48 /* 0x30 */
286 #define MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED 49 /* 0x31 */
287 #define MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR 50 /* 0x32 */
288 #define MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR 51 /* 0x33 */
289 #define MBEDTLS_SSL_ALERT_MSG_EXPORT_RESTRICTION 60 /* 0x3C */
290 #define MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION 70 /* 0x46 */
291 #define MBEDTLS_SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71 /* 0x47 */
292 #define MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR 80 /* 0x50 */
293 #define MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK 86 /* 0x56 */
294 #define MBEDTLS_SSL_ALERT_MSG_USER_CANCELED 90 /* 0x5A */
295 #define MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION 100 /* 0x64 */
296 #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT 110 /* 0x6E */
297 #define MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME 112 /* 0x70 */
298 #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY 115 /* 0x73 */
299 #define MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL 120 /* 0x78 */
300 
301 #define MBEDTLS_SSL_HS_HELLO_REQUEST 0
302 #define MBEDTLS_SSL_HS_CLIENT_HELLO 1
303 #define MBEDTLS_SSL_HS_SERVER_HELLO 2
304 #define MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST 3
305 #define MBEDTLS_SSL_HS_NEW_SESSION_TICKET 4
306 #define MBEDTLS_SSL_HS_CERTIFICATE 11
307 #define MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE 12
308 #define MBEDTLS_SSL_HS_CERTIFICATE_REQUEST 13
309 #define MBEDTLS_SSL_HS_SERVER_HELLO_DONE 14
310 #define MBEDTLS_SSL_HS_CERTIFICATE_VERIFY 15
311 #define MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE 16
312 #define MBEDTLS_SSL_HS_FINISHED 20
313 
314 /*
315  * TLS extensions
316  */
317 #define MBEDTLS_TLS_EXT_SERVERNAME 0
318 #define MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME 0
319 
320 #define MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH 1
321 
322 #define MBEDTLS_TLS_EXT_TRUNCATED_HMAC 4
323 
324 #define MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES 10
325 #define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS 11
326 
327 #define MBEDTLS_TLS_EXT_SIG_ALG 13
328 
329 #define MBEDTLS_TLS_EXT_ALPN 16
330 
331 #define MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC 22 /* 0x16 */
332 #define MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET 0x0017 /* 23 */
333 
334 #define MBEDTLS_TLS_EXT_SESSION_TICKET 35
335 
336 #define MBEDTLS_TLS_EXT_ECJPAKE_KKPP 256 /* experimental */
337 
338 #define MBEDTLS_TLS_EXT_RENEGOTIATION_INFO 0xFF01
339 
340 /*
341  * Size defines
342  */
343 #if !defined(MBEDTLS_PSK_MAX_LEN)
344 #define MBEDTLS_PSK_MAX_LEN 32 /* 256 bits */
345 #endif
346 
347 /* Dummy type used only for its size */
349 {
350 #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
351  unsigned char _pms_rsa[48]; /* RFC 5246 8.1.1 */
352 #endif
353 #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED)
354  unsigned char _pms_dhm[MBEDTLS_MPI_MAX_SIZE]; /* RFC 5246 8.1.2 */
355 #endif
356 #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
357  defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
358  defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
359  defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
360  unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]; /* RFC 4492 5.10 */
361 #endif
362 #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
363  unsigned char _pms_psk[4 + 2 * MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 2 */
364 #endif
365 #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
366  unsigned char _pms_dhe_psk[4 + MBEDTLS_MPI_MAX_SIZE
367  + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 3 */
368 #endif
369 #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)
370  unsigned char _pms_rsa_psk[52 + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 4 */
371 #endif
372 #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
373  unsigned char _pms_ecdhe_psk[4 + MBEDTLS_ECP_MAX_BYTES
374  + MBEDTLS_PSK_MAX_LEN]; /* RFC 5489 2 */
375 #endif
376 #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
377  unsigned char _pms_ecjpake[32]; /* Thread spec: SHA-256 output */
378 #endif
379 };
380 
381 #define MBEDTLS_PREMASTER_SIZE sizeof( union mbedtls_ssl_premaster_secret )
382 
383 #ifdef __cplusplus
384 extern "C" {
385 #endif
386 
387 /*
388  * SSL state machine
389  */
390 typedef enum
391 {
411 }
413 
431 typedef int mbedtls_ssl_send_t( void *ctx,
432  const unsigned char *buf,
433  size_t len );
434 
454 typedef int mbedtls_ssl_recv_t( void *ctx,
455  unsigned char *buf,
456  size_t len );
457 
480 typedef int mbedtls_ssl_recv_timeout_t( void *ctx,
481  unsigned char *buf,
482  size_t len,
483  uint32_t timeout );
506 typedef void mbedtls_ssl_set_timer_t( void * ctx,
507  uint32_t int_ms,
508  uint32_t fin_ms );
509 
521 typedef int mbedtls_ssl_get_timer_t( void * ctx );
522 
523 
524 /* Defined below */
528 
529 /* Defined in ssl_internal.h */
532 #if defined(MBEDTLS_X509_CRT_PARSE_C)
534 #endif
535 #if defined(MBEDTLS_SSL_PROTO_DTLS)
537 #endif
538 
539 /*
540  * This structure is used for storing current session data.
541  */
543 {
544 #if defined(MBEDTLS_HAVE_TIME)
546 #endif
549  size_t id_len;
550  unsigned char id[32];
551  unsigned char master[48];
553 #if defined(MBEDTLS_X509_CRT_PARSE_C)
555 #endif /* MBEDTLS_X509_CRT_PARSE_C */
556  uint32_t verify_result;
558 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
559  unsigned char *ticket;
560  size_t ticket_len;
561  uint32_t ticket_lifetime;
562 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
563 
564 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
565  unsigned char mfl_code;
566 #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
567 
568 #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
570 #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
571 
572 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
574 #endif
575 };
576 
581 {
582  /* Group items by size (largest first) to minimize padding overhead */
583 
584  /*
585  * Pointers
586  */
587 
588  const int *ciphersuite_list[4];
591  void (*f_dbg)(void *, int, const char *, int, const char *);
592  void *p_dbg;
595  int (*f_rng)(void *, unsigned char *, size_t);
596  void *p_rng;
599  int (*f_get_cache)(void *, mbedtls_ssl_session *);
601  int (*f_set_cache)(void *, const mbedtls_ssl_session *);
602  void *p_cache;
604 #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
605 
606  int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
607  void *p_sni;
608 #endif
609 
610 #if defined(MBEDTLS_X509_CRT_PARSE_C)
611 
612  int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *);
613  void *p_vrfy;
614 #endif
615 
616 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
617 
618  int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
619  void *p_psk;
620 #endif
621 
622 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
623 
624  int (*f_cookie_write)( void *, unsigned char **, unsigned char *,
625  const unsigned char *, size_t );
627  int (*f_cookie_check)( void *, const unsigned char *, size_t,
628  const unsigned char *, size_t );
629  void *p_cookie;
630 #endif
631 
632 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
633 
634  int (*f_ticket_write)( void *, const mbedtls_ssl_session *,
635  unsigned char *, const unsigned char *, size_t *, uint32_t * );
637  int (*f_ticket_parse)( void *, mbedtls_ssl_session *, unsigned char *, size_t);
638  void *p_ticket;
639 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
640 
641 #if defined(MBEDTLS_SSL_EXPORT_KEYS)
642 
643  int (*f_export_keys)( void *, const unsigned char *,
644  const unsigned char *, size_t, size_t, size_t );
646 #endif
647 
648 #if defined(MBEDTLS_X509_CRT_PARSE_C)
651  mbedtls_x509_crt *ca_chain;
653 #endif /* MBEDTLS_X509_CRT_PARSE_C */
654 
655 #if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
656  const int *sig_hashes;
657 #endif
658 
659 #if defined(MBEDTLS_ECP_C)
661 #endif
662 
663 #if defined(MBEDTLS_DHM_C)
666 #endif
667 
668 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
669  unsigned char *psk;
670  size_t psk_len;
671  unsigned char *psk_identity;
673 #endif
674 
675 #if defined(MBEDTLS_SSL_ALPN)
676  const char **alpn_list;
677 #endif
678 
679  /*
680  * Numerical settings (int then char)
681  */
682 
683  uint32_t read_timeout;
685 #if defined(MBEDTLS_SSL_PROTO_DTLS)
686  uint32_t hs_timeout_min;
688  uint32_t hs_timeout_max;
690 #endif
691 
692 #if defined(MBEDTLS_SSL_RENEGOTIATION)
694  unsigned char renego_period[8];
696 #endif
697 
698 #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
699  unsigned int badmac_limit;
700 #endif
701 
702 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
703  unsigned int dhm_min_bitlen;
704 #endif
705 
706  unsigned char max_major_ver;
707  unsigned char max_minor_ver;
708  unsigned char min_major_ver;
709  unsigned char min_minor_ver;
711  /*
712  * Flags (bitfields)
713  */
714 
715  unsigned int endpoint : 1;
716  unsigned int transport : 1;
717  unsigned int authmode : 2;
718  /* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */
719  unsigned int allow_legacy_renegotiation : 2 ;
720 #if defined(MBEDTLS_ARC4_C)
721  unsigned int arc4_disabled : 1;
722 #endif
723 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
724  unsigned int mfl_code : 3;
725 #endif
726 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
727  unsigned int encrypt_then_mac : 1 ;
728 #endif
729 #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
730  unsigned int extended_ms : 1;
731 #endif
732 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
733  unsigned int anti_replay : 1;
734 #endif
735 #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
736  unsigned int cbc_record_splitting : 1;
737 #endif
738 #if defined(MBEDTLS_SSL_RENEGOTIATION)
739  unsigned int disable_renegotiation : 1;
740 #endif
741 #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
742  unsigned int trunc_hmac : 1;
743 #endif
744 #if defined(MBEDTLS_SSL_SESSION_TICKETS)
745  unsigned int session_tickets : 1;
746 #endif
747 #if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
748  unsigned int fallback : 1;
749 #endif
750 };
751 
752 
754 {
757  /*
758  * Miscellaneous
759  */
760  int state;
761 #if defined(MBEDTLS_SSL_RENEGOTIATION)
766 #endif
767 
768  int major_ver;
769  int minor_ver;
771 #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
772  unsigned badmac_seen;
773 #endif
774 
780  void *p_bio;
782  /*
783  * Session layer
784  */
793  /*
794  * Record layer transformations
795  */
801  /*
802  * Timers
803  */
804  void *p_timer;
809  /*
810  * Record layer (incoming data)
811  */
812  unsigned char *in_buf;
813  unsigned char *in_ctr;
816  unsigned char *in_hdr;
817  unsigned char *in_len;
818  unsigned char *in_iv;
819  unsigned char *in_msg;
820  unsigned char *in_offt;
823  size_t in_msglen;
824  size_t in_left;
825 #if defined(MBEDTLS_SSL_PROTO_DTLS)
826  uint16_t in_epoch;
829 #endif
830 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
831  uint64_t in_window_top;
832  uint64_t in_window;
833 #endif
834 
835  size_t in_hslen;
837  int nb_zero;
840  /*
841  * Record layer (outgoing data)
842  */
843  unsigned char *out_buf;
844  unsigned char *out_ctr;
845  unsigned char *out_hdr;
846  unsigned char *out_len;
847  unsigned char *out_iv;
848  unsigned char *out_msg;
851  size_t out_msglen;
852  size_t out_left;
854 #if defined(MBEDTLS_ZLIB_SUPPORT)
855  unsigned char *compress_buf;
856 #endif
857 #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
858  signed char split_done;
859 #endif
860 
861  /*
862  * PKI layer
863  */
866  /*
867  * User settings
868  */
869 #if defined(MBEDTLS_X509_CRT_PARSE_C)
870  char *hostname;
872 #endif
873 
874 #if defined(MBEDTLS_SSL_ALPN)
875  const char *alpn_chosen;
876 #endif
877 
878  /*
879  * Information for DTLS hello verify
880  */
881 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
882  unsigned char *cli_id;
883  size_t cli_id_len;
884 #endif
885 
886  /*
887  * Secure renegotiation
888  */
889  /* needed to know when to send extension on server */
892 #if defined(MBEDTLS_SSL_RENEGOTIATION)
894  char own_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN];
895  char peer_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN];
896 #endif
897 };
898 
899 #if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
900 
901 #define MBEDTLS_SSL_CHANNEL_OUTBOUND 0
902 #define MBEDTLS_SSL_CHANNEL_INBOUND 1
903 
904 extern int (*mbedtls_ssl_hw_record_init)(mbedtls_ssl_context *ssl,
905  const unsigned char *key_enc, const unsigned char *key_dec,
906  size_t keylen,
907  const unsigned char *iv_enc, const unsigned char *iv_dec,
908  size_t ivlen,
909  const unsigned char *mac_enc, const unsigned char *mac_dec,
910  size_t maclen);
911 extern int (*mbedtls_ssl_hw_record_activate)(mbedtls_ssl_context *ssl, int direction);
912 extern int (*mbedtls_ssl_hw_record_reset)(mbedtls_ssl_context *ssl);
913 extern int (*mbedtls_ssl_hw_record_write)(mbedtls_ssl_context *ssl);
914 extern int (*mbedtls_ssl_hw_record_read)(mbedtls_ssl_context *ssl);
915 extern int (*mbedtls_ssl_hw_record_finish)(mbedtls_ssl_context *ssl);
916 #endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
917 
924 const int *mbedtls_ssl_list_ciphersuites( void );
925 
934 const char *mbedtls_ssl_get_ciphersuite_name( const int ciphersuite_id );
935 
944 int mbedtls_ssl_get_ciphersuite_id( const char *ciphersuite_name );
945 
954 
971  const mbedtls_ssl_config *conf );
972 
984 
991 void mbedtls_ssl_conf_endpoint( mbedtls_ssl_config *conf, int endpoint );
992 
1007 void mbedtls_ssl_conf_transport( mbedtls_ssl_config *conf, int transport );
1008 
1035 void mbedtls_ssl_conf_authmode( mbedtls_ssl_config *conf, int authmode );
1036 
1037 #if defined(MBEDTLS_X509_CRT_PARSE_C)
1038 
1050  int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
1051  void *p_vrfy );
1052 #endif /* MBEDTLS_X509_CRT_PARSE_C */
1053 
1062  int (*f_rng)(void *, unsigned char *, size_t),
1063  void *p_rng );
1064 
1080  void (*f_dbg)(void *, int, const char *, int, const char *),
1081  void *p_dbg );
1082 
1113  void *p_bio,
1114  mbedtls_ssl_send_t *f_send,
1115  mbedtls_ssl_recv_t *f_recv,
1116  mbedtls_ssl_recv_timeout_t *f_recv_timeout );
1117 
1134 void mbedtls_ssl_conf_read_timeout( mbedtls_ssl_config *conf, uint32_t timeout );
1135 
1157  void *p_timer,
1158  mbedtls_ssl_set_timer_t *f_set_timer,
1159  mbedtls_ssl_get_timer_t *f_get_timer );
1160 
1180 typedef int mbedtls_ssl_ticket_write_t( void *p_ticket,
1181  const mbedtls_ssl_session *session,
1182  unsigned char *start,
1183  const unsigned char *end,
1184  size_t *tlen,
1185  uint32_t *lifetime );
1186 
1187 #if defined(MBEDTLS_SSL_EXPORT_KEYS)
1188 
1208 typedef int mbedtls_ssl_export_keys_t( void *p_expkey,
1209  const unsigned char *ms,
1210  const unsigned char *kb,
1211  size_t maclen,
1212  size_t keylen,
1213  size_t ivlen );
1214 #endif /* MBEDTLS_SSL_EXPORT_KEYS */
1215 
1239 typedef int mbedtls_ssl_ticket_parse_t( void *p_ticket,
1240  mbedtls_ssl_session *session,
1241  unsigned char *buf,
1242  size_t len );
1243 
1244 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
1245 
1260  mbedtls_ssl_ticket_write_t *f_ticket_write,
1261  mbedtls_ssl_ticket_parse_t *f_ticket_parse,
1262  void *p_ticket );
1263 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
1264 
1265 #if defined(MBEDTLS_SSL_EXPORT_KEYS)
1266 
1277  mbedtls_ssl_export_keys_t *f_export_keys,
1278  void *p_export_keys );
1279 #endif /* MBEDTLS_SSL_EXPORT_KEYS */
1280 
1295 typedef int mbedtls_ssl_cookie_write_t( void *ctx,
1296  unsigned char **p, unsigned char *end,
1297  const unsigned char *info, size_t ilen );
1298 
1312 typedef int mbedtls_ssl_cookie_check_t( void *ctx,
1313  const unsigned char *cookie, size_t clen,
1314  const unsigned char *info, size_t ilen );
1315 
1316 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
1317 
1346  mbedtls_ssl_cookie_write_t *f_cookie_write,
1347  mbedtls_ssl_cookie_check_t *f_cookie_check,
1348  void *p_cookie );
1349 
1370  const unsigned char *info,
1371  size_t ilen );
1372 
1373 #endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
1374 
1375 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
1376 
1391 void mbedtls_ssl_conf_dtls_anti_replay( mbedtls_ssl_config *conf, char mode );
1392 #endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
1393 
1394 #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
1395 
1418 void mbedtls_ssl_conf_dtls_badmac_limit( mbedtls_ssl_config *conf, unsigned limit );
1419 #endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
1420 
1421 #if defined(MBEDTLS_SSL_PROTO_DTLS)
1422 
1453 void mbedtls_ssl_conf_handshake_timeout( mbedtls_ssl_config *conf, uint32_t min, uint32_t max );
1454 #endif /* MBEDTLS_SSL_PROTO_DTLS */
1455 
1456 #if defined(MBEDTLS_SSL_SRV_C)
1457 
1495  void *p_cache,
1496  int (*f_get_cache)(void *, mbedtls_ssl_session *),
1497  int (*f_set_cache)(void *, const mbedtls_ssl_session *) );
1498 #endif /* MBEDTLS_SSL_SRV_C */
1499 
1500 #if defined(MBEDTLS_SSL_CLI_C)
1501 
1516 #endif /* MBEDTLS_SSL_CLI_C */
1517 
1534  const int *ciphersuites );
1535 
1556  const int *ciphersuites,
1557  int major, int minor );
1558 
1559 #if defined(MBEDTLS_X509_CRT_PARSE_C)
1560 
1571  const mbedtls_x509_crt_profile *profile );
1572 
1581  mbedtls_x509_crt *ca_chain,
1582  mbedtls_x509_crl *ca_crl );
1583 
1613  mbedtls_x509_crt *own_cert,
1614  mbedtls_pk_context *pk_key );
1615 #endif /* MBEDTLS_X509_CRT_PARSE_C */
1616 
1617 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
1618 
1639  const unsigned char *psk, size_t psk_len,
1640  const unsigned char *psk_identity, size_t psk_identity_len );
1641 
1642 
1656  const unsigned char *psk, size_t psk_len );
1657 
1683  int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *,
1684  size_t),
1685  void *p_psk );
1686 #endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */
1687 
1688 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C)
1689 
1700 int mbedtls_ssl_conf_dh_param( mbedtls_ssl_config *conf, const char *dhm_P, const char *dhm_G );
1701 
1712 #endif /* MBEDTLS_DHM_C && defined(MBEDTLS_SSL_SRV_C) */
1713 
1714 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
1715 
1724  unsigned int bitlen );
1725 #endif /* MBEDTLS_DHM_C && MBEDTLS_SSL_CLI_C */
1726 
1727 #if defined(MBEDTLS_ECP_C)
1728 
1756  const mbedtls_ecp_group_id *curves );
1757 #endif /* MBEDTLS_ECP_C */
1758 
1759 #if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED)
1760 
1779  const int *hashes );
1780 #endif /* MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED */
1781 
1782 #if defined(MBEDTLS_X509_CRT_PARSE_C)
1783 
1794 int mbedtls_ssl_set_hostname( mbedtls_ssl_context *ssl, const char *hostname );
1795 #endif /* MBEDTLS_X509_CRT_PARSE_C */
1796 
1797 #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
1798 
1811  mbedtls_x509_crt *own_cert,
1812  mbedtls_pk_context *pk_key );
1813 
1826  mbedtls_x509_crt *ca_chain,
1827  mbedtls_x509_crl *ca_crl );
1828 
1840  int authmode );
1841 
1866  int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *,
1867  size_t),
1868  void *p_sni );
1869 #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
1870 
1871 #if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
1872 
1889 int mbedtls_ssl_set_hs_ecjpake_password( mbedtls_ssl_context *ssl,
1890  const unsigned char *pw,
1891  size_t pw_len );
1892 #endif /*MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
1893 
1894 #if defined(MBEDTLS_SSL_ALPN)
1895 
1907 int mbedtls_ssl_conf_alpn_protocols( mbedtls_ssl_config *conf, const char **protos );
1908 
1918 const char *mbedtls_ssl_get_alpn_protocol( const mbedtls_ssl_context *ssl );
1919 #endif /* MBEDTLS_SSL_ALPN */
1920 
1937 void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int minor );
1938 
1957 void mbedtls_ssl_conf_min_version( mbedtls_ssl_config *conf, int major, int minor );
1958 
1959 #if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
1960 
1979 void mbedtls_ssl_conf_fallback( mbedtls_ssl_config *conf, char fallback );
1980 #endif /* MBEDTLS_SSL_FALLBACK_SCSV && MBEDTLS_SSL_CLI_C */
1981 
1982 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1983 
1995 #endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
1996 
1997 #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
1998 
2010 #endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */
2011 
2012 #if defined(MBEDTLS_ARC4_C)
2013 
2028 void mbedtls_ssl_conf_arc4_support( mbedtls_ssl_config *conf, char arc4 );
2029 #endif /* MBEDTLS_ARC4_C */
2030 
2031 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
2032 
2047 int mbedtls_ssl_conf_max_frag_len( mbedtls_ssl_config *conf, unsigned char mfl_code );
2048 #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
2049 
2050 #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
2051 
2059 void mbedtls_ssl_conf_truncated_hmac( mbedtls_ssl_config *conf, int truncate );
2060 #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
2061 
2062 #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
2063 
2075 #endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */
2076 
2077 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
2078 
2088 void mbedtls_ssl_conf_session_tickets( mbedtls_ssl_config *conf, int use_tickets );
2089 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
2090 
2091 #if defined(MBEDTLS_SSL_RENEGOTIATION)
2092 
2109 void mbedtls_ssl_conf_renegotiation( mbedtls_ssl_config *conf, int renegotiation );
2110 #endif /* MBEDTLS_SSL_RENEGOTIATION */
2111 
2139 void mbedtls_ssl_conf_legacy_renegotiation( mbedtls_ssl_config *conf, int allow_legacy );
2140 
2141 #if defined(MBEDTLS_SSL_RENEGOTIATION)
2142 
2179 void mbedtls_ssl_conf_renegotiation_enforced( mbedtls_ssl_config *conf, int max_records );
2180 
2199  const unsigned char period[8] );
2200 #endif /* MBEDTLS_SSL_RENEGOTIATION */
2201 
2210 
2222 uint32_t mbedtls_ssl_get_verify_result( const mbedtls_ssl_context *ssl );
2223 
2231 const char *mbedtls_ssl_get_ciphersuite( const mbedtls_ssl_context *ssl );
2232 
2240 const char *mbedtls_ssl_get_version( const mbedtls_ssl_context *ssl );
2241 
2253 
2254 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
2255 
2272 #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
2273 
2274 #if defined(MBEDTLS_X509_CRT_PARSE_C)
2275 
2290 #endif /* MBEDTLS_X509_CRT_PARSE_C */
2291 
2292 #if defined(MBEDTLS_SSL_CLI_C)
2293 
2310 #endif /* MBEDTLS_SSL_CLI_C */
2311 
2334 
2355 
2356 #if defined(MBEDTLS_SSL_RENEGOTIATION)
2357 
2376 #endif /* MBEDTLS_SSL_RENEGOTIATION */
2377 
2412 int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len );
2413 
2449 int mbedtls_ssl_write( mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len );
2450 
2468  unsigned char level,
2469  unsigned char message );
2484 
2491 
2503 
2521  int endpoint, int transport, int preset );
2522 
2529 
2536 
2544 
2545 #ifdef __cplusplus
2546 }
2547 #endif
2548 
2549 #endif /* ssl.h */
uint64_t in_window_top
Definition: ssl.h:831
mbedtls_ssl_send_t * f_send
Definition: ssl.h:775
void * p_rng
Definition: ssl.h:596
const char ** alpn_list
Definition: ssl.h:676
unsigned char * in_ctr
Definition: ssl.h:813
mbedtls_x509_crt * peer_cert
Definition: ssl.h:554
unsigned char * out_msg
Definition: ssl.h:848
unsigned char * in_len
Definition: ssl.h:817
unsigned char * in_buf
Definition: ssl.h:812
Public key container.
Definition: pk.h:126
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:1239
mbedtls_mpi dhm_P
Definition: ssl.h:664
unsigned char max_minor_ver
Definition: ssl.h:707
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:709
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:1295
unsigned char * in_hdr
Definition: ssl.h:816
size_t psk_identity_len
Definition: ssl.h:672
unsigned int dhm_min_bitlen
Definition: ssl.h:703
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:1312
void * p_sni
Definition: ssl.h:607
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.)
unsigned char * ticket
Definition: ssl.h:559
size_t ticket_len
Definition: ssl.h:560
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:847
mbedtls_ssl_transform * transform_in
Definition: ssl.h:796
size_t in_left
Definition: ssl.h:824
int mbedtls_ssl_send_t(void *ctx, const unsigned char *buf, size_t len)
Callback type: send data on the network.
Definition: ssl.h:431
unsigned int badmac_limit
Definition: ssl.h:699
void * p_psk
Definition: ssl.h:619
void mbedtls_ssl_conf_fallback(mbedtls_ssl_config *conf, char fallback)
Set the fallback flag (client-side only).
int mbedtls_ssl_recv_t(void *ctx, unsigned char *buf, size_t len)
Callback type: receive data from the network.
Definition: ssl.h:454
const mbedtls_ecp_group_id * curve_list
Definition: ssl.h:660
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:69
unsigned char _pms_dhm[MBEDTLS_MPI_MAX_SIZE]
Definition: ssl.h:354
void * p_cache
Definition: ssl.h:602
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:351
unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]
Definition: ssl.h:360
uint32_t ticket_lifetime
Definition: ssl.h:561
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:785
unsigned badmac_seen
Definition: ssl.h:772
void mbedtls_ssl_conf_dtls_anti_replay(mbedtls_ssl_config *conf, char mode)
Enable or disable anti-replay protection for DTLS.
mbedtls_ssl_get_timer_t * f_get_timer
Definition: ssl.h:807
Configuration options (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:652
mbedtls_ssl_session * session_out
Definition: ssl.h:786
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.
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:480
SSL Ciphersuites for mbed TLS.
mbedtls_ssl_transform * transform_out
Definition: ssl.h:797
unsigned char mfl_code
Definition: ssl.h:565
void mbedtls_ssl_conf_renegotiation_period(mbedtls_ssl_config *conf, const unsigned char period[8])
Set record counter threshold for periodic renegotiation.
Multi-precision integer library.
int encrypt_then_mac
Definition: ssl.h:573
size_t in_hslen
Definition: ssl.h:835
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 mbedtls_ssl_write(mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len)
Try to write exactly &#39;len&#39; 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:832
int mbedtls_ssl_close_notify(mbedtls_ssl_context *ssl)
Notify the peer that the connection is being closed.
struct mbedtls_ssl_flight_item mbedtls_ssl_flight_item
Definition: ssl.h:536
void * p_cookie
Definition: ssl.h:629
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:798
uint32_t hs_timeout_min
Definition: ssl.h:686
mbedtls_ssl_handshake_params * handshake
Definition: ssl.h:790
void mbedtls_ssl_free(mbedtls_ssl_context *ssl)
Free referenced items in an SSL context and clear memory.
void mbedtls_ssl_conf_export_keys_cb(mbedtls_ssl_config *conf, mbedtls_ssl_export_keys_t *f_export_keys, void *p_export_keys)
Configure key export callback.
void mbedtls_ssl_conf_endpoint(mbedtls_ssl_config *conf, int endpoint)
Set the current endpoint type.
size_t out_left
Definition: ssl.h:852
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:819
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:708
struct mbedtls_ssl_transform mbedtls_ssl_transform
Definition: ssl.h:530
mbedtls_ssl_set_timer_t * f_set_timer
Definition: ssl.h:806
const char * mbedtls_ssl_get_alpn_protocol(const mbedtls_ssl_context *ssl)
Get the name of the negotiated Application Layer Protocol.
void mbedtls_ssl_conf_dhm_min_bitlen(mbedtls_ssl_config *conf, unsigned int bitlen)
Set the minimum length for Diffie-Hellman parameters.
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:650
mbedtls_ssl_recv_t * f_recv
Definition: ssl.h:776
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:788
mbedtls_ssl_states
Definition: ssl.h:390
const int * sig_hashes
Definition: ssl.h:656
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.
unsigned char _pms_ecdhe_psk[4+MBEDTLS_ECP_MAX_BYTES +MBEDTLS_PSK_MAX_LEN]
Definition: ssl.h:374
int mbedtls_ssl_set_client_transport_id(mbedtls_ssl_context *ssl, const unsigned char *info, size_t ilen)
Set client&#39;s transport-level identification info.
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.
size_t id_len
Definition: ssl.h:549
void mbedtls_ssl_conf_psk_cb(mbedtls_ssl_config *conf, int(*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t), void *p_psk)
Set the PSK callback (server-side only).
void * p_bio
Definition: ssl.h:780
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:762
int mbedtls_ssl_conf_alpn_protocols(mbedtls_ssl_config *conf, const char **protos)
Set the supported Application Layer Protocols.
void mbedtls_ssl_conf_cert_profile(mbedtls_ssl_config *conf, const mbedtls_x509_crt_profile *profile)
Set the X.509 security profile used for verification.
void * p_vrfy
Definition: ssl.h:613
const mbedtls_x509_crt_profile * cert_profile
Definition: ssl.h:649
void * p_timer
Definition: ssl.h:804
Diffie-Hellman-Merkle key exchange.
X.509 certificate parsing and writing.
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...
#define MBEDTLS_PSK_MAX_LEN
Definition: ssl.h:344
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:787
unsigned char * in_iv
Definition: ssl.h:818
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() ...
mbedtls_ssl_transform * transform_negotiate
Definition: ssl.h:799
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:53
unsigned char * out_ctr
Definition: ssl.h:844
int secure_renegotiation
Definition: ssl.h:890
int mbedtls_ssl_get_timer_t(void *ctx)
Callback type: get status of timers/delays.
Definition: ssl.h:521
DHM context structure.
Definition: dhm.h:149
const mbedtls_ssl_config * conf
Definition: ssl.h:755
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:820
unsigned char max_major_ver
Definition: ssl.h:706
unsigned char * psk
Definition: ssl.h:669
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:875
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:665
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:76
void * p_export_keys
Definition: ssl.h:645
char * hostname
Definition: ssl.h:870
unsigned char _pms_dhe_psk[4+MBEDTLS_MPI_MAX_SIZE +MBEDTLS_PSK_MAX_LEN]
Definition: ssl.h:367
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...
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:851
uint32_t read_timeout
Definition: ssl.h:683
void mbedtls_ssl_conf_legacy_renegotiation(mbedtls_ssl_config *conf, int allow_legacy)
Prevent or allow legacy renegotiation.
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).
unsigned char _pms_rsa_psk[52+MBEDTLS_PSK_MAX_LEN]
Definition: ssl.h:370
int mbedtls_ssl_renegotiate(mbedtls_ssl_context *ssl)
Initiate an SSL renegotiation on the running connection.
int mbedtls_ssl_export_keys_t(void *p_expkey, const unsigned char *ms, const unsigned char *kb, size_t maclen, size_t keylen, size_t ivlen)
Callback type: Export key block and master secret.
Definition: ssl.h:1208
unsigned char * out_len
Definition: ssl.h:846
uint32_t hs_timeout_max
Definition: ssl.h:688
MPI structure.
Definition: bignum.h:144
X.509 certificate revocation list parsing.
SSL/TLS configuration to be shared between mbedtls_ssl_context structures.
Definition: ssl.h:580
Container for an X.509 certificate.
Definition: x509_crt.h:52
time_t mbedtls_time_t
Definition: platform.h:254
unsigned char * cli_id
Definition: ssl.h:882
int renego_max_records
Definition: ssl.h:693
mbedtls_ssl_recv_timeout_t * f_recv_timeout
Definition: ssl.h:777
mbedtls_x509_crt * ca_chain
Definition: ssl.h:651
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:893
void mbedtls_ssl_config_free(mbedtls_ssl_config *conf)
Free an SSL configuration context.
unsigned char * psk_identity
Definition: ssl.h:671
int mbedtls_ssl_read(mbedtls_ssl_context *ssl, unsigned char *buf, size_t len)
Read at most &#39;len&#39; application data bytes.
struct mbedtls_ssl_key_cert mbedtls_ssl_key_cert
Definition: ssl.h:533
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:506
size_t mbedtls_ssl_get_bytes_avail(const mbedtls_ssl_context *ssl)
Return the number of data bytes available to read.
size_t next_record_offset
Definition: ssl.h:827
unsigned char * out_buf
Definition: ssl.h:843
size_t psk_len
Definition: ssl.h:670
void mbedtls_ssl_session_init(mbedtls_ssl_session *session)
Initialize SSL session structure.
Security profile for certificate verification.
Definition: x509_crt.h:107
void * p_dbg
Definition: ssl.h:592
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:1180
size_t cli_id_len
Definition: ssl.h:883
void mbedtls_ssl_conf_handshake_timeout(mbedtls_ssl_config *conf, uint32_t min, uint32_t max)
Set retransmit timeout values for the DTLS handshake.
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:763
unsigned char * out_hdr
Definition: ssl.h:845
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:363
uint32_t verify_result
Definition: ssl.h:556
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.
signed char split_done
Definition: ssl.h:858
int mbedtls_ssl_handshake_step(mbedtls_ssl_context *ssl)
Perform a single step of the SSL handshake.
const char * mbedtls_ssl_get_version(const mbedtls_ssl_context *ssl)
Return the current 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 the hostname to check against the received server certificate.
struct mbedtls_ssl_handshake_params mbedtls_ssl_handshake_params
Definition: ssl.h:531
#define MBEDTLS_ECP_MAX_BYTES
Definition: ecp.h:179
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:638
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_max_frag_len(const mbedtls_ssl_context *ssl)
Return the maximum fragment length (payload, in bytes).
#define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN
Definition: ssl.h:228
mbedtls_time_t start
Definition: ssl.h:545
size_t in_msglen
Definition: ssl.h:823
uint16_t in_epoch
Definition: ssl.h:826