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