Skip to content

Commit 6106896

Browse files
committed
DNS name comparison is now case insensitive.
1 parent 39c0dae commit 6106896

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

ext/openssl/openssl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4834,7 +4834,7 @@ static zend_bool php_openssl_match_cn(const char *subjectname, const char *certn
48344834
char *wildcard;
48354835
int prefix_len, suffix_len, subject_len;
48364836

4837-
if (strcmp(subjectname, certname) == 0) {
4837+
if (strcasecmp(subjectname, certname) == 0) {
48384838
return 1;
48394839
}
48404840

@@ -4844,7 +4844,7 @@ static zend_bool php_openssl_match_cn(const char *subjectname, const char *certn
48444844

48454845
// 1) prefix, if not empty, must match subject
48464846
prefix_len = wildcard - certname;
4847-
if (prefix_len && strncmp(subjectname, certname, prefix_len) != 0) {
4847+
if (prefix_len && strncasecmp(subjectname, certname, prefix_len) != 0) {
48484848
return 0;
48494849
}
48504850

@@ -4854,7 +4854,7 @@ static zend_bool php_openssl_match_cn(const char *subjectname, const char *certn
48544854
/* 2) suffix must match
48554855
* 3) no . between prefix and suffix
48564856
**/
4857-
return strcmp(wildcard + 1, subjectname + subject_len - suffix_len) == 0 &&
4857+
return strcasecmp(wildcard + 1, subjectname + subject_len - suffix_len) == 0 &&
48584858
memchr(subjectname + prefix_len, '.', subject_len - suffix_len - prefix_len) == NULL;
48594859
}
48604860

ext/openssl/tests/bug65729.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ stream_context_set_option($context, 'ssl', 'allow_self_signed', true);
1313
$server = stream_socket_server('ssl://127.0.0.1:64321', $errno, $errstr,
1414
STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context);
1515

16-
$expected_names = array('foo.test.com.sg', 'foo.test.com', 'foo.bar.test.com');
16+
$expected_names = array('foo.test.com.sg', 'foo.test.com', 'FOO.TEST.COM', 'foo.bar.test.com');
1717

1818
$pid = pcntl_fork();
1919
if ($pid == -1) {
@@ -44,6 +44,7 @@ Warning: stream_socket_client(): Failed to enable crypto in %s on line %d
4444
Warning: stream_socket_client(): unable to connect to ssl://127.0.0.1:64321 (Unknown error) in %s on line %d
4545
bool(false)
4646
resource(%d) of type (stream)
47+
resource(%d) of type (stream)
4748

4849
Warning: stream_socket_client(): Peer certificate CN=`*.test.com' did not match expected CN=`foo.bar.test.com' in %s on line %d
4950

0 commit comments

Comments
 (0)