Skip to content

Commit c8ef912

Browse files
notrojclaude
andcommitted
mod_ssl: constify X509_NAME_ENTRY and X509_EXTENSION pointers:
* modules/ssl/ssl_engine_vars.c (ssl_var_lookup_ssl_cert_dn, extract_dn): Constify X509_NAME_ENTRY * variables, constify X509_NAME * parameter of extract_dn, drop unnecessary casts on X509_NAME_ENTRY_get_object() calls. (ssl_ext_list): Use MODSSL_X509_EXT_CONST for X509_EXTENSION * since X509_EXTENSION accessors are only constified in OpenSSL 4. * modules/ssl/ssl_util_ssl.c, modules/ssl/ssl_util_ssl.h (modssl_X509_NAME_ENTRY_to_string): Constify X509_NAME_ENTRY * parameter. * modules/ssl/ssl_private.h: Add MODSSL_X509_EXT_CONST, defined as const for OpenSSL 4+ and empty otherwise. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8c7f4d3 commit c8ef912

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

modules/ssl/ssl_engine_vars.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ static const char *ssl_var_lookup_ssl_cert_dn(apr_pool_t *p, const X509_NAME *xs
732732
{
733733
const char *ptr;
734734
const char *result;
735-
X509_NAME_ENTRY *xsne;
735+
const X509_NAME_ENTRY *xsne;
736736
int i, j, n, idx = 0, raw = 0;
737737
apr_size_t varlen;
738738

@@ -759,7 +759,7 @@ static const char *ssl_var_lookup_ssl_cert_dn(apr_pool_t *p, const X509_NAME *xs
759759
for (j = 0; j < X509_NAME_entry_count(xsname); j++) {
760760
xsne = X509_NAME_get_entry(xsname, j);
761761

762-
n =OBJ_obj2nid((ASN1_OBJECT *)X509_NAME_ENTRY_get_object(xsne));
762+
n = OBJ_obj2nid(X509_NAME_ENTRY_get_object(xsne));
763763

764764
if (n == ssl_var_lookup_ssl_cert_dn_rec[i].nid && idx-- == 0) {
765765
result = modssl_X509_NAME_ENTRY_to_string(p, xsne, raw);
@@ -1112,9 +1112,9 @@ static const char *ssl_var_lookup_ssl_version(const char *var)
11121112
/* Add each RDN in 'xn' to the table 't' where the NID is present in
11131113
* 'nids', using key prefix 'pfx'. */
11141114
static void extract_dn(apr_table_t *t, apr_hash_t *nids, const char *pfx,
1115-
X509_NAME *xn, apr_pool_t *p)
1115+
const X509_NAME *xn, apr_pool_t *p)
11161116
{
1117-
X509_NAME_ENTRY *xsne;
1117+
const X509_NAME_ENTRY *xsne;
11181118
apr_hash_t *count;
11191119
int i, nid;
11201120

@@ -1129,7 +1129,7 @@ static void extract_dn(apr_table_t *t, apr_hash_t *nids, const char *pfx,
11291129

11301130
/* Retrieve the nid, and check whether this is one of the nids
11311131
* which are to be extracted. */
1132-
nid = OBJ_obj2nid((ASN1_OBJECT *)X509_NAME_ENTRY_get_object(xsne));
1132+
nid = OBJ_obj2nid(X509_NAME_ENTRY_get_object(xsne));
11331133

11341134
tag = apr_hash_get(nids, &nid, sizeof nid);
11351135
if (tag) {
@@ -1301,7 +1301,7 @@ apr_array_header_t *ssl_ext_list(apr_pool_t *p, conn_rec *c, int peer,
13011301
*/
13021302
array = apr_array_make(p, count, sizeof(char *));
13031303
for (j = 0; j < count; j++) {
1304-
X509_EXTENSION *ext = X509_get_ext(xs, j);
1304+
MODSSL_X509_EXT_CONST X509_EXTENSION *ext = X509_get_ext(xs, j);
13051305

13061306
if (OBJ_cmp(X509_EXTENSION_get_object(ext), oid) == 0) {
13071307
BIO *bio = BIO_new(BIO_s_mem());

modules/ssl/ssl_private.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@
155155
#define MODSSL_SSL_METHOD_CONST
156156
#endif
157157

158+
#if OPENSSL_VERSION_NUMBER >= 0x40000000L
159+
#define MODSSL_X509_EXT_CONST const
160+
#else
161+
#define MODSSL_X509_EXT_CONST
162+
#endif
163+
158164
#if defined(LIBRESSL_VERSION_NUMBER)
159165
/* Missing from LibreSSL */
160166
#if LIBRESSL_VERSION_NUMBER < 0x2060000f

modules/ssl/ssl_util_ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ static char *asn1_string_convert(apr_pool_t *p, ASN1_STRING *asn1str, int raw)
224224
#define asn1_string_to_utf8(p, a) asn1_string_convert(p, a, 0)
225225

226226
/* convert a NAME_ENTRY to UTF8 string */
227-
char *modssl_X509_NAME_ENTRY_to_string(apr_pool_t *p, X509_NAME_ENTRY *xsne,
227+
char *modssl_X509_NAME_ENTRY_to_string(apr_pool_t *p, const X509_NAME_ENTRY *xsne,
228228
int raw)
229229
{
230230
char *result = asn1_string_convert(p, X509_NAME_ENTRY_get_data(xsne), raw);

modules/ssl/ssl_util_ssl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ EVP_PKEY *modssl_read_privatekey(const char *filename, pem_password_cb *cb, vo
7171

7272
int modssl_smart_shutdown(SSL *ssl);
7373
BOOL modssl_X509_getBC(X509 *, int *, int *);
74-
char *modssl_X509_NAME_ENTRY_to_string(apr_pool_t *p, X509_NAME_ENTRY *xsne,
74+
char *modssl_X509_NAME_ENTRY_to_string(apr_pool_t *p, const X509_NAME_ENTRY *xsne,
7575
int raw);
7676
char *modssl_X509_NAME_to_string(apr_pool_t *, const X509_NAME *, int);
7777
BOOL modssl_X509_getSAN(apr_pool_t *, X509 *, int, const char *, int, apr_array_header_t **);

0 commit comments

Comments
 (0)