1--TEST-- 2Peer verification matches SAN names 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$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'san_peer_matching.pem.tmp'; 11$san = 'DNS:example.org, DNS:www.example.org, DNS:test.example.org'; 12 13$serverCode = <<<'CODE' 14 $serverUri = "ssl://127.0.0.1:64321"; 15 $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN; 16 $serverCtx = stream_context_create(['ssl' => [ 17 'local_cert' => '%s', 18 ]]); 19 20 $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx); 21 phpt_notify(); 22 23 @stream_socket_accept($server, 1); 24 @stream_socket_accept($server, 1); 25CODE; 26$serverCode = sprintf($serverCode, $certFile); 27 28$clientCode = <<<'CODE' 29 $serverUri = "ssl://127.0.0.1:64321"; 30 $clientFlags = STREAM_CLIENT_CONNECT; 31 $clientCtx = stream_context_create(['ssl' => [ 32 'verify_peer' => false, 33 ]]); 34 35 phpt_wait(); 36 37 stream_context_set_option($clientCtx, 'ssl', 'peer_name', 'example.org'); 38 var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx)); 39 40 stream_context_set_option($clientCtx, 'ssl', 'peer_name', 'moar.example.org'); 41 var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx)); 42CODE; 43 44include 'CertificateGenerator.inc'; 45$certificateGenerator = new CertificateGenerator(); 46$certificateGenerator->saveNewCertAsFileWithKey(null, $certFile, null, $san); 47 48include 'ServerClientTestCase.inc'; 49ServerClientTestCase::getInstance()->run($clientCode, $serverCode); 50?> 51--CLEAN-- 52<?php 53@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'san_peer_matching.pem.tmp'); 54?> 55--EXPECTF-- 56resource(%d) of type (stream) 57 58Warning: stream_socket_client(): Unable to locate peer certificate CN in %s on line %d 59 60Warning: stream_socket_client(): Failed to enable crypto in %s on line %d 61 62Warning: stream_socket_client(): Unable to connect to ssl://127.0.0.1:64321 (Unknown error) in %s on line %d 63bool(false) 64