From: "plaisthos (Code Review)"
Date: Tue, 31 Mar 2026 16:24:11 +0000
References:
Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net
Message-ID: <09af3da418721fdc6e64e5c9c9f54552df4658be-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="VDxpWqypr4w="; 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
--VDxpWqypr4w=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
plaisthos has uploaded this change for review. ( 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
---
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/1
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, '_');
--
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: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iea1d13c160599f134587c6f1c2f4a90e7f5e3991
Gerrit-Change-Number: 1596
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos
Gerrit-CC: openvpn-devel
--VDxpWqypr4w=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
plaisthos has upl=
oaded this change for review.
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
---
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/chang=
es/96/1596/1
diff --git a/src/openvpn/ssl_openssl.c b/src/openvpn/s=
sl_openssl.c
index 4650b85..0cd54134 100644
--- a/src/openvpn/ssl_openssl.c
+++ b/src/openvpn/ssl_open=
ssl.c
@@ -1846,7 +1846,6 @@
STACK_OF(X=
509_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_sub=
ject_name(info->x509);
if (!xn)
{
=
continue;
}
=
+ /* Ope=
nSSL 4.0 has made X509_get_subject_name return const
+ * but not adjusted t=
he 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_X50=
9_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_openssl.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).
<=
span> */
static result_t
-extract_x509_field_ssl(X509_NAME *x509, const char *fi=
eld_name, char *out, size_t size)
+extract_x509_field_ssl(const X509_NAME *x509, const char *fie=
ld_name, char *out, size_t size)
{
in=
t lastpos =3D -1;
int tmp =3D -1;
@@ -=
269,7 +269,7 @@
}
else
=
{
- X=
509_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)
{
<=
span> msg(D_TLS_ERRORS, "X509 subject name is NULL");=
@@ -457,7 +457,7 @@
x509_setenv_track(con=
st struct x509_track *xt, struct env_set *es, const int depth, X509 *x509)<=
/span>
{
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->nid, -1);
if (i >=3D =
0)
{
- X509_NAME_ENTRY *ent =3D X509_N=
AME_get_entry(x509_name, i);
+ const X509_NAME_ENTRY *ent =3D X509_NAME_g=
et_entry(x509_name, i);
if (ent)=
span>
{
- ASN1_STRING *val =3D X509_N=
AME_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 OPENSS=
L_VERSION_NUMBER < 0x40000000L
=
X509_EXTENSION *ext =3D X509_get_ext(x509, i);
+#else
+ const X509_EXTENSION *ext =3D =
X509_get_ext(x509, i);
+#endif
if (ext)
<=
span> {
=
BIO *bio =3D BIO_new(BIO_s_mem());
@@ -544,51 +54=
8,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;=
span>
- size_t name_expand_=
size;
- X509_NAME *x=
509 =3D X509_get_subject_name(peer_cert);
+ const X509_NAME *x509 =3D X509_get_subject_name(p=
eer_cert);
- n =3D X509_NAME_entry_count(x509);
- for (i =3D 0; i < n; ++i)
+ int n =3D X509_NAME_entry_count(x5=
09);
+ for (int i =
=3D 0; i < n; ++i)
{
- ent =3D X509_NAME_get_entry(x509, i);=
+ const X509_NAME_EN=
TRY *ent =3D X509_NAME_get_entry(x509, i);
if (!en=
t)
{
continue;=
}
- =
fn =3D X509_NAME_ENTRY_get_object(ent);
+ const ASN1_OBJECT *fn =3D X509_NAME_ENTR=
Y_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(f=
n);
if (fn_nid =3D=3D NID_undef)
=
{
continue;
}=
- objbuf =3D OB=
J_nid2sn(fn_nid);
+ =
const char *objbuf =3D OBJ_nid2sn(fn_nid);
i=
f (!objbuf)
{
continu=
e;
}
+ unsigned char *buf =3D NULL;
if =
(ASN1_STRING_to_UTF8(&buf, val) < 0)
{
continue;
}
- name_expand_size =3D 64 + s=
trlen(objbuf);
- =
name_expand =3D (char *)malloc(name_expand_size);
+ size_t name_expand_size =3D 64 + str=
len(objbuf);
+ =
char *name_expand =3D malloc(name_expand_size);
c=
heck_malloc_return(name_expand);
snprintf(name_exp=
and, name_expand_size, "X509_%d_%s", cert_depth, objbuf);<=
br> string_mod(name_expand, CC_PRINT, CC_CRLF, '_');<=
/span>
To view, visit change 1596. To unsubscribe,=
or for help writing mail filters, visit settings.
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iea1d13c160599f134587c6f1c2f=
4a90e7f5e3991
Gerrit-Change-Number: 1596
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <arne-openvpn@...1711...=
27...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...=
ts.sourceforge.net>
=
--VDxpWqypr4w=--