blob: bca94d67dd87910644d8fd4eb5824126e5a35cca [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * SSL/TLS interface definition
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003 * Copyright (c) 2004-2013, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#ifndef TLS_H
10#define TLS_H
11
12struct tls_connection;
13
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080014struct tls_random {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070015 const u8 *client_random;
16 size_t client_random_len;
17 const u8 *server_random;
18 size_t server_random_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070019};
20
21enum tls_event {
Dmitry Shmidt04949592012-07-19 12:16:46 -070022 TLS_CERT_CHAIN_SUCCESS,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070023 TLS_CERT_CHAIN_FAILURE,
Dmitry Shmidt04949592012-07-19 12:16:46 -070024 TLS_PEER_CERTIFICATE,
25 TLS_ALERT
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070026};
27
28/*
29 * Note: These are used as identifier with external programs and as such, the
30 * values must not be changed.
31 */
32enum 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,
Dmitry Shmidt051af732013-10-22 13:52:46 -070041 TLS_FAIL_SERVER_CHAIN_PROBE = 8,
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080042 TLS_FAIL_DOMAIN_SUFFIX_MISMATCH = 9,
43 TLS_FAIL_DOMAIN_MISMATCH = 10,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070044};
45
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080046
47#define TLS_MAX_ALT_SUBJECT 10
48
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070049union tls_event_data {
50 struct {
51 int depth;
52 const char *subject;
53 enum tls_fail_reason reason;
54 const char *reason_txt;
55 const struct wpabuf *cert;
56 } cert_fail;
57
58 struct {
59 int depth;
60 const char *subject;
61 const struct wpabuf *cert;
62 const u8 *hash;
63 size_t hash_len;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080064 const char *altsubject[TLS_MAX_ALT_SUBJECT];
65 int num_altsubject;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070066 } peer_cert;
Dmitry Shmidt04949592012-07-19 12:16:46 -070067
68 struct {
69 int is_local;
70 const char *type;
71 const char *description;
72 } alert;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070073};
74
75struct tls_config {
76 const char *opensc_engine_path;
77 const char *pkcs11_engine_path;
78 const char *pkcs11_module_path;
79 int fips_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080080 int cert_in_cb;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080081 const char *openssl_ciphers;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080082 unsigned int tls_session_lifetime;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070083
84 void (*event_cb)(void *ctx, enum tls_event ev,
85 union tls_event_data *data);
86 void *cb_ctx;
87};
88
89#define TLS_CONN_ALLOW_SIGN_RSA_MD5 BIT(0)
90#define TLS_CONN_DISABLE_TIME_CHECKS BIT(1)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070091#define TLS_CONN_DISABLE_SESSION_TICKET BIT(2)
Dmitry Shmidt34af3062013-07-11 10:46:32 -070092#define TLS_CONN_REQUEST_OCSP BIT(3)
93#define TLS_CONN_REQUIRE_OCSP BIT(4)
Dmitry Shmidt13ca8d82014-02-20 10:18:40 -080094#define TLS_CONN_DISABLE_TLSv1_1 BIT(5)
95#define TLS_CONN_DISABLE_TLSv1_2 BIT(6)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080096#define TLS_CONN_EAP_FAST BIT(7)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080097#define TLS_CONN_DISABLE_TLSv1_0 BIT(8)
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080098#define TLS_CONN_EXT_CERT_CHECK BIT(9)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070099
100/**
101 * struct tls_connection_params - Parameters for TLS connection
102 * @ca_cert: File or reference name for CA X.509 certificate in PEM or DER
103 * format
104 * @ca_cert_blob: ca_cert as inlined data or %NULL if not used
105 * @ca_cert_blob_len: ca_cert_blob length
106 * @ca_path: Path to CA certificates (OpenSSL specific)
107 * @subject_match: String to match in the subject of the peer certificate or
108 * %NULL to allow all subjects
109 * @altsubject_match: String to match in the alternative subject of the peer
110 * certificate or %NULL to allow all alternative subjects
Dmitry Shmidt051af732013-10-22 13:52:46 -0700111 * @suffix_match: String to suffix match in the dNSName or CN of the peer
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800112 * certificate or %NULL to allow all domain names. This may allow subdomains an
113 * wildcard certificates. Each domain name label must have a full match.
114 * @domain_match: String to match in the dNSName or CN of the peer
115 * certificate or %NULL to allow all domain names. This requires a full,
116 * case-insensitive match.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700117 * @client_cert: File or reference name for client X.509 certificate in PEM or
118 * DER format
119 * @client_cert_blob: client_cert as inlined data or %NULL if not used
120 * @client_cert_blob_len: client_cert_blob length
121 * @private_key: File or reference name for client private key in PEM or DER
122 * format (traditional format (RSA PRIVATE KEY) or PKCS#8 (PRIVATE KEY)
123 * @private_key_blob: private_key as inlined data or %NULL if not used
124 * @private_key_blob_len: private_key_blob length
125 * @private_key_passwd: Passphrase for decrypted private key, %NULL if no
126 * passphrase is used.
127 * @dh_file: File name for DH/DSA data in PEM format, or %NULL if not used
128 * @dh_blob: dh_file as inlined data or %NULL if not used
129 * @dh_blob_len: dh_blob length
130 * @engine: 1 = use engine (e.g., a smartcard) for private key operations
131 * (this is OpenSSL specific for now)
132 * @engine_id: engine id string (this is OpenSSL specific for now)
133 * @ppin: pointer to the pin variable in the configuration
134 * (this is OpenSSL specific for now)
135 * @key_id: the private key's id when using engine (this is OpenSSL
136 * specific for now)
137 * @cert_id: the certificate's id when using engine
138 * @ca_cert_id: the CA certificate's id when using engine
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800139 * @openssl_ciphers: OpenSSL cipher configuration
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700140 * @flags: Parameter options (TLS_CONN_*)
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700141 * @ocsp_stapling_response: DER encoded file with cached OCSP stapling response
142 * or %NULL if OCSP is not enabled
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700143 *
144 * TLS connection parameters to be configured with tls_connection_set_params()
145 * and tls_global_set_params().
146 *
147 * Certificates and private key can be configured either as a reference name
148 * (file path or reference to certificate store) or by providing the same data
149 * as a pointer to the data in memory. Only one option will be used for each
150 * field.
151 */
152struct tls_connection_params {
153 const char *ca_cert;
154 const u8 *ca_cert_blob;
155 size_t ca_cert_blob_len;
156 const char *ca_path;
157 const char *subject_match;
158 const char *altsubject_match;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700159 const char *suffix_match;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800160 const char *domain_match;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700161 const char *client_cert;
162 const u8 *client_cert_blob;
163 size_t client_cert_blob_len;
164 const char *private_key;
165 const u8 *private_key_blob;
166 size_t private_key_blob_len;
167 const char *private_key_passwd;
168 const char *dh_file;
169 const u8 *dh_blob;
170 size_t dh_blob_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700171
172 /* OpenSSL specific variables */
173 int engine;
174 const char *engine_id;
175 const char *pin;
176 const char *key_id;
177 const char *cert_id;
178 const char *ca_cert_id;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800179 const char *openssl_ciphers;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180
181 unsigned int flags;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700182 const char *ocsp_stapling_response;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700183};
184
185
186/**
187 * tls_init - Initialize TLS library
188 * @conf: Configuration data for TLS library
189 * Returns: Context data to be used as tls_ctx in calls to other functions,
190 * or %NULL on failure.
191 *
192 * Called once during program startup and once for each RSN pre-authentication
193 * session. In other words, there can be two concurrent TLS contexts. If global
194 * library initialization is needed (i.e., one that is shared between both
195 * authentication types), the TLS library wrapper should maintain a reference
196 * counter and do global initialization only when moving from 0 to 1 reference.
197 */
198void * tls_init(const struct tls_config *conf);
199
200/**
201 * tls_deinit - Deinitialize TLS library
202 * @tls_ctx: TLS context data from tls_init()
203 *
204 * Called once during program shutdown and once for each RSN pre-authentication
205 * session. If global library deinitialization is needed (i.e., one that is
206 * shared between both authentication types), the TLS library wrapper should
207 * maintain a reference counter and do global deinitialization only when moving
208 * from 1 to 0 references.
209 */
210void tls_deinit(void *tls_ctx);
211
212/**
213 * tls_get_errors - Process pending errors
214 * @tls_ctx: TLS context data from tls_init()
215 * Returns: Number of found error, 0 if no errors detected.
216 *
217 * Process all pending TLS errors.
218 */
219int tls_get_errors(void *tls_ctx);
220
221/**
222 * tls_connection_init - Initialize a new TLS connection
223 * @tls_ctx: TLS context data from tls_init()
224 * Returns: Connection context data, conn for other function calls
225 */
226struct tls_connection * tls_connection_init(void *tls_ctx);
227
228/**
229 * tls_connection_deinit - Free TLS connection data
230 * @tls_ctx: TLS context data from tls_init()
231 * @conn: Connection context data from tls_connection_init()
232 *
233 * Release all resources allocated for TLS connection.
234 */
235void tls_connection_deinit(void *tls_ctx, struct tls_connection *conn);
236
237/**
238 * tls_connection_established - Has the TLS connection been completed?
239 * @tls_ctx: TLS context data from tls_init()
240 * @conn: Connection context data from tls_connection_init()
241 * Returns: 1 if TLS connection has been completed, 0 if not.
242 */
243int tls_connection_established(void *tls_ctx, struct tls_connection *conn);
244
245/**
246 * tls_connection_shutdown - Shutdown TLS connection
247 * @tls_ctx: TLS context data from tls_init()
248 * @conn: Connection context data from tls_connection_init()
249 * Returns: 0 on success, -1 on failure
250 *
251 * Shutdown current TLS connection without releasing all resources. New
252 * connection can be started by using the same conn without having to call
253 * tls_connection_init() or setting certificates etc. again. The new
254 * connection should try to use session resumption.
255 */
256int tls_connection_shutdown(void *tls_ctx, struct tls_connection *conn);
257
258enum {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700259 TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN = -4,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700260 TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED = -3,
261 TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED = -2
262};
263
264/**
265 * tls_connection_set_params - Set TLS connection parameters
266 * @tls_ctx: TLS context data from tls_init()
267 * @conn: Connection context data from tls_connection_init()
268 * @params: Connection parameters
269 * Returns: 0 on success, -1 on failure,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700270 * TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED (-2) on error causing PKCS#11 engine
271 * failure, or
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700272 * TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED (-3) on failure to verify the
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700273 * PKCS#11 engine private key, or
274 * TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN (-4) on PIN error causing PKCS#11 engine
275 * failure.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700276 */
277int __must_check
278tls_connection_set_params(void *tls_ctx, struct tls_connection *conn,
279 const struct tls_connection_params *params);
280
281/**
282 * tls_global_set_params - Set TLS parameters for all TLS connection
283 * @tls_ctx: TLS context data from tls_init()
284 * @params: Global TLS parameters
285 * Returns: 0 on success, -1 on failure,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700286 * TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED (-2) on error causing PKCS#11 engine
287 * failure, or
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700288 * TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED (-3) on failure to verify the
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700289 * PKCS#11 engine private key, or
290 * TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN (-4) on PIN error causing PKCS#11 engine
291 * failure.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292 */
293int __must_check tls_global_set_params(
294 void *tls_ctx, const struct tls_connection_params *params);
295
296/**
297 * tls_global_set_verify - Set global certificate verification options
298 * @tls_ctx: TLS context data from tls_init()
299 * @check_crl: 0 = do not verify CRLs, 1 = verify CRL for the user certificate,
300 * 2 = verify CRL for all certificates
301 * Returns: 0 on success, -1 on failure
302 */
303int __must_check tls_global_set_verify(void *tls_ctx, int check_crl);
304
305/**
306 * tls_connection_set_verify - Set certificate verification options
307 * @tls_ctx: TLS context data from tls_init()
308 * @conn: Connection context data from tls_connection_init()
309 * @verify_peer: 1 = verify peer certificate
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800310 * @flags: Connection flags (TLS_CONN_*)
311 * @session_ctx: Session caching context or %NULL to use default
312 * @session_ctx_len: Length of @session_ctx in bytes.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700313 * Returns: 0 on success, -1 on failure
314 */
315int __must_check tls_connection_set_verify(void *tls_ctx,
316 struct tls_connection *conn,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800317 int verify_peer,
318 unsigned int flags,
319 const u8 *session_ctx,
320 size_t session_ctx_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700321
322/**
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800323 * tls_connection_get_random - Get random data from TLS connection
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324 * @tls_ctx: TLS context data from tls_init()
325 * @conn: Connection context data from tls_connection_init()
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800326 * @data: Structure of client/server random data (filled on success)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700327 * Returns: 0 on success, -1 on failure
328 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800329int __must_check tls_connection_get_random(void *tls_ctx,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700330 struct tls_connection *conn,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800331 struct tls_random *data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700332
333/**
334 * tls_connection_prf - Use TLS-PRF to derive keying material
335 * @tls_ctx: TLS context data from tls_init()
336 * @conn: Connection context data from tls_connection_init()
337 * @label: Label (e.g., description of the key) for PRF
338 * @server_random_first: seed is 0 = client_random|server_random,
339 * 1 = server_random|client_random
Dmitry Shmidtaf9da312015-04-03 10:03:11 -0700340 * @skip_keyblock: Skip TLS key block from the beginning of PRF output
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700341 * @out: Buffer for output data from TLS-PRF
342 * @out_len: Length of the output buffer
343 * Returns: 0 on success, -1 on failure
344 *
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800345 * tls_connection_prf() is required so that further keying material can be
346 * derived from the master secret. Example implementation of this function is in
347 * tls_prf_sha1_md5() when it is called with seed set to
348 * client_random|server_random (or server_random|client_random). For TLSv1.2 and
349 * newer, a different PRF is needed, though.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700350 */
351int __must_check tls_connection_prf(void *tls_ctx,
352 struct tls_connection *conn,
353 const char *label,
354 int server_random_first,
Dmitry Shmidtaf9da312015-04-03 10:03:11 -0700355 int skip_keyblock,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700356 u8 *out, size_t out_len);
357
358/**
359 * tls_connection_handshake - Process TLS handshake (client side)
360 * @tls_ctx: TLS context data from tls_init()
361 * @conn: Connection context data from tls_connection_init()
362 * @in_data: Input data from TLS server
363 * @appl_data: Pointer to application data pointer, or %NULL if dropped
364 * Returns: Output data, %NULL on failure
365 *
366 * The caller is responsible for freeing the returned output data. If the final
367 * handshake message includes application data, this is decrypted and
368 * appl_data (if not %NULL) is set to point this data. The caller is
369 * responsible for freeing appl_data.
370 *
371 * This function is used during TLS handshake. The first call is done with
372 * in_data == %NULL and the library is expected to return ClientHello packet.
373 * This packet is then send to the server and a response from server is given
374 * to TLS library by calling this function again with in_data pointing to the
375 * TLS message from the server.
376 *
377 * If the TLS handshake fails, this function may return %NULL. However, if the
378 * TLS library has a TLS alert to send out, that should be returned as the
379 * output data. In this case, tls_connection_get_failed() must return failure
380 * (> 0).
381 *
382 * tls_connection_established() should return 1 once the TLS handshake has been
383 * completed successfully.
384 */
385struct wpabuf * tls_connection_handshake(void *tls_ctx,
386 struct tls_connection *conn,
387 const struct wpabuf *in_data,
388 struct wpabuf **appl_data);
389
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800390struct wpabuf * tls_connection_handshake2(void *tls_ctx,
391 struct tls_connection *conn,
392 const struct wpabuf *in_data,
393 struct wpabuf **appl_data,
394 int *more_data_needed);
395
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700396/**
397 * tls_connection_server_handshake - Process TLS handshake (server side)
398 * @tls_ctx: TLS context data from tls_init()
399 * @conn: Connection context data from tls_connection_init()
400 * @in_data: Input data from TLS peer
401 * @appl_data: Pointer to application data pointer, or %NULL if dropped
402 * Returns: Output data, %NULL on failure
403 *
404 * The caller is responsible for freeing the returned output data.
405 */
406struct wpabuf * tls_connection_server_handshake(void *tls_ctx,
407 struct tls_connection *conn,
408 const struct wpabuf *in_data,
409 struct wpabuf **appl_data);
410
411/**
412 * tls_connection_encrypt - Encrypt data into TLS tunnel
413 * @tls_ctx: TLS context data from tls_init()
414 * @conn: Connection context data from tls_connection_init()
415 * @in_data: Plaintext data to be encrypted
416 * Returns: Encrypted TLS data or %NULL on failure
417 *
418 * This function is used after TLS handshake has been completed successfully to
419 * send data in the encrypted tunnel. The caller is responsible for freeing the
420 * returned output data.
421 */
422struct wpabuf * tls_connection_encrypt(void *tls_ctx,
423 struct tls_connection *conn,
424 const struct wpabuf *in_data);
425
426/**
427 * tls_connection_decrypt - Decrypt data from TLS tunnel
428 * @tls_ctx: TLS context data from tls_init()
429 * @conn: Connection context data from tls_connection_init()
430 * @in_data: Encrypted TLS data
431 * Returns: Decrypted TLS data or %NULL on failure
432 *
433 * This function is used after TLS handshake has been completed successfully to
434 * receive data from the encrypted tunnel. The caller is responsible for
435 * freeing the returned output data.
436 */
437struct wpabuf * tls_connection_decrypt(void *tls_ctx,
438 struct tls_connection *conn,
439 const struct wpabuf *in_data);
440
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800441struct wpabuf * tls_connection_decrypt2(void *tls_ctx,
442 struct tls_connection *conn,
443 const struct wpabuf *in_data,
444 int *more_data_needed);
445
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446/**
447 * tls_connection_resumed - Was session resumption used
448 * @tls_ctx: TLS context data from tls_init()
449 * @conn: Connection context data from tls_connection_init()
450 * Returns: 1 if current session used session resumption, 0 if not
451 */
452int tls_connection_resumed(void *tls_ctx, struct tls_connection *conn);
453
454enum {
455 TLS_CIPHER_NONE,
456 TLS_CIPHER_RC4_SHA /* 0x0005 */,
457 TLS_CIPHER_AES128_SHA /* 0x002f */,
458 TLS_CIPHER_RSA_DHE_AES128_SHA /* 0x0031 */,
459 TLS_CIPHER_ANON_DH_AES128_SHA /* 0x0034 */
460};
461
462/**
463 * tls_connection_set_cipher_list - Configure acceptable cipher suites
464 * @tls_ctx: TLS context data from tls_init()
465 * @conn: Connection context data from tls_connection_init()
466 * @ciphers: Zero (TLS_CIPHER_NONE) terminated list of allowed ciphers
467 * (TLS_CIPHER_*).
468 * Returns: 0 on success, -1 on failure
469 */
470int __must_check tls_connection_set_cipher_list(void *tls_ctx,
471 struct tls_connection *conn,
472 u8 *ciphers);
473
474/**
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800475 * tls_get_version - Get the current TLS version number
476 * @tls_ctx: TLS context data from tls_init()
477 * @conn: Connection context data from tls_connection_init()
478 * @buf: Buffer for returning the TLS version number
479 * @buflen: buf size
480 * Returns: 0 on success, -1 on failure
481 *
482 * Get the currently used TLS version number.
483 */
484int __must_check tls_get_version(void *tls_ctx, struct tls_connection *conn,
485 char *buf, size_t buflen);
486
487/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700488 * tls_get_cipher - Get current cipher name
489 * @tls_ctx: TLS context data from tls_init()
490 * @conn: Connection context data from tls_connection_init()
491 * @buf: Buffer for the cipher name
492 * @buflen: buf size
493 * Returns: 0 on success, -1 on failure
494 *
495 * Get the name of the currently used cipher.
496 */
497int __must_check tls_get_cipher(void *tls_ctx, struct tls_connection *conn,
498 char *buf, size_t buflen);
499
500/**
501 * tls_connection_enable_workaround - Enable TLS workaround options
502 * @tls_ctx: TLS context data from tls_init()
503 * @conn: Connection context data from tls_connection_init()
504 * Returns: 0 on success, -1 on failure
505 *
506 * This function is used to enable connection-specific workaround options for
507 * buffer SSL/TLS implementations.
508 */
509int __must_check tls_connection_enable_workaround(void *tls_ctx,
510 struct tls_connection *conn);
511
512/**
513 * tls_connection_client_hello_ext - Set TLS extension for ClientHello
514 * @tls_ctx: TLS context data from tls_init()
515 * @conn: Connection context data from tls_connection_init()
516 * @ext_type: Extension type
517 * @data: Extension payload (%NULL to remove extension)
518 * @data_len: Extension payload length
519 * Returns: 0 on success, -1 on failure
520 */
521int __must_check tls_connection_client_hello_ext(void *tls_ctx,
522 struct tls_connection *conn,
523 int ext_type, const u8 *data,
524 size_t data_len);
525
526/**
527 * tls_connection_get_failed - Get connection failure status
528 * @tls_ctx: TLS context data from tls_init()
529 * @conn: Connection context data from tls_connection_init()
530 *
531 * Returns >0 if connection has failed, 0 if not.
532 */
533int tls_connection_get_failed(void *tls_ctx, struct tls_connection *conn);
534
535/**
536 * tls_connection_get_read_alerts - Get connection read alert status
537 * @tls_ctx: TLS context data from tls_init()
538 * @conn: Connection context data from tls_connection_init()
539 * Returns: Number of times a fatal read (remote end reported error) has
540 * happened during this connection.
541 */
542int tls_connection_get_read_alerts(void *tls_ctx, struct tls_connection *conn);
543
544/**
545 * tls_connection_get_write_alerts - Get connection write alert status
546 * @tls_ctx: TLS context data from tls_init()
547 * @conn: Connection context data from tls_connection_init()
548 * Returns: Number of times a fatal write (locally detected error) has happened
549 * during this connection.
550 */
551int tls_connection_get_write_alerts(void *tls_ctx,
552 struct tls_connection *conn);
553
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700554typedef int (*tls_session_ticket_cb)
555(void *ctx, const u8 *ticket, size_t len, const u8 *client_random,
556 const u8 *server_random, u8 *master_secret);
557
558int __must_check tls_connection_set_session_ticket_cb(
559 void *tls_ctx, struct tls_connection *conn,
560 tls_session_ticket_cb cb, void *ctx);
561
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700562void tls_connection_set_log_cb(struct tls_connection *conn,
563 void (*log_cb)(void *ctx, const char *msg),
564 void *ctx);
565
566#define TLS_BREAK_VERIFY_DATA BIT(0)
567#define TLS_BREAK_SRV_KEY_X_HASH BIT(1)
568#define TLS_BREAK_SRV_KEY_X_SIGNATURE BIT(2)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700569#define TLS_DHE_PRIME_511B BIT(3)
570#define TLS_DHE_PRIME_767B BIT(4)
571#define TLS_DHE_PRIME_15 BIT(5)
572#define TLS_DHE_PRIME_58B BIT(6)
573#define TLS_DHE_NON_PRIME BIT(7)
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700574
575void tls_connection_set_test_flags(struct tls_connection *conn, u32 flags);
576
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800577int tls_get_library_version(char *buf, size_t buf_len);
578
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800579void tls_connection_set_success_data(struct tls_connection *conn,
580 struct wpabuf *data);
581
582void tls_connection_set_success_data_resumed(struct tls_connection *conn);
583
584const struct wpabuf *
585tls_connection_get_success_data(struct tls_connection *conn);
586
587void tls_connection_remove_session(struct tls_connection *conn);
588
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700589#endif /* TLS_H */