Skip to content

Commit 3fc013b

Browse files
committed
Fix CS and checking for IPv6 SAN verify
1 parent fd09728 commit 3fc013b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

ext/openssl/xp_ssl.c

+13-9
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
#define PHP_X509_NAME_ENTRY_TO_UTF8(ne, i, out) \
116116
ASN1_STRING_to_UTF8(&out, X509_NAME_ENTRY_get_data(X509_NAME_get_entry(ne, i)))
117117

118+
#if defined(HAVE_IPV6) && defined(HAVE_INET_PTON)
118119
/* Used for IPv6 Address peer verification */
119120
#define EXPAND_IPV6_ADDRESS(_str, _bytes) \
120121
do { \
@@ -129,6 +130,8 @@
129130
_bytes[14] << 8 | _bytes[15] \
130131
); \
131132
} while(0)
133+
#define HAVE_IPV6_SAN 1
134+
#endif
132135

133136
#if PHP_OPENSSL_API_VERSION < 0x10100
134137
static RSA *php_openssl_tmp_rsa_cb(SSL *s, int is_export, int keylength);
@@ -441,16 +444,17 @@ static bool php_openssl_matches_san_list(X509 *peer, const char *subject_name) /
441444
GENERAL_NAMES *alt_names = X509_get_ext_d2i(peer, NID_subject_alt_name, 0, 0);
442445
int alt_name_count = sk_GENERAL_NAME_num(alt_names);
443446

444-
#if defined(HAVE_IPV6) && defined(HAVE_INET_PTON)
447+
#ifdef HAVE_IPV6_SAN
445448
/* detect if subject name is an IPv6 address and expand once if required */
446-
char subject_name_ipv6_expanded[40];
447-
unsigned char ipv6[16];
448-
bool subject_name_is_ipv6 = false;
449-
subject_name_ipv6_expanded[0] = 0;
449+
char subject_name_ipv6_expanded[40];
450+
unsigned char ipv6[16];
451+
bool subject_name_is_ipv6 = false;
452+
subject_name_ipv6_expanded[0] = 0;
453+
450454
if (inet_pton(AF_INET6, subject_name, &ipv6)) {
451-
EXPAND_IPV6_ADDRESS(subject_name_ipv6_expanded, ipv6);
452-
subject_name_is_ipv6 = true;
453-
}
455+
EXPAND_IPV6_ADDRESS(subject_name_ipv6_expanded, ipv6);
456+
subject_name_is_ipv6 = true;
457+
}
454458
#endif
455459

456460
for (i = 0; i < alt_name_count; i++) {
@@ -491,7 +495,7 @@ static bool php_openssl_matches_san_list(X509 *peer, const char *subject_name) /
491495
return 1;
492496
}
493497
}
494-
#if defined(HAVE_IPV6) && defined(HAVE_INET_PTON)
498+
#ifdef HAVE_IPV6_SAN
495499
else if (san->d.ip->length == 16 && subject_name_is_ipv6) {
496500
ipbuffer[0] = 0;
497501
EXPAND_IPV6_ADDRESS(ipbuffer, san->d.iPAddress->data);

0 commit comments

Comments
 (0)