PolarSSL v1.3.2
ssl.h
Go to the documentation of this file.
1 
27 #ifndef POLARSSL_SSL_H
28 #define POLARSSL_SSL_H
29 
30 #include "config.h"
31 #include "net.h"
32 #include "bignum.h"
33 
34 #include "ssl_ciphersuites.h"
35 
36 #if defined(POLARSSL_MD5_C)
37 #include "md5.h"
38 #endif
39 
40 #if defined(POLARSSL_SHA1_C)
41 #include "sha1.h"
42 #endif
43 
44 #if defined(POLARSSL_SHA256_C)
45 #include "sha256.h"
46 #endif
47 
48 #if defined(POLARSSL_SHA512_C)
49 #include "sha512.h"
50 #endif
51 
52 // for session tickets
53 #if defined(POLARSSL_AES_C)
54 #include "aes.h"
55 #endif
56 
57 #if defined(POLARSSL_X509_CRT_PARSE_C)
58 #include "x509_crt.h"
59 #include "x509_crl.h"
60 #endif
61 
62 #if defined(POLARSSL_DHM_C)
63 #include "dhm.h"
64 #endif
65 
66 #if defined(POLARSSL_ECDH_C)
67 #include "ecdh.h"
68 #endif
69 
70 #if defined(POLARSSL_ZLIB_SUPPORT)
71 #include "zlib.h"
72 #endif
73 
74 #if defined(POLARSSL_HAVE_TIME)
75 #include <time.h>
76 #endif
77 
78 /* For convenience below and in programs */
79 #if defined(POLARSSL_KEY_EXCHANGE_PSK_ENABLED) || \
80  defined(POLARSSL_KEY_EXCHANGE_RSA_PSK_ENABLED) || \
81  defined(POLARSSL_KEY_EXCHANGE_DHE_PSK_ENABLED) || \
82  defined(POLARSSL_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
83 #define POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED
84 #endif
85 
86 #if defined(_MSC_VER) && !defined(inline)
87 #define inline _inline
88 #else
89 #if defined(__ARMCC_VERSION) && !defined(inline)
90 #define inline __inline
91 #endif /* __ARMCC_VERSION */
92 #endif /*_MSC_VER */
93 
94 /*
95  * SSL Error codes
96  */
97 #define POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE -0x7080
98 #define POLARSSL_ERR_SSL_BAD_INPUT_DATA -0x7100
99 #define POLARSSL_ERR_SSL_INVALID_MAC -0x7180
100 #define POLARSSL_ERR_SSL_INVALID_RECORD -0x7200
101 #define POLARSSL_ERR_SSL_CONN_EOF -0x7280
102 #define POLARSSL_ERR_SSL_UNKNOWN_CIPHER -0x7300
103 #define POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN -0x7380
104 #define POLARSSL_ERR_SSL_NO_SESSION_FOUND -0x7400
105 #define POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480
106 #define POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500
107 #define POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED -0x7580
108 #define POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600
109 #define POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED -0x7680
110 #define POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE -0x7700
111 #define POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780
112 #define POLARSSL_ERR_SSL_PEER_VERIFY_FAILED -0x7800
113 #define POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880
114 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900
115 #define POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980
116 #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00
117 #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80
118 #define POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00
119 #define POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80
120 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00
121 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_RP -0x7C80
122 #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_CS -0x7D00
123 #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80
124 #define POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00
125 #define POLARSSL_ERR_SSL_BAD_HS_FINISHED -0x7E80
126 #define POLARSSL_ERR_SSL_MALLOC_FAILED -0x7F00
127 #define POLARSSL_ERR_SSL_HW_ACCEL_FAILED -0x7F80
128 #define POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80
129 #define POLARSSL_ERR_SSL_COMPRESSION_FAILED -0x6F00
130 #define POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80
131 #define POLARSSL_ERR_SSL_BAD_HS_NEW_SESSION_TICKET -0x6E00
132 #define POLARSSL_ERR_SSL_SESSION_TICKET_EXPIRED -0x6D80
133 #define POLARSSL_ERR_SSL_PK_TYPE_MISMATCH -0x6D00
134 #define POLARSSL_ERR_SSL_UNKNOWN_IDENTITY -0x6C80
135 #define POLARSSL_ERR_SSL_INTERNAL_ERROR -0x6C00
137 /*
138  * Various constants
139  */
140 #define SSL_MAJOR_VERSION_3 3
141 #define SSL_MINOR_VERSION_0 0
142 #define SSL_MINOR_VERSION_1 1
143 #define SSL_MINOR_VERSION_2 2
144 #define SSL_MINOR_VERSION_3 3
146 /* Determine minimum supported version */
147 #define SSL_MIN_MAJOR_VERSION SSL_MAJOR_VERSION_3
148 
149 #if defined(POLARSSL_SSL_PROTO_SSL3)
150 #define SSL_MIN_MINOR_VERSION SSL_MINOR_VERSION_0
151 #else
152 #if defined(POLARSSL_SSL_PROTO_TLS1)
153 #define SSL_MIN_MINOR_VERSION SSL_MINOR_VERSION_1
154 #else
155 #if defined(POLARSSL_SSL_PROTO_TLS1_1)
156 #define SSL_MIN_MINOR_VERSION SSL_MINOR_VERSION_2
157 #else
158 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
159 #define SSL_MIN_MINOR_VERSION SSL_MINOR_VERSION_3
160 #endif
161 #endif
162 #endif
163 #endif
164 
165 /* Determine maximum supported version */
166 #define SSL_MAX_MAJOR_VERSION SSL_MAJOR_VERSION_3
167 
168 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
169 #define SSL_MAX_MINOR_VERSION SSL_MINOR_VERSION_3
170 #else
171 #if defined(POLARSSL_SSL_PROTO_TLS1_1)
172 #define SSL_MAX_MINOR_VERSION SSL_MINOR_VERSION_2
173 #else
174 #if defined(POLARSSL_SSL_PROTO_TLS1)
175 #define SSL_MAX_MINOR_VERSION SSL_MINOR_VERSION_1
176 #else
177 #if defined(POLARSSL_SSL_PROTO_SSL3)
178 #define SSL_MAX_MINOR_VERSION SSL_MINOR_VERSION_0
179 #endif
180 #endif
181 #endif
182 #endif
183 
184 /* RFC 6066 section 4, see also mfl_code_to_length in ssl_tls.c
185  * NONE must be zero so that memset()ing structure to zero works */
186 #define SSL_MAX_FRAG_LEN_NONE 0
187 #define SSL_MAX_FRAG_LEN_512 1
188 #define SSL_MAX_FRAG_LEN_1024 2
189 #define SSL_MAX_FRAG_LEN_2048 3
190 #define SSL_MAX_FRAG_LEN_4096 4
191 #define SSL_MAX_FRAG_LEN_INVALID 5
193 #define SSL_IS_CLIENT 0
194 #define SSL_IS_SERVER 1
195 #define SSL_COMPRESS_NULL 0
196 #define SSL_COMPRESS_DEFLATE 1
197 
198 #define SSL_VERIFY_NONE 0
199 #define SSL_VERIFY_OPTIONAL 1
200 #define SSL_VERIFY_REQUIRED 2
201 
202 #define SSL_INITIAL_HANDSHAKE 0
203 #define SSL_RENEGOTIATION 1 /* In progress */
204 #define SSL_RENEGOTIATION_DONE 2 /* Done */
205 #define SSL_RENEGOTIATION_PENDING 3 /* Requested (server only) */
206 
207 #define SSL_LEGACY_RENEGOTIATION 0
208 #define SSL_SECURE_RENEGOTIATION 1
209 
210 #define SSL_RENEGOTIATION_DISABLED 0
211 #define SSL_RENEGOTIATION_ENABLED 1
212 
213 #define SSL_LEGACY_NO_RENEGOTIATION 0
214 #define SSL_LEGACY_ALLOW_RENEGOTIATION 1
215 #define SSL_LEGACY_BREAK_HANDSHAKE 2
216 
217 #define SSL_TRUNC_HMAC_DISABLED 0
218 #define SSL_TRUNC_HMAC_ENABLED 1
219 #define SSL_TRUNCATED_HMAC_LEN 10 /* 80 bits, rfc 6066 section 7 */
220 
221 #define SSL_SESSION_TICKETS_DISABLED 0
222 #define SSL_SESSION_TICKETS_ENABLED 1
223 
224 #if !defined(POLARSSL_CONFIG_OPTIONS)
225 #define SSL_DEFAULT_TICKET_LIFETIME 86400
226 #endif /* !POLARSSL_CONFIG_OPTIONS */
227 
228 /*
229  * Size of the input / output buffer.
230  * Note: the RFC defines the default size of SSL / TLS messages. If you
231  * change the value here, other clients / servers may not be able to
232  * communicate with you anymore. Only change this value if you control
233  * both sides of the connection and have it reduced at both sides!
234  */
235 #if !defined(POLARSSL_CONFIG_OPTIONS)
236 #define SSL_MAX_CONTENT_LEN 16384
237 #endif /* !POLARSSL_CONFIG_OPTIONS */
238 
239 /*
240  * Allow an extra 512 bytes for the record header
241  * and encryption overhead (counter + MAC + padding)
242  * and allow for a maximum of 1024 of compression expansion if
243  * enabled.
244  */
245 #if defined(POLARSSL_ZLIB_SUPPORT)
246 #define SSL_COMPRESSION_ADD 1024
247 #else
248 #define SSL_COMPRESSION_ADD 0
249 #endif
250 
251 #define SSL_BUFFER_LEN (SSL_MAX_CONTENT_LEN + SSL_COMPRESSION_ADD + 512)
252 
253 #define SSL_EMPTY_RENEGOTIATION_INFO 0xFF
255 /*
256  * Supported Signature and Hash algorithms (For TLS 1.2)
257  * RFC 5246 section 7.4.1.4.1
258  */
259 #define SSL_HASH_NONE 0
260 #define SSL_HASH_MD5 1
261 #define SSL_HASH_SHA1 2
262 #define SSL_HASH_SHA224 3
263 #define SSL_HASH_SHA256 4
264 #define SSL_HASH_SHA384 5
265 #define SSL_HASH_SHA512 6
266 
267 #define SSL_SIG_ANON 0
268 #define SSL_SIG_RSA 1
269 #define SSL_SIG_ECDSA 3
270 
271 /*
272  * Client Certificate Types
273  * RFC 5246 section 7.4.4 plus RFC 4492 section 5.5
274  */
275 #define SSL_CERT_TYPE_RSA_SIGN 1
276 #define SSL_CERT_TYPE_ECDSA_SIGN 64
277 
278 /*
279  * Message, alert and handshake types
280  */
281 #define SSL_MSG_CHANGE_CIPHER_SPEC 20
282 #define SSL_MSG_ALERT 21
283 #define SSL_MSG_HANDSHAKE 22
284 #define SSL_MSG_APPLICATION_DATA 23
285 
286 #define SSL_ALERT_LEVEL_WARNING 1
287 #define SSL_ALERT_LEVEL_FATAL 2
288 
289 #define SSL_ALERT_MSG_CLOSE_NOTIFY 0 /* 0x00 */
290 #define SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10 /* 0x0A */
291 #define SSL_ALERT_MSG_BAD_RECORD_MAC 20 /* 0x14 */
292 #define SSL_ALERT_MSG_DECRYPTION_FAILED 21 /* 0x15 */
293 #define SSL_ALERT_MSG_RECORD_OVERFLOW 22 /* 0x16 */
294 #define SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30 /* 0x1E */
295 #define SSL_ALERT_MSG_HANDSHAKE_FAILURE 40 /* 0x28 */
296 #define SSL_ALERT_MSG_NO_CERT 41 /* 0x29 */
297 #define SSL_ALERT_MSG_BAD_CERT 42 /* 0x2A */
298 #define SSL_ALERT_MSG_UNSUPPORTED_CERT 43 /* 0x2B */
299 #define SSL_ALERT_MSG_CERT_REVOKED 44 /* 0x2C */
300 #define SSL_ALERT_MSG_CERT_EXPIRED 45 /* 0x2D */
301 #define SSL_ALERT_MSG_CERT_UNKNOWN 46 /* 0x2E */
302 #define SSL_ALERT_MSG_ILLEGAL_PARAMETER 47 /* 0x2F */
303 #define SSL_ALERT_MSG_UNKNOWN_CA 48 /* 0x30 */
304 #define SSL_ALERT_MSG_ACCESS_DENIED 49 /* 0x31 */
305 #define SSL_ALERT_MSG_DECODE_ERROR 50 /* 0x32 */
306 #define SSL_ALERT_MSG_DECRYPT_ERROR 51 /* 0x33 */
307 #define SSL_ALERT_MSG_EXPORT_RESTRICTION 60 /* 0x3C */
308 #define SSL_ALERT_MSG_PROTOCOL_VERSION 70 /* 0x46 */
309 #define SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71 /* 0x47 */
310 #define SSL_ALERT_MSG_INTERNAL_ERROR 80 /* 0x50 */
311 #define SSL_ALERT_MSG_USER_CANCELED 90 /* 0x5A */
312 #define SSL_ALERT_MSG_NO_RENEGOTIATION 100 /* 0x64 */
313 #define SSL_ALERT_MSG_UNSUPPORTED_EXT 110 /* 0x6E */
314 #define SSL_ALERT_MSG_UNRECOGNIZED_NAME 112 /* 0x70 */
315 #define SSL_ALERT_MSG_UNKNOWN_PSK_IDENTITY 115 /* 0x73 */
316 
317 #define SSL_HS_HELLO_REQUEST 0
318 #define SSL_HS_CLIENT_HELLO 1
319 #define SSL_HS_SERVER_HELLO 2
320 #define SSL_HS_NEW_SESSION_TICKET 4
321 #define SSL_HS_CERTIFICATE 11
322 #define SSL_HS_SERVER_KEY_EXCHANGE 12
323 #define SSL_HS_CERTIFICATE_REQUEST 13
324 #define SSL_HS_SERVER_HELLO_DONE 14
325 #define SSL_HS_CERTIFICATE_VERIFY 15
326 #define SSL_HS_CLIENT_KEY_EXCHANGE 16
327 #define SSL_HS_FINISHED 20
328 
329 /*
330  * TLS extensions
331  */
332 #define TLS_EXT_SERVERNAME 0
333 #define TLS_EXT_SERVERNAME_HOSTNAME 0
334 
335 #define TLS_EXT_MAX_FRAGMENT_LENGTH 1
336 
337 #define TLS_EXT_TRUNCATED_HMAC 4
338 
339 #define TLS_EXT_SUPPORTED_ELLIPTIC_CURVES 10
340 #define TLS_EXT_SUPPORTED_POINT_FORMATS 11
341 
342 #define TLS_EXT_SIG_ALG 13
343 
344 #define TLS_EXT_SESSION_TICKET 35
345 
346 #define TLS_EXT_RENEGOTIATION_INFO 0xFF01
347 
348 /*
349  * TLS extension flags (for extensions with outgoing ServerHello content
350  * that need it (e.g. for RENEGOTIATION_INFO the server already knows because
351  * of state of the renegotiation flag, so no indicator is required)
352  */
353 #define TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT (1 << 0)
354 
355 /*
356  * Size defines
357  */
358 #if !defined(POLARSSL_MPI_MAX_SIZE)
359 #define POLARSSL_PREMASTER_SIZE 512
360 #else
361 #define POLARSSL_PREMASTER_SIZE POLARSSL_MPI_MAX_SIZE
362 #endif
363 
364 #ifdef __cplusplus
365 extern "C" {
366 #endif
367 
368 /*
369  * Generic function pointers for allowing external RSA private key
370  * implementations.
371  */
372 typedef int (*rsa_decrypt_func)( void *ctx, int mode, size_t *olen,
373  const unsigned char *input, unsigned char *output,
374  size_t output_max_len );
375 typedef int (*rsa_sign_func)( void *ctx,
376  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
377  int mode, int hash_id, unsigned int hashlen,
378  const unsigned char *hash, unsigned char *sig );
379 typedef size_t (*rsa_key_len_func)( void *ctx );
380 
381 /*
382  * SSL state machine
383  */
384 typedef enum
385 {
404 }
405 ssl_states;
406 
407 typedef struct _ssl_session ssl_session;
408 typedef struct _ssl_context ssl_context;
411 #if defined(POLARSSL_SSL_SESSION_TICKETS)
413 #endif
414 #if defined(POLARSSL_X509_CRT_PARSE_C)
416 #endif
417 
418 /*
419  * This structure is used for storing current session data.
420  */
422 {
423 #if defined(POLARSSL_HAVE_TIME)
424  time_t start;
425 #endif
428  size_t length;
429  unsigned char id[32];
430  unsigned char master[48];
432 #if defined(POLARSSL_X509_CRT_PARSE_C)
434 #endif /* POLARSSL_X509_CRT_PARSE_C */
437 #if defined(POLARSSL_SSL_SESSION_TICKETS)
438  unsigned char *ticket;
439  size_t ticket_len;
440  uint32_t ticket_lifetime;
441 #endif /* POLARSSL_SSL_SESSION_TICKETS */
442 
443 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
444  unsigned char mfl_code;
445 #endif /* POLARSSL_SSL_MAX_FRAGMENT_LENGTH */
446 
447 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
449 #endif /* POLARSSL_SSL_TRUNCATED_HMAC */
450 };
451 
452 /*
453  * This structure contains a full set of runtime transform parameters
454  * either in negotiation or active.
455  */
457 {
458  /*
459  * Session specific crypto layer
460  */
463  unsigned int keylen;
464  size_t minlen;
465  size_t ivlen;
466  size_t fixed_ivlen;
467  size_t maclen;
469  unsigned char iv_enc[16];
470  unsigned char iv_dec[16];
472 #if defined(POLARSSL_SSL_PROTO_SSL3)
473  /* Needed only for SSL v3.0 secret */
474  unsigned char mac_enc[32];
475  unsigned char mac_dec[32];
476 #endif /* POLARSSL_SSL_PROTO_SSL3 */
477 
484  /*
485  * Session specific compression layer
486  */
487 #if defined(POLARSSL_ZLIB_SUPPORT)
488  z_stream ctx_deflate;
489  z_stream ctx_inflate;
490 #endif
491 };
492 
493 /*
494  * This structure contains the parameters only needed during handshake.
495  */
497 {
498  /*
499  * Handshake specific crypto variables
500  */
501  int sig_alg;
502  int cert_type;
504 #if defined(POLARSSL_DHM_C)
506 #endif
507 #if defined(POLARSSL_ECDH_C)
509 #endif
510 #if defined(POLARSSL_ECDH_C) || defined(POLARSSL_ECDSA_C)
512 #endif
513 #if defined(POLARSSL_X509_CRT_PARSE_C)
514 
521 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
523 #endif
524 #endif
525 
526  /*
527  * Checksum contexts
528  */
529 #if defined(POLARSSL_SSL_PROTO_SSL3) || defined(POLARSSL_SSL_PROTO_TLS1) || \
530  defined(POLARSSL_SSL_PROTO_TLS1_1)
533 #endif
534 #if defined(POLARSSL_SSL_PROTO_TLS1_2)
535 #if defined(POLARSSL_SHA256_C)
537 #endif
538 #if defined(POLARSSL_SHA512_C)
540 #endif
541 #endif /* POLARSSL_SSL_PROTO_TLS1_2 */
542 
543  void (*update_checksum)(ssl_context *, const unsigned char *, size_t);
544  void (*calc_verify)(ssl_context *, unsigned char *);
545  void (*calc_finished)(ssl_context *, unsigned char *, int);
546  int (*tls_prf)(const unsigned char *, size_t, const char *,
547  const unsigned char *, size_t,
548  unsigned char *, size_t);
549 
550  size_t pmslen;
552  unsigned char randbytes[64];
556  int resume;
559  int cli_exts;
561 #if defined(POLARSSL_SSL_SESSION_TICKETS)
563 #endif /* POLARSSL_SSL_SESSION_TICKETS */
564 };
565 
566 #if defined(POLARSSL_SSL_SESSION_TICKETS)
567 /*
568  * Parameters needed to secure session tickets
569  */
571 {
572  unsigned char key_name[16];
575  unsigned char mac_key[16];
576 };
577 #endif /* POLARSSL_SSL_SESSION_TICKETS */
578 
579 #if defined(POLARSSL_X509_CRT_PARSE_C)
580 /*
581  * List of certificate + private key pairs
582  */
584 {
589 };
590 #endif /* POLARSSL_X509_CRT_PARSE_C */
591 
593 {
594  /*
595  * Miscellaneous
596  */
597  int state;
600  int major_ver;
601  int minor_ver;
608  /*
609  * Callbacks (RNG, debug, I/O, verification)
610  */
611  int (*f_rng)(void *, unsigned char *, size_t);
612  void (*f_dbg)(void *, int, const char *);
613  int (*f_recv)(void *, unsigned char *, size_t);
614  int (*f_send)(void *, const unsigned char *, size_t);
615  int (*f_get_cache)(void *, ssl_session *);
616  int (*f_set_cache)(void *, const ssl_session *);
617 
618  void *p_rng;
619  void *p_dbg;
620  void *p_recv;
621  void *p_send;
622  void *p_get_cache;
623  void *p_set_cache;
624  void *p_hw_data;
626 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
627  int (*f_sni)(void *, ssl_context *, const unsigned char *, size_t);
628  void *p_sni;
629 #endif
630 
631 #if defined(POLARSSL_X509_CRT_PARSE_C)
632  int (*f_vrfy)(void *, x509_crt *, int, int *);
633  void *p_vrfy;
634 #endif
635 
636 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
637  int (*f_psk)(void *, ssl_context *, const unsigned char *, size_t);
638  void *p_psk;
639 #endif
640 
641  /*
642  * Session layer
643  */
652  /*
653  * Record layer transformations
654  */
660  /*
661  * Record layer (incoming data)
662  */
663  unsigned char *in_ctr;
664  unsigned char *in_hdr;
665  unsigned char *in_iv;
666  unsigned char *in_msg;
667  unsigned char *in_offt;
670  size_t in_msglen;
671  size_t in_left;
673  size_t in_hslen;
674  int nb_zero;
677  /*
678  * Record layer (outgoing data)
679  */
680  unsigned char *out_ctr;
681  unsigned char *out_hdr;
682  unsigned char *out_iv;
683  unsigned char *out_msg;
686  size_t out_msglen;
687  size_t out_left;
689 #if defined(POLARSSL_ZLIB_SUPPORT)
690  unsigned char *compress_buf;
691 #endif
692 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
693  unsigned char mfl_code;
694 #endif /* POLARSSL_SSL_MAX_FRAGMENT_LENGTH */
695 
696  /*
697  * PKI layer
698  */
699 #if defined(POLARSSL_X509_CRT_PARSE_C)
704  const char *peer_cn;
705 #endif /* POLARSSL_X509_CRT_PARSE_C */
706 
707  /*
708  * Support for generating and checking session tickets
709  */
710 #if defined(POLARSSL_SSL_SESSION_TICKETS)
712 #endif /* POLARSSL_SSL_SESSION_TICKETS */
713 
714  /*
715  * User settings
716  */
717  int endpoint;
718  int authmode;
723  const int *ciphersuite_list[4];
724 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
726 #endif
727 #if defined(POLARSSL_SSL_SESSION_TICKETS)
730 #endif
731 
732 #if defined(POLARSSL_DHM_C)
735 #endif
736 
737 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
738  /*
739  * PSK values
740  */
741  unsigned char *psk;
742  size_t psk_len;
743  unsigned char *psk_identity;
745 #endif
746 
747 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
748  /*
749  * SNI extension
750  */
751  unsigned char *hostname;
752  size_t hostname_len;
753 #endif
754 
755  /*
756  * Secure renegotiation
757  */
761  char own_verify_data[36];
762  char peer_verify_data[36];
763 };
764 
765 #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
766 
767 #define SSL_CHANNEL_OUTBOUND 0
768 #define SSL_CHANNEL_INBOUND 1
769 
770 extern int (*ssl_hw_record_init)(ssl_context *ssl,
771  const unsigned char *key_enc, const unsigned char *key_dec,
772  size_t keylen,
773  const unsigned char *iv_enc, const unsigned char *iv_dec,
774  size_t ivlen,
775  const unsigned char *mac_enc, const unsigned char *mac_dec,
776  size_t maclen);
777 extern int (*ssl_hw_record_activate)(ssl_context *ssl, int direction);
778 extern int (*ssl_hw_record_reset)(ssl_context *ssl);
779 extern int (*ssl_hw_record_write)(ssl_context *ssl);
780 extern int (*ssl_hw_record_read)(ssl_context *ssl);
781 extern int (*ssl_hw_record_finish)(ssl_context *ssl);
782 #endif
783 
790 const int *ssl_list_ciphersuites( void );
791 
800 const char *ssl_get_ciphersuite_name( const int ciphersuite_id );
801 
810 int ssl_get_ciphersuite_id( const char *ciphersuite_name );
811 
821 int ssl_init( ssl_context *ssl );
822 
833 int ssl_session_reset( ssl_context *ssl );
834 
844 void ssl_set_endpoint( ssl_context *ssl, int endpoint );
845 
863 void ssl_set_authmode( ssl_context *ssl, int authmode );
864 
865 #if defined(POLARSSL_X509_CRT_PARSE_C)
866 
877 void ssl_set_verify( ssl_context *ssl,
878  int (*f_vrfy)(void *, x509_crt *, int, int *),
879  void *p_vrfy );
880 #endif /* POLARSSL_X509_CRT_PARSE_C */
881 
889 void ssl_set_rng( ssl_context *ssl,
890  int (*f_rng)(void *, unsigned char *, size_t),
891  void *p_rng );
892 
900 void ssl_set_dbg( ssl_context *ssl,
901  void (*f_dbg)(void *, int, const char *),
902  void *p_dbg );
903 
913 void ssl_set_bio( ssl_context *ssl,
914  int (*f_recv)(void *, unsigned char *, size_t), void *p_recv,
915  int (*f_send)(void *, const unsigned char *, size_t), void *p_send );
916 
955  int (*f_get_cache)(void *, ssl_session *), void *p_get_cache,
956  int (*f_set_cache)(void *, const ssl_session *), void *p_set_cache );
957 
972 int ssl_set_session( ssl_context *ssl, const ssl_session *session );
973 
981 void ssl_set_ciphersuites( ssl_context *ssl, const int *ciphersuites );
982 
997  const int *ciphersuites,
998  int major, int minor );
999 
1000 #if defined(POLARSSL_X509_CRT_PARSE_C)
1001 
1009 void ssl_set_ca_chain( ssl_context *ssl, x509_crt *ca_chain,
1010  x509_crl *ca_crl, const char *peer_cn );
1011 
1030 int ssl_set_own_cert( ssl_context *ssl, x509_crt *own_cert,
1031  pk_context *pk_key );
1032 
1033 #if defined(POLARSSL_RSA_C)
1034 
1047 int ssl_set_own_cert_rsa( ssl_context *ssl, x509_crt *own_cert,
1048  rsa_context *rsa_key );
1049 #endif /* POLARSSL_RSA_C */
1050 
1072 int ssl_set_own_cert_alt( ssl_context *ssl, x509_crt *own_cert,
1073  void *rsa_key,
1074  rsa_decrypt_func rsa_decrypt,
1075  rsa_sign_func rsa_sign,
1076  rsa_key_len_func rsa_key_len );
1077 #endif /* POLARSSL_X509_CRT_PARSE_C */
1078 
1079 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
1080 
1092 int ssl_set_psk( ssl_context *ssl, const unsigned char *psk, size_t psk_len,
1093  const unsigned char *psk_identity, size_t psk_identity_len );
1094 
1115 void ssl_set_psk_cb( ssl_context *ssl,
1116  int (*f_psk)(void *, ssl_context *, const unsigned char *,
1117  size_t),
1118  void *p_psk );
1119 #endif /* POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED */
1120 
1121 #if defined(POLARSSL_DHM_C)
1122 
1133 int ssl_set_dh_param( ssl_context *ssl, const char *dhm_P, const char *dhm_G );
1134 
1144 int ssl_set_dh_param_ctx( ssl_context *ssl, dhm_context *dhm_ctx );
1145 #endif
1146 
1147 #if defined(POLARSSL_SSL_SERVER_NAME_INDICATION)
1148 
1158 int ssl_set_hostname( ssl_context *ssl, const char *hostname );
1159 
1179 void ssl_set_sni( ssl_context *ssl,
1180  int (*f_sni)(void *, ssl_context *, const unsigned char *,
1181  size_t),
1182  void *p_sni );
1183 #endif /* POLARSSL_SSL_SERVER_NAME_INDICATION */
1184 
1200 void ssl_set_max_version( ssl_context *ssl, int major, int minor );
1201 
1202 
1216 void ssl_set_min_version( ssl_context *ssl, int major, int minor );
1217 
1218 #if defined(POLARSSL_SSL_MAX_FRAGMENT_LENGTH)
1219 
1234 int ssl_set_max_frag_len( ssl_context *ssl, unsigned char mfl_code );
1235 #endif /* POLARSSL_SSL_MAX_FRAGMENT_LENGTH */
1236 
1237 #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
1238 
1249 int ssl_set_truncated_hmac( ssl_context *ssl, int truncate );
1250 #endif /* POLARSSL_SSL_TRUNCATED_HMAC */
1251 
1252 #if defined(POLARSSL_SSL_SESSION_TICKETS)
1253 
1269 int ssl_set_session_tickets( ssl_context *ssl, int use_tickets );
1270 
1278 void ssl_set_session_ticket_lifetime( ssl_context *ssl, int lifetime );
1279 #endif /* POLARSSL_SSL_SESSION_TICKETS */
1280 
1294 void ssl_set_renegotiation( ssl_context *ssl, int renegotiation );
1295 
1323 void ssl_legacy_renegotiation( ssl_context *ssl, int allow_legacy );
1324 
1332 size_t ssl_get_bytes_avail( const ssl_context *ssl );
1333 
1345 int ssl_get_verify_result( const ssl_context *ssl );
1346 
1354 const char *ssl_get_ciphersuite( const ssl_context *ssl );
1355 
1363 const char *ssl_get_version( const ssl_context *ssl );
1364 
1365 #if defined(POLARSSL_X509_CRT_PARSE_C)
1366 
1380 const x509_crt *ssl_get_peer_cert( const ssl_context *ssl );
1381 #endif /* POLARSSL_X509_CRT_PARSE_C */
1382 
1399 int ssl_get_session( const ssl_context *ssl, ssl_session *session );
1400 
1409 int ssl_handshake( ssl_context *ssl );
1410 
1423 int ssl_handshake_step( ssl_context *ssl );
1424 
1435 int ssl_renegotiate( ssl_context *ssl );
1436 
1447 int ssl_read( ssl_context *ssl, unsigned char *buf, size_t len );
1448 
1463 int ssl_write( ssl_context *ssl, const unsigned char *buf, size_t len );
1464 
1476  unsigned char level,
1477  unsigned char message );
1483 int ssl_close_notify( ssl_context *ssl );
1484 
1490 void ssl_free( ssl_context *ssl );
1491 
1498 void ssl_session_free( ssl_session *session );
1499 
1506 void ssl_transform_free( ssl_transform *transform );
1507 
1514 void ssl_handshake_free( ssl_handshake_params *handshake );
1515 
1516 /*
1517  * Internal functions (do not call directly)
1518  */
1521 void ssl_handshake_wrapup( ssl_context *ssl );
1522 
1524 
1525 int ssl_derive_keys( ssl_context *ssl );
1526 
1527 int ssl_read_record( ssl_context *ssl );
1532 int ssl_fetch_input( ssl_context *ssl, size_t nb_want );
1533 
1534 int ssl_write_record( ssl_context *ssl );
1535 int ssl_flush_output( ssl_context *ssl );
1536 
1539 
1542 
1543 int ssl_parse_finished( ssl_context *ssl );
1544 int ssl_write_finished( ssl_context *ssl );
1545 
1546 void ssl_optimize_checksum( ssl_context *ssl, const ssl_ciphersuite_t *ciphersuite_info );
1547 
1548 #if defined(POLARSSL_KEY_EXCHANGE__SOME__PSK_ENABLED)
1550 #endif
1551 
1552 #if defined(POLARSSL_PK_C)
1553 unsigned char ssl_sig_from_pk( pk_context *pk );
1554 pk_type_t ssl_pk_alg_from_sig( unsigned char sig );
1555 #endif
1556 
1557 md_type_t ssl_md_alg_from_hash( unsigned char hash );
1558 
1559 #if defined(POLARSSL_X509_CRT_PARSE_C)
1560 static inline pk_context *ssl_own_key( ssl_context *ssl )
1561 {
1562  return( ssl->handshake->key_cert == NULL ? NULL
1563  : ssl->handshake->key_cert->key );
1564 }
1565 
1566 static inline x509_crt *ssl_own_cert( ssl_context *ssl )
1567 {
1568  return( ssl->handshake->key_cert == NULL ? NULL
1569  : ssl->handshake->key_cert->cert );
1570 }
1571 #endif /* POLARSSL_X509_CRT_PARSE_C */
1572 
1573 /* constant-time buffer comparison */
1574 static inline int safer_memcmp( const void *a, const void *b, size_t n )
1575 {
1576  size_t i;
1577  const unsigned char *A = (const unsigned char *) a;
1578  const unsigned char *B = (const unsigned char *) b;
1579  unsigned char diff = 0;
1580 
1581  for( i = 0; i < n; i++ )
1582  diff |= A[i] ^ B[i];
1583 
1584  return( diff );
1585 }
1586 
1587 #ifdef __cplusplus
1588 }
1589 #endif
1590 
1591 #endif /* ssl.h */
const ecp_curve_info ** curves
Definition: ssl.h:511
unsigned char * hostname
Definition: ssl.h:751
ssl_session * session_in
Definition: ssl.h:644
unsigned char mfl_code
Definition: ssl.h:693
size_t length
Definition: ssl.h:428
void * p_set_cache
Definition: ssl.h:623
md_context_t md_ctx_dec
Definition: ssl.h:479
int ciphersuite
Definition: ssl.h:426
int trunc_hmac
Definition: ssl.h:725
size_t in_hslen
Definition: ssl.h:673
int ssl_send_alert_message(ssl_context *ssl, unsigned char level, unsigned char message)
Send an alert message.
void(* f_dbg)(void *, int, const char *)
Definition: ssl.h:612
int(* f_rng)(void *, unsigned char *, size_t)
Definition: ssl.h:611
sha256_context fin_sha256
Definition: ssl.h:536
size_t ivlen
Definition: ssl.h:465
int record_read
Definition: ssl.h:675
int major_ver
Definition: ssl.h:600
Generic cipher context.
Definition: cipher.h:239
#define POLARSSL_PREMASTER_SIZE
Definition: ssl.h:361
SHA-1 context structure.
Definition: sha1.h:54
sha1_context fin_sha1
Definition: ssl.h:532
int compression
Definition: ssl.h:427
pk_type_t ssl_pk_alg_from_sig(unsigned char sig)
Network communication functions.
int state
Definition: ssl.h:597
const char * peer_cn
Definition: ssl.h:704
unsigned char master[48]
Definition: ssl.h:430
char peer_verify_data[36]
Definition: ssl.h:762
int ssl_set_truncated_hmac(ssl_context *ssl, int truncate)
Activate negotiation of truncated HMAC (Client only) (Default: SSL_TRUNC_HMAC_ENABLED) ...
ssl_transform * transform_out
Definition: ssl.h:656
int(* f_sni)(void *, ssl_context *, const unsigned char *, size_t)
Definition: ssl.h:627
int nb_zero
Definition: ssl.h:674
void(* calc_verify)(ssl_context *, unsigned char *)
Definition: ssl.h:544
DHM context structure.
Definition: dhm.h:143
void * p_psk
Definition: ssl.h:638
size_t ticket_len
Definition: ssl.h:439
ssl_session * session_negotiate
Definition: ssl.h:647
ssl_session * session
Definition: ssl.h:646
void ssl_legacy_renegotiation(ssl_context *ssl, int allow_legacy)
Prevent or allow legacy renegotiation.
int ssl_parse_certificate(ssl_context *ssl)
void ssl_set_dbg(ssl_context *ssl, void(*f_dbg)(void *, int, const char *), void *p_dbg)
Set the debug callback.
ssl_key_cert * key_cert
Definition: ssl.h:700
ssl_key_cert * sni_key_cert
Definition: ssl.h:522
int ssl_set_session_tickets(ssl_context *ssl, int use_tickets)
Enable / Disable session tickets (Default: SSL_SESSION_TICKETS_ENABLED on client, SSL_SESSION_TICKETS...
unsigned char iv_enc[16]
Definition: ssl.h:469
size_t out_msglen
Definition: ssl.h:686
void ssl_set_verify(ssl_context *ssl, int(*f_vrfy)(void *, x509_crt *, int, int *), void *p_vrfy)
Set the verification callback (Optional).
int ticket_lifetime
Definition: ssl.h:729
ssl_transform * transform_in
Definition: ssl.h:655
cipher_context_t cipher_ctx_enc
Definition: ssl.h:481
const int * ciphersuite_list[4]
Definition: ssl.h:723
int ssl_parse_finished(ssl_context *ssl)
void * p_rng
Definition: ssl.h:618
mpi dhm_P
Definition: ssl.h:733
ssl_states
Definition: ssl.h:384
unsigned char premaster[POLARSSL_PREMASTER_SIZE]
Definition: ssl.h:553
void ssl_session_free(ssl_session *session)
Free referenced items in an SSL session including the peer certificate and clear memory.
AES context structure.
Definition: aes.h:58
int ssl_write_finished(ssl_context *ssl)
Configuration options (set of defines)
ssl_transform * transform
Definition: ssl.h:657
x509_crt * cert
Definition: ssl.h:585
size_t psk_identity_len
Definition: ssl.h:744
unsigned char * out_ctr
Definition: ssl.h:680
void ssl_handshake_wrapup(ssl_context *ssl)
char own_verify_data[36]
Definition: ssl.h:761
int(* f_send)(void *, const unsigned char *, size_t)
Definition: ssl.h:614
size_t in_msglen
Definition: ssl.h:670
int ssl_set_dh_param_ctx(ssl_context *ssl, dhm_context *dhm_ctx)
Set the Diffie-Hellman public P and G values, read from existing context (server-side only) ...
unsigned char * in_hdr
Definition: ssl.h:664
int secure_renegotiation
Definition: ssl.h:758
time_t start
Definition: ssl.h:424
MPI structure.
Definition: bignum.h:171
sha512_context fin_sha512
Definition: ssl.h:539
int ssl_handshake_server_step(ssl_context *ssl)
SSL Ciphersuites for PolarSSL.
int(* tls_prf)(const unsigned char *, size_t, const char *, const unsigned char *, size_t, unsigned char *, size_t)
Definition: ssl.h:546
unsigned char mac_key[16]
Definition: ssl.h:575
void * p_vrfy
Definition: ssl.h:633
size_t psk_len
Definition: ssl.h:742
void ssl_set_max_version(ssl_context *ssl, int major, int minor)
Set the maximum supported version sent from the client side and/or accepted at the server side (Defau...
const ssl_ciphersuite_t * ciphersuite_info
Definition: ssl.h:461
void * p_recv
Definition: ssl.h:620
unsigned char * psk
Definition: ssl.h:741
Multi-precision integer library.
void ssl_set_ciphersuites_for_version(ssl_context *ssl, const int *ciphersuites, int major, int minor)
Set the list of allowed ciphersuites for a specific version of the protocol.
int ssl_init(ssl_context *ssl)
Initialize an SSL context (An individual SSL context is not thread-safe)
int max_major_ver
Definition: ssl.h:603
int ssl_get_ciphersuite_id(const char *ciphersuite_name)
Return the ID of the ciphersuite associated with the given name.
int ssl_set_psk(ssl_context *ssl, 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 identity name connected to it.
void ssl_set_psk_cb(ssl_context *ssl, int(*f_psk)(void *, ssl_context *, const unsigned char *, size_t), void *p_psk)
Set the PSK callback (server-side only) (Optional).
unsigned int keylen
Definition: ssl.h:463
int ssl_get_session(const ssl_context *ssl, ssl_session *session)
Save session in order to resume it later (client-side only) Session data is copied to presented sessi...
md_type_t
Definition: md.h:51
int verify_result
Definition: ssl.h:435
int max_minor_ver
Definition: ssl.h:604
void * p_hw_data
Definition: ssl.h:624
unsigned char * in_ctr
Definition: ssl.h:663
ssl_handshake_params * handshake
Definition: ssl.h:649
void(* update_checksum)(ssl_context *, const unsigned char *, size_t)
Definition: ssl.h:543
size_t fixed_ivlen
Definition: ssl.h:466
int ssl_write_certificate(ssl_context *ssl)
size_t(* rsa_key_len_func)(void *ctx)
Definition: ssl.h:379
RSA context structure.
Definition: rsa.h:77
cipher_context_t cipher_ctx_dec
Definition: ssl.h:482
int in_msgtype
Definition: ssl.h:669
Container for an X.509 certificate.
Definition: x509_crt.h:53
size_t verify_data_len
Definition: ssl.h:760
const char * ssl_get_ciphersuite(const ssl_context *ssl)
Return the name of the current ciphersuite.
mpi dhm_G
Definition: ssl.h:734
const char * ssl_get_version(const ssl_context *ssl)
Return the current SSL version (SSLv3/TLSv1/etc)
void ssl_set_renegotiation(ssl_context *ssl, int renegotiation)
Enable / Disable renegotiation support for connection when initiated by peer (Default: SSL_RENEGOTIAT...
int min_minor_ver
Definition: ssl.h:606
unsigned char * out_msg
Definition: ssl.h:683
int client_auth
Definition: ssl.h:719
void * p_dbg
Definition: ssl.h:619
ssl_key_cert * key_cert
Current key/cert or key/cert list.
Definition: ssl.h:520
void * p_send
Definition: ssl.h:621
ecdh_context ecdh_ctx
Definition: ssl.h:508
x509_crl * ca_crl
Definition: ssl.h:703
static x509_crt * ssl_own_cert(ssl_context *ssl)
Definition: ssl.h:1566
int ssl_set_max_frag_len(ssl_context *ssl, unsigned char mfl_code)
Set the maximum fragment length to emit and/or negotiate (Default: 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)
SHA-512 context structure.
Definition: sha512.h:55
int ssl_handshake_client_step(ssl_context *ssl)
unsigned char * ticket
Definition: ssl.h:438
size_t maclen
Definition: ssl.h:467
int new_session_ticket
Definition: ssl.h:562
unsigned char * out_hdr
Definition: ssl.h:681
AES block cipher.
int ssl_set_own_cert(ssl_context *ssl, x509_crt *own_cert, pk_context *pk_key)
Set own certificate chain and private key.
int trunc_hmac
Definition: ssl.h:448
void ssl_set_endpoint(ssl_context *ssl, int endpoint)
Set the current endpoint type.
void ssl_set_ciphersuites(ssl_context *ssl, const int *ciphersuites)
Set the list of allowed ciphersuites (Overrides all version specific lists)
Curve information for use by other modules.
Definition: ecp.h:77
void ssl_set_rng(ssl_context *ssl, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Set the random number generator callback.
void * p_get_cache
Definition: ssl.h:622
void ssl_set_bio(ssl_context *ssl, int(*f_recv)(void *, unsigned char *, size_t), void *p_recv, int(*f_send)(void *, const unsigned char *, size_t), void *p_send)
Set the underlying BIO read and write callbacks.
void ssl_free(ssl_context *ssl)
Free referenced items in an SSL context and clear memory.
int(* rsa_sign_func)(void *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, int hash_id, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
Definition: ssl.h:375
unsigned char ssl_sig_from_pk(pk_context *pk)
void ssl_handshake_free(ssl_handshake_params *handshake)
Free referenced items in an SSL handshake context and clear memory.
int authmode
Definition: ssl.h:718
int ssl_flush_output(ssl_context *ssl)
int ssl_handshake(ssl_context *ssl)
Perform the SSL handshake.
unsigned char * in_offt
Definition: ssl.h:667
void ssl_set_min_version(ssl_context *ssl, int major, int minor)
Set the minimum accepted SSL/TLS protocol version (Default: SSL_MIN_MAJOR_VERSION, SSL_MIN_MINOR_VERSION)
Diffie-Hellman-Merkle key exchange.
X.509 certificate parsing and writing.
unsigned char * in_msg
Definition: ssl.h:666
int ssl_set_hostname(ssl_context *ssl, const char *hostname)
Set hostname for ServerName TLS extension (client-side only)
aes_context dec
Definition: ssl.h:574
int ssl_handshake_step(ssl_context *ssl)
Perform a single step of the SSL handshake.
MD5 context structure.
Definition: md5.h:54
pk_type_t
Public key types.
Definition: pk.h:90
aes_context enc
Definition: ssl.h:573
unsigned char mac_dec[32]
Definition: ssl.h:475
unsigned char iv_dec[16]
Definition: ssl.h:470
int ssl_parse_change_cipher_spec(ssl_context *ssl)
size_t hostname_len
Definition: ssl.h:752
Elliptic curve Diffie-Hellman.
int minor_ver
Definition: ssl.h:601
ECDH context structure.
Definition: ecdh.h:39
This structure is used for storing ciphersuite information.
int ssl_close_notify(ssl_context *ssl)
Notify the peer that the connection is being closed.
const x509_crt * ssl_get_peer_cert(const ssl_context *ssl)
Return the peer certificate from the current connection.
void ssl_set_session_cache(ssl_context *ssl, int(*f_get_cache)(void *, ssl_session *), void *p_get_cache, int(*f_set_cache)(void *, const ssl_session *), void *p_set_cache)
Set the session cache callbacks (server-side only) If not set, no session resuming is done...
size_t ssl_get_bytes_avail(const ssl_context *ssl)
Return the number of data bytes available to read.
int ssl_set_session(ssl_context *ssl, const ssl_session *session)
Request resumption of session (client-side only) Session data is copied from presented session struct...
size_t in_left
Definition: ssl.h:671
int session_tickets
Definition: ssl.h:728
pk_context * key
Definition: ssl.h:586
int allow_legacy_renegotiation
Definition: ssl.h:722
ssl_session * session_out
Definition: ssl.h:645
void(* calc_finished)(ssl_context *, unsigned char *, int)
Definition: ssl.h:545
int ssl_read_record(ssl_context *ssl)
int ssl_set_own_cert_rsa(ssl_context *ssl, x509_crt *own_cert, rsa_context *rsa_key)
Set own certificate chain and private RSA key.
int ssl_set_dh_param(ssl_context *ssl, 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(* f_vrfy)(void *, x509_crt *, int, int *)
Definition: ssl.h:632
int out_msgtype
Definition: ssl.h:685
void ssl_set_session_ticket_lifetime(ssl_context *ssl, int lifetime)
Set session ticket lifetime (server only) (Default: SSL_DEFAULT_TICKET_LIFETIME (86400 secs / 1 day))...
size_t out_left
Definition: ssl.h:687
SHA-1 cryptographic hash function.
md_context_t md_ctx_enc
Definition: ssl.h:478
unsigned char mac_enc[32]
Definition: ssl.h:474
int ssl_get_verify_result(const ssl_context *ssl)
Return the result of the certificate verification.
X.509 certificate revocation list parsing.
int ssl_session_reset(ssl_context *ssl)
Reset an already initialized SSL context for re-use while retaining application-set variables...
int min_major_ver
Definition: ssl.h:605
Certificate revocation list structure.
Definition: x509_crl.h:69
const int * ssl_list_ciphersuites(void)
Returns the list of ciphersuites supported by the SSL/TLS module.
SHA-384 and SHA-512 cryptographic hash function.
ssl_transform * transform_negotiate
Definition: ssl.h:658
uint32_t ticket_lifetime
Definition: ssl.h:440
unsigned char * in_iv
Definition: ssl.h:665
int disable_renegotiation
Definition: ssl.h:721
int verify_result
Definition: ssl.h:720
int ssl_write_change_cipher_spec(ssl_context *ssl)
int(* f_get_cache)(void *, ssl_session *)
Definition: ssl.h:615
int ssl_derive_keys(ssl_context *ssl)
void ssl_set_authmode(ssl_context *ssl, int authmode)
Set the certificate verification mode.
static pk_context * ssl_own_key(ssl_context *ssl)
Definition: ssl.h:1560
int(* f_set_cache)(void *, const ssl_session *)
Definition: ssl.h:616
SHA-256 context structure.
Definition: sha256.h:54
key_exchange_type_t
unsigned char mfl_code
Definition: ssl.h:444
int ssl_psk_derive_premaster(ssl_context *ssl, key_exchange_type_t key_ex)
int renegotiation
Definition: ssl.h:598
dhm_context dhm_ctx
Definition: ssl.h:505
static int safer_memcmp(const void *a, const void *b, size_t n)
Definition: ssl.h:1574
int ssl_send_fatal_handshake_failure(ssl_context *ssl)
ssl_ticket_keys * ticket_keys
Definition: ssl.h:711
size_t minlen
Definition: ssl.h:464
int ssl_read(ssl_context *ssl, unsigned char *buf, size_t len)
Read at most &#39;len&#39; application data bytes.
void ssl_transform_free(ssl_transform *transform)
Free referenced items in an SSL transform context and clear memory.
unsigned char * psk_identity
Definition: ssl.h:743
const char * ssl_get_ciphersuite_name(const int ciphersuite_id)
Return the name of the ciphersuite associated with the given ID.
MD5 message digest algorithm (hash function)
int ssl_renegotiate(ssl_context *ssl)
Initiate an SSL renegotiation on the running connection.
SHA-224 and SHA-256 cryptographic hash function.
int(* f_recv)(void *, unsigned char *, size_t)
Definition: ssl.h:613
unsigned char key_name[16]
Definition: ssl.h:572
int key_own_alloc
Definition: ssl.h:587
int ssl_write(ssl_context *ssl, const unsigned char *buf, size_t len)
Write exactly &#39;len&#39; application data bytes.
ssl_key_cert * next
Definition: ssl.h:588
void ssl_set_ca_chain(ssl_context *ssl, x509_crt *ca_chain, x509_crl *ca_crl, const char *peer_cn)
Set the data required to verify peer certificate.
x509_crt * ca_chain
Definition: ssl.h:702
md5_context fin_md5
Definition: ssl.h:531
int endpoint
Definition: ssl.h:717
int ssl_set_own_cert_alt(ssl_context *ssl, x509_crt *own_cert, void *rsa_key, rsa_decrypt_func rsa_decrypt, rsa_sign_func rsa_sign, rsa_key_len_func rsa_key_len)
Set own certificate and alternate non-PolarSSL RSA private key and handling callbacks, such as the PKCS#11 wrappers or any other external private key handler.
void ssl_set_sni(ssl_context *ssl, int(*f_sni)(void *, ssl_context *, const unsigned char *, size_t), void *p_sni)
Set server side ServerName TLS extension callback (optional, server-side only).
int ssl_fetch_input(ssl_context *ssl, size_t nb_want)
int(* f_psk)(void *, ssl_context *, const unsigned char *, size_t)
Definition: ssl.h:637
int ssl_write_record(ssl_context *ssl)
Public key container.
Definition: pk.h:177
unsigned char * out_iv
Definition: ssl.h:682
unsigned char randbytes[64]
Definition: ssl.h:552
int(* rsa_decrypt_func)(void *ctx, int mode, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len)
Definition: ssl.h:372
Generic message digest context.
Definition: md.h:129
void ssl_optimize_checksum(ssl_context *ssl, const ssl_ciphersuite_t *ciphersuite_info)
x509_crt * peer_cert
Definition: ssl.h:433
md_type_t ssl_md_alg_from_hash(unsigned char hash)
void * p_sni
Definition: ssl.h:628