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