xref: /PHP-7.0/ext/openssl/tests/bug54992.phpt (revision 020e1619)
1--TEST--
2Bug #54992: Stream not closed and error not returned when SSL CN_match fails
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__ . '/bug54992.pem',
14    ]]);
15
16    $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
17    phpt_notify();
18
19    @stream_socket_accept($server, 1);
20CODE;
21
22$clientCode = <<<'CODE'
23    $serverUri = "ssl://127.0.0.1:64321";
24    $clientFlags = STREAM_CLIENT_CONNECT;
25    $clientCtx = stream_context_create(['ssl' => [
26        'verify_peer' => true,
27        'cafile' => __DIR__ . '/bug54992-ca.pem',
28        'peer_name' => 'buga_buga',
29    ]]);
30
31    phpt_wait();
32    $client = stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx);
33
34    var_dump($client);
35CODE;
36
37include 'ServerClientTestCase.inc';
38ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
39--EXPECTF--
40Warning: stream_socket_client(): Peer certificate CN=`bug54992.local' did not match expected CN=`buga_buga' in %s on line %d
41
42Warning: stream_socket_client(): Failed to enable crypto in %s on line %d
43
44Warning: stream_socket_client(): unable to connect to ssl://127.0.0.1:64321 (Unknown error) in %s on line %d
45bool(false)
46
47
48