Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * SSL/TLS interface definition |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3 | * Copyright (c) 2004-2013, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef TLS_H |
| 10 | #define TLS_H |
| 11 | |
| 12 | struct tls_connection; |
| 13 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 14 | struct tls_random { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 15 | const u8 *client_random; |
| 16 | size_t client_random_len; |
| 17 | const u8 *server_random; |
| 18 | size_t server_random_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 19 | }; |
| 20 | |
| 21 | enum tls_event { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 22 | TLS_CERT_CHAIN_SUCCESS, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 23 | TLS_CERT_CHAIN_FAILURE, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 24 | TLS_PEER_CERTIFICATE, |
| 25 | TLS_ALERT |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | /* |
| 29 | * Note: These are used as identifier with external programs and as such, the |
| 30 | * values must not be changed. |
| 31 | */ |
| 32 | enum 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 Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 41 | TLS_FAIL_SERVER_CHAIN_PROBE = 8, |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 42 | TLS_FAIL_DOMAIN_SUFFIX_MISMATCH = 9, |
| 43 | TLS_FAIL_DOMAIN_MISMATCH = 10, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 44 | TLS_FAIL_INSUFFICIENT_KEY_LEN = 11, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 47 | |
| 48 | #define TLS_MAX_ALT_SUBJECT 10 |
| 49 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 50 | union 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 Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 65 | const char *altsubject[TLS_MAX_ALT_SUBJECT]; |
| 66 | int num_altsubject; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 67 | const char *serial_num; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 68 | } peer_cert; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 69 | |
| 70 | struct { |
| 71 | int is_local; |
| 72 | const char *type; |
| 73 | const char *description; |
| 74 | } alert; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | struct tls_config { |
| 78 | const char *opensc_engine_path; |
| 79 | const char *pkcs11_engine_path; |
| 80 | const char *pkcs11_module_path; |
| 81 | int fips_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 82 | int cert_in_cb; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 83 | const char *openssl_ciphers; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 84 | unsigned int tls_session_lifetime; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 85 | unsigned int crl_reload_interval; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 86 | unsigned int tls_flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 87 | |
| 88 | void (*event_cb)(void *ctx, enum tls_event ev, |
| 89 | union tls_event_data *data); |
| 90 | void *cb_ctx; |
| 91 | }; |
| 92 | |
| 93 | #define TLS_CONN_ALLOW_SIGN_RSA_MD5 BIT(0) |
| 94 | #define TLS_CONN_DISABLE_TIME_CHECKS BIT(1) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 95 | #define TLS_CONN_DISABLE_SESSION_TICKET BIT(2) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 96 | #define TLS_CONN_REQUEST_OCSP BIT(3) |
| 97 | #define TLS_CONN_REQUIRE_OCSP BIT(4) |
Dmitry Shmidt | 13ca8d8 | 2014-02-20 10:18:40 -0800 | [diff] [blame] | 98 | #define TLS_CONN_DISABLE_TLSv1_1 BIT(5) |
| 99 | #define TLS_CONN_DISABLE_TLSv1_2 BIT(6) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 100 | #define TLS_CONN_EAP_FAST BIT(7) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 101 | #define TLS_CONN_DISABLE_TLSv1_0 BIT(8) |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 102 | #define TLS_CONN_EXT_CERT_CHECK BIT(9) |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 103 | #define TLS_CONN_REQUIRE_OCSP_ALL BIT(10) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 104 | #define TLS_CONN_SUITEB BIT(11) |
| 105 | #define TLS_CONN_SUITEB_NO_ECDH BIT(12) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 106 | #define TLS_CONN_DISABLE_TLSv1_3 BIT(13) |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 107 | #define TLS_CONN_ENABLE_TLSv1_0 BIT(14) |
| 108 | #define TLS_CONN_ENABLE_TLSv1_1 BIT(15) |
| 109 | #define TLS_CONN_ENABLE_TLSv1_2 BIT(16) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
| 112 | * struct tls_connection_params - Parameters for TLS connection |
| 113 | * @ca_cert: File or reference name for CA X.509 certificate in PEM or DER |
| 114 | * format |
| 115 | * @ca_cert_blob: ca_cert as inlined data or %NULL if not used |
| 116 | * @ca_cert_blob_len: ca_cert_blob length |
| 117 | * @ca_path: Path to CA certificates (OpenSSL specific) |
| 118 | * @subject_match: String to match in the subject of the peer certificate or |
| 119 | * %NULL to allow all subjects |
| 120 | * @altsubject_match: String to match in the alternative subject of the peer |
| 121 | * certificate or %NULL to allow all alternative subjects |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 122 | * @suffix_match: String to suffix match in the dNSName or CN of the peer |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 123 | * certificate or %NULL to allow all domain names. This may allow subdomains an |
| 124 | * wildcard certificates. Each domain name label must have a full match. |
| 125 | * @domain_match: String to match in the dNSName or CN of the peer |
| 126 | * certificate or %NULL to allow all domain names. This requires a full, |
| 127 | * case-insensitive match. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 128 | * @client_cert: File or reference name for client X.509 certificate in PEM or |
| 129 | * DER format |
| 130 | * @client_cert_blob: client_cert as inlined data or %NULL if not used |
| 131 | * @client_cert_blob_len: client_cert_blob length |
| 132 | * @private_key: File or reference name for client private key in PEM or DER |
| 133 | * format (traditional format (RSA PRIVATE KEY) or PKCS#8 (PRIVATE KEY) |
| 134 | * @private_key_blob: private_key as inlined data or %NULL if not used |
| 135 | * @private_key_blob_len: private_key_blob length |
| 136 | * @private_key_passwd: Passphrase for decrypted private key, %NULL if no |
| 137 | * passphrase is used. |
| 138 | * @dh_file: File name for DH/DSA data in PEM format, or %NULL if not used |
| 139 | * @dh_blob: dh_file as inlined data or %NULL if not used |
| 140 | * @dh_blob_len: dh_blob length |
| 141 | * @engine: 1 = use engine (e.g., a smartcard) for private key operations |
| 142 | * (this is OpenSSL specific for now) |
| 143 | * @engine_id: engine id string (this is OpenSSL specific for now) |
| 144 | * @ppin: pointer to the pin variable in the configuration |
| 145 | * (this is OpenSSL specific for now) |
| 146 | * @key_id: the private key's id when using engine (this is OpenSSL |
| 147 | * specific for now) |
| 148 | * @cert_id: the certificate's id when using engine |
| 149 | * @ca_cert_id: the CA certificate's id when using engine |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 150 | * @openssl_ciphers: OpenSSL cipher configuration |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 151 | * @openssl_ecdh_curves: OpenSSL ECDH curve configuration. %NULL for auto if |
| 152 | * supported, empty string to disable, or a colon-separated curve list. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 153 | * @flags: Parameter options (TLS_CONN_*) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 154 | * @ocsp_stapling_response: DER encoded file with cached OCSP stapling response |
| 155 | * or %NULL if OCSP is not enabled |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 156 | * @ocsp_stapling_response_multi: DER encoded file with cached OCSP stapling |
| 157 | * response list (OCSPResponseList for ocsp_multi in RFC 6961) or %NULL if |
| 158 | * ocsp_multi is not enabled |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 159 | * |
| 160 | * TLS connection parameters to be configured with tls_connection_set_params() |
| 161 | * and tls_global_set_params(). |
| 162 | * |
| 163 | * Certificates and private key can be configured either as a reference name |
| 164 | * (file path or reference to certificate store) or by providing the same data |
| 165 | * as a pointer to the data in memory. Only one option will be used for each |
| 166 | * field. |
| 167 | */ |
| 168 | struct tls_connection_params { |
| 169 | const char *ca_cert; |
| 170 | const u8 *ca_cert_blob; |
| 171 | size_t ca_cert_blob_len; |
| 172 | const char *ca_path; |
| 173 | const char *subject_match; |
| 174 | const char *altsubject_match; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 175 | const char *suffix_match; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 176 | const char *domain_match; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 177 | const char *client_cert; |
| 178 | const u8 *client_cert_blob; |
| 179 | size_t client_cert_blob_len; |
| 180 | const char *private_key; |
| 181 | const u8 *private_key_blob; |
| 182 | size_t private_key_blob_len; |
| 183 | const char *private_key_passwd; |
| 184 | const char *dh_file; |
| 185 | const u8 *dh_blob; |
| 186 | size_t dh_blob_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 187 | |
| 188 | /* OpenSSL specific variables */ |
| 189 | int engine; |
| 190 | const char *engine_id; |
| 191 | const char *pin; |
| 192 | const char *key_id; |
| 193 | const char *cert_id; |
| 194 | const char *ca_cert_id; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 195 | const char *openssl_ciphers; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 196 | const char *openssl_ecdh_curves; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 197 | |
| 198 | unsigned int flags; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 199 | const char *ocsp_stapling_response; |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 200 | const char *ocsp_stapling_response_multi; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 201 | }; |
| 202 | |
| 203 | |
| 204 | /** |
| 205 | * tls_init - Initialize TLS library |
| 206 | * @conf: Configuration data for TLS library |
| 207 | * Returns: Context data to be used as tls_ctx in calls to other functions, |
| 208 | * or %NULL on failure. |
| 209 | * |
| 210 | * Called once during program startup and once for each RSN pre-authentication |
| 211 | * session. In other words, there can be two concurrent TLS contexts. If global |
| 212 | * library initialization is needed (i.e., one that is shared between both |
| 213 | * authentication types), the TLS library wrapper should maintain a reference |
| 214 | * counter and do global initialization only when moving from 0 to 1 reference. |
| 215 | */ |
| 216 | void * tls_init(const struct tls_config *conf); |
| 217 | |
| 218 | /** |
| 219 | * tls_deinit - Deinitialize TLS library |
| 220 | * @tls_ctx: TLS context data from tls_init() |
| 221 | * |
| 222 | * Called once during program shutdown and once for each RSN pre-authentication |
| 223 | * session. If global library deinitialization is needed (i.e., one that is |
| 224 | * shared between both authentication types), the TLS library wrapper should |
| 225 | * maintain a reference counter and do global deinitialization only when moving |
| 226 | * from 1 to 0 references. |
| 227 | */ |
| 228 | void tls_deinit(void *tls_ctx); |
| 229 | |
| 230 | /** |
| 231 | * tls_get_errors - Process pending errors |
| 232 | * @tls_ctx: TLS context data from tls_init() |
| 233 | * Returns: Number of found error, 0 if no errors detected. |
| 234 | * |
| 235 | * Process all pending TLS errors. |
| 236 | */ |
| 237 | int tls_get_errors(void *tls_ctx); |
| 238 | |
| 239 | /** |
| 240 | * tls_connection_init - Initialize a new TLS connection |
| 241 | * @tls_ctx: TLS context data from tls_init() |
| 242 | * Returns: Connection context data, conn for other function calls |
| 243 | */ |
| 244 | struct tls_connection * tls_connection_init(void *tls_ctx); |
| 245 | |
| 246 | /** |
| 247 | * tls_connection_deinit - Free TLS connection data |
| 248 | * @tls_ctx: TLS context data from tls_init() |
| 249 | * @conn: Connection context data from tls_connection_init() |
| 250 | * |
| 251 | * Release all resources allocated for TLS connection. |
| 252 | */ |
| 253 | void tls_connection_deinit(void *tls_ctx, struct tls_connection *conn); |
| 254 | |
| 255 | /** |
| 256 | * tls_connection_established - Has the TLS connection been completed? |
| 257 | * @tls_ctx: TLS context data from tls_init() |
| 258 | * @conn: Connection context data from tls_connection_init() |
| 259 | * Returns: 1 if TLS connection has been completed, 0 if not. |
| 260 | */ |
| 261 | int tls_connection_established(void *tls_ctx, struct tls_connection *conn); |
| 262 | |
| 263 | /** |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 264 | * tls_connection_peer_serial_num - Fetch peer certificate serial number |
| 265 | * @tls_ctx: TLS context data from tls_init() |
| 266 | * @conn: Connection context data from tls_connection_init() |
| 267 | * Returns: Allocated string buffer containing the peer certificate serial |
| 268 | * number or %NULL on error. |
| 269 | * |
| 270 | * The caller is responsible for freeing the returned buffer with os_free(). |
| 271 | */ |
| 272 | char * tls_connection_peer_serial_num(void *tls_ctx, |
| 273 | struct tls_connection *conn); |
| 274 | |
| 275 | /** |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 276 | * tls_connection_shutdown - Shutdown TLS connection |
| 277 | * @tls_ctx: TLS context data from tls_init() |
| 278 | * @conn: Connection context data from tls_connection_init() |
| 279 | * Returns: 0 on success, -1 on failure |
| 280 | * |
| 281 | * Shutdown current TLS connection without releasing all resources. New |
| 282 | * connection can be started by using the same conn without having to call |
| 283 | * tls_connection_init() or setting certificates etc. again. The new |
| 284 | * connection should try to use session resumption. |
| 285 | */ |
| 286 | int tls_connection_shutdown(void *tls_ctx, struct tls_connection *conn); |
| 287 | |
| 288 | enum { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 289 | TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN = -4, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 290 | TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED = -3, |
| 291 | TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED = -2 |
| 292 | }; |
| 293 | |
| 294 | /** |
| 295 | * tls_connection_set_params - Set TLS connection parameters |
| 296 | * @tls_ctx: TLS context data from tls_init() |
| 297 | * @conn: Connection context data from tls_connection_init() |
| 298 | * @params: Connection parameters |
| 299 | * Returns: 0 on success, -1 on failure, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 300 | * TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED (-2) on error causing PKCS#11 engine |
| 301 | * failure, or |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 302 | * TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED (-3) on failure to verify the |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 303 | * PKCS#11 engine private key, or |
| 304 | * TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN (-4) on PIN error causing PKCS#11 engine |
| 305 | * failure. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 306 | */ |
| 307 | int __must_check |
| 308 | tls_connection_set_params(void *tls_ctx, struct tls_connection *conn, |
| 309 | const struct tls_connection_params *params); |
| 310 | |
| 311 | /** |
| 312 | * tls_global_set_params - Set TLS parameters for all TLS connection |
| 313 | * @tls_ctx: TLS context data from tls_init() |
| 314 | * @params: Global TLS parameters |
| 315 | * Returns: 0 on success, -1 on failure, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 316 | * TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED (-2) on error causing PKCS#11 engine |
| 317 | * failure, or |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 318 | * TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED (-3) on failure to verify the |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 319 | * PKCS#11 engine private key, or |
| 320 | * TLS_SET_PARAMS_ENGINE_PRV_BAD_PIN (-4) on PIN error causing PKCS#11 engine |
| 321 | * failure. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 322 | */ |
| 323 | int __must_check tls_global_set_params( |
| 324 | void *tls_ctx, const struct tls_connection_params *params); |
| 325 | |
| 326 | /** |
| 327 | * tls_global_set_verify - Set global certificate verification options |
| 328 | * @tls_ctx: TLS context data from tls_init() |
| 329 | * @check_crl: 0 = do not verify CRLs, 1 = verify CRL for the user certificate, |
| 330 | * 2 = verify CRL for all certificates |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 331 | * @strict: 0 = allow CRL time errors, 1 = do not allow CRL time errors |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 332 | * Returns: 0 on success, -1 on failure |
| 333 | */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 334 | int __must_check tls_global_set_verify(void *tls_ctx, int check_crl, |
| 335 | int strict); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 336 | |
| 337 | /** |
| 338 | * tls_connection_set_verify - Set certificate verification options |
| 339 | * @tls_ctx: TLS context data from tls_init() |
| 340 | * @conn: Connection context data from tls_connection_init() |
| 341 | * @verify_peer: 1 = verify peer certificate |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 342 | * @flags: Connection flags (TLS_CONN_*) |
| 343 | * @session_ctx: Session caching context or %NULL to use default |
| 344 | * @session_ctx_len: Length of @session_ctx in bytes. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 345 | * Returns: 0 on success, -1 on failure |
| 346 | */ |
| 347 | int __must_check tls_connection_set_verify(void *tls_ctx, |
| 348 | struct tls_connection *conn, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 349 | int verify_peer, |
| 350 | unsigned int flags, |
| 351 | const u8 *session_ctx, |
| 352 | size_t session_ctx_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 353 | |
| 354 | /** |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 355 | * tls_connection_get_random - Get random data from TLS connection |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 356 | * @tls_ctx: TLS context data from tls_init() |
| 357 | * @conn: Connection context data from tls_connection_init() |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 358 | * @data: Structure of client/server random data (filled on success) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 359 | * Returns: 0 on success, -1 on failure |
| 360 | */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 361 | int __must_check tls_connection_get_random(void *tls_ctx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 362 | struct tls_connection *conn, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 363 | struct tls_random *data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 364 | |
| 365 | /** |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 366 | * tls_connection_export_key - Derive keying material from a TLS connection |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 367 | * @tls_ctx: TLS context data from tls_init() |
| 368 | * @conn: Connection context data from tls_connection_init() |
| 369 | * @label: Label (e.g., description of the key) for PRF |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 370 | * @out: Buffer for output data from TLS-PRF |
| 371 | * @out_len: Length of the output buffer |
| 372 | * Returns: 0 on success, -1 on failure |
| 373 | * |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 374 | * Exports keying material using the mechanism described in RFC 5705. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 375 | */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 376 | int __must_check tls_connection_export_key(void *tls_ctx, |
| 377 | struct tls_connection *conn, |
| 378 | const char *label, |
| 379 | u8 *out, size_t out_len); |
| 380 | |
| 381 | /** |
| 382 | * tls_connection_get_eap_fast_key - Derive key material for EAP-FAST |
| 383 | * @tls_ctx: TLS context data from tls_init() |
| 384 | * @conn: Connection context data from tls_connection_init() |
| 385 | * @out: Buffer for output data from TLS-PRF |
| 386 | * @out_len: Length of the output buffer |
| 387 | * Returns: 0 on success, -1 on failure |
| 388 | * |
| 389 | * Exports key material after the normal TLS key block for use with |
| 390 | * EAP-FAST. Most callers will want tls_connection_export_key(), but EAP-FAST |
| 391 | * uses a different legacy mechanism. |
| 392 | */ |
| 393 | int __must_check tls_connection_get_eap_fast_key(void *tls_ctx, |
| 394 | struct tls_connection *conn, |
| 395 | u8 *out, size_t out_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 396 | |
| 397 | /** |
| 398 | * tls_connection_handshake - Process TLS handshake (client side) |
| 399 | * @tls_ctx: TLS context data from tls_init() |
| 400 | * @conn: Connection context data from tls_connection_init() |
| 401 | * @in_data: Input data from TLS server |
| 402 | * @appl_data: Pointer to application data pointer, or %NULL if dropped |
| 403 | * Returns: Output data, %NULL on failure |
| 404 | * |
| 405 | * The caller is responsible for freeing the returned output data. If the final |
| 406 | * handshake message includes application data, this is decrypted and |
| 407 | * appl_data (if not %NULL) is set to point this data. The caller is |
| 408 | * responsible for freeing appl_data. |
| 409 | * |
| 410 | * This function is used during TLS handshake. The first call is done with |
| 411 | * in_data == %NULL and the library is expected to return ClientHello packet. |
| 412 | * This packet is then send to the server and a response from server is given |
| 413 | * to TLS library by calling this function again with in_data pointing to the |
| 414 | * TLS message from the server. |
| 415 | * |
| 416 | * If the TLS handshake fails, this function may return %NULL. However, if the |
| 417 | * TLS library has a TLS alert to send out, that should be returned as the |
| 418 | * output data. In this case, tls_connection_get_failed() must return failure |
| 419 | * (> 0). |
| 420 | * |
| 421 | * tls_connection_established() should return 1 once the TLS handshake has been |
| 422 | * completed successfully. |
| 423 | */ |
| 424 | struct wpabuf * tls_connection_handshake(void *tls_ctx, |
| 425 | struct tls_connection *conn, |
| 426 | const struct wpabuf *in_data, |
| 427 | struct wpabuf **appl_data); |
| 428 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 429 | struct wpabuf * tls_connection_handshake2(void *tls_ctx, |
| 430 | struct tls_connection *conn, |
| 431 | const struct wpabuf *in_data, |
| 432 | struct wpabuf **appl_data, |
| 433 | int *more_data_needed); |
| 434 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 435 | /** |
| 436 | * tls_connection_server_handshake - Process TLS handshake (server side) |
| 437 | * @tls_ctx: TLS context data from tls_init() |
| 438 | * @conn: Connection context data from tls_connection_init() |
| 439 | * @in_data: Input data from TLS peer |
| 440 | * @appl_data: Pointer to application data pointer, or %NULL if dropped |
| 441 | * Returns: Output data, %NULL on failure |
| 442 | * |
| 443 | * The caller is responsible for freeing the returned output data. |
| 444 | */ |
| 445 | struct wpabuf * tls_connection_server_handshake(void *tls_ctx, |
| 446 | struct tls_connection *conn, |
| 447 | const struct wpabuf *in_data, |
| 448 | struct wpabuf **appl_data); |
| 449 | |
| 450 | /** |
| 451 | * tls_connection_encrypt - Encrypt data into TLS tunnel |
| 452 | * @tls_ctx: TLS context data from tls_init() |
| 453 | * @conn: Connection context data from tls_connection_init() |
| 454 | * @in_data: Plaintext data to be encrypted |
| 455 | * Returns: Encrypted TLS data or %NULL on failure |
| 456 | * |
| 457 | * This function is used after TLS handshake has been completed successfully to |
| 458 | * send data in the encrypted tunnel. The caller is responsible for freeing the |
| 459 | * returned output data. |
| 460 | */ |
| 461 | struct wpabuf * tls_connection_encrypt(void *tls_ctx, |
| 462 | struct tls_connection *conn, |
| 463 | const struct wpabuf *in_data); |
| 464 | |
| 465 | /** |
| 466 | * tls_connection_decrypt - Decrypt data from TLS tunnel |
| 467 | * @tls_ctx: TLS context data from tls_init() |
| 468 | * @conn: Connection context data from tls_connection_init() |
| 469 | * @in_data: Encrypted TLS data |
| 470 | * Returns: Decrypted TLS data or %NULL on failure |
| 471 | * |
| 472 | * This function is used after TLS handshake has been completed successfully to |
| 473 | * receive data from the encrypted tunnel. The caller is responsible for |
| 474 | * freeing the returned output data. |
| 475 | */ |
| 476 | struct wpabuf * tls_connection_decrypt(void *tls_ctx, |
| 477 | struct tls_connection *conn, |
| 478 | const struct wpabuf *in_data); |
| 479 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 480 | struct wpabuf * tls_connection_decrypt2(void *tls_ctx, |
| 481 | struct tls_connection *conn, |
| 482 | const struct wpabuf *in_data, |
| 483 | int *more_data_needed); |
| 484 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 485 | /** |
| 486 | * tls_connection_resumed - Was session resumption used |
| 487 | * @tls_ctx: TLS context data from tls_init() |
| 488 | * @conn: Connection context data from tls_connection_init() |
| 489 | * Returns: 1 if current session used session resumption, 0 if not |
| 490 | */ |
| 491 | int tls_connection_resumed(void *tls_ctx, struct tls_connection *conn); |
| 492 | |
| 493 | enum { |
| 494 | TLS_CIPHER_NONE, |
| 495 | TLS_CIPHER_RC4_SHA /* 0x0005 */, |
| 496 | TLS_CIPHER_AES128_SHA /* 0x002f */, |
| 497 | TLS_CIPHER_RSA_DHE_AES128_SHA /* 0x0031 */, |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 498 | TLS_CIPHER_ANON_DH_AES128_SHA /* 0x0034 */, |
| 499 | TLS_CIPHER_RSA_DHE_AES256_SHA /* 0x0039 */, |
| 500 | TLS_CIPHER_AES256_SHA /* 0x0035 */, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 501 | }; |
| 502 | |
| 503 | /** |
| 504 | * tls_connection_set_cipher_list - Configure acceptable cipher suites |
| 505 | * @tls_ctx: TLS context data from tls_init() |
| 506 | * @conn: Connection context data from tls_connection_init() |
| 507 | * @ciphers: Zero (TLS_CIPHER_NONE) terminated list of allowed ciphers |
| 508 | * (TLS_CIPHER_*). |
| 509 | * Returns: 0 on success, -1 on failure |
| 510 | */ |
| 511 | int __must_check tls_connection_set_cipher_list(void *tls_ctx, |
| 512 | struct tls_connection *conn, |
| 513 | u8 *ciphers); |
| 514 | |
| 515 | /** |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 516 | * tls_get_version - Get the current TLS version number |
| 517 | * @tls_ctx: TLS context data from tls_init() |
| 518 | * @conn: Connection context data from tls_connection_init() |
| 519 | * @buf: Buffer for returning the TLS version number |
| 520 | * @buflen: buf size |
| 521 | * Returns: 0 on success, -1 on failure |
| 522 | * |
| 523 | * Get the currently used TLS version number. |
| 524 | */ |
| 525 | int __must_check tls_get_version(void *tls_ctx, struct tls_connection *conn, |
| 526 | char *buf, size_t buflen); |
| 527 | |
| 528 | /** |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 529 | * tls_get_cipher - Get current cipher name |
| 530 | * @tls_ctx: TLS context data from tls_init() |
| 531 | * @conn: Connection context data from tls_connection_init() |
| 532 | * @buf: Buffer for the cipher name |
| 533 | * @buflen: buf size |
| 534 | * Returns: 0 on success, -1 on failure |
| 535 | * |
| 536 | * Get the name of the currently used cipher. |
| 537 | */ |
| 538 | int __must_check tls_get_cipher(void *tls_ctx, struct tls_connection *conn, |
| 539 | char *buf, size_t buflen); |
| 540 | |
| 541 | /** |
| 542 | * tls_connection_enable_workaround - Enable TLS workaround options |
| 543 | * @tls_ctx: TLS context data from tls_init() |
| 544 | * @conn: Connection context data from tls_connection_init() |
| 545 | * Returns: 0 on success, -1 on failure |
| 546 | * |
| 547 | * This function is used to enable connection-specific workaround options for |
| 548 | * buffer SSL/TLS implementations. |
| 549 | */ |
| 550 | int __must_check tls_connection_enable_workaround(void *tls_ctx, |
| 551 | struct tls_connection *conn); |
| 552 | |
| 553 | /** |
| 554 | * tls_connection_client_hello_ext - Set TLS extension for ClientHello |
| 555 | * @tls_ctx: TLS context data from tls_init() |
| 556 | * @conn: Connection context data from tls_connection_init() |
| 557 | * @ext_type: Extension type |
| 558 | * @data: Extension payload (%NULL to remove extension) |
| 559 | * @data_len: Extension payload length |
| 560 | * Returns: 0 on success, -1 on failure |
| 561 | */ |
| 562 | int __must_check tls_connection_client_hello_ext(void *tls_ctx, |
| 563 | struct tls_connection *conn, |
| 564 | int ext_type, const u8 *data, |
| 565 | size_t data_len); |
| 566 | |
| 567 | /** |
| 568 | * tls_connection_get_failed - Get connection failure status |
| 569 | * @tls_ctx: TLS context data from tls_init() |
| 570 | * @conn: Connection context data from tls_connection_init() |
| 571 | * |
| 572 | * Returns >0 if connection has failed, 0 if not. |
| 573 | */ |
| 574 | int tls_connection_get_failed(void *tls_ctx, struct tls_connection *conn); |
| 575 | |
| 576 | /** |
| 577 | * tls_connection_get_read_alerts - Get connection read alert status |
| 578 | * @tls_ctx: TLS context data from tls_init() |
| 579 | * @conn: Connection context data from tls_connection_init() |
| 580 | * Returns: Number of times a fatal read (remote end reported error) has |
| 581 | * happened during this connection. |
| 582 | */ |
| 583 | int tls_connection_get_read_alerts(void *tls_ctx, struct tls_connection *conn); |
| 584 | |
| 585 | /** |
| 586 | * tls_connection_get_write_alerts - Get connection write alert status |
| 587 | * @tls_ctx: TLS context data from tls_init() |
| 588 | * @conn: Connection context data from tls_connection_init() |
| 589 | * Returns: Number of times a fatal write (locally detected error) has happened |
| 590 | * during this connection. |
| 591 | */ |
| 592 | int tls_connection_get_write_alerts(void *tls_ctx, |
| 593 | struct tls_connection *conn); |
| 594 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 595 | typedef int (*tls_session_ticket_cb) |
| 596 | (void *ctx, const u8 *ticket, size_t len, const u8 *client_random, |
| 597 | const u8 *server_random, u8 *master_secret); |
| 598 | |
| 599 | int __must_check tls_connection_set_session_ticket_cb( |
| 600 | void *tls_ctx, struct tls_connection *conn, |
| 601 | tls_session_ticket_cb cb, void *ctx); |
| 602 | |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 603 | void tls_connection_set_log_cb(struct tls_connection *conn, |
| 604 | void (*log_cb)(void *ctx, const char *msg), |
| 605 | void *ctx); |
| 606 | |
| 607 | #define TLS_BREAK_VERIFY_DATA BIT(0) |
| 608 | #define TLS_BREAK_SRV_KEY_X_HASH BIT(1) |
| 609 | #define TLS_BREAK_SRV_KEY_X_SIGNATURE BIT(2) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 610 | #define TLS_DHE_PRIME_511B BIT(3) |
| 611 | #define TLS_DHE_PRIME_767B BIT(4) |
| 612 | #define TLS_DHE_PRIME_15 BIT(5) |
| 613 | #define TLS_DHE_PRIME_58B BIT(6) |
| 614 | #define TLS_DHE_NON_PRIME BIT(7) |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 615 | |
| 616 | void tls_connection_set_test_flags(struct tls_connection *conn, u32 flags); |
| 617 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 618 | int tls_get_library_version(char *buf, size_t buf_len); |
| 619 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 620 | void tls_connection_set_success_data(struct tls_connection *conn, |
| 621 | struct wpabuf *data); |
| 622 | |
| 623 | void tls_connection_set_success_data_resumed(struct tls_connection *conn); |
| 624 | |
| 625 | const struct wpabuf * |
| 626 | tls_connection_get_success_data(struct tls_connection *conn); |
| 627 | |
| 628 | void tls_connection_remove_session(struct tls_connection *conn); |
| 629 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 630 | #endif /* TLS_H */ |