]> granicus.if.org Git - php/commitdiff
- Merge: Fixed certificate validation inside php_openssl_apply_verification_policy
authorPierre Joye <pajoye@php.net>
Fri, 9 Oct 2009 19:08:56 +0000 (19:08 +0000)
committerPierre Joye <pajoye@php.net>
Fri, 9 Oct 2009 19:08:56 +0000 (19:08 +0000)
ext/openssl/openssl.c

index 977a077d1ccfbe8f7cb854f9e8dfaf1c96966b83..402a5f5e8dc69a12a0cf030058f87d54e10e421c 100644 (file)
@@ -4323,8 +4323,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] == '.') {
@@ -4339,10 +4346,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;
                }
        }