[Openvpn-devel,v2] Use ASN1_STRING_get_length instead of ASN1_STRING_length

Message ID 20261102141709.30018-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v2] Use ASN1_STRING_get_length instead of ASN1_STRING_length |

Commit Message

Gert Doering Nov. 2, 2026, 2:17 p.m. UTC
  From: Arne Schwabe <arne@rfc2549.org>

OpenSSL 4.1 introduced ASN1_STRING_get_length and at the same
time deprecated the ASN1_STRING_length method. Use the
new method and keep and compat macro for older versions and
other OpenSSL like libraries.

Change-Id: I1bff3107f95b403d554bea4262c2dda270a1fc79
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Razvan Cojocaru <razvanc@mailbox.org>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2087
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2087
This mail reflects revision 2 of this Change.

Acked-by according to Gerrit (reflected above):
Razvan Cojocaru <razvanc@mailbox.org>
  

Patch

diff --git a/src/openvpn/openssl_compat.h b/src/openvpn/openssl_compat.h
index 4305fea..8309cee 100644
--- a/src/openvpn/openssl_compat.h
+++ b/src/openvpn/openssl_compat.h
@@ -204,4 +204,9 @@ 
 #define EVP_CIPH_FLAG_ENC_THEN_MAC 0x10000000
 #endif
 
+/* Introduced in OpenSSL 4.1.0 */
+#if OPENSSL_VERSION_NUMBER < 0x40100000
+#define ASN1_STRING_get_length (size_t)ASN1_STRING_length
+#endif
+
 #endif /* OPENSSL_COMPAT_H_ */
diff --git a/src/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_verify_openssl.c
index 146a384..0c36cf2 100644
--- a/src/openvpn/ssl_verify_openssl.c
+++ b/src/openvpn/ssl_verify_openssl.c
@@ -154,7 +154,7 @@ 
                     {
                         continue;
                     }
-                    if ((ssize_t)strlen(buf) != ASN1_STRING_length(name->d.rfc822Name))
+                    if (strlen(buf) != ASN1_STRING_get_length(name->d.rfc822Name))
                     {
                         msg(D_TLS_ERRORS, "ASN1 ERROR: string contained terminating zero");
                     }