xref: /PHP-5.6/ext/openssl/tests/bug65729.phpt (revision 020e1619)
1--TEST--
2Bug #65729: CN_match gives false positive when wildcard is used
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__ . '/bug65729.pem'
14    ]]);
15
16    $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
17    phpt_notify();
18
19    $expected_names = ['foo.test.com.sg', 'foo.test.com', 'FOO.TEST.COM', 'foo.bar.test.com'];
20    foreach ($expected_names as $name) {
21        @stream_socket_accept($server, 1);
22    }
23CODE;
24
25$clientCode = <<<'CODE'
26    $serverUri = "ssl://127.0.0.1:64321";
27    $clientFlags = STREAM_CLIENT_CONNECT;
28
29    phpt_wait();
30
31    $expected_names = ['foo.test.com.sg', 'foo.test.com', 'FOO.TEST.COM', 'foo.bar.test.com'];
32    foreach ($expected_names as $expected_name) {
33        $clientCtx = stream_context_create(['ssl' => [
34            'verify_peer'       => true,
35            'allow_self_signed'    => true,
36            'peer_name'          => $expected_name,
37        ]]);
38
39        var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx));
40    }
41CODE;
42
43include 'ServerClientTestCase.inc';
44ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
45--EXPECTF--
46Warning: stream_socket_client(): Peer certificate CN=`*.test.com' did not match expected CN=`foo.test.com.sg' in %s on line %d
47
48Warning: stream_socket_client(): Failed to enable crypto in %s on line %d
49
50Warning: stream_socket_client(): unable to connect to ssl://127.0.0.1:64321 (Unknown error) in %s on line %d
51bool(false)
52resource(%d) of type (stream)
53resource(%d) of type (stream)
54
55Warning: stream_socket_client(): Peer certificate CN=`*.test.com' did not match expected CN=`foo.bar.test.com' in %s on line %d
56
57Warning: stream_socket_client(): Failed to enable crypto in %s on line %d
58
59Warning: stream_socket_client(): unable to connect to ssl://127.0.0.1:64321 (Unknown error) in %s on line %d
60bool(false)
61