Stop failed cipher/digest lookups from polluting the OpenSSL error queue
PATCH 2/2 Make CRL reload EOF detection independent of stale error queue entries
In reply to Drew Blokzylbackend_tls_ctx_reload_crl() treats a NULL from PEM_read_bio_X509_CRL() as EOF when ERR_peek_error() shows PEM_R_NO_START_LINE. ERR_peek_error() returns the OLDEST queued error, so any entry left behind earlier in the thread turns a clean EOF into a "CRL: cannot read CRL from file" warning, prints the unrelated errors as if they came from the CRL file, and still installs the CRLs already parsed. The previous commit removes the leftover that triggered this in practice; this one stops the loop from depending on the queue being clean at all.
Start the loop from an empty queue so only errors raised by PEM_read_bio_X509_CRL() are visible, test the error it raised last rather than the oldest one, and clear the queue on the EOF path instead of popping a single entry.
--- src/openvpn/ssl_openssl.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
src/openvpn/ssl_openssl.c +11 -2
@@ -1360,6 +1360,13 @@ backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, b }int num_crls_loaded =0 ; +/* +* Start from an empty error queue so the EOF test below only sees errors +* raised by PEM_read_bio_X509_CRL(). A stale error left by an earlier +* operation in this thread would otherwise be what ERR_peek_error() +* returns, and a clean EOF gets reported as "cannot read CRL". +*/ +ERR_clear_error ();while (true) {X509_CRL *crl =PEM_read_bio_X509_CRL (in,NULL ,NULL ,NULL );
@@ -1367,13 +1374,15 @@ backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, b {/* * PEM_R_NO_START_LINE can be considered equivalent to EOF. +* ERR_peek_last_error() is the error PEM_read_bio_X509_CRL() +* raised last; ERR_peek_error() would be the oldest queued one. */ -bool eof =ERR_GET_REASON (ERR_peek_error ()) ==PEM_R_NO_START_LINE ; +bool eof =ERR_GET_REASON (ERR_peek_last_error ()) ==PEM_R_NO_START_LINE ;/* but warn if no CRLs have been loaded */ if (num_crls_loaded >0 && eof) {/* remove that error from error stack */ - (void )ERR_get_error (); +ERR_clear_error ();break ; }
Signature · 8 lines
2.53.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
PATCH 1/2 Drop the OpenSSL errors a failed cipher/digest lookup leaves behind
In reply to Drew Blokzylcipher_get() looks a cipher up with EVP_CIPHER_fetch() and hands the result, possibly NULL, to callers that only care whether it exists:cipher_valid_reason(), cipher_kt_mode_cbc/ofb_cfb/aead(), cipher_kt_block_size(), cipher_kt_insecure(). A failed fetch is a normal outcome for them, but under OpenSSL 3 it also pushes an EVP_R_UNSUPPORTED error ("digital envelope routines::unsupported, Algorithm (none : 0)") onto the thread's error queue, and nobody pops it.
The common way to get there is not exotic. A server that does not set --cipher gets the legacy default BF-CBC, which is not in --data-ciphers, so do_init_crypto_tls() initialises the pre-negotiation key_type with cipher "none". Every new client instance then runs init_instance() -> do_init_crypto_tls() -> cipher_kt_mode_ofb_cfb("none"), and the frame and OCC calculations (calculate_crypto_overhead(), frame_calculate_*()) walk the same key_type, each fetching "none" and failing. cipher_kt_block_size() adds a second case for AEAD ciphers whose CBC sibling does not exist (CHACHA20-POLY1305 -> "CHACHA20-CBC"). md_valid() has the same shape for digests.
The stale entry then misleads code that classifies an unrelated failure with ERR_peek_error(), which returns the OLDEST queued entry. The visible symptom is backend_tls_ctx_reload_crl() logging "CRL: cannot read CRL from file" on the first handshake after the CRL file changes although the CRL loaded fine (GitHub #1103). Traced with gdb on OpenVPN 2.7.0 and master with OpenSSL 3.5.5: the single entry on the queue at reload entry is the cipher_kt_mode_ofb_cfb("none") fetch from do_init_crypto_tls() of that same client instance.
Bracket the probing fetches with ERR_set_mark()/ERR_pop_to_mark() so a failed lookup leaves the queue as it found it; the return value already carries the answer these callers want. wolfSSL's compatibility layer has no error marks, so openssl_compat.h maps them to ERR_clear_error() there.
With this change the error queue is empty at multi_create_instance() and at backend_tls_ctx_reload_crl() entry for UDP, TCP and CHACHA20-POLY1305 clients, and the spurious warning is gone: three CRL replacements, three handshakes, zero warnings (unpatched: three of three).
--- src/openvpn/crypto_openssl.c | 16 +++++++++++++++- src/openvpn/openssl_compat.h | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-)
src/openvpn/crypto_openssl.c +15 -1
@@ -569,7 +569,17 @@ cipher_get(const char *ciphername)ASSERT (ciphername); ciphername =translate_cipher_name_from_openvpn (ciphername); -return EVP_CIPHER_fetch (NULL , ciphername,NULL ); + +/* A failed fetch leaves an EVP "unsupported" error on the thread's +* error queue. Callers legitimately probe names OpenSSL does not know +* ("none" for the not-yet-negotiated key_type, the CBC sibling of an +* AEAD cipher, user supplied names) and only look at the return value, +* so drop whatever the fetch raised instead of leaving it for an +* unrelated ERR_peek_error() to misinterpret later. */ +ERR_set_mark (); +evp_cipher_type *cipher =EVP_CIPHER_fetch (NULL , ciphername,NULL ); +ERR_pop_to_mark (); +return cipher; }bool
@@ -692,7 +702,9 @@ cipher_kt_block_size(const char *ciphername)strcpy (mode_str,"-CBC" ); +ERR_set_mark (); cbc_cipher =EVP_CIPHER_fetch (NULL ,translate_cipher_name_from_openvpn (name),NULL ); +ERR_pop_to_mark ();if (cbc_cipher) { block_size =EVP_CIPHER_block_size (cbc_cipher);
@@ -1001,7 +1013,9 @@ md_get(const char *digest)bool md_valid (const char *digest) { +ERR_set_mark ();evp_md_type *md =EVP_MD_fetch (NULL , digest,NULL ); +ERR_pop_to_mark ();bool valid = (md !=NULL );EVP_MD_free (md);return valid;
src/openvpn/openssl_compat.h +18 -0
@@ -47,6 +47,24 @@/* Define the type of error. This is something that is less * intrusive than casts everywhere */ +#if defined(ENABLE_CRYPTO_WOLFSSL ) +/* wolfSSL's OpenSSL compatibility layer has no error queue marks. The +* callers use them to drop what a failed lookup raised, so fall back to +* clearing the queue. */ +static inline int +ERR_set_mark (void ) +{ +return 1 ; +} + +static inline int +ERR_pop_to_mark (void ) +{ +ERR_clear_error (); +return 1 ; +} +#endif /* defined(ENABLE_CRYPTO_WOLFSSL) */ +#if defined(OPENSSL_IS_AWSLC )typedef uint32_t openssl_err_t ;typedef size_t openssl_stack_size_t ;
Signature · 8 lines
2.53.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
cover Stop failed cipher/digest lookups from polluting the OpenSSL error queue
This is the root-cause follow-up to the "CRL: cannot read CRL from file" report (GitHub #1103, PR #1104, which Arne rightly called a symptom fix).
Traced with gdb on OpenVPN 2.7.0 and master against OpenSSL 3.5.5: the entry that misleads the CRL reload is left by cipher_get() being asked for the cipher "none". That is the pre-negotiation key_type every server without --cipher gets (BF-CBC default, not in --data-ciphers), and every new client instance walks it in do_init_crypto_tls() and the frame/OCC calculations. cipher_kt_block_size()'s CBC-sibling probe and md_valid() have the same shape.
Patch 1 makes those probing lookups leave the queue as they found it (ERR_set_mark/ERR_pop_to_mark, with a wolfSSL fallback in openssl_compat.h). Patch 2 is the earlier CRL-side change, kept as
hardening: the EOF test now looks at the error PEM_read just raised rather than the oldest queued one, so no other leftover can produce the warning either.
Validated on an aarch64 Ubuntu 26.04 server (DCO) with UDP, TCP and CHACHA20-POLY1305 clients: the queue is empty at multi_create_instance() and at backend_tls_ctx_reload_crl() entry, three CRL replacements give three clean reloads (unpatched: three warnings), and a garbage CRL still fails with "loaded 0 CRLs" / "VERIFY ERROR: CRL not loaded".
Not compile-tested against wolfSSL; the shim is two static inlines.
Drew Blokzyl (2):
Drop the OpenSSL errors a failed cipher/digest lookup leaves behind Make CRL reload EOF detection independent of stale error queue entries
src/openvpn/crypto_openssl.c | 16 +++++++++++++++- src/openvpn/openssl_compat.h | 18 ++++++++++++++++++ src/openvpn/ssl_openssl.c | 13 +++++++++++-- 3 files changed, 44 insertions(+), 3 deletions(-)
Signature · 8 lines
2.53.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
PATCH v2 1/2 Do not look up the "none" cipher in OpenSSL
In reply to Drew Blokzylcipher_get() hands EVP_CIPHER_fetch() whatever name it is given, and the callers that only ask whether a cipher exists or which mode it has (cipher_kt_mode_cbc/ofb_cfb/aead(), cipher_kt_block_size(), cipher_kt_insecure()) treat NULL as "not that". For the "none" cipher that is the expected answer, but under OpenSSL 3 the failed fetch also pushes EVP_R_UNSUPPORTED ("digital envelope routines::unsupported, Algorithm (none : 0)") onto the thread's error queue, and nothing pops it.
"none" is what every server without --cipher carries in its pre-negotiation key_type: the legacy BF-CBC default is not in --data-ciphers, so do_init_crypto_tls() initialises the key_type with cipher "none". Each new client instance walks it in init_instance() -> do_init_crypto_tls() -> cipher_kt_mode_ofb_cfb("none") and in the frame and OCC calculations, and tls_ctx_reload_crl() runs right after. Its EOF test reads ERR_peek_error(), the OLDEST queued entry, so on the first handshake after the CRL file changed it finds the stale "unsupported" error and logs "CRL: cannot read CRL from file" for a CRL it loaded fine (GitHub #1103). Traced with gdb on 2.7.0 and master against OpenSSL 3.5.5.
Return NULL for "none" before touching OpenSSL, as cipher_kt_name() already does. Real cipher names behave as before, and cipher_valid_reason() still finds the OpenSSL reason on the queue when it reports an unknown cipher.
Left alone on purpose: cipher_kt_block_size()'s probe for the CBC sibling of an AEAD cipher (CHACHA20-POLY1305 -> "CHACHA20-CBC") and md_valid() leave the same kind of entry, but neither runs between client instance creation and the CRL reload. The next commit makes that reload robust against any leftover.
With this change the queue is empty at multi_create_instance() and at backend_tls_ctx_reload_crl() entry for UDP, TCP and CHACHA20-POLY1305 clients; three CRL replacements give three clean reloads (unpatched:
three warnings).
--- src/openvpn/crypto_openssl.c | 9 +++++++++ 1 file changed, 9 insertions(+)
src/openvpn/crypto_openssl.c +9 -0
@@ -568,6 +568,15 @@ cipher_get(const char *ciphername) {ASSERT (ciphername); +/* "none" is a valid OpenVPN cipher name that OpenSSL does not know. +* Return NULL without asking OpenSSL: a failed EVP_CIPHER_fetch() would +* leave an "unsupported" entry on the error queue that the cipher_kt_*() +* callers never clear. */ +if (strcmp ("none" , ciphername) ==0 ) + { +return NULL ; + } + ciphername =translate_cipher_name_from_openvpn (ciphername);return EVP_CIPHER_fetch (NULL , ciphername,NULL ); }
Signature · 8 lines
2.53.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
PATCH v2 2/2 Make CRL reload EOF detection independent of stale error queue entries
In reply to Drew Blokzylbackend_tls_ctx_reload_crl() treats a NULL from PEM_read_bio_X509_CRL() as EOF when ERR_peek_error() shows PEM_R_NO_START_LINE. ERR_peek_error() returns the OLDEST queued error, so any entry left behind earlier in the thread turns a clean EOF into a "CRL: cannot read CRL from file" warning, prints the unrelated errors as if they came from the CRL file, and still installs the CRLs already parsed. The previous commit removes the leftover that triggered this in practice; this one stops the loop from depending on the queue being clean at all.
Start the loop from an empty queue so only errors raised by PEM_read_bio_X509_CRL() are visible, test the error it raised last rather than the oldest one, and clear the queue on the EOF path instead of popping a single entry.
--- src/openvpn/ssl_openssl.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
src/openvpn/ssl_openssl.c +11 -2
@@ -1360,6 +1360,13 @@ backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, b }int num_crls_loaded =0 ; +/* +* Start from an empty error queue so the EOF test below only sees errors +* raised by PEM_read_bio_X509_CRL(). A stale error left by an earlier +* operation in this thread would otherwise be what ERR_peek_error() +* returns, and a clean EOF gets reported as "cannot read CRL". +*/ +ERR_clear_error ();while (true) {X509_CRL *crl =PEM_read_bio_X509_CRL (in,NULL ,NULL ,NULL );
@@ -1367,13 +1374,15 @@ backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, b {/* * PEM_R_NO_START_LINE can be considered equivalent to EOF. +* ERR_peek_last_error() is the error PEM_read_bio_X509_CRL() +* raised last; ERR_peek_error() would be the oldest queued one. */ -bool eof =ERR_GET_REASON (ERR_peek_error ()) ==PEM_R_NO_START_LINE ; +bool eof =ERR_GET_REASON (ERR_peek_last_error ()) ==PEM_R_NO_START_LINE ;/* but warn if no CRLs have been loaded */ if (num_crls_loaded >0 && eof) {/* remove that error from error stack */ - (void )ERR_get_error (); +ERR_clear_error ();break ; }
Signature · 8 lines
2.53.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
v2 cover Stop failed cipher/digest lookups from polluting the OpenSSL error queue
In reply to Drew BlokzylFrom: Ubuntu <[email protected]>
Root-cause follow-up to the "CRL: cannot read CRL from file" report (GitHub #1103, PR #1104, Gerrit change 1950 for v1 of patch 1).
Changes in v2:
Patch 1 takes the shape Arne suggested on the PR review: cipher_get() returns NULL for "none" before touching OpenSSL, no error marks and no wolfSSL shim, so cipher_valid_reason() keeps finding the OpenSSL reason on the queue when it reports an unknown cipher (Razvan's point on Gerrit 1950). The CBC-sibling probe in cipher_kt_block_size() and md_valid() are left as they are and named in the commit message; measured on the same rig, the entry the CHACHA20-CBC probe leaves does not survive to the next client instance.
Patch 2 is unchanged.
Validated again on the aarch64 Ubuntu 26.04 server (OpenSSL 3.5.5, DCO) with gdb watching the queue: five client instances (UDP, TCP, CHACHA20-POLY1305, a plain one after it, and one against a garbage CRL) enter multi_create_instance() and backend_tls_ctx_reload_crl() with an empty queue, four CRL replacements give four clean reloads, the garbage CRL still fails with "loaded 0 CRLs" / "VERIFY ERROR: CRL not loaded".
Drew Blokzyl (2):
Do not look up the "none" cipher in OpenSSL
Make CRL reload EOF detection independent of stale error queue entries
src/openvpn/crypto_openssl.c | 9 +++++++++ src/openvpn/ssl_openssl.c | 13 +++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-)
Signature · 8 lines
2.53.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
PATCH v3 2/2 Make CRL reload EOF detection independent of stale error queue entries
In reply to Drew Blokzylbackend_tls_ctx_reload_crl() treats a NULL from PEM_read_bio_X509_CRL() as EOF when ERR_peek_error() shows PEM_R_NO_START_LINE. ERR_peek_error() returns the OLDEST queued error, so any entry left behind earlier in the thread turns a clean EOF into a "CRL: cannot read CRL from file" warning, prints the unrelated errors as if they came from the CRL file, and still installs the CRLs already parsed. The previous commit removes the leftover that triggered this in practice; this one stops the loop from depending on the queue being clean at all.
If the queue is not empty when the CRL is loaded, say so at D_LOW with the queued errors, since that is a bug somewhere else worth seeing, then start the loop from an empty queue so only errors raised by PEM_read_bio_X509_CRL() are visible. Test the error it raised last rather than the oldest one, and clear the queue on the EOF path instead of popping a single entry.
--- src/openvpn/ssl_openssl.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
src/openvpn/ssl_openssl.c +17 -2
@@ -1360,6 +1360,19 @@ backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, b }int num_crls_loaded =0 ; +/* +* The EOF test below must only see errors raised by +* PEM_read_bio_X509_CRL(). Anything already queued was left by an +* earlier operation in this thread and would otherwise be what +* ERR_peek_error() returns, turning a clean EOF into "cannot read CRL". +* Report it, since that is a bug elsewhere, then start from an empty +* queue (crypto_msg() drains the queue while printing it). +*/ +if (ERR_peek_error () !=0 ) + { +crypto_msg (D_LOW ,"CRL: OpenSSL error queue not empty on CRL load" ); + } +ERR_clear_error ();while (true) {X509_CRL *crl =PEM_read_bio_X509_CRL (in,NULL ,NULL ,NULL );
@@ -1367,13 +1380,15 @@ backend_tls_ctx_reload_crl(struct tls_root_ctx *ssl_ctx, const char *crl_file, b {/* * PEM_R_NO_START_LINE can be considered equivalent to EOF. +* ERR_peek_last_error() is the error PEM_read_bio_X509_CRL() +* raised last; ERR_peek_error() would be the oldest queued one. */ -bool eof =ERR_GET_REASON (ERR_peek_error ()) ==PEM_R_NO_START_LINE ; +bool eof =ERR_GET_REASON (ERR_peek_last_error ()) ==PEM_R_NO_START_LINE ;/* but warn if no CRLs have been loaded */ if (num_crls_loaded >0 && eof) {/* remove that error from error stack */ - (void )ERR_get_error (); +ERR_clear_error ();break ; }
Signature · 8 lines
2.53.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
v3 cover Stop failed cipher/digest lookups from polluting the OpenSSL error queue
In reply to Drew BlokzylRoot-cause follow-up to the "CRL: cannot read CRL from file" report (GitHub #1103, PR #1104, Gerrit change 1950 for v1 of patch 1).
Changes in v3, both from Arne's review on the PR:
Patch 1: md_get() gets the same "none" guard as cipher_get(). Note this changes md_get("none") from a fatal "Message hash algorithm 'none' not found" to a NULL return; no caller passes "none" today (md_kt_name(), md_kt_size() and md_defined() check first), so behaviour is unchanged, but a future caller would hit the NULL rather than the fatal. Say if you would rather have an ASSERT there.
Patch 2: instead of clearing the queue silently before the CRL read loop, report a non-empty queue at D_LOW with the queued errors, then clear. crypto_msg() only drains the queue when the level is enabled, so the explicit ERR_clear_error() after it is what empties the queue at normal verbosity.
Changes in v2: patch 1 returns NULL for "none" before touching OpenSSL, no error marks and no wolfSSL shim, so cipher_valid_reason() keeps the OpenSSL reason for unknown names (Razvan's point on Gerrit 1950).
Validation on the aarch64 Ubuntu 26.04 server (OpenSSL 3.5.5, DCO) with gdb watching the queue:
- v3, both patches: UDP, TCP, CHACHA20-POLY1305 and a plain client after it enter multi_create_instance() and backend_tls_ctx_reload_crl() with an empty queue; four CRL replacements give four clean reloads; a garbage CRL still fails with "loaded 0 CRLs" / "VERIFY ERROR: CRL not loaded".
- patch 2 alone on master, i.e. with the "none" polluter still live:
the new D_LOW line fires with the stale "unsupported" entry printed above it, followed by "loaded 1 CRLs" and no false warning, on both a UDP and a TCP handshake after a CRL replacement.
Drew Blokzyl (2):
Do not look up the "none" cipher or digest in OpenSSL
Make CRL reload EOF detection independent of stale error queue entries
src/openvpn/crypto_openssl.c | 17 +++++++++++++++++ src/openvpn/ssl_openssl.c | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-)
Signature · 8 lines
2.53.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
PATCH v3 1/2 Do not look up the "none" cipher or digest in OpenSSL
cipher_get() hands EVP_CIPHER_fetch() whatever name it is given, and the callers that only ask whether a cipher exists or which mode it has (cipher_kt_mode_cbc/ofb_cfb/aead(), cipher_kt_block_size(), cipher_kt_insecure()) treat NULL as "not that". For the "none" cipher that is the expected answer, but under OpenSSL 3 the failed fetch also pushes EVP_R_UNSUPPORTED ("digital envelope routines::unsupported, Algorithm (none : 0)") onto the thread's error queue, and nothing pops it.
"none" is what every server without --cipher carries in its pre-negotiation key_type: the legacy BF-CBC default is not in --data-ciphers, so do_init_crypto_tls() initialises the key_type with cipher "none". Each new client instance walks it in init_instance() -> do_init_crypto_tls() -> cipher_kt_mode_ofb_cfb("none") and in the frame and OCC calculations, and tls_ctx_reload_crl() runs right after. Its EOF test reads ERR_peek_error(), the OLDEST queued entry, so on the first handshake after the CRL file changed it finds the stale "unsupported" error and logs "CRL: cannot read CRL from file" for a CRL it loaded fine (GitHub #1103). Traced with gdb on 2.7.0 and master against OpenSSL 3.5.5.
Return NULL for "none" before touching OpenSSL, as cipher_kt_name() already does. Real cipher names behave as before, and cipher_valid_reason() still finds the OpenSSL reason on the queue when it reports an unknown cipher. md_get() gets the same guard: no caller passes "none" today (md_kt_name(), md_kt_size() and md_defined() check first), but it has the same shape and would leave the same entry.
Left alone on purpose: cipher_kt_block_size()'s probe for the CBC sibling of an AEAD cipher (CHACHA20-POLY1305 -> "CHACHA20-CBC") and md_valid() leave the same kind of entry, but neither runs between client instance creation and the CRL reload. The next commit makes that reload robust against any leftover and reports one when it sees it.
With this change the queue is empty at multi_create_instance() and at backend_tls_ctx_reload_crl() entry for UDP, TCP and CHACHA20-POLY1305 clients; CRL replacements give clean reloads (unpatched: a warning every time).
--- src/openvpn/crypto_openssl.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
src/openvpn/crypto_openssl.c +17 -0
@@ -568,6 +568,15 @@ cipher_get(const char *ciphername) {ASSERT (ciphername); +/* "none" is a valid OpenVPN cipher name that OpenSSL does not know. +* Return NULL without asking OpenSSL: a failed EVP_CIPHER_fetch() would +* leave an "unsupported" entry on the error queue that the cipher_kt_*() +* callers never clear. */ +if (strcmp ("none" , ciphername) ==0 ) + { +return NULL ; + } + ciphername =translate_cipher_name_from_openvpn (ciphername);return EVP_CIPHER_fetch (NULL , ciphername,NULL ); }
@@ -981,6 +990,14 @@ md_get(const char *digest) {evp_md_type *md =NULL ;ASSERT (digest); + +/* "none" is a valid OpenVPN digest name that OpenSSL does not know. +* Return NULL without asking OpenSSL, see cipher_get(). */ +if (strcmp ("none" , digest) ==0 ) + { +return NULL ; + } + md =EVP_MD_fetch (NULL , digest,NULL );if (!md) {
Signature · 8 lines
2.53.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
PATCH v4 1/1 Do not look up the "none" cipher in OpenSSL
In reply to Drew Blokzylcipher_get() hands EVP_CIPHER_fetch() whatever name it is given, and the callers that only ask whether a cipher exists or which mode it has (cipher_kt_mode_cbc/ofb_cfb/aead(), cipher_kt_block_size(), cipher_kt_insecure()) treat NULL as "not that". For the "none" cipher that is the expected answer, but under OpenSSL 3 the failed fetch also pushes EVP_R_UNSUPPORTED ("digital envelope routines::unsupported, Algorithm (none : 0)") onto the thread's error queue, and nothing pops it.
"none" is what every server without --cipher carries in its pre-negotiation key_type: the legacy BF-CBC default is not in --data-ciphers, so do_init_crypto_tls() initialises the key_type with cipher "none". Each new client instance walks it in init_instance() -> do_init_crypto_tls() -> cipher_kt_mode_ofb_cfb("none") and in the frame and OCC calculations, and tls_ctx_reload_crl() runs right after. Before commit 15a1465f ("Make CRL reload EOF detection independent of stale error queue entries") that stale entry made the first handshake after a CRL change log "CRL: cannot read CRL from file" for a CRL it loaded fine (GitHub #1103); since then the reload reports it at D_LOW as "CRL:
OpenSSL error queue not empty on CRL load" and clears it.
Return NULL for "none" before touching OpenSSL, as cipher_kt_name() already does. Real cipher names behave as before, and cipher_valid_reason() still finds the OpenSSL reason on the queue when it reports an unknown cipher.
Left alone on purpose: cipher_kt_block_size()'s probe for the CBC sibling of an AEAD cipher (CHACHA20-POLY1305 -> "CHACHA20-CBC") and md_valid() leave the same kind of entry, but neither runs between client instance creation and the CRL reload.
With this change the queue is empty when the CRL reload runs for UDP and TCP clients, and CRL replacements give clean reloads with no "error queue not empty" report (current master: one per replacement).
---
v4: drop the md_get() guard (Razvan, Gerrit 1950 PS2). No caller can
reach md_get() with "none", so it protected nothing and only changed how md_get() reports a failure. Arne asked for it in v3; I agree with Razvan that it does not belong here. Subject and commit message amended to match. Patch 2/2 of v3 is in master as 15a1465f, so the message now refers to it instead of "the next commit".
Retested on master 54a66f35 + this patch, OpenSSL 3, UDP and TCP clients, CRL replaced before each connect: master logs the stale "unsupported" entry and "CRL: OpenSSL error queue not empty on CRL load" on every reload; with this patch only "CRL: loaded 1 CRLs". make check: 23 pass, 0 fail.
src/openvpn/crypto_openssl.c | 9 +++++++++ 1 file changed, 9 insertions(+)
src/openvpn/crypto_openssl.c +9 -0
@@ -568,6 +568,15 @@ cipher_get(const char *ciphername) {ASSERT (ciphername); +/* "none" is a valid OpenVPN cipher name that OpenSSL does not know. +* Return NULL without asking OpenSSL: a failed EVP_CIPHER_fetch() would +* leave an "unsupported" entry on the error queue that the cipher_kt_*() +* callers never clear. */ +if (strcmp ("none" , ciphername) ==0 ) + { +return NULL ; + } + ciphername =translate_cipher_name_from_openvpn (ciphername);return EVP_CIPHER_fetch (NULL , ciphername,NULL ); }
Signature · 8 lines
2.53.0 _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel