From: "cron2 (Code Review)" Date: Sat, 4 Apr 2026 15:51:41 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <7287d953fbc8ff38fed48a477a09f92fc6feef07-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="/cIea8iUzc8="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: OpenSSL 4.0: Make X509 objects const List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: flichtenheld , openvpn-devel --/cIea8iUzc8= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/15= 96?usp=3Demail ) Change subject: OpenSSL 4.0: Make X509 objects const ...................................................................... OpenSSL 4.0: Make X509 objects const In OpenSSL 4.0 a lot of the APIs have changed to return const objects. Adjust our source code to use const objects as well. Change-Id: Iea1d13c160599f134587c6f1c2f4a90e7f5e3991 Signed-off-by: Arne Schwabe Acked-by: Frank Lichtenheld Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1596 Message-Id: <20260402121049.41102-1-frank@...2641...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36= 437.html Signed-off-by: Gert Doering --- M src/openvpn/ssl_openssl.c M src/openvpn/ssl_verify_openssl.c 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index a26663a..fd05f43 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -1789,7 +1789,6 @@ STACK_OF(X509_NAME) *cert_names =3D NULL; X509_LOOKUP *lookup =3D NULL; X509_STORE *store =3D NULL; - X509_NAME *xn =3D NULL; BIO *in =3D NULL; int i, added =3D 0, prev =3D 0; @@ -1853,21 +1852,26 @@ } } - xn =3D X509_get_subject_name(info->x509); + /* OpenSSL 4.0 has made X509_get_subject_name return c= onst + * but not adjusted the other functions to take const + * arguments, and other libraries do not have const + * arguments, so just ignore const here */ + X509_NAME *xn =3D (X509_NAME *)X509_get_subject_name(i= nfo->x509); if (!xn) { continue; } + /* Don't add duplicate CA names */ - if (sk_X509_NAME_find(cert_names, xn) =3D=3D -1) + if (sk_X509_NAME_find(cert_names, (X509_NAME *)xn) =3D= =3D -1) { - xn =3D X509_NAME_dup(xn); - if (!xn) + X509_NAME *xn_dup =3D X509_NAME_dup(xn); + if (!xn_dup) { continue; } - sk_X509_NAME_push(cert_names, xn); + sk_X509_NAME_push(cert_names, xn_dup); } } diff --git a/src/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_verify_open= ssl.c index c70022f..96ca1a4 100644 --- a/src/openvpn/ssl_verify_openssl.c +++ b/src/openvpn/ssl_verify_openssl.c @@ -191,7 +191,7 @@ * to contain result is grounds for error). */ static result_t -extract_x509_field_ssl(X509_NAME *x509, const char *field_name, char *out,= size_t size) +extract_x509_field_ssl(const X509_NAME *x509, const char *field_name, char= *out, size_t size) { int lastpos =3D -1; int tmp =3D -1; @@ -209,7 +209,12 @@ do { lastpos =3D tmp; +#if OPENSSL_VERSION_NUMBER >=3D 0x30000000L tmp =3D X509_NAME_get_index_by_OBJ(x509, field_name_obj, lastpos); +#else + /* OpenSSL 1.1.x has the argument as non-const */ + tmp =3D X509_NAME_get_index_by_OBJ((X509_NAME *)x509, field_name_o= bj, lastpos); +#endif } while (tmp > -1); ASN1_OBJECT_free(field_name_obj); @@ -269,7 +274,7 @@ } else { - X509_NAME *x509_subject_name =3D X509_get_subject_name(peer_cert); + const X509_NAME *x509_subject_name =3D X509_get_subject_name(peer_= cert); if (x509_subject_name =3D=3D NULL) { msg(D_TLS_ERRORS, "X509 subject name is NULL"); @@ -457,7 +462,12 @@ x509_setenv_track(const struct x509_track *xt, struct env_set *es, const i= nt depth, X509 *x509) { struct gc_arena gc =3D gc_new(); +#if OPENSSL_VERSION_NUMBER < 0x30000000L + /* OpenSSL 1.1.x APIs all take non-const arguments */ X509_NAME *x509_name =3D X509_get_subject_name(x509); +#else + const X509_NAME *x509_name =3D X509_get_subject_name(x509); +#endif const char nullc =3D '\0'; while (xt) @@ -491,10 +501,10 @@ int i =3D X509_NAME_get_index_by_NID(x509_name, xt->ni= d, -1); if (i >=3D 0) { - X509_NAME_ENTRY *ent =3D X509_NAME_get_entry(x509_= name, i); + const X509_NAME_ENTRY *ent =3D X509_NAME_get_entry= (x509_name, i); if (ent) { - ASN1_STRING *val =3D X509_NAME_ENTRY_get_data(= ent); + const ASN1_STRING *val =3D X509_NAME_ENTRY_get= _data(ent); unsigned char *buf =3D NULL; if (ASN1_STRING_to_UTF8(&buf, val) >=3D 0) { @@ -508,7 +518,11 @@ i =3D X509_get_ext_by_NID(x509, xt->nid, -1); if (i >=3D 0) { +#if OPENSSL_VERSION_NUMBER < 0x40000000L X509_EXTENSION *ext =3D X509_get_ext(x509, i); +#else + const X509_EXTENSION *ext =3D X509_get_ext(x50= 9, i); +#endif if (ext) { BIO *bio =3D BIO_new(BIO_s_mem()); @@ -544,51 +558,43 @@ void x509_setenv(struct env_set *es, int cert_depth, openvpn_x509_cert_t *peer_= cert) { - int i, n; - int fn_nid; - ASN1_OBJECT *fn; - ASN1_STRING *val; - X509_NAME_ENTRY *ent; - const char *objbuf; - unsigned char *buf =3D NULL; - char *name_expand; - size_t name_expand_size; - X509_NAME *x509 =3D X509_get_subject_name(peer_cert); + const X509_NAME *x509 =3D X509_get_subject_name(peer_cert); - n =3D X509_NAME_entry_count(x509); - for (i =3D 0; i < n; ++i) + int n =3D X509_NAME_entry_count(x509); + for (int i =3D 0; i < n; ++i) { - ent =3D X509_NAME_get_entry(x509, i); + const X509_NAME_ENTRY *ent =3D X509_NAME_get_entry(x509, i); if (!ent) { continue; } - fn =3D X509_NAME_ENTRY_get_object(ent); + const ASN1_OBJECT *fn =3D X509_NAME_ENTRY_get_object(ent); if (!fn) { continue; } - val =3D X509_NAME_ENTRY_get_data(ent); + const ASN1_STRING *val =3D X509_NAME_ENTRY_get_data(ent); if (!val) { continue; } - fn_nid =3D OBJ_obj2nid(fn); + int fn_nid =3D OBJ_obj2nid(fn); if (fn_nid =3D=3D NID_undef) { continue; } - objbuf =3D OBJ_nid2sn(fn_nid); + const char *objbuf =3D OBJ_nid2sn(fn_nid); if (!objbuf) { continue; } + unsigned char *buf =3D NULL; if (ASN1_STRING_to_UTF8(&buf, val) < 0) { continue; } - name_expand_size =3D 64 + strlen(objbuf); - name_expand =3D (char *)malloc(name_expand_size); + size_t name_expand_size =3D 64 + strlen(objbuf); + char *name_expand =3D malloc(name_expand_size); check_malloc_return(name_expand); snprintf(name_expand, name_expand_size, "X509_%d_%s", cert_depth, = objbuf); string_mod(name_expand, CC_PRINT, CC_CRLF, '_'); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1596?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: Iea1d13c160599f134587c6f1c2f4a90e7f5e3991 Gerrit-Change-Number: 1596 Gerrit-PatchSet: 6 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel --/cIea8iUzc8= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

OpenSSL 4.0: Make X509 objects const

In O= penSSL 4.0 a lot of the APIs have changed to return const objects.
Adjus= t our source code to use const objects as well.

Change-Id: Iea1d13c1= 60599f134587c6f1c2f4a90e7f5e3991
Signed-off-by: Arne Schwabe <arne@...1186...= .1227...>
Acked-by: Frank Lichtenheld <frank@...2641...>
Ger= rit URL: https://gerrit.openvpn.net/c/openvpn/+/1596
Message-Id: <202= 60402121049.41102-1-frank@...2641...>
URL: https://www.mail-archive.c= om/openvpn-devel@lists.sourceforge.net/msg36437.html
Signed-off-by: Gert= Doering <gert@...1296...>
---
M src/openvpn/ssl_openssl.c
M= src/openvpn/ssl_verify_openssl.c
2 files changed, 39 insertions(+), 29 = deletions(-)

diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c
index a26663a..fd05f43 100644
--- a/src/openvpn/= ssl_openssl.c
+++ b/src/openvpn/ssl_openssl.c
@@ -1789,7 +1789,6 @@
STACK_OF(X509_NAME) *cert_nam= es =3D NULL;
X509_LOOKUP *lookup =3D NULL;
<= span> X509_STORE *store =3D NULL;
- X509_NAME *xn =3D NULL;
BIO *in = =3D NULL;
int i, added =3D 0, prev =3D 0;

@@ -1853,21 +1852,26 @@
= }
}

