Skip to content

Commit f0aa120

Browse files
committed
ext/openssl: make php_openssl_x509_fingerprint_match() warn on all failure cases
This prevents some instance of double warnings
1 parent 4d49c0c commit f0aa120

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

ext/openssl/tests/bug68920.phpt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,13 @@ bool(false)
7676

7777
Warning: stream_socket_client(): Invalid peer_fingerprint array; [algo => fingerprint] form required in %s on line %d
7878

79-
Warning: stream_socket_client(): peer_fingerprint match failure in %s on line %d
80-
8179
Warning: stream_socket_client(): Failed to enable crypto in %s on line %d
8280

8381
Warning: stream_socket_client(): Unable to connect to %s (Unknown error) in %s on line %d
8482
bool(false)
8583

8684
Warning: stream_socket_client(): Invalid peer_fingerprint array; [algo => fingerprint] form required in %s on line %d
8785

88-
Warning: stream_socket_client(): peer_fingerprint match failure in %s on line %d
89-
9086
Warning: stream_socket_client(): Failed to enable crypto in %s on line %d
9187

9288
Warning: stream_socket_client(): Unable to connect to %s (Unknown error) in %s on line %d

ext/openssl/xp_ssl.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,15 @@ static bool php_openssl_x509_fingerprint_match(php_stream *stream, X509 *peer, c
404404
break;
405405
}
406406

407-
return method && php_openssl_x509_fingerprint_is_equal(peer, method, Z_STR_P(val));
407+
if (UNEXPECTED(method == NULL)) {
408+
php_stream_warn(stream, AuthFailed, "peer_fingerprint length doesn't match a md5 or sha1 hash");
409+
return false;
410+
}
411+
if (!php_openssl_x509_fingerprint_is_equal(peer, method, Z_STR_P(val))) {
412+
php_stream_warn(stream, AuthFailed, "peer_fingerprint match failure");
413+
return false;
414+
}
415+
return true;
408416
} else if (Z_TYPE_P(val) == IS_ARRAY) {
409417
zval *current;
410418
zend_string *key;
@@ -422,6 +430,7 @@ static bool php_openssl_x509_fingerprint_match(php_stream *stream, X509 *peer, c
422430
return false;
423431
}
424432
if (!php_openssl_x509_fingerprint_is_equal(peer, ZSTR_VAL(key), Z_STR_P(current))) {
433+
php_stream_warn(stream, AuthFailed, "peer_fingerprint match failure");
425434
return false;
426435
}
427436
} ZEND_HASH_FOREACH_END();
@@ -635,9 +644,6 @@ static zend_result php_openssl_apply_peer_verification_policy(SSL *ssl, X509 *pe
635644
if (must_verify_fingerprint) {
636645
if (Z_TYPE_P(peer_fingerprint) == IS_STRING || Z_TYPE_P(peer_fingerprint) == IS_ARRAY) {
637646
if (!php_openssl_x509_fingerprint_match(stream, peer, peer_fingerprint)) {
638-
php_stream_warn(stream, AuthFailed,
639-
"peer_fingerprint match failure"
640-
);
641647
return FAILURE;
642648
}
643649
} else {

0 commit comments

Comments
 (0)