PageRenderTime 45ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/include/polarssl/ssl.h

https://github.com/leg0/polarssl
C Header | 1111 lines | 433 code | 123 blank | 555 comment | 2 complexity | eed54ebc7daeb7c02a2c07412a6a3dd6 MD5 | raw file
Possible License(s): GPL-2.0
  1. /**
  2. * \file ssl.h
  3. *
  4. * \brief SSL/TLS functions.
  5. *
  6. * Copyright (C) 2006-2012, Brainspark B.V.
  7. *
  8. * This file is part of PolarSSL (http://www.polarssl.org)
  9. * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
  10. *
  11. * All rights reserved.
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License along
  24. * with this program; if not, write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  26. */
  27. #ifndef POLARSSL_SSL_H
  28. #define POLARSSL_SSL_H
  29. #include <time.h>
  30. #include "net.h"
  31. #include "rsa.h"
  32. #include "md5.h"
  33. #include "sha1.h"
  34. #include "sha2.h"
  35. #include "sha4.h"
  36. #include "x509.h"
  37. #include "config.h"
  38. #if defined(POLARSSL_DHM_C)
  39. #include "dhm.h"
  40. #endif
  41. #if defined(POLARSSL_ZLIB_SUPPORT)
  42. #include "zlib.h"
  43. #endif
  44. #if defined(_MSC_VER) && !defined(inline)
  45. #define inline _inline
  46. #else
  47. #if defined(__ARMCC_VERSION) && !defined(inline)
  48. #define inline __inline
  49. #endif /* __ARMCC_VERSION */
  50. #endif /*_MSC_VER */
  51. /*
  52. * SSL Error codes
  53. */
  54. #define POLARSSL_ERR_SSL_FEATURE_UNAVAILABLE -0x7080 /**< The requested feature is not available. */
  55. #define POLARSSL_ERR_SSL_BAD_INPUT_DATA -0x7100 /**< Bad input parameters to function. */
  56. #define POLARSSL_ERR_SSL_INVALID_MAC -0x7180 /**< Verification of the message MAC failed. */
  57. #define POLARSSL_ERR_SSL_INVALID_RECORD -0x7200 /**< An invalid SSL record was received. */
  58. #define POLARSSL_ERR_SSL_CONN_EOF -0x7280 /**< The connection indicated an EOF. */
  59. #define POLARSSL_ERR_SSL_UNKNOWN_CIPHER -0x7300 /**< An unknown cipher was received. */
  60. #define POLARSSL_ERR_SSL_NO_CIPHER_CHOSEN -0x7380 /**< The server has no ciphersuites in common with the client. */
  61. #define POLARSSL_ERR_SSL_NO_SESSION_FOUND -0x7400 /**< No session to recover was found. */
  62. #define POLARSSL_ERR_SSL_NO_CLIENT_CERTIFICATE -0x7480 /**< No client certification received from the client, but required by the authentication mode. */
  63. #define POLARSSL_ERR_SSL_CERTIFICATE_TOO_LARGE -0x7500 /**< Our own certificate(s) is/are too large to send in an SSL message.*/
  64. #define POLARSSL_ERR_SSL_CERTIFICATE_REQUIRED -0x7580 /**< The own certificate is not set, but needed by the server. */
  65. #define POLARSSL_ERR_SSL_PRIVATE_KEY_REQUIRED -0x7600 /**< The own private key is not set, but needed. */
  66. #define POLARSSL_ERR_SSL_CA_CHAIN_REQUIRED -0x7680 /**< No CA Chain is set, but required to operate. */
  67. #define POLARSSL_ERR_SSL_UNEXPECTED_MESSAGE -0x7700 /**< An unexpected message was received from our peer. */
  68. #define POLARSSL_ERR_SSL_FATAL_ALERT_MESSAGE -0x7780 /**< A fatal alert message was received from our peer. */
  69. #define POLARSSL_ERR_SSL_PEER_VERIFY_FAILED -0x7800 /**< Verification of our peer failed. */
  70. #define POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY -0x7880 /**< The peer notified us that the connection is going to be closed. */
  71. #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_HELLO -0x7900 /**< Processing of the ClientHello handshake message failed. */
  72. #define POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO -0x7980 /**< Processing of the ServerHello handshake message failed. */
  73. #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE -0x7A00 /**< Processing of the Certificate handshake message failed. */
  74. #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_REQUEST -0x7A80 /**< Processing of the CertificateRequest handshake message failed. */
  75. #define POLARSSL_ERR_SSL_BAD_HS_SERVER_KEY_EXCHANGE -0x7B00 /**< Processing of the ServerKeyExchange handshake message failed. */
  76. #define POLARSSL_ERR_SSL_BAD_HS_SERVER_HELLO_DONE -0x7B80 /**< Processing of the ServerHelloDone handshake message failed. */
  77. #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE -0x7C00 /**< Processing of the ClientKeyExchange handshake message failed. */
  78. #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_RP -0x7C80 /**< Processing of the ClientKeyExchange handshake message failed in DHM Read Public. */
  79. #define POLARSSL_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE_DHM_CS -0x7D00 /**< Processing of the ClientKeyExchange handshake message failed in DHM Calculate Secret. */
  80. #define POLARSSL_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY -0x7D80 /**< Processing of the CertificateVerify handshake message failed. */
  81. #define POLARSSL_ERR_SSL_BAD_HS_CHANGE_CIPHER_SPEC -0x7E00 /**< Processing of the ChangeCipherSpec handshake message failed. */
  82. #define POLARSSL_ERR_SSL_BAD_HS_FINISHED -0x7E80 /**< Processing of the Finished handshake message failed. */
  83. #define POLARSSL_ERR_SSL_MALLOC_FAILED -0x7F00 /**< Memory allocation failed */
  84. #define POLARSSL_ERR_SSL_HW_ACCEL_FAILED -0x7F80 /**< Hardware acceleration function returned with error */
  85. #define POLARSSL_ERR_SSL_HW_ACCEL_FALLTHROUGH -0x6F80 /**< Hardware acceleration function skipped / left alone data */
  86. #define POLARSSL_ERR_SSL_COMPRESSION_FAILED -0x6F00 /**< Processing of the compression / decompression failed */
  87. #define POLARSSL_ERR_SSL_BAD_HS_PROTOCOL_VERSION -0x6E80 /**< Handshake protocol not within min/max boundaries */
  88. /*
  89. * Various constants
  90. */
  91. #define SSL_MAJOR_VERSION_3 3
  92. #define SSL_MINOR_VERSION_0 0 /*!< SSL v3.0 */
  93. #define SSL_MINOR_VERSION_1 1 /*!< TLS v1.0 */
  94. #define SSL_MINOR_VERSION_2 2 /*!< TLS v1.1 */
  95. #define SSL_MINOR_VERSION_3 3 /*!< TLS v1.2 */
  96. #define SSL_IS_CLIENT 0
  97. #define SSL_IS_SERVER 1
  98. #define SSL_COMPRESS_NULL 0
  99. #define SSL_COMPRESS_DEFLATE 1
  100. #define SSL_VERIFY_NONE 0
  101. #define SSL_VERIFY_OPTIONAL 1
  102. #define SSL_VERIFY_REQUIRED 2
  103. #define SSL_INITIAL_HANDSHAKE 0
  104. #define SSL_RENEGOTIATION 1
  105. #define SSL_LEGACY_RENEGOTIATION 0
  106. #define SSL_SECURE_RENEGOTIATION 1
  107. #define SSL_RENEGOTIATION_DISABLED 0
  108. #define SSL_RENEGOTIATION_ENABLED 1
  109. #define SSL_LEGACY_NO_RENEGOTIATION 0
  110. #define SSL_LEGACY_ALLOW_RENEGOTIATION 1
  111. #define SSL_LEGACY_BREAK_HANDSHAKE 2
  112. #define SSL_MAX_CONTENT_LEN 16384
  113. /*
  114. * Allow an extra 512 bytes for the record header
  115. * and encryption overhead (counter + MAC + padding)
  116. * and allow for a maximum of 1024 of compression expansion if
  117. * enabled.
  118. */
  119. #if defined(POLARSSL_ZLIB_SUPPORT)
  120. #define SSL_COMPRESSION_ADD 1024
  121. #else
  122. #define SSL_COMPRESSION_ADD 0
  123. #endif
  124. #define SSL_BUFFER_LEN (SSL_MAX_CONTENT_LEN + SSL_COMPRESSION_ADD + 512)
  125. /*
  126. * Supported ciphersuites (Official IANA names)
  127. */
  128. #define TLS_RSA_WITH_NULL_MD5 0x01 /**< Weak! */
  129. #define TLS_RSA_WITH_NULL_SHA 0x02 /**< Weak! */
  130. #define TLS_RSA_WITH_NULL_SHA256 0x3B /**< Weak! */
  131. #define TLS_RSA_WITH_DES_CBC_SHA 0x09 /**< Weak! Not in TLS 1.2 */
  132. #define TLS_DHE_RSA_WITH_DES_CBC_SHA 0x15 /**< Weak! Not in TLS 1.2 */
  133. #define TLS_RSA_WITH_RC4_128_MD5 0x04
  134. #define TLS_RSA_WITH_RC4_128_SHA 0x05
  135. #define TLS_RSA_WITH_3DES_EDE_CBC_SHA 0x0A
  136. #define TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA 0x16
  137. #define TLS_RSA_WITH_AES_128_CBC_SHA 0x2F
  138. #define TLS_DHE_RSA_WITH_AES_128_CBC_SHA 0x33
  139. #define TLS_RSA_WITH_AES_256_CBC_SHA 0x35
  140. #define TLS_DHE_RSA_WITH_AES_256_CBC_SHA 0x39
  141. #define TLS_RSA_WITH_AES_128_CBC_SHA256 0x3C /**< TLS 1.2 */
  142. #define TLS_RSA_WITH_AES_256_CBC_SHA256 0x3D /**< TLS 1.2 */
  143. #define TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 0x67 /**< TLS 1.2 */
  144. #define TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 0x6B /**< TLS 1.2 */
  145. #define TLS_RSA_WITH_CAMELLIA_128_CBC_SHA 0x41
  146. #define TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA 0x45
  147. #define TLS_RSA_WITH_CAMELLIA_256_CBC_SHA 0x84
  148. #define TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA 0x88
  149. #define TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xBA /**< TLS 1.2 */
  150. #define TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xBE /**< TLS 1.2 */
  151. #define TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 0xC0 /**< TLS 1.2 */
  152. #define TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 0xC4 /**< TLS 1.2 */
  153. #define TLS_RSA_WITH_AES_128_GCM_SHA256 0x9C
  154. #define TLS_RSA_WITH_AES_256_GCM_SHA384 0x9D
  155. #define TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 0x9E
  156. #define TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 0x9F
  157. #define SSL_EMPTY_RENEGOTIATION_INFO 0xFF /**< renegotiation info ext */
  158. /*
  159. * Supported Signature and Hash algorithms (For TLS 1.2)
  160. */
  161. #define SSL_HASH_NONE 0
  162. #define SSL_HASH_MD5 1
  163. #define SSL_HASH_SHA1 2
  164. #define SSL_HASH_SHA224 3
  165. #define SSL_HASH_SHA256 4
  166. #define SSL_HASH_SHA384 5
  167. #define SSL_HASH_SHA512 6
  168. #define SSL_SIG_RSA 1
  169. /*
  170. * Client Certificate Types
  171. */
  172. #define SSL_CERT_TYPE_RSA_SIGN 1
  173. /*
  174. * Message, alert and handshake types
  175. */
  176. #define SSL_MSG_CHANGE_CIPHER_SPEC 20
  177. #define SSL_MSG_ALERT 21
  178. #define SSL_MSG_HANDSHAKE 22
  179. #define SSL_MSG_APPLICATION_DATA 23
  180. #define SSL_ALERT_LEVEL_WARNING 1
  181. #define SSL_ALERT_LEVEL_FATAL 2
  182. #define SSL_ALERT_MSG_CLOSE_NOTIFY 0 /* 0x00 */
  183. #define SSL_ALERT_MSG_UNEXPECTED_MESSAGE 10 /* 0x0A */
  184. #define SSL_ALERT_MSG_BAD_RECORD_MAC 20 /* 0x14 */
  185. #define SSL_ALERT_MSG_DECRYPTION_FAILED 21 /* 0x15 */
  186. #define SSL_ALERT_MSG_RECORD_OVERFLOW 22 /* 0x16 */
  187. #define SSL_ALERT_MSG_DECOMPRESSION_FAILURE 30 /* 0x1E */
  188. #define SSL_ALERT_MSG_HANDSHAKE_FAILURE 40 /* 0x28 */
  189. #define SSL_ALERT_MSG_NO_CERT 41 /* 0x29 */
  190. #define SSL_ALERT_MSG_BAD_CERT 42 /* 0x2A */
  191. #define SSL_ALERT_MSG_UNSUPPORTED_CERT 43 /* 0x2B */
  192. #define SSL_ALERT_MSG_CERT_REVOKED 44 /* 0x2C */
  193. #define SSL_ALERT_MSG_CERT_EXPIRED 45 /* 0x2D */
  194. #define SSL_ALERT_MSG_CERT_UNKNOWN 46 /* 0x2E */
  195. #define SSL_ALERT_MSG_ILLEGAL_PARAMETER 47 /* 0x2F */
  196. #define SSL_ALERT_MSG_UNKNOWN_CA 48 /* 0x30 */
  197. #define SSL_ALERT_MSG_ACCESS_DENIED 49 /* 0x31 */
  198. #define SSL_ALERT_MSG_DECODE_ERROR 50 /* 0x32 */
  199. #define SSL_ALERT_MSG_DECRYPT_ERROR 51 /* 0x33 */
  200. #define SSL_ALERT_MSG_EXPORT_RESTRICTION 60 /* 0x3C */
  201. #define SSL_ALERT_MSG_PROTOCOL_VERSION 70 /* 0x46 */
  202. #define SSL_ALERT_MSG_INSUFFICIENT_SECURITY 71 /* 0x47 */
  203. #define SSL_ALERT_MSG_INTERNAL_ERROR 80 /* 0x50 */
  204. #define SSL_ALERT_MSG_USER_CANCELED 90 /* 0x5A */
  205. #define SSL_ALERT_MSG_NO_RENEGOTIATION 100 /* 0x64 */
  206. #define SSL_ALERT_MSG_UNSUPPORTED_EXT 110 /* 0x6E */
  207. #define SSL_ALERT_MSG_UNRECOGNIZED_NAME 112 /* 0x70 */
  208. #define SSL_HS_HELLO_REQUEST 0
  209. #define SSL_HS_CLIENT_HELLO 1
  210. #define SSL_HS_SERVER_HELLO 2
  211. #define SSL_HS_CERTIFICATE 11
  212. #define SSL_HS_SERVER_KEY_EXCHANGE 12
  213. #define SSL_HS_CERTIFICATE_REQUEST 13
  214. #define SSL_HS_SERVER_HELLO_DONE 14
  215. #define SSL_HS_CERTIFICATE_VERIFY 15
  216. #define SSL_HS_CLIENT_KEY_EXCHANGE 16
  217. #define SSL_HS_FINISHED 20
  218. /*
  219. * TLS extensions
  220. */
  221. #define TLS_EXT_SERVERNAME 0
  222. #define TLS_EXT_SERVERNAME_HOSTNAME 0
  223. #define TLS_EXT_SIG_ALG 13
  224. #define TLS_EXT_RENEGOTIATION_INFO 0xFF01
  225. /*
  226. * Generic function pointers for allowing external RSA private key
  227. * implementations.
  228. */
  229. typedef int (*rsa_decrypt_func)( void *ctx, int mode, size_t *olen,
  230. const unsigned char *input, unsigned char *output,
  231. size_t output_max_len );
  232. typedef int (*rsa_sign_func)( void *ctx,
  233. int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
  234. int mode, int hash_id, unsigned int hashlen,
  235. const unsigned char *hash, unsigned char *sig );
  236. typedef size_t (*rsa_key_len_func)( void *ctx );
  237. /*
  238. * SSL state machine
  239. */
  240. typedef enum
  241. {
  242. SSL_HELLO_REQUEST,
  243. SSL_CLIENT_HELLO,
  244. SSL_SERVER_HELLO,
  245. SSL_SERVER_CERTIFICATE,
  246. SSL_SERVER_KEY_EXCHANGE,
  247. SSL_CERTIFICATE_REQUEST,
  248. SSL_SERVER_HELLO_DONE,
  249. SSL_CLIENT_CERTIFICATE,
  250. SSL_CLIENT_KEY_EXCHANGE,
  251. SSL_CERTIFICATE_VERIFY,
  252. SSL_CLIENT_CHANGE_CIPHER_SPEC,
  253. SSL_CLIENT_FINISHED,
  254. SSL_SERVER_CHANGE_CIPHER_SPEC,
  255. SSL_SERVER_FINISHED,
  256. SSL_FLUSH_BUFFERS,
  257. SSL_HANDSHAKE_WRAPUP,
  258. SSL_HANDSHAKE_OVER
  259. }
  260. ssl_states;
  261. typedef struct _ssl_session ssl_session;
  262. typedef struct _ssl_context ssl_context;
  263. typedef struct _ssl_transform ssl_transform;
  264. typedef struct _ssl_handshake_params ssl_handshake_params;
  265. /*
  266. * This structure is used for storing current session data.
  267. */
  268. struct _ssl_session
  269. {
  270. time_t start; /*!< starting time */
  271. int ciphersuite; /*!< chosen ciphersuite */
  272. int compression; /*!< chosen compression */
  273. size_t length; /*!< session id length */
  274. unsigned char id[32]; /*!< session identifier */
  275. unsigned char master[48]; /*!< the master secret */
  276. x509_cert *peer_cert; /*!< peer X.509 cert chain */
  277. };
  278. /*
  279. * This structure contains a full set of runtime transform parameters
  280. * either in negotiation or active.
  281. */
  282. struct _ssl_transform
  283. {
  284. /*
  285. * Session specific crypto layer
  286. */
  287. unsigned int keylen; /*!< symmetric key length */
  288. size_t minlen; /*!< min. ciphertext length */
  289. size_t ivlen; /*!< IV length */
  290. size_t fixed_ivlen; /*!< Fixed part of IV (AEAD) */
  291. size_t maclen; /*!< MAC length */
  292. unsigned char iv_enc[16]; /*!< IV (encryption) */
  293. unsigned char iv_dec[16]; /*!< IV (decryption) */
  294. unsigned char mac_enc[32]; /*!< MAC (encryption) */
  295. unsigned char mac_dec[32]; /*!< MAC (decryption) */
  296. uint32_t ctx_enc[136]; /*!< encryption context */
  297. uint32_t ctx_dec[136]; /*!< decryption context */
  298. /*
  299. * Session specific compression layer
  300. */
  301. #if defined(POLARSSL_ZLIB_SUPPORT)
  302. z_stream ctx_deflate; /*!< compression context */
  303. z_stream ctx_inflate; /*!< decompression context */
  304. #endif
  305. };
  306. /*
  307. * This structure contains the parameters only needed during handshake.
  308. */
  309. struct _ssl_handshake_params
  310. {
  311. /*
  312. * Handshake specific crypto variables
  313. */
  314. int sig_alg; /*!< Signature algorithm */
  315. int cert_type; /*!< Requested cert type */
  316. int verify_sig_alg; /*!< Signature algorithm for verify */
  317. #if defined(POLARSSL_DHM_C)
  318. dhm_context dhm_ctx; /*!< DHM key exchange */
  319. #endif
  320. /*
  321. * Checksum contexts
  322. */
  323. md5_context fin_md5;
  324. sha1_context fin_sha1;
  325. sha2_context fin_sha2;
  326. sha4_context fin_sha4;
  327. void (*update_checksum)(ssl_context *, unsigned char *, size_t);
  328. void (*calc_verify)(ssl_context *, unsigned char *);
  329. void (*calc_finished)(ssl_context *, unsigned char *, int);
  330. int (*tls_prf)(unsigned char *, size_t, char *,
  331. unsigned char *, size_t,
  332. unsigned char *, size_t);
  333. size_t pmslen; /*!< premaster length */
  334. unsigned char randbytes[64]; /*!< random bytes */
  335. unsigned char premaster[POLARSSL_MPI_MAX_SIZE];
  336. /*!< premaster secret */
  337. int resume; /*!< session resume indicator*/
  338. };
  339. struct _ssl_context
  340. {
  341. /*
  342. * Miscellaneous
  343. */
  344. int state; /*!< SSL handshake: current state */
  345. int renegotiation; /*!< Initial or renegotiation */
  346. int major_ver; /*!< equal to SSL_MAJOR_VERSION_3 */
  347. int minor_ver; /*!< either 0 (SSL3) or 1 (TLS1.0) */
  348. int max_major_ver; /*!< max. major version from client */
  349. int max_minor_ver; /*!< max. minor version from client */
  350. int min_major_ver; /*!< min. major version accepted */
  351. int min_minor_ver; /*!< min. minor version accepted */
  352. /*
  353. * Callbacks (RNG, debug, I/O, verification)
  354. */
  355. int (*f_rng)(void *, unsigned char *, size_t);
  356. void (*f_dbg)(void *, int, const char *);
  357. int (*f_recv)(void *, unsigned char *, size_t);
  358. int (*f_send)(void *, const unsigned char *, size_t);
  359. int (*f_vrfy)(void *, x509_cert *, int, int *);
  360. int (*f_get_cache)(void *, ssl_session *);
  361. int (*f_set_cache)(void *, const ssl_session *);
  362. int (*f_sni)(void *, ssl_context *, const unsigned char *, size_t);
  363. void *p_rng; /*!< context for the RNG function */
  364. void *p_dbg; /*!< context for the debug function */
  365. void *p_recv; /*!< context for reading operations */
  366. void *p_send; /*!< context for writing operations */
  367. void *p_vrfy; /*!< context for verification */
  368. void *p_get_cache; /*!< context for cache retrieval */
  369. void *p_set_cache; /*!< context for cache store */
  370. void *p_sni; /*!< context for SNI extension */
  371. void *p_hw_data; /*!< context for HW acceleration */
  372. /*
  373. * Session layer
  374. */
  375. ssl_session *session_in; /*!< current session data (in) */
  376. ssl_session *session_out; /*!< current session data (out) */
  377. ssl_session *session; /*!< negotiated session data */
  378. ssl_session *session_negotiate; /*!< session data in negotiation */
  379. ssl_handshake_params *handshake; /*!< params required only during
  380. the handshake process */
  381. /*
  382. * Record layer transformations
  383. */
  384. ssl_transform *transform_in; /*!< current transform params (in) */
  385. ssl_transform *transform_out; /*!< current transform params (in) */
  386. ssl_transform *transform; /*!< negotiated transform params */
  387. ssl_transform *transform_negotiate; /*!< transform params in negotiation */
  388. /*
  389. * Record layer (incoming data)
  390. */
  391. unsigned char *in_ctr; /*!< 64-bit incoming message counter */
  392. unsigned char *in_hdr; /*!< 5-byte record header (in_ctr+8) */
  393. unsigned char *in_msg; /*!< the message contents (in_hdr+5) */
  394. unsigned char *in_offt; /*!< read offset in application data */
  395. int in_msgtype; /*!< record header: message type */
  396. size_t in_msglen; /*!< record header: message length */
  397. size_t in_left; /*!< amount of data read so far */
  398. size_t in_hslen; /*!< current handshake message length */
  399. int nb_zero; /*!< # of 0-length encrypted messages */
  400. /*
  401. * Record layer (outgoing data)
  402. */
  403. unsigned char *out_ctr; /*!< 64-bit outgoing message counter */
  404. unsigned char *out_hdr; /*!< 5-byte record header (out_ctr+8) */
  405. unsigned char *out_msg; /*!< the message contents (out_hdr+32)*/
  406. int out_msgtype; /*!< record header: message type */
  407. size_t out_msglen; /*!< record header: message length */
  408. size_t out_left; /*!< amount of data not yet written */
  409. /*
  410. * PKI layer
  411. */
  412. void *rsa_key; /*!< own RSA private key */
  413. rsa_decrypt_func rsa_decrypt; /*!< function for RSA decrypt*/
  414. rsa_sign_func rsa_sign; /*!< function for RSA sign */
  415. rsa_key_len_func rsa_key_len; /*!< function for RSA key len*/
  416. x509_cert *own_cert; /*!< own X.509 certificate */
  417. x509_cert *ca_chain; /*!< own trusted CA chain */
  418. x509_crl *ca_crl; /*!< trusted CA CRLs */
  419. const char *peer_cn; /*!< expected peer CN */
  420. /*
  421. * User settings
  422. */
  423. int endpoint; /*!< 0: client, 1: server */
  424. int authmode; /*!< verification mode */
  425. int client_auth; /*!< flag for client auth. */
  426. int verify_result; /*!< verification result */
  427. int disable_renegotiation; /*!< enable/disable renegotiation */
  428. int allow_legacy_renegotiation; /*!< allow legacy renegotiation */
  429. const int *ciphersuites; /*!< allowed ciphersuites */
  430. #if defined(POLARSSL_DHM_C)
  431. mpi dhm_P; /*!< prime modulus for DHM */
  432. mpi dhm_G; /*!< generator for DHM */
  433. #endif
  434. /*
  435. * TLS extensions
  436. */
  437. unsigned char *hostname;
  438. size_t hostname_len;
  439. /*
  440. * Secure renegotiation
  441. */
  442. int secure_renegotiation; /*!< does peer support legacy or
  443. secure renegotiation */
  444. size_t verify_data_len; /*!< length of verify data stored */
  445. char own_verify_data[36]; /*!< previous handshake verify data */
  446. char peer_verify_data[36]; /*!< previous handshake verify data */
  447. };
  448. #ifdef __cplusplus
  449. extern "C" {
  450. #endif
  451. extern const int ssl_default_ciphersuites[];
  452. #if defined(POLARSSL_SSL_HW_RECORD_ACCEL)
  453. extern int (*ssl_hw_record_init)(ssl_context *ssl,
  454. const unsigned char *key_enc, const unsigned char *key_dec,
  455. const unsigned char *iv_enc, const unsigned char *iv_dec,
  456. const unsigned char *mac_enc, const unsigned char *mac_dec);
  457. extern int (*ssl_hw_record_reset)(ssl_context *ssl);
  458. extern int (*ssl_hw_record_write)(ssl_context *ssl);
  459. extern int (*ssl_hw_record_read)(ssl_context *ssl);
  460. extern int (*ssl_hw_record_finish)(ssl_context *ssl);
  461. #endif
  462. /**
  463. * \brief Returns the list of ciphersuites supported by the SSL/TLS module.
  464. *
  465. * \return a statically allocated array of ciphersuites, the last
  466. * entry is 0.
  467. */
  468. static inline const int *ssl_list_ciphersuites( void )
  469. {
  470. return ssl_default_ciphersuites;
  471. }
  472. /**
  473. * \brief Return the name of the ciphersuite associated with the given
  474. * ID
  475. *
  476. * \param ciphersuite_id SSL ciphersuite ID
  477. *
  478. * \return a string containing the ciphersuite name
  479. */
  480. const char *ssl_get_ciphersuite_name( const int ciphersuite_id );
  481. /**
  482. * \brief Return the ID of the ciphersuite associated with the given
  483. * name
  484. *
  485. * \param ciphersuite_name SSL ciphersuite name
  486. *
  487. * \return the ID with the ciphersuite or 0 if not found
  488. */
  489. int ssl_get_ciphersuite_id( const char *ciphersuite_name );
  490. /**
  491. * \brief Initialize an SSL context
  492. *
  493. * \param ssl SSL context
  494. *
  495. * \return 0 if successful, or POLARSSL_ERR_SSL_MALLOC_FAILED if
  496. * memory allocation failed
  497. */
  498. int ssl_init( ssl_context *ssl );
  499. /**
  500. * \brief Reset an already initialized SSL context for re-use
  501. * while retaining application-set variables, function
  502. * pointers and data.
  503. *
  504. * \param ssl SSL context
  505. * \return 0 if successful, or POLASSL_ERR_SSL_MALLOC_FAILED,
  506. POLARSSL_ERR_SSL_HW_ACCEL_FAILED or
  507. * POLARSSL_ERR_SSL_COMPRESSION_FAILED
  508. */
  509. int ssl_session_reset( ssl_context *ssl );
  510. /**
  511. * \brief Set the current endpoint type
  512. *
  513. * \param ssl SSL context
  514. * \param endpoint must be SSL_IS_CLIENT or SSL_IS_SERVER
  515. */
  516. void ssl_set_endpoint( ssl_context *ssl, int endpoint );
  517. /**
  518. * \brief Set the certificate verification mode
  519. *
  520. * \param ssl SSL context
  521. * \param authmode can be:
  522. *
  523. * SSL_VERIFY_NONE: peer certificate is not checked (default),
  524. * this is insecure and SHOULD be avoided.
  525. *
  526. * SSL_VERIFY_OPTIONAL: peer certificate is checked, however the
  527. * handshake continues even if verification failed;
  528. * ssl_get_verify_result() can be called after the
  529. * handshake is complete.
  530. *
  531. * SSL_VERIFY_REQUIRED: peer *must* present a valid certificate,
  532. * handshake is aborted if verification failed.
  533. */
  534. void ssl_set_authmode( ssl_context *ssl, int authmode );
  535. /**
  536. * \brief Set the verification callback (Optional).
  537. *
  538. * If set, the verify callback is called for each
  539. * certificate in the chain. For implementation
  540. * information, please see \c x509parse_verify()
  541. *
  542. * \param ssl SSL context
  543. * \param f_vrfy verification function
  544. * \param p_vrfy verification parameter
  545. */
  546. void ssl_set_verify( ssl_context *ssl,
  547. int (*f_vrfy)(void *, x509_cert *, int, int *),
  548. void *p_vrfy );
  549. /**
  550. * \brief Set the random number generator callback
  551. *
  552. * \param ssl SSL context
  553. * \param f_rng RNG function
  554. * \param p_rng RNG parameter
  555. */
  556. void ssl_set_rng( ssl_context *ssl,
  557. int (*f_rng)(void *, unsigned char *, size_t),
  558. void *p_rng );
  559. /**
  560. * \brief Set the debug callback
  561. *
  562. * \param ssl SSL context
  563. * \param f_dbg debug function
  564. * \param p_dbg debug parameter
  565. */
  566. void ssl_set_dbg( ssl_context *ssl,
  567. void (*f_dbg)(void *, int, const char *),
  568. void *p_dbg );
  569. /**
  570. * \brief Set the underlying BIO read and write callbacks
  571. *
  572. * \param ssl SSL context
  573. * \param f_recv read callback
  574. * \param p_recv read parameter
  575. * \param f_send write callback
  576. * \param p_send write parameter
  577. */
  578. void ssl_set_bio( ssl_context *ssl,
  579. int (*f_recv)(void *, unsigned char *, size_t), void *p_recv,
  580. int (*f_send)(void *, const unsigned char *, size_t), void *p_send );
  581. /**
  582. * \brief Set the session cache callbacks (server-side only)
  583. * If not set, no session resuming is done.
  584. *
  585. * The session cache has the responsibility to check for stale
  586. * entries based on timeout. See RFC 5246 for recommendations.
  587. *
  588. * Warning: session.peer_cert is cleared by the SSL/TLS layer on
  589. * connection shutdown, so do not cache the pointer! Either set
  590. * it to NULL or make a full copy of the certificate.
  591. *
  592. * The get callback is called once during the initial handshake
  593. * to enable session resuming. The get function has the
  594. * following parameters: (void *parameter, ssl_session *session)
  595. * If a valid entry is found, it should fill the master of
  596. * the session object with the cached values and return 0,
  597. * return 1 otherwise. Optionally peer_cert can be set as well
  598. * if it is properly present in cache entry.
  599. *
  600. * The set callback is called once during the initial handshake
  601. * to enable session resuming after the entire handshake has
  602. * been finished. The set function has the following parameters:
  603. * (void *parameter, const ssl_session *session). The function
  604. * should create a cache entry for future retrieval based on
  605. * the data in the session structure and should keep in mind
  606. * that the ssl_session object presented (and all its referenced
  607. * data) is cleared by the SSL/TLS layer when the connection is
  608. * terminated. It is recommended to add metadata to determine if
  609. * an entry is still valid in the future. Return 0 if
  610. * successfully cached, return 1 otherwise.
  611. *
  612. * \param ssl SSL context
  613. * \param f_get_cache session get callback
  614. * \param p_get_cache session get parameter
  615. * \param f_set_cache session set callback
  616. * \param p_set_cache session set parameter
  617. */
  618. void ssl_set_session_cache( ssl_context *ssl,
  619. int (*f_get_cache)(void *, ssl_session *), void *p_get_cache,
  620. int (*f_set_cache)(void *, const ssl_session *), void *p_set_cache );
  621. /**
  622. * \brief Request resumption of session (client-side only)
  623. * Session data is copied from presented session structure.
  624. *
  625. * Warning: session.peer_cert is cleared by the SSL/TLS layer on
  626. * connection shutdown, so do not cache the pointer! Either set
  627. * it to NULL or make a full copy of the certificate when
  628. * storing the session for use in this function.
  629. *
  630. * \param ssl SSL context
  631. * \param session session context
  632. */
  633. void ssl_set_session( ssl_context *ssl, const ssl_session *session );
  634. /**
  635. * \brief Set the list of allowed ciphersuites
  636. *
  637. * \param ssl SSL context
  638. * \param ciphersuites 0-terminated list of allowed ciphersuites
  639. */
  640. void ssl_set_ciphersuites( ssl_context *ssl, const int *ciphersuites );
  641. /**
  642. * \brief Set the data required to verify peer certificate
  643. *
  644. * \param ssl SSL context
  645. * \param ca_chain trusted CA chain (meaning all fully trusted top-level CAs)
  646. * \param ca_crl trusted CA CRLs
  647. * \param peer_cn expected peer CommonName (or NULL)
  648. */
  649. void ssl_set_ca_chain( ssl_context *ssl, x509_cert *ca_chain,
  650. x509_crl *ca_crl, const char *peer_cn );
  651. /**
  652. * \brief Set own certificate chain and private key
  653. *
  654. * Note: own_cert should contain IN order from the bottom
  655. * up your certificate chain. The top certificate (self-signed)
  656. * can be omitted.
  657. *
  658. * \param ssl SSL context
  659. * \param own_cert own public certificate chain
  660. * \param rsa_key own private RSA key
  661. */
  662. void ssl_set_own_cert( ssl_context *ssl, x509_cert *own_cert,
  663. rsa_context *rsa_key );
  664. /**
  665. * \brief Set own certificate and alternate non-PolarSSL private
  666. * key and handling callbacks, such as the PKCS#11 wrappers
  667. * or any other external private key handler.
  668. * (see the respective RSA functions in rsa.h for documentation
  669. * of the callback parameters, with the only change being
  670. * that the rsa_context * is a void * in the callbacks)
  671. *
  672. * Note: own_cert should contain IN order from the bottom
  673. * up your certificate chain. The top certificate (self-signed)
  674. * can be omitted.
  675. *
  676. * \param ssl SSL context
  677. * \param own_cert own public certificate chain
  678. * \param rsa_key alternate implementation private RSA key
  679. * \param rsa_decrypt_func alternate implementation of \c rsa_pkcs1_decrypt()
  680. * \param rsa_sign_func alternate implementation of \c rsa_pkcs1_sign()
  681. * \param rsa_key_len_func function returning length of RSA key in bytes
  682. */
  683. void ssl_set_own_cert_alt( ssl_context *ssl, x509_cert *own_cert,
  684. void *rsa_key,
  685. rsa_decrypt_func rsa_decrypt,
  686. rsa_sign_func rsa_sign,
  687. rsa_key_len_func rsa_key_len );
  688. #if defined(POLARSSL_DHM_C)
  689. /**
  690. * \brief Set the Diffie-Hellman public P and G values,
  691. * read as hexadecimal strings (server-side only)
  692. * (Default: POLARSSL_DHM_RFC5114_MODP_1024_[PG])
  693. *
  694. * \param ssl SSL context
  695. * \param dhm_P Diffie-Hellman-Merkle modulus
  696. * \param dhm_G Diffie-Hellman-Merkle generator
  697. *
  698. * \return 0 if successful
  699. */
  700. int ssl_set_dh_param( ssl_context *ssl, const char *dhm_P, const char *dhm_G );
  701. /**
  702. * \brief Set the Diffie-Hellman public P and G values,
  703. * read from existing context (server-side only)
  704. *
  705. * \param ssl SSL context
  706. * \param dhm_ctx Diffie-Hellman-Merkle context
  707. *
  708. * \return 0 if successful
  709. */
  710. int ssl_set_dh_param_ctx( ssl_context *ssl, dhm_context *dhm_ctx );
  711. #endif
  712. /**
  713. * \brief Set hostname for ServerName TLS extension
  714. * (client-side only)
  715. *
  716. *
  717. * \param ssl SSL context
  718. * \param hostname the server hostname
  719. *
  720. * \return 0 if successful or POLARSSL_ERR_SSL_MALLOC_FAILED
  721. */
  722. int ssl_set_hostname( ssl_context *ssl, const char *hostname );
  723. /**
  724. * \brief Set server side ServerName TLS extension callback
  725. * (optional, server-side only).
  726. *
  727. * If set, the ServerName callback is called whenever the
  728. * server receives a ServerName TLS extension from the client
  729. * during a handshake. The ServerName callback has the
  730. * following parameters: (void *parameter, ssl_context *ssl,
  731. * const unsigned char *hostname, size_t len). If a suitable
  732. * certificate is found, the callback should set the
  733. * certificate and key to use with ssl_set_own_cert() (and
  734. * possibly adjust the CA chain as well) and return 0. The
  735. * callback should return -1 to abort the handshake at this
  736. * point.
  737. *
  738. * \param ssl SSL context
  739. * \param f_sni verification function
  740. * \param p_sni verification parameter
  741. */
  742. void ssl_set_sni( ssl_context *ssl,
  743. int (*f_sni)(void *, ssl_context *, const unsigned char *,
  744. size_t),
  745. void *p_sni );
  746. /**
  747. * \brief Set the maximum supported version sent from the client side
  748. *
  749. * \param ssl SSL context
  750. * \param major Major version number (only SSL_MAJOR_VERSION_3 supported)
  751. * \param minor Minor version number (SSL_MINOR_VERSION_0,
  752. * SSL_MINOR_VERSION_1 and SSL_MINOR_VERSION_2,
  753. * SSL_MINOR_VERSION_3 supported)
  754. */
  755. void ssl_set_max_version( ssl_context *ssl, int major, int minor );
  756. /**
  757. * \brief Set the minimum accepted SSL/TLS protocol version
  758. * (Default: SSL_MAJOR_VERSION_3, SSL_MINOR_VERSION_0)
  759. *
  760. * \param ssl SSL context
  761. * \param major Major version number (only SSL_MAJOR_VERSION_3 supported)
  762. * \param minor Minor version number (SSL_MINOR_VERSION_0,
  763. * SSL_MINOR_VERSION_1 and SSL_MINOR_VERSION_2,
  764. * SSL_MINOR_VERSION_3 supported)
  765. */
  766. void ssl_set_min_version( ssl_context *ssl, int major, int minor );
  767. /**
  768. * \brief Enable / Disable renegotiation support for connection when
  769. * initiated by peer
  770. * (Default: SSL_RENEGOTIATION_DISABLED)
  771. *
  772. * Note: A server with support enabled is more vulnerable for a
  773. * resource DoS by a malicious client. You should enable this on
  774. * a client to enable server-initiated renegotiation.
  775. *
  776. * \param ssl SSL context
  777. * \param renegotiation Enable or disable (SSL_RENEGOTIATION_ENABLED or
  778. * SSL_RENEGOTIATION_DISABLED)
  779. */
  780. void ssl_set_renegotiation( ssl_context *ssl, int renegotiation );
  781. /**
  782. * \brief Prevent or allow legacy renegotiation.
  783. * (Default: SSL_LEGACY_NO_RENEGOTIATION)
  784. *
  785. * SSL_LEGACY_NO_RENEGOTIATION allows connections to
  786. * be established even if the peer does not support
  787. * secure renegotiation, but does not allow renegotiation
  788. * to take place if not secure.
  789. * (Interoperable and secure option)
  790. *
  791. * SSL_LEGACY_ALLOW_RENEGOTIATION allows renegotiations
  792. * with non-upgraded peers. Allowing legacy renegotiation
  793. * makes the connection vulnerable to specific man in the
  794. * middle attacks. (See RFC 5746)
  795. * (Most interoperable and least secure option)
  796. *
  797. * SSL_LEGACY_BREAK_HANDSHAKE breaks off connections
  798. * if peer does not support secure renegotiation. Results
  799. * in interoperability issues with non-upgraded peers
  800. * that do not support renegotiation altogether.
  801. * (Most secure option, interoperability issues)
  802. *
  803. * \param ssl SSL context
  804. * \param allow_legacy Prevent or allow (SSL_NO_LEGACY_RENEGOTIATION,
  805. * SSL_ALLOW_LEGACY_RENEGOTIATION or
  806. * SSL_LEGACY_BREAK_HANDSHAKE)
  807. */
  808. void ssl_legacy_renegotiation( ssl_context *ssl, int allow_legacy );
  809. /**
  810. * \brief Return the number of data bytes available to read
  811. *
  812. * \param ssl SSL context
  813. *
  814. * \return how many bytes are available in the read buffer
  815. */
  816. size_t ssl_get_bytes_avail( const ssl_context *ssl );
  817. /**
  818. * \brief Return the result of the certificate verification
  819. *
  820. * \param ssl SSL context
  821. *
  822. * \return 0 if successful, or a combination of:
  823. * BADCERT_EXPIRED
  824. * BADCERT_REVOKED
  825. * BADCERT_CN_MISMATCH
  826. * BADCERT_NOT_TRUSTED
  827. */
  828. int ssl_get_verify_result( const ssl_context *ssl );
  829. /**
  830. * \brief Return the name of the current ciphersuite
  831. *
  832. * \param ssl SSL context
  833. *
  834. * \return a string containing the ciphersuite name
  835. */
  836. const char *ssl_get_ciphersuite( const ssl_context *ssl );
  837. /**
  838. * \brief Return the current SSL version (SSLv3/TLSv1/etc)
  839. *
  840. * \param ssl SSL context
  841. *
  842. * \return a string containing the SSL version
  843. */
  844. const char *ssl_get_version( const ssl_context *ssl );
  845. /**
  846. * \brief Return the peer certificate from the current connection
  847. *
  848. * Note: Can be NULL in case no certificate was sent during
  849. * the handshake. Different calls for the same connection can
  850. * return the same or different pointers for the same
  851. * certificate and even a different certificate altogether.
  852. * The peer cert CAN change in a single connection if
  853. * renegotiation is performed.
  854. *
  855. * \param ssl SSL context
  856. *
  857. * \return the current peer certificate
  858. */
  859. const x509_cert *ssl_get_peer_cert( const ssl_context *ssl );
  860. /**
  861. * \brief Perform the SSL handshake
  862. *
  863. * \param ssl SSL context
  864. *
  865. * \return 0 if successful, POLARSSL_ERR_NET_WANT_READ,
  866. * POLARSSL_ERR_NET_WANT_WRITE, or a specific SSL error code.
  867. */
  868. int ssl_handshake( ssl_context *ssl );
  869. /**
  870. * \brief Perform a single step of the SSL handshake
  871. *
  872. * Note: the state of the context (ssl->state) will be at
  873. * the following state after execution of this function.
  874. * Do not call this function if state is SSL_HANDSHAKE_OVER.
  875. *
  876. * \param ssl SSL context
  877. *
  878. * \return 0 if successful, POLARSSL_ERR_NET_WANT_READ,
  879. * POLARSSL_ERR_NET_WANT_WRITE, or a specific SSL error code.
  880. */
  881. int ssl_handshake_step( ssl_context *ssl );
  882. /**
  883. * \brief Perform an SSL renegotiation on the running connection
  884. *
  885. * \param ssl SSL context
  886. *
  887. * \return 0 if succesful, or any ssl_handshake() return value.
  888. */
  889. int ssl_renegotiate( ssl_context *ssl );
  890. /**
  891. * \brief Read at most 'len' application data bytes
  892. *
  893. * \param ssl SSL context
  894. * \param buf buffer that will hold the data
  895. * \param len how many bytes must be read
  896. *
  897. * \return This function returns the number of bytes read, 0 for EOF,
  898. * or a negative error code.
  899. */
  900. int ssl_read( ssl_context *ssl, unsigned char *buf, size_t len );
  901. /**
  902. * \brief Write exactly 'len' application data bytes
  903. *
  904. * \param ssl SSL context
  905. * \param buf buffer holding the data
  906. * \param len how many bytes must be written
  907. *
  908. * \return This function returns the number of bytes written,
  909. * or a negative error code.
  910. *
  911. * \note When this function returns POLARSSL_ERR_NET_WANT_WRITE,
  912. * it must be called later with the *same* arguments,
  913. * until it returns a positive value.
  914. */
  915. int ssl_write( ssl_context *ssl, const unsigned char *buf, size_t len );
  916. /**
  917. * \brief Send an alert message
  918. *
  919. * \param ssl SSL context
  920. * \param level The alert level of the message
  921. * (SSL_ALERT_LEVEL_WARNING or SSL_ALERT_LEVEL_FATAL)
  922. * \param message The alert message (SSL_ALERT_MSG_*)
  923. *
  924. * \return 0 if successful, or a specific SSL error code.
  925. */
  926. int ssl_send_alert_message( ssl_context *ssl,
  927. unsigned char level,
  928. unsigned char message );
  929. /**
  930. * \brief Notify the peer that the connection is being closed
  931. *
  932. * \param ssl SSL context
  933. */
  934. int ssl_close_notify( ssl_context *ssl );
  935. /**
  936. * \brief Free referenced items in an SSL context and clear memory
  937. *
  938. * \param ssl SSL context
  939. */
  940. void ssl_free( ssl_context *ssl );
  941. /**
  942. * \brief Free referenced items in an SSL session including the
  943. * peer certificate and clear memory
  944. *
  945. * \param session SSL session
  946. */
  947. void ssl_session_free( ssl_session *session );
  948. /**
  949. * \brief Free referenced items in an SSL transform context and clear
  950. * memory
  951. *
  952. * \param transform SSL transform context
  953. */
  954. void ssl_transform_free( ssl_transform *transform );
  955. /**
  956. * \brief Free referenced items in an SSL handshake context and clear
  957. * memory
  958. *
  959. * \param handshake SSL handshake context
  960. */
  961. void ssl_handshake_free( ssl_handshake_params *handshake );
  962. /*
  963. * Internal functions (do not call directly)
  964. */
  965. int ssl_handshake_client_step( ssl_context *ssl );
  966. int ssl_handshake_server_step( ssl_context *ssl );
  967. void ssl_handshake_wrapup( ssl_context *ssl );
  968. int ssl_send_fatal_handshake_failure( ssl_context *ssl );
  969. int ssl_derive_keys( ssl_context *ssl );
  970. int ssl_read_record( ssl_context *ssl );
  971. /**
  972. * \return 0 if successful, POLARSSL_ERR_SSL_CONN_EOF on EOF or
  973. * another negative error code.
  974. */
  975. int ssl_fetch_input( ssl_context *ssl, size_t nb_want );
  976. int ssl_write_record( ssl_context *ssl );
  977. int ssl_flush_output( ssl_context *ssl );
  978. int ssl_parse_certificate( ssl_context *ssl );
  979. int ssl_write_certificate( ssl_context *ssl );
  980. int ssl_parse_change_cipher_spec( ssl_context *ssl );
  981. int ssl_write_change_cipher_spec( ssl_context *ssl );
  982. int ssl_parse_finished( ssl_context *ssl );
  983. int ssl_write_finished( ssl_context *ssl );
  984. void ssl_optimize_checksum( ssl_context *ssl, int ciphersuite );
  985. #ifdef __cplusplus
  986. }
  987. #endif
  988. #endif /* ssl.h */