1--TEST--
2Host name mismatch triggers error
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__ . '/bug54992.pem'
15    ]]);
16
17    $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
18    phpt_notify();
19
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' => true,
28        'cafile' => __DIR__ . '/bug54992-ca.pem'
29    ]]);
30
31    phpt_wait();
32    $client = stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx);
33
34    var_dump($client);
35CODE;
36
37include 'ServerClientTestCase.inc';
38ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
39?>
40--EXPECTF--
41Warning: stream_socket_client(): Peer certificate CN=`bug54992.local' did not match expected CN=`127.0.0.1' in %s on line %d
42
43Warning: stream_socket_client(): Failed to enable crypto in %s on line %d
44
45Warning: stream_socket_client(): unable to connect to ssl://127.0.0.1:64321 (Unknown error) in %s on line %d
46bool(false)
47