blob: d13657e16372ac8378d32f1018c0cb4bb7f0e66e [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
14struct tls_keys {
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 Shmidt8d520ff2011-05-09 14:06:53 -070082
83 void (*event_cb)(void *ctx, enum tls_event ev,
84 union tls_event_data *data);
85 void *cb_ctx;
86};
87
88#define TLS_CONN_ALLOW_SIGN_RSA_MD5 BIT(0)
89#define TLS_CONN_DISABLE_TIME_CHECKS BIT(1)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070090#define TLS_CONN_DISABLE_SESSION_TICKET BIT(2)
Dmitry Shmidt34af3062013-07-11 10:46:32 -070091#define TLS_CONN_REQUEST_OCSP BIT(3)
92#define TLS_CONN_REQUIRE_OCSP BIT(4)
Dmitry Shmidt13ca8d82014-02-20 10:18:40 -080093#define TLS_CONN_DISABLE_TLSv1_1 BIT(5)
94#define TLS_CONN_DISABLE_TLSv1_2 BIT(6)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080095#define TLS_CONN_EAP_FAST BIT(7)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070096
97/**
98 * struct tls_connection_params - Parameters for TLS connection
99 * @ca_cert: File or reference name for CA X.509 certificate in PEM or DER
100 * format
101 * @ca_cert_blob: ca_cert as inlined data or %NULL if not used
102 * @ca_cert_blob_len: ca_cert_blob length
103 * @ca_path: Path to CA certificates (OpenSSL specific)
104 * @subject_match: String to match in the subject of the peer certificate or
105 * %NULL to allow all subjects
106 * @altsubject_match: String to match in the alternative subject of the peer
107 * certificate or %NULL to allow all alternative subjects
Dmitry Shmidt051af732013-10-22 13:52:46 -0700108 * @suffix_match: String to suffix match in the dNSName or CN of the peer
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800109 * certificate or %NULL to allow all domain names. This may allow subdomains an
110 * wildcard certificates. Each domain name label must have a full match.
111 * @domain_match: String to match in the dNSName or CN of the peer
112 * certificate or %NULL to allow all domain names. This requires a full,
113 * case-insensitive match.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 * @client_cert: File or reference name for client X.509 certificate in PEM or
115 * DER format
116 * @client_cert_blob: client_cert as inlined data or %NULL if not used
117 * @client_cert_blob_len: client_cert_blob length
118 * @private_key: File or reference name for client private key in PEM or DER
119 * format (traditional format (RSA PRIVATE KEY) or PKCS#8 (PRIVATE KEY)
120 * @private_key_blob: private_key as inlined data or %NULL if not used
121 * @private_key_blob_len: private_key_blob length
122 * @private_key_passwd: Passphrase for decrypted private key, %NULL if no
123 * passphrase is used.
124 * @dh_file: File name for DH/DSA data in PEM format, or %NULL if not used
125 * @dh_blob: dh_file as inlined data or %NULL if not used
126 * @dh_blob_len: dh_blob length
127 * @engine: 1 = use engine (e.g., a smartcard) for private key operations
128 * (this is OpenSSL specific for now)
129 * @engine_id: engine id string (this is OpenSSL specific for now)
130 * @ppin: pointer to the pin variable in the configuration
131 * (this is OpenSSL specific for now)
132 * @key_id: the private key's id when using engine (this is OpenSSL
133 * specific for now)
134 * @cert_id: the certificate's id when using engine
135 * @ca_cert_id: the CA certificate's id when using engine
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800136 * @openssl_ciphers: OpenSSL cipher configuration
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700137 * @flags: Parameter options (TLS_CONN_*)
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700138 * @ocsp_stapling_response: DER encoded file with cached OCSP stapling response
139 * or %NULL if OCSP is not enabled
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700140 *
141 * TLS connection parameters to be configured with tls_connection_set_params()
142 * and tls_global_set_params().
143 *
144 * Certificates and private key can be configured either as a reference name
145 * (file path or reference to certificate store) or by providing the same data
146 * as a pointer to the data in memory. Only one option will be used for each
147 * field.
148 */
149struct tls_connection_params {
150 const char *ca_cert;
151 const u8 *ca_cert_blob;
152 size_t ca_cert_blob_len;
153 const char *ca_path;
154 const char *subject_match;
155 const char *altsubject_match;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700156 const char *suffix_match;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800157 const char *domain_match;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700158 const char *client_cert;
159 const u8 *client_cert_blob;
160 size_t client_cert_blob_len;
161 const char *private_key;
162 const u8 *private_key_blob;
163 size_t private_key_blob_len;
164 const char *private_key_passwd;
165 const char *dh_file;
166 const u8 *dh_blob;
167 size_t dh_blob_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700168
169 /* OpenSSL specific variables */
170 int engine;
171 const char *engine_id;
172 const char *pin;
173 const char *key_id;
174 const char *cert_id;
175 const char *ca_cert_id;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800176 const char *openssl_ciphers;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700177
178 unsigned int flags;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700179 const char *ocsp_stapling_response;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180};
181
182
183/**
184 * tls_init - Initialize TLS library
185 * @conf: Configuration data for TLS library
186 * Returns: Context data to be used as tls_ctx in calls to other functions,
187 * or %NULL on failure.
188 *
189 * Called once during program startup and once for each RSN pre-authentication
190 * session. In other words, there can be two concurrent TLS contexts. If global
191 * library initialization is needed (i.e., one that is shared between both
192 * authentication types), the TLS library wrapper should maintain a reference
193 * counter and do global initialization only when moving from 0 to 1 reference.
194 */
195void * tls_init(const struct tls_config *conf);
196
197/**
198 * tls_deinit - Deinitialize TLS library
199 * @tls_ctx: TLS context data from tls_init()
200 *
201 * Called once during program shutdown and once for each RSN pre-authentication
202 * session. If global library deinitialization is needed (i.e., one that is
203 * shared between both authentication types), the TLS library wrapper should
204 * maintain a reference counter and do global deinitialization only when moving
205 * from 1 to 0 references.
206 */
207void tls_deinit(void *tls_ctx);
208
209/**
210 * tls_get_errors - Process pending errors
211 * @tls_ctx: TLS context data from tls_init()
212 * Returns: Number of found error, 0 if no errors detected.
213 *
214 * Process all pending TLS errors.
215 */
216int tls_get_errors(void *tls_ctx);
217
218/**
219 * tls_connection_init - Initialize a new TLS connection
220 * @tls_ctx: TLS context data from tls_init()
221 * Returns: Connection context data, conn for other function calls
222 */
223struct tls_connection * tls_connection_init(void *tls_ctx);
224
225/**
226 * tls_connection_deinit - Free TLS connection data
227 * @tls_ctx: TLS context data from tls_init()
228 * @conn: Connection context data from tls_connection_init()
229 *
230 * Release all resources allocated for TLS connection.
231 */
232void tls_connection_deinit(void *tls_ctx, struct tls_connection *conn);
233
234/**
235 * tls_connection_established - Has the TLS connection been completed?
236 * @tls_ctx: TLS context data from tls_init()
237 * @conn: Connection context data from tls_connection_init()
238 * Returns: 1 if TLS connection has been completed, 0 if not.
239 */
240int tls_connection_established(void *tls_ctx, struct tls_connection *conn);
241
242/**
243 * tls_connection_shutdown - Shutdown TLS connection
244 * @tls_ctx: TLS context data from tls_init()
245 * @conn: Connection context data from tls_connection_init()
246 * Returns: 0 on success, -1 on failure
247 *
248 * Shutdown current TLS connection without releasing all resources. New
249 * connection can be started by using the same conn without having to call
250 * tls_connection_init() or setting certificates etc. again. The new
251 * connection should try to use session resumption.
252 */
253int tls_connection_shutdown(void *tls_ctx, struct tls_connection *conn);
254
255enum {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700256 TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN = -4,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700257 TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED = -3,
258 TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED = -2
259};
260
261/**
262 * tls_connection_set_params - Set TLS connection parameters
263 * @tls_ctx: TLS context data from tls_init()
264 * @conn: Connection context data from tls_connection_init()
265 * @params: Connection parameters
266 * Returns: 0 on success, -1 on failure,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700267 * TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED (-2) on error causing PKCS#11 engine
268 * failure, or
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700269 * TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED (-3) on failure to verify the
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700270 * PKCS#11 engine private key, or
271 * TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN (-4) on PIN error causing PKCS#11 engine
272 * failure.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700273 */
274int __must_check
275tls_connection_set_params(void *tls_ctx, struct tls_connection *conn,
276 const struct tls_connection_params *params);
277
278/**
279 * tls_global_set_params - Set TLS parameters for all TLS connection
280 * @tls_ctx: TLS context data from tls_init()
281 * @params: Global TLS parameters
282 * Returns: 0 on success, -1 on failure,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700283 * TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED (-2) on error causing PKCS#11 engine
284 * failure, or
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700285 * TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED (-3) on failure to verify the
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700286 * PKCS#11 engine private key, or
287 * TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN (-4) on PIN error causing PKCS#11 engine
288 * failure.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700289 */
290int __must_check tls_global_set_params(
291 void *tls_ctx, const struct tls_connection_params *params);
292
293/**
294 * tls_global_set_verify - Set global certificate verification options
295 * @tls_ctx: TLS context data from tls_init()
296 * @check_crl: 0 = do not verify CRLs, 1 = verify CRL for the user certificate,
297 * 2 = verify CRL for all certificates
298 * Returns: 0 on success, -1 on failure
299 */
300int __must_check tls_global_set_verify(void *tls_ctx, int check_crl);
301
302/**
303 * tls_connection_set_verify - Set certificate verification options
304 * @tls_ctx: TLS context data from tls_init()
305 * @conn: Connection context data from tls_connection_init()
306 * @verify_peer: 1 = verify peer certificate
307 * Returns: 0 on success, -1 on failure
308 */
309int __must_check tls_connection_set_verify(void *tls_ctx,
310 struct tls_connection *conn,
311 int verify_peer);
312
313/**
Dmitry Shmidtaf9da312015-04-03 10:03:11 -0700314 * tls_connection_get_keys - Get random data from TLS connection
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315 * @tls_ctx: TLS context data from tls_init()
316 * @conn: Connection context data from tls_connection_init()
Dmitry Shmidtaf9da312015-04-03 10:03:11 -0700317 * @keys: Structure of client/server random data (filled on success)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700318 * Returns: 0 on success, -1 on failure
319 */
320int __must_check tls_connection_get_keys(void *tls_ctx,
321 struct tls_connection *conn,
322 struct tls_keys *keys);
323
324/**
325 * tls_connection_prf - Use TLS-PRF to derive keying material
326 * @tls_ctx: TLS context data from tls_init()
327 * @conn: Connection context data from tls_connection_init()
328 * @label: Label (e.g., description of the key) for PRF
329 * @server_random_first: seed is 0 = client_random|server_random,
330 * 1 = server_random|client_random
Dmitry Shmidtaf9da312015-04-03 10:03:11 -0700331 * @skip_keyblock: Skip TLS key block from the beginning of PRF output
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700332 * @out: Buffer for output data from TLS-PRF
333 * @out_len: Length of the output buffer
334 * Returns: 0 on success, -1 on failure
335 *
336 * This function is optional to implement if tls_connection_get_keys() provides
337 * access to master secret and server/client random values. If these values are
338 * not exported from the TLS library, tls_connection_prf() is required so that
339 * further keying material can be derived from the master secret. If not
340 * implemented, the function will still need to be defined, but it can just
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800341 * return -1. Example implementation of this function is in tls_prf_sha1_md5()
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700342 * when it is called with seed set to client_random|server_random (or
343 * server_random|client_random).
344 */
345int __must_check tls_connection_prf(void *tls_ctx,
346 struct tls_connection *conn,
347 const char *label,
348 int server_random_first,
Dmitry Shmidtaf9da312015-04-03 10:03:11 -0700349 int skip_keyblock,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700350 u8 *out, size_t out_len);
351
352/**
353 * tls_connection_handshake - Process TLS handshake (client side)
354 * @tls_ctx: TLS context data from tls_init()
355 * @conn: Connection context data from tls_connection_init()
356 * @in_data: Input data from TLS server
357 * @appl_data: Pointer to application data pointer, or %NULL if dropped
358 * Returns: Output data, %NULL on failure
359 *
360 * The caller is responsible for freeing the returned output data. If the final
361 * handshake message includes application data, this is decrypted and
362 * appl_data (if not %NULL) is set to point this data. The caller is
363 * responsible for freeing appl_data.
364 *
365 * This function is used during TLS handshake. The first call is done with
366 * in_data == %NULL and the library is expected to return ClientHello packet.
367 * This packet is then send to the server and a response from server is given
368 * to TLS library by calling this function again with in_data pointing to the
369 * TLS message from the server.
370 *
371 * If the TLS handshake fails, this function may return %NULL. However, if the
372 * TLS library has a TLS alert to send out, that should be returned as the
373 * output data. In this case, tls_connection_get_failed() must return failure
374 * (> 0).
375 *
376 * tls_connection_established() should return 1 once the TLS handshake has been
377 * completed successfully.
378 */
379struct wpabuf * tls_connection_handshake(void *tls_ctx,
380 struct tls_connection *conn,
381 const struct wpabuf *in_data,
382 struct wpabuf **appl_data);
383
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800384struct wpabuf * tls_connection_handshake2(void *tls_ctx,
385 struct tls_connection *conn,
386 const struct wpabuf *in_data,
387 struct wpabuf **appl_data,
388 int *more_data_needed);
389
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700390/**
391 * tls_connection_server_handshake - Process TLS handshake (server side)
392 * @tls_ctx: TLS context data from tls_init()
393 * @conn: Connection context data from tls_connection_init()
394 * @in_data: Input data from TLS peer
395 * @appl_data: Pointer to application data pointer, or %NULL if dropped
396 * Returns: Output data, %NULL on failure
397 *
398 * The caller is responsible for freeing the returned output data.
399 */
400struct wpabuf * tls_connection_server_handshake(void *tls_ctx,
401 struct tls_connection *conn,
402 const struct wpabuf *in_data,
403 struct wpabuf **appl_data);
404
405/**
406 * tls_connection_encrypt - Encrypt data into TLS tunnel
407 * @tls_ctx: TLS context data from tls_init()
408 * @conn: Connection context data from tls_connection_init()
409 * @in_data: Plaintext data to be encrypted
410 * Returns: Encrypted TLS data or %NULL on failure
411 *
412 * This function is used after TLS handshake has been completed successfully to
413 * send data in the encrypted tunnel. The caller is responsible for freeing the
414 * returned output data.
415 */
416struct wpabuf * tls_connection_encrypt(void *tls_ctx,
417 struct tls_connection *conn,
418 const struct wpabuf *in_data);
419
420/**
421 * tls_connection_decrypt - Decrypt data from TLS tunnel
422 * @tls_ctx: TLS context data from tls_init()
423 * @conn: Connection context data from tls_connection_init()
424 * @in_data: Encrypted TLS data
425 * Returns: Decrypted TLS data or %NULL on failure
426 *
427 * This function is used after TLS handshake has been completed successfully to
428 * receive data from the encrypted tunnel. The caller is responsible for
429 * freeing the returned output data.
430 */
431struct wpabuf * tls_connection_decrypt(void *tls_ctx,
432 struct tls_connection *conn,
433 const struct wpabuf *in_data);
434
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800435struct wpabuf * tls_connection_decrypt2(void *tls_ctx,
436 struct tls_connection *conn,
437 const struct wpabuf *in_data,
438 int *more_data_needed);
439
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440/**
441 * tls_connection_resumed - Was session resumption used
442 * @tls_ctx: TLS context data from tls_init()
443 * @conn: Connection context data from tls_connection_init()
444 * Returns: 1 if current session used session resumption, 0 if not
445 */
446int tls_connection_resumed(void *tls_ctx, struct tls_connection *conn);
447
448enum {
449 TLS_CIPHER_NONE,
450 TLS_CIPHER_RC4_SHA /* 0x0005 */,
451 TLS_CIPHER_AES128_SHA /* 0x002f */,
452 TLS_CIPHER_RSA_DHE_AES128_SHA /* 0x0031 */,
453 TLS_CIPHER_ANON_DH_AES128_SHA /* 0x0034 */
454};
455
456/**
457 * tls_connection_set_cipher_list - Configure acceptable cipher suites
458 * @tls_ctx: TLS context data from tls_init()
459 * @conn: Connection context data from tls_connection_init()
460 * @ciphers: Zero (TLS_CIPHER_NONE) terminated list of allowed ciphers
461 * (TLS_CIPHER_*).
462 * Returns: 0 on success, -1 on failure
463 */
464int __must_check tls_connection_set_cipher_list(void *tls_ctx,
465 struct tls_connection *conn,
466 u8 *ciphers);
467
468/**
469 * tls_get_cipher - Get current cipher name
470 * @tls_ctx: TLS context data from tls_init()
471 * @conn: Connection context data from tls_connection_init()
472 * @buf: Buffer for the cipher name
473 * @buflen: buf size
474 * Returns: 0 on success, -1 on failure
475 *
476 * Get the name of the currently used cipher.
477 */
478int __must_check tls_get_cipher(void *tls_ctx, struct tls_connection *conn,
479 char *buf, size_t buflen);
480
481/**
482 * tls_connection_enable_workaround - Enable TLS workaround options
483 * @tls_ctx: TLS context data from tls_init()
484 * @conn: Connection context data from tls_connection_init()
485 * Returns: 0 on success, -1 on failure
486 *
487 * This function is used to enable connection-specific workaround options for
488 * buffer SSL/TLS implementations.
489 */
490int __must_check tls_connection_enable_workaround(void *tls_ctx,
491 struct tls_connection *conn);
492
493/**
494 * tls_connection_client_hello_ext - Set TLS extension for ClientHello
495 * @tls_ctx: TLS context data from tls_init()
496 * @conn: Connection context data from tls_connection_init()
497 * @ext_type: Extension type
498 * @data: Extension payload (%NULL to remove extension)
499 * @data_len: Extension payload length
500 * Returns: 0 on success, -1 on failure
501 */
502int __must_check tls_connection_client_hello_ext(void *tls_ctx,
503 struct tls_connection *conn,
504 int ext_type, const u8 *data,
505 size_t data_len);
506
507/**
508 * tls_connection_get_failed - Get connection failure status
509 * @tls_ctx: TLS context data from tls_init()
510 * @conn: Connection context data from tls_connection_init()
511 *
512 * Returns >0 if connection has failed, 0 if not.
513 */
514int tls_connection_get_failed(void *tls_ctx, struct tls_connection *conn);
515
516/**
517 * tls_connection_get_read_alerts - Get connection read alert status
518 * @tls_ctx: TLS context data from tls_init()
519 * @conn: Connection context data from tls_connection_init()
520 * Returns: Number of times a fatal read (remote end reported error) has
521 * happened during this connection.
522 */
523int tls_connection_get_read_alerts(void *tls_ctx, struct tls_connection *conn);
524
525/**
526 * tls_connection_get_write_alerts - Get connection write alert status
527 * @tls_ctx: TLS context data from tls_init()
528 * @conn: Connection context data from tls_connection_init()
529 * Returns: Number of times a fatal write (locally detected error) has happened
530 * during this connection.
531 */
532int tls_connection_get_write_alerts(void *tls_ctx,
533 struct tls_connection *conn);
534
535/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700536 * tls_capabilities - Get supported TLS capabilities
537 * @tls_ctx: TLS context data from tls_init()
538 * Returns: Bit field of supported TLS capabilities (TLS_CAPABILITY_*)
539 */
540unsigned int tls_capabilities(void *tls_ctx);
541
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700542typedef int (*tls_session_ticket_cb)
543(void *ctx, const u8 *ticket, size_t len, const u8 *client_random,
544 const u8 *server_random, u8 *master_secret);
545
546int __must_check tls_connection_set_session_ticket_cb(
547 void *tls_ctx, struct tls_connection *conn,
548 tls_session_ticket_cb cb, void *ctx);
549
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700550void tls_connection_set_log_cb(struct tls_connection *conn,
551 void (*log_cb)(void *ctx, const char *msg),
552 void *ctx);
553
554#define TLS_BREAK_VERIFY_DATA BIT(0)
555#define TLS_BREAK_SRV_KEY_X_HASH BIT(1)
556#define TLS_BREAK_SRV_KEY_X_SIGNATURE BIT(2)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700557#define TLS_DHE_PRIME_511B BIT(3)
558#define TLS_DHE_PRIME_767B BIT(4)
559#define TLS_DHE_PRIME_15 BIT(5)
560#define TLS_DHE_PRIME_58B BIT(6)
561#define TLS_DHE_NON_PRIME BIT(7)
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700562
563void tls_connection_set_test_flags(struct tls_connection *conn, u32 flags);
564
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800565int tls_get_library_version(char *buf, size_t buf_len);
566
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700567#endif /* TLS_H */