summaryrefslogtreecommitdiff
path: root/ext/openssl/openssl.c
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2009-09-14 12:50:30 +0000
committerIlia Alshanetsky <iliaa@php.net>2009-09-14 12:50:30 +0000
commitd3ae759391cf4059749b03b02eb2c5496546f17d (patch)
tree21e4fab28040d87a342b157b30a41b2e46cc5262 /ext/openssl/openssl.c
parentaa597262681e287109e9c5f24f8bd8ea34146031 (diff)
downloadphp-git-d3ae759391cf4059749b03b02eb2c5496546f17d.tar.gz
Fixed certificate validation inside php_openssl_apply_verification_policy
Diffstat (limited to 'ext/openssl/openssl.c')
-rw-r--r--ext/openssl/openssl.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index e80cf393e7..764b6df594 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -4583,8 +4583,15 @@ int php_openssl_apply_verification_policy(SSL *ssl, X509 *peer, php_stream *stre
GET_VER_OPT_STRING("CN_match", cnmatch);
if (cnmatch) {
int match = 0;
+ int name_len = X509_NAME_get_text_by_NID(name, NID_commonName, buf, sizeof(buf));
- X509_NAME_get_text_by_NID(name, NID_commonName, buf, sizeof(buf));
+ if (name_len == -1) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to locate peer certificate CN");
+ return FAILURE;
+ } else if (name_len != strlen(buf)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Peer certificate CN=`%.*s' is malformed", name_len, buf);
+ return FAILURE;
+ }
match = strcmp(cnmatch, buf) == 0;
if (!match && strlen(buf) > 3 && buf[0] == '*' && buf[1] == '.') {
@@ -4599,10 +4606,7 @@ int php_openssl_apply_verification_policy(SSL *ssl, X509 *peer, php_stream *stre
if (!match) {
/* didn't match */
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
- "Peer certificate CN=`%s' did not match expected CN=`%s'",
- buf, cnmatch);
-
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Peer certificate CN=`%.*s' did not match expected CN=`%s'", name_len, buf, cnmatch);
return FAILURE;
}
}