Skip to contentSkip to conversation

Change in openvpn[master]: ssl_verify_openssl: Clean up extract_x509_extension

Openvpn-devel In review flichtenheld (Code Review) 3 participants 8 messages Jan 30 – Mar 23 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1769789455000.I23cc00aee47aef007ab2e7d50b52c6de299505db@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1507?usp=email

to review the following change.

Change subject: ssl_verify_openssl: Clean up extract_x509_extension
......................................................................

ssl_verify_openssl: Clean up extract_x509_extension

* Avoid sign-compare warning when comparing string lengths
* Use the nicer alias rfc822Name instead of the general ia5 from the GENERAL_NAME union.
* Use the official ASN1_STRING_length API instead of accessing the struct directly.
* C11 changes

Change-Id I23cc00aee47aef007ab2e7d50b52c6de299505db

---
M src/openvpn/ssl_verify_openssl.c

1 file changed, 5 insertions(+), 16 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/1507/1

src/openvpn/ssl_verify_openssl.c +5 -16
index 58f665c..90a8a51 100644
@@ -118,16 +118,10 @@
     return nid == NID_subject_alt_name || nid == NID_issuer_alt_name;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 static bool
 extract_x509_extension(X509 *cert, char *fieldname, char *out, size_t size)
 {
     bool retval = false;
-    char *buf = 0;
 
     if (!x509_username_field_ext_supported(fieldname))
     {
@@ -139,17 +133,15 @@
     GENERAL_NAMES *extensions = X509_get_ext_d2i(cert, nid, NULL, NULL);
     if (extensions)
     {
-        int numalts;
-        int i;
         /* get amount of alternatives,
          * RFC2459 claims there MUST be at least
          * one, but we don't depend on it...
          */
 
-        numalts = sk_GENERAL_NAME_num(extensions);
+        int numalts = sk_GENERAL_NAME_num(extensions);
 
         /* loop through all alternatives */
-        for (i = 0; i < numalts; i++)
+        for (int i = 0; i < numalts; i++)
         {
             /* get a handle to alternative name number i */
             const GENERAL_NAME *name = sk_GENERAL_NAME_value(extensions, i);
@@ -157,11 +149,12 @@
             switch (name->type)
             {
                 case GEN_EMAIL:
-                    if (ASN1_STRING_to_UTF8((unsigned char **)&buf, name->d.ia5) < 0)
+                    char *buf = NULL;
+                    if (ASN1_STRING_to_UTF8((unsigned char **)&buf, name->d.rfc822Name) < 0)
                     {
                         continue;
                     }
-                    if (strlen(buf) != name->d.ia5->length)
+                    if ((ssize_t)strlen(buf) != ASN1_STRING_length(name->d.rfc822Name))
                     {
                         msg(D_TLS_ERRORS, "ASN1 ERROR: string contained terminating zero");
                         OPENSSL_free(buf);
@@ -185,10 +178,6 @@
     return retval;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * Extract a field from an X509 subject name.
  *

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1507?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I23cc00aee47aef007ab2e7d50b52c6de299505db
Gerrit-Change-Number: 1507
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1507?usp=email

to look at the new patch set (#2).

Change subject: ssl_verify_openssl: Clean up extract_x509_extension
......................................................................

ssl_verify_openssl: Clean up extract_x509_extension

* Avoid sign-compare warning when comparing string lengths
* Use the nicer alias rfc822Name instead of the general ia5 from the GENERAL_NAME union.
* Use the official ASN1_STRING_length API instead of accessing the struct directly.
* C11 changes

Change-Id I23cc00aee47aef007ab2e7d50b52c6de299505db

---
M src/openvpn/ssl_verify_openssl.c

1 file changed, 6 insertions(+), 17 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/1507/2

src/openvpn/ssl_verify_openssl.c +6 -17
index 58f665c..46401cd 100644
@@ -118,16 +118,10 @@
     return nid == NID_subject_alt_name || nid == NID_issuer_alt_name;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 static bool
 extract_x509_extension(X509 *cert, char *fieldname, char *out, size_t size)
 {
     bool retval = false;
-    char *buf = 0;
 
     if (!x509_username_field_ext_supported(fieldname))
     {
@@ -139,29 +133,28 @@
     GENERAL_NAMES *extensions = X509_get_ext_d2i(cert, nid, NULL, NULL);
     if (extensions)
     {
-        int numalts;
-        int i;
         /* get amount of alternatives,
          * RFC2459 claims there MUST be at least
          * one, but we don't depend on it...
          */
 
-        numalts = sk_GENERAL_NAME_num(extensions);
+        int numalts = sk_GENERAL_NAME_num(extensions);
 
         /* loop through all alternatives */
-        for (i = 0; i < numalts; i++)
+        for (int i = 0; i < numalts; i++)
         {
             /* get a handle to alternative name number i */
             const GENERAL_NAME *name = sk_GENERAL_NAME_value(extensions, i);
+            char *buf = NULL;
 
             switch (name->type)
             {
                 case GEN_EMAIL:
-                    if (ASN1_STRING_to_UTF8((unsigned char **)&buf, name->d.ia5) < 0)
+                    if (ASN1_STRING_to_UTF8((unsigned char **)&buf, name->d.rfc822Name) < 0)
                     {
                         continue;
                     }
-                    if (strlen(buf) != name->d.ia5->length)
+                    if ((ssize_t)strlen(buf) != ASN1_STRING_length(name->d.rfc822Name))
                     {
                         msg(D_TLS_ERRORS, "ASN1 ERROR: string contained terminating zero");
                         OPENSSL_free(buf);
@@ -175,7 +168,7 @@
                     break;
 
                 default:
-                    msg(D_TLS_DEBUG, "%s: ignoring general name field type %i", __func__,
+                    msg(D_TLS_DEBUG, "%s: ignoring general name field type %d", __func__,
                         name->type);
                     break;
             }
@@ -185,10 +178,6 @@
     return retval;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * Extract a field from an X509 subject name.
  *

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1507?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I23cc00aee47aef007ab2e7d50b52c6de299505db
Gerrit-Change-Number: 1507
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld.

plaisthos has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1507?usp=email )

Change subject: ssl_verify_openssl: Clean up extract_x509_extension
......................................................................

Patch Set 7: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1507?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I23cc00aee47aef007ab2e7d50b52c6de299505db
Gerrit-Change-Number: 1507
Gerrit-PatchSet: 7
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 09 Mar 2026 13:14:54 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

#4 lore raw

PATCH v7 1/1 ssl_verify_openssl: Clean up extract_x509_extension

In reply to a message not in the archive

* Avoid sign-compare warning when comparing string lengths
* Use the nicer alias rfc822Name instead of the general ia5 from the GENERAL_NAME union.
* Use the official ASN1_STRING_length API instead of accessing the struct directly.
* C11 changes

Change-Id I23cc00aee47aef007ab2e7d50b52c6de299505db

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1507
---

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/+/1507
This mail reflects revision 7 of this Change.

Acked-by according to Gerrit (reflected above):
Arne Schwabe <[email protected]...>

src/openvpn/ssl_verify_openssl.c +6 -17
index 58f665c..46401cd 100644
@@ -118,16 +118,10 @@
     return nid == NID_subject_alt_name || nid == NID_issuer_alt_name;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 static bool
 extract_x509_extension(X509 *cert, char *fieldname, char *out, size_t size)
 {
     bool retval = false;
-    char *buf = 0;
 
     if (!x509_username_field_ext_supported(fieldname))
     {
@@ -139,29 +133,28 @@
     GENERAL_NAMES *extensions = X509_get_ext_d2i(cert, nid, NULL, NULL);
     if (extensions)
     {
-        int numalts;
-        int i;
         /* get amount of alternatives,
          * RFC2459 claims there MUST be at least
          * one, but we don't depend on it...
          */
 
-        numalts = sk_GENERAL_NAME_num(extensions);
+        int numalts = sk_GENERAL_NAME_num(extensions);
 
         /* loop through all alternatives */
-        for (i = 0; i < numalts; i++)
+        for (int i = 0; i < numalts; i++)
         {
             /* get a handle to alternative name number i */
             const GENERAL_NAME *name = sk_GENERAL_NAME_value(extensions, i);
+            char *buf = NULL;
 
             switch (name->type)
             {
                 case GEN_EMAIL:
-                    if (ASN1_STRING_to_UTF8((unsigned char **)&buf, name->d.ia5) < 0)
+                    if (ASN1_STRING_to_UTF8((unsigned char **)&buf, name->d.rfc822Name) < 0)
                     {
                         continue;
                     }
-                    if (strlen(buf) != name->d.ia5->length)
+                    if ((ssize_t)strlen(buf) != ASN1_STRING_length(name->d.rfc822Name))
                     {
                         msg(D_TLS_ERRORS, "ASN1 ERROR: string contained terminating zero");
                         OPENSSL_free(buf);
@@ -175,7 +168,7 @@
                     break;
 
                 default:
-                    msg(D_TLS_DEBUG, "%s: ignoring general name field type %i", __func__,
+                    msg(D_TLS_DEBUG, "%s: ignoring general name field type %d", __func__,
                         name->type);
                     break;
             }
@@ -185,10 +178,6 @@
     return retval;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * Extract a field from an X509 subject name.
  *
#5 lore raw

[Openvpn-devel] [PATCH applied] Re: ssl_verify_openssl: Clean up extract_x509_extension

This looked good to me, but "OpenSSL innards" are still foreign territory, so thanks Arne for looking at the ia5/rfc822Name change (I found it surprising since we had an "ia5->length" before and now need to do ASN1_STRING_LENGTH(), but I'm sure there is a good reason behind this).

Your patch has been applied to the master branch.

commit 66060627a8cf05c8761d75985e76482d20df4f29

Author: Frank Lichtenheld
Date:   Mon Mar 9 14:32:36 2026 +0100
     ssl_verify_openssl: Clean up extract_x509_extension

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1507
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg35980.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#6 lore raw

Re: [Openvpn-devel] [PATCH applied] Re: ssl_verify_openssl: Clean up extract_x509_extension

Hi,

Quoted 5 lines · Gert Doering

This looked good to me, but "OpenSSL innards" are still foreign territory, so thanks Arne for looking at the ia5/rfc822Name change (I found it surprising since we had an "ia5->length" before and now need to do ASN1_STRING_LENGTH(), but I'm sure there is a good reason behind this).

Quoted 7 lines

Your patch has been applied to the master branch.

commit 66060627a8cf05c8761d75985e76482d20df4f29

Author: Frank Lichtenheld
Date:   Mon Mar 9 14:32:36 2026 +0100

ssl_verify_openssl: Clean up extract_x509_extension

As suggested by Rudi Heitbaum in GH PR 1003, I have cherry-picked this back to release/2.7 - it's "long term compat". We expect OpenVPN 2.7.x to be maintained for long enough that OpenSSL4 becomes a thing, and then we need the patch - so we can do it right away, and be not surprised.

The patch is the same as in the master branch, except for the #pragma removal - which git does not care much about ("you want it gone, it was not there in the first place, so the net result is what you want").

Mildly tested via GH actions.

commit 5f0a168311a53b935f776d4c1566c4f2f3cde98b (release/2.7)

Author: Frank Lichtenheld <[email protected]...>
Date:   Mon Mar 9 14:32:36 2026 +0100

ssl_verify_openssl: Clean up extract_x509_extension
...

    (cherry picked from commit 66060627a8cf05c8761d75985e76482d20df4f29)

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]...
#7 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#8) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1507?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by plaisthos

Change subject: ssl_verify_openssl: Clean up extract_x509_extension
......................................................................

ssl_verify_openssl: Clean up extract_x509_extension

* Avoid sign-compare warning when comparing string lengths
* Use the nicer alias rfc822Name instead of the general ia5 from the GENERAL_NAME union.
* Use the official ASN1_STRING_length API instead of accessing the struct directly.
* C11 changes

Change-Id I23cc00aee47aef007ab2e7d50b52c6de299505db

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1507
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35980.html

---
M src/openvpn/ssl_verify_openssl.c

1 file changed, 6 insertions(+), 17 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/1507/8

src/openvpn/ssl_verify_openssl.c +6 -17
index 58f665c..46401cd 100644
@@ -118,16 +118,10 @@
     return nid == NID_subject_alt_name || nid == NID_issuer_alt_name;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 static bool
 extract_x509_extension(X509 *cert, char *fieldname, char *out, size_t size)
 {
     bool retval = false;
-    char *buf = 0;
 
     if (!x509_username_field_ext_supported(fieldname))
     {
@@ -139,29 +133,28 @@
     GENERAL_NAMES *extensions = X509_get_ext_d2i(cert, nid, NULL, NULL);
     if (extensions)
     {
-        int numalts;
-        int i;
         /* get amount of alternatives,
          * RFC2459 claims there MUST be at least
          * one, but we don't depend on it...
          */
 
-        numalts = sk_GENERAL_NAME_num(extensions);
+        int numalts = sk_GENERAL_NAME_num(extensions);
 
         /* loop through all alternatives */
-        for (i = 0; i < numalts; i++)
+        for (int i = 0; i < numalts; i++)
         {
             /* get a handle to alternative name number i */
             const GENERAL_NAME *name = sk_GENERAL_NAME_value(extensions, i);
+            char *buf = NULL;
 
             switch (name->type)
             {
                 case GEN_EMAIL:
-                    if (ASN1_STRING_to_UTF8((unsigned char **)&buf, name->d.ia5) < 0)
+                    if (ASN1_STRING_to_UTF8((unsigned char **)&buf, name->d.rfc822Name) < 0)
                     {
                         continue;
                     }
-                    if (strlen(buf) != name->d.ia5->length)
+                    if ((ssize_t)strlen(buf) != ASN1_STRING_length(name->d.rfc822Name))
                     {
                         msg(D_TLS_ERRORS, "ASN1 ERROR: string contained terminating zero");
                         OPENSSL_free(buf);
@@ -175,7 +168,7 @@
                     break;
 
                 default:
-                    msg(D_TLS_DEBUG, "%s: ignoring general name field type %i", __func__,
+                    msg(D_TLS_DEBUG, "%s: ignoring general name field type %d", __func__,
                         name->type);
                     break;
             }
@@ -185,10 +178,6 @@
     return retval;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * Extract a field from an X509 subject name.
  *

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1507?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I23cc00aee47aef007ab2e7d50b52c6de299505db
Gerrit-Change-Number: 1507
Gerrit-PatchSet: 8
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>

#8 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1507?usp=email )

Change subject: ssl_verify_openssl: Clean up extract_x509_extension
......................................................................

ssl_verify_openssl: Clean up extract_x509_extension

* Avoid sign-compare warning when comparing string lengths
* Use the nicer alias rfc822Name instead of the general ia5 from the GENERAL_NAME union.
* Use the official ASN1_STRING_length API instead of accessing the struct directly.
* C11 changes

Change-Id I23cc00aee47aef007ab2e7d50b52c6de299505db

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1507
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg35980.html

---
M src/openvpn/ssl_verify_openssl.c

1 file changed, 6 insertions(+), 17 deletions(-)
src/openvpn/ssl_verify_openssl.c +6 -17
index 58f665c..46401cd 100644
@@ -118,16 +118,10 @@
     return nid == NID_subject_alt_name || nid == NID_issuer_alt_name;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-compare"
-#endif
-
 static bool
 extract_x509_extension(X509 *cert, char *fieldname, char *out, size_t size)
 {
     bool retval = false;
-    char *buf = 0;
 
     if (!x509_username_field_ext_supported(fieldname))
     {
@@ -139,29 +133,28 @@
     GENERAL_NAMES *extensions = X509_get_ext_d2i(cert, nid, NULL, NULL);
     if (extensions)
     {
-        int numalts;
-        int i;
         /* get amount of alternatives,
          * RFC2459 claims there MUST be at least
          * one, but we don't depend on it...
          */
 
-        numalts = sk_GENERAL_NAME_num(extensions);
+        int numalts = sk_GENERAL_NAME_num(extensions);
 
         /* loop through all alternatives */
-        for (i = 0; i < numalts; i++)
+        for (int i = 0; i < numalts; i++)
         {
             /* get a handle to alternative name number i */
             const GENERAL_NAME *name = sk_GENERAL_NAME_value(extensions, i);
+            char *buf = NULL;
 
             switch (name->type)
             {
                 case GEN_EMAIL:
-                    if (ASN1_STRING_to_UTF8((unsigned char **)&buf, name->d.ia5) < 0)
+                    if (ASN1_STRING_to_UTF8((unsigned char **)&buf, name->d.rfc822Name) < 0)
                     {
                         continue;
                     }
-                    if (strlen(buf) != name->d.ia5->length)
+                    if ((ssize_t)strlen(buf) != ASN1_STRING_length(name->d.rfc822Name))
                     {
                         msg(D_TLS_ERRORS, "ASN1 ERROR: string contained terminating zero");
                         OPENSSL_free(buf);
@@ -175,7 +168,7 @@
                     break;
 
                 default:
-                    msg(D_TLS_DEBUG, "%s: ignoring general name field type %i", __func__,
+                    msg(D_TLS_DEBUG, "%s: ignoring general name field type %d", __func__,
                         name->type);
                     break;
             }
@@ -185,10 +178,6 @@
     return retval;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 /*
  * Extract a field from an X509 subject name.
  *

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1507?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I23cc00aee47aef007ab2e7d50b52c6de299505db
Gerrit-Change-Number: 1507
Gerrit-PatchSet: 8
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>