2 * WPA Supplicant / SSL/TLS interface functions for openssl
3 * Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
17 #ifndef CONFIG_SMARTCARD
18 #ifndef OPENSSL_NO_ENGINE
19 #define OPENSSL_NO_ENGINE
23 #include <openssl/ssl.h>
24 #include <openssl/err.h>
25 #include <openssl/pkcs12.h>
26 #include <openssl/x509v3.h>
27 #ifndef OPENSSL_NO_ENGINE
28 #include <openssl/engine.h>
29 #endif /* OPENSSL_NO_ENGINE */
34 #if OPENSSL_VERSION_NUMBER >= 0x0090800fL
35 #define OPENSSL_d2i_TYPE const unsigned char **
37 #define OPENSSL_d2i_TYPE unsigned char **
40 static int tls_openssl_ref_count = 0;
42 struct tls_connection {
44 BIO *ssl_in, *ssl_out;
45 #ifndef OPENSSL_NO_ENGINE
46 ENGINE *engine; /* functional reference to the engine */
47 EVP_PKEY *private_key; /* the private key if using engine */
48 #endif /* OPENSSL_NO_ENGINE */
49 char *subject_match, *altsubject_match;
50 int read_alerts, write_alerts, failed;
52 tls_session_ticket_cb session_ticket_cb;
53 void *session_ticket_cb_ctx;
55 /* SessionTicket received from OpenSSL hello_extension_cb (server) */
57 size_t session_ticket_len;
61 #ifdef CONFIG_NO_STDOUT_DEBUG
63 static void _tls_show_errors(void)
67 while ((err = ERR_get_error())) {
68 /* Just ignore the errors, since stdout is disabled */
71 #define tls_show_errors(l, f, t) _tls_show_errors()
73 #else /* CONFIG_NO_STDOUT_DEBUG */
75 static void tls_show_errors(int level, const char *func, const char *txt)
79 wpa_printf(level, "OpenSSL: %s - %s %s",
80 func, txt, ERR_error_string(ERR_get_error(), NULL));
82 while ((err = ERR_get_error())) {
83 wpa_printf(MSG_INFO, "OpenSSL: pending error: %s",
84 ERR_error_string(err, NULL));
88 #endif /* CONFIG_NO_STDOUT_DEBUG */
91 #ifdef CONFIG_NATIVE_WINDOWS
93 /* Windows CryptoAPI and access to certificate stores */
96 #ifdef __MINGW32_VERSION
98 * MinGW does not yet include all the needed definitions for CryptoAPI, so
99 * define here whatever extra is needed.
101 #define CALG_SSL3_SHAMD5 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SSL3SHAMD5)
102 #define CERT_SYSTEM_STORE_CURRENT_USER (1 << 16)
103 #define CERT_STORE_READONLY_FLAG 0x00008000
104 #define CERT_STORE_OPEN_EXISTING_FLAG 0x00004000
105 #define CRYPT_ACQUIRE_COMPARE_KEY_FLAG 0x00000004
108 (*CryptAcquireCertificatePrivateKey)(PCCERT_CONTEXT pCert, DWORD dwFlags,
109 void *pvReserved, HCRYPTPROV *phCryptProv,
110 DWORD *pdwKeySpec, BOOL *pfCallerFreeProv)
111 = NULL; /* to be loaded from crypt32.dll */
113 static PCCERT_CONTEXT WINAPI
114 (*CertEnumCertificatesInStore)(HCERTSTORE hCertStore,
115 PCCERT_CONTEXT pPrevCertContext)
116 = NULL; /* to be loaded from crypt32.dll */
118 static int mingw_load_crypto_func(void)
122 /* MinGW does not yet have full CryptoAPI support, so load the needed
125 if (CryptAcquireCertificatePrivateKey)
128 dll = LoadLibrary("crypt32");
130 wpa_printf(MSG_DEBUG, "CryptoAPI: Could not load crypt32 "
135 CryptAcquireCertificatePrivateKey = GetProcAddress(
136 dll, "CryptAcquireCertificatePrivateKey");
137 if (CryptAcquireCertificatePrivateKey == NULL) {
138 wpa_printf(MSG_DEBUG, "CryptoAPI: Could not get "
139 "CryptAcquireCertificatePrivateKey() address from "
144 CertEnumCertificatesInStore = (void *) GetProcAddress(
145 dll, "CertEnumCertificatesInStore");
146 if (CertEnumCertificatesInStore == NULL) {
147 wpa_printf(MSG_DEBUG, "CryptoAPI: Could not get "
148 "CertEnumCertificatesInStore() address from "
156 #else /* __MINGW32_VERSION */
158 static int mingw_load_crypto_func(void)
163 #endif /* __MINGW32_VERSION */
166 struct cryptoapi_rsa_data {
167 const CERT_CONTEXT *cert;
168 HCRYPTPROV crypt_prov;
170 BOOL free_crypt_prov;
174 static void cryptoapi_error(const char *msg)
176 wpa_printf(MSG_INFO, "CryptoAPI: %s; err=%u",
177 msg, (unsigned int) GetLastError());
181 static int cryptoapi_rsa_pub_enc(int flen, const unsigned char *from,
182 unsigned char *to, RSA *rsa, int padding)
184 wpa_printf(MSG_DEBUG, "%s - not implemented", __func__);
189 static int cryptoapi_rsa_pub_dec(int flen, const unsigned char *from,
190 unsigned char *to, RSA *rsa, int padding)
192 wpa_printf(MSG_DEBUG, "%s - not implemented", __func__);
197 static int cryptoapi_rsa_priv_enc(int flen, const unsigned char *from,
198 unsigned char *to, RSA *rsa, int padding)
200 struct cryptoapi_rsa_data *priv =
201 (struct cryptoapi_rsa_data *) rsa->meth->app_data;
203 DWORD hash_size, len, i;
204 unsigned char *buf = NULL;
208 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,
209 ERR_R_PASSED_NULL_PARAMETER);
213 if (padding != RSA_PKCS1_PADDING) {
214 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,
215 RSA_R_UNKNOWN_PADDING_TYPE);
219 if (flen != 16 /* MD5 */ + 20 /* SHA-1 */) {
220 wpa_printf(MSG_INFO, "%s - only MD5-SHA1 hash supported",
222 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,
223 RSA_R_INVALID_MESSAGE_LENGTH);
227 if (!CryptCreateHash(priv->crypt_prov, CALG_SSL3_SHAMD5, 0, 0, &hash))
229 cryptoapi_error("CryptCreateHash failed");
233 len = sizeof(hash_size);
234 if (!CryptGetHashParam(hash, HP_HASHSIZE, (BYTE *) &hash_size, &len,
236 cryptoapi_error("CryptGetHashParam failed");
240 if ((int) hash_size != flen) {
241 wpa_printf(MSG_INFO, "CryptoAPI: Invalid hash size (%u != %d)",
242 (unsigned) hash_size, flen);
243 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,
244 RSA_R_INVALID_MESSAGE_LENGTH);
247 if (!CryptSetHashParam(hash, HP_HASHVAL, (BYTE * ) from, 0)) {
248 cryptoapi_error("CryptSetHashParam failed");
253 buf = os_malloc(len);
255 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE);
259 if (!CryptSignHash(hash, priv->key_spec, NULL, 0, buf, &len)) {
260 cryptoapi_error("CryptSignHash failed");
264 for (i = 0; i < len; i++)
265 to[i] = buf[len - i - 1];
270 CryptDestroyHash(hash);
276 static int cryptoapi_rsa_priv_dec(int flen, const unsigned char *from,
277 unsigned char *to, RSA *rsa, int padding)
279 wpa_printf(MSG_DEBUG, "%s - not implemented", __func__);
284 static void cryptoapi_free_data(struct cryptoapi_rsa_data *priv)
288 if (priv->crypt_prov && priv->free_crypt_prov)
289 CryptReleaseContext(priv->crypt_prov, 0);
291 CertFreeCertificateContext(priv->cert);
296 static int cryptoapi_finish(RSA *rsa)
298 cryptoapi_free_data((struct cryptoapi_rsa_data *) rsa->meth->app_data);
299 os_free((void *) rsa->meth);
305 static const CERT_CONTEXT * cryptoapi_find_cert(const char *name, DWORD store)
308 const CERT_CONTEXT *ret = NULL;
310 cs = CertOpenStore((LPCSTR) CERT_STORE_PROV_SYSTEM, 0, 0,
311 store | CERT_STORE_OPEN_EXISTING_FLAG |
312 CERT_STORE_READONLY_FLAG, L"MY");
314 cryptoapi_error("Failed to open 'My system store'");
318 if (strncmp(name, "cert://", 7) == 0) {
319 unsigned short wbuf[255];
320 MultiByteToWideChar(CP_ACP, 0, name + 7, -1, wbuf, 255);
321 ret = CertFindCertificateInStore(cs, X509_ASN_ENCODING |
323 0, CERT_FIND_SUBJECT_STR,
325 } else if (strncmp(name, "hash://", 7) == 0) {
326 CRYPT_HASH_BLOB blob;
328 const char *hash = name + 7;
331 len = os_strlen(hash) / 2;
332 buf = os_malloc(len);
333 if (buf && hexstr2bin(hash, buf, len) == 0) {
336 ret = CertFindCertificateInStore(cs,
345 CertCloseStore(cs, 0);
351 static int tls_cryptoapi_cert(SSL *ssl, const char *name)
354 RSA *rsa = NULL, *pub_rsa;
355 struct cryptoapi_rsa_data *priv;
356 RSA_METHOD *rsa_meth;
359 (strncmp(name, "cert://", 7) != 0 &&
360 strncmp(name, "hash://", 7) != 0))
363 priv = os_zalloc(sizeof(*priv));
364 rsa_meth = os_zalloc(sizeof(*rsa_meth));
365 if (priv == NULL || rsa_meth == NULL) {
366 wpa_printf(MSG_WARNING, "CryptoAPI: Failed to allocate memory "
367 "for CryptoAPI RSA method");
373 priv->cert = cryptoapi_find_cert(name, CERT_SYSTEM_STORE_CURRENT_USER);
374 if (priv->cert == NULL) {
375 priv->cert = cryptoapi_find_cert(
376 name, CERT_SYSTEM_STORE_LOCAL_MACHINE);
378 if (priv->cert == NULL) {
379 wpa_printf(MSG_INFO, "CryptoAPI: Could not find certificate "
384 cert = d2i_X509(NULL, (OPENSSL_d2i_TYPE) &priv->cert->pbCertEncoded,
385 priv->cert->cbCertEncoded);
387 wpa_printf(MSG_INFO, "CryptoAPI: Could not process X509 DER "
392 if (mingw_load_crypto_func())
395 if (!CryptAcquireCertificatePrivateKey(priv->cert,
396 CRYPT_ACQUIRE_COMPARE_KEY_FLAG,
397 NULL, &priv->crypt_prov,
399 &priv->free_crypt_prov)) {
400 cryptoapi_error("Failed to acquire a private key for the "
405 rsa_meth->name = "Microsoft CryptoAPI RSA Method";
406 rsa_meth->rsa_pub_enc = cryptoapi_rsa_pub_enc;
407 rsa_meth->rsa_pub_dec = cryptoapi_rsa_pub_dec;
408 rsa_meth->rsa_priv_enc = cryptoapi_rsa_priv_enc;
409 rsa_meth->rsa_priv_dec = cryptoapi_rsa_priv_dec;
410 rsa_meth->finish = cryptoapi_finish;
411 rsa_meth->flags = RSA_METHOD_FLAG_NO_CHECK;
412 rsa_meth->app_data = (char *) priv;
416 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,
417 ERR_R_MALLOC_FAILURE);
421 if (!SSL_use_certificate(ssl, cert)) {
426 pub_rsa = cert->cert_info->key->pkey->pkey.rsa;
430 rsa->n = BN_dup(pub_rsa->n);
431 rsa->e = BN_dup(pub_rsa->e);
432 if (!RSA_set_method(rsa, rsa_meth))
435 if (!SSL_use_RSAPrivateKey(ssl, rsa))
448 cryptoapi_free_data(priv);
454 static int tls_cryptoapi_ca_cert(SSL_CTX *ssl_ctx, SSL *ssl, const char *name)
457 PCCERT_CONTEXT ctx = NULL;
465 if (mingw_load_crypto_func())
468 if (name == NULL || strncmp(name, "cert_store://", 13) != 0)
473 wstore = os_malloc((os_strlen(store) + 1) * sizeof(WCHAR));
476 wsprintf(wstore, L"%S", store);
477 cs = CertOpenSystemStore(0, wstore);
480 cs = CertOpenSystemStore(0, store);
483 wpa_printf(MSG_DEBUG, "%s: failed to open system cert store "
484 "'%s': error=%d", __func__, store,
485 (int) GetLastError());
489 while ((ctx = CertEnumCertificatesInStore(cs, ctx))) {
490 cert = d2i_X509(NULL, (OPENSSL_d2i_TYPE) &ctx->pbCertEncoded,
493 wpa_printf(MSG_INFO, "CryptoAPI: Could not process "
494 "X509 DER encoding for CA cert");
498 X509_NAME_oneline(X509_get_subject_name(cert), buf,
500 wpa_printf(MSG_DEBUG, "OpenSSL: Loaded CA certificate for "
501 "system certificate store: subject='%s'", buf);
503 if (!X509_STORE_add_cert(ssl_ctx->cert_store, cert)) {
504 tls_show_errors(MSG_WARNING, __func__,
505 "Failed to add ca_cert to OpenSSL "
506 "certificate store");
512 if (!CertCloseStore(cs, 0)) {
513 wpa_printf(MSG_DEBUG, "%s: failed to close system cert store "
514 "'%s': error=%d", __func__, name + 13,
515 (int) GetLastError());
522 #else /* CONFIG_NATIVE_WINDOWS */
524 static int tls_cryptoapi_cert(SSL *ssl, const char *name)
529 #endif /* CONFIG_NATIVE_WINDOWS */
532 static void ssl_info_cb(const SSL *ssl, int where, int ret)
537 wpa_printf(MSG_DEBUG, "SSL: (where=0x%x ret=0x%x)", where, ret);
538 w = where & ~SSL_ST_MASK;
539 if (w & SSL_ST_CONNECT)
541 else if (w & SSL_ST_ACCEPT)
546 if (where & SSL_CB_LOOP) {
547 wpa_printf(MSG_DEBUG, "SSL: %s:%s",
548 str, SSL_state_string_long(ssl));
549 } else if (where & SSL_CB_ALERT) {
550 wpa_printf(MSG_INFO, "SSL: SSL3 alert: %s:%s:%s",
551 where & SSL_CB_READ ?
552 "read (remote end reported an error)" :
553 "write (local SSL3 detected an error)",
554 SSL_alert_type_string_long(ret),
555 SSL_alert_desc_string_long(ret));
556 if ((ret >> 8) == SSL3_AL_FATAL) {
557 struct tls_connection *conn =
558 SSL_get_app_data((SSL *) ssl);
559 if (where & SSL_CB_READ)
562 conn->write_alerts++;
564 } else if (where & SSL_CB_EXIT && ret <= 0) {
565 wpa_printf(MSG_DEBUG, "SSL: %s:%s in %s",
566 str, ret == 0 ? "failed" : "error",
567 SSL_state_string_long(ssl));
572 #ifndef OPENSSL_NO_ENGINE
574 * tls_engine_load_dynamic_generic - load any openssl engine
575 * @pre: an array of commands and values that load an engine initialized
576 * in the engine specific function
577 * @post: an array of commands and values that initialize an already loaded
578 * engine (or %NULL if not required)
579 * @id: the engine id of the engine to load (only required if post is not %NULL
581 * This function is a generic function that loads any openssl engine.
583 * Returns: 0 on success, -1 on failure
585 static int tls_engine_load_dynamic_generic(const char *pre[],
586 const char *post[], const char *id)
589 const char *dynamic_id = "dynamic";
591 engine = ENGINE_by_id(id);
594 wpa_printf(MSG_DEBUG, "ENGINE: engine '%s' is already "
600 engine = ENGINE_by_id(dynamic_id);
601 if (engine == NULL) {
602 wpa_printf(MSG_INFO, "ENGINE: Can't find engine %s [%s]",
604 ERR_error_string(ERR_get_error(), NULL));
608 /* Perform the pre commands. This will load the engine. */
609 while (pre && pre[0]) {
610 wpa_printf(MSG_DEBUG, "ENGINE: '%s' '%s'", pre[0], pre[1]);
611 if (ENGINE_ctrl_cmd_string(engine, pre[0], pre[1], 0) == 0) {
612 wpa_printf(MSG_INFO, "ENGINE: ctrl cmd_string failed: "
613 "%s %s [%s]", pre[0], pre[1],
614 ERR_error_string(ERR_get_error(), NULL));
622 * Free the reference to the "dynamic" engine. The loaded engine can
623 * now be looked up using ENGINE_by_id().
627 engine = ENGINE_by_id(id);
628 if (engine == NULL) {
629 wpa_printf(MSG_INFO, "ENGINE: Can't find engine %s [%s]",
630 id, ERR_error_string(ERR_get_error(), NULL));
634 while (post && post[0]) {
635 wpa_printf(MSG_DEBUG, "ENGINE: '%s' '%s'", post[0], post[1]);
636 if (ENGINE_ctrl_cmd_string(engine, post[0], post[1], 0) == 0) {
637 wpa_printf(MSG_DEBUG, "ENGINE: ctrl cmd_string failed:"
638 " %s %s [%s]", post[0], post[1],
639 ERR_error_string(ERR_get_error(), NULL));
640 ENGINE_remove(engine);
653 * tls_engine_load_dynamic_pkcs11 - load the pkcs11 engine provided by opensc
654 * @pkcs11_so_path: pksc11_so_path from the configuration
655 * @pcks11_module_path: pkcs11_module_path from the configuration
657 static int tls_engine_load_dynamic_pkcs11(const char *pkcs11_so_path,
658 const char *pkcs11_module_path)
660 char *engine_id = "pkcs11";
661 const char *pre_cmd[] = {
662 "SO_PATH", NULL /* pkcs11_so_path */,
663 "ID", NULL /* engine_id */,
665 /* "NO_VCHECK", "1", */
669 const char *post_cmd[] = {
670 "MODULE_PATH", NULL /* pkcs11_module_path */,
674 if (!pkcs11_so_path || !pkcs11_module_path)
677 pre_cmd[1] = pkcs11_so_path;
678 pre_cmd[3] = engine_id;
679 post_cmd[1] = pkcs11_module_path;
681 wpa_printf(MSG_DEBUG, "ENGINE: Loading pkcs11 Engine from %s",
684 return tls_engine_load_dynamic_generic(pre_cmd, post_cmd, engine_id);
689 * tls_engine_load_dynamic_opensc - load the opensc engine provided by opensc
690 * @opensc_so_path: opensc_so_path from the configuration
692 static int tls_engine_load_dynamic_opensc(const char *opensc_so_path)
694 char *engine_id = "opensc";
695 const char *pre_cmd[] = {
696 "SO_PATH", NULL /* opensc_so_path */,
697 "ID", NULL /* engine_id */,
706 pre_cmd[1] = opensc_so_path;
707 pre_cmd[3] = engine_id;
709 wpa_printf(MSG_DEBUG, "ENGINE: Loading OpenSC Engine from %s",
712 return tls_engine_load_dynamic_generic(pre_cmd, NULL, engine_id);
714 #endif /* OPENSSL_NO_ENGINE */
717 void * tls_init(const struct tls_config *conf)
721 if (tls_openssl_ref_count == 0) {
722 SSL_load_error_strings();
724 /* TODO: if /dev/urandom is available, PRNG is seeded
725 * automatically. If this is not the case, random data should
730 #endif /* PKCS12_FUNCS */
732 tls_openssl_ref_count++;
734 ssl = SSL_CTX_new(TLSv1_method());
738 SSL_CTX_set_info_callback(ssl, ssl_info_cb);
740 #ifndef OPENSSL_NO_ENGINE
742 (conf->opensc_engine_path || conf->pkcs11_engine_path ||
743 conf->pkcs11_module_path)) {
744 wpa_printf(MSG_DEBUG, "ENGINE: Loading dynamic engine");
745 ERR_load_ENGINE_strings();
746 ENGINE_load_dynamic();
748 if (tls_engine_load_dynamic_opensc(conf->opensc_engine_path) ||
749 tls_engine_load_dynamic_pkcs11(conf->pkcs11_engine_path,
750 conf->pkcs11_module_path)) {
755 #endif /* OPENSSL_NO_ENGINE */
761 void tls_deinit(void *ssl_ctx)
763 SSL_CTX *ssl = ssl_ctx;
766 tls_openssl_ref_count--;
767 if (tls_openssl_ref_count == 0) {
768 #ifndef OPENSSL_NO_ENGINE
770 #endif /* OPENSSL_NO_ENGINE */
771 CRYPTO_cleanup_all_ex_data();
779 static int tls_engine_init(struct tls_connection *conn, const char *engine_id,
780 const char *pin, const char *key_id,
781 const char *cert_id, const char *ca_cert_id)
783 #ifndef OPENSSL_NO_ENGINE
785 if (engine_id == NULL) {
786 wpa_printf(MSG_ERROR, "ENGINE: Engine ID not set");
790 wpa_printf(MSG_ERROR, "ENGINE: Smartcard PIN not set");
793 if (key_id == NULL) {
794 wpa_printf(MSG_ERROR, "ENGINE: Key Id not set");
799 conn->engine = ENGINE_by_id(engine_id);
801 wpa_printf(MSG_ERROR, "ENGINE: engine %s not available [%s]",
802 engine_id, ERR_error_string(ERR_get_error(), NULL));
805 if (ENGINE_init(conn->engine) != 1) {
806 wpa_printf(MSG_ERROR, "ENGINE: engine init failed "
807 "(engine: %s) [%s]", engine_id,
808 ERR_error_string(ERR_get_error(), NULL));
811 wpa_printf(MSG_DEBUG, "ENGINE: engine initialized");
813 if (ENGINE_ctrl_cmd_string(conn->engine, "PIN", pin, 0) == 0) {
814 wpa_printf(MSG_ERROR, "ENGINE: cannot set pin [%s]",
815 ERR_error_string(ERR_get_error(), NULL));
818 /* load private key first in-case PIN is required for cert */
819 conn->private_key = ENGINE_load_private_key(conn->engine,
821 if (!conn->private_key) {
822 wpa_printf(MSG_ERROR, "ENGINE: cannot load private key with id"
823 " '%s' [%s]", key_id,
824 ERR_error_string(ERR_get_error(), NULL));
825 ret = TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED;
829 /* handle a certificate and/or CA certificate */
830 if (cert_id || ca_cert_id) {
831 const char *cmd_name = "LOAD_CERT_CTRL";
833 /* test if the engine supports a LOAD_CERT_CTRL */
834 if (!ENGINE_ctrl(conn->engine, ENGINE_CTRL_GET_CMD_FROM_NAME,
835 0, (void *)cmd_name, NULL)) {
836 wpa_printf(MSG_ERROR, "ENGINE: engine does not support"
837 " loading certificates");
838 ret = TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED;
847 ENGINE_free(conn->engine);
851 if (conn->private_key) {
852 EVP_PKEY_free(conn->private_key);
853 conn->private_key = NULL;
857 #else /* OPENSSL_NO_ENGINE */
859 #endif /* OPENSSL_NO_ENGINE */
863 static void tls_engine_deinit(struct tls_connection *conn)
865 #ifndef OPENSSL_NO_ENGINE
866 wpa_printf(MSG_DEBUG, "ENGINE: engine deinit");
867 if (conn->private_key) {
868 EVP_PKEY_free(conn->private_key);
869 conn->private_key = NULL;
872 ENGINE_finish(conn->engine);
875 #endif /* OPENSSL_NO_ENGINE */
879 int tls_get_errors(void *ssl_ctx)
884 while ((err = ERR_get_error())) {
885 wpa_printf(MSG_INFO, "TLS - SSL error: %s",
886 ERR_error_string(err, NULL));
893 struct tls_connection * tls_connection_init(void *ssl_ctx)
895 SSL_CTX *ssl = ssl_ctx;
896 struct tls_connection *conn;
899 conn = os_zalloc(sizeof(*conn));
902 conn->ssl = SSL_new(ssl);
903 if (conn->ssl == NULL) {
904 tls_show_errors(MSG_INFO, __func__,
905 "Failed to initialize new SSL connection");
910 SSL_set_app_data(conn->ssl, conn);
911 options = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 |
912 SSL_OP_SINGLE_DH_USE;
913 #ifdef SSL_OP_NO_COMPRESSION
914 options |= SSL_OP_NO_COMPRESSION;
915 #endif /* SSL_OP_NO_COMPRESSION */
916 SSL_set_options(conn->ssl, options);
918 conn->ssl_in = BIO_new(BIO_s_mem());
920 tls_show_errors(MSG_INFO, __func__,
921 "Failed to create a new BIO for ssl_in");
927 conn->ssl_out = BIO_new(BIO_s_mem());
928 if (!conn->ssl_out) {
929 tls_show_errors(MSG_INFO, __func__,
930 "Failed to create a new BIO for ssl_out");
932 BIO_free(conn->ssl_in);
937 SSL_set_bio(conn->ssl, conn->ssl_in, conn->ssl_out);
943 void tls_connection_deinit(void *ssl_ctx, struct tls_connection *conn)
948 tls_engine_deinit(conn);
949 os_free(conn->subject_match);
950 os_free(conn->altsubject_match);
951 os_free(conn->session_ticket);
956 int tls_connection_established(void *ssl_ctx, struct tls_connection *conn)
958 return conn ? SSL_is_init_finished(conn->ssl) : 0;
962 int tls_connection_shutdown(void *ssl_ctx, struct tls_connection *conn)
967 /* Shutdown previous TLS connection without notifying the peer
968 * because the connection was already terminated in practice
969 * and "close notify" shutdown alert would confuse AS. */
970 SSL_set_quiet_shutdown(conn->ssl, 1);
971 SSL_shutdown(conn->ssl);
976 static int tls_match_altsubject_component(X509 *cert, int type,
977 const char *value, size_t len)
983 ext = X509_get_ext_d2i(cert, NID_subject_alt_name, NULL, NULL);
985 for (i = 0; ext && i < sk_GENERAL_NAME_num(ext); i++) {
986 gen = sk_GENERAL_NAME_value(ext, i);
987 if (gen->type != type)
989 if (os_strlen((char *) gen->d.ia5->data) == len &&
990 os_memcmp(value, gen->d.ia5->data, len) == 0)
998 static int tls_match_altsubject(X509 *cert, const char *match)
1001 const char *pos, *end;
1006 if (os_strncmp(pos, "EMAIL:", 6) == 0) {
1009 } else if (os_strncmp(pos, "DNS:", 4) == 0) {
1012 } else if (os_strncmp(pos, "URI:", 4) == 0) {
1016 wpa_printf(MSG_INFO, "TLS: Invalid altSubjectName "
1020 end = os_strchr(pos, ';');
1022 if (os_strncmp(end + 1, "EMAIL:", 6) == 0 ||
1023 os_strncmp(end + 1, "DNS:", 4) == 0 ||
1024 os_strncmp(end + 1, "URI:", 4) == 0)
1026 end = os_strchr(end + 1, ';');
1031 len = os_strlen(pos);
1032 if (tls_match_altsubject_component(cert, type, pos, len) > 0)
1041 static int tls_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
1047 struct tls_connection *conn;
1048 char *match, *altmatch;
1050 err_cert = X509_STORE_CTX_get_current_cert(x509_ctx);
1051 err = X509_STORE_CTX_get_error(x509_ctx);
1052 depth = X509_STORE_CTX_get_error_depth(x509_ctx);
1053 ssl = X509_STORE_CTX_get_ex_data(x509_ctx,
1054 SSL_get_ex_data_X509_STORE_CTX_idx());
1055 X509_NAME_oneline(X509_get_subject_name(err_cert), buf, sizeof(buf));
1057 conn = SSL_get_app_data(ssl);
1058 match = conn ? conn->subject_match : NULL;
1059 altmatch = conn ? conn->altsubject_match : NULL;
1061 if (!preverify_ok) {
1062 wpa_printf(MSG_WARNING, "TLS: Certificate verification failed,"
1063 " error %d (%s) depth %d for '%s'", err,
1064 X509_verify_cert_error_string(err), depth, buf);
1066 wpa_printf(MSG_DEBUG, "TLS: tls_verify_cb - "
1067 "preverify_ok=%d err=%d (%s) depth=%d buf='%s'",
1069 X509_verify_cert_error_string(err), depth, buf);
1070 if (depth == 0 && match && os_strstr(buf, match) == NULL) {
1071 wpa_printf(MSG_WARNING, "TLS: Subject '%s' did not "
1072 "match with '%s'", buf, match);
1074 } else if (depth == 0 && altmatch &&
1075 !tls_match_altsubject(err_cert, altmatch)) {
1076 wpa_printf(MSG_WARNING, "TLS: altSubjectName match "
1077 "'%s' not found", altmatch);
1082 return preverify_ok;
1086 #ifndef OPENSSL_NO_STDIO
1087 static int tls_load_ca_der(void *_ssl_ctx, const char *ca_cert)
1089 SSL_CTX *ssl_ctx = _ssl_ctx;
1090 X509_LOOKUP *lookup;
1093 lookup = X509_STORE_add_lookup(ssl_ctx->cert_store,
1094 X509_LOOKUP_file());
1095 if (lookup == NULL) {
1096 tls_show_errors(MSG_WARNING, __func__,
1097 "Failed add lookup for X509 store");
1101 if (!X509_LOOKUP_load_file(lookup, ca_cert, X509_FILETYPE_ASN1)) {
1102 unsigned long err = ERR_peek_error();
1103 tls_show_errors(MSG_WARNING, __func__,
1104 "Failed load CA in DER format");
1105 if (ERR_GET_LIB(err) == ERR_LIB_X509 &&
1106 ERR_GET_REASON(err) == X509_R_CERT_ALREADY_IN_HASH_TABLE) {
1107 wpa_printf(MSG_DEBUG, "OpenSSL: %s - ignoring "
1108 "cert already in hash table error",
1116 #endif /* OPENSSL_NO_STDIO */
1119 static int tls_connection_ca_cert(void *_ssl_ctx, struct tls_connection *conn,
1120 const char *ca_cert, const u8 *ca_cert_blob,
1121 size_t ca_cert_blob_len, const char *ca_path)
1123 SSL_CTX *ssl_ctx = _ssl_ctx;
1126 * Remove previously configured trusted CA certificates before adding
1129 X509_STORE_free(ssl_ctx->cert_store);
1130 ssl_ctx->cert_store = X509_STORE_new();
1131 if (ssl_ctx->cert_store == NULL) {
1132 wpa_printf(MSG_DEBUG, "OpenSSL: %s - failed to allocate new "
1133 "certificate store", __func__);
1138 X509 *cert = d2i_X509(NULL, (OPENSSL_d2i_TYPE) &ca_cert_blob,
1141 tls_show_errors(MSG_WARNING, __func__,
1142 "Failed to parse ca_cert_blob");
1146 if (!X509_STORE_add_cert(ssl_ctx->cert_store, cert)) {
1147 unsigned long err = ERR_peek_error();
1148 tls_show_errors(MSG_WARNING, __func__,
1149 "Failed to add ca_cert_blob to "
1150 "certificate store");
1151 if (ERR_GET_LIB(err) == ERR_LIB_X509 &&
1152 ERR_GET_REASON(err) ==
1153 X509_R_CERT_ALREADY_IN_HASH_TABLE) {
1154 wpa_printf(MSG_DEBUG, "OpenSSL: %s - ignoring "
1155 "cert already in hash table error",
1163 wpa_printf(MSG_DEBUG, "OpenSSL: %s - added ca_cert_blob "
1164 "to certificate store", __func__);
1165 SSL_set_verify(conn->ssl, SSL_VERIFY_PEER, tls_verify_cb);
1169 #ifdef CONFIG_NATIVE_WINDOWS
1170 if (ca_cert && tls_cryptoapi_ca_cert(ssl_ctx, conn->ssl, ca_cert) ==
1172 wpa_printf(MSG_DEBUG, "OpenSSL: Added CA certificates from "
1173 "system certificate store");
1174 SSL_set_verify(conn->ssl, SSL_VERIFY_PEER, tls_verify_cb);
1177 #endif /* CONFIG_NATIVE_WINDOWS */
1179 if (ca_cert || ca_path) {
1180 #ifndef OPENSSL_NO_STDIO
1181 if (SSL_CTX_load_verify_locations(ssl_ctx, ca_cert, ca_path) !=
1183 tls_show_errors(MSG_WARNING, __func__,
1184 "Failed to load root certificates");
1186 tls_load_ca_der(ssl_ctx, ca_cert) == 0) {
1187 wpa_printf(MSG_DEBUG, "OpenSSL: %s - loaded "
1188 "DER format CA certificate",
1193 wpa_printf(MSG_DEBUG, "TLS: Trusted root "
1194 "certificate(s) loaded");
1195 tls_get_errors(ssl_ctx);
1197 SSL_set_verify(conn->ssl, SSL_VERIFY_PEER, tls_verify_cb);
1198 #else /* OPENSSL_NO_STDIO */
1199 wpa_printf(MSG_DEBUG, "OpenSSL: %s - OPENSSL_NO_STDIO",
1202 #endif /* OPENSSL_NO_STDIO */
1204 /* No ca_cert configured - do not try to verify server
1206 SSL_set_verify(conn->ssl, SSL_VERIFY_NONE, NULL);
1213 static int tls_global_ca_cert(SSL_CTX *ssl_ctx, const char *ca_cert)
1216 if (SSL_CTX_load_verify_locations(ssl_ctx, ca_cert, NULL) != 1)
1218 tls_show_errors(MSG_WARNING, __func__,
1219 "Failed to load root certificates");
1223 wpa_printf(MSG_DEBUG, "TLS: Trusted root "
1224 "certificate(s) loaded");
1226 #ifndef OPENSSL_NO_STDIO
1227 /* Add the same CAs to the client certificate requests */
1228 SSL_CTX_set_client_CA_list(ssl_ctx,
1229 SSL_load_client_CA_file(ca_cert));
1230 #endif /* OPENSSL_NO_STDIO */
1237 int tls_global_set_verify(void *ssl_ctx, int check_crl)
1242 X509_STORE *cs = SSL_CTX_get_cert_store(ssl_ctx);
1244 tls_show_errors(MSG_INFO, __func__, "Failed to get "
1245 "certificate store when enabling "
1249 flags = X509_V_FLAG_CRL_CHECK;
1251 flags |= X509_V_FLAG_CRL_CHECK_ALL;
1252 X509_STORE_set_flags(cs, flags);
1258 static int tls_connection_set_subject_match(struct tls_connection *conn,
1259 const char *subject_match,
1260 const char *altsubject_match)
1262 os_free(conn->subject_match);
1263 conn->subject_match = NULL;
1264 if (subject_match) {
1265 conn->subject_match = os_strdup(subject_match);
1266 if (conn->subject_match == NULL)
1270 os_free(conn->altsubject_match);
1271 conn->altsubject_match = NULL;
1272 if (altsubject_match) {
1273 conn->altsubject_match = os_strdup(altsubject_match);
1274 if (conn->altsubject_match == NULL)
1282 int tls_connection_set_verify(void *ssl_ctx, struct tls_connection *conn,
1289 SSL_set_verify(conn->ssl, SSL_VERIFY_PEER |
1290 SSL_VERIFY_FAIL_IF_NO_PEER_CERT |
1291 SSL_VERIFY_CLIENT_ONCE, tls_verify_cb);
1293 SSL_set_verify(conn->ssl, SSL_VERIFY_NONE, NULL);
1296 SSL_set_accept_state(conn->ssl);
1302 static int tls_connection_client_cert(struct tls_connection *conn,
1303 const char *client_cert,
1304 const u8 *client_cert_blob,
1305 size_t client_cert_blob_len)
1307 if (client_cert == NULL && client_cert_blob == NULL)
1310 if (client_cert_blob &&
1311 SSL_use_certificate_ASN1(conn->ssl, (u8 *) client_cert_blob,
1312 client_cert_blob_len) == 1) {
1313 wpa_printf(MSG_DEBUG, "OpenSSL: SSL_use_certificate_ASN1 --> "
1316 } else if (client_cert_blob) {
1317 tls_show_errors(MSG_DEBUG, __func__,
1318 "SSL_use_certificate_ASN1 failed");
1321 if (client_cert == NULL)
1324 #ifndef OPENSSL_NO_STDIO
1325 if (SSL_use_certificate_file(conn->ssl, client_cert,
1326 SSL_FILETYPE_ASN1) == 1) {
1327 wpa_printf(MSG_DEBUG, "OpenSSL: SSL_use_certificate_file (DER)"
1331 tls_show_errors(MSG_DEBUG, __func__,
1332 "SSL_use_certificate_file (DER) failed");
1335 if (SSL_use_certificate_file(conn->ssl, client_cert,
1336 SSL_FILETYPE_PEM) == 1) {
1337 wpa_printf(MSG_DEBUG, "OpenSSL: SSL_use_certificate_file (PEM)"
1341 tls_show_errors(MSG_DEBUG, __func__,
1342 "SSL_use_certificate_file (PEM) failed");
1344 #else /* OPENSSL_NO_STDIO */
1345 wpa_printf(MSG_DEBUG, "OpenSSL: %s - OPENSSL_NO_STDIO", __func__);
1346 #endif /* OPENSSL_NO_STDIO */
1352 static int tls_global_client_cert(SSL_CTX *ssl_ctx, const char *client_cert)
1354 #ifndef OPENSSL_NO_STDIO
1355 if (client_cert == NULL)
1358 if (SSL_CTX_use_certificate_file(ssl_ctx, client_cert,
1359 SSL_FILETYPE_ASN1) != 1 &&
1360 SSL_CTX_use_certificate_file(ssl_ctx, client_cert,
1361 SSL_FILETYPE_PEM) != 1) {
1362 tls_show_errors(MSG_INFO, __func__,
1363 "Failed to load client certificate");
1367 #else /* OPENSSL_NO_STDIO */
1368 if (client_cert == NULL)
1370 wpa_printf(MSG_DEBUG, "OpenSSL: %s - OPENSSL_NO_STDIO", __func__);
1372 #endif /* OPENSSL_NO_STDIO */
1376 static int tls_passwd_cb(char *buf, int size, int rwflag, void *password)
1378 if (password == NULL) {
1381 os_strlcpy(buf, (char *) password, size);
1382 return os_strlen(buf);
1387 static int tls_parse_pkcs12(SSL_CTX *ssl_ctx, SSL *ssl, PKCS12 *p12,
1392 STACK_OF(X509) *certs;
1399 if (!PKCS12_parse(p12, passwd, &pkey, &cert, &certs)) {
1400 tls_show_errors(MSG_DEBUG, __func__,
1401 "Failed to parse PKCS12 file");
1405 wpa_printf(MSG_DEBUG, "TLS: Successfully parsed PKCS12 data");
1408 X509_NAME_oneline(X509_get_subject_name(cert), buf,
1410 wpa_printf(MSG_DEBUG, "TLS: Got certificate from PKCS12: "
1411 "subject='%s'", buf);
1413 if (SSL_use_certificate(ssl, cert) != 1)
1416 if (SSL_CTX_use_certificate(ssl_ctx, cert) != 1)
1423 wpa_printf(MSG_DEBUG, "TLS: Got private key from PKCS12");
1425 if (SSL_use_PrivateKey(ssl, pkey) != 1)
1428 if (SSL_CTX_use_PrivateKey(ssl_ctx, pkey) != 1)
1431 EVP_PKEY_free(pkey);
1435 while ((cert = sk_X509_pop(certs)) != NULL) {
1436 X509_NAME_oneline(X509_get_subject_name(cert), buf,
1438 wpa_printf(MSG_DEBUG, "TLS: additional certificate"
1439 " from PKCS12: subject='%s'", buf);
1441 * There is no SSL equivalent for the chain cert - so
1442 * always add it to the context...
1444 if (SSL_CTX_add_extra_chain_cert(ssl_ctx, cert) != 1) {
1449 sk_X509_free(certs);
1455 tls_get_errors(ssl_ctx);
1459 #endif /* PKCS12_FUNCS */
1462 static int tls_read_pkcs12(SSL_CTX *ssl_ctx, SSL *ssl, const char *private_key,
1469 f = fopen(private_key, "rb");
1473 p12 = d2i_PKCS12_fp(f, NULL);
1477 tls_show_errors(MSG_INFO, __func__,
1478 "Failed to use PKCS#12 file");
1482 return tls_parse_pkcs12(ssl_ctx, ssl, p12, passwd);
1484 #else /* PKCS12_FUNCS */
1485 wpa_printf(MSG_INFO, "TLS: PKCS12 support disabled - cannot read "
1488 #endif /* PKCS12_FUNCS */
1492 static int tls_read_pkcs12_blob(SSL_CTX *ssl_ctx, SSL *ssl,
1493 const u8 *blob, size_t len, const char *passwd)
1498 p12 = d2i_PKCS12(NULL, (OPENSSL_d2i_TYPE) &blob, len);
1500 tls_show_errors(MSG_INFO, __func__,
1501 "Failed to use PKCS#12 blob");
1505 return tls_parse_pkcs12(ssl_ctx, ssl, p12, passwd);
1507 #else /* PKCS12_FUNCS */
1508 wpa_printf(MSG_INFO, "TLS: PKCS12 support disabled - cannot parse "
1511 #endif /* PKCS12_FUNCS */
1515 static int tls_engine_get_cert(struct tls_connection *conn,
1516 const char *cert_id,
1519 #ifndef OPENSSL_NO_ENGINE
1520 /* this runs after the private key is loaded so no PIN is required */
1522 const char *cert_id;
1525 params.cert_id = cert_id;
1528 if (!ENGINE_ctrl_cmd(conn->engine, "LOAD_CERT_CTRL",
1529 0, ¶ms, NULL, 1)) {
1530 wpa_printf(MSG_ERROR, "ENGINE: cannot load client cert with id"
1531 " '%s' [%s]", cert_id,
1532 ERR_error_string(ERR_get_error(), NULL));
1533 return TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED;
1536 wpa_printf(MSG_ERROR, "ENGINE: did not properly cert with id"
1538 return TLS_SET_PARAMS_ENGINE_PRV_INIT_FAILED;
1540 *cert = params.cert;
1542 #else /* OPENSSL_NO_ENGINE */
1544 #endif /* OPENSSL_NO_ENGINE */
1548 static int tls_connection_engine_client_cert(struct tls_connection *conn,
1549 const char *cert_id)
1551 #ifndef OPENSSL_NO_ENGINE
1554 if (tls_engine_get_cert(conn, cert_id, &cert))
1557 if (!SSL_use_certificate(conn->ssl, cert)) {
1558 tls_show_errors(MSG_ERROR, __func__,
1559 "SSL_use_certificate failed");
1564 wpa_printf(MSG_DEBUG, "ENGINE: SSL_use_certificate --> "
1568 #else /* OPENSSL_NO_ENGINE */
1570 #endif /* OPENSSL_NO_ENGINE */
1574 static int tls_connection_engine_ca_cert(void *_ssl_ctx,
1575 struct tls_connection *conn,
1576 const char *ca_cert_id)
1578 #ifndef OPENSSL_NO_ENGINE
1580 SSL_CTX *ssl_ctx = _ssl_ctx;
1582 if (tls_engine_get_cert(conn, ca_cert_id, &cert))
1585 /* start off the same as tls_connection_ca_cert */
1586 X509_STORE_free(ssl_ctx->cert_store);
1587 ssl_ctx->cert_store = X509_STORE_new();
1588 if (ssl_ctx->cert_store == NULL) {
1589 wpa_printf(MSG_DEBUG, "OpenSSL: %s - failed to allocate new "
1590 "certificate store", __func__);
1594 if (!X509_STORE_add_cert(ssl_ctx->cert_store, cert)) {
1595 unsigned long err = ERR_peek_error();
1596 tls_show_errors(MSG_WARNING, __func__,
1597 "Failed to add CA certificate from engine "
1598 "to certificate store");
1599 if (ERR_GET_LIB(err) == ERR_LIB_X509 &&
1600 ERR_GET_REASON(err) == X509_R_CERT_ALREADY_IN_HASH_TABLE) {
1601 wpa_printf(MSG_DEBUG, "OpenSSL: %s - ignoring cert"
1602 " already in hash table error",
1610 wpa_printf(MSG_DEBUG, "OpenSSL: %s - added CA certificate from engine "
1611 "to certificate store", __func__);
1612 SSL_set_verify(conn->ssl, SSL_VERIFY_PEER, tls_verify_cb);
1615 #else /* OPENSSL_NO_ENGINE */
1617 #endif /* OPENSSL_NO_ENGINE */
1621 static int tls_connection_engine_private_key(struct tls_connection *conn)
1623 #ifndef OPENSSL_NO_ENGINE
1624 if (SSL_use_PrivateKey(conn->ssl, conn->private_key) != 1) {
1625 tls_show_errors(MSG_ERROR, __func__,
1626 "ENGINE: cannot use private key for TLS");
1629 if (!SSL_check_private_key(conn->ssl)) {
1630 tls_show_errors(MSG_INFO, __func__,
1631 "Private key failed verification");
1635 #else /* OPENSSL_NO_ENGINE */
1636 wpa_printf(MSG_ERROR, "SSL: Configuration uses engine, but "
1637 "engine support was not compiled in");
1639 #endif /* OPENSSL_NO_ENGINE */
1643 static int tls_connection_private_key(void *_ssl_ctx,
1644 struct tls_connection *conn,
1645 const char *private_key,
1646 const char *private_key_passwd,
1647 const u8 *private_key_blob,
1648 size_t private_key_blob_len)
1650 SSL_CTX *ssl_ctx = _ssl_ctx;
1654 if (private_key == NULL && private_key_blob == NULL)
1657 if (private_key_passwd) {
1658 passwd = os_strdup(private_key_passwd);
1664 SSL_CTX_set_default_passwd_cb(ssl_ctx, tls_passwd_cb);
1665 SSL_CTX_set_default_passwd_cb_userdata(ssl_ctx, passwd);
1668 while (private_key_blob) {
1669 if (SSL_use_PrivateKey_ASN1(EVP_PKEY_RSA, conn->ssl,
1670 (u8 *) private_key_blob,
1671 private_key_blob_len) == 1) {
1672 wpa_printf(MSG_DEBUG, "OpenSSL: SSL_use_PrivateKey_"
1673 "ASN1(EVP_PKEY_RSA) --> OK");
1677 tls_show_errors(MSG_DEBUG, __func__,
1678 "SSL_use_PrivateKey_ASN1(EVP_PKEY_RSA)"
1682 if (SSL_use_PrivateKey_ASN1(EVP_PKEY_DSA, conn->ssl,
1683 (u8 *) private_key_blob,
1684 private_key_blob_len) == 1) {
1685 wpa_printf(MSG_DEBUG, "OpenSSL: SSL_use_PrivateKey_"
1686 "ASN1(EVP_PKEY_DSA) --> OK");
1690 tls_show_errors(MSG_DEBUG, __func__,
1691 "SSL_use_PrivateKey_ASN1(EVP_PKEY_DSA)"
1695 if (SSL_use_RSAPrivateKey_ASN1(conn->ssl,
1696 (u8 *) private_key_blob,
1697 private_key_blob_len) == 1) {
1698 wpa_printf(MSG_DEBUG, "OpenSSL: "
1699 "SSL_use_RSAPrivateKey_ASN1 --> OK");
1703 tls_show_errors(MSG_DEBUG, __func__,
1704 "SSL_use_RSAPrivateKey_ASN1 failed");
1707 if (tls_read_pkcs12_blob(ssl_ctx, conn->ssl, private_key_blob,
1708 private_key_blob_len, passwd) == 0) {
1709 wpa_printf(MSG_DEBUG, "OpenSSL: PKCS#12 as blob --> "
1718 while (!ok && private_key) {
1719 #ifndef OPENSSL_NO_STDIO
1720 if (SSL_use_PrivateKey_file(conn->ssl, private_key,
1721 SSL_FILETYPE_ASN1) == 1) {
1722 wpa_printf(MSG_DEBUG, "OpenSSL: "
1723 "SSL_use_PrivateKey_File (DER) --> OK");
1727 tls_show_errors(MSG_DEBUG, __func__,
1728 "SSL_use_PrivateKey_File (DER) "
1732 if (SSL_use_PrivateKey_file(conn->ssl, private_key,
1733 SSL_FILETYPE_PEM) == 1) {
1734 wpa_printf(MSG_DEBUG, "OpenSSL: "
1735 "SSL_use_PrivateKey_File (PEM) --> OK");
1739 tls_show_errors(MSG_DEBUG, __func__,
1740 "SSL_use_PrivateKey_File (PEM) "
1743 #else /* OPENSSL_NO_STDIO */
1744 wpa_printf(MSG_DEBUG, "OpenSSL: %s - OPENSSL_NO_STDIO",
1746 #endif /* OPENSSL_NO_STDIO */
1748 if (tls_read_pkcs12(ssl_ctx, conn->ssl, private_key, passwd)
1750 wpa_printf(MSG_DEBUG, "OpenSSL: Reading PKCS#12 file "
1756 if (tls_cryptoapi_cert(conn->ssl, private_key) == 0) {
1757 wpa_printf(MSG_DEBUG, "OpenSSL: Using CryptoAPI to "
1758 "access certificate store --> OK");
1767 wpa_printf(MSG_INFO, "OpenSSL: Failed to load private key");
1773 SSL_CTX_set_default_passwd_cb(ssl_ctx, NULL);
1776 if (!SSL_check_private_key(conn->ssl)) {
1777 tls_show_errors(MSG_INFO, __func__, "Private key failed "
1782 wpa_printf(MSG_DEBUG, "SSL: Private key loaded successfully");
1787 static int tls_global_private_key(SSL_CTX *ssl_ctx, const char *private_key,
1788 const char *private_key_passwd)
1792 if (private_key == NULL)
1795 if (private_key_passwd) {
1796 passwd = os_strdup(private_key_passwd);
1802 SSL_CTX_set_default_passwd_cb(ssl_ctx, tls_passwd_cb);
1803 SSL_CTX_set_default_passwd_cb_userdata(ssl_ctx, passwd);
1805 #ifndef OPENSSL_NO_STDIO
1806 SSL_CTX_use_PrivateKey_file(ssl_ctx, private_key,
1807 SSL_FILETYPE_ASN1) != 1 &&
1808 SSL_CTX_use_PrivateKey_file(ssl_ctx, private_key,
1809 SSL_FILETYPE_PEM) != 1 &&
1810 #endif /* OPENSSL_NO_STDIO */
1811 tls_read_pkcs12(ssl_ctx, NULL, private_key, passwd)) {
1812 tls_show_errors(MSG_INFO, __func__,
1813 "Failed to load private key");
1820 SSL_CTX_set_default_passwd_cb(ssl_ctx, NULL);
1822 if (!SSL_CTX_check_private_key(ssl_ctx)) {
1823 tls_show_errors(MSG_INFO, __func__,
1824 "Private key failed verification");
1832 static int tls_connection_dh(struct tls_connection *conn, const char *dh_file)
1834 #ifdef OPENSSL_NO_DH
1835 if (dh_file == NULL)
1837 wpa_printf(MSG_ERROR, "TLS: openssl does not include DH support, but "
1838 "dh_file specified");
1840 #else /* OPENSSL_NO_DH */
1844 /* TODO: add support for dh_blob */
1845 if (dh_file == NULL)
1850 bio = BIO_new_file(dh_file, "r");
1852 wpa_printf(MSG_INFO, "TLS: Failed to open DH file '%s': %s",
1853 dh_file, ERR_error_string(ERR_get_error(), NULL));
1856 dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
1858 #ifndef OPENSSL_NO_DSA
1859 while (dh == NULL) {
1861 wpa_printf(MSG_DEBUG, "TLS: Failed to parse DH file '%s': %s -"
1862 " trying to parse as DSA params", dh_file,
1863 ERR_error_string(ERR_get_error(), NULL));
1864 bio = BIO_new_file(dh_file, "r");
1867 dsa = PEM_read_bio_DSAparams(bio, NULL, NULL, NULL);
1870 wpa_printf(MSG_DEBUG, "TLS: Failed to parse DSA file "
1871 "'%s': %s", dh_file,
1872 ERR_error_string(ERR_get_error(), NULL));
1876 wpa_printf(MSG_DEBUG, "TLS: DH file in DSA param format");
1877 dh = DSA_dup_DH(dsa);
1880 wpa_printf(MSG_INFO, "TLS: Failed to convert DSA "
1881 "params into DH params");
1886 #endif /* !OPENSSL_NO_DSA */
1888 wpa_printf(MSG_INFO, "TLS: Failed to read/parse DH/DSA file "
1893 if (SSL_set_tmp_dh(conn->ssl, dh) != 1) {
1894 wpa_printf(MSG_INFO, "TLS: Failed to set DH params from '%s': "
1896 ERR_error_string(ERR_get_error(), NULL));
1902 #endif /* OPENSSL_NO_DH */
1906 static int tls_global_dh(SSL_CTX *ssl_ctx, const char *dh_file)
1908 #ifdef OPENSSL_NO_DH
1909 if (dh_file == NULL)
1911 wpa_printf(MSG_ERROR, "TLS: openssl does not include DH support, but "
1912 "dh_file specified");
1914 #else /* OPENSSL_NO_DH */
1918 /* TODO: add support for dh_blob */
1919 if (dh_file == NULL)
1921 if (ssl_ctx == NULL)
1924 bio = BIO_new_file(dh_file, "r");
1926 wpa_printf(MSG_INFO, "TLS: Failed to open DH file '%s': %s",
1927 dh_file, ERR_error_string(ERR_get_error(), NULL));
1930 dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
1932 #ifndef OPENSSL_NO_DSA
1933 while (dh == NULL) {
1935 wpa_printf(MSG_DEBUG, "TLS: Failed to parse DH file '%s': %s -"
1936 " trying to parse as DSA params", dh_file,
1937 ERR_error_string(ERR_get_error(), NULL));
1938 bio = BIO_new_file(dh_file, "r");
1941 dsa = PEM_read_bio_DSAparams(bio, NULL, NULL, NULL);
1944 wpa_printf(MSG_DEBUG, "TLS: Failed to parse DSA file "
1945 "'%s': %s", dh_file,
1946 ERR_error_string(ERR_get_error(), NULL));
1950 wpa_printf(MSG_DEBUG, "TLS: DH file in DSA param format");
1951 dh = DSA_dup_DH(dsa);
1954 wpa_printf(MSG_INFO, "TLS: Failed to convert DSA "
1955 "params into DH params");
1960 #endif /* !OPENSSL_NO_DSA */
1962 wpa_printf(MSG_INFO, "TLS: Failed to read/parse DH/DSA file "
1967 if (SSL_CTX_set_tmp_dh(ssl_ctx, dh) != 1) {
1968 wpa_printf(MSG_INFO, "TLS: Failed to set DH params from '%s': "
1970 ERR_error_string(ERR_get_error(), NULL));
1976 #endif /* OPENSSL_NO_DH */
1980 int tls_connection_get_keys(void *ssl_ctx, struct tls_connection *conn,
1981 struct tls_keys *keys)
1985 if (conn == NULL || keys == NULL)
1988 if (ssl == NULL || ssl->s3 == NULL || ssl->session == NULL)
1991 os_memset(keys, 0, sizeof(*keys));
1992 keys->master_key = ssl->session->master_key;
1993 keys->master_key_len = ssl->session->master_key_length;
1994 keys->client_random = ssl->s3->client_random;
1995 keys->client_random_len = SSL3_RANDOM_SIZE;
1996 keys->server_random = ssl->s3->server_random;
1997 keys->server_random_len = SSL3_RANDOM_SIZE;
2003 int tls_connection_prf(void *tls_ctx, struct tls_connection *conn,
2004 const char *label, int server_random_first,
2005 u8 *out, size_t out_len)
2011 u8 * tls_connection_handshake(void *ssl_ctx, struct tls_connection *conn,
2012 const u8 *in_data, size_t in_len,
2013 size_t *out_len, u8 **appl_data,
2014 size_t *appl_data_len)
2023 * Give TLS handshake data from the server (if available) to OpenSSL
2027 BIO_write(conn->ssl_in, in_data, in_len) < 0) {
2028 tls_show_errors(MSG_INFO, __func__,
2029 "Handshake failed - BIO_write");
2033 /* Initiate TLS handshake or continue the existing handshake */
2034 res = SSL_connect(conn->ssl);
2036 int err = SSL_get_error(conn->ssl, res);
2037 if (err == SSL_ERROR_WANT_READ)
2038 wpa_printf(MSG_DEBUG, "SSL: SSL_connect - want "
2040 else if (err == SSL_ERROR_WANT_WRITE)
2041 wpa_printf(MSG_DEBUG, "SSL: SSL_connect - want to "
2044 tls_show_errors(MSG_INFO, __func__, "SSL_connect");
2049 /* Get the TLS handshake data to be sent to the server */
2050 res = BIO_ctrl_pending(conn->ssl_out);
2051 wpa_printf(MSG_DEBUG, "SSL: %d bytes pending from ssl_out", res);
2052 out_data = os_malloc(res == 0 ? 1 : res);
2053 if (out_data == NULL) {
2054 wpa_printf(MSG_DEBUG, "SSL: Failed to allocate memory for "
2055 "handshake output (%d bytes)", res);
2056 if (BIO_reset(conn->ssl_out) < 0) {
2057 tls_show_errors(MSG_INFO, __func__,
2058 "BIO_reset failed");
2063 res = res == 0 ? 0 : BIO_read(conn->ssl_out, out_data, res);
2065 tls_show_errors(MSG_INFO, __func__,
2066 "Handshake failed - BIO_read");
2067 if (BIO_reset(conn->ssl_out) < 0) {
2068 tls_show_errors(MSG_INFO, __func__,
2069 "BIO_reset failed");
2076 if (SSL_is_init_finished(conn->ssl) && appl_data) {
2077 *appl_data = os_malloc(in_len);
2079 res = SSL_read(conn->ssl, *appl_data, in_len);
2081 tls_show_errors(MSG_INFO, __func__,
2082 "Failed to read possible "
2083 "Application Data");
2084 os_free(*appl_data);
2087 *appl_data_len = res;
2088 wpa_hexdump_key(MSG_MSGDUMP, "SSL: Application"
2089 " Data in Finish message",
2090 *appl_data, *appl_data_len);
2099 u8 * tls_connection_server_handshake(void *ssl_ctx,
2100 struct tls_connection *conn,
2101 const u8 *in_data, size_t in_len,
2109 BIO_write(conn->ssl_in, in_data, in_len) < 0) {
2110 tls_show_errors(MSG_INFO, __func__,
2111 "Handshake failed - BIO_write");
2115 res = SSL_read(conn->ssl, buf, sizeof(buf));
2117 wpa_printf(MSG_DEBUG, "SSL: Unexpected data from SSL_read "
2121 res = BIO_ctrl_pending(conn->ssl_out);
2122 wpa_printf(MSG_DEBUG, "SSL: %d bytes pending from ssl_out", res);
2123 out_data = os_malloc(res == 0 ? 1 : res);
2124 if (out_data == NULL) {
2125 wpa_printf(MSG_DEBUG, "SSL: Failed to allocate memory for "
2126 "handshake output (%d bytes)", res);
2127 if (BIO_reset(conn->ssl_out) < 0) {
2128 tls_show_errors(MSG_INFO, __func__,
2129 "BIO_reset failed");
2134 res = res == 0 ? 0 : BIO_read(conn->ssl_out, out_data, res);
2136 tls_show_errors(MSG_INFO, __func__,
2137 "Handshake failed - BIO_read");
2138 if (BIO_reset(conn->ssl_out) < 0) {
2139 tls_show_errors(MSG_INFO, __func__,
2140 "BIO_reset failed");
2150 int tls_connection_encrypt(void *ssl_ctx, struct tls_connection *conn,
2151 const u8 *in_data, size_t in_len,
2152 u8 *out_data, size_t out_len)
2159 /* Give plaintext data for OpenSSL to encrypt into the TLS tunnel. */
2160 if ((res = BIO_reset(conn->ssl_in)) < 0 ||
2161 (res = BIO_reset(conn->ssl_out)) < 0) {
2162 tls_show_errors(MSG_INFO, __func__, "BIO_reset failed");
2165 res = SSL_write(conn->ssl, in_data, in_len);
2167 tls_show_errors(MSG_INFO, __func__,
2168 "Encryption failed - SSL_write");
2172 /* Read encrypted data to be sent to the server */
2173 res = BIO_read(conn->ssl_out, out_data, out_len);
2175 tls_show_errors(MSG_INFO, __func__,
2176 "Encryption failed - BIO_read");
2184 int tls_connection_decrypt(void *ssl_ctx, struct tls_connection *conn,
2185 const u8 *in_data, size_t in_len,
2186 u8 *out_data, size_t out_len)
2190 /* Give encrypted data from TLS tunnel for OpenSSL to decrypt. */
2191 res = BIO_write(conn->ssl_in, in_data, in_len);
2193 tls_show_errors(MSG_INFO, __func__,
2194 "Decryption failed - BIO_write");
2197 if (BIO_reset(conn->ssl_out) < 0) {
2198 tls_show_errors(MSG_INFO, __func__, "BIO_reset failed");
2202 /* Read decrypted data for further processing */
2203 res = SSL_read(conn->ssl, out_data, out_len);
2205 tls_show_errors(MSG_INFO, __func__,
2206 "Decryption failed - SSL_read");
2214 int tls_connection_resumed(void *ssl_ctx, struct tls_connection *conn)
2216 return conn ? conn->ssl->hit : 0;
2220 int tls_connection_set_cipher_list(void *tls_ctx, struct tls_connection *conn,
2223 char buf[100], *pos, *end;
2227 if (conn == NULL || conn->ssl == NULL || ciphers == NULL)
2232 end = pos + sizeof(buf);
2235 while (*c != TLS_CIPHER_NONE) {
2239 case TLS_CIPHER_RC4_SHA:
2242 case TLS_CIPHER_AES128_SHA:
2243 suite = "AES128-SHA";
2245 case TLS_CIPHER_RSA_DHE_AES128_SHA:
2246 suite = "DHE-RSA-AES128-SHA";
2248 case TLS_CIPHER_ANON_DH_AES128_SHA:
2249 suite = "ADH-AES128-SHA";
2252 wpa_printf(MSG_DEBUG, "TLS: Unsupported "
2253 "cipher selection: %d", *c);
2256 ret = os_snprintf(pos, end - pos, ":%s", suite);
2257 if (ret < 0 || ret >= end - pos)
2264 wpa_printf(MSG_DEBUG, "OpenSSL: cipher suites: %s", buf + 1);
2266 if (SSL_set_cipher_list(conn->ssl, buf + 1) != 1) {
2267 tls_show_errors(MSG_INFO, __func__,
2268 "Cipher suite configuration failed");
2276 int tls_get_cipher(void *ssl_ctx, struct tls_connection *conn,
2277 char *buf, size_t buflen)
2280 if (conn == NULL || conn->ssl == NULL)
2283 name = SSL_get_cipher(conn->ssl);
2287 os_strlcpy(buf, name, buflen);
2292 int tls_connection_enable_workaround(void *ssl_ctx,
2293 struct tls_connection *conn)
2295 SSL_set_options(conn->ssl, SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS);
2301 #if defined(EAP_FAST) || defined(EAP_FAST_DYNAMIC)
2302 /* ClientHello TLS extensions require a patch to openssl, so this function is
2303 * commented out unless explicitly needed for EAP-FAST in order to be able to
2304 * build this file with unmodified openssl. */
2305 int tls_connection_client_hello_ext(void *ssl_ctx, struct tls_connection *conn,
2306 int ext_type, const u8 *data,
2309 if (conn == NULL || conn->ssl == NULL)
2312 if (SSL_set_hello_extension(conn->ssl, ext_type, (void *) data,
2318 #endif /* EAP_FAST || EAP_FAST_DYNAMIC */
2321 int tls_connection_get_failed(void *ssl_ctx, struct tls_connection *conn)
2325 return conn->failed;
2329 int tls_connection_get_read_alerts(void *ssl_ctx, struct tls_connection *conn)
2333 return conn->read_alerts;
2337 int tls_connection_get_write_alerts(void *ssl_ctx, struct tls_connection *conn)
2341 return conn->write_alerts;
2345 int tls_connection_set_params(void *tls_ctx, struct tls_connection *conn,
2346 const struct tls_connection_params *params)
2354 while ((err = ERR_get_error())) {
2355 wpa_printf(MSG_INFO, "%s: Clearing pending SSL error: %s",
2356 __func__, ERR_error_string(err, NULL));
2359 if (params->engine) {
2360 wpa_printf(MSG_DEBUG, "SSL: Initializing TLS engine");
2361 ret = tls_engine_init(conn, params->engine_id, params->pin,
2362 params->key_id, params->cert_id,
2363 params->ca_cert_id);
2367 if (tls_connection_set_subject_match(conn,
2368 params->subject_match,
2369 params->altsubject_match))
2372 if (params->engine && params->ca_cert_id) {
2373 if (tls_connection_engine_ca_cert(tls_ctx, conn,
2374 params->ca_cert_id))
2375 return TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED;
2376 } else if (tls_connection_ca_cert(tls_ctx, conn, params->ca_cert,
2377 params->ca_cert_blob,
2378 params->ca_cert_blob_len,
2382 if (params->engine && params->cert_id) {
2383 if (tls_connection_engine_client_cert(conn, params->cert_id))
2384 return TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED;
2385 } else if (tls_connection_client_cert(conn, params->client_cert,
2386 params->client_cert_blob,
2387 params->client_cert_blob_len))
2390 if (params->engine && params->key_id) {
2391 wpa_printf(MSG_DEBUG, "TLS: Using private key from engine");
2392 if (tls_connection_engine_private_key(conn))
2393 return TLS_SET_PARAMS_ENGINE_PRV_VERIFY_FAILED;
2394 } else if (tls_connection_private_key(tls_ctx, conn,
2395 params->private_key,
2396 params->private_key_passwd,
2397 params->private_key_blob,
2398 params->private_key_blob_len)) {
2399 wpa_printf(MSG_INFO, "TLS: Failed to load private key '%s'",
2400 params->private_key);
2404 if (tls_connection_dh(conn, params->dh_file)) {
2405 wpa_printf(MSG_INFO, "TLS: Failed to load DH file '%s'",
2410 tls_get_errors(tls_ctx);
2416 int tls_global_set_params(void *tls_ctx,
2417 const struct tls_connection_params *params)
2419 SSL_CTX *ssl_ctx = tls_ctx;
2422 while ((err = ERR_get_error())) {
2423 wpa_printf(MSG_INFO, "%s: Clearing pending SSL error: %s",
2424 __func__, ERR_error_string(err, NULL));
2427 if (tls_global_ca_cert(ssl_ctx, params->ca_cert))
2430 if (tls_global_client_cert(ssl_ctx, params->client_cert))
2433 if (tls_global_private_key(ssl_ctx, params->private_key,
2434 params->private_key_passwd))
2437 if (tls_global_dh(ssl_ctx, params->dh_file)) {
2438 wpa_printf(MSG_INFO, "TLS: Failed to load DH file '%s'",
2447 int tls_connection_get_keyblock_size(void *tls_ctx,
2448 struct tls_connection *conn)
2450 const EVP_CIPHER *c;
2453 if (conn == NULL || conn->ssl == NULL ||
2454 conn->ssl->enc_read_ctx == NULL ||
2455 conn->ssl->enc_read_ctx->cipher == NULL ||
2456 conn->ssl->read_hash == NULL)
2459 c = conn->ssl->enc_read_ctx->cipher;
2460 #if OPENSSL_VERSION_NUMBER >= 0x00909000L
2461 h = EVP_MD_CTX_md(conn->ssl->read_hash);
2463 h = conn->ssl->read_hash;
2466 return 2 * (EVP_CIPHER_key_length(c) +
2468 EVP_CIPHER_iv_length(c));
2472 unsigned int tls_capabilities(void *tls_ctx)
2478 int tls_connection_set_ia(void *tls_ctx, struct tls_connection *conn,
2485 int tls_connection_ia_send_phase_finished(void *tls_ctx,
2486 struct tls_connection *conn,
2488 u8 *out_data, size_t out_len)
2494 int tls_connection_ia_final_phase_finished(void *tls_ctx,
2495 struct tls_connection *conn)
2501 int tls_connection_ia_permute_inner_secret(void *tls_ctx,
2502 struct tls_connection *conn,
2503 const u8 *key, size_t key_len)
2509 #if defined(EAP_FAST) || defined(EAP_FAST_DYNAMIC)
2510 /* Pre-shared secred requires a patch to openssl, so this function is
2511 * commented out unless explicitly needed for EAP-FAST in order to be able to
2512 * build this file with unmodified openssl. */
2514 static int tls_sess_sec_cb(SSL *s, void *secret, int *secret_len,
2515 STACK_OF(SSL_CIPHER) *peer_ciphers,
2516 SSL_CIPHER **cipher, void *arg)
2518 struct tls_connection *conn = arg;
2521 if (conn == NULL || conn->session_ticket_cb == NULL)
2524 ret = conn->session_ticket_cb(conn->session_ticket_cb_ctx,
2525 conn->session_ticket,
2526 conn->session_ticket_len,
2527 s->s3->client_random,
2528 s->s3->server_random, secret);
2529 os_free(conn->session_ticket);
2530 conn->session_ticket = NULL;
2535 *secret_len = SSL_MAX_MASTER_KEY_LENGTH;
2540 #ifdef SSL_OP_NO_TICKET
2541 static void tls_hello_ext_cb(SSL *s, int client_server, int type,
2542 unsigned char *data, int len, void *arg)
2544 struct tls_connection *conn = arg;
2546 if (conn == NULL || conn->session_ticket_cb == NULL)
2549 wpa_printf(MSG_DEBUG, "OpenSSL: %s: type=%d length=%d", __func__,
2552 if (type == TLSEXT_TYPE_session_ticket && !client_server) {
2553 os_free(conn->session_ticket);
2554 conn->session_ticket = NULL;
2556 wpa_hexdump(MSG_DEBUG, "OpenSSL: ClientHello SessionTicket "
2557 "extension", data, len);
2558 conn->session_ticket = os_malloc(len);
2559 if (conn->session_ticket == NULL)
2562 os_memcpy(conn->session_ticket, data, len);
2563 conn->session_ticket_len = len;
2566 #else /* SSL_OP_NO_TICKET */
2567 static int tls_hello_ext_cb(SSL *s, TLS_EXTENSION *ext, void *arg)
2569 struct tls_connection *conn = arg;
2571 if (conn == NULL || conn->session_ticket_cb == NULL)
2574 wpa_printf(MSG_DEBUG, "OpenSSL: %s: type=%d length=%d", __func__,
2575 ext->type, ext->length);
2577 os_free(conn->session_ticket);
2578 conn->session_ticket = NULL;
2580 if (ext->type == 35) {
2581 wpa_hexdump(MSG_DEBUG, "OpenSSL: ClientHello SessionTicket "
2582 "extension", ext->data, ext->length);
2583 conn->session_ticket = os_malloc(ext->length);
2584 if (conn->session_ticket == NULL)
2585 return SSL_AD_INTERNAL_ERROR;
2587 os_memcpy(conn->session_ticket, ext->data, ext->length);
2588 conn->session_ticket_len = ext->length;
2593 #endif /* SSL_OP_NO_TICKET */
2594 #endif /* EAP_FAST || EAP_FAST_DYNAMIC */
2597 int tls_connection_set_session_ticket_cb(void *tls_ctx,
2598 struct tls_connection *conn,
2599 tls_session_ticket_cb cb,
2602 #if defined(EAP_FAST) || defined(EAP_FAST_DYNAMIC)
2603 conn->session_ticket_cb = cb;
2604 conn->session_ticket_cb_ctx = ctx;
2607 if (SSL_set_session_secret_cb(conn->ssl, tls_sess_sec_cb,
2610 #ifdef SSL_OP_NO_TICKET
2611 SSL_set_tlsext_debug_callback(conn->ssl, tls_hello_ext_cb);
2612 SSL_set_tlsext_debug_arg(conn->ssl, conn);
2613 #else /* SSL_OP_NO_TICKET */
2614 if (SSL_set_hello_extension_cb(conn->ssl, tls_hello_ext_cb,
2617 #endif /* SSL_OP_NO_TICKET */
2619 if (SSL_set_session_secret_cb(conn->ssl, NULL, NULL) != 1)
2621 #ifdef SSL_OP_NO_TICKET
2622 SSL_set_tlsext_debug_callback(conn->ssl, NULL);
2623 SSL_set_tlsext_debug_arg(conn->ssl, conn);
2624 #else /* SSL_OP_NO_TICKET */
2625 if (SSL_set_hello_extension_cb(conn->ssl, NULL, NULL) != 1)
2627 #endif /* SSL_OP_NO_TICKET */
2631 #else /* EAP_FAST || EAP_FAST_DYNAMIC */
2633 #endif /* EAP_FAST || EAP_FAST_DYNAMIC */