1--TEST-- 2Bug #65729: CN_match gives false positive when wildcard is used 3--SKIPIF-- 4<?php 5if (!extension_loaded("openssl")) die("skip openssl not loaded"); 6if (!function_exists("proc_open")) die("skip no proc_open"); 7?> 8--FILE-- 9<?php 10$serverCode = <<<'CODE' 11 $serverUri = "ssl://127.0.0.1:64321"; 12 $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN; 13 $serverCtx = stream_context_create(['ssl' => [ 14 'local_cert' => __DIR__ . '/bug65729.pem' 15 ]]); 16 17 $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx); 18 phpt_notify(); 19 20 $expected_names = ['foo.test.com.sg', 'foo.test.com', 'FOO.TEST.COM', 'foo.bar.test.com']; 21 foreach ($expected_names as $name) { 22 @stream_socket_accept($server, 1); 23 } 24CODE; 25 26$clientCode = <<<'CODE' 27 $serverUri = "ssl://127.0.0.1:64321"; 28 $clientFlags = STREAM_CLIENT_CONNECT; 29 30 phpt_wait(); 31 32 $expected_names = ['foo.test.com.sg', 'foo.test.com', 'FOO.TEST.COM', 'foo.bar.test.com']; 33 foreach ($expected_names as $expected_name) { 34 $clientCtx = stream_context_create(['ssl' => [ 35 'verify_peer' => true, 36 'allow_self_signed' => true, 37 'peer_name' => $expected_name, 38 ]]); 39 40 var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx)); 41 } 42CODE; 43 44include 'ServerClientTestCase.inc'; 45ServerClientTestCase::getInstance()->run($clientCode, $serverCode); 46?> 47--EXPECTF-- 48Warning: stream_socket_client(): Peer certificate CN=`*.test.com' did not match expected CN=`foo.test.com.sg' in %s on line %d 49 50Warning: stream_socket_client(): Failed to enable crypto in %s on line %d 51 52Warning: stream_socket_client(): unable to connect to ssl://127.0.0.1:64321 (Unknown error) in %s on line %d 53bool(false) 54resource(%d) of type (stream) 55resource(%d) of type (stream) 56 57Warning: stream_socket_client(): Peer certificate CN=`*.test.com' did not match expected CN=`foo.bar.test.com' in %s on line %d 58 59Warning: stream_socket_client(): Failed to enable crypto in %s on line %d 60 61Warning: stream_socket_client(): unable to connect to ssl://127.0.0.1:64321 (Unknown error) in %s on line %d 62bool(false) 63