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