Skip to content

Commit 108105b

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #76694: native Windows cert verification uses CN as sever name
2 parents ee74f2e + 7fd4826 commit 108105b

File tree

2 files changed

+7
-45
lines changed

2 files changed

+7
-45
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ PHP NEWS
1919
reference). (Dmitry)
2020
. Fixed bug #80968 (JIT segfault with return from required file). (Dmitry)
2121

22+
- OpenSSL:
23+
. Fixed bug #76694 (native Windows cert verification uses CN as sever name).
24+
(cmb)
25+
2226
- MySQLnd:
2327
. Fixed bug #80761 (PDO uses too much memory). (Nikita)
2428

ext/openssl/xp_ssl.c

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -715,56 +715,14 @@ static int php_openssl_win_cert_verify_callback(X509_STORE_CTX *x509_store_ctx,
715715
LPWSTR server_name = NULL;
716716
BOOL verify_result;
717717

718-
{ /* This looks ridiculous and it is - but we validate the name ourselves using the peer_name
719-
ctx option, so just use the CN from the cert here */
720-
721-
X509_NAME *cert_name;
722-
unsigned char *cert_name_utf8;
723-
int index, cert_name_utf8_len;
724-
DWORD num_wchars;
725-
726-
cert_name = X509_get_subject_name(cert);
727-
index = X509_NAME_get_index_by_NID(cert_name, NID_commonName, -1);
728-
if (index < 0) {
729-
php_error_docref(NULL, E_WARNING, "Unable to locate certificate CN");
730-
CertFreeCertificateChain(cert_chain_ctx);
731-
CertFreeCertificateContext(cert_ctx);
732-
RETURN_CERT_VERIFY_FAILURE(SSL_R_CERTIFICATE_VERIFY_FAILED);
733-
}
734-
735-
cert_name_utf8_len = PHP_X509_NAME_ENTRY_TO_UTF8(cert_name, index, cert_name_utf8);
736-
737-
num_wchars = MultiByteToWideChar(CP_UTF8, 0, (char*)cert_name_utf8, -1, NULL, 0);
738-
if (num_wchars == 0) {
739-
php_error_docref(NULL, E_WARNING, "Unable to convert %s to wide character string", cert_name_utf8);
740-
OPENSSL_free(cert_name_utf8);
741-
CertFreeCertificateChain(cert_chain_ctx);
742-
CertFreeCertificateContext(cert_ctx);
743-
RETURN_CERT_VERIFY_FAILURE(SSL_R_CERTIFICATE_VERIFY_FAILED);
744-
}
745-
746-
server_name = emalloc((num_wchars * sizeof(WCHAR)) + sizeof(WCHAR));
747-
748-
num_wchars = MultiByteToWideChar(CP_UTF8, 0, (char*)cert_name_utf8, -1, server_name, num_wchars);
749-
if (num_wchars == 0) {
750-
php_error_docref(NULL, E_WARNING, "Unable to convert %s to wide character string", cert_name_utf8);
751-
efree(server_name);
752-
OPENSSL_free(cert_name_utf8);
753-
CertFreeCertificateChain(cert_chain_ctx);
754-
CertFreeCertificateContext(cert_ctx);
755-
RETURN_CERT_VERIFY_FAILURE(SSL_R_CERTIFICATE_VERIFY_FAILED);
756-
}
757-
758-
OPENSSL_free(cert_name_utf8);
759-
}
760-
761718
ssl_policy_params.dwAuthType = (sslsock->is_client) ? AUTHTYPE_SERVER : AUTHTYPE_CLIENT;
762-
ssl_policy_params.pwszServerName = server_name;
719+
/* we validate the name ourselves using the peer_name
720+
ctx option, so no need to use a server name here */
721+
ssl_policy_params.pwszServerName = NULL;
763722
chain_policy_params.pvExtraPolicyPara = &ssl_policy_params;
764723

765724
verify_result = CertVerifyCertificateChainPolicy(CERT_CHAIN_POLICY_SSL, cert_chain_ctx, &chain_policy_params, &chain_policy_status);
766725

767-
efree(server_name);
768726
CertFreeCertificateChain(cert_chain_ctx);
769727
CertFreeCertificateContext(cert_ctx);
770728

0 commit comments

Comments
 (0)