1189251Ssam/*
2214734Srpaulo * SSL/TLS interface definition
3214734Srpaulo * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
4189251Ssam *
5252726Srpaulo * This software may be distributed under the terms of the BSD license.
6252726Srpaulo * See README for more details.
7189251Ssam */
8189251Ssam
9189251Ssam#ifndef TLS_H
10189251Ssam#define TLS_H
11189251Ssam
12189251Ssamstruct tls_connection;
13189251Ssam
14189251Ssamstruct tls_keys {
15189251Ssam	const u8 *master_key; /* TLS master secret */
16189251Ssam	size_t master_key_len;
17189251Ssam	const u8 *client_random;
18189251Ssam	size_t client_random_len;
19189251Ssam	const u8 *server_random;
20189251Ssam	size_t server_random_len;
21189251Ssam};
22189251Ssam
23214734Srpauloenum tls_event {
24252726Srpaulo	TLS_CERT_CHAIN_SUCCESS,
25214734Srpaulo	TLS_CERT_CHAIN_FAILURE,
26252726Srpaulo	TLS_PEER_CERTIFICATE,
27252726Srpaulo	TLS_ALERT
28214734Srpaulo};
29214734Srpaulo
30214734Srpaulo/*
31214734Srpaulo * Note: These are used as identifier with external programs and as such, the
32214734Srpaulo * values must not be changed.
33214734Srpaulo */
34214734Srpauloenum tls_fail_reason {
35214734Srpaulo	TLS_FAIL_UNSPECIFIED = 0,
36214734Srpaulo	TLS_FAIL_UNTRUSTED = 1,
37214734Srpaulo	TLS_FAIL_REVOKED = 2,
38214734Srpaulo	TLS_FAIL_NOT_YET_VALID = 3,
39214734Srpaulo	TLS_FAIL_EXPIRED = 4,
40214734Srpaulo	TLS_FAIL_SUBJECT_MISMATCH = 5,
41214734Srpaulo	TLS_FAIL_ALTSUBJECT_MISMATCH = 6,
42214734Srpaulo	TLS_FAIL_BAD_CERTIFICATE = 7,
43214734Srpaulo	TLS_FAIL_SERVER_CHAIN_PROBE = 8
44214734Srpaulo};
45214734Srpaulo
46214734Srpaulounion tls_event_data {
47214734Srpaulo	struct {
48214734Srpaulo		int depth;
49214734Srpaulo		const char *subject;
50214734Srpaulo		enum tls_fail_reason reason;
51214734Srpaulo		const char *reason_txt;
52214734Srpaulo		const struct wpabuf *cert;
53214734Srpaulo	} cert_fail;
54214734Srpaulo
55214734Srpaulo	struct {
56214734Srpaulo		int depth;
57214734Srpaulo		const char *subject;
58214734Srpaulo		const struct wpabuf *cert;
59214734Srpaulo		const u8 *hash;
60214734Srpaulo		size_t hash_len;
61214734Srpaulo	} peer_cert;
62252726Srpaulo
63252726Srpaulo	struct {
64252726Srpaulo		int is_local;
65252726Srpaulo		const char *type;
66252726Srpaulo		const char *description;
67252726Srpaulo	} alert;
68214734Srpaulo};
69214734Srpaulo
70189251Ssamstruct tls_config {
71189251Ssam	const char *opensc_engine_path;
72189251Ssam	const char *pkcs11_engine_path;
73189251Ssam	const char *pkcs11_module_path;
74214734Srpaulo	int fips_mode;
75252726Srpaulo	int cert_in_cb;
76214734Srpaulo
77214734Srpaulo	void (*event_cb)(void *ctx, enum tls_event ev,
78214734Srpaulo			 union tls_event_data *data);
79214734Srpaulo	void *cb_ctx;
80189251Ssam};
81189251Ssam
82209158Srpaulo#define TLS_CONN_ALLOW_SIGN_RSA_MD5 BIT(0)
83209158Srpaulo#define TLS_CONN_DISABLE_TIME_CHECKS BIT(1)
84252726Srpaulo#define TLS_CONN_DISABLE_SESSION_TICKET BIT(2)
85209158Srpaulo
86189251Ssam/**
87189251Ssam * struct tls_connection_params - Parameters for TLS connection
88189251Ssam * @ca_cert: File or reference name for CA X.509 certificate in PEM or DER
89189251Ssam * format
90189251Ssam * @ca_cert_blob: ca_cert as inlined data or %NULL if not used
91189251Ssam * @ca_cert_blob_len: ca_cert_blob length
92189251Ssam * @ca_path: Path to CA certificates (OpenSSL specific)
93189251Ssam * @subject_match: String to match in the subject of the peer certificate or
94189251Ssam * %NULL to allow all subjects
95189251Ssam * @altsubject_match: String to match in the alternative subject of the peer
96189251Ssam * certificate or %NULL to allow all alternative subjects
97189251Ssam * @client_cert: File or reference name for client X.509 certificate in PEM or
98189251Ssam * DER format
99189251Ssam * @client_cert_blob: client_cert as inlined data or %NULL if not used
100189251Ssam * @client_cert_blob_len: client_cert_blob length
101189251Ssam * @private_key: File or reference name for client private key in PEM or DER
102189251Ssam * format (traditional format (RSA PRIVATE KEY) or PKCS#8 (PRIVATE KEY)
103189251Ssam * @private_key_blob: private_key as inlined data or %NULL if not used
104189251Ssam * @private_key_blob_len: private_key_blob length
105189251Ssam * @private_key_passwd: Passphrase for decrypted private key, %NULL if no
106189251Ssam * passphrase is used.
107189251Ssam * @dh_file: File name for DH/DSA data in PEM format, or %NULL if not used
108189251Ssam * @dh_blob: dh_file as inlined data or %NULL if not used
109189251Ssam * @dh_blob_len: dh_blob length
110189251Ssam * @engine: 1 = use engine (e.g., a smartcard) for private key operations
111189251Ssam * (this is OpenSSL specific for now)
112189251Ssam * @engine_id: engine id string (this is OpenSSL specific for now)
113189251Ssam * @ppin: pointer to the pin variable in the configuration
114189251Ssam * (this is OpenSSL specific for now)
115189251Ssam * @key_id: the private key's id when using engine (this is OpenSSL
116189251Ssam * specific for now)
117189251Ssam * @cert_id: the certificate's id when using engine
118189251Ssam * @ca_cert_id: the CA certificate's id when using engine
119209158Srpaulo * @flags: Parameter options (TLS_CONN_*)
120189251Ssam *
121189251Ssam * TLS connection parameters to be configured with tls_connection_set_params()
122189251Ssam * and tls_global_set_params().
123189251Ssam *
124189251Ssam * Certificates and private key can be configured either as a reference name
125189251Ssam * (file path or reference to certificate store) or by providing the same data
126189251Ssam * as a pointer to the data in memory. Only one option will be used for each
127189251Ssam * field.
128189251Ssam */
129189251Ssamstruct tls_connection_params {
130189251Ssam	const char *ca_cert;
131189251Ssam	const u8 *ca_cert_blob;
132189251Ssam	size_t ca_cert_blob_len;
133189251Ssam	const char *ca_path;
134189251Ssam	const char *subject_match;
135189251Ssam	const char *altsubject_match;
136189251Ssam	const char *client_cert;
137189251Ssam	const u8 *client_cert_blob;
138189251Ssam	size_t client_cert_blob_len;
139189251Ssam	const char *private_key;
140189251Ssam	const u8 *private_key_blob;
141189251Ssam	size_t private_key_blob_len;
142189251Ssam	const char *private_key_passwd;
143189251Ssam	const char *dh_file;
144189251Ssam	const u8 *dh_blob;
145189251Ssam	size_t dh_blob_len;
146189251Ssam
147189251Ssam	/* OpenSSL specific variables */
148189251Ssam	int engine;
149189251Ssam	const char *engine_id;
150189251Ssam	const char *pin;
151189251Ssam	const char *key_id;
152189251Ssam	const char *cert_id;
153189251Ssam	const char *ca_cert_id;
154209158Srpaulo
155209158Srpaulo	unsigned int flags;
156189251Ssam};
157189251Ssam
158189251Ssam
159189251Ssam/**
160189251Ssam * tls_init - Initialize TLS library
161189251Ssam * @conf: Configuration data for TLS library
162189251Ssam * Returns: Context data to be used as tls_ctx in calls to other functions,
163189251Ssam * or %NULL on failure.
164189251Ssam *
165189251Ssam * Called once during program startup and once for each RSN pre-authentication
166189251Ssam * session. In other words, there can be two concurrent TLS contexts. If global
167189251Ssam * library initialization is needed (i.e., one that is shared between both
168189251Ssam * authentication types), the TLS library wrapper should maintain a reference
169189251Ssam * counter and do global initialization only when moving from 0 to 1 reference.
170189251Ssam */
171189251Ssamvoid * tls_init(const struct tls_config *conf);
172189251Ssam
173189251Ssam/**
174189251Ssam * tls_deinit - Deinitialize TLS library
175189251Ssam * @tls_ctx: TLS context data from tls_init()
176189251Ssam *
177189251Ssam * Called once during program shutdown and once for each RSN pre-authentication
178189251Ssam * session. If global library deinitialization is needed (i.e., one that is
179189251Ssam * shared between both authentication types), the TLS library wrapper should
180189251Ssam * maintain a reference counter and do global deinitialization only when moving
181189251Ssam * from 1 to 0 references.
182189251Ssam */
183189251Ssamvoid tls_deinit(void *tls_ctx);
184189251Ssam
185189251Ssam/**
186189251Ssam * tls_get_errors - Process pending errors
187189251Ssam * @tls_ctx: TLS context data from tls_init()
188189251Ssam * Returns: Number of found error, 0 if no errors detected.
189189251Ssam *
190189251Ssam * Process all pending TLS errors.
191189251Ssam */
192189251Ssamint tls_get_errors(void *tls_ctx);
193189251Ssam
194189251Ssam/**
195189251Ssam * tls_connection_init - Initialize a new TLS connection
196189251Ssam * @tls_ctx: TLS context data from tls_init()
197189251Ssam * Returns: Connection context data, conn for other function calls
198189251Ssam */
199189251Ssamstruct tls_connection * tls_connection_init(void *tls_ctx);
200189251Ssam
201189251Ssam/**
202189251Ssam * tls_connection_deinit - Free TLS connection data
203189251Ssam * @tls_ctx: TLS context data from tls_init()
204189251Ssam * @conn: Connection context data from tls_connection_init()
205189251Ssam *
206189251Ssam * Release all resources allocated for TLS connection.
207189251Ssam */
208189251Ssamvoid tls_connection_deinit(void *tls_ctx, struct tls_connection *conn);
209189251Ssam
210189251Ssam/**
211189251Ssam * tls_connection_established - Has the TLS connection been completed?
212189251Ssam * @tls_ctx: TLS context data from tls_init()
213189251Ssam * @conn: Connection context data from tls_connection_init()
214189251Ssam * Returns: 1 if TLS connection has been completed, 0 if not.
215189251Ssam */
216189251Ssamint tls_connection_established(void *tls_ctx, struct tls_connection *conn);
217189251Ssam
218189251Ssam/**
219189251Ssam * tls_connection_shutdown - Shutdown TLS connection
220189251Ssam * @tls_ctx: TLS context data from tls_init()
221189251Ssam * @conn: Connection context data from tls_connection_init()
222189251Ssam * Returns: 0 on success, -1 on failure
223189251Ssam *
224189251Ssam * Shutdown current TLS connection without releasing all resources. New
225189251Ssam * connection can be started by using the same conn without having to call
226189251Ssam * tls_connection_init() or setting certificates etc. again. The new
227189251Ssam * connection should try to use session resumption.
228189251Ssam */
229189251Ssamint tls_connection_shutdown(void *tls_ctx, struct tls_connection *conn);
230189251Ssam
231189251Ssamenum {
232189251Ssam	TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED = -3,
233189251Ssam	TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED = -2
234189251Ssam};
235189251Ssam
236189251Ssam/**
237189251Ssam * tls_connection_set_params - Set TLS connection parameters
238189251Ssam * @tls_ctx: TLS context data from tls_init()
239189251Ssam * @conn: Connection context data from tls_connection_init()
240189251Ssam * @params: Connection parameters
241189251Ssam * Returns: 0 on success, -1 on failure,
242189251Ssam * TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED (-2) on possible PIN error causing
243189251Ssam * PKCS#11 engine failure, or
244189251Ssam * TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED (-3) on failure to verify the
245189251Ssam * PKCS#11 engine private key.
246189251Ssam */
247189251Ssamint __must_check
248189251Ssamtls_connection_set_params(void *tls_ctx, struct tls_connection *conn,
249189251Ssam			  const struct tls_connection_params *params);
250189251Ssam
251189251Ssam/**
252189251Ssam * tls_global_set_params - Set TLS parameters for all TLS connection
253189251Ssam * @tls_ctx: TLS context data from tls_init()
254189251Ssam * @params: Global TLS parameters
255189251Ssam * Returns: 0 on success, -1 on failure,
256189251Ssam * TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED (-2) on possible PIN error causing
257189251Ssam * PKCS#11 engine failure, or
258189251Ssam * TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED (-3) on failure to verify the
259189251Ssam * PKCS#11 engine private key.
260189251Ssam */
261189251Ssamint __must_check tls_global_set_params(
262189251Ssam	void *tls_ctx, const struct tls_connection_params *params);
263189251Ssam
264189251Ssam/**
265189251Ssam * tls_global_set_verify - Set global certificate verification options
266189251Ssam * @tls_ctx: TLS context data from tls_init()
267189251Ssam * @check_crl: 0 = do not verify CRLs, 1 = verify CRL for the user certificate,
268189251Ssam * 2 = verify CRL for all certificates
269189251Ssam * Returns: 0 on success, -1 on failure
270189251Ssam */
271189251Ssamint __must_check tls_global_set_verify(void *tls_ctx, int check_crl);
272189251Ssam
273189251Ssam/**
274189251Ssam * tls_connection_set_verify - Set certificate verification options
275189251Ssam * @tls_ctx: TLS context data from tls_init()
276189251Ssam * @conn: Connection context data from tls_connection_init()
277189251Ssam * @verify_peer: 1 = verify peer certificate
278189251Ssam * Returns: 0 on success, -1 on failure
279189251Ssam */
280189251Ssamint __must_check tls_connection_set_verify(void *tls_ctx,
281189251Ssam					   struct tls_connection *conn,
282189251Ssam					   int verify_peer);
283189251Ssam
284189251Ssam/**
285189251Ssam * tls_connection_get_keys - Get master key and random data from TLS connection
286189251Ssam * @tls_ctx: TLS context data from tls_init()
287189251Ssam * @conn: Connection context data from tls_connection_init()
288189251Ssam * @keys: Structure of key/random data (filled on success)
289189251Ssam * Returns: 0 on success, -1 on failure
290189251Ssam */
291189251Ssamint __must_check tls_connection_get_keys(void *tls_ctx,
292189251Ssam					 struct tls_connection *conn,
293189251Ssam					 struct tls_keys *keys);
294189251Ssam
295189251Ssam/**
296189251Ssam * tls_connection_prf - Use TLS-PRF to derive keying material
297189251Ssam * @tls_ctx: TLS context data from tls_init()
298189251Ssam * @conn: Connection context data from tls_connection_init()
299189251Ssam * @label: Label (e.g., description of the key) for PRF
300189251Ssam * @server_random_first: seed is 0 = client_random|server_random,
301189251Ssam * 1 = server_random|client_random
302189251Ssam * @out: Buffer for output data from TLS-PRF
303189251Ssam * @out_len: Length of the output buffer
304189251Ssam * Returns: 0 on success, -1 on failure
305189251Ssam *
306189251Ssam * This function is optional to implement if tls_connection_get_keys() provides
307189251Ssam * access to master secret and server/client random values. If these values are
308189251Ssam * not exported from the TLS library, tls_connection_prf() is required so that
309189251Ssam * further keying material can be derived from the master secret. If not
310189251Ssam * implemented, the function will still need to be defined, but it can just
311252726Srpaulo * return -1. Example implementation of this function is in tls_prf_sha1_md5()
312189251Ssam * when it is called with seed set to client_random|server_random (or
313189251Ssam * server_random|client_random).
314189251Ssam */
315189251Ssamint __must_check  tls_connection_prf(void *tls_ctx,
316189251Ssam				     struct tls_connection *conn,
317189251Ssam				     const char *label,
318189251Ssam				     int server_random_first,
319189251Ssam				     u8 *out, size_t out_len);
320189251Ssam
321189251Ssam/**
322189251Ssam * tls_connection_handshake - Process TLS handshake (client side)
323189251Ssam * @tls_ctx: TLS context data from tls_init()
324189251Ssam * @conn: Connection context data from tls_connection_init()
325214734Srpaulo * @in_data: Input data from TLS server
326189251Ssam * @appl_data: Pointer to application data pointer, or %NULL if dropped
327214734Srpaulo * Returns: Output data, %NULL on failure
328189251Ssam *
329214734Srpaulo * The caller is responsible for freeing the returned output data. If the final
330189251Ssam * handshake message includes application data, this is decrypted and
331214734Srpaulo * appl_data (if not %NULL) is set to point this data. The caller is
332214734Srpaulo * responsible for freeing appl_data.
333189251Ssam *
334189251Ssam * This function is used during TLS handshake. The first call is done with
335189251Ssam * in_data == %NULL and the library is expected to return ClientHello packet.
336189251Ssam * This packet is then send to the server and a response from server is given
337189251Ssam * to TLS library by calling this function again with in_data pointing to the
338189251Ssam * TLS message from the server.
339189251Ssam *
340189251Ssam * If the TLS handshake fails, this function may return %NULL. However, if the
341189251Ssam * TLS library has a TLS alert to send out, that should be returned as the
342189251Ssam * output data. In this case, tls_connection_get_failed() must return failure
343189251Ssam * (> 0).
344189251Ssam *
345189251Ssam * tls_connection_established() should return 1 once the TLS handshake has been
346189251Ssam * completed successfully.
347189251Ssam */
348214734Srpaulostruct wpabuf * tls_connection_handshake(void *tls_ctx,
349214734Srpaulo					 struct tls_connection *conn,
350214734Srpaulo					 const struct wpabuf *in_data,
351214734Srpaulo					 struct wpabuf **appl_data);
352189251Ssam
353252726Srpaulostruct wpabuf * tls_connection_handshake2(void *tls_ctx,
354252726Srpaulo					  struct tls_connection *conn,
355252726Srpaulo					  const struct wpabuf *in_data,
356252726Srpaulo					  struct wpabuf **appl_data,
357252726Srpaulo					  int *more_data_needed);
358252726Srpaulo
359189251Ssam/**
360189251Ssam * tls_connection_server_handshake - Process TLS handshake (server side)
361189251Ssam * @tls_ctx: TLS context data from tls_init()
362189251Ssam * @conn: Connection context data from tls_connection_init()
363189251Ssam * @in_data: Input data from TLS peer
364214734Srpaulo * @appl_data: Pointer to application data pointer, or %NULL if dropped
365214734Srpaulo * Returns: Output data, %NULL on failure
366189251Ssam *
367214734Srpaulo * The caller is responsible for freeing the returned output data.
368189251Ssam */
369214734Srpaulostruct wpabuf * tls_connection_server_handshake(void *tls_ctx,
370214734Srpaulo						struct tls_connection *conn,
371214734Srpaulo						const struct wpabuf *in_data,
372214734Srpaulo						struct wpabuf **appl_data);
373189251Ssam
374189251Ssam/**
375189251Ssam * tls_connection_encrypt - Encrypt data into TLS tunnel
376189251Ssam * @tls_ctx: TLS context data from tls_init()
377189251Ssam * @conn: Connection context data from tls_connection_init()
378214734Srpaulo * @in_data: Plaintext data to be encrypted
379214734Srpaulo * Returns: Encrypted TLS data or %NULL on failure
380189251Ssam *
381189251Ssam * This function is used after TLS handshake has been completed successfully to
382214734Srpaulo * send data in the encrypted tunnel. The caller is responsible for freeing the
383214734Srpaulo * returned output data.
384189251Ssam */
385214734Srpaulostruct wpabuf * tls_connection_encrypt(void *tls_ctx,
386214734Srpaulo				       struct tls_connection *conn,
387214734Srpaulo				       const struct wpabuf *in_data);
388189251Ssam
389189251Ssam/**
390189251Ssam * tls_connection_decrypt - Decrypt data from TLS tunnel
391189251Ssam * @tls_ctx: TLS context data from tls_init()
392189251Ssam * @conn: Connection context data from tls_connection_init()
393214734Srpaulo * @in_data: Encrypted TLS data
394214734Srpaulo * Returns: Decrypted TLS data or %NULL on failure
395189251Ssam *
396189251Ssam * This function is used after TLS handshake has been completed successfully to
397214734Srpaulo * receive data from the encrypted tunnel. The caller is responsible for
398214734Srpaulo * freeing the returned output data.
399189251Ssam */
400214734Srpaulostruct wpabuf * tls_connection_decrypt(void *tls_ctx,
401214734Srpaulo				       struct tls_connection *conn,
402214734Srpaulo				       const struct wpabuf *in_data);
403189251Ssam
404252726Srpaulostruct wpabuf * tls_connection_decrypt2(void *tls_ctx,
405252726Srpaulo					struct tls_connection *conn,
406252726Srpaulo					const struct wpabuf *in_data,
407252726Srpaulo					int *more_data_needed);
408252726Srpaulo
409189251Ssam/**
410189251Ssam * tls_connection_resumed - Was session resumption used
411189251Ssam * @tls_ctx: TLS context data from tls_init()
412189251Ssam * @conn: Connection context data from tls_connection_init()
413189251Ssam * Returns: 1 if current session used session resumption, 0 if not
414189251Ssam */
415189251Ssamint tls_connection_resumed(void *tls_ctx, struct tls_connection *conn);
416189251Ssam
417189251Ssamenum {
418189251Ssam	TLS_CIPHER_NONE,
419189251Ssam	TLS_CIPHER_RC4_SHA /* 0x0005 */,
420189251Ssam	TLS_CIPHER_AES128_SHA /* 0x002f */,
421189251Ssam	TLS_CIPHER_RSA_DHE_AES128_SHA /* 0x0031 */,
422189251Ssam	TLS_CIPHER_ANON_DH_AES128_SHA /* 0x0034 */
423189251Ssam};
424189251Ssam
425189251Ssam/**
426189251Ssam * tls_connection_set_cipher_list - Configure acceptable cipher suites
427189251Ssam * @tls_ctx: TLS context data from tls_init()
428189251Ssam * @conn: Connection context data from tls_connection_init()
429189251Ssam * @ciphers: Zero (TLS_CIPHER_NONE) terminated list of allowed ciphers
430189251Ssam * (TLS_CIPHER_*).
431189251Ssam * Returns: 0 on success, -1 on failure
432189251Ssam */
433189251Ssamint __must_check tls_connection_set_cipher_list(void *tls_ctx,
434189251Ssam						struct tls_connection *conn,
435189251Ssam						u8 *ciphers);
436189251Ssam
437189251Ssam/**
438189251Ssam * tls_get_cipher - Get current cipher name
439189251Ssam * @tls_ctx: TLS context data from tls_init()
440189251Ssam * @conn: Connection context data from tls_connection_init()
441189251Ssam * @buf: Buffer for the cipher name
442189251Ssam * @buflen: buf size
443189251Ssam * Returns: 0 on success, -1 on failure
444189251Ssam *
445189251Ssam * Get the name of the currently used cipher.
446189251Ssam */
447189251Ssamint __must_check tls_get_cipher(void *tls_ctx, struct tls_connection *conn,
448189251Ssam				char *buf, size_t buflen);
449189251Ssam
450189251Ssam/**
451189251Ssam * tls_connection_enable_workaround - Enable TLS workaround options
452189251Ssam * @tls_ctx: TLS context data from tls_init()
453189251Ssam * @conn: Connection context data from tls_connection_init()
454189251Ssam * Returns: 0 on success, -1 on failure
455189251Ssam *
456189251Ssam * This function is used to enable connection-specific workaround options for
457189251Ssam * buffer SSL/TLS implementations.
458189251Ssam */
459189251Ssamint __must_check tls_connection_enable_workaround(void *tls_ctx,
460189251Ssam						  struct tls_connection *conn);
461189251Ssam
462189251Ssam/**
463189251Ssam * tls_connection_client_hello_ext - Set TLS extension for ClientHello
464189251Ssam * @tls_ctx: TLS context data from tls_init()
465189251Ssam * @conn: Connection context data from tls_connection_init()
466189251Ssam * @ext_type: Extension type
467189251Ssam * @data: Extension payload (%NULL to remove extension)
468189251Ssam * @data_len: Extension payload length
469189251Ssam * Returns: 0 on success, -1 on failure
470189251Ssam */
471189251Ssamint __must_check tls_connection_client_hello_ext(void *tls_ctx,
472189251Ssam						 struct tls_connection *conn,
473189251Ssam						 int ext_type, const u8 *data,
474189251Ssam						 size_t data_len);
475189251Ssam
476189251Ssam/**
477189251Ssam * tls_connection_get_failed - Get connection failure status
478189251Ssam * @tls_ctx: TLS context data from tls_init()
479189251Ssam * @conn: Connection context data from tls_connection_init()
480189251Ssam *
481189251Ssam * Returns >0 if connection has failed, 0 if not.
482189251Ssam */
483189251Ssamint tls_connection_get_failed(void *tls_ctx, struct tls_connection *conn);
484189251Ssam
485189251Ssam/**
486189251Ssam * tls_connection_get_read_alerts - Get connection read alert status
487189251Ssam * @tls_ctx: TLS context data from tls_init()
488189251Ssam * @conn: Connection context data from tls_connection_init()
489189251Ssam * Returns: Number of times a fatal read (remote end reported error) has
490189251Ssam * happened during this connection.
491189251Ssam */
492189251Ssamint tls_connection_get_read_alerts(void *tls_ctx, struct tls_connection *conn);
493189251Ssam
494189251Ssam/**
495189251Ssam * tls_connection_get_write_alerts - Get connection write alert status
496189251Ssam * @tls_ctx: TLS context data from tls_init()
497189251Ssam * @conn: Connection context data from tls_connection_init()
498189251Ssam * Returns: Number of times a fatal write (locally detected error) has happened
499189251Ssam * during this connection.
500189251Ssam */
501189251Ssamint tls_connection_get_write_alerts(void *tls_ctx,
502189251Ssam				    struct tls_connection *conn);
503189251Ssam
504189251Ssam/**
505189251Ssam * tls_connection_get_keyblock_size - Get TLS key_block size
506189251Ssam * @tls_ctx: TLS context data from tls_init()
507189251Ssam * @conn: Connection context data from tls_connection_init()
508189251Ssam * Returns: Size of the key_block for the negotiated cipher suite or -1 on
509189251Ssam * failure
510189251Ssam */
511189251Ssamint tls_connection_get_keyblock_size(void *tls_ctx,
512189251Ssam				     struct tls_connection *conn);
513189251Ssam
514189251Ssam/**
515189251Ssam * tls_capabilities - Get supported TLS capabilities
516189251Ssam * @tls_ctx: TLS context data from tls_init()
517189251Ssam * Returns: Bit field of supported TLS capabilities (TLS_CAPABILITY_*)
518189251Ssam */
519189251Ssamunsigned int tls_capabilities(void *tls_ctx);
520189251Ssam
521189251Ssamtypedef int (*tls_session_ticket_cb)
522189251Ssam(void *ctx, const u8 *ticket, size_t len, const u8 *client_random,
523189251Ssam const u8 *server_random, u8 *master_secret);
524189251Ssam
525189251Ssamint __must_check  tls_connection_set_session_ticket_cb(
526189251Ssam	void *tls_ctx, struct tls_connection *conn,
527189251Ssam	tls_session_ticket_cb cb, void *ctx);
528189251Ssam
529189251Ssam#endif /* TLS_H */
530