]> granicus.if.org Git - php/commitdiff
Deprecate CN_match in favor of peer_name in SSL contexts
authorDaniel Lowrey <rdlowrey@php.net>
Wed, 26 Feb 2014 20:06:08 +0000 (13:06 -0700)
committerDaniel Lowrey <rdlowrey@php.net>
Wed, 26 Feb 2014 20:20:06 +0000 (13:20 -0700)
25 files changed:
NEWS
UPGRADING
ext/openssl/openssl.c
ext/openssl/tests/bug46127.phpt
ext/openssl/tests/bug48182.phpt
ext/openssl/tests/bug54992.phpt
ext/openssl/tests/bug65538_001.phpt
ext/openssl/tests/bug65538_003.phpt
ext/openssl/tests/bug65729.phpt
ext/openssl/tests/openssl_peer_fingerprint.phpt
ext/openssl/tests/peer_verification.phpt
ext/openssl/tests/san_peer_matching.phpt
ext/openssl/tests/session_meta_capture.phpt
ext/openssl/tests/sni_001.phpt
ext/openssl/tests/stream_crypto_flags_001.phpt
ext/openssl/tests/stream_crypto_flags_002.phpt
ext/openssl/tests/stream_crypto_flags_003.phpt
ext/openssl/tests/stream_crypto_flags_004.phpt
ext/openssl/tests/stream_verify_peer_name_001.phpt [moved from ext/openssl/tests/stream_verify_host_001.phpt with 96% similarity]
ext/openssl/tests/stream_verify_peer_name_002.phpt [moved from ext/openssl/tests/stream_verify_host_002.phpt with 96% similarity]
ext/openssl/tests/stream_verify_peer_name_003.phpt [moved from ext/openssl/tests/stream_verify_host_003.phpt with 100% similarity]
ext/openssl/tests/streams_crypto_method.phpt
ext/openssl/tests/tlsv1.0_wrapper.phpt
ext/openssl/tests/tlsv1.1_wrapper.phpt
ext/openssl/tests/tlsv1.2_wrapper.phpt

diff --git a/NEWS b/NEWS
index b79f0006a9b06bdc7dfd142c1f3b88e664a8f73e..0c28d48c4ae2d6b8b0b85ade63336bd05ba01ad5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,9 @@ PHP                                                                        NEWS
   . Implemented unified default encoding
     (RFC: https://wiki.php.net/rfc/default_encoding). (Yasuo Ohgaki)
 
+- Curl
+  . Check for openssl.cafile ini directive when loading CA certs. (Daniel Lowrey)
+
 - Fileinfo
   . Upgraded to libmagic-5.17 (Anatol)
 
@@ -25,12 +28,17 @@ PHP                                                                        NEWS
   . Fallback to Windows CA cert store for peer verification if no openssl.cafile
     ini directive or "cafile" SSL context option specified in Windows.
     (Chris Wright)
+  . The openssl.cafile and openssl.capath ini directives introduced in alpha2
+    now have PHP_INI_PERDIR accessibility (was PHP_INI_ALL). (Daniel Lowrey)
+  . New "peer_name" SSL context option replaces "CN_match" (which still works
+    as before but triggers E_DEPRECATED). (Daniel Lowrey)
   . Fixed segfault when accessing non-existent context for client SNI use
     (Daniel Lowrey)
   . Fixed bug #66501 (Add EC key support to php_openssl_is_private_key).
     (Mark Zedwood)
-  . Fixed Bug #47030 (add new boolean "verify_host" SSL context option
-    allowing clients to verify names separately from peer certs).
+  . Fixed Bug #47030 (add new boolean "verify_peer_name" SSL context option
+    allowing clients to verify cert names separately from the cert itself).
+    "verify_peer_name" is enabled by default for client streams.
     (Daniel Lowrey)
   . Fixed Bug #65538 ("cafile" SSL context option now supports stream
     wrappers). (Daniel Lowrey)
index 4ef3085672c89e980608fbea578092fc6f27ec7b..6ae672e4f5f36140c376c437da1c968df43dddf1 100755 (executable)
--- a/UPGRADING
+++ b/UPGRADING
@@ -69,8 +69,8 @@ PHP X.Y UPGRADE NOTES
 
 - Added gost-crypto (CryptoPro S-box) hash algo.
 
-- Stream wrappers verify peers and host names by default in encrypted client
-  streams.
+- Stream wrappers verify peer certificates and host names by default in
+  encrypted client streams.
 
 - Added openssl certificate fingerprint support (inclusive stream context
   option).
