mbed TLS v2.1.2
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 /* For convenience below and in programs */
59 #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) || \
60  defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
61  defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
62  defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
63 #define MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED
64 #endif
65 
66 #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
67  defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
68  defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
69 #define MBEDTLS_KEY_EXCHANGE__SOME__ECDHE_ENABLED
70 #endif
71 
72 #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) || \
73  defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
74  defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
75 #define MBEDTLS_KEY_EXCHANGE__SOME__SIGNATURE_ENABLED
76 #endif
77 
78 /*
79  * SSL Error codes
80  */
81 #define MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE -0x7080
82 #define MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100
83 #define MBEDTLS_ERR_SSL_INVALID_MAC -0x7180
84 #define MBEDTLS_ERR_SSL_INVALID_RECORD -0x7200
85 #define MBEDTLS_ERR_SSL_CONN_EOF -0x7280
86 #define MBEDTLS_ERR_SSL_UNKNOWN_CIPHER -0x7300
87 #define MBEDTLS_ERR_SSL_NO_CIPHER_CHOSEN -0x7380
88 #define MBEDTLS_ERR_SSL_NO_RNG -0x7400
89 #define MBEDTLS_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480
90 #define MBEDTLS_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500
91 #define MBEDTLS_ERR_SSL_CERTIFICATE_REQUIRED -0x7580
92 #define MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600
93 #define MBEDTLS_ERR_SSL_CA_CHAIN_REQUIRED -0x7680
94 #define MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE -0x7700
95 #define MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780
96 #define MBEDTLS_ERR_SSL_PEER_VERIFY_FAILED -0x7800
97 #define MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880
98 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900
99 #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980
100 #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00
101 #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80
102 #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00
103 #define MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80
104 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00
105 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80
106 #define MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00
107 #define MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80
108 #define MBEDTLS_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00
109 #define MBEDTLS_ERR_SSL_BAD_HS_FINISHED -0x7E80
110 #define MBEDTLS_ERR_SSL_ALLOC_FAILED -0x7F00
111 #define MBEDTLS_ERR_SSL_HW_ACCEL_FAILED -0x7F80
112 #define MBEDTLS_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80
113 #define MBEDTLS_ERR_SSL_COMPRESSION_FAILED -0x6F00
114 #define MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80
115 #define MBEDTLS_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00
116 #define MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80
117 #define MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH -0x6D00
118 #define MBEDTLS_ERR_SSL_UNKNOWN_IDENTITY -0x6C80
119 #define MBEDTLS_ERR_SSL_INTERNAL_ERROR -0x6C00
120 #define MBEDTLS_ERR_SSL_COUNTER_WRAPPING -0x6B80
121 #define MBEDTLS_ERR_SSL_WAITING_SERVER_HELLO_RENEGO -0x6B00
122 #define MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED -0x6A80
123 #define MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL -0x6A00
124 #define MBEDTLS_ERR_SSL_NO_USABLE_CIPHERSUITE -0x6980
125 #define MBEDTLS_ERR_SSL_WANT_READ -0x6900
126 #define MBEDTLS_ERR_SSL_WANT_WRITE -0x6880
127 #define MBEDTLS_ERR_SSL_TIMEOUT -0x6800
128 #define MBEDTLS_ERR_SSL_CLIENT_RECONNECT -0x6780
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 #define MBEDTLS_SSL_MAX_HOST_NAME_LEN 255
144 /* RFC 6066 section 4, see also mfl_code_to_length in ssl_tls.c
145  * NONE must be zero so that memset()ing structure to zero works */
146 #define MBEDTLS_SSL_MAX_FRAG_LEN_NONE 0
147 #define MBEDTLS_SSL_MAX_FRAG_LEN_512 1
148 #define MBEDTLS_SSL_MAX_FRAG_LEN_1024 2
149 #define MBEDTLS_SSL_MAX_FRAG_LEN_2048 3
150 #define MBEDTLS_SSL_MAX_FRAG_LEN_4096 4
151 #define MBEDTLS_SSL_MAX_FRAG_LEN_INVALID 5
153 #define MBEDTLS_SSL_IS_CLIENT 0
154 #define MBEDTLS_SSL_IS_SERVER 1
155 
156 #define MBEDTLS_SSL_IS_NOT_FALLBACK 0
157 #define MBEDTLS_SSL_IS_FALLBACK 1
158 
159 #define MBEDTLS_SSL_EXTENDED_MS_DISABLED 0
160 #define MBEDTLS_SSL_EXTENDED_MS_ENABLED 1
161 
162 #define MBEDTLS_SSL_ETM_DISABLED 0
163 #define MBEDTLS_SSL_ETM_ENABLED 1
164 
165 #define MBEDTLS_SSL_COMPRESS_NULL 0
166 #define MBEDTLS_SSL_COMPRESS_DEFLATE 1
167 
168 #define MBEDTLS_SSL_VERIFY_NONE 0
169 #define MBEDTLS_SSL_VERIFY_OPTIONAL 1
170 #define MBEDTLS_SSL_VERIFY_REQUIRED 2
171 #define MBEDTLS_SSL_VERIFY_UNSET 3 /* Used only for sni_authmode */
172 
173 #define MBEDTLS_SSL_LEGACY_RENEGOTIATION 0
174 #define MBEDTLS_SSL_SECURE_RENEGOTIATION 1
175 
176 #define MBEDTLS_SSL_RENEGOTIATION_DISABLED 0
177 #define MBEDTLS_SSL_RENEGOTIATION_ENABLED 1
178 
179 #define MBEDTLS_SSL_ANTI_REPLAY_DISABLED 0
180 #define MBEDTLS_SSL_ANTI_REPLAY_ENABLED 1
181 
182 #define MBEDTLS_SSL_RENEGOTIATION_NOT_ENFORCED -1
183 #define MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT 16
184 
185 #define MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION 0
186 #define MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION 1
187 #define MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE 2
188 
189 #define MBEDTLS_SSL_TRUNC_HMAC_DISABLED 0
190 #define MBEDTLS_SSL_TRUNC_HMAC_ENABLED 1
191 #define MBEDTLS_SSL_TRUNCATED_HMAC_LEN 10 /* 80 bits, rfc 6066 section 7 */
192 
193 #define MBEDTLS_SSL_SESSION_TICKETS_DISABLED 0
194 #define MBEDTLS_SSL_SESSION_TICKETS_ENABLED 1
195 
196 #define MBEDTLS_SSL_CBC_RECORD_SPLITTING_DISABLED 0
197 #define MBEDTLS_SSL_CBC_RECORD_SPLITTING_ENABLED 1
198 
199 #define MBEDTLS_SSL_ARC4_ENABLED 0
200 #define MBEDTLS_SSL_ARC4_DISABLED 1
201 
202 #define MBEDTLS_SSL_PRESET_DEFAULT 0
203 #define MBEDTLS_SSL_PRESET_SUITEB 2
204 
205 /*
206  * Default range for DTLS retransmission timer value, in milliseconds.
207  * RFC 6347 4.2.4.1 says from 1 second to 60 seconds.
208  */
209 #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MIN 1000
210 #define MBEDTLS_SSL_DTLS_TIMEOUT_DFL_MAX 60000
211 
220 #if !defined(MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME)
221 #define MBEDTLS_SSL_DEFAULT_TICKET_LIFETIME 86400
222 #endif
223 
224 /*
225  * Maxium fragment length in bytes,
226  * determines the size of each of the two internal I/O buffers.
227  *
228  * Note: the RFC defines the default size of SSL / TLS messages. If you
229  * change the value here, other clients / servers may not be able to
230  * communicate with you anymore. Only change this value if you control
231  * both sides of the connection and have it reduced at both sides, or
232  * if you're using the Max Fragment Length extension and you know all your
233  * peers are using it too!
234  */
235 #if !defined(MBEDTLS_SSL_MAX_CONTENT_LEN)
236 #define MBEDTLS_SSL_MAX_CONTENT_LEN 16384
237 #endif
238 
239 /* \} name SECTION: Module settings */
240 
241 /*
242  * Length of the verify data for secure renegotiation
243  */
244 #if defined(MBEDTLS_SSL_PROTO_SSL3)
245 #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 36
246 #else
247 #define MBEDTLS_SSL_VERIFY_DATA_MAX_LEN 12
248 #endif
249 
250 /*
251  * Signaling ciphersuite values (SCSV)
252  */
253 #define MBEDTLS_SSL_EMPTY_RENEGOTIATION_INFO 0xFF
254 #define MBEDTLS_SSL_FALLBACK_SCSV_VALUE 0x5600
256 /*
257  * Supported Signature and Hash algorithms (For TLS 1.2)
258  * RFC 5246 section 7.4.1.4.1
259  */
260 #define MBEDTLS_SSL_HASH_NONE 0
261 #define MBEDTLS_SSL_HASH_MD5 1
262 #define MBEDTLS_SSL_HASH_SHA1 2
263 #define MBEDTLS_SSL_HASH_SHA224 3
264 #define MBEDTLS_SSL_HASH_SHA256 4
265 #define MBEDTLS_SSL_HASH_SHA384 5
266 #define MBEDTLS_SSL_HASH_SHA512 6
267 
268 #define MBEDTLS_SSL_SIG_ANON 0
269 #define MBEDTLS_SSL_SIG_RSA 1
270 #define MBEDTLS_SSL_SIG_ECDSA 3
271 
272 /*
273  * Client Certificate Types
274  * RFC 5246 section 7.4.4 plus RFC 4492 section 5.5
275  */
276 #define MBEDTLS_SSL_CERT_TYPE_RSA_SIGN 1
277 #define MBEDTLS_SSL_CERT_TYPE_ECDSA_SIGN 64
278 
279 /*
280  * Message, alert and handshake types
281  */
282 #define MBEDTLS_SSL_MSG_CHANGE_CIPHER_SPEC 20
283 #define MBEDTLS_SSL_MSG_ALERT 21
284 #define MBEDTLS_SSL_MSG_HANDSHAKE 22
285 #define MBEDTLS_SSL_MSG_APPLICATION_DATA 23
286 
287 #define MBEDTLS_SSL_ALERT_LEVEL_WARNING 1
288 #define MBEDTLS_SSL_ALERT_LEVEL_FATAL 2
289 
290 #define MBEDTLS_SSL_ALERT_MSG_CLOSE_NOTIFY 0 /* 0x00 */
291 #define MBEDTLS_SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10 /* 0x0A */
292 #define MBEDTLS_SSL_ALERT_MSG_BAD_RECORD_MAC 20 /* 0x14 */
293 #define MBEDTLS_SSL_ALERT_MSG_DECRYPTION_FAILED 21 /* 0x15 */
294 #define MBEDTLS_SSL_ALERT_MSG_RECORD_OVERFLOW 22 /* 0x16 */
295 #define MBEDTLS_SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30 /* 0x1E */
296 #define MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE 40 /* 0x28 */
297 #define MBEDTLS_SSL_ALERT_MSG_NO_CERT 41 /* 0x29 */
298 #define MBEDTLS_SSL_ALERT_MSG_BAD_CERT 42 /* 0x2A */
299 #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_CERT 43 /* 0x2B */
300 #define MBEDTLS_SSL_ALERT_MSG_CERT_REVOKED 44 /* 0x2C */
301 #define MBEDTLS_SSL_ALERT_MSG_CERT_EXPIRED 45 /* 0x2D */
302 #define MBEDTLS_SSL_ALERT_MSG_CERT_UNKNOWN 46 /* 0x2E */
303 #define MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER 47 /* 0x2F */
304 #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_CA 48 /* 0x30 */
305 #define MBEDTLS_SSL_ALERT_MSG_ACCESS_DENIED 49 /* 0x31 */
306 #define MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR 50 /* 0x32 */
307 #define MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR 51 /* 0x33 */
308 #define MBEDTLS_SSL_ALERT_MSG_EXPORT_RESTRICTION 60 /* 0x3C */
309 #define MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION 70 /* 0x46 */
310 #define MBEDTLS_SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71 /* 0x47 */
311 #define MBEDTLS_SSL_ALERT_MSG_INTERNAL_ERROR 80 /* 0x50 */
312 #define MBEDTLS_SSL_ALERT_MSG_INAPROPRIATE_FALLBACK 86 /* 0x56 */
313 #define MBEDTLS_SSL_ALERT_MSG_USER_CANCELED 90 /* 0x5A */
314 #define MBEDTLS_SSL_ALERT_MSG_NO_RENEGOTIATION 100 /* 0x64 */
315 #define MBEDTLS_SSL_ALERT_MSG_UNSUPPORTED_EXT 110 /* 0x6E */
316 #define MBEDTLS_SSL_ALERT_MSG_UNRECOGNIZED_NAME 112 /* 0x70 */
317 #define MBEDTLS_SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY 115 /* 0x73 */
318 #define MBEDTLS_SSL_ALERT_MSG_NO_APPLICATION_PROTOCOL 120 /* 0x78 */
319 
320 #define MBEDTLS_SSL_HS_HELLO_REQUEST 0
321 #define MBEDTLS_SSL_HS_CLIENT_HELLO 1
322 #define MBEDTLS_SSL_HS_SERVER_HELLO 2
323 #define MBEDTLS_SSL_HS_HELLO_VERIFY_REQUEST 3
324 #define MBEDTLS_SSL_HS_NEW_SESSION_TICKET 4
325 #define MBEDTLS_SSL_HS_CERTIFICATE 11
326 #define MBEDTLS_SSL_HS_SERVER_KEY_EXCHANGE 12
327 #define MBEDTLS_SSL_HS_CERTIFICATE_REQUEST 13
328 #define MBEDTLS_SSL_HS_SERVER_HELLO_DONE 14
329 #define MBEDTLS_SSL_HS_CERTIFICATE_VERIFY 15
330 #define MBEDTLS_SSL_HS_CLIENT_KEY_EXCHANGE 16
331 #define MBEDTLS_SSL_HS_FINISHED 20
332 
333 /*
334  * TLS extensions
335  */
336 #define MBEDTLS_TLS_EXT_SERVERNAME 0
337 #define MBEDTLS_TLS_EXT_SERVERNAME_HOSTNAME 0
338 
339 #define MBEDTLS_TLS_EXT_MAX_FRAGMENT_LENGTH 1
340 
341 #define MBEDTLS_TLS_EXT_TRUNCATED_HMAC 4
342 
343 #define MBEDTLS_TLS_EXT_SUPPORTED_ELLIPTIC_CURVES 10
344 #define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS 11
345 
346 #define MBEDTLS_TLS_EXT_SIG_ALG 13
347 
348 #define MBEDTLS_TLS_EXT_ALPN 16
349 
350 #define MBEDTLS_TLS_EXT_ENCRYPT_THEN_MAC 22 /* 0x16 */
351 #define MBEDTLS_TLS_EXT_EXTENDED_MASTER_SECRET 0x0017 /* 23 */
352 
353 #define MBEDTLS_TLS_EXT_SESSION_TICKET 35
354 
355 #define MBEDTLS_TLS_EXT_RENEGOTIATION_INFO 0xFF01
356 
357 /*
358  * Size defines
359  */
360 #if !defined(MBEDTLS_PSK_MAX_LEN)
361 #define MBEDTLS_PSK_MAX_LEN 32 /* 256 bits */
362 #endif
363 
364 /* Dummy type used only for its size */
366 {
367 #if defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED)
368  unsigned char _pms_rsa[48]; /* RFC 5246 8.1.1 */
369 #endif
370 #if defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED)
371  unsigned char _pms_dhm[MBEDTLS_MPI_MAX_SIZE]; /* RFC 5246 8.1.2 */
372 #endif
373 #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
374  defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) || \
375  defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
376  defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
377  unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]; /* RFC 4492 5.10 */
378 #endif
379 #if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
380  unsigned char _pms_psk[4 + 2 * MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 2 */
381 #endif
382 #if defined(MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED)
383  unsigned char _pms_dhe_psk[4 + MBEDTLS_MPI_MAX_SIZE
384  + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 3 */
385 #endif
386 #if defined(MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED)
387  unsigned char _pms_rsa_psk[52 + MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 4 */
388 #endif
389 #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
390  unsigned char _pms_ecdhe_psk[4 + MBEDTLS_ECP_MAX_BYTES
391  + MBEDTLS_PSK_MAX_LEN]; /* RFC 5489 2 */
392 #endif
393 };
394 
395 #define MBEDTLS_PREMASTER_SIZE sizeof( union mbedtls_ssl_premaster_secret )
396 
397 #ifdef __cplusplus
398 extern "C" {
399 #endif
400 
401 /*
402  * SSL state machine
403  */
404 typedef enum
405 {
425 }
427 
428 /* Defined below */
432 
433 /* Defined in ssl_internal.h */
436 #if defined(MBEDTLS_X509_CRT_PARSE_C)
438 #endif
439 #if defined(MBEDTLS_SSL_PROTO_DTLS)
441 #endif
442 
443 /*
444  * This structure is used for storing current session data.
445  */
447 {
448 #if defined(MBEDTLS_HAVE_TIME)
449  time_t start;
450 #endif
453  size_t id_len;
454  unsigned char id[32];
455  unsigned char master[48];
457 #if defined(MBEDTLS_X509_CRT_PARSE_C)
459 #endif /* MBEDTLS_X509_CRT_PARSE_C */
460  uint32_t verify_result;
462 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
463  unsigned char *ticket;
464  size_t ticket_len;
465  uint32_t ticket_lifetime;
466 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
467 
468 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
469  unsigned char mfl_code;
470 #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
471 
472 #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
474 #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
475 
476 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
478 #endif
479 };
480 
485 {
486  /* Group items by size (largest first) to minimize padding overhead */
487 
488  /*
489  * Pointers
490  */
491 
492  const int *ciphersuite_list[4];
495  void (*f_dbg)(void *, int, const char *, int, const char *);
496  void *p_dbg;
499  int (*f_rng)(void *, unsigned char *, size_t);
500  void *p_rng;
503  int (*f_get_cache)(void *, mbedtls_ssl_session *);
505  int (*f_set_cache)(void *, const mbedtls_ssl_session *);
506  void *p_cache;
508 #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
509 
510  int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
511  void *p_sni;
512 #endif
513 
514 #if defined(MBEDTLS_X509_CRT_PARSE_C)
515 
516  int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *);
517  void *p_vrfy;
518 #endif
519 
520 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
521 
522  int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t);
523  void *p_psk;
524 #endif
525 
526 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
527 
528  int (*f_cookie_write)( void *, unsigned char **, unsigned char *,
529  const unsigned char *, size_t );
531  int (*f_cookie_check)( void *, const unsigned char *, size_t,
532  const unsigned char *, size_t );
533  void *p_cookie;
534 #endif
535 
536 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
537 
538  int (*f_ticket_write)( void *, const mbedtls_ssl_session *,
539  unsigned char *, const unsigned char *, size_t *, uint32_t * );
541  int (*f_ticket_parse)( void *, mbedtls_ssl_session *, unsigned char *, size_t);
542  void *p_ticket;
543 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
544 
545 #if defined(MBEDTLS_X509_CRT_PARSE_C)
548  mbedtls_x509_crt *ca_chain;
550 #endif /* MBEDTLS_X509_CRT_PARSE_C */
551 
552 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__SIGNATURE_ENABLED)
553  const int *sig_hashes;
554 #endif
555 
556 #if defined(MBEDTLS_ECP_C)
558 #endif
559 
560 #if defined(MBEDTLS_DHM_C)
563 #endif
564 
565 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
566  unsigned char *psk;
567  size_t psk_len;
568  unsigned char *psk_identity;
570 #endif
571 
572 #if defined(MBEDTLS_SSL_ALPN)
573  const char **alpn_list;
574 #endif
575 
576  /*
577  * Numerical settings (int then char)
578  */
579 
580  uint32_t read_timeout;
582 #if defined(MBEDTLS_SSL_PROTO_DTLS)
583  uint32_t hs_timeout_min;
585  uint32_t hs_timeout_max;
587 #endif
588 
589 #if defined(MBEDTLS_SSL_RENEGOTIATION)
591  unsigned char renego_period[8];
593 #endif
594 
595 #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
596  unsigned int badmac_limit;
597 #endif
598 
599 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
600  unsigned int dhm_min_bitlen;
601 #endif
602 
603  unsigned char max_major_ver;
604  unsigned char max_minor_ver;
605  unsigned char min_major_ver;
606  unsigned char min_minor_ver;
608  /*
609  * Flags (bitfields)
610  */
611 
612  unsigned int endpoint : 1;
613  unsigned int transport : 1;
614  unsigned int authmode : 2;
615  /* needed even with renego disabled for LEGACY_BREAK_HANDSHAKE */
616  unsigned int allow_legacy_renegotiation : 2 ;
617 #if defined(MBEDTLS_ARC4_C)
618  unsigned int arc4_disabled : 1;
619 #endif
620 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
621  unsigned int mfl_code : 3;
622 #endif
623 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
624  unsigned int encrypt_then_mac : 1 ;
625 #endif
626 #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
627  unsigned int extended_ms : 1;
628 #endif
629 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
630  unsigned int anti_replay : 1;
631 #endif
632 #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
633  unsigned int cbc_record_splitting : 1;
634 #endif
635 #if defined(MBEDTLS_SSL_RENEGOTIATION)
636  unsigned int disable_renegotiation : 1;
637 #endif
638 #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
639  unsigned int trunc_hmac : 1;
640 #endif
641 #if defined(MBEDTLS_SSL_SESSION_TICKETS)
642  unsigned int session_tickets : 1;
643 #endif
644 #if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
645  unsigned int fallback : 1;
646 #endif
647 };
648 
649 
651 {
654  /*
655  * Miscellaneous
656  */
657  int state;
658 #if defined(MBEDTLS_SSL_RENEGOTIATION)
663 #endif
664 
665  int major_ver;
666  int minor_ver;
668 #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
669  unsigned badmac_seen;
670 #endif
671 
672  /*
673  * Callbacks
674  */
675  int (*f_send)(void *, const unsigned char *, size_t);
676  int (*f_recv)(void *, unsigned char *, size_t);
677  int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t);
678  void *p_bio;
680  /*
681  * Session layer
682  */
691  /*
692  * Record layer transformations
693  */
699  /*
700  * Timers
701  */
702  void *p_timer;
703  void (*f_set_timer)(void *, uint32_t, uint32_t);
704  int (*f_get_timer)(void *);
706  /*
707  * Record layer (incoming data)
708  */
709  unsigned char *in_buf;
710  unsigned char *in_ctr;
713  unsigned char *in_hdr;
714  unsigned char *in_len;
715  unsigned char *in_iv;
716  unsigned char *in_msg;
717  unsigned char *in_offt;
720  size_t in_msglen;
721  size_t in_left;
722 #if defined(MBEDTLS_SSL_PROTO_DTLS)
723  uint16_t in_epoch;
726 #endif
727 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
728  uint64_t in_window_top;
729  uint64_t in_window;
730 #endif
731 
732  size_t in_hslen;
734  int nb_zero;
737  /*
738  * Record layer (outgoing data)
739  */
740  unsigned char *out_buf;
741  unsigned char *out_ctr;
742  unsigned char *out_hdr;
743  unsigned char *out_len;
744  unsigned char *out_iv;
745  unsigned char *out_msg;
748  size_t out_msglen;
749  size_t out_left;
751 #if defined(MBEDTLS_ZLIB_SUPPORT)
752  unsigned char *compress_buf;
753 #endif
754 #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
755  signed char split_done;
756 #endif
757 
758  /*
759  * PKI layer
760  */
763  /*
764  * User settings
765  */
766 #if defined(MBEDTLS_X509_CRT_PARSE_C)
767  char *hostname;
769 #endif
770 
771 #if defined(MBEDTLS_SSL_ALPN)
772  const char *alpn_chosen;
773 #endif
774 
775  /*
776  * Information for DTLS hello verify
777  */
778 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
779  unsigned char *cli_id;
780  size_t cli_id_len;
781 #endif
782 
783  /*
784  * Secure renegotiation
785  */
786  /* needed to know when to send extension on server */
789 #if defined(MBEDTLS_SSL_RENEGOTIATION)
793 #endif
794 };
795 
796 #if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
797 
798 #define MBEDTLS_SSL_CHANNEL_OUTBOUND 0
799 #define MBEDTLS_SSL_CHANNEL_INBOUND 1
800 
801 extern int (*mbedtls_ssl_hw_record_init)(mbedtls_ssl_context *ssl,
802  const unsigned char *key_enc, const unsigned char *key_dec,
803  size_t keylen,
804  const unsigned char *iv_enc, const unsigned char *iv_dec,
805  size_t ivlen,
806  const unsigned char *mac_enc, const unsigned char *mac_dec,
807  size_t maclen);
808 extern int (*mbedtls_ssl_hw_record_activate)(mbedtls_ssl_context *ssl, int direction);
809 extern int (*mbedtls_ssl_hw_record_reset)(mbedtls_ssl_context *ssl);
810 extern int (*mbedtls_ssl_hw_record_write)(mbedtls_ssl_context *ssl);
811 extern int (*mbedtls_ssl_hw_record_read)(mbedtls_ssl_context *ssl);
812 extern int (*mbedtls_ssl_hw_record_finish)(mbedtls_ssl_context *ssl);
813 #endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
814 
821 const int *mbedtls_ssl_list_ciphersuites( void );
822 
831 const char *mbedtls_ssl_get_ciphersuite_name( const int ciphersuite_id );
832 
841 int mbedtls_ssl_get_ciphersuite_id( const char *ciphersuite_name );
842 
851 
868  const mbedtls_ssl_config *conf );
869 
881 
888 void mbedtls_ssl_conf_endpoint( mbedtls_ssl_config *conf, int endpoint );
889 
904 void mbedtls_ssl_conf_transport( mbedtls_ssl_config *conf, int transport );
905 
931 void mbedtls_ssl_conf_authmode( mbedtls_ssl_config *conf, int authmode );
932 
933 #if defined(MBEDTLS_X509_CRT_PARSE_C)
934 
946  int (*f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *),
947  void *p_vrfy );
948 #endif /* MBEDTLS_X509_CRT_PARSE_C */
949 
958  int (*f_rng)(void *, unsigned char *, size_t),
959  void *p_rng );
960 
976  void (*f_dbg)(void *, int, const char *, int, const char *),
977  void *p_dbg );
978 
1003  void *p_bio,
1004  int (*f_send)(void *, const unsigned char *, size_t),
1005  int (*f_recv)(void *, unsigned char *, size_t),
1006  int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t) );
1007 
1024 void mbedtls_ssl_conf_read_timeout( mbedtls_ssl_config *conf, uint32_t timeout );
1025 
1042  void *p_timer,
1043  void (*f_set_timer)(void *, uint32_t int_ms, uint32_t fin_ms),
1044  int (*f_get_timer)(void *) );
1045 
1065 typedef int mbedtls_ssl_ticket_write_t( void *p_ticket,
1066  const mbedtls_ssl_session *session,
1067  unsigned char *start,
1068  const unsigned char *end,
1069  size_t *tlen,
1070  uint32_t *lifetime );
1071 
1095 typedef int mbedtls_ssl_ticket_parse_t( void *p_ticket,
1096  mbedtls_ssl_session *session,
1097  unsigned char *buf,
1098  size_t len );
1099 
1100 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_SRV_C)
1101 
1116  mbedtls_ssl_ticket_write_t *f_ticket_write,
1117  mbedtls_ssl_ticket_parse_t *f_ticket_parse,
1118  void *p_ticket );
1119 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_SRV_C */
1120 
1135 typedef int mbedtls_ssl_cookie_write_t( void *ctx,
1136  unsigned char **p, unsigned char *end,
1137  const unsigned char *info, size_t ilen );
1138 
1152 typedef int mbedtls_ssl_cookie_check_t( void *ctx,
1153  const unsigned char *cookie, size_t clen,
1154  const unsigned char *info, size_t ilen );
1155 
1156 #if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY) && defined(MBEDTLS_SSL_SRV_C)
1157 
1186  mbedtls_ssl_cookie_write_t *f_cookie_write,
1187  mbedtls_ssl_cookie_check_t *f_cookie_check,
1188  void *p_cookie );
1189 
1210  const unsigned char *info,
1211  size_t ilen );
1212 
1213 #endif /* MBEDTLS_SSL_DTLS_HELLO_VERIFY && MBEDTLS_SSL_SRV_C */
1214 
1215 #if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
1216 
1231 void mbedtls_ssl_conf_dtls_anti_replay( mbedtls_ssl_config *conf, char mode );
1232 #endif /* MBEDTLS_SSL_DTLS_ANTI_REPLAY */
1233 
1234 #if defined(MBEDTLS_SSL_DTLS_BADMAC_LIMIT)
1235 
1258 void mbedtls_ssl_conf_dtls_badmac_limit( mbedtls_ssl_config *conf, unsigned limit );
1259 #endif /* MBEDTLS_SSL_DTLS_BADMAC_LIMIT */
1260 
1261 #if defined(MBEDTLS_SSL_PROTO_DTLS)
1262 
1278 void mbedtls_ssl_conf_handshake_timeout( mbedtls_ssl_config *conf, uint32_t min, uint32_t max );
1279 #endif /* MBEDTLS_SSL_PROTO_DTLS */
1280 
1281 #if defined(MBEDTLS_SSL_SRV_C)
1282 
1320  void *p_cache,
1321  int (*f_get_cache)(void *, mbedtls_ssl_session *),
1322  int (*f_set_cache)(void *, const mbedtls_ssl_session *) );
1323 #endif /* MBEDTLS_SSL_SRV_C */
1324 
1325 #if defined(MBEDTLS_SSL_CLI_C)
1326 
1341 #endif /* MBEDTLS_SSL_CLI_C */
1342 
1359  const int *ciphersuites );
1360 
1381  const int *ciphersuites,
1382  int major, int minor );
1383 
1384 #if defined(MBEDTLS_X509_CRT_PARSE_C)
1385 
1392  const mbedtls_x509_crt_profile *profile );
1393 
1402  mbedtls_x509_crt *ca_chain,
1403  mbedtls_x509_crl *ca_crl );
1404 
1429  mbedtls_x509_crt *own_cert,
1430  mbedtls_pk_context *pk_key );
1431 #endif /* MBEDTLS_X509_CRT_PARSE_C */
1432 
1433 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
1434 
1449  const unsigned char *psk, size_t psk_len,
1450  const unsigned char *psk_identity, size_t psk_identity_len );
1451 
1452 
1466  const unsigned char *psk, size_t psk_len );
1467 
1493  int (*f_psk)(void *, mbedtls_ssl_context *, const unsigned char *,
1494  size_t),
1495  void *p_psk );
1496 #endif /* MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED */
1497 
1498 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C)
1499 
1510 int mbedtls_ssl_conf_dh_param( mbedtls_ssl_config *conf, const char *dhm_P, const char *dhm_G );
1511 
1522 #endif /* MBEDTLS_DHM_C && defined(MBEDTLS_SSL_SRV_C) */
1523 
1524 #if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_CLI_C)
1525 
1534  unsigned int bitlen );
1535 #endif /* MBEDTLS_DHM_C && MBEDTLS_SSL_CLI_C */
1536 
1537 #if defined(MBEDTLS_ECP_C)
1538 
1568  const mbedtls_ecp_group_id *curves );
1569 #endif /* MBEDTLS_ECP_C */
1570 
1571 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__SIGNATURE_ENABLED)
1572 
1591  const int *hashes );
1592 #endif /* MBEDTLS_KEY_EXCHANGE__SOME__SIGNATURE_ENABLED */
1593 
1594 #if defined(MBEDTLS_X509_CRT_PARSE_C)
1595 
1605 int mbedtls_ssl_set_hostname( mbedtls_ssl_context *ssl, const char *hostname );
1606 #endif /* MBEDTLS_X509_CRT_PARSE_C */
1607 
1608 #if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
1609 
1622  mbedtls_x509_crt *own_cert,
1623  mbedtls_pk_context *pk_key );
1624 
1637  mbedtls_x509_crt *ca_chain,
1638  mbedtls_x509_crl *ca_crl );
1639 
1651  int authmode );
1652 
1677  int (*f_sni)(void *, mbedtls_ssl_context *, const unsigned char *,
1678  size_t),
1679  void *p_sni );
1680 #endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
1681 
1682 #if defined(MBEDTLS_SSL_ALPN)
1683 
1692 int mbedtls_ssl_conf_alpn_protocols( mbedtls_ssl_config *conf, const char **protos );
1693 
1703 const char *mbedtls_ssl_get_alpn_protocol( const mbedtls_ssl_context *ssl );
1704 #endif /* MBEDTLS_SSL_ALPN */
1705 
1722 void mbedtls_ssl_conf_max_version( mbedtls_ssl_config *conf, int major, int minor );
1723 
1742 void mbedtls_ssl_conf_min_version( mbedtls_ssl_config *conf, int major, int minor );
1743 
1744 #if defined(MBEDTLS_SSL_FALLBACK_SCSV) && defined(MBEDTLS_SSL_CLI_C)
1745 
1764 void mbedtls_ssl_conf_fallback( mbedtls_ssl_config *conf, char fallback );
1765 #endif /* MBEDTLS_SSL_FALLBACK_SCSV && MBEDTLS_SSL_CLI_C */
1766 
1767 #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
1768 
1780 #endif /* MBEDTLS_SSL_ENCRYPT_THEN_MAC */
1781 
1782 #if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
1783 
1795 #endif /* MBEDTLS_SSL_EXTENDED_MASTER_SECRET */
1796 
1797 #if defined(MBEDTLS_ARC4_C)
1798 
1811 void mbedtls_ssl_conf_arc4_support( mbedtls_ssl_config *conf, char arc4 );
1812 #endif /* MBEDTLS_ARC4_C */
1813 
1814 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
1815 
1830 int mbedtls_ssl_conf_max_frag_len( mbedtls_ssl_config *conf, unsigned char mfl_code );
1831 #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
1832 
1833 #if defined(MBEDTLS_SSL_TRUNCATED_HMAC)
1834 
1842 void mbedtls_ssl_conf_truncated_hmac( mbedtls_ssl_config *conf, int truncate );
1843 #endif /* MBEDTLS_SSL_TRUNCATED_HMAC */
1844 
1845 #if defined(MBEDTLS_SSL_CBC_RECORD_SPLITTING)
1846 
1858 #endif /* MBEDTLS_SSL_CBC_RECORD_SPLITTING */
1859 
1860 #if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
1861 
1871 void mbedtls_ssl_conf_session_tickets( mbedtls_ssl_config *conf, int use_tickets );
1872 #endif /* MBEDTLS_SSL_SESSION_TICKETS && MBEDTLS_SSL_CLI_C */
1873 
1874 #if defined(MBEDTLS_SSL_RENEGOTIATION)
1875 
1892 void mbedtls_ssl_conf_renegotiation( mbedtls_ssl_config *conf, int renegotiation );
1893 #endif /* MBEDTLS_SSL_RENEGOTIATION */
1894 
1922 void mbedtls_ssl_conf_legacy_renegotiation( mbedtls_ssl_config *conf, int allow_legacy );
1923 
1924 #if defined(MBEDTLS_SSL_RENEGOTIATION)
1925 
1962 void mbedtls_ssl_conf_renegotiation_enforced( mbedtls_ssl_config *conf, int max_records );
1963 
1982  const unsigned char period[8] );
1983 #endif /* MBEDTLS_SSL_RENEGOTIATION */
1984 
1993 
2005 uint32_t mbedtls_ssl_get_verify_result( const mbedtls_ssl_context *ssl );
2006 
2014 const char *mbedtls_ssl_get_ciphersuite( const mbedtls_ssl_context *ssl );
2015 
2023 const char *mbedtls_ssl_get_version( const mbedtls_ssl_context *ssl );
2024 
2036 
2037 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
2038 
2055 #endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
2056 
2057 #if defined(MBEDTLS_X509_CRT_PARSE_C)
2058 
2073 #endif /* MBEDTLS_X509_CRT_PARSE_C */
2074 
2075 #if defined(MBEDTLS_SSL_CLI_C)
2076 
2093 #endif /* MBEDTLS_SSL_CLI_C */
2094 
2116 
2131 
2132 #if defined(MBEDTLS_SSL_RENEGOTIATION)
2133 
2144 #endif /* MBEDTLS_SSL_RENEGOTIATION */
2145 
2173 int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len );
2174 
2204 int mbedtls_ssl_write( mbedtls_ssl_context *ssl, const unsigned char *buf, size_t len );
2205 
2217  unsigned char level,
2218  unsigned char message );
2225 
2232 
2244 
2262  int endpoint, int transport, int preset );
2263 
2270 
2277 
2285 
2286 #ifdef __cplusplus
2287 }
2288 #endif
2289 
2290 #endif /* ssl.h */
uint64_t in_window_top
Definition: ssl.h:728
time_t start
Definition: ssl.h:449
void * p_rng
Definition: ssl.h:500
const char ** alpn_list
Definition: ssl.h:573
unsigned int transport
Definition: ssl.h:613
unsigned char * in_ctr
Definition: ssl.h:710
mbedtls_x509_crt * peer_cert
Definition: ssl.h:458
unsigned char * out_msg
Definition: ssl.h:745
unsigned char master[48]
Definition: ssl.h:455
unsigned int trunc_hmac
Definition: ssl.h:639
unsigned char * in_len
Definition: ssl.h:714
unsigned char * in_buf
Definition: ssl.h:709
unsigned int endpoint
Definition: ssl.h:612
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:1095
mbedtls_mpi dhm_P
Definition: ssl.h:561
char peer_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]
Definition: ssl.h:792
unsigned char max_minor_ver
Definition: ssl.h:604
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:606
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:1135
unsigned char * in_hdr
Definition: ssl.h:713
size_t psk_identity_len
Definition: ssl.h:569
unsigned int dhm_min_bitlen
Definition: ssl.h:600
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:1152
void * p_sni
Definition: ssl.h:511
unsigned char * ticket
Definition: ssl.h:463
int(* f_get_timer)(void *)
Definition: ssl.h:704
int(* f_recv_timeout)(void *, unsigned char *, size_t, uint32_t)
Definition: ssl.h:677
size_t ticket_len
Definition: ssl.h:464
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:744
mbedtls_ssl_transform * transform_in
Definition: ssl.h:694
size_t in_left
Definition: ssl.h:721
unsigned int authmode
Definition: ssl.h:614
unsigned int badmac_limit
Definition: ssl.h:596
void * p_psk
Definition: ssl.h:523
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:630
unsigned int fallback
Definition: ssl.h:645
const mbedtls_ecp_group_id * curve_list
Definition: ssl.h:557
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) ...
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:528
Certificate revocation list structure.
Definition: x509_crl.h:69
int(* f_get_cache)(void *, mbedtls_ssl_session *)
Callback to retrieve a session from the cache.
Definition: ssl.h:503
unsigned char _pms_dhm[MBEDTLS_MPI_MAX_SIZE]
Definition: ssl.h:371
void(* f_dbg)(void *, int, const char *, int, const char *)
Callback for printing debug output.
Definition: ssl.h:495
void * p_cache
Definition: ssl.h:506
int(* f_sni)(void *, mbedtls_ssl_context *, const unsigned char *, size_t)
Callback for setting cert according to SNI extension.
Definition: ssl.h:510
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:368
unsigned char _pms_ecdh[MBEDTLS_ECP_MAX_BYTES]
Definition: ssl.h:377
unsigned char renego_period[8]
Definition: ssl.h:591
uint32_t ticket_lifetime
Definition: ssl.h:465
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:683
unsigned badmac_seen
Definition: ssl.h:669
void mbedtls_ssl_conf_dtls_anti_replay(mbedtls_ssl_config *conf, char mode)
Enable or disable anti-replay protection for DTLS.
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:549
mbedtls_ssl_session * session_out
Definition: ssl.h:684
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.
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:538
mbedtls_ssl_transform * transform_out
Definition: ssl.h:695
unsigned char mfl_code
Definition: ssl.h:469
void mbedtls_ssl_conf_renegotiation_period(mbedtls_ssl_config *conf, const unsigned char period[8])
Set record counter threshold for periodic renegotiation.
int(* f_recv)(void *, unsigned char *, size_t)
Definition: ssl.h:676
unsigned int mfl_code
Definition: ssl.h:621
int(* f_set_cache)(void *, const mbedtls_ssl_session *)
Callback to store a session into the cache.
Definition: ssl.h:505
Multi-precision integer library.
int encrypt_then_mac
Definition: ssl.h:477
size_t in_hslen
Definition: ssl.h:732
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 '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)
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:531
uint64_t in_window
Definition: ssl.h:729
int mbedtls_ssl_close_notify(mbedtls_ssl_context *ssl)
Notify the peer that the connection is being closed.
void * p_cookie
Definition: ssl.h:533
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:696
uint32_t hs_timeout_min
Definition: ssl.h:583
mbedtls_ssl_handshake_params * handshake
Definition: ssl.h:688
void mbedtls_ssl_free(mbedtls_ssl_context *ssl)
Free referenced items in an SSL context and clear memory.
void mbedtls_ssl_conf_endpoint(mbedtls_ssl_config *conf, int endpoint)
Set the current endpoint type.
size_t out_left
Definition: ssl.h:749
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:716
int(* f_send)(void *, const unsigned char *, size_t)
Definition: ssl.h:675
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:605
const char * mbedtls_ssl_get_alpn_protocol(const mbedtls_ssl_context *ssl)
Get the name of the negotiated Application Layer Protocol.
const int * ciphersuite_list[4]
Definition: ssl.h:492
int(* f_rng)(void *, unsigned char *, size_t)
Callback for getting (pseudo-)random numbers.
Definition: ssl.h:499
void mbedtls_ssl_conf_dhm_min_bitlen(mbedtls_ssl_config *conf, unsigned int bitlen)
Set the minimum length for Diffie-Hellman parameters.
void(* f_set_timer)(void *, uint32_t, uint32_t)
Definition: ssl.h:703
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:547
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:686
mbedtls_ssl_states
Definition: ssl.h:404
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:553
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:453
unsigned int encrypt_then_mac
Definition: ssl.h:624
void * p_bio
Definition: ssl.h:678
unsigned int cbc_record_splitting
Definition: ssl.h:633
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:659
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.
unsigned char _pms_ecdhe_psk[4+MBEDTLS_ECP_MAX_BYTES+MBEDTLS_PSK_MAX_LEN]
Definition: ssl.h:391
void * p_vrfy
Definition: ssl.h:517
const mbedtls_x509_crt_profile * cert_profile
Definition: ssl.h:546
void * p_timer
Definition: ssl.h:702
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...
#define MBEDTLS_PSK_MAX_LEN
Definition: ssl.h:361
unsigned int session_tickets
Definition: ssl.h:642
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:685
unsigned char * in_iv
Definition: ssl.h:715
char own_verify_data[MBEDTLS_SSL_VERIFY_DATA_MAX_LEN]
Definition: ssl.h:791
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:697
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:741
int secure_renegotiation
Definition: ssl.h:787
DHM context structure.
Definition: dhm.h:149
const mbedtls_ssl_config * conf
Definition: ssl.h:652
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.
int(* f_psk)(void *, mbedtls_ssl_context *, const unsigned char *, size_t)
Callback to retrieve PSK key from identity.
Definition: ssl.h:522
unsigned char * in_offt
Definition: ssl.h:717
unsigned int extended_ms
Definition: ssl.h:627
unsigned char max_major_ver
Definition: ssl.h:603
unsigned char * psk
Definition: ssl.h:566
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:772
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:562
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
unsigned int disable_renegotiation
Definition: ssl.h:636
char * hostname
Definition: ssl.h:767
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:748
uint32_t read_timeout
Definition: ssl.h:580
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:387
int mbedtls_ssl_renegotiate(mbedtls_ssl_context *ssl)
Initiate an SSL renegotiation on the running connection.
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:541
unsigned char * out_len
Definition: ssl.h:743
int(* f_vrfy)(void *, mbedtls_x509_crt *, int, uint32_t *)
Callback to customize X.509 certificate chain verification.
Definition: ssl.h:516
unsigned int arc4_disabled
Definition: ssl.h:618
uint32_t hs_timeout_max
Definition: ssl.h:585
MPI structure.
Definition: bignum.h:143
SSL/TLS configuration to be shared between mbedtls_ssl_context structures.
Definition: ssl.h:484
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:52
unsigned char * cli_id
Definition: ssl.h:779
int renego_max_records
Definition: ssl.h:590
mbedtls_x509_crt * ca_chain
Definition: ssl.h:548
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:790
void mbedtls_ssl_config_free(mbedtls_ssl_config *conf)
Free an SSL configuration context.
unsigned char * psk_identity
Definition: ssl.h:568
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:384
size_t next_record_offset
Definition: ssl.h:724
unsigned char * out_buf
Definition: ssl.h:740
size_t psk_len
Definition: ssl.h:567
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:496
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:1065
size_t cli_id_len
Definition: ssl.h:780
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:660
unsigned char * out_hdr
Definition: ssl.h:742
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:380
uint32_t verify_result
Definition: ssl.h:460
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:616
signed char split_done
Definition: ssl.h:755
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: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:542
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:247
size_t in_msglen
Definition: ssl.h:720
uint16_t in_epoch
Definition: ssl.h:723