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--FILE--
8<?php
9$serverCode = <<<'CODE'
10    $serverUri = "ssl://127.0.0.1:64321";
11    $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
12    $serverCtx = stream_context_create(['ssl' => [
13        'local_cert' => __DIR__ . '/san-cert.pem',
14    ]]);
15
16    $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
17    phpt_notify();
18
19    @stream_socket_accept($server, 1);
20    @stream_socket_accept($server, 1);
21CODE;
22
23$clientCode = <<<'CODE'
24    $serverUri = "ssl://127.0.0.1:64321";
25    $clientFlags = STREAM_CLIENT_CONNECT;
26    $clientCtx = stream_context_create(['ssl' => [
27        'verify_peer' => false,
28        'cafile' => __DIR__ . '/san-ca.pem',
29    ]]);
30
31    phpt_wait();
32
33    stream_context_set_option($clientCtx, 'ssl', 'peer_name', 'example.org');
34    var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
35
36    stream_context_set_option($clientCtx, 'ssl', 'peer_name', 'moar.example.org');
37    var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
38CODE;
39
40include 'ServerClientTestCase.inc';
41ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
42--EXPECTF--
43resource(%d) of type (stream)
44
45Warning: stream_socket_client(): Unable to locate peer certificate CN in %s on line %d
46
47Warning: stream_socket_client(): Failed to enable crypto in %s on line %d
48
49Warning: stream_socket_client(): unable to connect to ssl://127.0.0.1:64321 (Unknown error) in %s on line %d
50bool(false)
51