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