From b04da8c0066e13249009739d8fb4b1fc314cf49d Mon Sep 17 00:00:00 2001 From: Davide Caratti Date: Fri, 3 Sep 2021 11:57:52 +0200 Subject: [PATCH] fix NetworkManager-CI failures with OpenSSL-3.0.0 Signed-off-by: Davide Caratti --- ...er-Fix-failure-when-using-session-ti.patch | 110 ++++++++++++++++++ ...stemwide-secpolicy-overrides-for-TLS.patch | 66 +++++++++++ ...padding-after-initializing-the-ciphe.patch | 58 +++++++++ ...eprecated-functions-from-des_encrypt.patch | 68 +++++++++++ wpa_supplicant.spec | 11 +- 5 files changed, 312 insertions(+), 1 deletion(-) create mode 100644 0001-EAP-TTLS-PEAP-peer-Fix-failure-when-using-session-ti.patch create mode 100644 0001-OpenSSL-Allow-systemwide-secpolicy-overrides-for-TLS.patch create mode 100644 0001-openssl-Disable-padding-after-initializing-the-ciphe.patch create mode 100644 0001-openssl-Remove-deprecated-functions-from-des_encrypt.patch diff --git a/0001-EAP-TTLS-PEAP-peer-Fix-failure-when-using-session-ti.patch b/0001-EAP-TTLS-PEAP-peer-Fix-failure-when-using-session-ti.patch new file mode 100644 index 0000000..0e94b20 --- /dev/null +++ b/0001-EAP-TTLS-PEAP-peer-Fix-failure-when-using-session-ti.patch @@ -0,0 +1,110 @@ +From 872609c15110d32ee2d306aeeeffdd4e42ef6fc6 Mon Sep 17 00:00:00 2001 +Message-Id: <872609c15110d32ee2d306aeeeffdd4e42ef6fc6.1627507211.git.davide.caratti@gmail.com> +From: Alexander Clouter +Date: Fri, 16 Oct 2020 09:49:36 +0100 +Subject: [PATCH] EAP-TTLS/PEAP peer: Fix failure when using session tickets + under TLS 1.3 + +EAP peer does not expect data present when beginning the Phase 2 in +EAP-{TTLS,PEAP} but in TLS 1.3 session tickets are sent after the +handshake completes. + +There are several strategies that can be used to handle this, but this +patch picks up from the discussion[1] and implements the proposed use of +SSL_MODE_AUTO_RETRY. SSL_MODE_AUTO_RETRY has already been enabled by +default in OpenSSL 1.1.1, but it needs to be enabled for older versions. + +The main OpenSSL wrapper change in tls_connection_decrypt() takes care +of the new possible case with SSL_MODE_AUTO_RETRY for +SSL_ERROR_WANT_READ to indicate that a non-application_data was +processed. That is not really an error case with TLS 1.3, so allow it to +complete and return an empty decrypted application data buffer. +EAP-PEAP/TTLS processing can then use this to move ahead with starting +Phase 2. + +[1] https://www.spinics.net/lists/hostap/msg05376.html + +Signed-off-by: Alexander Clouter +--- + src/crypto/tls_openssl.c | 18 ++++++++++++++---- + src/eap_peer/eap_peap.c | 4 ++++ + src/eap_peer/eap_ttls.c | 5 +++++ + 3 files changed, 23 insertions(+), 4 deletions(-) + +diff --git a/src/crypto/tls_openssl.c b/src/crypto/tls_openssl.c +index ef872c50e..345a35ee1 100644 +--- a/src/crypto/tls_openssl.c ++++ b/src/crypto/tls_openssl.c +@@ -1045,6 +1045,8 @@ void * tls_init(const struct tls_config *conf) + SSL_CTX_set_options(ssl, SSL_OP_NO_SSLv2); + SSL_CTX_set_options(ssl, SSL_OP_NO_SSLv3); + ++ SSL_CTX_set_mode(ssl, SSL_MODE_AUTO_RETRY); ++ + #ifdef SSL_MODE_NO_AUTO_CHAIN + /* Number of deployed use cases assume the default OpenSSL behavior of + * auto chaining the local certificate is in use. BoringSSL removed this +@@ -4543,10 +4545,18 @@ struct wpabuf * tls_connection_decrypt(void *tls_ctx, + return NULL; + res = SSL_read(conn->ssl, wpabuf_mhead(buf), wpabuf_size(buf)); + if (res < 0) { +- tls_show_errors(MSG_INFO, __func__, +- "Decryption failed - SSL_read"); +- wpabuf_free(buf); +- return NULL; ++ int err = SSL_get_error(conn->ssl, res); ++ ++ if (err == SSL_ERROR_WANT_READ) { ++ wpa_printf(MSG_DEBUG, ++ "SSL: SSL_connect - want more data"); ++ res = 0; ++ } else { ++ tls_show_errors(MSG_INFO, __func__, ++ "Decryption failed - SSL_read"); ++ wpabuf_free(buf); ++ return NULL; ++ } + } + wpabuf_put(buf, res); + +diff --git a/src/eap_peer/eap_peap.c b/src/eap_peer/eap_peap.c +index 7c3704369..a13428d37 100644 +--- a/src/eap_peer/eap_peap.c ++++ b/src/eap_peer/eap_peap.c +@@ -803,6 +803,10 @@ static int eap_peap_decrypt(struct eap_sm *sm, struct eap_peap_data *data, + res = eap_peer_tls_decrypt(sm, &data->ssl, in_data, &in_decrypted); + if (res) + return res; ++ if (wpabuf_len(in_decrypted) == 0) { ++ wpabuf_free(in_decrypted); ++ return 1; ++ } + + continue_req: + wpa_hexdump_buf(MSG_DEBUG, "EAP-PEAP: Decrypted Phase 2 EAP", +diff --git a/src/eap_peer/eap_ttls.c b/src/eap_peer/eap_ttls.c +index 642d179c6..3bf1e97e6 100644 +--- a/src/eap_peer/eap_ttls.c ++++ b/src/eap_peer/eap_ttls.c +@@ -1441,6 +1441,7 @@ static int eap_ttls_decrypt(struct eap_sm *sm, struct eap_ttls_data *data, + + if ((in_data == NULL || wpabuf_len(in_data) == 0) && + data->phase2_start) { ++start: + return eap_ttls_phase2_start(sm, data, ret, identifier, + out_data); + } +@@ -1455,6 +1456,10 @@ static int eap_ttls_decrypt(struct eap_sm *sm, struct eap_ttls_data *data, + retval = eap_peer_tls_decrypt(sm, &data->ssl, in_data, &in_decrypted); + if (retval) + goto done; ++ if (wpabuf_len(in_decrypted) == 0) { ++ wpabuf_free(in_decrypted); ++ goto start; ++ } + + continue_req: + data->phase2_start = 0; +-- +2.31.1 + diff --git a/0001-OpenSSL-Allow-systemwide-secpolicy-overrides-for-TLS.patch b/0001-OpenSSL-Allow-systemwide-secpolicy-overrides-for-TLS.patch new file mode 100644 index 0000000..fafabbd --- /dev/null +++ b/0001-OpenSSL-Allow-systemwide-secpolicy-overrides-for-TLS.patch @@ -0,0 +1,66 @@ +From 9afb68b03976d019bb450e5e33b0d8e48867691c Mon Sep 17 00:00:00 2001 +Message-Id: <9afb68b03976d019bb450e5e33b0d8e48867691c.1626202922.git.davide.caratti@gmail.com> +From: Jouni Malinen +Date: Tue, 8 Sep 2020 17:55:36 +0300 +Subject: [PATCH] OpenSSL: Allow systemwide secpolicy overrides for TLS version + +Explicit configuration to enable TLS v1.0 and/or v1.1 did not work with +systemwide OpenSSL secpolicy=2 cases (e.g., Ubuntu 20.04). Allow such +systemwide configuration to be overridden if the older TLS versions have +been explicitly enabled in the network profile. The default behavior +follows the systemwide policy, but this allows compatibility with old +authentication servers without having to touch the systemwide policy. + +Signed-off-by: Jouni Malinen +--- + src/crypto/tls_openssl.c | 26 +++++++++++++++++--------- + 1 file changed, 17 insertions(+), 9 deletions(-) + +diff --git a/src/crypto/tls_openssl.c b/src/crypto/tls_openssl.c +index e73dd7f5b..f7dfecbbf 100644 +--- a/src/crypto/tls_openssl.c ++++ b/src/crypto/tls_openssl.c +@@ -2995,16 +2995,12 @@ static int tls_set_conn_flags(struct tls_connection *conn, unsigned int flags, + + /* Explicit request to enable TLS versions even if needing to + * override systemwide policies. */ +- if (flags & TLS_CONN_ENABLE_TLSv1_0) { ++ if (flags & TLS_CONN_ENABLE_TLSv1_0) + version = TLS1_VERSION; +- } else if (flags & TLS_CONN_ENABLE_TLSv1_1) { +- if (!(flags & TLS_CONN_DISABLE_TLSv1_0)) +- version = TLS1_1_VERSION; +- } else if (flags & TLS_CONN_ENABLE_TLSv1_2) { +- if (!(flags & (TLS_CONN_DISABLE_TLSv1_0 | +- TLS_CONN_DISABLE_TLSv1_1))) +- version = TLS1_2_VERSION; +- } ++ else if (flags & TLS_CONN_ENABLE_TLSv1_1) ++ version = TLS1_1_VERSION; ++ else if (flags & TLS_CONN_ENABLE_TLSv1_2) ++ version = TLS1_2_VERSION; + if (!version) { + wpa_printf(MSG_DEBUG, + "OpenSSL: Invalid TLS version configuration"); +@@ -3018,6 +3014,18 @@ static int tls_set_conn_flags(struct tls_connection *conn, unsigned int flags, + } + } + #endif /* >= 1.1.0 */ ++#if OPENSSL_VERSION_NUMBER >= 0x10100000L && \ ++ !defined(LIBRESSL_VERSION_NUMBER) && \ ++ !defined(OPENSSL_IS_BORINGSSL) ++ if ((flags & (TLS_CONN_ENABLE_TLSv1_0 | TLS_CONN_ENABLE_TLSv1_1)) && ++ SSL_get_security_level(ssl) >= 2) { ++ /* ++ * Need to drop to security level 1 to allow TLS versions older ++ * than 1.2 to be used when explicitly enabled in configuration. ++ */ ++ SSL_set_security_level(conn->ssl, 1); ++ } ++#endif + + #ifdef CONFIG_SUITEB + #ifdef OPENSSL_IS_BORINGSSL +-- +2.31.1 + diff --git a/0001-openssl-Disable-padding-after-initializing-the-ciphe.patch b/0001-openssl-Disable-padding-after-initializing-the-ciphe.patch new file mode 100644 index 0000000..3c1329d --- /dev/null +++ b/0001-openssl-Disable-padding-after-initializing-the-ciphe.patch @@ -0,0 +1,58 @@ +From e2e9adc3d9b6bb9c433ebb6404ee439b42e91746 Mon Sep 17 00:00:00 2001 +Message-Id: +From: Davide Caratti +Date: Tue, 17 Aug 2021 10:58:53 +0200 +Subject: [PATCH] openssl: Disable padding after initializing the cipher suite + +according to OpenSSL documentation [1], EVP_CIPHER_CTX_set_padding() +should be called after EVP_EncryptInit_ex(), EVP_DecryptInit_ex(), or +EVP_CipherInit_ex(). Not doing this causes EVP_CIPHER_CTX_set_padding() +to return false on OpenSSL-3.0.0, resulting in the impossibility to +connect in many scenarios. Fix this changing the order of function calls +where needed. + +[1] https://www.openssl.org/docs/man1.1.1/man3/EVP_CIPHER_CTX_set_padding.html + +Reported-by: Vladimir Benes +Signed-off-by: Davide Caratti +--- + src/crypto/crypto_openssl.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/crypto/crypto_openssl.c b/src/crypto/crypto_openssl.c +index 9411cb9cf..4b87702e4 100644 +--- a/src/crypto/crypto_openssl.c ++++ b/src/crypto/crypto_openssl.c +@@ -248,8 +248,8 @@ int rc4_skip(const u8 *key, size_t keylen, size_t skip, + + ctx = EVP_CIPHER_CTX_new(); + if (!ctx || +- !EVP_CIPHER_CTX_set_padding(ctx, 0) || + !EVP_CipherInit_ex(ctx, EVP_rc4(), NULL, NULL, NULL, 1) || ++ !EVP_CIPHER_CTX_set_padding(ctx, 0) || + !EVP_CIPHER_CTX_set_key_length(ctx, keylen) || + !EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, 1)) + goto out; +@@ -709,8 +709,8 @@ struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg, + } + + if (!(ctx->enc = EVP_CIPHER_CTX_new()) || +- !EVP_CIPHER_CTX_set_padding(ctx->enc, 0) || + !EVP_EncryptInit_ex(ctx->enc, cipher, NULL, NULL, NULL) || ++ !EVP_CIPHER_CTX_set_padding(ctx->enc, 0) || + !EVP_CIPHER_CTX_set_key_length(ctx->enc, key_len) || + !EVP_EncryptInit_ex(ctx->enc, NULL, NULL, key, iv)) { + if (ctx->enc) +@@ -720,8 +720,8 @@ struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg, + } + + if (!(ctx->dec = EVP_CIPHER_CTX_new()) || +- !EVP_CIPHER_CTX_set_padding(ctx->dec, 0) || + !EVP_DecryptInit_ex(ctx->dec, cipher, NULL, NULL, NULL) || ++ !EVP_CIPHER_CTX_set_padding(ctx->dec, 0) || + !EVP_CIPHER_CTX_set_key_length(ctx->dec, key_len) || + !EVP_DecryptInit_ex(ctx->dec, NULL, NULL, key, iv)) { + EVP_CIPHER_CTX_free(ctx->enc); +-- +2.31.1 + diff --git a/0001-openssl-Remove-deprecated-functions-from-des_encrypt.patch b/0001-openssl-Remove-deprecated-functions-from-des_encrypt.patch new file mode 100644 index 0000000..85f1a0a --- /dev/null +++ b/0001-openssl-Remove-deprecated-functions-from-des_encrypt.patch @@ -0,0 +1,68 @@ +From d265dd2d965db3669d07caa69539beb8def0edb2 Mon Sep 17 00:00:00 2001 +Message-Id: +From: Davide Caratti +Date: Tue, 17 Aug 2021 10:58:54 +0200 +Subject: [PATCH] openssl: Remove deprecated functions from des_encrypt() + +NetworkManager-CI detected systematic failures on test scenarios using +MSCHAPv2 when wpa_supplicant uses OpenSSL-3.0.0. +The 'test_module_tests.py' script also fails, and the following log is +shown: + + 1627404013.761569: generate_nt_response failed + 1627404013.761582: ms_funcs: 1 error + +It seems that either DES_set_key() or DES_ecb_encrypt() changed their +semantic, but it doesn't make sense to fix them since their use has been +deprecated. Converting des_encrypt() to avoid use of deprecated +functions proved to fix the problem, and removed a couple of build +warnings at the same time. + +Reported-by: Vladimir Benes +Signed-off-by: Davide Caratti +--- + src/crypto/crypto_openssl.c | 21 +++++++++++++++------ + 1 file changed, 15 insertions(+), 6 deletions(-) + +diff --git a/src/crypto/crypto_openssl.c b/src/crypto/crypto_openssl.c +index a4b1083bb..9411cb9cf 100644 +--- a/src/crypto/crypto_openssl.c ++++ b/src/crypto/crypto_openssl.c +@@ -206,8 +206,8 @@ int md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac) + int des_encrypt(const u8 *clear, const u8 *key, u8 *cypher) + { + u8 pkey[8], next, tmp; +- int i; +- DES_key_schedule ks; ++ int i, plen, ret = -1; ++ EVP_CIPHER_CTX *ctx; + + /* Add parity bits to the key */ + next = 0; +@@ -218,10 +218,19 @@ int des_encrypt(const u8 *clear, const u8 *key, u8 *cypher) + } + pkey[i] = next | 1; + +- DES_set_key((DES_cblock *) &pkey, &ks); +- DES_ecb_encrypt((DES_cblock *) clear, (DES_cblock *) cypher, &ks, +- DES_ENCRYPT); +- return 0; ++ ctx = EVP_CIPHER_CTX_new(); ++ if (ctx && ++ EVP_EncryptInit_ex(ctx, EVP_des_ecb(), NULL, pkey, NULL) == 1 && ++ EVP_CIPHER_CTX_set_padding(ctx, 0) == 1 && ++ EVP_EncryptUpdate(ctx, cypher, &plen, clear, 8) == 1 && ++ EVP_EncryptFinal_ex(ctx, &cypher[plen], &plen) == 1) ++ ret = 0; ++ else ++ wpa_printf(MSG_ERROR, "OpenSSL: DES encrypt failed"); ++ ++ if (ctx) ++ EVP_CIPHER_CTX_free(ctx); ++ return ret; + } + + +-- +2.31.1 + diff --git a/wpa_supplicant.spec b/wpa_supplicant.spec index 13484e4..b87d86b 100644 --- a/wpa_supplicant.spec +++ b/wpa_supplicant.spec @@ -9,7 +9,7 @@ Summary: WPA/WPA2/IEEE 802.1X Supplicant Name: wpa_supplicant Epoch: 1 Version: 2.9 -Release: 14%{?dist} +Release: 15%{?dist} License: BSD Source0: http://w1.fi/releases/%{name}-%{version}.tar.gz Source1: wpa_supplicant.conf @@ -52,6 +52,12 @@ Patch12: 0001-P2P-Fix-a-corner-case-in-peer-addition-based-on-PD-R.patch # fix for 802.11r networks, and cards that don't support it Patch13: 0001-Check-for-FT-support-when-selecting-FT-suites.patch +#fix nmci failures with OpenSSL-3.0.0 +Patch14: 0001-OpenSSL-Allow-systemwide-secpolicy-overrides-for-TLS.patch +Patch15: 0001-EAP-TTLS-PEAP-peer-Fix-failure-when-using-session-ti.patch +Patch16: 0001-openssl-Disable-padding-after-initializing-the-ciphe.patch +Patch17: 0001-openssl-Remove-deprecated-functions-from-des_encrypt.patch + URL: http://w1.fi/wpa_supplicant/ %if %with gui @@ -211,6 +217,9 @@ chmod -R 0644 wpa_supplicant/examples/*.py %changelog +* Fri Sep 9 2021 Davide Caratti - 1:2.9-15 +- Fix NetworkManager-CI failures with OpenSSL 3.0 + * Tue Jul 27 2021 Dave Olsthoorn - 1:2.9-14 - Fix issues with FT a.k.a. 802.11r when not supported by adapter