From: "plaisthos (Code Review)" Date: Tue, 31 Mar 2026 16:52:36 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <44acc7956b1c39ea8af8d227c334601f53b32ca5-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="qLdpP8zxFgo="; 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: , Cc: openvpn-devel --qLdpP8zxFgo= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable plaisthos has uploaded a new patch set (#2). ( http://gerrit.openvpn.net/c/= openvpn/+/1596?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 --- M src/openvpn/ssl_openssl.c M src/openvpn/ssl_verify_openssl.c 2 files changed, 29 insertions(+), 30 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/1596/2 diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c index 4650b85..0cd54134 100644 --- a/src/openvpn/ssl_openssl.c +++ b/src/openvpn/ssl_openssl.c @@ -1846,7 +1846,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; @@ -1910,21 +1909,25 @@ } } - xn =3D X509_get_subject_name(info->x509); + + const X509_NAME *xn =3D X509_get_subject_name(info->x5= 09); if (!xn) { continue; } + /* OpenSSL 4.0 has made X509_get_subject_name return c= onst + * but not adjusted the other functions to take a + * const argument */ /* 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 20188f4..367f81a 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; @@ -269,7 +269,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 +457,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 +491,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 +508,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 +548,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, '_'); --=20 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: 2 Gerrit-Owner: plaisthos Gerrit-CC: openvpn-devel --qLdpP8zxFgo= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

plaisthos uploaded patch set #2 to this change.

View Change

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 us= e const objects as well.

Change-Id: Iea1d13c160599f134587c6f1c2f4a90= e7f5e3991
Signed-off-by: Arne Schwabe <arne@...1227...>
---
= M src/openvpn/ssl_openssl.c
M src/openvpn/ssl_verify_openssl.c
2 file= s changed, 29 insertions(+), 30 deletions(-)

git=
 pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/1596/2
diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/ssl_openssl.c<= br>index 4650b85..0cd54134 100644
--- a/src/openvpn/s= sl_openssl.c
+++ b/src/openvpn/ssl_openssl.c
@@ -1846,7 +1846,6 @@
STACK_OF(X509_NAME) *cert_name= s =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;

@@ -1910,21 +1909,25 @@
= }
}
<= br>- xn =3D X5= 09_get_subject_name(info->x509);
+
+ = const X509_NAME *xn =3D X509_get_subject_name(info->x50= 9);
if (!xn)
= {
continue;
= }

+ /* OpenSSL 4.0 has made X509= _get_subject_name return const
+ * but not adjusted the other functions to t= ake a
+ = * const argument */
/* Don'= t add duplicate CA names */
- if (sk_X509_NAME_find(cert_names, xn) =3D=3D -1)<= /span>
+ = if (sk_X509_NAME_find(cert_names, (X509_NAME *)xn) =3D=3D -1)
{

- xn =3D X509_NAME_dup(xn);
- if (!xn)
= + X509_N= AME *xn_dup =3D X509_NAME_dup(xn);
+ if (!xn_dup)
= {
continue;<= /span>
}
- 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_verif= y_openssl.c
index 20188f4..367f81a 100644
-= -- a/src/openvpn/ssl_verify_openssl.c
+++ b/src/openvpn/ssl= _verify_openssl.c
@@ -191,7 +191,7 @@
* t= o contain result is grounds for error).
*/
static result_t

-ext= ract_x509_field_ssl(X509_NAME *x509, const char *field_name, char *out, siz= e_t size)
+extract_x5= 09_field_ssl(const X509_NAME *x509, const char *field_name, char *out, size= _t size)
{
int lastpos =3D -1;=
int tmp =3D -1;
@@ -269,7 +269,7 @@ }
else
{
<= span style=3D"color: hsl(0, 100%, 40%);">- X509_NAME *x509_subject_n= ame =3D X509_get_subject_name(peer_cert);
+ const X509_NAME *x509_subject_name =3D X509_g= et_subject_name(peer_cert);
if (x509_subject_name = =3D=3D NULL)
{
msg(D_= TLS_ERRORS, "X509 subject name is NULL");
@@ -457= ,7 +457,7 @@
x509_setenv_track(const struct x509_track *xt= , struct env_set *es, const int depth, X509 *x509)
{

struct gc_arena gc =3D gc_new();
- X509_NAME *x509_name =3D X509_get_subject_na= me(x509);
+ const = X509_NAME *x509_name =3D X509_get_subject_name(x509);
= const char nullc =3D '\0';

w= hile (xt)
@@ -491,10 +491,10 @@
= int i =3D X509_NAME_get_index_by_NID(x509_name, xt->nid, -1);<= /span>
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);<= /span>
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 +508,11 @@
i =3D X509_get= _ext_by_NID(x509, xt->nid, -1);
= if (i >=3D 0)
{
+#if OPENSSL_VERSION_NUMBER < 0x= 40000000L

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 B= IO_new(BIO_s_mem());
@@ -544,51 +548,43 @@
= void
x509_setenv(struct env_set *es, int cert_depth, open= vpn_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_NA= ME_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_g= et_entry(x509, i);
if (!ent)
= {
continue;
}
- fn =3D X509_NAME_= ENTRY_get_object(ent);
- val =3D X509_NAME_ENTRY_get_data(ent);
+ const ASN1_STRI= NG *val =3D X509_NAME_ENTRY_get_data(ent);
if (!va= l)
{
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 *objb= uf =3D OBJ_nid2sn(fn_nid);
if (!objbuf)
= {
continue;
= }
+ unsi= gned char *buf =3D NULL;
if (ASN1_STRING_to_UTF8(&= amp;buf, val) < 0)
{
= continue;
}
- name_expand_size =3D 64 + strlen(objbuf);<= br>- 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(nam= e_expand);
snprintf(name_expand, name_expand_size,= "X509_%d_%s", cert_depth, objbuf);
stri= ng_mod(name_expand, CC_PRINT, CC_CRLF, '_');

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

<= /div>
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iea1d13c160599f134587c6f1c2f= 4a90e7f5e3991
Gerrit-Change-Number: 1596
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --qLdpP8zxFgo=--