From: "cron2 (Code Review)" Date: Sat, 4 Apr 2026 14:00:41 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <05c08a485dd1d3fc33b52c5f8e6d4f9d49439edf-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="1P34w3hsNxQ="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Use ASN1_BIT_STRING_get_bit to check for netscape certificate usage List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: flichtenheld , openvpn-devel --1P34w3hsNxQ= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/15= 87?usp=3Demail ) Change subject: Use ASN1_BIT_STRING_get_bit to check for netscape certifica= te usage ...................................................................... Use ASN1_BIT_STRING_get_bit to check for netscape certificate usage The ASN_BIT_STRING object has become opaque in OpenSSL 4.0. So instead of accessing the internal, we have to use a method now to check these attributes. The bit counting in ASN.1 and of this method is a bit strange and it will count bits from the left instead of the right, so the previous mask of 0x80 for clients is now 0 and 0x40 for server is now 1. Change-Id: I77500d435f212a4bf42ee8cfca07d0285fe694f2 Signed-off-by: Arne Schwabe Acked-by: Frank Lichtenheld Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1587 Message-Id: <20260404072336.30014-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36= 446.html Signed-off-by: Gert Doering --- M src/openvpn/ssl_verify_openssl.c 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_verify_open= ssl.c index 08946cd..c70022f 100644 --- a/src/openvpn/ssl_verify_openssl.c +++ b/src/openvpn/ssl_verify_openssl.c @@ -609,22 +609,27 @@ if (usage =3D=3D NS_CERT_CHECK_CLIENT) { /* - * Unfortunately, X509_check_purpose() does some weird thing that + * Unfortunately, X509_check_purpose() before OpenSSL 4.0 does som= e weird thing that * prevent it to take a const argument */ result_t result =3D X509_check_purpose(peer_cert, X509_PURPOSE_SSL_CLIENT, 0) ? SU= CCESS : FAILURE; - /* - * old versions of OpenSSL allow us to make the less strict check = we used to - * do. If this less strict check pass, warn user that this might n= ot be the - * case when its distribution will update to OpenSSL 1.1 + * Note that we did not check for netscape certificate type here b= ut + * instead a general SSL/TLS client purpose. These nscert attribut= es + * might stop being accepted by TLS libraries in the future. + * Currently, OpenSSL 4.0 and aws-lc 1.9.0 still consider nscert c= lient + * as acceptable. + * + * So in case that this check failed, we now check if this is caus= ed + * by the check above no longer recognising nscert attributes. */ if (result =3D=3D FAILURE) { ASN1_BIT_STRING *ns; ns =3D X509_get_ext_d2i(peer_cert, NID_netscape_cert_type, NUL= L, NULL); - result =3D (ns && ASN1_STRING_length(ns) > 0 && (ASN1_STRING_g= et0_data(ns)[0] & NS_SSL_CLIENT)) ? SUCCESS : FAILURE; + // bit 0 is to check if certificate is the client certificate + result =3D ASN1_BIT_STRING_get_bit(ns, 0) ? SUCCESS : FAILURE; if (result =3D=3D SUCCESS) { msg(M_WARN, "X509: Certificate is a client certificate yet= it's purpose " @@ -637,22 +642,27 @@ if (usage =3D=3D NS_CERT_CHECK_SERVER) { /* - * Unfortunately, X509_check_purpose() does some weird thing that + * Unfortunately, X509_check_purpose() before OpenSSL 4.0 does som= e weird thing that * prevent it to take a const argument */ result_t result =3D X509_check_purpose(peer_cert, X509_PURPOSE_SSL_SERVER, 0) ? SU= CCESS : FAILURE; /* - * old versions of OpenSSL allow us to make the less strict check = we used to - * do. If this less strict check pass, warn user that this might n= ot be the - * case when its distribution will update to OpenSSL 1.1 + * Note that we did not check for netscape certificate type here b= ut + * instead a general SSL/TLS server purpose. These nscert attribut= es + * might stop being accepted by TLS libraries in the future. + * Currently, OpenSSL 4.0 and aws-lc 1.9.0 still consider nscert s= erver + * as acceptable. + * + * So in case that this check failed, we now check if this is caus= ed + * by the check above no longer recognising nscert attributes. */ if (result =3D=3D FAILURE) { - ASN1_BIT_STRING *ns; - ns =3D X509_get_ext_d2i(peer_cert, NID_netscape_cert_type, NUL= L, NULL); - result =3D (ns && ASN1_STRING_length(ns) > 0 && (ASN1_STRING_g= et0_data(ns)[0] & NS_SSL_SERVER)) ? SUCCESS : FAILURE; + ASN1_BIT_STRING *ns =3D X509_get_ext_d2i(peer_cert, NID_netsca= pe_cert_type, NULL, NULL); + // Server bit is 1 for ASN1_BIT_STRING_get_bit + result =3D ASN1_BIT_STRING_get_bit(ns, 1) ? SUCCESS : FAILURE; if (result =3D=3D SUCCESS) { msg(M_WARN, "X509: Certificate is a server certificate yet= it's purpose " -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1587?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: merged Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I77500d435f212a4bf42ee8cfca07d0285fe694f2 Gerrit-Change-Number: 1587 Gerrit-PatchSet: 7 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel --1P34w3hsNxQ= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

Use ASN1_BIT_STRING_get_bit to check for netscap=
e certificate usage

The ASN_BIT_STRING object has become opaque in O= penSSL 4.0. So instead
of accessing the internal, we have to use a metho= d now to check these
attributes.

The bit counting in ASN.1 and of= this method is a bit strange and
it will count bits from the left inste= ad of the right, so the previous
mask of 0x80 for clients is now 0 and 0= x40 for server is now 1.

Change-Id: I77500d435f212a4bf42ee8cfca07d02= 85fe694f2
Signed-off-by: Arne Schwabe <arne@...1227...>
Acked-b= y: Frank Lichtenheld <frank@...2641...>
Gerrit URL: https://gerrit= .openvpn.net/c/openvpn/+/1587
Message-Id: <20260404072336.30014-1-ger= t@...1296...>
URL: https://www.mail-archive.com/openvpn-devel@...1096...= ourceforge.net/msg36446.html
Signed-off-by: Gert Doering <gert@...1826...= 6...>
---
M src/openvpn/ssl_verify_openssl.c
1 file changed, 23= insertions(+), 13 deletions(-)

diff --git a/src/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_verify_o=
penssl.c
index 08946cd..c70022f 100644
--- = a/src/openvpn/ssl_verify_openssl.c
+++ b/src/openvpn/ssl_ve= rify_openssl.c
@@ -609,22 +609,27 @@
i= f (usage =3D=3D NS_CERT_CHECK_CLIENT)
{
/*
- = * Unfortunately, X509_check_purpose() does some weird thing that+ * Unfortunately, X50= 9_check_purpose() before OpenSSL 4.0 does some weird thing that
<= span> * prevent it to take a const argument
= */
result_t result =3D
= X509_check_purpose(peer_cert, X509_PURPOSE_SSL_CLIENT, 0) ? SUCCESS := FAILURE;
-
<= span> /*
- = * old versions of OpenSSL allow us to make the less strict check we use= d to
- * do. If= this less strict check pass, warn user that this might not be the- * case when its distr= ibution will update to OpenSSL 1.1
+ * Note that we did not check for netscape certifica= te type here but
+ = * instead a general SSL/TLS client purpose. These nscert attributes
+ * might stop= being accepted by TLS libraries in the future.
+ * Currently, OpenSSL 4.0 and aws-lc 1.= 9.0 still consider nscert client
+ * as acceptable.
+ *
+ * So in case that this check failed, we now check if thi= s is caused
+ = * by the check above no longer recognising nscert attributes.
*/

if (result =3D=3D FAILURE)=
{
ASN1_BIT_STRING *ns;

ns =3D X509_get_ext_d2i(peer_cert, NID_netscape_ce= rt_type, NULL, NULL);
-= result =3D (ns && ASN1_STRING_length(ns) > 0 &&a= mp; (ASN1_STRING_get0_data(ns)[0] & NS_SSL_CLIENT)) ? SUCCESS : FAILURE= ;
+ // bit= 0 is to check if certificate is the client certificate
+ result =3D ASN1_BIT_STRING_= get_bit(ns, 0) ? SUCCESS : FAILURE;
if (result= =3D=3D SUCCESS)
{
= msg(M_WARN, "X509: Certificate is a client certificate yet it= 9;s purpose "
@@ -637,22 +642,27 @@
= if (usage =3D=3D NS_CERT_CHECK_SERVER)
{
= /*
- = * Unfortunately, X509_check_purpose() does some weird thing that
+ * Unfortunately,= X509_check_purpose() before OpenSSL 4.0 does some weird thing that<= br> * prevent it to take a const argument
= */
result_t result =3D
= X509_check_purpose(peer_cert, X509_PURPOSE_SSL_SERVER, 0) ? SUCCE= SS : FAILURE;

/*
- * old versions of OpenSSL al= low us to make the less strict check we used to

- * do. If this less strict check pass, wa= rn user that this might not be the
- * case when its distribution will update to OpenSSL 1= .1
+ * Note t= hat we did not check for netscape certificate type here but
+ * instead a general SSL/TL= S server purpose. These nscert attributes
+ * might stop being accepted by TLS libraries= in the future.
+ = * Currently, OpenSSL 4.0 and aws-lc 1.9.0 still consider nscert server=
+ * as accep= table.
+ *
+ * So in case = that this check failed, we now check if this is caused
+ * by the check above no longer = recognising nscert attributes.
*/
if (result =3D=3D FAILURE)

{
<= span style=3D"color: hsl(0, 100%, 40%);">- ASN1_BIT_STRING *ns;<= /span>
- ns =3D X50= 9_get_ext_d2i(peer_cert, NID_netscape_cert_type, NULL, NULL);
- result =3D (ns &&am= p; ASN1_STRING_length(ns) > 0 && (ASN1_STRING_get0_data(ns)[0] &= amp; NS_SSL_SERVER)) ? SUCCESS : FAILURE;
+ ASN1_BIT_STRING *ns =3D X509_get_ext_d2i(= peer_cert, NID_netscape_cert_type, NULL, NULL);
+ // Server bit is 1 for ASN1_BIT_STR= ING_get_bit
+ = result =3D ASN1_BIT_STRING_get_bit(ns, 1) ? SUCCESS : FAILURE; if (result =3D=3D SUCCESS)
= {
msg(M_WARN, "X509: Certificate is= a server certificate yet it's purpose "

To view, visit change 1587. To unsubscribe, or for help writing mail= filters, visit = settings.

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I77500d435f212a4bf42ee8cfca0= 7d0285fe694f2
Gerrit-Change-Number: 1587
Gerrit-PatchSet: 7
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --1P34w3hsNxQ=--