]> granicus.if.org Git - php/commitdiff
Fixed certificate validation inside php_openssl_apply_verification_policy
authorIlia Alshanetsky <iliaa@php.net>
Mon, 14 Sep 2009 12:50:30 +0000 (12:50 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 14 Sep 2009 12:50:30 +0000 (12:50 +0000)
NEWS
ext/openssl/openssl.c

diff --git a/NEWS b/NEWS
index 48c076a6de07b75db189edc7d32a7150eecfff6b..8c99f45899c8a513ba8a13b985da7cfacddb5f62 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? Sep 2009, PHP 5.2.11
+- Fixed certificate validation inside php_openssl_apply_verification_policy
+  (Ryan Sleevi, Ilia)
 
 10 Sep 2009, PHP 5.2.11RC3
 - Updated timezone database to version 2009.13 (2009m) (Derick)
index 6c8aefa2fefe6fea79e48a86f29980f36230e9ea..9e4fc2785fbdee9215d69586f30b91a4545af6d8 100644 (file)
@@ -3845,8 +3845,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] == '.') {
@@ -3861,10 +3868,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;
                }
        }