blob: 585db8bbed179449d231b7ae539da4d7f2519b4f [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 Shmidtd2986c22017-10-23 14:22:09 -070044 TLS_FAIL_INSUFFICIENT_KEY_LEN = 11,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070045};
46
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080047
48#define TLS_MAX_ALT_SUBJECT 10
49
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070050union tls_event_data {
51 struct {
52 int depth;
53 const char *subject;
54 enum tls_fail_reason reason;
55 const char *reason_txt;
56 const struct wpabuf *cert;
57 } cert_fail;
58
59 struct {
60 int depth;
61 const char *subject;
62 const struct wpabuf *cert;
63 const u8 *hash;
64 size_t hash_len;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080065 const char *altsubject[TLS_MAX_ALT_SUBJECT];
66 int num_altsubject;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070067 } peer_cert;
Dmitry Shmidt04949592012-07-19 12:16:46 -070068
69 struct {
70 int is_local;
71 const char *type;
72 const char *description;
73 } alert;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070074};
75
76struct tls_config {
77 const char *opensc_engine_path;
78 const char *pkcs11_engine_path;
79 const char *pkcs11_module_path;
80 int fips_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080081 int cert_in_cb;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080082 const char *openssl_ciphers;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080083 unsigned int tls_session_lifetime;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070084 unsigned int tls_flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070085
86 void (*event_cb)(void *ctx, enum tls_event ev,
87 union tls_event_data *data);
88 void *cb_ctx;
89};
90
91#define TLS_CONN_ALLOW_SIGN_RSA_MD5 BIT(0)
92#define TLS_CONN_DISABLE_TIME_CHECKS BIT(1)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070093#define TLS_CONN_DISABLE_SESSION_TICKET BIT(2)
Dmitry Shmidt34af3062013-07-11 10:46:32 -070094#define TLS_CONN_REQUEST_OCSP BIT(3)
95#define TLS_CONN_REQUIRE_OCSP BIT(4)
Dmitry Shmidt13ca8d82014-02-20 10:18:40 -080096#define TLS_CONN_DISABLE_TLSv1_1 BIT(5)
97#define TLS_CONN_DISABLE_TLSv1_2 BIT(6)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080098#define TLS_CONN_EAP_FAST BIT(7)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080099#define TLS_CONN_DISABLE_TLSv1_0 BIT(8)
Dmitry Shmidt55840ad2015-12-14 12:45:46 -0800100#define TLS_CONN_EXT_CERT_CHECK BIT(9)
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800101#define TLS_CONN_REQUIRE_OCSP_ALL BIT(10)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700102#define TLS_CONN_SUITEB BIT(11)
103#define TLS_CONN_SUITEB_NO_ECDH BIT(12)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700104#define TLS_CONN_DISABLE_TLSv1_3 BIT(13)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700105
106/**
107 * struct tls_connection_params - Parameters for TLS connection
108 * @ca_cert: File or reference name for CA X.509 certificate in PEM or DER
109 * format
110 * @ca_cert_blob: ca_cert as inlined data or %NULL if not used
111 * @ca_cert_blob_len: ca_cert_blob length
112 * @ca_path: Path to CA certificates (OpenSSL specific)
113 * @subject_match: String to match in the subject of the peer certificate or
114 * %NULL to allow all subjects
115 * @altsubject_match: String to match in the alternative subject of the peer
116 * certificate or %NULL to allow all alternative subjects
Dmitry Shmidt051af732013-10-22 13:52:46 -0700117 * @suffix_match: String to suffix match in the dNSName or CN of the peer
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800118 * certificate or %NULL to allow all domain names. This may allow subdomains an
119 * wildcard certificates. Each domain name label must have a full match.
120 * @domain_match: String to match in the dNSName or CN of the peer
121 * certificate or %NULL to allow all domain names. This requires a full,
122 * case-insensitive match.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700123 * @client_cert: File or reference name for client X.509 certificate in PEM or
124 * DER format
125 * @client_cert_blob: client_cert as inlined data or %NULL if not used
126 * @client_cert_blob_len: client_cert_blob length
127 * @private_key: File or reference name for client private key in PEM or DER
128 * format (traditional format (RSA PRIVATE KEY) or PKCS#8 (PRIVATE KEY)
129 * @private_key_blob: private_key as inlined data or %NULL if not used
130 * @private_key_blob_len: private_key_blob length
131 * @private_key_passwd: Passphrase for decrypted private key, %NULL if no
132 * passphrase is used.
133 * @dh_file: File name for DH/DSA data in PEM format, or %NULL if not used
134 * @dh_blob: dh_file as inlined data or %NULL if not used
135 * @dh_blob_len: dh_blob length
136 * @engine: 1 = use engine (e.g., a smartcard) for private key operations
137 * (this is OpenSSL specific for now)
138 * @engine_id: engine id string (this is OpenSSL specific for now)
139 * @ppin: pointer to the pin variable in the configuration
140 * (this is OpenSSL specific for now)
141 * @key_id: the private key's id when using engine (this is OpenSSL
142 * specific for now)
143 * @cert_id: the certificate's id when using engine
144 * @ca_cert_id: the CA certificate's id when using engine
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800145 * @openssl_ciphers: OpenSSL cipher configuration
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700146 * @flags: Parameter options (TLS_CONN_*)
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700147 * @ocsp_stapling_response: DER encoded file with cached OCSP stapling response
148 * or %NULL if OCSP is not enabled
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800149 * @ocsp_stapling_response_multi: DER encoded file with cached OCSP stapling
150 * response list (OCSPResponseList for ocsp_multi in RFC 6961) or %NULL if
151 * ocsp_multi is not enabled
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700152 *
153 * TLS connection parameters to be configured with tls_connection_set_params()
154 * and tls_global_set_params().
155 *
156 * Certificates and private key can be configured either as a reference name
157 * (file path or reference to certificate store) or by providing the same data
158 * as a pointer to the data in memory. Only one option will be used for each
159 * field.
160 */
161struct tls_connection_params {
162 const char *ca_cert;
163 const u8 *ca_cert_blob;
164 size_t ca_cert_blob_len;
165 const char *ca_path;
166 const char *subject_match;
167 const char *altsubject_match;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700168 const char *suffix_match;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800169 const char *domain_match;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700170 const char *client_cert;
171 const u8 *client_cert_blob;
172 size_t client_cert_blob_len;
173 const char *private_key;
174 const u8 *private_key_blob;
175 size_t private_key_blob_len;
176 const char *private_key_passwd;
177 const char *dh_file;
178 const u8 *dh_blob;
179 size_t dh_blob_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180
181 /* OpenSSL specific variables */
182 int engine;
183 const char *engine_id;
184 const char *pin;
185 const char *key_id;
186 const char *cert_id;
187 const char *ca_cert_id;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800188 const char *openssl_ciphers;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189
190 unsigned int flags;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700191 const char *ocsp_stapling_response;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800192 const char *ocsp_stapling_response_multi;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700193};
194
195
196/**
197 * tls_init - Initialize TLS library
198 * @conf: Configuration data for TLS library
199 * Returns: Context data to be used as tls_ctx in calls to other functions,
200 * or %NULL on failure.
201 *
202 * Called once during program startup and once for each RSN pre-authentication
203 * session. In other words, there can be two concurrent TLS contexts. If global
204 * library initialization is needed (i.e., one that is shared between both
205 * authentication types), the TLS library wrapper should maintain a reference
206 * counter and do global initialization only when moving from 0 to 1 reference.
207 */
208void * tls_init(const struct tls_config *conf);
209
210/**
211 * tls_deinit - Deinitialize TLS library
212 * @tls_ctx: TLS context data from tls_init()
213 *
214 * Called once during program shutdown and once for each RSN pre-authentication
215 * session. If global library deinitialization is needed (i.e., one that is
216 * shared between both authentication types), the TLS library wrapper should
217 * maintain a reference counter and do global deinitialization only when moving
218 * from 1 to 0 references.
219 */
220void tls_deinit(void *tls_ctx);
221
222/**
223 * tls_get_errors - Process pending errors
224 * @tls_ctx: TLS context data from tls_init()
225 * Returns: Number of found error, 0 if no errors detected.
226 *
227 * Process all pending TLS errors.
228 */
229int tls_get_errors(void *tls_ctx);
230
231/**
232 * tls_connection_init - Initialize a new TLS connection
233 * @tls_ctx: TLS context data from tls_init()
234 * Returns: Connection context data, conn for other function calls
235 */
236struct tls_connection * tls_connection_init(void *tls_ctx);
237
238/**
239 * tls_connection_deinit - Free TLS connection data
240 * @tls_ctx: TLS context data from tls_init()
241 * @conn: Connection context data from tls_connection_init()
242 *
243 * Release all resources allocated for TLS connection.
244 */
245void tls_connection_deinit(void *tls_ctx, struct tls_connection *conn);
246
247/**
248 * tls_connection_established - Has the TLS connection been completed?
249 * @tls_ctx: TLS context data from tls_init()
250 * @conn: Connection context data from tls_connection_init()
251 * Returns: 1 if TLS connection has been completed, 0 if not.
252 */
253int tls_connection_established(void *tls_ctx, struct tls_connection *conn);
254
255/**
256 * tls_connection_shutdown - Shutdown TLS connection
257 * @tls_ctx: TLS context data from tls_init()
258 * @conn: Connection context data from tls_connection_init()
259 * Returns: 0 on success, -1 on failure
260 *
261 * Shutdown current TLS connection without releasing all resources. New
262 * connection can be started by using the same conn without having to call
263 * tls_connection_init() or setting certificates etc. again. The new
264 * connection should try to use session resumption.
265 */
266int tls_connection_shutdown(void *tls_ctx, struct tls_connection *conn);
267
268enum {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700269 TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN = -4,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700270 TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED = -3,
271 TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED = -2
272};
273
274/**
275 * tls_connection_set_params - Set TLS connection parameters
276 * @tls_ctx: TLS context data from tls_init()
277 * @conn: Connection context data from tls_connection_init()
278 * @params: Connection parameters
279 * Returns: 0 on success, -1 on failure,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700280 * TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED (-2) on error causing PKCS#11 engine
281 * failure, or
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700282 * TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED (-3) on failure to verify the
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700283 * PKCS#11 engine private key, or
284 * TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN (-4) on PIN error causing PKCS#11 engine
285 * failure.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700286 */
287int __must_check
288tls_connection_set_params(void *tls_ctx, struct tls_connection *conn,
289 const struct tls_connection_params *params);
290
291/**
292 * tls_global_set_params - Set TLS parameters for all TLS connection
293 * @tls_ctx: TLS context data from tls_init()
294 * @params: Global TLS parameters
295 * Returns: 0 on success, -1 on failure,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700296 * TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED (-2) on error causing PKCS#11 engine
297 * failure, or
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700298 * TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED (-3) on failure to verify the
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700299 * PKCS#11 engine private key, or
300 * TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN (-4) on PIN error causing PKCS#11 engine
301 * failure.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700302 */
303int __must_check tls_global_set_params(
304 void *tls_ctx, const struct tls_connection_params *params);
305
306/**
307 * tls_global_set_verify - Set global certificate verification options
308 * @tls_ctx: TLS context data from tls_init()
309 * @check_crl: 0 = do not verify CRLs, 1 = verify CRL for the user certificate,
310 * 2 = verify CRL for all certificates
311 * Returns: 0 on success, -1 on failure
312 */
313int __must_check tls_global_set_verify(void *tls_ctx, int check_crl);
314
315/**
316 * tls_connection_set_verify - Set certificate verification options
317 * @tls_ctx: TLS context data from tls_init()
318 * @conn: Connection context data from tls_connection_init()
319 * @verify_peer: 1 = verify peer certificate
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800320 * @flags: Connection flags (TLS_CONN_*)
321 * @session_ctx: Session caching context or %NULL to use default
322 * @session_ctx_len: Length of @session_ctx in bytes.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700323 * Returns: 0 on success, -1 on failure
324 */
325int __must_check tls_connection_set_verify(void *tls_ctx,
326 struct tls_connection *conn,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800327 int verify_peer,
328 unsigned int flags,
329 const u8 *session_ctx,
330 size_t session_ctx_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700331
332/**
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800333 * tls_connection_get_random - Get random data from TLS connection
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700334 * @tls_ctx: TLS context data from tls_init()
335 * @conn: Connection context data from tls_connection_init()
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800336 * @data: Structure of client/server random data (filled on success)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700337 * Returns: 0 on success, -1 on failure
338 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800339int __must_check tls_connection_get_random(void *tls_ctx,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700340 struct tls_connection *conn,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800341 struct tls_random *data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700342
343/**
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700344 * tls_connection_export_key - Derive keying material from a TLS connection
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700345 * @tls_ctx: TLS context data from tls_init()
346 * @conn: Connection context data from tls_connection_init()
347 * @label: Label (e.g., description of the key) for PRF
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700348 * @out: Buffer for output data from TLS-PRF
349 * @out_len: Length of the output buffer
350 * Returns: 0 on success, -1 on failure
351 *
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700352 * Exports keying material using the mechanism described in RFC 5705.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700353 */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700354int __must_check tls_connection_export_key(void *tls_ctx,
355 struct tls_connection *conn,
356 const char *label,
357 u8 *out, size_t out_len);
358
359/**
360 * tls_connection_get_eap_fast_key - Derive key material for EAP-FAST
361 * @tls_ctx: TLS context data from tls_init()
362 * @conn: Connection context data from tls_connection_init()
363 * @out: Buffer for output data from TLS-PRF
364 * @out_len: Length of the output buffer
365 * Returns: 0 on success, -1 on failure
366 *
367 * Exports key material after the normal TLS key block for use with
368 * EAP-FAST. Most callers will want tls_connection_export_key(), but EAP-FAST
369 * uses a different legacy mechanism.
370 */
371int __must_check tls_connection_get_eap_fast_key(void *tls_ctx,
372 struct tls_connection *conn,
373 u8 *out, size_t out_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700374
375/**
376 * tls_connection_handshake - Process TLS handshake (client side)
377 * @tls_ctx: TLS context data from tls_init()
378 * @conn: Connection context data from tls_connection_init()
379 * @in_data: Input data from TLS server
380 * @appl_data: Pointer to application data pointer, or %NULL if dropped
381 * Returns: Output data, %NULL on failure
382 *
383 * The caller is responsible for freeing the returned output data. If the final
384 * handshake message includes application data, this is decrypted and
385 * appl_data (if not %NULL) is set to point this data. The caller is
386 * responsible for freeing appl_data.
387 *
388 * This function is used during TLS handshake. The first call is done with
389 * in_data == %NULL and the library is expected to return ClientHello packet.
390 * This packet is then send to the server and a response from server is given
391 * to TLS library by calling this function again with in_data pointing to the
392 * TLS message from the server.
393 *
394 * If the TLS handshake fails, this function may return %NULL. However, if the
395 * TLS library has a TLS alert to send out, that should be returned as the
396 * output data. In this case, tls_connection_get_failed() must return failure
397 * (> 0).
398 *
399 * tls_connection_established() should return 1 once the TLS handshake has been
400 * completed successfully.
401 */
402struct wpabuf * tls_connection_handshake(void *tls_ctx,
403 struct tls_connection *conn,
404 const struct wpabuf *in_data,
405 struct wpabuf **appl_data);
406
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800407struct wpabuf * tls_connection_handshake2(void *tls_ctx,
408 struct tls_connection *conn,
409 const struct wpabuf *in_data,
410 struct wpabuf **appl_data,
411 int *more_data_needed);
412
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700413/**
414 * tls_connection_server_handshake - Process TLS handshake (server side)
415 * @tls_ctx: TLS context data from tls_init()
416 * @conn: Connection context data from tls_connection_init()
417 * @in_data: Input data from TLS peer
418 * @appl_data: Pointer to application data pointer, or %NULL if dropped
419 * Returns: Output data, %NULL on failure
420 *
421 * The caller is responsible for freeing the returned output data.
422 */
423struct wpabuf * tls_connection_server_handshake(void *tls_ctx,
424 struct tls_connection *conn,
425 const struct wpabuf *in_data,
426 struct wpabuf **appl_data);
427
428/**
429 * tls_connection_encrypt - Encrypt data into TLS tunnel
430 * @tls_ctx: TLS context data from tls_init()
431 * @conn: Connection context data from tls_connection_init()
432 * @in_data: Plaintext data to be encrypted
433 * Returns: Encrypted TLS data or %NULL on failure
434 *
435 * This function is used after TLS handshake has been completed successfully to
436 * send data in the encrypted tunnel. The caller is responsible for freeing the
437 * returned output data.
438 */
439struct wpabuf * tls_connection_encrypt(void *tls_ctx,
440 struct tls_connection *conn,
441 const struct wpabuf *in_data);
442
443/**
444 * tls_connection_decrypt - Decrypt data from TLS tunnel
445 * @tls_ctx: TLS context data from tls_init()
446 * @conn: Connection context data from tls_connection_init()
447 * @in_data: Encrypted TLS data
448 * Returns: Decrypted TLS data or %NULL on failure
449 *
450 * This function is used after TLS handshake has been completed successfully to
451 * receive data from the encrypted tunnel. The caller is responsible for
452 * freeing the returned output data.
453 */
454struct wpabuf * tls_connection_decrypt(void *tls_ctx,
455 struct tls_connection *conn,
456 const struct wpabuf *in_data);
457
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800458struct wpabuf * tls_connection_decrypt2(void *tls_ctx,
459 struct tls_connection *conn,
460 const struct wpabuf *in_data,
461 int *more_data_needed);
462
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700463/**
464 * tls_connection_resumed - Was session resumption used
465 * @tls_ctx: TLS context data from tls_init()
466 * @conn: Connection context data from tls_connection_init()
467 * Returns: 1 if current session used session resumption, 0 if not
468 */
469int tls_connection_resumed(void *tls_ctx, struct tls_connection *conn);
470
471enum {
472 TLS_CIPHER_NONE,
473 TLS_CIPHER_RC4_SHA /* 0x0005 */,
474 TLS_CIPHER_AES128_SHA /* 0x002f */,
475 TLS_CIPHER_RSA_DHE_AES128_SHA /* 0x0031 */,
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800476 TLS_CIPHER_ANON_DH_AES128_SHA /* 0x0034 */,
477 TLS_CIPHER_RSA_DHE_AES256_SHA /* 0x0039 */,
478 TLS_CIPHER_AES256_SHA /* 0x0035 */,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479};
480
481/**
482 * tls_connection_set_cipher_list - Configure acceptable cipher suites
483 * @tls_ctx: TLS context data from tls_init()
484 * @conn: Connection context data from tls_connection_init()
485 * @ciphers: Zero (TLS_CIPHER_NONE) terminated list of allowed ciphers
486 * (TLS_CIPHER_*).
487 * Returns: 0 on success, -1 on failure
488 */
489int __must_check tls_connection_set_cipher_list(void *tls_ctx,
490 struct tls_connection *conn,
491 u8 *ciphers);
492
493/**
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800494 * tls_get_version - Get the current TLS version number
495 * @tls_ctx: TLS context data from tls_init()
496 * @conn: Connection context data from tls_connection_init()
497 * @buf: Buffer for returning the TLS version number
498 * @buflen: buf size
499 * Returns: 0 on success, -1 on failure
500 *
501 * Get the currently used TLS version number.
502 */
503int __must_check tls_get_version(void *tls_ctx, struct tls_connection *conn,
504 char *buf, size_t buflen);
505
506/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700507 * tls_get_cipher - Get current cipher name
508 * @tls_ctx: TLS context data from tls_init()
509 * @conn: Connection context data from tls_connection_init()
510 * @buf: Buffer for the cipher name
511 * @buflen: buf size
512 * Returns: 0 on success, -1 on failure
513 *
514 * Get the name of the currently used cipher.
515 */
516int __must_check tls_get_cipher(void *tls_ctx, struct tls_connection *conn,
517 char *buf, size_t buflen);
518
519/**
520 * tls_connection_enable_workaround - Enable TLS workaround options
521 * @tls_ctx: TLS context data from tls_init()
522 * @conn: Connection context data from tls_connection_init()
523 * Returns: 0 on success, -1 on failure
524 *
525 * This function is used to enable connection-specific workaround options for
526 * buffer SSL/TLS implementations.
527 */
528int __must_check tls_connection_enable_workaround(void *tls_ctx,
529 struct tls_connection *conn);
530
531/**
532 * tls_connection_client_hello_ext - Set TLS extension for ClientHello
533 * @tls_ctx: TLS context data from tls_init()
534 * @conn: Connection context data from tls_connection_init()
535 * @ext_type: Extension type
536 * @data: Extension payload (%NULL to remove extension)
537 * @data_len: Extension payload length
538 * Returns: 0 on success, -1 on failure
539 */
540int __must_check tls_connection_client_hello_ext(void *tls_ctx,
541 struct tls_connection *conn,
542 int ext_type, const u8 *data,
543 size_t data_len);
544
545/**
546 * tls_connection_get_failed - Get connection failure status
547 * @tls_ctx: TLS context data from tls_init()
548 * @conn: Connection context data from tls_connection_init()
549 *
550 * Returns >0 if connection has failed, 0 if not.
551 */
552int tls_connection_get_failed(void *tls_ctx, struct tls_connection *conn);
553
554/**
555 * tls_connection_get_read_alerts - Get connection read alert status
556 * @tls_ctx: TLS context data from tls_init()
557 * @conn: Connection context data from tls_connection_init()
558 * Returns: Number of times a fatal read (remote end reported error) has
559 * happened during this connection.
560 */
561int tls_connection_get_read_alerts(void *tls_ctx, struct tls_connection *conn);
562
563/**
564 * tls_connection_get_write_alerts - Get connection write alert status
565 * @tls_ctx: TLS context data from tls_init()
566 * @conn: Connection context data from tls_connection_init()
567 * Returns: Number of times a fatal write (locally detected error) has happened
568 * during this connection.
569 */
570int tls_connection_get_write_alerts(void *tls_ctx,
571 struct tls_connection *conn);
572
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700573typedef int (*tls_session_ticket_cb)
574(void *ctx, const u8 *ticket, size_t len, const u8 *client_random,
575 const u8 *server_random, u8 *master_secret);
576
577int __must_check tls_connection_set_session_ticket_cb(
578 void *tls_ctx, struct tls_connection *conn,
579 tls_session_ticket_cb cb, void *ctx);
580
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700581void tls_connection_set_log_cb(struct tls_connection *conn,
582 void (*log_cb)(void *ctx, const char *msg),
583 void *ctx);
584
585#define TLS_BREAK_VERIFY_DATA BIT(0)
586#define TLS_BREAK_SRV_KEY_X_HASH BIT(1)
587#define TLS_BREAK_SRV_KEY_X_SIGNATURE BIT(2)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700588#define TLS_DHE_PRIME_511B BIT(3)
589#define TLS_DHE_PRIME_767B BIT(4)
590#define TLS_DHE_PRIME_15 BIT(5)
591#define TLS_DHE_PRIME_58B BIT(6)
592#define TLS_DHE_NON_PRIME BIT(7)
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700593
594void tls_connection_set_test_flags(struct tls_connection *conn, u32 flags);
595
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800596int tls_get_library_version(char *buf, size_t buf_len);
597
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800598void tls_connection_set_success_data(struct tls_connection *conn,
599 struct wpabuf *data);
600
601void tls_connection_set_success_data_resumed(struct tls_connection *conn);
602
603const struct wpabuf *
604tls_connection_get_success_data(struct tls_connection *conn);
605
606void tls_connection_remove_session(struct tls_connection *conn);
607
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700608#endif /* TLS_H */