@@ -104,10 +104,14 @@ PHP X.Y UPGRADE NOTES
 
 - Added "crypto_method" SSL context option for use in encrypted streams.
 
+- Added "peer_name" SSL context option to better reflect peer certificate
+  name matching using SAN extension (replaces deprecated "CN_match").
+
 - Added stream wrapper support when specifying "cafile" SSL context paths.
 
-- Independent peer cert and host names validation is now available via a new
-  "verify_host" SSL context option.
+- Independent peer cert and peer name validation is now available via a new
+  boolean "verify_peer_name" SSL context option. This option is enabled by
+  default in encrypted client streams.
 
 - Added protocol-specific tlsv1.0://, tlsv1.1:// and tlsv1.2:// encryption
   stream wrappers. tls:// wrapper now supports TLSv1.1 and TLSv1.2 (previously
@@ -131,6 +135,13 @@ PHP X.Y UPGRADE NOTES
   Instance calls from an incompatible context are now deprecated and issue
   E_DEPRECATED instead of E_STRICT. See https://wiki.php.net/rfc/incompat_ctx
 
+- The "CN_match" SSL context option is deprecated in favor of the new
+  "peer_name" option. Name verification now checks certificate SAN names as
+  well as the CN field and "CN_match" is deprecated to avoid confusion. Its
+  use triggers E_DEPRECATED but continues to work as before. If both values
+  are specified "CN_match" takes precedence. Otherwise, the two options are
+  interchangeable.
+
 ========================================
 4. Changed Functions
 ========================================
