Skip to content

Commit 659894a

Browse files
heitbaumlws-team
authored andcommitted
tls/openssl: build with the constified X509 name accessors in OpenSSL 4
OpenSSL 4.0 changed X509_get_subject_name() and X509_get_issuer_name() to return a const X509_NAME *, so assigning the result to a plain X509_NAME * fails the -Wignored-qualifiers -Werror build: openssl-x509.c:140:20: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers] Make the read-only users const, and cast at the two sites that fill in the subject name of a cert that has not been signed yet. All of this also compiles against OpenSSL 3, where the accessors return non-const. Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
1 parent 7eb8c9c commit 659894a

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

lib/tls/openssl/openssl-client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ OpenSSL_client_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx)
216216
char cert_cn[256] = "unknown";
217217
X509 *cert = X509_STORE_CTX_get_current_cert(x509_ctx);
218218
if (cert) {
219-
X509_NAME *subject = X509_get_subject_name(cert);
219+
const X509_NAME *subject = X509_get_subject_name(cert);
220220
if (subject)
221221
X509_NAME_get_text_by_NID(subject, NID_commonName, cert_cn, sizeof(cert_cn));
222222
}

lib/tls/openssl/openssl-server.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ lws_tls_vhost_backend_create_ctx(struct lws_vhost *vhost)
644644
SSL_CTX_set_cert_store(tls->ssl_ctx, x509_store);
645645
STACK_OF(X509_NAME) *calist = sk_X509_NAME_new_null();
646646
if (calist) {
647-
X509_NAME *name = X509_get_subject_name(client_CA);
647+
const X509_NAME *name = X509_get_subject_name(client_CA);
648648
if (name)
649649
sk_X509_NAME_push(calist, X509_NAME_dup(name));
650650
SSL_CTX_set_client_CA_list(tls->ssl_ctx, calist);
@@ -940,7 +940,11 @@ lws_tls_acme_sni_cert_create(struct lws_vhost *vhost, const char *san_a,
940940

941941
X509_set_pubkey(vhost->tls.ss->x509, vhost->tls.ss->pkey);
942942

943-
name = X509_get_subject_name(vhost->tls.ss->x509);
943+
/*
944+
* OpenSSL 4 constified the accessor, but the name is still owned by
945+
* the unsigned cert and is meant to be filled in here
946+
*/
947+
name = (X509_NAME *)X509_get_subject_name(vhost->tls.ss->x509);
944948
X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC,
945949
(unsigned char *)"GB", -1, -1, 0);
946950
X509_NAME_add_entry_by_txt(name, "O", MBSTRING_ASC,

lib/tls/openssl/openssl-x509.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ lws_tls_openssl_cert_info(X509 *x509, enum lws_tls_cert_info type,
100100
int tag, xclass, r = 1;
101101
long xlen, loc;
102102
#endif
103-
X509_NAME *xn;
103+
const X509_NAME *xn;
104104
#if !defined(LWS_PLAT_OPTEE)
105105
char *p, *p1;
106106
size_t rl;
@@ -487,7 +487,7 @@ lws_x509_verify(struct lws_x509_cert *x509, struct lws_x509_cert *trusted,
487487
int ret;
488488

489489
if (common_name) {
490-
X509_NAME *xn = X509_get_subject_name(x509->cert);
490+
const X509_NAME *xn = X509_get_subject_name(x509->cert);
491491
if (!xn)
492492
return -1;
493493

@@ -1020,7 +1020,11 @@ lws_x509_create_cert(struct lws_context *context,
10201020

10211021
X509_set_pubkey(x509, pkey);
10221022

1023-
name = X509_get_subject_name(x509);
1023+
/*
1024+
* OpenSSL 4 constified the accessor, but the name is still owned by
1025+
* the unsigned cert and is meant to be filled in here
1026+
*/
1027+
name = (X509_NAME *)X509_get_subject_name(x509);
10241028
X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC,
10251029
(unsigned char *)info->san, -1, -1, 0);
10261030

0 commit comments

Comments
 (0)