wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
tls.h
Go to the documentation of this file.
1 
5 #ifndef TLS_H
6 #define TLS_H
7 
8 struct tls_connection;
9 
10 struct tls_random {
11  const u8 *client_random;
12  size_t client_random_len;
13  const u8 *server_random;
14  size_t server_random_len;
15 };
16 
17 enum tls_event {
18  TLS_CERT_CHAIN_SUCCESS,
19  TLS_CERT_CHAIN_FAILURE,
20  TLS_PEER_CERTIFICATE,
21  TLS_ALERT
22 };
23 
24 /*
25  * Note: These are used as identifier with external programs and as such, the
26  * values must not be changed.
27  */
28 enum tls_fail_reason {
29  TLS_FAIL_UNSPECIFIED = 0,
30  TLS_FAIL_UNTRUSTED = 1,
31  TLS_FAIL_REVOKED = 2,
32  TLS_FAIL_NOT_YET_VALID = 3,
33  TLS_FAIL_EXPIRED = 4,
34  TLS_FAIL_SUBJECT_MISMATCH = 5,
35  TLS_FAIL_ALTSUBJECT_MISMATCH = 6,
36  TLS_FAIL_BAD_CERTIFICATE = 7,
37  TLS_FAIL_SERVER_CHAIN_PROBE = 8,
38  TLS_FAIL_DOMAIN_SUFFIX_MISMATCH = 9,
39  TLS_FAIL_DOMAIN_MISMATCH = 10,
40 };
41 
42 
43 #define TLS_MAX_ALT_SUBJECT 10
44 
46  struct {
47  int depth;
48  const char *subject;
49  enum tls_fail_reason reason;
50  const char *reason_txt;
51  const struct wpabuf *cert;
52  } cert_fail;
53 
54  struct {
55  int depth;
56  const char *subject;
57  const struct wpabuf *cert;
58  const u8 *hash;
59  size_t hash_len;
60  const char *altsubject[TLS_MAX_ALT_SUBJECT];
61  int num_altsubject;
62  } peer_cert;
63 
64  struct {
65  int is_local;
66  const char *type;
67  const char *description;
68  } alert;
69 };
70 
71 struct tls_config {
72  const char *opensc_engine_path;
73  const char *pkcs11_engine_path;
74  const char *pkcs11_module_path;
75  int fips_mode;
76  int cert_in_cb;
77  const char *openssl_ciphers;
78  unsigned int tls_session_lifetime;
79 
80  void (*event_cb)(void *ctx, enum tls_event ev,
81  union tls_event_data *data);
82  void *cb_ctx;
83 };
84 
85 #define TLS_CONN_ALLOW_SIGN_RSA_MD5 BIT(0)
86 #define TLS_CONN_DISABLE_TIME_CHECKS BIT(1)
87 #define TLS_CONN_DISABLE_SESSION_TICKET BIT(2)
88 #define TLS_CONN_REQUEST_OCSP BIT(3)
89 #define TLS_CONN_REQUIRE_OCSP BIT(4)
90 #define TLS_CONN_DISABLE_TLSv1_1 BIT(5)
91 #define TLS_CONN_DISABLE_TLSv1_2 BIT(6)
92 #define TLS_CONN_EAP_FAST BIT(7)
93 #define TLS_CONN_DISABLE_TLSv1_0 BIT(8)
94 
148  const char *ca_cert;
149  const u8 *ca_cert_blob;
150  size_t ca_cert_blob_len;
151  const char *ca_path;
152  const char *subject_match;
153  const char *altsubject_match;
154  const char *suffix_match;
155  const char *domain_match;
156  const char *client_cert;
157  const u8 *client_cert_blob;
158  size_t client_cert_blob_len;
159  const char *private_key;
160  const u8 *private_key_blob;
161  size_t private_key_blob_len;
162  const char *private_key_passwd;
163  const char *dh_file;
164  const u8 *dh_blob;
165  size_t dh_blob_len;
166 
167  /* OpenSSL specific variables */
168  int engine;
169  const char *engine_id;
170  const char *pin;
171  const char *key_id;
172  const char *cert_id;
173  const char *ca_cert_id;
174  const char *openssl_ciphers;
175 
176  unsigned int flags;
177  const char *ocsp_stapling_response;
178 };
179 
180 
193 void * tls_init(const struct tls_config *conf);
194 
205 void tls_deinit(void *tls_ctx);
206 
214 int tls_get_errors(void *tls_ctx);
215 
221 struct tls_connection * tls_connection_init(void *tls_ctx);
222 
230 void tls_connection_deinit(void *tls_ctx, struct tls_connection *conn);
231 
238 int tls_connection_established(void *tls_ctx, struct tls_connection *conn);
239 
251 int tls_connection_shutdown(void *tls_ctx, struct tls_connection *conn);
252 
253 enum {
254  TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN = -4,
255  TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED = -3,
256  TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED = -2
257 };
258 
272 int __must_check
273 tls_connection_set_params(void *tls_ctx, struct tls_connection *conn,
274  const struct tls_connection_params *params);
275 
288 int __must_check tls_global_set_params(
289  void *tls_ctx, const struct tls_connection_params *params);
290 
298 int __must_check tls_global_set_verify(void *tls_ctx, int check_crl);
299 
310 int __must_check tls_connection_set_verify(void *tls_ctx,
311  struct tls_connection *conn,
312  int verify_peer,
313  unsigned int flags,
314  const u8 *session_ctx,
315  size_t session_ctx_len);
316 
324 int __must_check tls_connection_get_random(void *tls_ctx,
325  struct tls_connection *conn,
326  struct tls_random *data);
327 
346 int __must_check tls_connection_prf(void *tls_ctx,
347  struct tls_connection *conn,
348  const char *label,
349  int server_random_first,
350  int skip_keyblock,
351  u8 *out, size_t out_len);
352 
380 struct wpabuf * tls_connection_handshake(void *tls_ctx,
381  struct tls_connection *conn,
382  const struct wpabuf *in_data,
383  struct wpabuf **appl_data);
384 
385 struct wpabuf * tls_connection_handshake2(void *tls_ctx,
386  struct tls_connection *conn,
387  const struct wpabuf *in_data,
388  struct wpabuf **appl_data,
389  int *more_data_needed);
390 
401 struct wpabuf * tls_connection_server_handshake(void *tls_ctx,
402  struct tls_connection *conn,
403  const struct wpabuf *in_data,
404  struct wpabuf **appl_data);
405 
417 struct wpabuf * tls_connection_encrypt(void *tls_ctx,
418  struct tls_connection *conn,
419  const struct wpabuf *in_data);
420 
432 struct wpabuf * tls_connection_decrypt(void *tls_ctx,
433  struct tls_connection *conn,
434  const struct wpabuf *in_data);
435 
436 struct wpabuf * tls_connection_decrypt2(void *tls_ctx,
437  struct tls_connection *conn,
438  const struct wpabuf *in_data,
439  int *more_data_needed);
440 
447 int tls_connection_resumed(void *tls_ctx, struct tls_connection *conn);
448 
449 enum {
450  TLS_CIPHER_NONE,
451  TLS_CIPHER_RC4_SHA /* 0x0005 */,
452  TLS_CIPHER_AES128_SHA /* 0x002f */,
453  TLS_CIPHER_RSA_DHE_AES128_SHA /* 0x0031 */,
454  TLS_CIPHER_ANON_DH_AES128_SHA /* 0x0034 */
455 };
456 
465 int __must_check tls_connection_set_cipher_list(void *tls_ctx,
466  struct tls_connection *conn,
467  u8 *ciphers);
468 
479 int __must_check tls_get_version(void *tls_ctx, struct tls_connection *conn,
480  char *buf, size_t buflen);
481 
492 int __must_check tls_get_cipher(void *tls_ctx, struct tls_connection *conn,
493  char *buf, size_t buflen);
494 
504 int __must_check tls_connection_enable_workaround(void *tls_ctx,
505  struct tls_connection *conn);
506 
516 int __must_check tls_connection_client_hello_ext(void *tls_ctx,
517  struct tls_connection *conn,
518  int ext_type, const u8 *data,
519  size_t data_len);
520 
528 int tls_connection_get_failed(void *tls_ctx, struct tls_connection *conn);
529 
537 int tls_connection_get_read_alerts(void *tls_ctx, struct tls_connection *conn);
538 
546 int tls_connection_get_write_alerts(void *tls_ctx,
547  struct tls_connection *conn);
548 
549 typedef int (*tls_session_ticket_cb)
550 (void *ctx, const u8 *ticket, size_t len, const u8 *client_random,
551  const u8 *server_random, u8 *master_secret);
552 
553 int __must_check tls_connection_set_session_ticket_cb(
554  void *tls_ctx, struct tls_connection *conn,
555  tls_session_ticket_cb cb, void *ctx);
556 
557 void tls_connection_set_log_cb(struct tls_connection *conn,
558  void (*log_cb)(void *ctx, const char *msg),
559  void *ctx);
560 
561 #define TLS_BREAK_VERIFY_DATA BIT(0)
562 #define TLS_BREAK_SRV_KEY_X_HASH BIT(1)
563 #define TLS_BREAK_SRV_KEY_X_SIGNATURE BIT(2)
564 #define TLS_DHE_PRIME_511B BIT(3)
565 #define TLS_DHE_PRIME_767B BIT(4)
566 #define TLS_DHE_PRIME_15 BIT(5)
567 #define TLS_DHE_PRIME_58B BIT(6)
568 #define TLS_DHE_NON_PRIME BIT(7)
569 
570 void tls_connection_set_test_flags(struct tls_connection *conn, u32 flags);
571 
572 int tls_get_library_version(char *buf, size_t buf_len);
573 
574 void tls_connection_set_success_data(struct tls_connection *conn,
575  struct wpabuf *data);
576 
577 void tls_connection_set_success_data_resumed(struct tls_connection *conn);
578 
579 const struct wpabuf *
580 tls_connection_get_success_data(struct tls_connection *conn);
581 
582 void tls_connection_remove_session(struct tls_connection *conn);
583 
584 #endif /* TLS_H */
int __must_check tls_get_version(void *tls_ctx, struct tls_connection *conn, char *buf, size_t buflen)
Get the current TLS version number.
Definition: tls_gnutls.c:1426
Parameters for TLS connection.
Definition: tls.h:147
Definition: tls.h:10
int __must_check tls_connection_client_hello_ext(void *tls_ctx, struct tls_connection *conn, int ext_type, const u8 *data, size_t data_len)
Set TLS extension for ClientHello.
Definition: tls_gnutls.c:1451
int __must_check tls_connection_get_random(void *tls_ctx, struct tls_connection *conn, struct tls_random *data)
Get random data from TLS connection.
Definition: tls_gnutls.c:722
int tls_connection_established(void *tls_ctx, struct tls_connection *conn)
Has the TLS connection been completed?
Definition: tls_gnutls.c:285
int tls_connection_get_failed(void *tls_ctx, struct tls_connection *conn)
Get connection failure status.
Definition: tls_gnutls.c:1460
Definition: tls.h:71
Definition: wpabuf.h:16
int __must_check tls_connection_enable_workaround(void *tls_ctx, struct tls_connection *conn)
Enable TLS workaround options.
Definition: tls_gnutls.c:1443
Definition: tls.h:45
struct wpabuf * tls_connection_encrypt(void *tls_ctx, struct tls_connection *conn, const struct wpabuf *in_data)
Encrypt data into TLS tunnel.
Definition: tls_gnutls.c:1347
struct wpabuf * tls_connection_decrypt(void *tls_ctx, struct tls_connection *conn, const struct wpabuf *in_data)
Decrypt data from TLS tunnel.
Definition: tls_gnutls.c:1368
struct tls_connection * tls_connection_init(void *tls_ctx)
Initialize a new TLS connection.
Definition: tls_gnutls.c:232
void tls_connection_deinit(void *tls_ctx, struct tls_connection *conn)
Free TLS connection data.
Definition: tls_gnutls.c:269
int __must_check tls_connection_prf(void *tls_ctx, struct tls_connection *conn, const char *label, int server_random_first, int skip_keyblock, u8 *out, size_t out_len)
Use TLS-PRF to derive keying material.
Definition: tls_gnutls.c:745
struct wpabuf * tls_connection_server_handshake(void *tls_ctx, struct tls_connection *conn, const struct wpabuf *in_data, struct wpabuf **appl_data)
Process TLS handshake (server side)
Definition: tls_gnutls.c:1338
int __must_check tls_global_set_verify(void *tls_ctx, int check_crl)
Set global certificate verification options.
Definition: tls_gnutls.c:699
int tls_connection_resumed(void *tls_ctx, struct tls_connection *conn)
Was session resumption used.
Definition: tls_gnutls.c:1410
int __must_check tls_connection_set_params(void *tls_ctx, struct tls_connection *conn, const struct tls_connection_params *params)
Set TLS connection parameters.
Definition: tls_gnutls.c:338
int __must_check tls_connection_set_verify(void *tls_ctx, struct tls_connection *conn, int verify_peer, unsigned int flags, const u8 *session_ctx, size_t session_ctx_len)
Set certificate verification options.
Definition: tls_gnutls.c:706
int tls_connection_shutdown(void *tls_ctx, struct tls_connection *conn)
Shutdown TLS connection.
Definition: tls_gnutls.c:291
struct wpabuf * tls_connection_handshake(void *tls_ctx, struct tls_connection *conn, const struct wpabuf *in_data, struct wpabuf **appl_data)
Process TLS handshake (client side)
Definition: tls_gnutls.c:1233
int __must_check tls_connection_set_cipher_list(void *tls_ctx, struct tls_connection *conn, u8 *ciphers)
Configure acceptable cipher suites.
Definition: tls_gnutls.c:1418
int __must_check tls_get_cipher(void *tls_ctx, struct tls_connection *conn, char *buf, size_t buflen)
Get current cipher name.
Definition: tls_gnutls.c:1434
void * tls_init(const struct tls_config *conf)
Initialize TLS library.
Definition: tls_gnutls.c:91
void tls_deinit(void *tls_ctx)
Deinitialize TLS library.
Definition: tls_gnutls.c:125
Definition: tls_gnutls.c:38
int tls_connection_get_read_alerts(void *tls_ctx, struct tls_connection *conn)
Get connection read alert status.
Definition: tls_gnutls.c:1468
int __must_check tls_global_set_params(void *tls_ctx, const struct tls_connection_params *params)
Set TLS parameters for all TLS connection.
Definition: tls_gnutls.c:595
int tls_get_errors(void *tls_ctx)
Process pending errors.
Definition: tls_gnutls.c:141
int tls_connection_get_write_alerts(void *tls_ctx, struct tls_connection *conn)
Get connection write alert status.
Definition: tls_gnutls.c:1476