show extra info for OpenSSL errors
PATCH 1/1 show extra info for OpenSSL errors
This also shows the extra data from the OpenSSL error function that can contain extra information. For example, the command
openvpn --providers vollbit
will print out (on macOS):
OpenSSLerror:12800067:DSO support routines::could not load the shared library:filename(/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib): dlopen(/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib, 0x0002): tried: '/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib' (no such file), '/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib' (no such file)
--- src/openvpn/crypto_openssl.c | 20 ++++++++++++++++++-- src/openvpn/openssl_compat.h | 12 ++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-)
src/openvpn/crypto_openssl.c +18 -2
@@ -238,9 +238,16 @@ void crypto_print_openssl_errors(const unsigned int flags) {unsigned long err =0 ; +int line, errflags; +const char *file, *data, *func; -while ((err =ERR_get_error ())) +while ((err =ERR_get_error_all (&file, &line, &func, &data, &errflags)) !=0 ) { +if (!(errflags &ERR_TXT_STRING )) + { + data ="" ; + } +/* Be more clear about frequently occurring "no shared cipher" error */ if (ERR_GET_REASON (err) ==SSL_R_NO_SHARED_CIPHER ) {
@@ -258,7 +265,16 @@ crypto_print_openssl_errors(const unsigned int flags)"tls-version-min 1.0 to the client configuration to use TLS 1.0+ " "instead of TLS 1.0 only"); } -msg (flags,"OpenSSL: %s" ,ERR_error_string (err,NULL )); + +/* print file and line if verb >=8 */ +if (!check_debug_level (D_TLS_DEBUG_MED )) + { +msg (flags,"OpenSSL%s:%s" ,ERR_error_string (err,NULL ), data); + } +else + { +msg (flags,"OpenSSL (%s:%d %s): %s:%s" , file, line, func,ERR_error_string (err,NULL ), data); + } } }
src/openvpn/openssl_compat.h +12 -0
@@ -43,6 +43,7 @@#include <openssl/rsa.h> #include <openssl/ssl.h> #include <openssl/x509.h> +#include <openssl/err.h> /* Functionality missing in 1.1.0 */ #if OPENSSL_VERSION_NUMBER <0x10101000L && !defined(ENABLE_CRYPTO_WOLFSSL )
@@ -799,6 +800,17 @@ EVP_MD_free(const EVP_MD *md)/* OpenSSL 1.1.1 and lower use only const EVP_MD, nothing to free */ } +static inline unsigned long +ERR_get_error_all (const char **file,int *line, +const char **func, +const char **data,int *flags) +{ +static const char *empty ="" ; + *func = empty; +long err =ERR_get_error_line_data (file, line, data, flags); +return err; +} +#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */ #endif /* OPENSSL_COMPAT_H_ */
Signature · 1 line
2.39.2 (Apple Git-143)
Hi,
Quoted 8 lines · Arne Schwabe
This also shows the extra data from the OpenSSL error function that can contain extra information. For example, the command
openvpn --providers vollbitwill print out (on macOS):
OpenSSLerror:12800067:DSO support routines::could not load the shared library:filename(/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib): dlopen(/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib, 0x0002): tried: '/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/[email protected]..../3.1.1_1/lib/ossl-modules/vollbit.dylib' (no such file), '/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib' (no such file)
Feature-ACK on providing more detail, because otherwise these errors can get really hard to track down.
Your example above is somewhat excessive on repeating paths, but I do not see this on my FreeBSD test case
$ src/openvpn/openvpn --providers legacyXX default --show-tls 2023-07-10 17:44:27 OpenSSLerror:12800067:DSO support routines::could not load the shared library:filename(/usr/lib/ossl-modules/legacyXX.so): /usr/lib/ossl-modules/legacyXX.so: Undefined symbol "ossl_md4_functions" 2023-07-10 17:44:27 OpenSSLerror:12800067:DSO support routines::could not load the shared library: 2023-07-10 17:44:27 OpenSSLerror:07880025:common libcrypto routines::reason(524325):name=legacyXX
"this is just the right amount of details" :-) - for something that does not exist, I get
2023-07-10 17:45:17 OpenSSLerror:12800067:DSO support routines::could not load the shared library:filename(/usr/lib/ossl-modules/legacyYY.so): Cannot open "/usr/lib/ossl-modules/legacyYY.so"
Code-wise, I would prefer to have someone who understands OpenSSL give this another look... Selva, Antonio? Thanks :-)
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]...Hi,
This looks good except that the format of the log could be kept closer to the current one:
Quoted 53 lines · Arne Schwabe
This also shows the extra data from the OpenSSL error function that can contain extra information. For example, the command
openvpn --providers vollbitwill print out (on macOS):
OpenSSLerror:12800067:DSO support
routines::couldnot load the shared
library:filename(/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib):
dlopen(/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib,0x0002): tried: '/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib'
(no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/[email protected]....../3.1.1_1/lib/ossl-modules/vollbit.dylib' (no such file), '/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib'
(no such file)Change-Id Ic2ee89937dcd85721bcacd1b700a20c640364f80Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/crypto_openssl.c | 20 ++++++++++++++++++-- src/openvpn/openssl_compat.h | 12 ++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-)src/openvpn/crypto_openssl.c +8
-1@@ -238,9 +238,16 @@ void crypto_print_openssl_errors(const unsigned int flags) {unsigned long err =0 ; +int line, errflags; +const char *file, *data, *func; -while ((err =ERR_get_error ())) +while ((err =ERR_get_error_all (&file, &line, &func, &data, &errflags)) !=0 ) { +if (!(errflags &ERR_TXT_STRING )) + { + data ="" ; + } +/* Be more clear about frequently occurring "no shared cipher" error */
if (ERR_GET_REASON(err) == SSL_R_NO_SHARED_CIPHER) {src/openvpn/crypto_openssl.c +0
-0@@ -258,7 +265,16 @@ crypto_print_openssl_errors(const unsigned int flags) "tls-version-min 1.0 to the client configuration to useTLS 1.0+ "
"instead of TLS 1.0 only"); }
src/openvpn/crypto_openssl.c crypto_print_openssl_errors(const unsigned int flags) · line 272
Quoted 6 lines
src/openvpn/crypto_openssl.c +5
-1-msg (flags,"OpenSSL: %s" ,ERR_error_string (err,NULL )); + +/* print file and line if verb >=8 */ +if (!check_debug_level (D_TLS_DEBUG_MED )) + { +msg (flags,"OpenSSL%s:%s" ,ERR_error_string (err,NULL ), data);
Better to retain the ':" after "OpenSSL" in case anyone is parsing the logs
msg(flags, "OpenSSL: %s:%s, ERR_error_string(err, NULL), data);
Quoted 6 lines
src/openvpn/crypto_openssl.c +4
-0+ } +else + { + msg(flags, "OpenSSL (%s:%d %s): %s:%s", file, line, func,
ERR_error_string(err, NULL), data);
Again, I think we could keep the same order as above with additional info (file:line:func) moved to the end with a consistent use of the delimiter ':'
msg(flags, "OpenSSL: %s:%s:%s:%s:%s, ERR_error_string(err, NULL), data, file, line, func);
Quoted 20 lines
src/openvpn/crypto_openssl.c +1
-0+ } } }src/openvpn/openssl_compat.h +1
-0@@ -43,6 +43,7 @@#include <openssl/rsa.h> #include <openssl/ssl.h> #include <openssl/x509.h> +#include <openssl/err.h> /* Functionality missing in 1.1.0 */ #if OPENSSL_VERSION_NUMBER < 0x10101000L &&!defined(ENABLE_CRYPTO_WOLFSSL)
src/openvpn/openssl_compat.h +0
-0@@ -799,6 +800,17 @@ EVP_MD_free(const EVP_MD *md)/* OpenSSL 1.1.1 and lower use only const EVP_MD, nothing to free */ }
src/openvpn/openssl_compat.h EVP_MD_free(const EVP_MD *md) · line 811
Quoted 10 lines
src/openvpn/openssl_compat.h +8
-0+static inline unsigned long +ERR_get_error_all (const char **file,int *line, +const char **func, +const char **data,int *flags) +{ +static const char *empty ="" ; + *func = empty; +long err =ERR_get_error_line_data (file, line, data, flags);
unsigned long err = ....
Quoted 10 lines
src/openvpn/openssl_compat.h +3
-0+ return err; +} +#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */ #endif /*
OPENSSL_COMPAT_H_*/
--
PATCH v2 1/1 show extra info for OpenSSL errors
In reply to Arne SchwabeThis also shows the extra data from the OpenSSL error function that can contain extra information. For example, the command
openvpn --providers vollbit
will print out (on macOS):
OpenSSL: error:12800067:DSO support routines::could not load the shared library:filename(/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib): dlopen(/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib, 0x0002): tried: '/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib' (no such file), '/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib' (no such file)
Patch v2: Format message more like current messages
--- src/openvpn/crypto_openssl.c | 21 +++++++++++++++++++-- src/openvpn/openssl_compat.h | 12 ++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-)
src/openvpn/crypto_openssl.c +19 -2
@@ -238,9 +238,16 @@ void crypto_print_openssl_errors(const unsigned int flags) {unsigned long err =0 ; +int line, errflags; +const char *file, *data, *func; -while ((err =ERR_get_error ())) +while ((err =ERR_get_error_all (&file, &line, &func, &data, &errflags)) !=0 ) { +if (!(errflags &ERR_TXT_STRING )) + { + data ="" ; + } +/* Be more clear about frequently occurring "no shared cipher" error */ if (ERR_GET_REASON (err) ==SSL_R_NO_SHARED_CIPHER ) {
@@ -258,7 +265,17 @@ crypto_print_openssl_errors(const unsigned int flags)"tls-version-min 1.0 to the client configuration to use TLS 1.0+ " "instead of TLS 1.0 only"); } -msg (flags,"OpenSSL: %s" ,ERR_error_string (err,NULL )); + +/* print file and line if verb >=8 */ +if (!check_debug_level (D_TLS_DEBUG_MED )) + { +msg (flags,"OpenSSL: %s:%s" ,ERR_error_string (err,NULL ), data); + } +else + { +msg (flags,"OpenSSL: %s:%s:%s:%d:%s" ,ERR_error_string (err,NULL ), + data, file, line, func); + } } }
src/openvpn/openssl_compat.h +12 -0
@@ -43,6 +43,7 @@#include <openssl/rsa.h> #include <openssl/ssl.h> #include <openssl/x509.h> +#include <openssl/err.h> /* Functionality missing in 1.1.0 */ #if OPENSSL_VERSION_NUMBER <0x10101000L && !defined(ENABLE_CRYPTO_WOLFSSL )
@@ -799,6 +800,17 @@ EVP_MD_free(const EVP_MD *md)/* OpenSSL 1.1.1 and lower use only const EVP_MD, nothing to free */ } +static inline unsigned long +ERR_get_error_all (const char **file,int *line, +const char **func, +const char **data,int *flags) +{ +static const char *empty ="" ; + *func = empty; +long err =ERR_get_error_line_data (file, line, data, flags); +return err; +} +#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */ #endif /* OPENSSL_COMPAT_H_ */
Signature · 1 line
2.39.2 (Apple Git-143)
Quoted 87 lines · Arne Schwabe
This also shows the extra data from the OpenSSL error function that can contain extra information. For example, the command
openvpn --providers vollbitwill print out (on macOS):
OpenSSL: error:12800067:DSO support
routines::couldnot load the
shared library:filename(/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib):
dlopen(/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib,0x0002): tried: '/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib'
(no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/[email protected]....../3.1.1_1/lib/ossl-modules/vollbit.dylib' (no such file), '/opt/homebrew/Cellar/[email protected].../3.1.1_1/lib/ossl-modules/vollbit.dylib'
(no such file)Patch v2: Format message more like current messages
Change-Id Ic2ee89937dcd85721bcacd1b700a20c640364f80Signed-off-by Arne Schwabe <[email protected]...>--- src/openvpn/crypto_openssl.c | 21 +++++++++++++++++++-- src/openvpn/openssl_compat.h | 12 ++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-)src/openvpn/crypto_openssl.c +8
-1@@ -238,9 +238,16 @@ void crypto_print_openssl_errors(const unsigned int flags) {unsigned long err =0 ; +int line, errflags; +const char *file, *data, *func; -while ((err =ERR_get_error ())) +while ((err =ERR_get_error_all (&file, &line, &func, &data, &errflags)) !=0 ) { +if (!(errflags &ERR_TXT_STRING )) + { + data ="" ; + } +/* Be more clear about frequently occurring "no shared cipher" error */
if (ERR_GET_REASON(err) == SSL_R_NO_SHARED_CIPHER) {src/openvpn/crypto_openssl.c +0
-0@@ -258,7 +265,17 @@ crypto_print_openssl_errors(const unsigned int flags) "tls-version-min 1.0 to the client configuration to useTLS 1.0+ "
"instead of TLS 1.0 only"); }src/openvpn/crypto_openssl.c +5
-1-msg (flags,"OpenSSL: %s" ,ERR_error_string (err,NULL )); + +/* print file and line if verb >=8 */ +if (!check_debug_level (D_TLS_DEBUG_MED )) + { + msg(flags, "OpenSSL: %s:%s", ERR_error_string(err, NULL),data);
src/openvpn/crypto_openssl.c +4
-0+ } +else + { + msg(flags, "OpenSSL: %s:%s:%s:%d:%s", ERR_error_string(err,NULL),
src/openvpn/crypto_openssl.c +2
-0+ data, file, line, func); + } } }src/openvpn/openssl_compat.h +1
-0@@ -43,6 +43,7 @@#include <openssl/rsa.h> #include <openssl/ssl.h> #include <openssl/x509.h> +#include <openssl/err.h> /* Functionality missing in 1.1.0 */ #if OPENSSL_VERSION_NUMBER < 0x10101000L &&!defined(ENABLE_CRYPTO_WOLFSSL)
src/openvpn/openssl_compat.h +0
-0@@ -799,6 +800,17 @@ EVP_MD_free(const EVP_MD *md)/* OpenSSL 1.1.1 and lower use only const EVP_MD, nothing to free */ }
src/openvpn/openssl_compat.h EVP_MD_free(const EVP_MD *md) · line 811
Quoted 10 lines
src/openvpn/openssl_compat.h +8
-0+static inline unsigned long +ERR_get_error_all (const char **file,int *line, +const char **func, +const char **data,int *flags) +{ +static const char *empty ="" ; + *func = empty; +long err =ERR_get_error_line_data (file, line, data, flags);
I think you missed to change that to "unsigned long err = ...."
+ return err;
Quoted 8 lines
src/openvpn/openssl_compat.h +2
-1+} +#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */ #endif /* OPENSSL_COMPAT_H_ */ --2.39.2 (Apple Git-143)
The above could be handled at merge time, so:
Thanks, Selva for having an extra eye :-) - I asked for the feature, and it works beautifully for me, but what do I understand about OpenSSL internals... ("unsigned long" fixed on the fly).
Tried on FreeBSD 14 with OpenSSL 3 and a broken provider (which is what triggered the whole thing):
$ src/openvpn/openvpn --providers legacyXX 2023-08-11 20:19:53 OpenSSL: error:12800067:DSO support routines::could not load the shared library:filename(/usr/lib/ossl-modules/legacyXX.so): /usr/lib/ossl-modules/legacyXX.so: Undefined symbol "ossl_md4_functions"
.. and on Linux with OpenSSL 1.1.1t, passing a wrong passphrase:
2023-08-11 20:17:24 OpenSSL: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt: 2023-08-11 20:17:24 OpenSSL: error:23077074:PKCS12 routines:PKCS12_pbe_crypt:pkcs12 cipherfinal error: 2023-08-11 20:17:24 OpenSSL: error:2306A075:PKCS12 routines:PKCS12_item_decrypt_d2i:pkcs12 pbe crypt error: 2023-08-11 20:17:24 OpenSSL: error:0907B00D:PEM routines:PEM_read_bio_PrivateKey:ASN1 lib: 2023-08-11 20:17:24 Cannot load private key file [[INLINE]]
(which looks to be "the same what it printed before", so at least it does not break anything)
With 3.0 it prints, in the same situation...
2023-08-11 20:24:01 OpenSSL: error:1C800064:Provider routines::bad decrypt: 2023-08-11 20:24:01 OpenSSL: error:11800074:PKCS12 routines::pkcs12 cipherfinal error:maybe wrong password
.. or
2023-08-11 20:23:21 OpenSSL: error:0308010C:digital envelope routines::unsupported:Global default library context, Algorithm (DES-CBC : 10), Properties ()
(ahem...)
So, very nice.
For extra sanity checking pushed to GHA first, to get more OpenSSL/OS combinations tested.
Your patch has been applied to the master and release/2.6 branch.
commit 0f8485f2870277fb7ccdb4097380e35dc35b064e (master) commit 101499a43d222dcefbf5c6fc6f8b71a4f5d1f533 (release/2.6)
Author: Arne Schwabe Date: Fri Aug 11 14:15:03 2023 +0200
show extra info for OpenSSL errors
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]/msg26929.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering