Home | History | Annotate | Download | only in crypto
      1 /*
      2  * SSL/TLS interface definition
      3  * Copyright (c) 2004-2013, Jouni Malinen <j (at) w1.fi>
      4  *
      5  * This software may be distributed under the terms of the BSD license.
      6  * See README for more details.
      7  */
      8 
      9 #ifndef TLS_H
     10 #define TLS_H
     11 
     12 struct tls_connection;
     13 
     14 struct tls_random {
     15 	const u8 *client_random;
     16 	size_t client_random_len;
     17 	const u8 *server_random;
     18 	size_t server_random_len;
     19 };
     20 
     21 enum tls_event {
     22 	TLS_CERT_CHAIN_SUCCESS,
     23 	TLS_CERT_CHAIN_FAILURE,
     24 	TLS_PEER_CERTIFICATE,
     25 	TLS_ALERT
     26 };
     27 
     28 /*
     29  * Note: These are used as identifier with external programs and as such, the
     30  * values must not be changed.
     31  */
     32 enum tls_fail_reason {
     33 	TLS_FAIL_UNSPECIFIED = 0,
     34 	TLS_FAIL_UNTRUSTED = 1,
     35 	TLS_FAIL_REVOKED = 2,
     36 	TLS_FAIL_NOT_YET_VALID = 3,
     37 	TLS_FAIL_EXPIRED = 4,
     38 	TLS_FAIL_SUBJECT_MISMATCH = 5,
     39 	TLS_FAIL_ALTSUBJECT_MISMATCH = 6,
     40 	TLS_FAIL_BAD_CERTIFICATE = 7,
     41 	TLS_FAIL_SERVER_CHAIN_PROBE = 8,
     42 	TLS_FAIL_DOMAIN_SUFFIX_MISMATCH = 9,
     43 	TLS_FAIL_DOMAIN_MISMATCH = 10,
     44 	TLS_FAIL_INSUFFICIENT_KEY_LEN = 11,
     45 };
     46 
     47 
     48 #define TLS_MAX_ALT_SUBJECT 10
     49 
     50 union tls_event_data {
     51 	struct {
     52 		int depth;
     53 		const char *subject;
     54 		enum tls_fail_reason reason;
     55 		const char *reason_txt;
     56 		const struct wpabuf *cert;
     57 	} cert_fail;
     58 
     59 	struct {
     60 		int depth;
     61 		const char *subject;
     62 		const struct wpabuf *cert;
     63 		const u8 *hash;
     64 		size_t hash_len;
     65 		const char *altsubject[TLS_MAX_ALT_SUBJECT];
     66 		int num_altsubject;
     67 	} peer_cert;
     68 
     69 	struct {
     70 		int is_local;
     71 		const char *type;
     72 		const char *description;
     73 	} alert;
     74 };
     75 
     76 struct tls_config {
     77 	const char *opensc_engine_path;
     78 	const char *pkcs11_engine_path;
     79 	const char *pkcs11_module_path;
     80 	int fips_mode;
     81 	int cert_in_cb;
     82 	const char *openssl_ciphers;
     83 	unsigned int tls_session_lifetime;
     84 	unsigned int tls_flags;
     85 
     86 	void (*event_cb)(void *ctx, enum tls_event ev,
     87 			 union tls_event_data *data);
     88 	void *cb_ctx;
     89 };
     90 
     91 #define TLS_CONN_ALLOW_SIGN_RSA_MD5 BIT(0)
     92 #define TLS_CONN_DISABLE_TIME_CHECKS BIT(1)
     93 #define TLS_CONN_DISABLE_SESSION_TICKET BIT(2)
     94 #define TLS_CONN_REQUEST_OCSP BIT(3)
     95 #define TLS_CONN_REQUIRE_OCSP BIT(4)
     96 #define TLS_CONN_DISABLE_TLSv1_1 BIT(5)
     97 #define TLS_CONN_DISABLE_TLSv1_2 BIT(6)
     98 #define TLS_CONN_EAP_FAST BIT(7)
     99 #define TLS_CONN_DISABLE_TLSv1_0 BIT(8)
    100 #define TLS_CONN_EXT_CERT_CHECK BIT(9)
    101 #define TLS_CONN_REQUIRE_OCSP_ALL BIT(10)
    102 #define TLS_CONN_SUITEB BIT(11)
    103 #define TLS_CONN_SUITEB_NO_ECDH BIT(12)
    104 
    105 /**
    106  * struct tls_connection_params - Parameters for TLS connection
    107  * @ca_cert: File or reference name for CA X.509 certificate in PEM or DER
    108  * format
    109  * @ca_cert_blob: ca_cert as inlined data or %NULL if not used
    110  * @ca_cert_blob_len: ca_cert_blob length
    111  * @ca_path: Path to CA certificates (OpenSSL specific)
    112  * @subject_match: String to match in the subject of the peer certificate or
    113  * %NULL to allow all subjects
    114  * @altsubject_match: String to match in the alternative subject of the peer
    115  * certificate or %NULL to allow all alternative subjects
    116  * @suffix_match: String to suffix match in the dNSName or CN of the peer
    117  * certificate or %NULL to allow all domain names. This may allow subdomains an
    118  * wildcard certificates. Each domain name label must have a full match.
    119  * @domain_match: String to match in the dNSName or CN of the peer
    120  * certificate or %NULL to allow all domain names. This requires a full,
    121  * case-insensitive match.
    122  * @client_cert: File or reference name for client X.509 certificate in PEM or
    123  * DER format
    124  * @client_cert_blob: client_cert as inlined data or %NULL if not used
    125  * @client_cert_blob_len: client_cert_blob length
    126  * @private_key: File or reference name for client private key in PEM or DER
    127  * format (traditional format (RSA PRIVATE KEY) or PKCS#8 (PRIVATE KEY)
    128  * @private_key_blob: private_key as inlined data or %NULL if not used
    129  * @private_key_blob_len: private_key_blob length
    130  * @private_key_passwd: Passphrase for decrypted private key, %NULL if no
    131  * passphrase is used.
    132  * @dh_file: File name for DH/DSA data in PEM format, or %NULL if not used
    133  * @dh_blob: dh_file as inlined data or %NULL if not used
    134  * @dh_blob_len: dh_blob length
    135  * @engine: 1 = use engine (e.g., a smartcard) for private key operations
    136  * (this is OpenSSL specific for now)
    137  * @engine_id: engine id string (this is OpenSSL specific for now)
    138  * @ppin: pointer to the pin variable in the configuration
    139  * (this is OpenSSL specific for now)
    140  * @key_id: the private key's id when using engine (this is OpenSSL
    141  * specific for now)
    142  * @cert_id: the certificate's id when using engine
    143  * @ca_cert_id: the CA certificate's id when using engine
    144  * @openssl_ciphers: OpenSSL cipher configuration
    145  * @flags: Parameter options (TLS_CONN_*)
    146  * @ocsp_stapling_response: DER encoded file with cached OCSP stapling response
    147  *	or %NULL if OCSP is not enabled
    148  * @ocsp_stapling_response_multi: DER encoded file with cached OCSP stapling
    149  *	response list (OCSPResponseList for ocsp_multi in RFC 6961) or %NULL if
    150  *	ocsp_multi is not enabled
    151  *
    152  * TLS connection parameters to be configured with tls_connection_set_params()
    153  * and tls_global_set_params().
    154  *
    155  * Certificates and private key can be configured either as a reference name
    156  * (file path or reference to certificate store) or by providing the same data
    157  * as a pointer to the data in memory. Only one option will be used for each
    158  * field.
    159  */
    160 struct tls_connection_params {
    161 	const char *ca_cert;
    162 	const u8 *ca_cert_blob;
    163 	size_t ca_cert_blob_len;
    164 	const char *ca_path;
    165 	const char *subject_match;
    166 	const char *altsubject_match;
    167 	const char *suffix_match;
    168 	const char *domain_match;
    169 	const char *client_cert;
    170 	const u8 *client_cert_blob;
    171 	size_t client_cert_blob_len;
    172 	const char *private_key;
    173 	const u8 *private_key_blob;
    174 	size_t private_key_blob_len;
    175 	const char *private_key_passwd;
    176 	const char *dh_file;
    177 	const u8 *dh_blob;
    178 	size_t dh_blob_len;
    179 
    180 	/* OpenSSL specific variables */
    181 	int engine;
    182 	const char *engine_id;
    183 	const char *pin;
    184 	const char *key_id;
    185 	const char *cert_id;
    186 	const char *ca_cert_id;
    187 	const char *openssl_ciphers;
    188 
    189 	unsigned int flags;
    190 	const char *ocsp_stapling_response;
    191 	const char *ocsp_stapling_response_multi;
    192 };
    193 
    194 
    195 /**
    196  * tls_init - Initialize TLS library
    197  * @conf: Configuration data for TLS library
    198  * Returns: Context data to be used as tls_ctx in calls to other functions,
    199  * or %NULL on failure.
    200  *
    201  * Called once during program startup and once for each RSN pre-authentication
    202  * session. In other words, there can be two concurrent TLS contexts. If global
    203  * library initialization is needed (i.e., one that is shared between both
    204  * authentication types), the TLS library wrapper should maintain a reference
    205  * counter and do global initialization only when moving from 0 to 1 reference.
    206  */
    207 void * tls_init(const struct tls_config *conf);
    208 
    209 /**
    210  * tls_deinit - Deinitialize TLS library
    211  * @tls_ctx: TLS context data from tls_init()
    212  *
    213  * Called once during program shutdown and once for each RSN pre-authentication
    214  * session. If global library deinitialization is needed (i.e., one that is
    215  * shared between both authentication types), the TLS library wrapper should
    216  * maintain a reference counter and do global deinitialization only when moving
    217  * from 1 to 0 references.
    218  */
    219 void tls_deinit(void *tls_ctx);
    220 
    221 /**
    222  * tls_get_errors - Process pending errors
    223  * @tls_ctx: TLS context data from tls_init()
    224  * Returns: Number of found error, 0 if no errors detected.
    225  *
    226  * Process all pending TLS errors.
    227  */
    228 int tls_get_errors(void *tls_ctx);
    229 
    230 /**
    231  * tls_connection_init - Initialize a new TLS connection
    232  * @tls_ctx: TLS context data from tls_init()
    233  * Returns: Connection context data, conn for other function calls
    234  */
    235 struct tls_connection * tls_connection_init(void *tls_ctx);
    236 
    237 /**
    238  * tls_connection_deinit - Free TLS connection data
    239  * @tls_ctx: TLS context data from tls_init()
    240  * @conn: Connection context data from tls_connection_init()
    241  *
    242  * Release all resources allocated for TLS connection.
    243  */
    244 void tls_connection_deinit(void *tls_ctx, struct tls_connection *conn);
    245 
    246 /**
    247  * tls_connection_established - Has the TLS connection been completed?
    248  * @tls_ctx: TLS context data from tls_init()
    249  * @conn: Connection context data from tls_connection_init()
    250  * Returns: 1 if TLS connection has been completed, 0 if not.
    251  */
    252 int tls_connection_established(void *tls_ctx, struct tls_connection *conn);
    253 
    254 /**
    255  * tls_connection_shutdown - Shutdown TLS connection
    256  * @tls_ctx: TLS context data from tls_init()
    257  * @conn: Connection context data from tls_connection_init()
    258  * Returns: 0 on success, -1 on failure
    259  *
    260  * Shutdown current TLS connection without releasing all resources. New
    261  * connection can be started by using the same conn without having to call
    262  * tls_connection_init() or setting certificates etc. again. The new
    263  * connection should try to use session resumption.
    264  */
    265 int tls_connection_shutdown(void *tls_ctx, struct tls_connection *conn);
    266 
    267 enum {
    268 	TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN = -4,
    269 	TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED = -3,
    270 	TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED = -2
    271 };
    272 
    273 /**
    274  * tls_connection_set_params - Set TLS connection parameters
    275  * @tls_ctx: TLS context data from tls_init()
    276  * @conn: Connection context data from tls_connection_init()
    277  * @params: Connection parameters
    278  * Returns: 0 on success, -1 on failure,
    279  * TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED (-2) on error causing PKCS#11 engine
    280  * failure, or
    281  * TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED (-3) on failure to verify the
    282  * PKCS#11 engine private key, or
    283  * TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN (-4) on PIN error causing PKCS#11 engine
    284  * failure.
    285  */
    286 int __must_check
    287 tls_connection_set_params(void *tls_ctx, struct tls_connection *conn,
    288 			  const struct tls_connection_params *params);
    289 
    290 /**
    291  * tls_global_set_params - Set TLS parameters for all TLS connection
    292  * @tls_ctx: TLS context data from tls_init()
    293  * @params: Global TLS parameters
    294  * Returns: 0 on success, -1 on failure,
    295  * TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED (-2) on error causing PKCS#11 engine
    296  * failure, or
    297  * TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED (-3) on failure to verify the
    298  * PKCS#11 engine private key, or
    299  * TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN (-4) on PIN error causing PKCS#11 engine
    300  * failure.
    301  */
    302 int __must_check tls_global_set_params(
    303 	void *tls_ctx, const struct tls_connection_params *params);
    304 
    305 /**
    306  * tls_global_set_verify - Set global certificate verification options
    307  * @tls_ctx: TLS context data from tls_init()
    308  * @check_crl: 0 = do not verify CRLs, 1 = verify CRL for the user certificate,
    309  * 2 = verify CRL for all certificates
    310  * Returns: 0 on success, -1 on failure
    311  */
    312 int __must_check tls_global_set_verify(void *tls_ctx, int check_crl);
    313 
    314 /**
    315  * tls_connection_set_verify - Set certificate verification options
    316  * @tls_ctx: TLS context data from tls_init()
    317  * @conn: Connection context data from tls_connection_init()
    318  * @verify_peer: 1 = verify peer certificate
    319  * @flags: Connection flags (TLS_CONN_*)
    320  * @session_ctx: Session caching context or %NULL to use default
    321  * @session_ctx_len: Length of @session_ctx in bytes.
    322  * Returns: 0 on success, -1 on failure
    323  */
    324 int __must_check tls_connection_set_verify(void *tls_ctx,
    325 					   struct tls_connection *conn,
    326 					   int verify_peer,
    327 					   unsigned int flags,
    328 					   const u8 *session_ctx,
    329 					   size_t session_ctx_len);
    330 
    331 /**
    332  * tls_connection_get_random - Get random data from TLS connection
    333  * @tls_ctx: TLS context data from tls_init()
    334  * @conn: Connection context data from tls_connection_init()
    335  * @data: Structure of client/server random data (filled on success)
    336  * Returns: 0 on success, -1 on failure
    337  */
    338 int __must_check tls_connection_get_random(void *tls_ctx,
    339 					 struct tls_connection *conn,
    340 					 struct tls_random *data);
    341 
    342 /**
    343  * tls_connection_export_key - Derive keying material from a TLS connection
    344  * @tls_ctx: TLS context data from tls_init()
    345  * @conn: Connection context data from tls_connection_init()
    346  * @label: Label (e.g., description of the key) for PRF
    347  * @out: Buffer for output data from TLS-PRF
    348  * @out_len: Length of the output buffer
    349  * Returns: 0 on success, -1 on failure
    350  *
    351  * Exports keying material using the mechanism described in RFC 5705.
    352  */
    353 int __must_check tls_connection_export_key(void *tls_ctx,
    354 					   struct tls_connection *conn,
    355 					   const char *label,
    356 					   u8 *out, size_t out_len);
    357 
    358 /**
    359  * tls_connection_get_eap_fast_key - Derive key material for EAP-FAST
    360  * @tls_ctx: TLS context data from tls_init()
    361  * @conn: Connection context data from tls_connection_init()
    362  * @out: Buffer for output data from TLS-PRF
    363  * @out_len: Length of the output buffer
    364  * Returns: 0 on success, -1 on failure
    365  *
    366  * Exports key material after the normal TLS key block for use with
    367  * EAP-FAST. Most callers will want tls_connection_export_key(), but EAP-FAST
    368  * uses a different legacy mechanism.
    369  */
    370 int __must_check tls_connection_get_eap_fast_key(void *tls_ctx,
    371 						 struct tls_connection *conn,
    372 						 u8 *out, size_t out_len);
    373 
    374 /**
    375  * tls_connection_handshake - Process TLS handshake (client side)
    376  * @tls_ctx: TLS context data from tls_init()
    377  * @conn: Connection context data from tls_connection_init()
    378  * @in_data: Input data from TLS server
    379  * @appl_data: Pointer to application data pointer, or %NULL if dropped
    380  * Returns: Output data, %NULL on failure
    381  *
    382  * The caller is responsible for freeing the returned output data. If the final
    383  * handshake message includes application data, this is decrypted and
    384  * appl_data (if not %NULL) is set to point this data. The caller is
    385  * responsible for freeing appl_data.
    386  *
    387  * This function is used during TLS handshake. The first call is done with
    388  * in_data == %NULL and the library is expected to return ClientHello packet.
    389  * This packet is then send to the server and a response from server is given
    390  * to TLS library by calling this function again with in_data pointing to the
    391  * TLS message from the server.
    392  *
    393  * If the TLS handshake fails, this function may return %NULL. However, if the
    394  * TLS library has a TLS alert to send out, that should be returned as the
    395  * output data. In this case, tls_connection_get_failed() must return failure
    396  * (> 0).
    397  *
    398  * tls_connection_established() should return 1 once the TLS handshake has been
    399  * completed successfully.
    400  */
    401 struct wpabuf * tls_connection_handshake(void *tls_ctx,
    402 					 struct tls_connection *conn,
    403 					 const struct wpabuf *in_data,
    404 					 struct wpabuf **appl_data);
    405 
    406 struct wpabuf * tls_connection_handshake2(void *tls_ctx,
    407 					  struct tls_connection *conn,
    408 					  const struct wpabuf *in_data,
    409 					  struct wpabuf **appl_data,
    410 					  int *more_data_needed);
    411 
    412 /**
    413  * tls_connection_server_handshake - Process TLS handshake (server side)
    414  * @tls_ctx: TLS context data from tls_init()
    415  * @conn: Connection context data from tls_connection_init()
    416  * @in_data: Input data from TLS peer
    417  * @appl_data: Pointer to application data pointer, or %NULL if dropped
    418  * Returns: Output data, %NULL on failure
    419  *
    420  * The caller is responsible for freeing the returned output data.
    421  */
    422 struct wpabuf * tls_connection_server_handshake(void *tls_ctx,
    423 						struct tls_connection *conn,
    424 						const struct wpabuf *in_data,
    425 						struct wpabuf **appl_data);
    426 
    427 /**
    428  * tls_connection_encrypt - Encrypt data into TLS tunnel
    429  * @tls_ctx: TLS context data from tls_init()
    430  * @conn: Connection context data from tls_connection_init()
    431  * @in_data: Plaintext data to be encrypted
    432  * Returns: Encrypted TLS data or %NULL on failure
    433  *
    434  * This function is used after TLS handshake has been completed successfully to
    435  * send data in the encrypted tunnel. The caller is responsible for freeing the
    436  * returned output data.
    437  */
    438 struct wpabuf * tls_connection_encrypt(void *tls_ctx,
    439 				       struct tls_connection *conn,
    440 				       const struct wpabuf *in_data);
    441 
    442 /**
    443  * tls_connection_decrypt - Decrypt data from TLS tunnel
    444  * @tls_ctx: TLS context data from tls_init()
    445  * @conn: Connection context data from tls_connection_init()
    446  * @in_data: Encrypted TLS data
    447  * Returns: Decrypted TLS data or %NULL on failure
    448  *
    449  * This function is used after TLS handshake has been completed successfully to
    450  * receive data from the encrypted tunnel. The caller is responsible for
    451  * freeing the returned output data.
    452  */
    453 struct wpabuf * tls_connection_decrypt(void *tls_ctx,
    454 				       struct tls_connection *conn,
    455 				       const struct wpabuf *in_data);
    456 
    457 struct wpabuf * tls_connection_decrypt2(void *tls_ctx,
    458 					struct tls_connection *conn,
    459 					const struct wpabuf *in_data,
    460 					int *more_data_needed);
    461 
    462 /**
    463  * tls_connection_resumed - Was session resumption used
    464  * @tls_ctx: TLS context data from tls_init()
    465  * @conn: Connection context data from tls_connection_init()
    466  * Returns: 1 if current session used session resumption, 0 if not
    467  */
    468 int tls_connection_resumed(void *tls_ctx, struct tls_connection *conn);
    469 
    470 enum {
    471 	TLS_CIPHER_NONE,
    472 	TLS_CIPHER_RC4_SHA /* 0x0005 */,
    473 	TLS_CIPHER_AES128_SHA /* 0x002f */,
    474 	TLS_CIPHER_RSA_DHE_AES128_SHA /* 0x0031 */,
    475 	TLS_CIPHER_ANON_DH_AES128_SHA /* 0x0034 */,
    476 	TLS_CIPHER_RSA_DHE_AES256_SHA /* 0x0039 */,
    477 	TLS_CIPHER_AES256_SHA /* 0x0035 */,
    478 };
    479 
    480 /**
    481  * tls_connection_set_cipher_list - Configure acceptable cipher suites
    482  * @tls_ctx: TLS context data from tls_init()
    483  * @conn: Connection context data from tls_connection_init()
    484  * @ciphers: Zero (TLS_CIPHER_NONE) terminated list of allowed ciphers
    485  * (TLS_CIPHER_*).
    486  * Returns: 0 on success, -1 on failure
    487  */
    488 int __must_check tls_connection_set_cipher_list(void *tls_ctx,
    489 						struct tls_connection *conn,
    490 						u8 *ciphers);
    491 
    492 /**
    493  * tls_get_version - Get the current TLS version number
    494  * @tls_ctx: TLS context data from tls_init()
    495  * @conn: Connection context data from tls_connection_init()
    496  * @buf: Buffer for returning the TLS version number
    497  * @buflen: buf size
    498  * Returns: 0 on success, -1 on failure
    499  *
    500  * Get the currently used TLS version number.
    501  */
    502 int __must_check tls_get_version(void *tls_ctx, struct tls_connection *conn,
    503 				 char *buf, size_t buflen);
    504 
    505 /**
    506  * tls_get_cipher - Get current cipher name
    507  * @tls_ctx: TLS context data from tls_init()
    508  * @conn: Connection context data from tls_connection_init()
    509  * @buf: Buffer for the cipher name
    510  * @buflen: buf size
    511  * Returns: 0 on success, -1 on failure
    512  *
    513  * Get the name of the currently used cipher.
    514  */
    515 int __must_check tls_get_cipher(void *tls_ctx, struct tls_connection *conn,
    516 				char *buf, size_t buflen);
    517 
    518 /**
    519  * tls_connection_enable_workaround - Enable TLS workaround options
    520  * @tls_ctx: TLS context data from tls_init()
    521  * @conn: Connection context data from tls_connection_init()
    522  * Returns: 0 on success, -1 on failure
    523  *
    524  * This function is used to enable connection-specific workaround options for
    525  * buffer SSL/TLS implementations.
    526  */
    527 int __must_check tls_connection_enable_workaround(void *tls_ctx,
    528 						  struct tls_connection *conn);
    529 
    530 /**
    531  * tls_connection_client_hello_ext - Set TLS extension for ClientHello
    532  * @tls_ctx: TLS context data from tls_init()
    533  * @conn: Connection context data from tls_connection_init()
    534  * @ext_type: Extension type
    535  * @data: Extension payload (%NULL to remove extension)
    536  * @data_len: Extension payload length
    537  * Returns: 0 on success, -1 on failure
    538  */
    539 int __must_check tls_connection_client_hello_ext(void *tls_ctx,
    540 						 struct tls_connection *conn,
    541 						 int ext_type, const u8 *data,
    542 						 size_t data_len);
    543 
    544 /**
    545  * tls_connection_get_failed - Get connection failure status
    546  * @tls_ctx: TLS context data from tls_init()
    547  * @conn: Connection context data from tls_connection_init()
    548  *
    549  * Returns >0 if connection has failed, 0 if not.
    550  */
    551 int tls_connection_get_failed(void *tls_ctx, struct tls_connection *conn);
    552 
    553 /**
    554  * tls_connection_get_read_alerts - Get connection read alert status
    555  * @tls_ctx: TLS context data from tls_init()
    556  * @conn: Connection context data from tls_connection_init()
    557  * Returns: Number of times a fatal read (remote end reported error) has
    558  * happened during this connection.
    559  */
    560 int tls_connection_get_read_alerts(void *tls_ctx, struct tls_connection *conn);
    561 
    562 /**
    563  * tls_connection_get_write_alerts - Get connection write alert status
    564  * @tls_ctx: TLS context data from tls_init()
    565  * @conn: Connection context data from tls_connection_init()
    566  * Returns: Number of times a fatal write (locally detected error) has happened
    567  * during this connection.
    568  */
    569 int tls_connection_get_write_alerts(void *tls_ctx,
    570 				    struct tls_connection *conn);
    571 
    572 typedef int (*tls_session_ticket_cb)
    573 (void *ctx, const u8 *ticket, size_t len, const u8 *client_random,
    574  const u8 *server_random, u8 *master_secret);
    575 
    576 int __must_check  tls_connection_set_session_ticket_cb(
    577 	void *tls_ctx, struct tls_connection *conn,
    578 	tls_session_ticket_cb cb, void *ctx);
    579 
    580 void tls_connection_set_log_cb(struct tls_connection *conn,
    581 			       void (*log_cb)(void *ctx, const char *msg),
    582 			       void *ctx);
    583 
    584 #define TLS_BREAK_VERIFY_DATA BIT(0)
    585 #define TLS_BREAK_SRV_KEY_X_HASH BIT(1)
    586 #define TLS_BREAK_SRV_KEY_X_SIGNATURE BIT(2)
    587 #define TLS_DHE_PRIME_511B BIT(3)
    588 #define TLS_DHE_PRIME_767B BIT(4)
    589 #define TLS_DHE_PRIME_15 BIT(5)
    590 #define TLS_DHE_PRIME_58B BIT(6)
    591 #define TLS_DHE_NON_PRIME BIT(7)
    592 
    593 void tls_connection_set_test_flags(struct tls_connection *conn, u32 flags);
    594 
    595 int tls_get_library_version(char *buf, size_t buf_len);
    596 
    597 void tls_connection_set_success_data(struct tls_connection *conn,
    598 				     struct wpabuf *data);
    599 
    600 void tls_connection_set_success_data_resumed(struct tls_connection *conn);
    601 
    602 const struct wpabuf *
    603 tls_connection_get_success_data(struct tls_connection *conn);
    604 
    605 void tls_connection_remove_session(struct tls_connection *conn);
    606 
    607 #endif /* TLS_H */
    608