Skip to content

Commit

Permalink
show extra info for OpenSSL errors
Browse files Browse the repository at this point in the history
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):

     OpenSSL: error:12800067:DSO support routines::could not load the shared library:filename(/opt/homebrew/Cellar/openssl@3/3.1.1_1/lib/ossl-modules/vollbit.dylib): dlopen(/opt/homebrew/Cellar/openssl@3/3.1.1_1/lib/ossl-modules/vollbit.dylib, 0x0002): tried: '/opt/homebrew/Cellar/openssl@3/3.1.1_1/lib/ossl-modules/vollbit.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/Cellar/openssl@3/3.1.1_1/lib/ossl-modules/vollbit.dylib' (no such file), '/opt/homebrew/Cellar/openssl@3/3.1.1_1/lib/ossl-modules/vollbit.dylib' (no such file)

Patch v2: Format message more like current messages

Change-Id: Ic2ee89937dcd85721bcacd1b700a20c640364f80
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]>
(cherry picked from commit 0f8485f)
  • Loading branch information
schwabe authored and cron2 committed Aug 11, 2023
1 parent 09e2360 commit 101499a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/openvpn/crypto_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,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)
{
Expand All @@ -260,7 +267,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);
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/openvpn/openssl_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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)
Expand Down Expand Up @@ -801,6 +802,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;
unsigned long err = ERR_get_error_line_data(file, line, data, flags);
return err;
}

#endif /* OPENSSL_VERSION_NUMBER < 0x30000000L */

#endif /* OPENSSL_COMPAT_H_ */

0 comments on commit 101499a

Please sign in to comment.