- xn =3D= X509_get_subject_name(info->x509);
+ /* OpenSSL 4.0 has made X509_get_sub= ject_name return const
+ = * arguments, and other libraries do not have const
+ * arguments, so just= ignore const here */
+ X509_NAME *xn =3D (X509_NAME *)X509_get_subject_name(= info->x509);
if (!xn)
{

continue= ;
}

+
= /* Don't add duplicate CA names */
- if (sk_X509_NAME_find(cert_names, xn= ) =3D=3D -1)
+ = if (sk_X509_NAME_find(cert_names, (X509_NAME *)xn) =3D=3D -1)<= /span>
{
- xn =3D X509_NAME_dup(xn);- if (!x= n)
+ = X509_NAME *xn_dup =3D X509_NAME_dup(xn);
+ if (!xn_dup)
= {
= continue;
}
- sk_X509_NAME_push= (cert_names, xn);
+ = sk_X509_NAME_push(cert_names, xn_dup);
}

}

diff --git a/src/openvpn/ssl_verify_openssl.c b/src/open= vpn/ssl_verify_openssl.c
index c70022f..96ca1a4 100644
--- a/src/openvpn/ssl_verify_openssl.c
+++ b/sr= c/openvpn/ssl_verify_openssl.c
@@ -191,7 +191,7 @@ * to contain result is grounds for error).
*/
static result_t
-extract_x509_field_ssl(X509_NAME *x509, const char *field_name, c= har *out, size_t size)
= +#if OPENSSL_VERSION_NUMBER >=3D 0x30000000L
tm= p =3D X509_NAME_get_index_by_OBJ(x509, field_name_obj, lastpos);
= +#else
+ /* OpenSSL 1.1.x has the argument as= non-const */
+ = tmp =3D X509_NAME_get_index_by_OBJ((X509_NAME *)x509, field_name_obj, las= tpos);
+#endif=
} while (tmp > -1);