index d2b453807d9b461aca763749cacdd904769aba8b..88ae9a10002053f4fe9116cf63e3340fd21735ef 100755 (executable)
@@ -5145,24 +5145,26 @@ static zend_bool matches_common_name(X509 *peer, const char *subject_name TSRMLS
 int php_openssl_apply_verification_policy(SSL *ssl, X509 *peer, php_stream *stream TSRMLS_DC) /* {{{ */
 {
        zval **val = NULL;
-       char *cnmatch = NULL;
+       char *peer_name = NULL;
        int err;
        zend_bool must_verify_peer;
-       zend_bool must_verify_host;
+       zend_bool must_verify_peer_name;
        zend_bool must_verify_fingerprint;
+       zend_bool has_cnmatch_ctx_opt;
        php_openssl_netstream_data_t *sslsock = (php_openssl_netstream_data_t*)stream->abstract;
 
        must_verify_peer = GET_VER_OPT("verify_peer")
                ? zend_is_true(*val)
                : sslsock->is_client;
 
-       must_verify_host = GET_VER_OPT("verify_host")
+       has_cnmatch_ctx_opt = GET_VER_OPT("CN_match");
+       must_verify_peer_name = (has_cnmatch_ctx_opt || GET_VER_OPT("verify_peer_name"))
                ? zend_is_true(*val)
                : sslsock->is_client;
 
        must_verify_fingerprint = (GET_VER_OPT("peer_fingerprint") && zend_is_true(*val));
 
-       if ((must_verify_peer || must_verify_host || must_verify_fingerprint) && peer == NULL) {
+       if ((must_verify_peer || must_verify_peer_name || must_verify_fingerprint) && peer == NULL) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not get peer certificate");
                return FAILURE;
        }
@@ -5190,7 +5192,7 @@ int php_openssl_apply_verification_policy(SSL *ssl, X509 *peer, php_stream *stre
                }
        }
 
-       /* If a peer_fingerprint match is required this trumps host verification */
+       /* If a peer_fingerprint match is required this trumps peer and peer_name verification */
        if (must_verify_fingerprint) {
                if (Z_TYPE_PP(val) == IS_STRING || Z_TYPE_PP(val) == IS_ARRAY) {
                        if (!php_x509_fingerprint_match(peer, *val TSRMLS_CC)) {
@@ -5207,18 +5209,24 @@ int php_openssl_apply_verification_policy(SSL *ssl, X509 *peer, php_stream *stre
        }
 
        /* verify the host name presented in the peer certificate */
+       if (must_verify_peer_name) {
+               GET_VER_OPT_STRING("peer_name", peer_name);
 
-       if (must_verify_host) {
-               GET_VER_OPT_STRING("CN_match", cnmatch);
-               /* If no CN_match was specified assign the autodetected url name in client environments */
-               if (cnmatch == NULL && sslsock->is_client) {
-                       cnmatch = sslsock->url_name;
+               if (has_cnmatch_ctx_opt) {
+                       GET_VER_OPT_STRING("CN_match", peer_name);
+                       php_error(E_DEPRECATED,
+                               "the 'CN_match' SSL context option is deprecated in favor of 'peer_name'"
+                       );
+               }
+               /* If no peer name was specified we use the autodetected url name in client environments */
+               if (peer_name == NULL && sslsock->is_client) {
+                       peer_name = sslsock->url_name;
                }
 
-               if (cnmatch) {
-                       if (matches_san_list(peer, cnmatch TSRMLS_CC)) {
+               if (peer_name) {
+                       if (matches_san_list(peer, peer_name TSRMLS_CC)) {
                                return SUCCESS;
-                       } else if (matches_common_name(peer, cnmatch TSRMLS_CC)) {
+                       } else if (matches_common_name(peer, peer_name TSRMLS_CC)) {
                                return SUCCESS;
                        } else {
                                return FAILURE;
@@ -5342,7 +5350,7 @@ static int win_cert_verify_callback(X509_STORE_CTX *x509_store_ctx, void *arg) /
                LPWSTR server_name = NULL;
                BOOL verify_result;
 
-               { /* This looks ridiculous and it is - but we validate the name ourselves using the CN_match
+               { /* This looks ridiculous and it is - but we validate the name ourselves using the peer_name
                     ctx option, so just use the CN from the cert here */
 
                        X509_NAME *cert_name;
index 6a3d1a0d6c9220d569289093da524f4e3b1c67bc..80bd61c287c01286ed10f5aa60d010804f96ca68 100644 (file)
@@ -27,7 +27,7 @@ $clientCode = <<<'CODE'
 
     $clientCtx = stream_context_create(['ssl' => [
         'verify_peer' => false,
-        'verify_host' => false
+        'verify_peer_name' => false
     ]]);
 
     phpt_wait();
index 8d3f9eef4354206f67dcba18653637b87143e59a..5211c23d20d674116f7381aaefdd0098b3cde6a6 100644 (file)
@@ -28,7 +28,7 @@ $clientCode = <<<'CODE'
     $clientFlags = STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT;
     $clientCtx = stream_context_create(['ssl' => [
         'cafile' => __DIR__ . '/bug54992-ca.pem',
-        'CN_match' => 'bug54992.local'
+        'peer_name' => 'bug54992.local'
     ]]);
 
     phpt_wait();
index 2937faa16995fb5ad1cff0f2009f06ceea52b1ff..bcb33fdd8aec7375d79820fc96e89eb2e8852c8c 100644 (file)
@@ -25,7 +25,7 @@ $clientCode = <<<'CODE'
     $clientCtx = stream_context_create(['ssl' => [
         'verify_peer' => true,
         'cafile' => __DIR__ . '/bug54992-ca.pem',
-        'CN_match' => 'buga_buga',
+        'peer_name' => 'buga_buga',
     ]]);
 
     phpt_wait();
index ea7d6f4d8d35b649d9a1e2a690161288e1c9817b..e666859d0d82ff5b0f14c07c9762e9d2a6bb6016 100644 (file)
@@ -37,7 +37,7 @@ $clientCode = <<<'CODE'
     $serverUri = "https://127.0.0.1:64321/";
     $clientCtx = stream_context_create(['ssl' => [
         'cafile' => 'file://' . __DIR__ . '/bug54992-ca.pem',
-        'CN_match' => 'bug54992.local',
+        'peer_name' => 'bug54992.local',
     ]]);
 
     phpt_wait();
index b927e4ed854c406e2c17b2dbe6a27507fce950bd..da99779143d593658d31615fe7e8e89564ac598f 100644 (file)
@@ -38,7 +38,7 @@ $clientCode = <<<'CODE'
     $serverUri = "https://127.0.0.1:64321/";
     $clientCtx = stream_context_create(['ssl' => [
         'cafile' => 'phar://' . __DIR__ . '/bug65538.phar/bug54992-ca.pem',
-        'CN_match' => 'bug54992.local',
+        'peer_name' => 'bug54992.local',
     ]]);
 
     phpt_wait();
index e27dbb9c93d3c795b819c02b672266e996232baa..b405b7213d6ecfcf12dfb57d0830bb0aa13f0a3d 100644 (file)
@@ -33,7 +33,7 @@ $clientCode = <<<'CODE'
         $clientCtx = stream_context_create(['ssl' => [
             'verify_peer'       => true,
             'allow_self_signed'    => true,
-            'CN_match'          => $expected_name,
+            'peer_name'          => $expected_name,
         ]]);
 
         var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
index 5390c492eeff5e784304eacf303fb87335483e92..0bd91d543a0852c80634154dc708af14caebd16e 100644 (file)
@@ -27,7 +27,7 @@ $clientCode = <<<'CODE'
         'verify_peer'       => true,
         'cafile'            => __DIR__ . '/bug54992-ca.pem',
         'capture_peer_cert'    => true,
-        'CN_match'          => 'bug54992.local',
+        'peer_name'          => 'bug54992.local',
     ]]);
 
     phpt_wait();
index 607b61797fa126fb07b8681a686e893a5b70b819..6aff34ddd802dc45965b60532df9d904d04074e3 100644 (file)
@@ -40,14 +40,14 @@ $clientCode = <<<'CODE'
     // Should succeed with peer verification disabled in context
     $clientCtx = stream_context_create(['ssl' => [
         'verify_peer' => false,
-        'verify_host' => false,
+        'verify_peer_name' => false,
     ]]);
     var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
 
     // Should succeed with CA file specified in context
     $clientCtx = stream_context_create(['ssl' => [
         'cafile'   => $caFile,
-        'CN_match' => 'bug54992.local',
+        'peer_name' => 'bug54992.local',
     ]]);
     var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
 CODE;
index 3fa479ea13450c35272499e288dc9ab2b35e5bcc..0e1f30cb649508376f3422691ae819e9aeda4224 100644 (file)
@@ -30,10 +30,10 @@ $clientCode = <<<'CODE'
 
     phpt_wait();
 
-    stream_context_set_option($clientCtx, 'ssl', 'CN_match', 'example.org');
+    stream_context_set_option($clientCtx, 'ssl', 'peer_name', 'example.org');
     var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
 
-    stream_context_set_option($clientCtx, 'ssl', 'CN_match', 'moar.example.org');
+    stream_context_set_option($clientCtx, 'ssl', 'peer_name', 'moar.example.org');
     var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
 CODE;
 
index 3b2a80446fd8794dccc88cdf8b182adac0f5daaf..62cdffe6860932ad2e6078ca65294e455d148446 100644 (file)
@@ -29,7 +29,7 @@ $clientCode = <<<'CODE'
     $clientCtx = stream_context_create(['ssl' => [
         'verify_peer' => true,
         'cafile' => __DIR__ . '/bug54992-ca.pem',
-        'CN_match' => 'bug54992.local',
+        'peer_name' => 'bug54992.local',
         'capture_session_meta' => true,
     ]]);
 
index 0dbd18d381520bb30a94adf937d5a1999b74462c..e6c05f7ec23a5d04e862c21500c9b9d988a405bf 100644 (file)
@@ -26,9 +26,9 @@ function context($host = NULL) {
        stream_context_set_option($ctx, 'ssl', 'capture_peer_cert', true);
        stream_context_set_option($ctx, 'ssl', 'verify_peer', false);
        if ($host) {
-               stream_context_set_option($ctx, 'ssl', 'CN_match', $host);
+               stream_context_set_option($ctx, 'ssl', 'peer_name', $host);
        } else {
-               stream_context_set_option($ctx, 'ssl', 'verify_host', false);
+               stream_context_set_option($ctx, 'ssl', 'verify_peer_name', false);
        }
 
        return $ctx;
index b9a49f9ac2059fe751e945d709c2ca166af4a35a..f988886db2bb50dd8f7af1a49903b85ba9d78e4a 100644 (file)
@@ -27,7 +27,7 @@ $clientCode = <<<'CODE'
     $clientCtx = stream_context_create(['ssl' => [
         'verify_peer' => true,
         'cafile' => __DIR__ . '/bug54992-ca.pem',
-        'CN_match' => 'bug54992.local',
+        'peer_name' => 'bug54992.local',
     ]]);
 
     phpt_wait();
index 15b3fb94161883b215bdf8d2e9f2383f472773e2..b72b4d62f29fb72562405ddd39383e5ff2e6ae79 100644 (file)
@@ -29,7 +29,7 @@ $clientCode = <<<'CODE'
     $clientCtx = stream_context_create(['ssl' => [
         'verify_peer' => true,
         'cafile' => __DIR__ . '/bug54992-ca.pem',
-        'CN_match' => 'bug54992.local',
+        'peer_name' => 'bug54992.local',
     ]]);
 
     phpt_wait();
index c5aebd891fbdd2c2bdefe6186644b384cf9e76bc..30ca7a76e99b2ad209b57f8589d1590687323df8 100644 (file)
@@ -32,7 +32,7 @@ $clientCode = <<<'CODE'
     $clientCtx = stream_context_create(['ssl' => [
         'verify_peer' => true,
         'cafile' => __DIR__ . '/bug54992-ca.pem',
-        'CN_match' => 'bug54992.local',
+        'peer_name' => 'bug54992.local',
     ]]);
 
     phpt_wait();
index 38f406caa3e31eeac809039048d6689c2630f5eb..e51a2bab3e0dc289d9d4afcfb682cd97c1f27a3b 100644 (file)
@@ -29,7 +29,7 @@ $clientCode = <<<'CODE'
     $clientCtx = stream_context_create(['ssl' => [
         'verify_peer' => true,
         'cafile' => __DIR__ . '/bug54992-ca.pem',
-        'CN_match' => 'bug54992.local',
+        'peer_name' => 'bug54992.local',
     ]]);
 
     phpt_wait();
similarity index 96%
rename from ext/openssl/tests/stream_verify_host_001.phpt
rename to ext/openssl/tests/stream_verify_peer_name_001.phpt
index c4d87b82db1c114ed742c01281ce6bbf6f366d7a..4aecf8c7446ad8f3446b8e3ab0e9119d650bb2b5 100644 (file)
@@ -24,7 +24,7 @@ $clientCode = <<<'CODE'
     $clientFlags = STREAM_CLIENT_CONNECT;
     $clientCtx = stream_context_create(['ssl' => [
         'verify_peer' => false,
-        'CN_match' => 'bug54992.local'
+        'peer_name' => 'bug54992.local'
     ]]);
 
     phpt_wait();
similarity index 96%
rename from ext/openssl/tests/stream_verify_host_002.phpt
rename to ext/openssl/tests/stream_verify_peer_name_002.phpt
index c0db4f2d906a212e315c5a2e9d42fd07f4688cf9..ae97ea1269766878df6b3e3ab293b4739c35bea7 100644 (file)
@@ -25,7 +25,7 @@ $clientCode = <<<'CODE'
     $clientCtx = stream_context_create(['ssl' => [
         'verify_peer' => true,
         'cafile' => __DIR__ . '/bug54992-ca.pem',
-        'verify_host' => false
+        'verify_peer_name' => false
     ]]);
 
     phpt_wait();
index 1bf9048151148a3028daa8b164a49e7b2a7fbd0a..84f793430840d0040482bf4d09ce744d5f494ec6 100644 (file)
@@ -39,7 +39,7 @@ $clientCode = <<<'CODE'
     $clientCtx = stream_context_create(['ssl' => [
         'crypto_method' => STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
         'verify_peer' => false,
-        'verify_host' => false
+        'verify_peer_name' => false
     ]]);
 
     phpt_wait();
index d24ab455deb9c6f53362a0c09dca3060f204d2bc..7479259426f3c3b712b61ae2cf4e4a079763b55c 100644 (file)
@@ -24,7 +24,7 @@ $clientCode = <<<'CODE'
     $flags = STREAM_CLIENT_CONNECT;
     $ctx = stream_context_create(['ssl' => [
         'verify_peer' => false,
-        'verify_host' => false,
+        'verify_peer_name' => false,
     ]]);
 
     phpt_wait();
index cd881782c4aebd81dc302a5f2bb31305c7c29b2f..3e067a14b761bf181e64d51f1044cc8353b21b7e 100644 (file)
@@ -25,7 +25,7 @@ $clientCode = <<<'CODE'
     $flags = STREAM_CLIENT_CONNECT;
     $ctx = stream_context_create(['ssl' => [
         'verify_peer' => false,
-        'verify_host' => false,
+        'verify_peer_name' => false,
     ]]);
 
     phpt_wait();
index 124fdf202c3247a919625ba0ce84f3e60ac12305..ca967d18b492ebffddc15a0094e6db43b13ef26a 100644 (file)
@@ -25,7 +25,7 @@ $clientCode = <<<'CODE'
     $flags = STREAM_CLIENT_CONNECT;
     $ctx = stream_context_create(['ssl' => [
         'verify_peer' => false,
-        'verify_host' => false,
+        'verify_peer_name' => false,
     ]]);
 
     phpt_wait();