From: "plaisthos (Code Review)" Date: Wed, 1 Apr 2026 11:56:52 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <4919df01330f26900d59a7a88ea342574518762b-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Bep6Dqz2u7Y="; 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: flichtenheld Cc: openvpn-devel --Bep6Dqz2u7Y= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld,=20 I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1596?usp=3Demail to look at the new patch set (#4). The following approvals got outdated and were removed: Code-Review-1 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 --- M src/openvpn/ssl_openssl.c M src/openvpn/ssl_verify_openssl.c 2 files changed, 35 insertions(+), 30 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/1596/4 diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index 3c33cc7..04e3521 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -1852,7 +1852,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; @@ -1916,21 +1915,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 3c57f7f..ef30620 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,7 @@ 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(); - X509_NAME *x509_name =3D X509_get_subject_name(x509); + const X509_NAME *x509_name =3D X509_get_subject_name(x509); const char nullc =3D '\0'; while (xt) @@ -491,10 +496,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 +513,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 +553,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: 4 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld --Bep6Dqz2u7Y= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: flichtenheld.

plaisthos uploaded patch set #4 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/1596?usp=3Demail">View Chan= ge

The following approvals got outdated and were removed: Code-Review-1 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...>
---
M src/openvpn/ssl_openssl.c
M= src/openvpn/ssl_verify_openssl.c
2 files changed, 35 insertions(+), 30 = deletions(-)

git pull ssh://gerrit.openvpn.net:2=
9418/openvpn refs/changes/96/1596/4
diff --git a/src/openvpn/ssl_op=
enssl.c b/src/openvpn/ssl_openssl.c
index 3c33cc7..04e3521 = 100644
--- a/src/openvpn/ssl_openssl.c
+++ = b/src/openvpn/ssl_openssl.c
@@ -1852,7 +1852,6 @@ STACK_OF(X509_NAME) *cert_names =3D NULL;
= X509_LOOKUP *lookup =3D NULL;
X509_STORE *store =3D NU= LL;
- X509_NAME *xn = =3D NULL;
BIO *in =3D NULL;
int i= , added =3D 0, prev =3D 0;

@@ -1916,21 +1= 915,26 @@
}
= }

- xn =3D X509_get_subject_name(info->x509= );
+ = /* OpenSSL 4.0 has made X509_get_subject_name return const
+ * but not ad= justed 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(info->x509);
= if (!xn)
{
= continue;
= }

- = 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/sr= c/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_verify_openssl.cindex 3c57f7f..ef30620 100644
--- a/src/openvpn/ssl_= verify_openssl.c
+++ b/src/openvpn/ssl_verify_openssl.c

@@ -191,7 +191,7 @@
* to contain result is g= rounds for error).
*/
static result_t
-extract_x509_field_ssl(X= 509_NAME *x509, const char *field_name, char *out, size_t size)
<= span style=3D"color: hsl(120, 100%, 40%);">+extract_x509_field_ssl(const X5= 09_NAME *x509, const char *field_name, char *out, size_t size)

{
int lastpos =3D -1;
int tm= p =3D -1;
@@ -209,7 +209,12 @@
do
{
lastpos =3D tmp;
+#if OPENSSL_VERSION_NUMBER >=3D= 0x30000000L

tmp =3D X509_NAME_get_index_by_OBJ(x5= 09, field_name_obj, lastpos);
+#else
+ = /* OpenSSL 1.1.x has the argument as non-const */
+ tmp =3D X509_NAME_get_index_by_OB= J((X509_NAME *)x509, field_name_obj, 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,7 @@
= x509_setenv_track(const struct x509_track *xt, struct env_set *es, const in= t depth, X509 *x509)
{
struct gc_aren= a gc =3D gc_new();
- = X509_NAME *x509_name =3D X509_get_subject_name(x509);
+ const X509_NAME *x509_name =3D X509_= get_subject_name(x509);
const char nullc =3D '\0&#= 39;;

while (xt)
@@ -= 491,10 +496,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_S= TRING *val =3D X509_NAME_ENTRY_get_data(ent);
+ const ASN1_STRING *va= l =3D X509_NAME_ENTRY_get_data(ent);
= unsigned char *buf =3D NULL;
= if (ASN1_STRING_to_UTF8(&buf, val) >=3D 0)
= {
@@ -508,7 +513,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 X50= 9_EXTENSION *ext =3D X509_get_ext(x509, i);
+#endif
= if (ext)
{
= BIO *bio =3D BIO_new(BIO_s_mem());@@ -544,51 +553,43 @@
void
x509_se= tenv(struct env_set *es, int cert_depth, openvpn_x509_cert_t *peer_cert)

{
- i= nt i, n;
- int fn_ni= d;
- ASN1_OBJECT *fn= ;
- ASN1_STRING *val= ;
- X509_NAME_ENTRY = *ent;
- const char *= objbuf;
- unsigned c= har *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 X5= 09_get_subject_name(peer_cert);

- n =3D X509_NAME_entry_count(x509);- for (i =3D 0; i < n; ++= i)
+ int n =3D X50= 9_NAME_entry_count(x509);
+ for (int i =3D 0; i < n; ++i)
{- ent =3D X509_NAME_get_e= ntry(x509, i);
+ = const X509_NAME_ENTRY *ent =3D X509_NAME_get_entry(x509, i);
<= span> if (!ent)
{
= continue;
}
- fn =3D X509_NAME_ENTRY_get_object(ent);<= br>+ 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_ge= t_data(ent);
if (!val)
{<= /span>
continue;
}- fn_nid =3D OBJ_obj2nid(= fn);
+ int fn_= nid =3D OBJ_obj2nid(fn);
if (fn_nid =3D=3D NID_und= ef)
{
continue;
}
-= objbuf =3D OBJ_nid2sn(fn_nid);
+ const char *objbuf =3D OBJ_nid2sn(fn_nid);
if (!objbuf)
{
continue;

}
+ unsigned char *buf =3D NULL;<= br> if (ASN1_STRING_to_UTF8(&buf, val) < 0)
= {
continue;
= }
- name_e= xpand_size =3D 64 + strlen(objbuf);
- name_expand =3D (char *)malloc(name_expand_size);
+ size_t name_exp= and_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_de= pth, 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: 4
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
= --Bep6Dqz2u7Y=--