From: "cron2 (Code Review)" Date: Sat, 4 Apr 2026 15:51:36 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <7287d953fbc8ff38fed48a477a09f92fc6feef07-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="m0c0+SBZrwY="; 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 , flichtenheld Cc: openvpn-devel --m0c0+SBZrwY= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#6) to the change originally created by= plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/1596?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by flichtenheld 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(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/1596/6 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'; =20 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: newpatchset 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 --m0c0+SBZrwY= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #6 to the change originally created by plaisthos.<= /p>

Vi= ew Change

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

OpenSSL 4.0: Make X509 objec=
ts const

In OpenSSL 4.0 a lot of the APIs have changed to return con= st objects.
Adjust our source code to use const objects as well.

= Change-Id: Iea1d13c160599f134587c6f1c2f4a90e7f5e3991
Signed-off-by: Arne= Schwabe <arne@...1227...>
Acked-by: Frank Lichtenheld <frank@...220...= ..2641...>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1596Message-Id: <20260402121049.41102-1-frank@...2641...>
URL: https:= //www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36437.htmlSigned-off-by: Gert Doering <gert@...1296...>
---
M src/openvp= n/ssl_openssl.c
M src/openvpn/ssl_verify_openssl.c
2 files changed, 3= 9 insertions(+), 29 deletions(-)

git pull ssh:=
//gerrit.openvpn.net:29418/openvpn refs/changes/96/1596/6
diff --=
git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c
index a26663a..fd05f43 100644
--- a/src/openvpn/ssl_openss= l.c
+++ b/src/openvpn/ssl_openssl.c
@@ -178= 9,7 +1789,6 @@
STACK_OF(X509_NAME) *cert_names =3D NUL= L;
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_su= bject_name(info->x509);
+ /* OpenSSL 4.0 has made X509_get_subject_name re= turn const
+ = * but not adjusted the other functions to take const
= + * argumen= ts, and other libraries do not have const
+ * arguments, so just ignore cons= t here */
+ = X509_NAME *xn =3D (X509_NAME *)X509_get_subject_name(info->x50= 9);
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_veri= fy_openssl.c
index c70022f..96ca1a4 100644
= --- a/src/openvpn/ssl_verify_openssl.c
+++ b/src/openvpn/ss= l_verify_openssl.c
@@ -191,7 +191,7 @@
* = to contain result is grounds for error).
*/
static result_t
-ex= tract_x509_field_ssl(X509_NAME *x509, const char *field_name, char *out, si= ze_t size)
+extract_x= 509_field_ssl(const X509_NAME *x509, const char *field_name, char *out, siz= e_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_N= AME_get_index_by_OBJ(x509, field_name_obj, lastpos);
+#else
+ /* OpenSSL 1.1.x has the argument as non-const = */
+ tmp =3D X= 509_NAME_get_index_by_OBJ((X509_NAME *)x509, field_name_obj, lastpos);
+#endif
= } while (tmp > -1);

ASN1_OBJE= CT_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_s= ubject_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 int depth, X509 *x509)
{<= br> struct gc_arena gc =3D gc_new();
+#if OPENSSL_VERSION_NUMBER < 0x30000000L
+ /* OpenSSL 1.1.x API= s 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);
<= span style=3D"color: hsl(120, 100%, 40%);">+#endif

con= st char nullc =3D '\0';

whil= e (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);
<= span> unsigned char *buf =3D NULL;

if (ASN1_STRING_to_UTF8(&buf, val) >= ;=3D 0)

{
@@ -= 508,7 +518,11 @@
i =3D X509_get_ex= t_by_NID(x509, xt->nid, -1);
if= (i >=3D 0)
{
+#if OPENSSL_VERSION_NUMBER < 0x400= 00000L
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 @@
vo= id
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_na= me(peer_cert);
+ c= onst 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_EN= TRY_get_object(ent);
= + const ASN1_OBJECT *fn =3D X509_NAME_ENTRY_get_object(ent);<= br> 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;
= }
+ unsigne= d 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 ma= lloc(name_expand_size);

check_malloc_return(name_e= xpand);
snprintf(name_expand, name_expand_size, &q= uot;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: newpatchset
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>
= --m0c0+SBZrwY=--