= ASN1_OBJECT_free(field_name_obj);
@@ -269,7 +274,7 @@

}
else
{=
- X509_NAME *x509_subj= ect_name =3D X509_get_subject_name(peer_cert);
+ const X509_NAME *x509_subject_name =3D X= 509_get_subject_name(peer_cert);
if (x509_subject_= name =3D=3D NULL)
{
m= sg(D_TLS_ERRORS, "X509 subject name is NULL");
@@= -457,7 +462,12 @@
x509_setenv_track(const struct x509_tra= ck *xt, struct env_set *es, const int depth, X509 *x509)
{=
struct gc_arena gc =3D gc_new();
+#if OPENSSL_VERSION_NUMBER < 0x300000= 00L
+ /* OpenSSL 1= .1.x APIs all take non-const arguments */
X509_NAME *x= 509_name =3D X509_get_subject_name(x509);
+#else
+ const X509_NAME *x509_name =3D X509_get_subject_name(x509);

+#endif
= const char nullc =3D '\0';

= while (xt)
@@ -491,10 +501,10 @@
= int i =3D X509_NAME_get_index_by_NID(x509_name, xt->nid, = -1);
if (i >=3D 0)
= {
= - X509_NAME_ENTRY *ent =3D X509_NAME_get_entry(x509_= name, i);
+ = const X509_NAME_ENTRY *ent =3D X509_NAME_get_entry(x509_name,= i);
if (ent)
= {
= - ASN1_STRING *val =3D X509_NAME_ENTRY_get_data(= ent);
+ = const ASN1_STRING *val =3D X509_NAME_ENTRY_get_data(ent);
unsigned char *buf =3D NULL;
if (ASN1_STRING_to_UTF8(&buf, = val) >=3D 0)
{
@@ -508,7 +518,11 @@

i =3D X50= 9_get_ext_by_NID(x509, xt->nid, -1);
= if (i >=3D 0)
{+#if OPENSSL_VERSION_NUMBER &l= t; 0x40000000L
X509_EXTENSION = *ext =3D X509_get_ext(x509, i);
+#else
+ = const X509_EXTENSION *ext =3D X509_get_ext(x509, = i);
+#endif if (ext)
= {
BIO *bio = =3D BIO_new(BIO_s_mem());
@@ -544,51 +558,43 @@
<= span> void

x509_setenv(struct env_set *es, int cert_depth,= openvpn_x509_cert_t *peer_cert)
{
- int i, n;
- int fn_nid;
- ASN1_OBJECT *fn;
- ASN1_STRING *val;
- X509_NAME_ENTRY *ent;
- const char *objbuf;
- unsigned char *buf =3D NULL;
- char *name_expand;
- size_t name_expand_size;
<= span style=3D"color: hsl(0, 100%, 40%);">- X509_NAME *x509 =3D X509_get_= subject_name(peer_cert);
+ const X509_NAME *x509 =3D X509_get_subject_name(peer_cert);=

- n =3D = X509_NAME_entry_count(x509);
- for (i =3D 0; i < n; ++i)
+ int n =3D X509_NAME_entry_count(x509);
+ for (int i =3D 0; i < n; = ++i)
{
- ent =3D X509_NAME_get_entry(x509, i);
+ const X509_NAME_ENTRY *ent =3D X5= 09_NAME_get_entry(x509, i);
if (!ent)
{
continue;
= }
- fn =3D X= 509_NAME_ENTRY_get_object(ent);
+ const ASN1_OBJECT *fn =3D X509_NAME_ENTRY_get_object(en= t);
if (!fn)
{
= continue;
}
- val =3D X509_NAME_ENTRY_get_data(= ent);
+ const = ASN1_STRING *val =3D X509_NAME_ENTRY_get_data(ent);
= if (!val)
{
continu= e;
}
- fn_nid =3D OBJ_obj2nid(fn);
+ int fn_nid =3D OBJ_obj2nid(fn);
<= span> if (fn_nid =3D=3D NID_undef)
{
continue;
}
- objbuf =3D OBJ_nid2sn(fn_nid= );

+ const cha= r *objbuf =3D OBJ_nid2sn(fn_nid);
if (!objbuf)
{
continue;
}

+ = unsigned char *buf =3D NULL;
if (ASN1_STRING_to= _UTF8(&buf, val) < 0)
{
= continue;
}
- name_expand_size =3D 64 + strlen(objbuf);<= /span>
- name_expand = =3D (char *)malloc(name_expand_size);
+ size_t name_expand_size =3D 64 + strlen(objbuf);<= /span>
+ char *name_e= xpand =3D malloc(name_expand_size);
check_malloc_r= eturn(name_expand);
snprintf(name_expand, name_exp= and_size, "X509_%d_%s", cert_depth, objbuf);
= string_mod(name_expand, CC_PRINT, CC_CRLF, '_');

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

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iea1d13c160599f134587c6f1c2f= 4a90e7f5e3991
Gerrit-Change-Number: 1596
Gerrit-PatchSet: 6
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --/cIea8iUzc8=--