OpenSSL 3.0 improvements for OpenVPN
v3 cover OpenSSL 3.0 improvements for OpenVPN
This patchset removes almost all deprecation warnings from OpenVPN that related to OpenSSL 3.0. The patchset has already been tested with users and OpenSSL 3.0 as part of my OpenVPN for Android client.
Some patches also improve interaction with new features of OpenSSL 3.0, mainly with providers.
The patchset does not address using a provider to replace the RSA_method/EC_method. This is a separate patchset currently prepared by Selva.
Arne Schwabe (21):
[OSSL 3.0] Use new EVP_MAC API for HMAC implementation [OSSL 3.0] Add --with-openssl-engine autoconf option (auto|yes|no) [OSSL 3.0] Implement DES ECB encrypt via EVP_CIPHER api [OSSL 3.0] Remove DES check with OpenSSL 3.0
[OSSL 3.0] Use EVP_PKEY based API for loading DH keys [OSSL 3.0] Deprecate --ecdh-curve with OpenSSL 3.0 and adjust mbed TLS
message
[OSSL 3.0] Remove DES key fixup code
[OSSL 3.0] Use EVP_PKEY_get_group_name to query group name Refactor early initialisation and uninitialisation into methods [OSSL 3.0] Replace EVP_get_cipherbyname with EVP_CIPHER_fetch [OSSL 3.0] USe EVP_MD_get0_name instead EV_MD_name
[OSSL 3.0] Allow loading of non default providers
[OSSL 3.0] Remove dependency on BF-CBC existance from test_ncp [OSSL 3.0] Use TYPE_do_all_provided function for listing cipher/digest [OSSL 3.0] Do not allow CTS ciphers
Add message when decoding PKCS12 file fails.
Add small unit test for testing HMAC
Fix error when BF-CBC is not available
Add insecure tls-cert-profile options
Add macos OpenSSL 3.0 and ASAN builds
Always use 8192 bytes for ERR_BUF_SIZE
.github/workflows/build.yaml | 28 ++- configure.ac | 68 ++++-- doc/man-sections/generic-options.rst | 10 + doc/man-sections/tls-options.rst | 6 + src/openvpn/crypto.c | 46 ---- src/openvpn/crypto.h | 2 - src/openvpn/crypto_backend.h | 18 +- src/openvpn/crypto_mbedtls.c | 34 +-- src/openvpn/crypto_openssl.c | 288 +++++++++++++++++++------ src/openvpn/crypto_openssl.h | 8 + src/openvpn/error.h | 6 +- src/openvpn/ntlm.c | 1 - src/openvpn/openssl_compat.h | 61 ++++++ src/openvpn/openvpn.c | 27 ++- src/openvpn/options.c | 7 + src/openvpn/options.h | 1 + src/openvpn/ssl.c | 18 -- src/openvpn/ssl_mbedtls.c | 8 +- src/openvpn/ssl_openssl.c | 57 +++-- tests/unit_tests/openvpn/test_crypto.c | 61 +++++- tests/unit_tests/openvpn/test_ncp.c | 13 +- 21 files changed, 541 insertions(+), 227 deletions(-)
Signature · 1 line
2.33.0
PATCH v3 1/21 Use new EVP_MAC API for HMAC implementation
The old API is deprecated in OpenSSL 3.0 and the new API does not yet exist in OpenSSL 1.1. Emulating the new API would be more complex than just having two implementations. So this switches to a new hmac implementation for OpenSSL 3.0.
Unfortunately the new API does not have an easy to reset an HMAC, so we need to keep the key around to emulate a reset functionality.
--- src/openvpn/crypto_backend.h | 2 +- src/openvpn/crypto_mbedtls.c | 2 +- src/openvpn/crypto_openssl.c | 96 +++++++++++++++++++++++++++++++++++- src/openvpn/crypto_openssl.h | 8 +++ 4 files changed, 104 insertions(+), 4 deletions(-)
src/openvpn/crypto_backend.h +1 -1
@@ -643,7 +643,7 @@ void hmac_ctx_cleanup(hmac_ctx_t *ctx);* * @return Size of the HMAC, or \0 if ctx is NULL. */ -int hmac_ctx_size (const hmac_ctx_t *ctx); +int hmac_ctx_size (hmac_ctx_t *ctx);/* * Resets the given HMAC context, preserving the associated key information
src/openvpn/crypto_mbedtls.c +1 -1
@@ -939,7 +939,7 @@ hmac_ctx_cleanup(mbedtls_md_context_t *ctx) }int -hmac_ctx_size (const mbedtls_md_context_t *ctx) +hmac_ctx_size (mbedtls_md_context_t *ctx) {if (NULL == ctx) {
src/openvpn/crypto_openssl.c +94 -2
114 lines not on this page · raw message
src/openvpn/crypto_openssl.h +8 -0
@@ -47,7 +47,15 @@ typedef EVP_CIPHER_CTX cipher_ctx_t;typedef EVP_MD_CTX md_ctx_t ;/** Generic HMAC %context. */ +#if OPENSSL_VERSION_NUMBER <0x30000000L typedef HMAC_CTX hmac_ctx_t ; +#else +typedef struct { +OSSL_PARAM params[3 ]; +uint8_t key[EVP_MAX_KEY_LENGTH ]; +EVP_MAC_CTX *ctx; +}hmac_ctx_t ; +#endif /** Maximum length of an IV */ #define OPENVPN_MAX_IV_LENGTH EVP_MAX_IV_LENGTH
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 01/21] [OSSL 3.0] Use new EVP_MAC API for HMAC implementation
Quoted 9 lines · Arne Schwabe
The old API is deprecated in OpenSSL 3.0 and the new API does not yet exist in OpenSSL 1.1. Emulating the new API would be more complex than just having two implementations. So this switches to a new hmac implementation for OpenSSL 3.0.
Unfortunately the new API does not have an easy to reset an HMAC, so we need to keep the key around to emulate a reset functionality.
Signed-off-by Arne Schwabe <[email protected]...>
Looked at the code, compiled with OpenSSL 3.1.0 and 1.1.1, and ran --test-crypto for both.
Small typo in commit message: "does not have an easy to reset", probably should be "easy way to reset".
[Openvpn-devel] [PATCH applied] Re: Use new EVP_MAC API for HMAC implementation
In reply to Arne SchwabeI have lightly tested this ("make check" on 1.1.1 and 3.0.0 builds) and it seems to do nicely. Especially that we already merged the HMAC test (unit_tests/test_crypto.c) gives confidence :-)
Your patch has been applied to the master branch.
commit 7865ffdcbc603894f268d892d638b111e8b61c36
Author: Arne Schwabe Date: Tue Oct 19 20:31:07 2021 +0200
Use new EVP_MAC API for HMAC implementation
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Max Fillinger <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23013.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 2/21 Add --with-openssl-engine autoconf option (auto|yes|no)
In reply to Arne SchwabeThis allows to select engine support at configure time. For OpenSSL 1.1 the default is not changed and we detect if engine support is available.
Engine support is deprecated in OpenSSL 3.0 and for OpenSSL 3.0 the default is to disable engine support as engine support is deprecated and generates compiler warnings which in turn also break -Werror.
By using --with-openssl-engine=no or --with-openssl-engine=yes engine support can be forced on or off. If it is enabled but not detected an error will be thown.
This commit cleans up the configurelogic a bit and removes the ENGINE_cleanup checks as we can just assume that it will be also available as macro or function if the other engine functions are available. Before the cleanup we would only check for the existance of engine.h if ENGINE_cleanup was not found.
--- configure.ac | 68 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 17 deletions(-)
configure.ac +51 -17
@@ -267,6 +267,18 @@ AC_ARG_ENABLE( [enable_wolfssl_options_h="yes"] ) +AC_ARG_WITH( + [openssl-engine], + [AS_HELP_STRING([--with-openssl-engine], [enable engine support with OpenSSL. Default enabled for OpenSSL < 3.0, auto,yes,no @<:@default=auto@:>@])], + [ + case "${withval}" in + auto|yes|no) ;; + *) AC_MSG_ERROR([bad value ${withval} for --with-engine]) ;; + esac + ], + [with_openssl_engine="auto"] +) + AC_ARG_VAR([PLUGINDIR], [Path of plug-in directory @<:@default=LIBDIR/openvpn/plugins@:>@]) if test -n "${PLUGINDIR}"; then plugindir="${PLUGINDIR}"
@@ -800,23 +812,45 @@ if test "${with_crypto_library}" = "openssl"; then [AC_MSG_ERROR([openssl check failed])] ) - have_openssl_engine="yes" - AC_CHECK_FUNCS( - [ \ - ENGINE_load_builtin_engines \ - ENGINE_register_all_complete \ - ENGINE_cleanup \ - ], - , - [have_openssl_engine="no"; break] - ) - if test "${have_openssl_engine}" = "no"; then - AC_CHECK_DECL( [ENGINE_cleanup], [have_openssl_engine="yes"],, - [[ - #include <openssl/engine.h> - ]] - ) - fi + if test "${with_openssl_engine}" = "auto"; then + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ + #include <openssl/opensslv.h> + ]], + [[ + /* Version encoding: MNNFFPPS - see opensslv.h for details */ + #if OPENSSL_VERSION_NUMBER >= 0x30000000L + #error Engine supported disabled by default in OpenSSL 3.0+ + #endif + ]] + )], + [have_openssl_engine="yes"], + [have_openssl_engine="no"] + ) + if test "${have_openssl_engine}" = "yes"; then + AC_CHECK_FUNCS( + [ \ + ENGINE_load_builtin_engines \ + ENGINE_register_all_complete \ + ], + , + [have_openssl_engine="no"; break] + ) + fi + else + have_openssl_engine="${with_openssl_engine}" + if test "${have_openssl_engine}" = "yes"; then + AC_CHECK_FUNCS( + [ \ + ENGINE_load_builtin_engines \ + ENGINE_register_all_complete \ + ], + , + [AC_MSG_ERROR([OpenSSL engine support not found])] + ) + fi + fi if test "${have_openssl_engine}" = "yes"; then AC_DEFINE([HAVE_OPENSSL_ENGINE], [1], [OpenSSL engine support available]) fi
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 02/21] [OSSL 3.0] Add --with-openssl-engine autoconf option (auto|yes|no)
Quoted 11 lines · Arne Schwabe
This allows to select engine support at configure time. For OpenSSL 1.1 the default is not changed and we detect if engine support is available.
Engine support is deprecated in OpenSSL 3.0 and for OpenSSL 3.0 the default is to disable engine support as engine support is deprecated and generates compiler warnings which in turn also break -Werror.
By using --with-openssl-engine=no or --with-openssl-engine=yes engine support can be forced on or off. If it is enabled but not detected an error will be thown.
Quoted 6 lines
This commit cleans up the configurelogic a bit and removes the
ENGINE_cleanupchecks as we can just assume that it will be also available as macro or function if the other engine functions are available. Before the cleanup we would only check for the existance ofengine.hifENGINE_cleanupwas not found.Signed-off-by Arne Schwabe <[email protected]...>
Looks good to me. My one nitpick is that the part below uses a mix of spaces and tabs for indentation. But the entire file doesn't seem terribly consistent about that.
Quoted 43 lines
configure.ac +39
-0+ if test "${with_openssl_engine}" = "auto"; then + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ + #include <openssl/opensslv.h> + ]], + [[ + /* Version encoding: MNNFFPPS - see opensslv.h for details */ + #if OPENSSL_VERSION_NUMBER >= 0x30000000L + #error Engine supported disabled by default in OpenSSL 3.0+ + #endif + ]] + )], + [have_openssl_engine="yes"], + [have_openssl_engine="no"] + ) + if test "${have_openssl_engine}" = "yes"; then + AC_CHECK_FUNCS( + [ \ + ENGINE_load_builtin_engines \ + ENGINE_register_all_complete \ + ], + , + [have_openssl_engine="no"; break] + ) + fi + else + have_openssl_engine="${with_openssl_engine}" + if test "${have_openssl_engine}" = "yes"; then + AC_CHECK_FUNCS( + [ \ + ENGINE_load_builtin_engines \ + ENGINE_register_all_complete \ + ], + , + [AC_MSG_ERROR([OpenSSL engine support not found])] + ) + fi + fi if test "${have_openssl_engine}" = "yes"; then AC_DEFINE([HAVE_OPENSSL_ENGINE], [1], [OpenSSL engine support available]) fi
[Openvpn-devel] [PATCH applied] Re: Add --with-openssl-engine autoconf option (auto|yes|no)
In reply to Arne SchwabeI have reformatted the indentation (your editor seems to have played tricks with you, since configure.ac actually uses tabs, which the rest doesn't...). Tested on 3.0.0 and 1.1.1 builds.
3.0.0 does not report anything about "engine support" in the configure output, which we might want to extend a bit ("checking for openssl engine support... no" or such), but config.log and config.h show that it disabled things properly.
.. which makes "make check" much more happy, as it does no longer try to build and run the libengine test, which always failed before (with 3.0.0) - yay :-)
Your patch has been applied to the master branch.
commit 75fb5e1215f125a2ce472e10ae75b507262429b9
Author: Arne Schwabe Date: Tue Oct 19 20:31:08 2021 +0200
Add --with-openssl-engine autoconf option (auto|yes|no)
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Max Fillinger <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23000.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 3/21 Implement DES ECB encrypt via EVP_CIPHER api
In reply to Arne SchwabeEven though DES is super outdated and also NTLM is super outdated, eliminating the warnings for OpenSSL 3.0 is still a step in the right direction and using the correct APIs.
--- src/openvpn/crypto_openssl.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
src/openvpn/crypto_openssl.c +19 -3
@@ -879,10 +879,26 @@ cipher_des_encrypt_ecb(const unsigned char key[DES_KEY_LENGTH], unsigned char src[DES_KEY_LENGTH], unsigned char dst[DES_KEY_LENGTH]) { -DES_key_schedule sched; +EVP_CIPHER_CTX *ctx =EVP_CIPHER_CTX_new (); +if (!ctx) + { +crypto_msg (M_FATAL ,"%s: EVP_CIPHER_CTX_new() failed" , __func__); + } +if (!EVP_EncryptInit_ex (ctx,EVP_bf_ecb (),NULL , key,0 )) + { +crypto_msg (M_FATAL ,"%s: EVP_EncryptInit_ex() failed" , __func__); + } -DES_set_key_unchecked ((DES_cblock *)key, &sched); -DES_ecb_encrypt ((DES_cblock *)src, (DES_cblock *)dst, &sched,DES_ENCRYPT ); +int len; +if (!EVP_EncryptUpdate (ctx, dst, &len, src,DES_KEY_LENGTH )) + { +crypto_msg (M_FATAL ,"%s: EVP_EncryptUpdate() failed" , __func__); + } + +if (!EVP_EncryptFinal (ctx, dst + len, &len)) + { +crypto_msg (M_FATAL ,"%s: EVP_EncryptFinal() failed" , __func__); + } }/*
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 03/21] [OSSL 3.0] Implement DES ECB encrypt via EVP_CIPHER api
Quoted 1 line · Arne Schwabe
+ if (!EVP_EncryptInit_ex(ctx,
EVP_bf_ecb(), NULL, key, 0))
EVP_bf_ecb() is the Blowfish cipher, not DES.
Re: [Openvpn-devel] [PATCH v3 03/21] [OSSL 3.0] Implement DES ECB encrypt via EVP_CIPHER api
Am 20.10.21 um 19:36 schrieb Max Fillinger:
Quoted 5 lines · Arne Schwabe
Quoted 1 line
+ if (!EVP_EncryptInit_ex(ctx,
EVP_bf_ecb(), NULL, key, 0))
EVP_bf_ecb()is the Blowfish cipher, not DES.
Oops. I probably need to write a unit test for this one too. Because that sounds like I broke this.
Arne
Re: [Openvpn-devel] [PATCH v3 03/21] [OSSL 3.0] Implement DES ECB encrypt via EVP_CIPHER api
In reply to Arne SchwabeHi,
Quoted 16 lines · Arne Schwabe
Even though DES is super outdated and also NTLM is super outdated, eliminating the warnings for OpenSSL 3.0 is still a step in the right direction and using the correct APIs.
Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/crypto_openssl.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)src/openvpn/crypto_openssl.c +0
-0@@ -879,10 +879,26 @@ cipher_des_encrypt_ecb(const unsigned char key[DES_KEY_LENGTH ], unsigned char src[DES_KEY_LENGTH],
src/openvpn/crypto_openssl.c cipher_des_encrypt_ecb(const unsigned char · line 889
Quoted 10 lines
src/openvpn/crypto_openssl.c +6
-1unsigned char dst[DES_KEY_LENGTH]) { -DES_key_schedule sched; +EVP_CIPHER_CTX *ctx =EVP_CIPHER_CTX_new (); +if (!ctx) + { +crypto_msg (M_FATAL ,"%s: EVP_CIPHER_CTX_new() failed" , __func__); + } +if (!EVP_EncryptInit_ex (ctx,EVP_bf_ecb (),NULL , key,0 ))
Apart from the wrong cipher type that Max pointed out, this call will fail in OpenSSL 3.0 unless legacy is loaded, right? Causing a run-time error in that case sounds good to me but a helpful error message like legacy provider may be required or even a check whether legacy is loaded and error out appropriately would be helpful.
PS: can't we just get rid of the use of DES altogether?
Selva
Re: [Openvpn-devel] [PATCH v3 03/21] [OSSL 3.0] Implement DES ECB encrypt via EVP_CIPHER api
Hi,
Quoted 1 line · Selva Nair
PS: can't we just get rid of the use of DES altogether?
Is there a newer NTLM auth variant that does not use DES?
Otherwise it's "keep NTLM auth => keep DES"...
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Re: [Openvpn-devel] [PATCH v3 03/21] [OSSL 3.0] Implement DES ECB encrypt via EVP_CIPHER api
In reply to Selva NairQuoted 11 lines
Apart from the wrong cipher type that Max pointed out, this call will fail in OpenSSL 3.0 unless legacy is loaded, right? Causing a run-time error in that case sounds good to me but a helpful error message like legacy provider may be required or even a check whether legacy is loaded and error out appropriately would be helpful.
PS: can't we just get rid of the use of DES altogether?
As Gert pointed out that NTLM depends on it. We can trick a bit here with DES-EDE and three times the same key but yes it should have a better error message.
Arne
Re: [Openvpn-devel] [PATCH v3 03/21] [OSSL 3.0] Implement DES ECB encrypt via EVP_CIPHER api
Quoted 9 lines · Arne Schwabe
Quoted 9 lines
Apart from the wrong cipher type that Max pointed out, this call will fail in OpenSSL 3.0 unless legacy is loaded, right? Causing a run-time error in that case sounds good to me but a helpful error message like legacy provider may be required or even a check whether legacy is loaded and error out appropriately would be helpful.
Quoted 7 lines
Quoted 2 lines
PS: can't we just get rid of the use of DES altogether?
As Gert pointed out that NTLM depends on it. We can trick a bit here with DES-EDE and three times the same key but yes it should have a better error message.
Oh, proxy with ntlm auth... That will have to live on for a while longer.
In that case we could load the legacy provider if http-proxy with auto, auto-nct or ntlm is in options (in a separate patch), and can leave the generic error message in this patch?
Selva
PATCH v3 4/21 Remove DES check with OpenSSL 3.0
In reply to Arne SchwabeDES is very deprecated and accidently getting on the of the 16 insecure keys that OpenSSL checks is extremely unlikely so we no longer use the deprecated functions without replacement in OpenSSL 3.0.
--- src/openvpn/crypto_openssl.c | 8 ++++++++ 1 file changed, 8 insertions(+)
src/openvpn/crypto_openssl.c +8 -0
@@ -521,6 +521,11 @@ key_des_num_cblocks(const EVP_CIPHER *kt)bool key_des_check (uint8_t *key,int key_len,int ndc) { +#if OPENSSL_VERSION_NUMBER <0x30000000L +/* DES is deprecated and the method to even check the keys is deprecated +* in OpenSSL 3.0. Instead of checking for the 16 weak/semi-weak keys +* we just accept them in OpenSSL 3.0 since the risk of randomly getting +* these is pretty weak */ int i;struct buffer b;
@@ -553,6 +558,9 @@ key_des_check(uint8_t *key, int key_len, int ndc) err:ERR_clear_error ();return false; +#else +return true; +#endif }void
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 04/21] [OSSL 3.0] Remove DES check with OpenSSL 3.0
Quoted 27 lines · Arne Schwabe
DES is very deprecated and accidently getting on the of the 16 insecure keys that OpenSSL checks is extremely unlikely so we no longer use the deprecated functions without replacement in OpenSSL 3.0.
Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/crypto_openssl.c | 8 ++++++++ 1 file changed, 8 insertions(+)src/openvpn/crypto_openssl.c +5
-0@@ -521,6 +521,11 @@ key_des_num_cblocks(const EVP_CIPHER *kt)bool key_des_check (uint8_t *key,int key_len,int ndc) { +#if OPENSSL_VERSION_NUMBER <0x30000000L +/* DES is deprecated and the method to even check the keys is deprecated +* in OpenSSL 3.0. Instead of checking for the 16 weak/semi-weak keys +* we just accept them in OpenSSL 3.0 since the risk of randomly getting +* these is pretty weak */ int i;struct buffer b;
src/openvpn/crypto_openssl.c key_des_check(uint8_t *key, int key_len, int ndc) · line 566
Quoted 9 lines
src/openvpn/crypto_openssl.c +3
-0@@ -553,6 +558,9 @@ key_des_check(uint8_t *key, int key_len, int ndc) err:ERR_clear_error ();return false; +#else +return true; +#endif }void
The code change looks good to me. Dropping the check is no loss because *all* DES keys are weak keys.
The comment probably makes more sense in the #else branch, or before the version check. Since I'm already nitpicking, it should be "the risk is low", not "weak".
[Openvpn-devel] [PATCH applied] Re: Remove DES check with OpenSSL 3.0
In reply to Arne SchwabeTaking MaxF review into account, moving the comment as suggested, and changing "risk ... is ... weak" to "low".
Your patch has been applied to the master branch.
commit d67658feeab4742b9b6f57806ba8e93c8eec75b8
Author: Arne Schwabe Date: Tue Oct 19 20:31:10 2021 +0200
Remove DES check with OpenSSL 3.0
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23004.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 5/21 Use EVP_PKEY based API for loading DH keys
In reply to Arne SchwabeOpenSSL 3.0 replaces the DH API with a generic EVP_KEY based API to load DH parameters.
--- src/openvpn/ssl_openssl.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
src/openvpn/ssl_openssl.c +21 -2
@@ -649,7 +649,6 @@ void tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file, bool dh_file_inline) { - DH *dh; BIO *bio;ASSERT (NULL != ctx);
@@ -670,7 +669,26 @@ tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file, } } - dh =PEM_read_bio_DHparams (bio,NULL ,NULL ,NULL ); +#if OPENSSL_VERSION_NUMBER >=0x30000000L +EVP_PKEY *dh =PEM_read_bio_Parameters (bio,NULL ); +BIO_free (bio); + +if (!dh) + { +crypto_msg (M_FATAL ,"Cannot load DH parameters from %s" , +print_key_filename (dh_file, dh_file_inline)); + } +if (!SSL_CTX_set0_tmp_dh_pkey (ctx->ctx, dh)) + { +crypto_msg (M_FATAL ,"SSL_CTX_set_tmp_dh" ); + } + +msg (D_TLS_DEBUG_LOW ,"Diffie-Hellman initialized with %d bit key" , +8 *EVP_PKEY_get_size (dh)); + +EVP_PKEY_free (dh); +#else +DH *dh =PEM_read_bio_DHparams (bio,NULL ,NULL ,NULL );BIO_free (bio);if (!dh)
@@ -687,6 +705,7 @@ tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file, 8 * DH_size(dh));DH_free (dh); +#endif }void
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 05/21] [OSSL 3.0] Use EVP_PKEY based API for loading DH keys
Quoted 4 lines · Arne Schwabe
OpenSSL 3.0 replaces the DH API with a generic
EVP_KEYbased API to load DH parameters.Signed-off-by Arne Schwabe <[email protected]...>
Looked at the patch, compiled with OpenSSL 3.1.0, tested that I can get a server and client to talk to each other on localhost.
[Openvpn-devel] [PATCH applied] Re: Use EVP_PKEY based API for loading DH keys
In reply to Arne SchwabeHave no OpenSSL 3.0 based test environment yet - so, trusting MaxF's tests here. Just did compile + client test on 1.1.1
Your patch has been applied to the master branch.
commit 658c72e6e651437943f46a975751109759abd858
Author: Arne Schwabe Date: Tue Oct 19 20:31:11 2021 +0200
Use EVP_PKEY based API for loading DH keys
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Max Fillinger <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23015.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v3 05/21] [OSSL 3.0] Use EVP_PKEY based API for loading DH keys
In reply to Arne SchwabeHi,
Just a nit:
src/openvpn/ssl_openssl.c tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file, · line 684
Quoted 4 lines · Arne Schwabe
src/openvpn/ssl_openssl.c +4
-0+if (!SSL_CTX_set0_tmp_dh_pkey (ctx->ctx, dh)) + { +crypto_msg (M_FATAL ,"SSL_CTX_set_tmp_dh" ); + }
This error message looks incorrect and incomplete.
-Steffan
PATCH v3 6/21 Deprecate --ecdh-curve with OpenSSL 3.0 and adjust mbed TLS message
In reply to Arne SchwabeOpenSSL 3.0 deprecates SSL_CTX_set_tmp_ecdh() in favour of SSL_CTX_set1_groups(3). We already support the SSL_CTX_set1_groups using the --tls-groups. Adjust both mbed TLS and OpenSSL 3.0 to say that --ecdh-curve is ingored and --tls-groups should be used.
--- src/openvpn/ssl_mbedtls.c | 5 +++-- src/openvpn/ssl_openssl.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-)
src/openvpn/ssl_mbedtls.c +3 -2
@@ -440,8 +440,9 @@ tls_ctx_load_ecdh_params(struct tls_root_ctx *ctx, const char *curve_name {if (NULL != curve_name) { -msg (M_WARN ,"WARNING: mbed TLS builds do not support specifying an ECDH " -"curve, using default curves." ); +msg (M_WARN ,"WARNING: mbed TLS builds do not support specifying an " +"ECDH curve with --ecdh-curve, using default curves. Use " +"--tls-groups to specify curves." ); } }
src/openvpn/ssl_openssl.c +9 -3
@@ -709,10 +709,16 @@ tls_ctx_load_dh_params(struct tls_root_ctx *ctx, const char *dh_file, }void -tls_ctx_load_ecdh_params (struct tls_root_ctx *ctx,const char *curve_name - ) +tls_ctx_load_ecdh_params (struct tls_root_ctx *ctx,const char *curve_name) { -#ifndef OPENSSL_NO_EC +#if OPENSSL_VERSION_NUMBER >=0x30000000L +if (curve_name !=NULL ) + { +msg (M_WARN ,"WARNING: OpenSSL 3.0+ builds do not support specifying an " +"ECDH curve with --ecdh-curve, using default curves. Use " +"--tls-groups to specify groups." ); + } +#elif !defined(OPENSSL_NO_EC )int nid = NID_undef;EC_KEY *ecdh =NULL ;const char *sname =NULL ;
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 06/21] [OSSL 3.0] Deprecate --ecdh-curve with OpenSSL 3.0 and adjust mbed TLS message
Quoted 6 lines · Arne Schwabe
OpenSSL 3.0 deprecates
SSL_CTX_set_tmp_ecdh()in favour ofSSL_CTX_set1_groups(3). We already support theSSL_CTX_set1_groupsusing the --tls-groups. Adjust both mbed TLS and OpenSSL 3.0 to say that --ecdh-curve is ingored and --tls-groups should be used.Signed-off-by Arne Schwabe <[email protected]...>
Not much to say here. It compiles and I can see the warning when I use the option.
[Openvpn-devel] [PATCH applied] Re: Deprecate --ecdh-curve with OpenSSL 3.0 and adjust mbed TLS message
In reply to Arne SchwabeI have not tested this further, just done a cursory stare-at-code.
Your patch has been applied to the master branch.
commit 39eb3125e4f433fc61c92321175f663f13f163e7
Author: Arne Schwabe Date: Tue Oct 19 20:31:12 2021 +0200
Deprecate --ecdh-curve with OpenSSL 3.0 and adjust mbed TLS message
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Max Fillinger <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg22999.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 7/21 Remove DES key fixup code
In reply to Arne SchwabeThis code mainly sets the parity bits in the DES keys. As mbed TLS and OpenSSL already ignore these bits in the DES key and since DES is deprecated, remove this special DES code that is not even needed by the libraries.
--- src/openvpn/crypto.c | 46 ------------------------------------ src/openvpn/crypto.h | 2 -- src/openvpn/crypto_backend.h | 9 ------- src/openvpn/crypto_mbedtls.c | 24 ------------------- src/openvpn/crypto_openssl.c | 27 --------------------- src/openvpn/ntlm.c | 1 - src/openvpn/ssl.c | 18 -------------- 7 files changed, 127 deletions(-)
src/openvpn/crypto.c +0 -46
@@ -956,45 +956,6 @@ check_key(struct key *key, const struct key_type *kt)return true; } -/* -* Make safe mutations to key to ensure it is valid, -* such as ensuring correct parity on DES keys. -* -* This routine cannot guarantee it will generate a good -* key. You must always call check_key after this routine -* to make sure. -*/ -void -fixup_key (struct key *key,const struct key_type *kt) -{ -struct gc_arena gc =gc_new (); -if (kt->cipher) - { -#ifdef ENABLE_DEBUG -const struct key orig = *key; -#endif -const int ndc =key_des_num_cblocks (kt->cipher); - -if (ndc) - { -key_des_fixup (key->cipher, kt->cipher_length, ndc); - } - -#ifdef ENABLE_DEBUG -if (check_debug_level (D_CRYPTO_DEBUG )) - { -if (memcmp (orig.cipher, key->cipher, kt->cipher_length)) - { -dmsg (D_CRYPTO_DEBUG ,"CRYPTO INFO: fixup_key: before=%s after=%s" , -format_hex (orig.cipher, kt->cipher_length,0 , &gc), -format_hex (key->cipher, kt->cipher_length,0 , &gc)); - } - } -#endif - } -gc_free (&gc); -} -void check_replay_consistency (const struct key_type *kt,bool packet_id) {
@@ -1043,10 +1004,6 @@ generate_key_random(struct key *key, const struct key_type *kt)dmsg (D_SHOW_KEY_SOURCE ,"Cipher source entropy: %s" ,format_hex (key->cipher, cipher_len,0 , &gc));dmsg (D_SHOW_KEY_SOURCE ,"HMAC source entropy: %s" ,format_hex (key->hmac, hmac_len,0 , &gc)); -if (kt) - { -fixup_key (key, kt); - } }while (kt && !check_key (key, kt));gc_free (&gc);
@@ -1589,9 +1546,6 @@ verify_fix_key2(struct key2 *key2, const struct key_type *kt, const char *sharedfor (i =0 ; i < key2->n; ++i) { -/* Fix parity for DES keys and make sure not a weak key */ -fixup_key (&key2->keys[i], kt); -/* This should be a very improbable failure */ if (!check_key (&key2->keys[i], kt)) {
src/openvpn/crypto.h +0 -2
@@ -288,8 +288,6 @@ void check_replay_consistency(const struct key_type *kt, bool packet_id);bool check_key (struct key *key,const struct key_type *kt); -void fixup_key (struct key *key,const struct key_type *kt); -bool write_key (const struct key *key,const struct key_type *kt,struct buffer *buf);
src/openvpn/crypto_backend.h +0 -9
@@ -170,15 +170,6 @@ int key_des_num_cblocks(const cipher_kt_t *kt);*/ bool key_des_check (uint8_t *key,int key_len,int ndc); -/* -* Fix the given DES key, setting its parity to odd. -* -* @param key Key to check -* @param key_len Length of the key, in bytes -* @param ndc Number of DES cblocks that the key is made up of. -*/ -void key_des_fixup (uint8_t *key,int key_len,int ndc); -/** * Encrypt the given block, using DES ECB mode *
src/openvpn/crypto_mbedtls.c +0 -24
@@ -422,11 +422,6 @@ key_des_check(uint8_t *key, int key_len, int ndc)msg (D_CRYPT_ERRORS ,"CRYPTO INFO: check_key_DES: weak key detected" ); goto err; } -if (0 !=mbedtls_des_key_check_key_parity (key)) - { -msg (D_CRYPT_ERRORS ,"CRYPTO INFO: check_key_DES: bad parity detected" ); - goto err; - } }return true;
@@ -434,25 +429,6 @@ err:return false; } -void -key_des_fixup (uint8_t *key,int key_len,int ndc) -{ -int i; -struct buffer b; - -buf_set_read (&b, key, key_len); -for (i =0 ; i < ndc; ++i) - { -unsigned char *key =buf_read_alloc (&b,MBEDTLS_DES_KEY_SIZE ); -if (!key) - { -msg (D_CRYPT_ERRORS ,"CRYPTO INFO: fixup_key_DES: insufficient key material" ); -return ; - } -mbedtls_des_key_set_parity (key); - } -} -/* * * Generic cipher key type functions
src/openvpn/crypto_openssl.c +0 -27
@@ -546,12 +546,6 @@ key_des_check(uint8_t *key, int key_len, int ndc) "CRYPTO INFO: check_key_DES: weak key detected"); goto err; } -if (!DES_check_key_parity (dc)) - { -crypto_msg (D_CRYPT_ERRORS , -"CRYPTO INFO: check_key_DES: bad parity detected" ); - goto err; - } }return true;
@@ -563,27 +557,6 @@ err:#endif } -void -key_des_fixup (uint8_t *key,int key_len,int ndc) -{ -int i; -struct buffer b; - -buf_set_read (&b, key, key_len); -for (i =0 ; i < ndc; ++i) - { -DES_cblock *dc = (DES_cblock *)buf_read_alloc (&b,sizeof (DES_cblock)); -if (!dc) - { -msg (D_CRYPT_ERRORS ,"CRYPTO INFO: fixup_key_DES: insufficient key material" ); -ERR_clear_error (); -return ; - } -DES_set_odd_parity (dc); - } -} - -/* * * Generic cipher key type functions
src/openvpn/ntlm.c +0 -1
@@ -67,7 +67,6 @@ create_des_keys(const unsigned char *hash, unsigned char *key) key[5 ] = ((hash[4 ] &31 ) <<3 ) | (hash[5 ] >>5 ); key[6 ] = ((hash[5 ] &63 ) <<2 ) | (hash[6 ] >>6 ); key[7 ] = ((hash[6 ] &127 ) <<1 ); -key_des_fixup (key,8 ,1 ); } static void
src/openvpn/ssl.c +0 -18
@@ -1739,24 +1739,6 @@ generate_key_expansion_openvpn_prf(const struct tls_session *session, struct key }secure_memzero (&master,sizeof (master)); - - -/* -* fixup_key only correctly sets DES parity bits if the cipher is a -* DES variant. -* -* The newer OpenSSL and mbed TLS libraries (those that support EKM) -* ignore these bits. -* -* We keep the DES fixup here as compatibility. -* OpenVPN3 never did this fixup anyway. So this code is *probably* not -* required but we keep it for compatibility until we remove DES support -* since it does not hurt either. -*/ -for (int i =0 ; i <2 ; ++i) - { -fixup_key (&key2->keys[i], &session->opt->key_type); - } key2->n =2 ;return true;
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 07/21] [OSSL 3.0] Remove DES key fixup code
Quoted 6 lines · Arne Schwabe
This code mainly sets the parity bits in the DES keys. As mbed TLS and OpenSSL already ignore these bits in the DES key and since DES is deprecated, remove this special DES code that is not even needed by the libraries.
Signed-off-by Arne Schwabe <[email protected]...>
Makes sense, why should we care about the parity bits when no-one else does?
Compiled and ran --test-crypto for DES/DES3 with OpenSSL 3.1.0, 1.1.1 and mbedtls 2.26.
[Openvpn-devel] [PATCH applied] Re: Remove DES key fixup code
In reply to Arne SchwabeLooks reasonable, passes client side tests (with 1.1.1 only, lazy) :-)
It might bite up for NTLM (as I see it's used there as well, and that is the only place where we really continue to need DES). Seems I need to set up a NTLM proxy auth environment to test this...
Your patch has been applied to the master branch.
commit e23c152aa58f533a224df4bc3d433e2be967f64b
Author: Arne Schwabe Date: Tue Oct 19 20:31:13 2021 +0200
Remove DES key fixup code
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Max Fillinger <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23014.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 8/21 Use EVP_PKEY_get_group_name to query group name
In reply to Arne SchwabeEC_Key methods are deprecated in OpenSSL 3.0. Use EVP_PKEY_get_group_name instead to query the EC group name from an EVP_PKEY and add a compatibility function for older OpenSSL versions.
--- src/openvpn/openssl_compat.h | 42 ++++++++++++++++++++++++++++++++++++ src/openvpn/ssl_openssl.c | 14 ++++++------ 2 files changed, 50 insertions(+), 6 deletions(-)
src/openvpn/openssl_compat.h +42 -0
@@ -718,4 +718,46 @@ SSL_CTX_set_max_proto_version(SSL_CTX *ctx, long tls_ver_max)return 1 ; }#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L && !defined(ENABLE_CRYPTO_WOLFSSL) */ + +/* Functionality missing in 1.1.1 */ +#if OPENSSL_VERSION_NUMBER <0x30000000L && !defined(OPENSSL_NO_EC ) + +/* Note that this is not a perfect emulation of the new function but +* is good enough for our case of printing certificate details during +* handshake */ +static inline +int EVP_PKEY_get_group_name (EVP_PKEY *pkey,char *gname,size_t gname_sz, +size_t *gname_len) +{ +const EC_KEY * ec =EVP_PKEY_get0_EC_KEY (pkey); +if (ec ==NULL ) + { +return 0 ; + } +const EC_GROUP * group =EC_KEY_get0_group (ec); +int nid =EC_GROUP_get_curve_name (group); + +if (nid ==0 ) + { +return 0 ; + } +const char *curve =OBJ_nid2sn (nid); + +strncpynt (gname, curve, gname_sz); + *gname_len =min_int (strlen (curve), gname_sz); +return 1 ; +} +#endif + +/** Mimics SSL_CTX_new_ex for OpenSSL < 3 */ +#if OPENSSL_VERSION_NUMBER <0x30000000L +static inline SSL_CTX * +SSL_CTX_new_ex (void *libctx,const char *propq,const SSL_METHOD *method) +{ + (void ) libctx; + (void ) propq; +return SSL_CTX_new (method); +} +#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */ +#endif /* OPENSSL_COMPAT_H_ */
src/openvpn/ssl_openssl.c +8 -6
@@ -2053,13 +2053,15 @@ print_cert_details(X509 *cert, char *buf, size_t buflen)int typeid =EVP_PKEY_id (pkey);#ifndef OPENSSL_NO_EC -if (typeid ==EVP_PKEY_EC &&EVP_PKEY_get0_EC_KEY (pkey) !=NULL ) +char groupname[256 ]; +if (typeid ==EVP_PKEY_EC ) { -const EC_KEY *ec =EVP_PKEY_get0_EC_KEY (pkey); -const EC_GROUP *group =EC_KEY_get0_group (ec); - -int nid =EC_GROUP_get_curve_name (group); -if (nid ==0 || (curve =OBJ_nid2sn (nid)) ==NULL ) +size_t len; +if (EVP_PKEY_get_group_name (pkey, groupname,sizeof (groupname), &len)) + { + curve = groupname; + } +else { curve ="(error getting curve name)" ; }
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 08/21] [OSSL 3.0] Use EVP_PKEY_get_group_name to query group name
Hi,
I had looked at v1 of this so easy:
Quoted 35 lines · Arne Schwabe
EC_Keymethods are deprecated in OpenSSL 3.0. UseEVP_PKEY_get_group_nameinstead to query the EC group name from anEVP_PKEYand add a compatibility function for older OpenSSL versions.Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/openssl_compat.h | 42 ++++++++++++++++++++++++++++++++++++ src/openvpn/ssl_openssl.c | 14 ++++++------ 2 files changed, 50 insertions(+), 6 deletions(-)src/openvpn/openssl_compat.h +0
-0@@ -718,4 +718,46 @@ SSL_CTX_set_max_proto_version(SSL_CTX *ctx, long tls_ver_max) return 1; }#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L && !defined(ENABLE_CRYPTO_WOLFSSL) */
src/openvpn/openssl_compat.h +14
-0+ +/* Functionality missing in 1.1.1 */ +#if OPENSSL_VERSION_NUMBER <0x30000000L && !defined(OPENSSL_NO_EC ) + +/* Note that this is not a perfect emulation of the new function but +* is good enough for our case of printing certificate details during +* handshake */ +static inline +int EVP_PKEY_get_group_name (EVP_PKEY *pkey,char *gname,size_t gname_sz, +size_t *gname_len) +{ +const EC_KEY * ec =EVP_PKEY_get0_EC_KEY (pkey); +if (ec ==NULL ) + {
src/openvpn/openssl_compat.h SSL_CTX_set_max_proto_version(SSL_CTX *ctx, long tls_ver_max) · line 744
Quoted 10 lines
src/openvpn/openssl_compat.h +10
-0+return 0 ; + } +const EC_GROUP * group =EC_KEY_get0_group (ec); +int nid =EC_GROUP_get_curve_name (group); + +if (nid ==0 ) + { +return 0 ; + } +const char *curve =OBJ_nid2sn (nid);
I would have preferred a curve !=NULL check here. Though very unlikely to happen, we do not want a segfault in strncpy.
+
src/openvpn/openssl_compat.h SSL_CTX_set_max_proto_version(SSL_CTX *ctx, long tls_ver_max) · line 747
Quoted 3 lines
src/openvpn/openssl_compat.h +2
-0+strncpynt (gname, curve, gname_sz); + *gname_len =min_int (strlen (curve), gname_sz);
gname_sz - 1 ?
That said, our strncpynt ensures that strlen(curve) will be less than gname_sz, so this could be just strlen(curve) or left as is.
src/openvpn/openssl_compat.h SSL_CTX_set_max_proto_version(SSL_CTX *ctx, long tls_ver_max) · line 755
Quoted 9 lines
src/openvpn/openssl_compat.h +8
-0+ return 1; +} +#endif + +/** Mimics SSL_CTX_new_ex for OpenSSL < 3 */ +#if OPENSSL_VERSION_NUMBER <0x30000000L +static inline SSL_CTX * +SSL_CTX_new_ex (void *libctx,const char *propq,const SSL_METHOD *method)
This looks like a spill-over from one of my xkey patches --- "git commit -p" malfunction?
Unless the "unused functions police" objects, we can keep it.
+{
Quoted 33 lines
src/openvpn/openssl_compat.h +6
-0+ (void ) libctx; + (void ) propq; +return SSL_CTX_new (method); +} +#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */ +#endif /* OPENSSL_COMPAT_H_ */ src/openvpn/ssl_openssl.c +8
-6@@ -2053,13 +2053,15 @@ print_cert_details(X509 *cert, char *buf, size_t buflen)int typeid =EVP_PKEY_id (pkey);#ifndef OPENSSL_NO_EC -if (typeid ==EVP_PKEY_EC &&EVP_PKEY_get0_EC_KEY (pkey) !=NULL ) +char groupname[256 ]; +if (typeid ==EVP_PKEY_EC ) { -const EC_KEY *ec =EVP_PKEY_get0_EC_KEY (pkey); -const EC_GROUP *group =EC_KEY_get0_group (ec); - -int nid =EC_GROUP_get_curve_name (group); -if (nid ==0 || (curve =OBJ_nid2sn (nid)) ==NULL ) +size_t len; +if (EVP_PKEY_get_group_name (pkey, groupname,sizeof (groupname), &len)) + { + curve = groupname; + } +else {
Quoted 4 lines
curve = "(error getting curve name)";
}Looks good otherwise and works as expected.
Selva
Re: [Openvpn-devel] [PATCH v3 08/21] [OSSL 3.0] Use EVP_PKEY_get_group_name to query group name
In reply to Arne SchwabeQuoted 32 lines · Arne Schwabe
EC_Keymethods are deprecated in OpenSSL 3.0. UseEVP_PKEY_get_group_nameinstead to query the EC group name from anEVP_PKEYand add a compatibility function for older OpenSSL versions.Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/openssl_compat.h | 42 ++++++++++++++++++++++++++++++++++++ src/openvpn/ssl_openssl.c | 14 ++++++------ 2 files changed, 50 insertions(+), 6 deletions(-)src/openvpn/openssl_compat.h +14
-0@@ -718,4 +718,46 @@ SSL_CTX_set_max_proto_version(SSL_CTX *ctx, long tls_ver_max)return 1 ; }#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L && !defined(ENABLE_CRYPTO_WOLFSSL) */ + +/* Functionality missing in 1.1.1 */ +#if OPENSSL_VERSION_NUMBER <0x30000000L && !defined(OPENSSL_NO_EC ) + +/* Note that this is not a perfect emulation of the new function but +* is good enough for our case of printing certificate details during +* handshake */ +static inline +int EVP_PKEY_get_group_name (EVP_PKEY *pkey,char *gname,size_t gname_sz, +size_t *gname_len) +{ +const EC_KEY * ec =EVP_PKEY_get0_EC_KEY (pkey); +if (ec ==NULL ) + {
src/openvpn/openssl_compat.h SSL_CTX_set_max_proto_version(SSL_CTX *ctx, long tls_ver_max) · line 744
Quoted 10 lines
src/openvpn/openssl_compat.h +10
-0+return 0 ; + } +const EC_GROUP * group =EC_KEY_get0_group (ec); +int nid =EC_GROUP_get_curve_name (group); + +if (nid ==0 ) + { +return 0 ; + } +const char *curve =OBJ_nid2sn (nid);
The old code also has a curve == NULL check. Is that not necessary here?
PATCH v3 9/21 Refactor early initialisation and uninitialisation into methods
In reply to Arne SchwabeThis put the early initialisation and uninitialisation that needs to happen between option parsing and post processing into small methods.
--- src/openvpn/openvpn.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
src/openvpn/openvpn.c +18 -5
@@ -105,6 +105,20 @@ tunnel_point_to_point(struct context *c)#undef PROCESS_SIGNAL_P2P +void init_early (struct context *c) +{ +net_ctx_init (c, &(*c).net_ctx); + +/* init verbosity and mute levels */ +init_verb_mute (c,IVM_LEVEL_1 ); + +} + +static void uninit_early (struct context *c) +{ +net_ctx_free (&(*c).net_ctx); +} +/**************************************************************************/ /**
@@ -193,10 +207,9 @@ openvpn_main(int argc, char *argv[])open_plugins (&c, true,OPENVPN_PLUGIN_INIT_PRE_CONFIG_PARSE );#endif -net_ctx_init (&c, &c.net_ctx); - -/* init verbosity and mute levels */ -init_verb_mute (&c,IVM_LEVEL_1 ); +/* Early initialisation that need to happen before option +* post processing and other early startup but after parsing */ +init_early (&c);/* set dev options */ init_options_dev (&c.options);
@@ -308,7 +321,7 @@ openvpn_main(int argc, char *argv[])env_set_destroy (c.es);uninit_options (&c.options);gc_reset (&c.gc); -net_ctx_free (&c.net_ctx); +uninit_early (&c); }while (c.sig->signal_received ==SIGHUP ); }
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 09/21] Refactor early initialisation and uninitialisation into methods
Hi,
Quoted 13 lines · Arne Schwabe
This put the early initialisation and uninitialisation that needs to happen between option parsing and post processing into small methods.
Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/openvpn.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)src/openvpn/openvpn.c +0
-0
src/openvpn/openvpn.c tunnel_point_to_point(struct context *c) · line 111
Quoted 7 lines
src/openvpn/openvpn.c +3
-0@@ -105,6 +105,20 @@ tunnel_point_to_point(struct context *c)#undef PROCESS_SIGNAL_P2P +void init_early (struct context *c) +{ +net_ctx_init (c, &(*c).net_ctx);
&c->net_ctx would be more readable and less mysterious.
src/openvpn/openvpn.c tunnel_point_to_point(struct context *c) · line 117
Quoted 7 lines
src/openvpn/openvpn.c +7
-0+ +/* init verbosity and mute levels */ +init_verb_mute (c,IVM_LEVEL_1 ); + +} + +static void uninit_early (struct context *c)
+{
src/openvpn/openvpn.c tunnel_point_to_point(struct context *c) · line 122
Quoted 2 lines
src/openvpn/openvpn.c +1
-0+net_ctx_free (&(*c).net_ctx);
&c->net_ctx
Quoted 22 lines
src/openvpn/openvpn.c +5
-4+} +/**************************************************************************/ /** @@ -193,10 +207,9 @@ openvpn_main(int argc, char *argv[])open_plugins (&c, true,OPENVPN_PLUGIN_INIT_PRE_CONFIG_PARSE );#endif -net_ctx_init(&c, &c.net_ctx); - -/* init verbosity and mute levels */ -init_verb_mute (&c,IVM_LEVEL_1 ); +/* Early initialisation that need to happen before option +* post processing and other early startup but after parsing */ +init_early (&c);/* set dev options */ init_options_dev(&c.options);
src/openvpn/openvpn.c openvpn_main(int argc, char *argv[]) · line 324
Quoted 5 lines
src/openvpn/openvpn.c +1
-1@@ -308,7 +321,7 @@ openvpn_main(int argc, char *argv[])env_set_destroy (c.es);uninit_options (&c.options);gc_reset (&c.gc); -net_ctx_free (&c.net_ctx); +uninit_early (&c);
}
src/openvpn/openvpn.c openvpn_main(int argc, char *argv[]) · line 327
Quoted 2 lines
src/openvpn/openvpn.c +0
-0while (c.sig->signal_received ==SIGHUP ); }
Looks good otherwise. The nits could be fixed at commit time?
Selva
Re: [Openvpn-devel] [PATCH v3 09/21] Refactor early initialisation and uninitialisation into methods
In reply to Arne SchwabeQuoted 4 lines · Arne Schwabe
This put the early initialisation and uninitialisation that needs to happen between option parsing and post processing into small methods.
Signed-off-by Arne Schwabe <[email protected]...>
It's easy to see that this does not change the behavior. Compiled and tested with OpenSSL 3 only because it doesn't actually touch any OpenSSL code.
PATCH v3 10/21 Replace EVP_get_cipherbyname with EVP_CIPHER_fetch
In reply to Arne SchwabeIn OpenSSL 3.0 EVP_get_cipherbyname return a non NULL algorithm even if the algorithm is not avaialble with the currently available provider. Luckily EVP_get_cipherbyname can be used here as drop in replacement and returns only non NULL if the algorithm is actually currently supported.
--- src/openvpn/crypto_openssl.c | 6 +++--- src/openvpn/openssl_compat.h | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-)
src/openvpn/crypto_openssl.c +3 -3
@@ -572,7 +572,7 @@ cipher_kt_get(const char *ciphername)ASSERT (ciphername); ciphername =translate_cipher_name_from_openvpn (ciphername); - cipher =EVP_get_cipherbyname (ciphername); + cipher =EVP_CIPHER_fetch (NULL , ciphername,NULL );if (NULL == cipher) {
@@ -658,7 +658,7 @@ cipher_kt_block_size(const EVP_CIPHER *cipher)strcpy (mode_str,"-CBC" ); - cbc_cipher =EVP_get_cipherbyname (translate_cipher_name_from_openvpn (name)); + cbc_cipher =EVP_CIPHER_fetch (NULL ,translate_cipher_name_from_openvpn (name),NULL );if (cbc_cipher) { block_size =EVP_CIPHER_block_size (cbc_cipher);
@@ -894,7 +894,7 @@ md_kt_get(const char *digest) {const EVP_MD *md =NULL ;ASSERT (digest); - md =EVP_get_digestbyname (digest); + md =EVP_MD_fetch (NULL , digest,NULL );if (!md) {crypto_msg (M_FATAL ,"Message hash algorithm '%s' not found" , digest);
src/openvpn/openssl_compat.h +17 -0
@@ -758,6 +758,23 @@ SSL_CTX_new_ex(void *libctx, const char *propq, const SSL_METHOD *method) (void ) propq;return SSL_CTX_new (method); } +/* Mimics the functions but only when the default context without +* options is chosen */ +static inline const EVP_CIPHER * +EVP_CIPHER_fetch (void *ctx,const char *algorithm,const char *properties) +{ +ASSERT (!ctx); +ASSERT (!properties); +return EVP_get_cipherbyname (algorithm); +} + +static inline const EVP_MD * +EVP_MD_fetch (void *ctx,const char *algorithm,const char *properties) +{ +ASSERT (!ctx); +ASSERT (!properties); +return EVP_get_digestbyname (algorithm); +}#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */ #endif /* OPENSSL_COMPAT_H_ */
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 10/21] [OSSL 3.0] Replace EVP_get_cipherbyname with EVP_CIPHER_fetch
Quoted 7 lines · Arne Schwabe
In OpenSSL 3.0
EVP_get_cipherbynamereturn a non NULL algorithm even if the algorithm is not avaialble with the currently available provider. LuckilyEVP_get_cipherbynamecan be used here as drop in replacement and returns only non NULL if the algorithm is actually currently supported.Signed-off-by Arne Schwabe <[email protected]...>
Looks good to me!
Some small errors in the commit message:
"return a non Null algorithm": Should be "may return", I think.
second "EVP_get_cipherbyname" should be "EVP_CIPHER_fetch".
Re: [Openvpn-devel] [PATCH v3 10/21] [OSSL 3.0] Replace EVP_get_cipherbyname with EVP_CIPHER_fetch
In reply to Arne SchwabeThis has an ACK, but will leak memory in OpenSSL 3.0
Quoted 17 lines · Arne Schwabe
In OpenSSL 3.0
EVP_get_cipherbynamereturn a non NULL algorithm even if the algorithm is not avaialble with the currently available provider. LuckilyEVP_get_cipherbynamecan be used here as drop in replacement and returns only non NULL if the algorithm is actually currently supported.Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/crypto_openssl.c | 6 +++--- src/openvpn/openssl_compat.h | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-)src/openvpn/crypto_openssl.c +0
-0
src/openvpn/crypto_openssl.c cipher_kt_get(const char *ciphername) · line 576
Quoted 6 lines
src/openvpn/crypto_openssl.c +1
-1@@ -572,7 +572,7 @@ cipher_kt_get(const char *ciphername)ASSERT (ciphername); ciphername =translate_cipher_name_from_openvpn (ciphername); - cipher =EVP_get_cipherbyname (ciphername); + cipher =EVP_CIPHER_fetch (NULL , ciphername,NULL );
In OpenSSL 3.0, this 'cipher' must be freed. But the compat function is written using get_cipherbyname() which returns a const variable that should not be freed. Also, here we want to return a const cipher to the caller.
One option is to continue using get_cipherbyname() but add a helper call for OpenSSL 3.0 to check algorithm availability. Say, EVP_CIPHER_available() that fetches, checks the result and frees --- to be used on top of the existing code.
Selva
Re: [Openvpn-devel] [PATCH v3 10/21] [OSSL 3.0] Replace EVP_get_cipherbyname with EVP_CIPHER_fetch
Am 30.10.21 um 21:28 schrieb Selva Nair:
Quoted 34 lines
This has an ACK, but will leak memory in OpenSSL 3.0
On Tue, Oct 19, 2021 at 2:32 PM Arne Schwabe <[email protected]... <mailto:[email protected]...>> wrote:
In OpenSSL 3.0 EVP_get_cipherbyname return a non NULL algorithm even if the algorithm is not avaialble with the currently available provider. Luckily EVP_get_cipherbyname can be used here as drop in replacement and returns only non NULL if the algorithm is actually currently supported. Signed-off-by: Arne Schwabe <[email protected]... <mailto:[email protected]...>> --- src/openvpn/crypto_openssl.c | 6 +++--- src/openvpn/openssl_compat.h | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c index 93c85a836..b10bd7cd5 100644 --- a/src/openvpn/crypto_openssl.c +++ b/src/openvpn/crypto_openssl.c @@ -572,7 +572,7 @@ cipher_kt_get(const char *ciphername) ASSERT(ciphername); ciphername = translate_cipher_name_from_openvpn(ciphername); - cipher = EVP_get_cipherbyname(ciphername); + cipher = EVP_CIPHER_fetch(NULL, ciphername, NULL);In OpenSSL 3.0, this 'cipher' must be freed. But the compat function is written using
get_cipherbyname()which returns a const variable that should not be freed. Also, here we want to return a const cipher to the caller.
Quoted 4 lines
One option is to continue using
get_cipherbyname()but add a helper call for OpenSSL 3.0 to check algorithm availability. Say,EVP_CIPHER_available()that fetches, checks the result and frees --- to be used on top of the existing code.
That is an option but will break as soon as we have the first cipher that is no longer defined with EVP_ORIG_GLOBAL compatibility definition. I need to check how much work it is to teach OpenVPN to free the cipher and md.
Arne
Re: [Openvpn-devel] [PATCH v3 10/21] [OSSL 3.0] Replace EVP_get_cipherbyname with EVP_CIPHER_fetch
Quoted 11 lines
Quoted 6 lines
One option is to continue using
get_cipherbyname()but add a helper call for OpenSSL 3.0 to check algorithm availability. Say,EVP_CIPHER_available()that fetches, checks the result and frees --- to be used on top of the existing code.That is an option but will break as soon as we have the first cipher that is no longer defined with
EVP_ORIG_GLOBALcompatibility definition. I need to check how much work it is to teach OpenVPN to free the cipher and md.
I looked at this and I think the best option is to change API to use strings rather than EVP_CIPHER in the "public" API of the ssl library implementation. That will simplify the code rather than to complicate it.
Arne
[Openvpn-devel] [PATCH applied] Re: Replace EVP_get_cipherbyname with EVP_CIPHER_fetch
In reply to Arne SchwabeThis patch took at bit of massaging to get in, due to the context having SSL_CTX_new_ex() which disappeared during 08 v3->v4 -> replaced by proper context (adding #if OPENSSL_VERSION_NUMBER < 0x30000000L).
I have read Selva's comment about mem leaking, and decided to still merge it - this OSS 3 thing is work in progress, and I want to get the later patches in that have ACKs, so the code can get more exposure (we must not forget to return here and fix it, of course).
I have stared at the code a bit, and given it "make check" treatment - this now explodes for 3.0.0 in the ncp_testdriver
Unsupported cipher in --data-ciphers: BF-CBC
[ ERROR ] --- Test failed with exception: Segmentation fault(11)
(but I assume that this will be fixed as soon as the legacy provider
stuff gets in). t_lpback.sh still fails, but now with a proper error
message ("Cipher SEED-OFB not supported") - I seem to remember a later patch fixing the cipher listing part, so SEED-OFB won't even show up as a candidate.
1.1.1 passes just fine.
Your patch has been applied to the master branch.
commit f40edaa5abe5255710315deacd8c82cdfef12647
Author: Arne Schwabe Date: Tue Oct 19 20:31:16 2021 +0200
Replace EVP_get_cipherbyname with EVP_CIPHER_fetch
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-By: Max Fillinger <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23005.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 11/21 USe EVP_MD_get0_name instead EV_MD_name
In reply to Arne SchwabeUse the new name for the function as it indicates with get0 the ownership of the returned value
--- src/openvpn/crypto_openssl.c | 2 +- src/openvpn/openssl_compat.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
src/openvpn/crypto_openssl.c +1 -1
@@ -916,7 +916,7 @@ md_kt_name(const EVP_MD *kt) {return "[null-digest]" ; } -return EVP_MD_name (kt); +return EVP_MD_get0_name (kt); }unsigned char
src/openvpn/openssl_compat.h +2 -0
@@ -751,6 +751,8 @@ int EVP_PKEY_get_group_name(EVP_PKEY *pkey, char *gname, size_t gname_sz,/** Mimics SSL_CTX_new_ex for OpenSSL < 3 */ #if OPENSSL_VERSION_NUMBER <0x30000000L +#define EVP_MD_get0_name EVP_MD_name +static inline SSL_CTX *SSL_CTX_new_ex (void *libctx,const char *propq,const SSL_METHOD *method) {
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 11/21] [OSSL 3.0] USe EVP_MD_get0_name instead EV_MD_name
Quoted 4 lines · Arne Schwabe
Use the new name for the function as it indicates with get0 the ownership of the returned value
Signed-off-by Arne Schwabe <[email protected]...>
Looks good to me.
Typo: "USe"
[Openvpn-devel] [PATCH applied] Re: Use EVP_MD_get0_name instead EV_MD_name
In reply to Arne SchwabeSome context massaging required (ssl_compat context, 08, v3->v4, ...)
1.1.1 builds & passes "make check" just fine.
3.0.0 shows the same failures as before (ncp_testdriver, t_lpback.sh), which means "nothing new broke", so this change seems to be good enough.
Your patch has been applied to the master branch.
commit 5a112250745b69a3ca2f3e00aed9ea02b2e717bb
Author: Arne Schwabe Date: Tue Oct 19 20:31:17 2021 +0200
Use EVP_MD_get0_name instead EV_MD_name
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Max Fillinger <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23016.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 12/21 Allow loading of non default providers
In reply to Arne SchwabeThis allows OpenVPN to load non-default providers. This is mainly useful for loading the legacy provider with --provider legacy:default
--- doc/man-sections/generic-options.rst | 10 ++++++++++ src/openvpn/crypto_backend.h | 7 +++++++ src/openvpn/crypto_mbedtls.c | 8 ++++++++ src/openvpn/crypto_openssl.c | 29 ++++++++++++++++++++++++++++ src/openvpn/openvpn.c | 4 ++++ src/openvpn/options.c | 4 ++++ src/openvpn/options.h | 1 + 7 files changed, 63 insertions(+)
doc/man-sections/generic-options.rst +10 -0
@@ -280,6 +280,16 @@ which mode OpenVPN is configured as. This option solves the problem by persisting keys across :code:`SIGUSR1` resets, so they don't need to be re-read. +--provider providers + Load the : separated list of (OpenSSL) providers. This is mainly useful for + using an external provider for key management like tpm2-openssl or to load + the legacy provider with + + :: + + --provider "legacy:default" + + --remap-usr1 signal Control whether internally or externally generated :code:`SIGUSR1` signals are remapped to :code:`SIGHUP` (restart without persisting state) or
src/openvpn/crypto_backend.h +7 -0
@@ -78,6 +78,13 @@ void crypto_clear_error(void);*/ void crypto_init_lib_engine (const char *engine_name); + +/** +* Load the given (OpenSSL) providers +* @param providers list of providers to load, seperated by : +*/ +void crypto_init_lib_provider (const char *providers); +#ifdef DMALLOC /* * OpenSSL memory debugging. If dmalloc debugging is enabled, tell
src/openvpn/crypto_mbedtls.c +8 -0
@@ -70,6 +70,14 @@ crypto_init_lib_engine(const char *engine_name) "available"); } +void crypto_init_lib_provider (const char *providers) +{ +if (providers) + { +msg (M_WARN ,"Note: mbed TLS provider functionality is not available" ); + } +} +/* * * Functions related to the core crypto library
src/openvpn/crypto_openssl.c +29 -0
@@ -54,6 +54,9 @@#if (OPENSSL_VERSION_NUMBER >=0x10100000L ) && !defined(LIBRESSL_VERSION_NUMBER )#include <openssl/kdf.h> #endif +#if OPENSSL_VERSION_NUMBER >=0x30000000L +#include <openssl/provider.h> +#endif /* * Check for key size creepage.
@@ -145,6 +148,32 @@ crypto_init_lib_engine(const char *engine_name)#endif } +void +crypto_init_lib_provider (const char *providers) +{ +if (!providers) + { +return ; + } +#if OPENSSL_VERSION_NUMBER >=0x30000000L +struct gc_arena gc =gc_new (); +char *tmp_providers =string_alloc (providers, &gc); + +const char *provname; +while ((provname =strsep (&tmp_providers,":" ))) + { +/* Load providers into the default (NULL) library context */ +OSSL_PROVIDER * provider =OSSL_PROVIDER_load (NULL , provname); +if (!provider) + { +crypto_msg (M_FATAL ,"failed to load provider '%s'" , provname); + } + } +#else /* OPENSSL_VERSION_NUMBER >= 0x30000000L */ +msg (M_WARN ,"Note: OpenSSL hardware crypto engine functionality is not available" ); +#endif +} +/* * * Functions related to the core crypto library
src/openvpn/openvpn.c +4 -0
@@ -112,6 +112,10 @@ void init_early(struct context *c)/* init verbosity and mute levels */ init_verb_mute (c,IVM_LEVEL_1 ); +/* Initialise OpenVPN provider, this needs to be intialised this +* early since option post processing and also openssl info +* printing depends on it */ +crypto_init_lib_provider ((*c).options.providers); }static void uninit_early (struct context *c)
src/openvpn/options.c +4 -0
@@ -8178,6 +8178,10 @@ add_option(struct options *options, options->engine = "auto"; } } +else if (streq (p[0 ],"provider" ) && p[1 ] && !p[2 ]) + { + options->providers = p[1 ]; + }#endif /* ENABLE_CRYPTO_MBEDTLS */ #ifdef ENABLE_PREDICTION_RESISTANCE else if (streq(p[0], "use-prediction-resistance") && !p[1])
src/openvpn/options.h +1 -0
@@ -521,6 +521,7 @@ struct optionsconst char *prng_hash;int prng_nonce_secret_len;const char *engine; +const char *providers;bool replay;bool mute_replay_warnings;int replay_window;
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 12/21] [OSSL 3.0] Allow loading of non default providers
Hi,
Not a code review but a general comment as this is a new option that warrants some discussion.
Quoted 3 lines · Arne Schwabe
This allows OpenVPN to load non-default providers. This is mainly useful for loading the legacy provider with --provider legacy:default
While this format looks okay, we need to consider a few things to get this option right and possibly extensible in future without causing a regression.
(i) Provider name may not be a simple word like legacy -- could also be the path to a shared object with possible embedded space in the path name. A single option with optional quotes, picked apart using ":" as separator can still work.
Ideally I would have preferred space separated provider names with each quoted if needed, but the format proposed here may be easier to parse. Need clear documentation, though.
(ii) We may want to attach some meaning to the order in which providers are specified. Here is why:
When multiple providers implement the same method (say, KEYEXCH), there is no guarantee in OpenSSL as to which will get used. Unless a property query like "?provider=my-fast-aes" is also used. Here the prefix "?" to mean preferred but not exclusive. In cases like an pkcs11 token provider, one would need to say the opposite like "?provider=default" to ensure default is preferred and the token provider is to be used only when required -- say when the key is in a token. Same would be the case with our proposed built-in "external-key provider" which should be used only for certain operations that handle the external key.
How this relates to the --provider option is like this: in some cases we want to know which provider the user prefers. Instead of hard-coding the preferred provider to "default" which the user may not even want to load. We could state that the first provider specified will become the preferred one when there are multiple choices for a method or when a preferred fallback is required. In that case the option for legacy would be
--provider default:legacy
And, if this option is absent, we take it to mean that the "default" provider should be loaded. This explicit loading of providers takes away some ambiguity regarding which one's are made available. However, this could conflict with what is in the OpenSSL config file. Which is not a bad thing as we probably should not use the config file to load providers (which we currently do) -- it's not supported on some platforms (Windows as of now) and can lead to broken setups due to user error.
At the same time, provider paths and their names could be set up in OpenSSL config files, so loading them through config has some advantages. So, an alternate option is to not add this option at all and require the use of a config file to load additional providers like "legacy + default". Loading a custom config file is possible with OpenSSL 3.0 and could be enabled on Windows in a safe manner.
Or always load providers from OPENSSL config and use the "--provider foo" on top of that.
We could also consider a separate option to specify a preferred property query ("?provider=myprov") that could be added later and not rely on any ordering here.
The above is just meant for further discussion -- I'm not entirely sure what the best approach is.
Regards,
Selva
Re: [Openvpn-devel] [PATCH v3 12/21] [OSSL 3.0] Allow loading of non default providers
Am 20.10.21 um 20:19 schrieb Selva Nair:
Quoted 16 lines
Hi,
Not a code review but a general comment as this is a new option that warrants some discussion.
On Tue, Oct 19, 2021 at 2:32 PM Arne Schwabe <[email protected]... <mailto:[email protected]...>> wrote:
This allows OpenVPN to load non-default providers. This is mainly useful for loading the legacy provider with --provider legacy:default
While this format looks okay, we need to consider a few things to get this option right and possibly extensible in future without causing a regression.
Quoted 8 lines
(i) Provider name may not be a simple word like legacy -- could also be the path to a shared object with possible embedded space in the path name. A single option with optional quotes, picked apart using ":" as separator can still work.
Ideally I would have preferred space separated provider names with each quoted if needed, but the format proposed here may be easier to parse. Need clear documentation, though.
Yeah using : was easier to parse since I need otherwise to setup an array or a list to store the parameter but it is doable. I was just hoping that nobody would use a : in the provider name.
Quoted 2 lines
(ii) We may want to attach some meaning to the order in which providers are specified.
That would be mostly a documentation thing to explain that the providers are loaded the in order specified with that option.
Here is why:
Quoted 18 lines
When multiple providers implement the same method (say, KEYEXCH), there is no guarantee in OpenSSL as to which will get used. Unless a property query like "?provider=my-fast-aes" is also used. Here the prefix "?" to mean preferred but not exclusive. In cases like an pkcs11 token provider, one would need to say the opposite like "?provider=default" to ensure default is preferred and the token provider is to be used only when required -- say when the key is in a token. Same would be the case with our proposed built-in "external-key provider" which should be used only for certain operations that handle the external key.
How this relates to the --provider option is like this: in some cases we want to know which provider the user prefers. Instead of hard-coding the preferred provider to "default" which the user may not even want to load. We could state that the first provider specified will become the preferred one when there are multiple choices for a method or when a preferred fallback is required. In that case the option for legacy would be
Quoted 4 lines
--provider default:legacy
And, if this option is absent, we take it to mean that the "default" provider should be loaded.
I would not explicitly load the default provider then but rather inherit what the system gives us. If the system wide config loads fips we should not load default instead.
Quoted 7 lines
This explicit loading of providers takes away
some ambiguity regarding which one's are made available. However, this could conflict with what is in the OpenSSL config file. Which is not a bad thing as we probably should not use the config file to load providers (which we currently do) -- it's not supported on some platforms (Windows as of now) and can lead to broken setups due to user error.
Yeah. I agree on that. I needed this for ANdroid where I also don't have a OpenSSL and adding one is not something I really want to do.
Quoted 10 lines
At the same time, provider paths and their names could be set up in OpenSSL config files, so loading them through config has some advantages. So, an alternate option is to not add this option at all and require the use of a config file to load additional providers like "legacy + default". Loading a custom config file is possible with OpenSSL 3.0 and could be enabled on Windows in a safe manner.
Or always load providers from OPENSSL config and use the "--provider foo" on top of that.
Quoted 6 lines
We could also consider a separate option to specify a preferred property query ("?provider=myprov") that could be added later and not rely on any ordering here.
The above is just meant for further discussion -- I'm not entirely sure what the best approach is.
No, me neither.
Arne
Re: [Openvpn-devel] [PATCH v3 12/21] [OSSL 3.0] Allow loading of non default providers
Quoted 22 lines · Arne Schwabe
Am 20.10.21 um 20:19 schrieb Selva Nair:
Quoted 21 lines
Hi,
Not a code review but a general comment as this is a new option that warrants some discussion.
On Tue, Oct 19, 2021 at 2:32 PM Arne Schwabe <[email protected]... <mailto:[email protected]...>> wrote:
This allows OpenVPN to load non-default providers. This is mainly useful for loading the legacy provider with --provider legacy:default
While this format looks okay, we need to consider a few things to get this option right and possibly extensible in future without causing a regression.
(i) Provider name may not be a simple word like legacy -- could also be the path to a shared object with possible embedded space in the path name. A single option with optional quotes, picked apart using ":" as separator can still work.
Quoted 9 lines
Quoted 3 lines
Ideally I would have preferred space separated provider names with each quoted if needed, but the format proposed here may be easier to parse. Need clear documentation, though.
Yeah using : was easier to parse since I need otherwise to setup an array or a list to store the parameter but it is doable. I was just hoping that nobody would use a : in the provider name.
Use of '.' in the name is the recommended method to have a namespace in the provider name and reduce chances of name conflict. No one may use ':' and filenames are unlikely to contain ':' as its not legal in some platforms.
That said, adding an array or list is easier than it looks. We have several options that use an array or list and the code overhead is small.
Quoted 28 lines
Quoted 3 lines
(ii) We may want to attach some meaning to the order in which providers are specified.
That would be mostly a documentation thing to explain that the providers are loaded the in order specified with that option.
Here is why:
Quoted 11 lines
When multiple providers implement the same method (say, KEYEXCH), there is no guarantee in OpenSSL as to which will get used. Unless a property query like "?provider=my-fast-aes" is also used. Here the prefix "?" to mean preferred but not exclusive. In cases like an pkcs11 token provider, one would need to say the opposite like "?provider=default" to ensure default is preferred and the token provider is to be used only when required -- say when the key is in a token. Same would be the case with our proposed built-in "external-key provider" which should be used only for certain operations that handle the external key.
Quoted 6 lines
How this relates to the --provider option is like this: in some cases we want to know which provider the user prefers. Instead of hard-coding the preferred provider to "default" which the user may not even want to load. We could state that the first provider specified will become the preferred one when there are multiple choices for a method or when a preferred fallback is required. In that case the option for legacy would
be
Quoted 1 line
Quoted 9 lines
Quoted 4 lines
--provider default:legacy
And, if this option is absent, we take it to mean that the "default" provider should be loaded.
I would not explicitly load the default provider then but rather inherit what the system gives us. If the system wide config loads fips we should not load default instead.
IMO, this idea that OpenSSL folks have that just adding a "fips=yes" plus a few lines in the config can make the application FIPS enabled is far-fetched. In reality OpenVPN will have to be recompiled with some changes to make it FIPS compliant. At that point one can also change what providers are loaded by default.
I was thinking of having a load_providers() function called early -- say in options-post-process stage where we load
(i) default provider
(ii) providers specified in --providers option
This adds much certainty to what is available. A FIPS-enabled OpenVPN can change this or we could have a --fips option that changes this. No dependency on system-wide config file and those who need legacy only need to just specify "--providers legacy"
In addition, one could automatically load "legacy" if any of the options indicate its need -- like NTLM auth for proxy or BF-CBC in --data-ciphers etc. In situations where it cannot be inferred from options, user will have to use --providers legacy, though.
It may be necessary to call this load_providers() also to process options like --show-ciphers and similar.
Selva
Re: [Openvpn-devel] [PATCH v3 12/21] [OSSL 3.0] Allow loading of non default providers
Quoted 6 lines
IMO, this idea that OpenSSL folks have that just adding a "fips=yes" plus a few lines in the config can make the application FIPS enabled is far-fetched. In reality OpenVPN will have to be recompiled with some changes to make it FIPS compliant. At that point one can also change what providers are loaded by default.
There is a wide range between completely fully FIPS compliant and non-FIPS compliant. Especially on Red Hat Enterprise, you can set the system to a FIPS mode where OpenSSL stops offering non FIPS algorithms and also other crypto libraries do not do non-FIPS algorithms anymore.
And I put some effort into making OpenVPN still behave nicely in those situations. It is not really compliant/certified per se but for a lot of customers that is "good enough".
The "fips=yes" is similiar I think. It is "good enough" for many people.
Quoted 2 lines
I was thinking of having a
load_providers()function called early -- say in options-post-process stage where we load
This commit already loads them as early as possible after parsing options if the option is enabled.
Quoted 9 lines
(i) default provider
(ii) providers specified in --providers optionThis adds much certainty to what is available. A FIPS-enabled OpenVPN can change this or we could have a --fips option that changes this. No dependency on system-wide config file and those who need legacy only need to just specify "--providers legacy"
Quoted 7 lines
In addition, one could automatically load "legacy" if any of the options indicate its need -- like NTLM auth for proxy or BF-CBC in --data-ciphers etc. In situations where it cannot be inferred from options, user will have to use --providers legacy, though.
It may be necessary to call this
load_providers()also to process options like --show-ciphers and similar.
No. I am actually against loading legacy on demand or loading the default provider if --provider is not specified. Often there are system wide security defaults in place and I don't think OpenVPN should override them unless explicitly instructed to do so.
Especially in the Red Hat Enterprise 9 or whatever will have OpenSSL 3.0 I would expect in fips mode to switch to a global config of OpenSSL that uses the FIPS provider instead of default. And I don't want to break that by loading default.
Arne
Re: [Openvpn-devel] [PATCH v3 12/21] [OSSL 3.0] Allow loading of non default providers
Hi
No. I am actually against loading legacy on demand or loading the
Quoted 4 lines
default provider if --provider is not specified. Often there are system wide security defaults in place and I don't think OpenVPN should override them unless explicitly instructed to do so.
Okay, that adds some clarity :)
In that case let the system default + explicit options take control. If that breaks anything or causes an error, we can try our best to print a helpful error message.
Selva
Re: [Openvpn-devel] [PATCH v3 12/21] [OSSL 3.0] Allow loading of non default providers
In reply to Arne SchwabeHi,
Some very minor nits and a couple of points that would require a v4:
Quoted 20 lines · Arne Schwabe
This allows OpenVPN to load non-default providers. This is mainly useful for loading the legacy provider with --provider legacy:default
Signed-off-by Arne Schwabe <[email protected]...>--- doc/man-sections/generic-options.rst | 10 ++++++++++ src/openvpn/crypto_backend.h | 7 +++++++ src/openvpn/crypto_mbedtls.c | 8 ++++++++ src/openvpn/crypto_openssl.c | 29 ++++++++++++++++++++++++++++ src/openvpn/openvpn.c | 4 ++++ src/openvpn/options.c | 4 ++++ src/openvpn/options.h | 1 + 7 files changed, 63 insertions(+)doc/man-sections/generic-options.rst +0
-0
doc/man-sections/generic-options.rst which mode OpenVPN is configured as. · line 283
Quoted 4 lines
doc/man-sections/generic-options.rst +1
-0@@ -280,6 +280,16 @@ which mode OpenVPN is configured as. This option solves the problem by persisting keys across :code:`SIGUSR1` resets, so they don't need to be re-read. +--provider providers
+ Load the : separated list of (OpenSSL) providers. This is mainly useful
doc/man-sections/generic-options.rst which mode OpenVPN is configured as. · line 290
Quoted 8 lines
for
+ using an external provider for key management like tpm2-openssl or to loaddoc/man-sections/generic-options.rst +5
-0+ the legacy provider with + + :: + + --provider "legacy:default"
Please consider renaming the option as "--providers" in plural.
Quoted 1 line
+
+
Quoted 61 lines
--remap-usr1 signal
Control whether internally or externally generated :code:SIGUSR1
signals
are remapped to :code:SIGHUP(restart without persisting state) orsrc/openvpn/crypto_backend.h +7
-0@@ -78,6 +78,13 @@ void crypto_clear_error(void);*/ void crypto_init_lib_engine (const char *engine_name); + +/** +* Load the given (OpenSSL) providers +* @param providers list of providers to load, seperated by : +*/ +void crypto_init_lib_provider (const char *providers); +#ifdef DMALLOC /* * OpenSSL memory debugging. If dmalloc debugging is enabled, tell src/openvpn/crypto_mbedtls.c +8
-0@@ -70,6 +70,14 @@ crypto_init_lib_engine(const char *engine_name) "available"); } +void crypto_init_lib_provider (const char *providers) +{ +if (providers) + { +msg (M_WARN ,"Note: mbed TLS provider functionality is not available"); + } +} +/* * * Functions related to the core crypto library
src/openvpn/crypto_openssl.c +3
-0@@ -54,6 +54,9 @@#if (OPENSSL_VERSION_NUMBER >=0x10100000L ) && !defined(LIBRESSL_VERSION_NUMBER )#include <openssl/kdf.h> #endif +#if OPENSSL_VERSION_NUMBER >=0x30000000L +#include <openssl/provider.h> +#endif /* * Check for key size creepage.
src/openvpn/crypto_openssl.c +0
-0@@ -145,6 +148,32 @@ crypto_init_lib_engine(const char *engine_name)#endif }
src/openvpn/crypto_openssl.c crypto_init_lib_engine(const char *engine_name) · line 160
Quoted 10 lines
src/openvpn/crypto_openssl.c +10
-0+void +crypto_init_lib_provider (const char *providers) +{ +if (!providers) + { +return ; + } +#if OPENSSL_VERSION_NUMBER >=0x30000000L +struct gc_arena gc =gc_new (); +char *tmp_providers =string_alloc (providers, &gc);
+
src/openvpn/crypto_openssl.c crypto_init_lib_engine(const char *engine_name)
Quoted 10 lines
src/openvpn/crypto_openssl.c +9
-0+const char *provname; +while ((provname =strsep (&tmp_providers,":" ))) + { +/* Load providers into the default (NULL) library context */ +OSSL_PROVIDER * provider =OSSL_PROVIDER_load (NULL , provname); +if (!provider) + { +crypto_msg (M_FATAL ,"failed to load provider '%s'" , provname); + }
The gc has to be freed here.
src/openvpn/crypto_openssl.c crypto_init_lib_engine(const char *engine_name) · line 175
Quoted 5 lines
src/openvpn/crypto_openssl.c +3
-0+ } +#else /* OPENSSL_VERSION_NUMBER >= 0x30000000L */ + msg(M_WARN, "Note: OpenSSL hardware crypto engine functionality is not available");
"hardware crypto engine" --> "provider"
+#endif
Quoted 10 lines
src/openvpn/crypto_openssl.c +2
-0+} +/* * * Functions related to the core crypto library src/openvpn/openvpn.c +0
-0
src/openvpn/openvpn.c void init_early(struct context *c) · line 118
Quoted 7 lines
src/openvpn/openvpn.c +4
-0@@ -112,6 +112,10 @@ void init_early(struct context *c)/* init verbosity and mute levels */ init_verb_mute (c,IVM_LEVEL_1 ); +/* Initialise OpenVPN provider, this needs to be intialised this +* early since option post processing and also openssl info +* printing depends on it */ +crypto_init_lib_provider ((*c).options.providers);
c->options.providers
Quoted 23 lines
src/openvpn/openvpn.c +0
-0}static void uninit_early (struct context *c)src/openvpn/options.c +4
-0@@ -8178,6 +8178,10 @@ add_option(struct options *options, options->engine = "auto"; } } +else if (streq (p[0 ],"provider" ) && p[1 ] && !p[2 ]) + { + options->providers = p[1 ]; + }#endif /* ENABLE_CRYPTO_MBEDTLS */ #ifdef ENABLE_PREDICTION_RESISTANCE else if (streq(p[0], "use-prediction-resistance") && !p[1])src/openvpn/options.h +0
-0
src/openvpn/options.h struct options · line 527
Quoted 7 lines
src/openvpn/options.h +1
-0@@ -521,6 +521,7 @@ struct optionsconst char *prng_hash;int prng_nonce_secret_len;const char *engine; +const char *providers;bool replay;bool mute_replay_warnings;int replay_window;
--
We should not repeatedly load providers in each SIGHUP loop without unloading them in some uninit() call. That would require saving pointers to these explicitly loaded providers, unfortunately...
Selva
Re: [Openvpn-devel] [PATCH v3 12/21] [OSSL 3.0] Allow loading of non default providers
Hi,
I have caused more than enough chatter about this patch, hopefully this is the last comment
Quoted 5 lines · I previously
We should not repeatedly load providers in each SIGHUP loop without unloading them in some
uninit()call. That would require saving pointers to these explicitly loaded providers, unfortunately...
I want to suggest an alternative: act on this option only the first time, not in every SIGHUP loop. The reason being it's not easy to support changing of loaded providers in the default libctx during every SIGHUP in a good way:
OpenSSL will parse its config file only once and cannot be convinced to do it again at SIGHUP. Also it will attempt to do the automatic provider loading only once (the so-called fallback to default). That means, running with "--providers foo" and doing a SIGHUP with that option removed from the config file will result in no providers if we unload "foo". If we do not unload it on SIGHUP, it will always be loaded contrary to user intent, as well as leak memory due to multiple loads.
Just document that "--providers" will be parsed once and the program has to be restarted to change it.
There are other approaches like swapping the default libctx, but not worth the trouble, IMO.
Selva
Quoted 1 line
PATCH v3 13/21 Remove dependency on BF-CBC existance from test_ncp
In reply to Arne SchwabeThe test_check_ncp_ciphers_list test assumed that BF-CBC is always available, which is no longer the case with OpenSSL 3.0. Rewrite the test to not rely on BF-CBC to be available.
--- tests/unit_tests/openvpn/test_ncp.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
tests/unit_tests/openvpn/test_ncp.c +10 -3
@@ -41,6 +41,7 @@/* Defines for use in the tests and the mock parse_line() */ const char *bf_chacha ="BF-CBC:CHACHA20-POLY1305" ; +const char *aes_chacha ="AES-128-CBC:CHACHA20-POLY1305" ;const char *aes_ciphers ="AES-256-GCM:AES-128-GCM" ;
@@ -59,6 +60,7 @@ test_check_ncp_ciphers_list(void **state) {struct gc_arena gc =gc_new ();bool have_chacha =cipher_kt_get ("CHACHA20-POLY1305" ); +bool have_blowfish=cipher_kt_get ("BF-CBC" );assert_string_equal (mutate_ncp_cipher_list ("none" , &gc),"none" ); assert_string_equal(mutate_ncp_cipher_list("AES-256-GCM:none", &gc),
@@ -66,7 +68,12 @@ test_check_ncp_ciphers_list(void **state)assert_string_equal (mutate_ncp_cipher_list (aes_ciphers, &gc), aes_ciphers); -if (have_chacha) +if (have_chacha) + { +assert_string_equal (mutate_ncp_cipher_list (aes_chacha, &gc), aes_chacha); + } + +if (have_chacha && have_blowfish) {assert_string_equal (mutate_ncp_cipher_list (bf_chacha, &gc), bf_chacha); assert_string_equal(mutate_ncp_cipher_list("BF-CBC:CHACHA20-POLY1305", &gc),
@@ -82,8 +89,8 @@ test_check_ncp_ciphers_list(void **state)bool have_chacha_mixed_case =cipher_kt_get ("ChaCha20-Poly1305" );if (have_chacha_mixed_case) { -assert_string_equal (mutate_ncp_cipher_list ("BF-CBC:ChaCha20-Poly1305" , &gc), - bf_chacha); +assert_string_equal (mutate_ncp_cipher_list ("AES-128-CBC:ChaCha20-Poly1305" , &gc), + aes_chacha); }assert_ptr_equal (mutate_ncp_cipher_list ("vollbit" , &gc),NULL );
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 13/21] [OSSL 3.0] Remove dependency on BF-CBC existance from test_ncp
Quoted 3 lines · Arne Schwabe
The
test_check_ncp_ciphers_listtest assumed that BF-CBC is always available, which is no longer the case with OpenSSL 3.0. Rewrite the test to not rely on BF-CBC to be available.
Unit tests are working now. I've got some style nitpicks that I think can be fixed during commit:
Quoted 2 lines
bool have_chacha = cipher_kt_get("CHACHA20-POLY1305");+ bool have_blowfish=
cipher_kt_get("BF-CBC");
Add space before =
tests/unit_tests/openvpn/test_ncp.c test_check_ncp_ciphers_list(void **state) · line 74
Quoted 5 lines
tests/unit_tests/openvpn/test_ncp.c +4
-1-if (have_chacha) +if (have_chacha) + { +assert_string_equal (mutate_ncp_cipher_list (aes_chacha, &gc), aes_chacha); + }
Add space before (
[Openvpn-devel] [PATCH applied] Re: Remove dependency on BF-CBC existance from test_ncp
In reply to Arne SchwabeI can confirm that this fixes ncp_testdriver for 3.0.0 builds, which is what it says :-) (and 1.1.1 builds still succeed).
Took me a bit to understand the new if/else clauses, but after a while it started making sense :-)
Your patch has been applied to the master branch.
commit c07f95f3cacdf7c877762db8d1a3f7cf0a4a4675
Author: Arne Schwabe Date: Tue Oct 19 20:31:19 2021 +0200
Remove dependency on BF-CBC existance from test_ncp
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Max Fillinger <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23003.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 14/21 Use TYPE_do_all_provided function for listing cipher/digest
In reply to Arne SchwabeWith OpenSSL 3.0 the use of nid values is deprecated and new algorithms do not even have NID values anymore.
This also works nicely with providers now:
openvpn --provider legacy:default --show-ciphers
shows more ciphers (e.g. BF-CBC) than just
openvpn --show-ciphers
when compiled with OpenSSL 3.0
--- src/openvpn/crypto_openssl.c | 95 +++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 34 deletions(-)
src/openvpn/crypto_openssl.c +61 -34
@@ -311,86 +311,113 @@ cipher_name_cmp(const void *a, const void *b)return strcmp (cipher_kt_name (*cipher_a),cipher_kt_name (*cipher_b)); } +struct collect_ciphers { +/* If we ever exceed this, we must be more selective */ +const EVP_CIPHER *list[1000 ]; +size_t num; +}; + +static void collect_ciphers (EVP_CIPHER *cipher,void *list) +{ +struct collect_ciphers * cipher_list = list; +if (cipher_list->num == (sizeof (cipher_list->list)/sizeof (*cipher_list->list))) + { +msg (M_WARN ,"WARNING: Too many ciphers, not showing all" ); +return ; + } + + if (cipher && (cipher_kt_mode_cbc(cipher) +#ifdef ENABLE_OFB_CFB_MODE + ||cipher_kt_mode_ofb_cfb (cipher) +#endif + ||cipher_kt_mode_aead (cipher) + )) + { + cipher_list->list[cipher_list->num++] = cipher; + } +} +void show_available_ciphers (void ) { -int nid; -size_t i; +struct collect_ciphers cipher_list = {0 }; -/* If we ever exceed this, we must be more selective */ -const EVP_CIPHER *cipher_list[1000 ]; -size_t num_ciphers =0 ;#ifndef ENABLE_SMALL printf ("The following ciphers and cipher modes are available for use\n" "with " PACKAGE_NAME ". Each cipher shown below may be used as a\n" "parameter to the --data-ciphers (or --cipher) option. In static \n" -"key mode only CBC mode is allowed.\n\n" ); +"key mode only CBC mode is allowed.\n" ); +printf ("See also openssl list -cipher-algorithms\n\n" );#endif -for (nid =0 ; nid <10000 ; ++nid) +#if OPENSSL_VERSION_NUMBER >=0x30000000L +EVP_CIPHER_do_all_provided (NULL , collect_ciphers, &cipher_list); +#else +for (int nid =0 ; nid <10000 ; ++nid) {const EVP_CIPHER *cipher =EVP_get_cipherbynid (nid); - if (cipher && (cipher_kt_mode_cbc(cipher) -#ifdef ENABLE_OFB_CFB_MODE - ||cipher_kt_mode_ofb_cfb (cipher) -#endif - ||cipher_kt_mode_aead (cipher) - )) - { - cipher_list[num_ciphers++] = cipher; - } -if (num_ciphers == (sizeof (cipher_list)/sizeof (*cipher_list))) - { -msg (M_WARN ,"WARNING: Too many ciphers, not showing all" ); -break ; - } +/* We cast the const away so we can keep the function prototype +* compatible with EVP_CIPHER_do_all_provided */ +collect_ciphers ((EVP_CIPHER *)cipher, &cipher_list); } +#endif /* cast to non-const to prevent warning */ -qsort ((EVP_CIPHER *)cipher_list, num_ciphers,sizeof (*cipher_list), cipher_name_cmp); +qsort ((EVP_CIPHER *)cipher_list.list, cipher_list.num,sizeof (*cipher_list.list), cipher_name_cmp); -for (i =0 ; i < num_ciphers; i++) +for (size_t i =0 ; i < cipher_list.num; i++) { -if (!cipher_kt_insecure (cipher_list[i])) +if (!cipher_kt_insecure (cipher_list.list[i])) { -print_cipher (cipher_list[i]); +print_cipher (cipher_list.list[i]); } }printf ("\nThe following ciphers have a block size of less than 128 bits, \n" "and are therefore deprecated. Do not use unless you have to.\n\n" ); -for (i =0 ; i < num_ciphers; i++) +for (int i =0 ; i < cipher_list.num; i++) { -if (cipher_kt_insecure (cipher_list[i])) +if (cipher_kt_insecure (cipher_list.list[i])) { -print_cipher (cipher_list[i]); +print_cipher (cipher_list.list[i]); } }printf ("\n" ); }void -show_available_digests (void ) +print_digest (EVP_MD * digest,void * unused) { -int nid; +printf ("%s %d bit digest size\n" ,EVP_MD_get0_name (digest), +EVP_MD_size (digest) *8 ); +} +void +show_available_digests (void ) +{#ifndef ENABLE_SMALL printf ("The following message digests are available for use with\n" PACKAGE_NAME ". A message digest is used in conjunction with\n" "the HMAC function, to authenticate received packets.\n" "You can specify a message digest as parameter to\n" -"the --auth option.\n\n" ); +"the --auth option.\n" ); +printf ("See also openssl list -digest-algorithms\n\n" );#endif -for (nid =0 ; nid <10000 ; ++nid) +#if OPENSSL_VERSION_NUMBER >=0x30000000L +EVP_MD_do_all_provided (NULL , print_digest,NULL ); +#else +for (int nid =0 ; nid <10000 ; ++nid) {const EVP_MD *digest =EVP_get_digestbynid (nid);if (digest) { -printf ("%s %d bit digest size\n" , -OBJ_nid2sn (nid),EVP_MD_size (digest) *8 ); +/* We cast the const away so we can keep the function prototype +* compatible with EVP_MD_do_all_provided */ +print_digest ((EVP_MD *)digest,NULL ); } } +#endif printf ("\n" ); }
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 14/21] [OSSL 3.0] Use TYPE_do_all_provided function for listing cipher/digest
Quoted 7 lines · Arne Schwabe
With OpenSSL 3.0 the use of nid values is deprecated and new algorithms do not even have NID values anymore.
This also works nicely with providers now:
openvpn --provider legacy:default --show-ciphers
Quoted 7 lines
shows more ciphers (e.g. BF-CBC) than just
openvpn --show-cipherswhen compiled with OpenSSL 3.0
Signed-off-by Arne Schwabe <[email protected]...>
Looks good, and the tests work with OpenSSL 3 and OpenSSL 1.1.1 when I also apply the "Do not allow CTS ciphers" patch.
One nitpick:
Quoted 4 lines
src/openvpn/crypto_openssl.c +4
-0+struct collect_ciphers { +/* If we ever exceed this, we must be more selective */ +const EVP_CIPHER *list[1000 ]; +size_t num;
src/openvpn/crypto_openssl.c cipher_name_cmp(const void *a, const void *b) · line 327
Quoted 10 lines
src/openvpn/crypto_openssl.c +10
-0+}; + +static void collect_ciphers (EVP_CIPHER *cipher,void *list) +{ +struct collect_ciphers * cipher_list = list; +if (cipher_list->num == (sizeof (cipher_list->list)/sizeof (*cipher_list->list))) + { +msg (M_WARN ,"WARNING: Too many ciphers, not showing all" ); +return ; + }
I think it would be more readable to use a const (or a #define) for the length of the cipher list array, instead of using sizeof.
Re: [Openvpn-devel] [PATCH v3 14/21] [OSSL 3.0] Use TYPE_do_all_provided function for listing cipher/digest
Quoted 32 lines · Max Fillinger
Quoted 7 lines · Arne Schwabe
With OpenSSL 3.0 the use of nid values is deprecated and new algorithms do not even have NID values anymore.
This also works nicely with providers now:
openvpn --provider legacy:default --show-ciphersQuoted 7 lines
shows more ciphers (e.g. BF-CBC) than just
openvpn --show-cipherswhen compiled with OpenSSL 3.0
Signed-off-by Arne Schwabe <[email protected]...>Looks good, and the tests work with OpenSSL 3 and OpenSSL 1.1.1 when I also apply the "Do not allow CTS ciphers" patch.
One nitpick:
src/openvpn/crypto_openssl.c cipher_name_cmp(const void *a, const void *b)
Quoted 10 lines
src/openvpn/crypto_openssl.c +10
-0+struct collect_ciphers { +/* If we ever exceed this, we must be more selective */ +const EVP_CIPHER *list[1000 ]; +size_t num; +}; + +static void collect_ciphers (EVP_CIPHER *cipher,void *list) +{ +struct collect_ciphers * cipher_list = list; + if (cipher_list->num ==(sizeof(cipher_list->list)/sizeof(*cipher_list->list)))
Quoted 8 lines
src/openvpn/crypto_openssl.c cipher_name_cmp(const void *a, const void *b) · line 327
Quoted 4 lines
src/openvpn/crypto_openssl.c +4
-0+ { +msg (M_WARN ,"WARNING: Too many ciphers, not showing all" ); +return ; + }I think it would be more readable to use a const (or a #define) for the length of the cipher list array, instead of using sizeof.
IIRC, we have SIZE(x) = sizeof(x)/sizeof(*x) defined in some header for this.
Selva
PATCH v3 15/21 Do not allow CTS ciphers
In reply to Arne SchwabeWe do not support CTS algorithms (cipher text stealing) algorithms.
--- src/openvpn/crypto_openssl.c | 3 +++ 1 file changed, 3 insertions(+)
src/openvpn/crypto_openssl.c +3 -0
@@ -760,6 +760,9 @@ cipher_kt_mode_cbc(const cipher_kt_t *cipher) {return cipher &&cipher_kt_mode (cipher) ==OPENVPN_MODE_CBC /* Exclude AEAD cipher modes, they require a different API */ +#ifdef EVP_CIPH_FLAG_CTS + && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_CTS) +#endif && !(EVP_CIPHER_flags (cipher) &EVP_CIPH_FLAG_AEAD_CIPHER ); }
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 15/21] [OSSL 3.0] Do not allow CTS ciphers
Quoted 13 lines · Arne Schwabe
We do not support CTS algorithms (cipher text stealing) algorithms.
Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/crypto_openssl.c | 3 +++ 1 file changed, 3 insertions(+)src/openvpn/crypto_openssl.c +0
-0
src/openvpn/crypto_openssl.c cipher_kt_mode_cbc(const cipher_kt_t *cipher) · line 768
Quoted 9 lines
src/openvpn/crypto_openssl.c +3
-0@@ -760,6 +760,9 @@ cipher_kt_mode_cbc(const cipher_kt_t *cipher) {return cipher &&cipher_kt_mode (cipher) ==OPENVPN_MODE_CBC /* Exclude AEAD cipher modes, they require a different API */ +#ifdef EVP_CIPH_FLAG_CTS + && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_CTS) +#endif && !(EVP_CIPHER_flags (cipher) &EVP_CIPH_FLAG_AEAD_CIPHER ); }
Together with the previous patch, this makes the tests work. One thing I'm unsure about is that this check is only done for CBC mode. Cipher-text stealing can be used in *any* block cipher mode (even CTR, though that would be amazingly pointless).
I compiled OpenVPN with support for OFB and CFB modes and didn't see any CTS in the --show-ciphers output. But do we know for sure that there's no supported version or configuration of OpenSSL that uses cipher-text stealing in non-CBC modes?
Max Fillinger
Acked-byRe: [Openvpn-devel] [PATCH v3 15/21] [OSSL 3.0] Do not allow CTS ciphers
Quoted 25 lines · Max Fillinger
Quoted 18 lines · Arne Schwabe
We do not support CTS algorithms (cipher text stealing) algorithms.
Signed-off-by Arne Schwabe <[email protected]...>---
src/openvpn/crypto_openssl.c| 3 +++1 file changed, 3 insertions(+)src/openvpn/crypto_openssl.c +0
-0@@ -760,6 +760,9 @@ cipher_kt_mode_cbc(const cipher_kt_t *cipher) {return cipher &&
cipher_kt_mode(cipher)==OPENVPN_MODE_CBC/* Exclude AEAD cipher modes, they require a different API */src/openvpn/crypto_openssl.c +3
-0+#ifdef EVP_CIPH_FLAG_CTS + && !(EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_CTS) +#endif Quoted 3 lines
&& !(EVP_CIPHER_flags(cipher) &
EVP_CIPH_FLAG_AEAD_CIPHER); }Together with the previous patch, this makes the tests work. One thing I'm unsure about is that this check is only done for CBC mode. Cipher-text stealing can be used in *any* block cipher mode (even CTR, though that would be amazingly pointless).
Quoted 1 line
I compiled OpenVPN with support for OFB and CFB modes and didn't see any CTS in the --show-ciphers output. But do we know for sure that there's no supported version or configuration of OpenSSL that uses cipher-text stealing in non-CBC modes?
Disregard that. I keep forgetting how OFB and CFB work. They don't need any padding so ciphertext stealing would be pointless here.
[Openvpn-devel] [PATCH applied] Re: Do not allow CTS ciphers
In reply to Arne SchwabeLightly client-side tested on OpenSSL 1.1.x and 3.0. No surprises.
Your patch has been applied to the master branch.
commit 14e4f3b1583749adf104be362a3e2422e0c9e524
Author: Arne Schwabe Date: Tue Oct 19 20:31:21 2021 +0200
Do not allow CTS ciphers
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Max Fillinger <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23002.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 16/21 Add message when decoding PKCS12 file fails.
In reply to Arne SchwabeCurrently we never display the OpenSSL error stack when decoding a PCKS12 file fails. With LibreSSL defaulting to RC2-40-CBC, the failure might not be a wrong password but can actually be an unsupported encoding, seeing the error stack is really helpful (example from OpenSSL 3.0):
error:0308010C:digital envelope routines:inner_evp_generic_fetch:unsupported:crypto/evp/evp_fetch.c:346:Global default library context, Algorithm (RC2-40-CBC : 0), Properties ()
to pinpoint the issue
--- src/openvpn/ssl_openssl.c | 2 ++ 1 file changed, 2 insertions(+)
src/openvpn/ssl_openssl.c +2 -0
@@ -831,6 +831,8 @@ tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file, ca =NULL ;if (!PKCS12_parse (p12, password, &pkey, &cert, &ca)) { +crypto_msg (M_WARN ,"Decoding PKCS12 failed. Probably wrong password " +"or unsupported/legacy encryption" );#ifdef ENABLE_MANAGEMENT if (management && (ERR_GET_REASON (ERR_peek_error ()) ==PKCS12_R_MAC_VERIFY_FAILURE )) {
Signature · 1 line
2.33.0
[Openvpn-devel] [PATCH applied] Re: Add message when decoding PKCS12 file fails.
"That was an easy one" :-) - error reporting is always useful, and the code change is trivial enough. Tested with "wrong password" only, which now prints:
2021-10-21 08:24:01 OpenSSL: error:23076071:PKCS12 routines:PKCS12_parse:mac verify failure 2021-10-21 08:24:01 OpenSSL: error:23076071:PKCS12 routines:PKCS12_parse:mac verify failure 2021-10-21 08:24:01 Decoding PKCS12 failed. Probably wrong password or unsupported/legacy encryption 2021-10-21 08:24:01 SIGUSR1[soft,private-key-password-failure] received, process restarting
Your patch has been applied to the master branch.
commit 6ac4e63c577986ec11eae3519fe8516e8ca8ac0f
Author: Arne Schwabe Date: Tue Oct 19 20:31:22 2021 +0200
Add message when decoding PKCS12 file fails.
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23017.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH applied] Re: Add message when decoding PKCS12 file fails.
Hi,
decided in the community meeting today that this should also be cherry-picked to 2.5 - I have not actually tested with a pkcs12 file, just run the basic compile/client test cycle (and the patch is trivial enough).
commit 1f54811e92c89fe07d7cea8339e928980bfe0536 (HEAD -> release/2.5)
Author: Arne Schwabe <[email protected]...> Date: Tue Oct 19 20:31:22 2021 +0200
Add message when decoding PKCS12 file fails.
gert
Quoted 38 lines · Gert Doering
Acked-by Gert Doering <[email protected]...>"That was an easy one" :-) - error reporting is always useful, and the code change is trivial enough. Tested with "wrong password" only, which now prints:
2021-10-21 08:24:01 OpenSSL: error:23076071:PKCS12 routines:PKCS12_parse:mac verify failure 2021-10-21 08:24:01 OpenSSL: error:23076071:PKCS12 routines:PKCS12_parse:mac verify failure 2021-10-21 08:24:01 Decoding PKCS12 failed. Probably wrong password or unsupported/legacy encryption 2021-10-21 08:24:01 SIGUSR1[soft,private-key-password-failure] received, process restartingYour patch has been applied to the master branch.
commit
6ac4e63c577986ec11eae3519fe8516e8ca8ac0fAuthor: Arne Schwabe Date: Tue Oct 19 20:31:22 2021 +0200Add message when decoding PKCS12 file fails. Signed-off-by: Arne Schwabe <[email protected]...> Acked-by: Gert Doering <[email protected]...> Message-Id: <[email protected]...> URL: https://www.mail-archive.com/[email protected]/msg23017.html Signed-off-by: Gert Doering <[email protected]...>--
kind regards,Gert Doering
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...PATCH v3 17/21 Add small unit test for testing HMAC
In reply to Arne SchwabeThis just adds a very simple unit test to check that the HMAC implementation produces a well known hash.
--- tests/unit_tests/openvpn/test_crypto.c | 61 +++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 7 deletions(-)
tests/unit_tests/openvpn/test_crypto.c +54 -7
@@ -141,6 +141,11 @@ static uint8_t good_prf[32] = {0xd9, 0x8c, 0x85, 0x18, 0xc8, 0x5e, 0x94, 0x69,0x27 ,0x91 ,0x6a ,0xcf ,0xc2 ,0xd5 ,0x92 ,0xfb ,0xb1 ,0x56 ,0x7e ,0x4b ,0x4b ,0x14 ,0x59 ,0xe6 , 0xa9, 0x04, 0xac, 0x2d, 0xda, 0xb7, 0x2d, 0x67}; + +static const char * ipsumlorem ="Lorem ipsum dolor sit amet, consectetur " +"adipisici elit, sed eiusmod tempor incidunt " +"ut labore et dolore magna aliqua." ; +static void crypto_test_tls_prf (void **state) {
@@ -150,12 +155,6 @@ crypto_test_tls_prf(void **state)const size_t seed_len =strlen (seedstr); - - -const char * ipsumlorem ="Lorem ipsum dolor sit amet, consectetur " -"adipisici elit, sed eiusmod tempor incidunt ut " -"labore et dolore magna aliqua." ; -const unsigned char *secret = (const unsigned char *) ipsumlorem;size_t secret_len =strlen ((const char *)secret);
@@ -166,13 +165,61 @@ crypto_test_tls_prf(void **state)assert_memory_equal (good_prf, out,sizeof (out)); } +static uint8_t testkey[20 ] = {0x0b ,0x00 }; +static uint8_t goodhash[20 ] = {0x58 ,0xea ,0x5a ,0xf0 ,0x42 ,0x94 ,0xe9 ,0x17 , +0xed ,0x84 ,0xb9 ,0xf0 ,0x83 ,0x30 ,0x23 ,0xae , +0x8b ,0xa7 ,0x7e ,0xb8 }; + +static void +crypto_test_hmac (void **state) +{ +hmac_ctx_t *hmac =hmac_ctx_new (); +const md_kt_t *sha1 =md_kt_get ("SHA1" ); + +assert_int_equal (md_kt_size (sha1),20 ); + +uint8_t key[20 ]; +memcpy (key, testkey,sizeof (key)); + +hmac_ctx_init (hmac, key,20 , sha1); +hmac_ctx_update (hmac, (const uint8_t *)ipsumlorem, (int )strlen (ipsumlorem)); +hmac_ctx_update (hmac, (const uint8_t *)ipsumlorem, (int )strlen (ipsumlorem)); + +uint8_t hash[20 ]; +hmac_ctx_final (hmac, hash); + +assert_memory_equal (hash, goodhash,sizeof (hash)); +memset (hash,0x00 ,sizeof (hash)); + +/* try again */ +hmac_ctx_reset (hmac); +hmac_ctx_update (hmac, (const uint8_t *)ipsumlorem, (int )strlen (ipsumlorem)); +hmac_ctx_update (hmac, (const uint8_t *)ipsumlorem, (int )strlen (ipsumlorem)); +hmac_ctx_final (hmac, hash); + +assert_memory_equal (hash, goodhash,sizeof (hash)); + +/* Fill our key with random data to ensure it is not used by hmac anymore */ +memset (key,0x55 ,sizeof (key)); + +hmac_ctx_reset (hmac); +hmac_ctx_update (hmac, (const uint8_t *)ipsumlorem, (int )strlen (ipsumlorem)); +hmac_ctx_update (hmac, (const uint8_t *)ipsumlorem, (int )strlen (ipsumlorem)); +hmac_ctx_final (hmac, hash); + +assert_memory_equal (hash, goodhash,sizeof (hash)); +hmac_ctx_cleanup (hmac); +hmac_ctx_free (hmac); +} +int main (void ) {const struct CMUnitTest tests[] = {cmocka_unit_test (crypto_pem_encode_decode_loopback),cmocka_unit_test (crypto_translate_cipher_names), -cmocka_unit_test (crypto_test_tls_prf) +cmocka_unit_test (crypto_test_tls_prf), +cmocka_unit_test (crypto_test_hmac) };#if defined(ENABLE_CRYPTO_OPENSSL )
Signature · 1 line
2.33.0
[Openvpn-devel] [PATCH applied] Re: Add small unit test for testing HMAC
Unit tests are good :-) - tested with OpenSSL 1.1.1 and mbedTLS builds
[==========] Running 4 test(s).
[ RUN ] crypto_pem_encode_decode_loopback
[ OK ] crypto_pem_encode_decode_loopback
[ RUN ] crypto_translate_cipher_names
[ OK ] crypto_translate_cipher_names
[ RUN ] crypto_test_tls_prf
[ OK ] crypto_test_tls_prf
[ RUN ] crypto_test_hmac
[ OK ] crypto_test_hmac
[==========] 4 test(s) run.
[ PASSED ] 4 test(s).
PASS: crypto_testdriver
Your patch has been applied to the master branch.
commit bf079db4888381791308e08b1de9b87670a72c95
Author: Arne Schwabe Date: Tue Oct 19 20:31:23 2021 +0200
Add small unit test for testing HMAC
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23012.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 18/21 Fix error when BF-CBC is not available
In reply to Arne SchwabeThrough the multiple iteration of allowing OpenVPN to run without BF-CBC we accidentially made a regression and still required BF-CBC.
This patch fixes the code path and restores its intended function.
--- src/openvpn/options.c | 3 +++ 1 file changed, 3 insertions(+)
src/openvpn/options.c +3 -0
@@ -3797,6 +3797,9 @@ calc_options_string_link_mtu(const struct options *o, const struct frame *frame)/* overhead of BF-CBC: 64 bit block size, 64 bit IV size */ frame_add_to_extra_frame (&fake_frame,64 /8 +64 /8 ); +/* set ciphername to none, so its size does get added in the fake_kt and +* the cipher is not tried to be resolved */ + ciphername ="none" ; }init_key_type (&fake_kt, ciphername, o->authname, true, false);
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 18/21] Fix error when BF-CBC is not available
Quoted 6 lines · Arne Schwabe
Through the multiple iteration of allowing OpenVPN to run without BF-CBC we accidentially made a regression and still required BF-CBC.
This patch fixes the code path and restores its intended function.
Signed-off-by Arne Schwabe <[email protected]...>
This fixes running with --mode server when BF-CBC is unavailable.
[Openvpn-devel] [PATCH applied] Re: Fix error when BF-CBC is not available
In reply to Arne SchwabeAs discussed online, this is really just about OCC initialization, and that really shouldn't pull in BF-CBC if not requested :-)
I have rewrapped the comment - one overlong line + one short line looked avoidably silly :-)
Your patch has been applied to the master branch.
commit 056991925633ea27a1536bb610e0055072631ce7
Author: Arne Schwabe Date: Tue Oct 19 20:31:24 2021 +0200
Fix error when BF-CBC is not available
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Max Fillinger <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23010.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 19/21 Add insecure tls-cert-profile options
In reply to Arne SchwabeThe recent deprecation of SHA1 certificates in OpenSSL 3.0 makes it necessary to reallow them in certain deployments. Currently this works by using the hack of using tls-cipher "DEFAULT:@SECLEVEL=0". Add insecure as option to tls-cert-profile to allow setting a seclevel of 0.
--- doc/man-sections/tls-options.rst | 6 ++++++ src/openvpn/ssl_mbedtls.c | 3 ++- src/openvpn/ssl_openssl.c | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-)
doc/man-sections/tls-options.rst +6 -0
@@ -373,6 +373,9 @@ certificates and keys: https://github.com/OpenVPN/easy-rsa The following profiles are supported: + :code:`insecure` + Identical for mbed TLS to `legacy` + :code:`legacy` (default) SHA1 and newer, RSA 2048-bit+, any elliptic curve.
@@ -385,6 +388,9 @@ certificates and keys: https://github.com/OpenVPN/easy-rsa This option is only fully supported for mbed TLS builds. OpenSSL builds use the following approximation: + :code:`insecure` + sets "security level 0" + :code:`legacy` (default) sets "security level 1"
src/openvpn/ssl_mbedtls.c +2 -1
@@ -336,7 +336,8 @@ tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)void tls_ctx_set_cert_profile (struct tls_root_ctx *ctx,const char *profile) { -if (!profile ||0 ==strcmp (profile,"legacy" )) +if (!profile ||0 ==strcmp (profile,"legacy" ) + ||0 ==strcmp (profile,"insecure" )) { ctx->cert_profile = openvpn_x509_crt_profile_legacy; }
src/openvpn/ssl_openssl.c +5 -1
@@ -532,7 +532,11 @@ tls_ctx_set_cert_profile(struct tls_root_ctx *ctx, const char *profile)* callbacks that we could try to implement to achieve something similar. * For now, use OpenSSL's security levels to achieve similar (but not equal) * behaviour. */ -if (!profile ||0 ==strcmp (profile,"legacy" )) +if (!profile ||0 ==strcmp (profile,"insecure" )) + { +SSL_CTX_set_security_level (ctx->ctx,0 ); + } +else if (!profile ||0 ==strcmp (profile,"legacy" )) {SSL_CTX_set_security_level (ctx->ctx,1 ); }
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 19/21] Add insecure tls-cert-profile options
Quoted 6 lines · Arne Schwabe
The recent deprecation of SHA1 certificates in OpenSSL 3.0 makes it necessary to reallow them in certain deployments. Currently this works by using the hack of using tls-cipher "DEFAULT:@SECLEVEL=0". Add insecure as option to tls-cert-profile to allow setting a seclevel of 0.
Signed-off-by Arne Schwabe <[email protected]...>
This makes insecure the default mode:
src/openvpn/ssl_openssl.c tls_ctx_set_cert_profile(struct tls_root_ctx *ctx, const char *profile) · line 542
Quoted 9 lines
src/openvpn/ssl_openssl.c +5
-0+if (!profile ||0 ==strcmp (profile,"insecure" )) + { +SSL_CTX_set_security_level (ctx->ctx,0 ); + } +else if (!profile ||0 ==strcmp (profile,"legacy" )) {SSL_CTX_set_security_level (ctx->ctx,1 ); }
When we don't pass a tls-cert-profile option, profile is NULL here, so it takes the first branch.
PATCH v3 20/21 Add macos OpenSSL 3.0 and ASAN builds
In reply to Arne Schwabe--- .github/workflows/build.yaml | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)
.github/workflows/build.yaml +25 -3
@@ -168,15 +168,37 @@ jobs: macos: runs-on: macos-latest + strategy: + fail-fast: false + matrix: + ossl: [ 1.1, 3 ] + build: [ normal, asan ] + include: + - build: asan + cflags: "-fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer -g -O1" + ldflags: -fsanitize=address + # Our build system ignores LDFLAGS for plugins + configureflags: --disable-plugin-auth-pam --disable-plugin-down-root + - build: normal + cflags: "-O2 -g" + ldflags: "" + configureflags: "" + + name: "macOS - OpenSSL ${{matrix.ossl}} - ${{matrix.build}}" + env: + CFLAGS: ${{ matrix.cflags }} + LDFLAGS: ${{ matrix.ldflags }} + OPENSSL_CFLAGS: -I/usr/local/opt/openssl@${{matrix.ossl}}/include + OPENSSL_LIBS: "-L/usr/local/opt/openssl@${{matrix.ossl}}/lib -lcrypto -lssl" steps: + - name: Install dependencies + run: brew install [email protected]... [email protected]... lzo lz4 man2html cmocka libtool automake autoconf - name: Checkout OpenVPN uses: actions/[email protected]... - - name: Install dependencies - run: brew install openssl lzo lz4 man2html cmocka libtool automake autoconf - name: autoconf run: autoreconf -fvi - name: configure - run: OPENSSL_CFLAGS=-I/usr/local/opt/[email protected].../include OPENSSL_LIBS="-L/usr/local/opt/[email protected].../lib -lcrypto -lssl" ./configure + run: ./configure ${{matrix.configureflags}} - name: make all run: make -j4 - name: make check
Signature · 1 line
2.33.0
[Openvpn-devel] [PATCH applied] Re: Add macos OpenSSL 3.0 and ASAN builds
Since most of the bits and pieces are in now, and "make check" succeeds (unless doing t_client tests with BF-CBC), we can reasonably add this to the build matrix. No code change, just GH action.
Your patch has been applied to the master branch.
commit 96f27a29cd4c95dadc16f3ba22876742f426d1c2
Author: Arne Schwabe Date: Tue Oct 19 20:31:26 2021 +0200
Add macos OpenSSL 3.0 and ASAN builds
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23018.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v3 21/21 Always use 8192 bytes for ERR_BUF_SIZE
In reply to Arne SchwabeThe signature messages required by external key managed also break the 1280 limit. To also avoid this surprise of different behaviour with PKCS11 enabled/disable, always use the larger size.
--- src/openvpn/error.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
src/openvpn/error.h +1 -5
@@ -36,12 +36,8 @@#endif /* #define ABORT_ON_ERROR */ - -#ifdef ENABLE_PKCS11 #define ERR_BUF_SIZE 8192 -#else -#define ERR_BUF_SIZE 1280 -#endif +struct gc_arena ;
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v3 21/21] Always use 8192 bytes for ERR_BUF_SIZE
Hi,
Quoted 4 lines · Arne Schwabe
The signature messages required by external key managed also break the 1280 limit. To also avoid this surprise of different behaviour with PKCS11 enabled/disable, always use the larger size.
This may be enough in most cases, but to be safer, shall we increase it to 10240? I have seen up to 6 K handshake messages when undigested messages are to be passed to the management interface and that's already 8K with base64 overhead.
That said, I think we need a better solution. As it stands it's a bit silly that we keep allocating required buffers dynamically at the origination point, a number of places in manage.c, all the way up to x_msg_va() in error.c where it gets silently truncated to a hard-coded size.
Can we use the return value of vsnprintf() in x_msg_va() to determine the size of the buffer required? Not sure whether that is reliable on all platforms. Only the size of m1 has to be determined as m2 has a more-or-less predictable overhead on top of that.
Selva
Re: [Openvpn-devel] [PATCH v3 21/21] Always use 8192 bytes for ERR_BUF_SIZE
In reply to Arne SchwabeHi,
Quoted 3 lines · Arne Schwabe
The signature messages required by external key managed also break the 1280 limit. To also avoid this surprise of different behaviour with PKCS11 enabled/disable, always use the larger size.
JFTR, this patch has been obsoleted by Selva's eeb019acee57e commit.
This is now "large" for PKCS11 *or* ENABLE_MANAGEMENT, so for the original purpose, fixed.
All original comments still apply, like, "make this less silly"
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...PATCH v4 1/1 Implement DES ECB encrypt via EVP_CIPHER api
In reply to Arne SchwabeEven though DES is super outdated and also NTLM is super outdated, eliminating the warnings for OpenSSL 3.0 is still a step in the right direction and using the correct APIs. We cheat a bit by using 3DES instead of DES to avoid needing legacy provider for DES encryption for now.
Patch v4: add unit test, use 3DES to avoid legacy provider for now
--- src/openvpn/crypto_openssl.c | 40 ++++++++++++++++++++++++-- tests/unit_tests/openvpn/test_crypto.c | 27 ++++++++++++++++- 2 files changed, 63 insertions(+), 4 deletions(-)
src/openvpn/crypto_openssl.c +37 -3
@@ -867,10 +867,44 @@ cipher_des_encrypt_ecb(const unsigned char key[DES_KEY_LENGTH], unsigned char src[DES_KEY_LENGTH], unsigned char dst[DES_KEY_LENGTH]) { -DES_key_schedule sched; +/* We are using 3DES here with three times the same key to cheat +* and emulate DES as 3DES is better supported than DES */ +EVP_CIPHER_CTX *ctx =EVP_CIPHER_CTX_new (); +if (!ctx) + { +crypto_msg (M_FATAL ,"%s: EVP_CIPHER_CTX_new() failed" , __func__); + } + +unsigned char key3[DES_KEY_LENGTH *3 ]; +for (int i =0 ;i <3 ;i++) + { +memcpy (key3 + (i *DES_KEY_LENGTH ), key,DES_KEY_LENGTH ); + } -DES_set_key_unchecked ((DES_cblock *)key, &sched); -DES_ecb_encrypt ((DES_cblock *)src, (DES_cblock *)dst, &sched,DES_ENCRYPT ); +if (!EVP_EncryptInit_ex (ctx,EVP_des_ede3_ecb (),NULL , key3,0 )) + { +crypto_msg (M_FATAL ,"%s: EVP_EncryptInit_ex() failed" , __func__); + } + +int len; + +/* The EVP_EncryptFinal method will write to the dst+len pointer even +* though there is nothing to encrypt anymore, provide space for that to +* not overflow the stack */ +unsigned char dst2[DES_KEY_LENGTH *2 ]; +if (!EVP_EncryptUpdate (ctx, dst2, &len, src,DES_KEY_LENGTH )) + { +crypto_msg (M_FATAL ,"%s: EVP_EncryptUpdate() failed" , __func__); + } + +if (!EVP_EncryptFinal (ctx, dst2 + len, &len)) + { +crypto_msg (M_FATAL ,"%s: EVP_EncryptFinal() failed" , __func__); + } + +memcpy (dst, dst2,DES_KEY_LENGTH ); + +EVP_CIPHER_CTX_free (ctx); }/*
tests/unit_tests/openvpn/test_crypto.c +26 -1
@@ -212,6 +212,30 @@ crypto_test_hmac(void **state)hmac_ctx_free (hmac); } +void +test_des_encrypt (void **state) +{ +/* We have a small des encrypt method that is only for NTLMv1. This unit +* test ensures that it is not accidentally broken */ + +const unsigned char des_key[DES_KEY_LENGTH ] = {0x42 ,0x23 }; + +const char *src ="MoinWelt" ; + +/* cipher_des_encrypt_ecb wants a non const */ +unsigned char *src2 = (unsigned char *)strdup (src); + +unsigned char dst[DES_KEY_LENGTH ]; +cipher_des_encrypt_ecb (des_key, src2, dst); + +const unsigned char dst_good[DES_KEY_LENGTH ] = {0xd3 ,0x8f ,0x61 ,0xf7 ,0xbe ,0x27 ,0xb6 ,0xa2 }; + +assert_memory_equal (dst, dst_good,DES_KEY_LENGTH ); + +free (src2); +} + +int main (void ) {
@@ -219,7 +243,8 @@ main(void)cmocka_unit_test (crypto_pem_encode_decode_loopback),cmocka_unit_test (crypto_translate_cipher_names),cmocka_unit_test (crypto_test_tls_prf), - cmocka_unit_test(crypto_test_hmac) +cmocka_unit_test (crypto_test_hmac), + cmocka_unit_test(test_des_encrypt) };#if defined(ENABLE_CRYPTO_OPENSSL )
Signature · 1 line
2.33.0
PATCH v4 1/1 Use EVP_PKEY_get_group_name to query group name
EC_Key methods are deprecated in OpenSSL 3.0. Use EVP_PKEY_get_group_name instead to query the EC group name from an EVP_PKEY and add a compatibility function for older OpenSSL versions.
Patch v4: adjust compatibility function and remove accidently included fragment
of unrelated patch.
--- src/openvpn/openssl_compat.h | 36 ++++++++++++++++++++++++++++++++++++ src/openvpn/ssl_openssl.c | 14 ++++++++------ 2 files changed, 44 insertions(+), 6 deletions(-)
src/openvpn/openssl_compat.h +36 -0
@@ -718,4 +718,40 @@ SSL_CTX_set_max_proto_version(SSL_CTX *ctx, long tls_ver_max)return 1 ; }#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L && !defined(ENABLE_CRYPTO_WOLFSSL) */ + +/* Functionality missing in 1.1.1 */ +#if OPENSSL_VERSION_NUMBER <0x30000000L && !defined(OPENSSL_NO_EC ) + +/* Note that this is not a perfect emulation of the new function but +* is good enough for our case of printing certificate details during +* handshake */ +static inline +int EVP_PKEY_get_group_name (EVP_PKEY *pkey,char *gname,size_t gname_sz, +size_t *gname_len) +{ +const EC_KEY * ec =EVP_PKEY_get0_EC_KEY (pkey); +if (ec ==NULL ) + { +return 0 ; + } +const EC_GROUP * group =EC_KEY_get0_group (ec); +int nid =EC_GROUP_get_curve_name (group); + +if (nid ==0 ) + { +return 0 ; + } +const char *curve =OBJ_nid2sn (nid); +if (!curve) + { + curve ="(error fetching curve name)" ; + } + +strncpynt (gname, curve, gname_sz); + +/* strncpynt ensures null termination so just strlen is fine here */ + *gname_len =strlen (curve); +return 1 ; +} +#endif #endif /* OPENSSL_COMPAT_H_ */
src/openvpn/ssl_openssl.c +8 -6
@@ -2053,13 +2053,15 @@ print_cert_details(X509 *cert, char *buf, size_t buflen)int typeid =EVP_PKEY_id (pkey);#ifndef OPENSSL_NO_EC -if (typeid ==EVP_PKEY_EC &&EVP_PKEY_get0_EC_KEY (pkey) !=NULL ) +char groupname[256 ]; +if (typeid ==EVP_PKEY_EC ) { -const EC_KEY *ec =EVP_PKEY_get0_EC_KEY (pkey); -const EC_GROUP *group =EC_KEY_get0_group (ec); - -int nid =EC_GROUP_get_curve_name (group); -if (nid ==0 || (curve =OBJ_nid2sn (nid)) ==NULL ) +size_t len; +if (EVP_PKEY_get_group_name (pkey, groupname,sizeof (groupname), &len)) + { + curve = groupname; + } +else { curve ="(error getting curve name)" ; }
Signature · 1 line
2.33.0
A message that is not in the archive (sent off-list or not yet received): [email protected]...
PATCH v4 1/1 Use EVP_PKEY_get_group_name to query group name
Somehow I managed to mess-up the reply address with this one. No wonder it failed to show up in patchwork.
Sending again to the list
---------- Forwarded message ---------
From: Selva Nair <[email protected]...>
Date: Fri, Oct 29, 2021 at 12:06 PM
Subject: Re: [Openvpn-devel] [PATCH v4] [OSSL 3.0] Use EVP_PKEY_get_group_name to query group name
Hi,
Quoted 87 lines · Arne Schwabe
EC_Keymethods are deprecated in OpenSSL 3.0. UseEVP_PKEY_get_group_nameinstead to query the EC group name from anEVP_PKEYand add a compatibility function for older OpenSSL versions.Patch v4: adjust compatibility function and remove accidently included fragment
of unrelated patch.Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/openssl_compat.h | 36 ++++++++++++++++++++++++++++++++++++ src/openvpn/ssl_openssl.c | 14 ++++++++------ 2 files changed, 44 insertions(+), 6 deletions(-)src/openvpn/openssl_compat.h +0
-0@@ -718,4 +718,40 @@ SSL_CTX_set_max_proto_version(SSL_CTX *ctx, long tls_ver_max) return 1; }#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L && !defined(ENABLE_CRYPTO_WOLFSSL) */
src/openvpn/openssl_compat.h +36
-0+ +/* Functionality missing in 1.1.1 */ +#if OPENSSL_VERSION_NUMBER <0x30000000L && !defined(OPENSSL_NO_EC ) + +/* Note that this is not a perfect emulation of the new function but +* is good enough for our case of printing certificate details during +* handshake */ +static inline +int EVP_PKEY_get_group_name (EVP_PKEY *pkey,char *gname,size_t gname_sz, +size_t *gname_len) +{ +const EC_KEY * ec =EVP_PKEY_get0_EC_KEY (pkey); +if (ec ==NULL ) + { +return 0 ; + } +const EC_GROUP * group =EC_KEY_get0_group (ec); +int nid =EC_GROUP_get_curve_name (group); + +if (nid ==0 ) + { +return 0 ; + } +const char *curve =OBJ_nid2sn (nid); +if (!curve) + { + curve ="(error fetching curve name)" ; + } + +strncpynt (gname, curve, gname_sz); + +/* strncpynt ensures null termination so just strlen is fine here */ + *gname_len =strlen (curve); +return 1 ; +} +#endif #endif /* OPENSSL_COMPAT_H_ */ src/openvpn/ssl_openssl.c +8
-6@@ -2053,13 +2053,15 @@ print_cert_details(X509 *cert, char *buf, size_t buflen)int typeid =EVP_PKEY_id (pkey);#ifndef OPENSSL_NO_EC -if (typeid ==EVP_PKEY_EC &&EVP_PKEY_get0_EC_KEY (pkey) !=NULL ) +char groupname[256 ]; +if (typeid ==EVP_PKEY_EC ) { -const EC_KEY *ec =EVP_PKEY_get0_EC_KEY (pkey); -const EC_GROUP *group =EC_KEY_get0_group (ec); - -int nid =EC_GROUP_get_curve_name (group); -if (nid ==0 || (curve =OBJ_nid2sn (nid)) ==NULL ) +size_t len; +if (EVP_PKEY_get_group_name (pkey, groupname,sizeof (groupname), &len)) + { + curve = groupname; + } +else {
Quoted 3 lines
curve = "(error getting curve name)";
}[Openvpn-devel] [PATCH applied] Re: Use EVP_PKEY_get_group_name to query group name
In reply to Arne SchwabeStared a bit at the code (verified that "curve" is never used out of scope, since it's now a local array), die minimum test run vs. 1.1.1 and 3.0.0 - no surprises (t_lpback.sh still fails due to the FETCH parts missing, but they can now go in).
Your patch has been applied to the master branch.
commit 4b3c1e76d747d0e7e6aec280680777aef356a940
Author: Arne Schwabe Date: Fri Oct 29 13:11:09 2021 +0200
Use EVP_PKEY_get_group_name to query group name
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Selva Nair <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23077.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v4] [OSSL 3.0] Implement DES ECB encrypt via EVP_CIPHER api
In reply to Arne SchwabeQuoted 8 lines · Arne Schwabe
Even though DES is super outdated and also NTLM is super outdated, eliminating the warnings for OpenSSL 3.0 is still a step in the right direction and using the correct APIs. We cheat a bit by using 3DES instead of DES to avoid needing legacy provider for DES encryption for now.
Patch v4: add unit test, use 3DES to avoid legacy provider for now
Signed-off-by Arne Schwabe <[email protected]...>
Looks good to me, and the unit tests succeed with OpenSSL 1.1.1 and 3.
Small nitpick that can be fixed at compile time:
Quoted 1 line
+ if (!EVP_EncryptInit_ex(ctx,
EVP_des_ede3_ecb(), NULL, key3, 0))
The last argument for this function is "const unsigned char *iv", so this should be NULL instead of 0. (Passing NULL here is correct because ECB mode doesn't need an initialization vector.)
[Openvpn-devel] [PATCH applied] Re: Implement DES ECB encrypt via EVP_CIPHER api
In reply to Arne SchwabeCliend side tested on OpenSSL 1.1.1 and 3.0.0 - thanks for the in-person explanation about DES and 3DES-with-same-key :-) and for adding a unit test.
[ RUN ] test_des_encrypt
[ OK ] test_des_encrypt
Your patch has been applied to the master branch.
commit c426a3e77ee5377ca1c6254feabb04e41aa6dfed
Author: Arne Schwabe Date: Fri Oct 29 13:11:08 2021 +0200
Implement DES ECB encrypt via EVP_CIPHER api
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Max Fillinger <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23078.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v4 1/1 Add insecure tls-cert-profile options
In reply to Arne SchwabeThe recent deprecation of SHA1 certificates in OpenSSL 3.0 makes it necessary to reallow them in certain deployments. Currently this works by using the hack of using tls-cipher "DEFAULT:@SECLEVEL=0". Add insecure as option to tls-cert-profile to allow setting a seclevel of 0.
Patch v4: fix default accidentially changed to insecure
--- doc/man-sections/tls-options.rst | 6 ++++++ src/openvpn/ssl_mbedtls.c | 3 ++- src/openvpn/ssl_openssl.c | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-)
doc/man-sections/tls-options.rst +6 -0
@@ -373,6 +373,9 @@ certificates and keys: https://github.com/OpenVPN/easy-rsa The following profiles are supported: + :code:`insecure` + Identical for mbed TLS to `legacy` + :code:`legacy` (default) SHA1 and newer, RSA 2048-bit+, any elliptic curve.
@@ -385,6 +388,9 @@ certificates and keys: https://github.com/OpenVPN/easy-rsa This option is only fully supported for mbed TLS builds. OpenSSL builds use the following approximation: + :code:`insecure` + sets "security level 0" + :code:`legacy` (default) sets "security level 1"
src/openvpn/ssl_mbedtls.c +2 -1
@@ -336,7 +336,8 @@ tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)void tls_ctx_set_cert_profile (struct tls_root_ctx *ctx,const char *profile) { -if (!profile ||0 ==strcmp (profile,"legacy" )) +if (!profile ||0 ==strcmp (profile,"legacy" ) + ||0 ==strcmp (profile,"insecure" )) { ctx->cert_profile = openvpn_x509_crt_profile_legacy; }
src/openvpn/ssl_openssl.c +4 -0
@@ -536,6 +536,10 @@ tls_ctx_set_cert_profile(struct tls_root_ctx *ctx, const char *profile) {SSL_CTX_set_security_level (ctx->ctx,1 ); } + else if (0 == strcmp(profile, "insecure")) + { +SSL_CTX_set_security_level (ctx->ctx,0 ); + } else if (0 == strcmp(profile, "preferred")) {SSL_CTX_set_security_level (ctx->ctx,2 );
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v4] Add insecure tls-cert-profile options
Quoted 8 lines · Arne Schwabe
The recent deprecation of SHA1 certificates in OpenSSL 3.0 makes it necessary to reallow them in certain deployments. Currently this works by using the hack of using tls-cipher "DEFAULT:@SECLEVEL=0". Add insecure as option to tls-cert-profile to allow setting a seclevel of 0.
Patch v4: fix default accidentially changed to insecure
Signed-off-by Arne Schwabe <[email protected]...>
With OpenSSL 3, OpenVPN accepts certs signed with SHA1 if and only if "--tls-cert-profile insecure" is used.
[Openvpn-devel] [PATCH applied] Re: Add insecure tls-cert-profile options
In reply to Arne Schwabe(Client-side) tested with 1.1.1 and 3.0.0.
Without options, my sha1 certificates still fail for the 3.0.0 build, and *with* "tls-cert-profile insecure" it works.
Your patch has been applied to the master branch.
commit 23efeb7a0bd9e0a6d997ae6e77e0e04170da3e67
Author: Arne Schwabe Date: Fri Oct 29 13:24:07 2021 +0200
Add insecure tls-cert-profile options
Signed-off-by: Arne Schwabe <[email protected]...>
Acked-by: Max Fillinger <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23076.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH applied] Re: Add insecure tls-cert-profile options
Hi,
Quoted 5 lines · Gert Doering
(Client-side) tested with 1.1.1 and 3.0.0.
Without options, my sha1 certificates still fail for the 3.0.0 build, and *with* "tls-cert-profile insecure" it works.
Quoted 7 lines
Your patch has been applied to the master branch.
commit
23efeb7a0bd9e0a6d997ae6e77e0e04170da3e67Author: Arne Schwabe Date: Fri Oct 29 13:24:07 2021 +0200Add insecure tls-cert-profile options
Based on the discussion on IRC (just now) I have applied this to 2.5 as well - Ubuntu 22.04 builds with OpenSSL 3.0.x, and without that patch, existing user setups with sha1 certs will break and no option to work around that.
commit 7b1b100557608db8a311d06f7578ceb7c4d33aa6 (HEAD -> release/2.5)
Author: Arne Schwabe <[email protected]...> Date: Fri Oct 29 13:24:07 2021 +0200
Add insecure tls-cert-profile options
(cherry picked from commit 23efeb7a0bd9e0a6d997ae6e77e0e04170da3e67)
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...PATCH v4 1/1 Refactor early initialisation and uninitialisation into methods
In reply to Arne SchwabeThis put the early initialisation and uninitialisation that needs to happen between option parsing and post processing into small methods.
--- src/openvpn/openvpn.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
src/openvpn/openvpn.c +18 -5
@@ -105,6 +105,20 @@ tunnel_point_to_point(struct context *c)#undef PROCESS_SIGNAL_P2P +void init_early (struct context *c) +{ +net_ctx_init (c, c->net_ctx); + +/* init verbosity and mute levels */ +init_verb_mute (c,IVM_LEVEL_1 ); + +} + +static void uninit_early (struct context *c) +{ +net_ctx_free (&c->net_ctx); +} +/**************************************************************************/ /**
@@ -193,10 +207,9 @@ openvpn_main(int argc, char *argv[])open_plugins (&c, true,OPENVPN_PLUGIN_INIT_PRE_CONFIG_PARSE );#endif -net_ctx_init (&c, &c.net_ctx); - -/* init verbosity and mute levels */ -init_verb_mute (&c,IVM_LEVEL_1 ); +/* Early initialisation that need to happen before option +* post processing and other early startup but after parsing */ +init_early (&c);/* set dev options */ init_options_dev (&c.options);
@@ -308,7 +321,7 @@ openvpn_main(int argc, char *argv[])env_set_destroy (c.es);uninit_options (&c.options);gc_reset (&c.gc); -net_ctx_free (&c.net_ctx); +uninit_early (&c); }while (c.sig->signal_received ==SIGHUP ); }
Signature · 1 line
2.33.0
Re: [Openvpn-devel] [PATCH v4] Refactor early initialisation and uninitialisation into methods
Hi,
src/openvpn/openvpn.c tunnel_point_to_point(struct context *c) · line 120
Quoted 4 lines · Arne Schwabe
src/openvpn/openvpn.c +4
-0+static void uninit_early (struct context *c) +{ +net_ctx_free (&c->net_ctx); +}
The extra "&" here does not look right. Shouldn't this be "c->net_ctx" as in "init_early()"?
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Re: [Openvpn-devel] [PATCH v4] Refactor early initialisation and uninitialisation into methods
Hi,
Quoted 10 lines · Gert Doering
Hi,
src/openvpn/openvpn.c tunnel_point_to_point(struct context *c) · line 120
Quoted 4 lines · Arne Schwabe
src/openvpn/openvpn.c +4
-0+static void uninit_early (struct context *c) +{ +net_ctx_free (&c->net_ctx); +}The extra "&" here does not look right. Shouldn't this be "
c->net_ctx" as in "init_early()"?
it's the other way around.
"init_early()" should also use the "&" operator.
We need to pass a pointer to the networking context, but the member is a real object.
(Check the code being removed for reference).
Regards,
Signature · 1 line
Antonio Quartulli
Re: [Openvpn-devel] [PATCH v4] Refactor early initialisation and uninitialisation into methods
In reply to Arne SchwabeHi
Quoted 13 lines · Arne Schwabe
This put the early initialisation and uninitialisation that needs to happen between option parsing and post processing into small methods.
Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/openvpn.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)src/openvpn/openvpn.c +0
-0
src/openvpn/openvpn.c tunnel_point_to_point(struct context *c) · line 111
Quoted 7 lines
src/openvpn/openvpn.c +3
-0@@ -105,6 +105,20 @@ tunnel_point_to_point(struct context *c)#undef PROCESS_SIGNAL_P2P +void init_early (struct context *c) +{ +net_ctx_init (c, c->net_ctx);
hmm... this should have been &c->net_ctx. Can this be fixed during commit? The rest looks good.
Quoted 49 lines
src/openvpn/openvpn.c +11
-0+ +/* init verbosity and mute levels */ +init_verb_mute (c,IVM_LEVEL_1 ); + +} + +static void uninit_early (struct context *c) +{ +net_ctx_free (&c->net_ctx); +} +/**************************************************************************/ /**
src/openvpn/openvpn.c +3
-4@@ -193,10 +207,9 @@ openvpn_main(int argc, char *argv[])open_plugins (&c, true,OPENVPN_PLUGIN_INIT_PRE_CONFIG_PARSE );#endif -net_ctx_init(&c, &c.net_ctx); - -/* init verbosity and mute levels */ -init_verb_mute (&c,IVM_LEVEL_1 ); +/* Early initialisation that need to happen before option +* post processing and other early startup but after parsing */ +init_early (&c);/* set dev options */ init_options_dev(&c.options);src/openvpn/openvpn.c +1
-2@@ -308,7 +321,7 @@ openvpn_main(int argc, char *argv[])env_set_destroy (c.es);uninit_options (&c.options);gc_reset (&c.gc); -net_ctx_free (&c.net_ctx); +uninit_early (&c); }while (c.sig->signal_received ==SIGHUP ); } --2.33.0
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel