1--TEST--
2IPv6 Peer verification matches SAN names
3--EXTENSIONS--
4openssl
5--SKIPIF--
6<?php
7if (!function_exists("proc_open")) die("skip no proc_open");
8if (getenv("CI_NO_IPV6") || !defined("AF_INET6")) {
9    die('skip no IPv6 support');
10}
11if (@stream_socket_client('udp://[::1]:8888') === false)
12    die('skip no IPv6 support');
13?>
14--FILE--
15<?php
16$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'san_ipv6_peer_matching.pem.tmp';
17$san = 'IP:2001:db8:85a3:8d3:1319:8a2e:370:7348';
18
19$serverCode = <<<'CODE'
20    $serverUri = "ssl://[::1]:64324";
21    $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
22    $serverCtx = stream_context_create(['ssl' => [
23        'local_cert' => '%s',
24    ]]);
25
26    $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
27    phpt_notify();
28
29    @stream_socket_accept($server, 1);
30    @stream_socket_accept($server, 1);
31CODE;
32$serverCode = sprintf($serverCode, $certFile);
33
34$clientCode = <<<'CODE'
35    $serverUri = "ssl://[::1]:64324";
36    $clientFlags = STREAM_CLIENT_CONNECT;
37    $clientCtx = stream_context_create(['ssl' => [
38        'verify_peer' => false,
39    ]]);
40
41    phpt_wait();
42
43    stream_context_set_option($clientCtx, 'ssl', 'peer_name', '2001:db8:85a3:8d3:1319:8a2e:370:7348');
44    var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
45
46    stream_context_set_option($clientCtx, 'ssl', 'peer_name', '2001:db8:85a3:8d3:1319:8a2e:370:7349');
47    var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
48CODE;
49
50include 'CertificateGenerator.inc';
51$certificateGenerator = new CertificateGenerator();
52$certificateGenerator->saveNewCertAsFileWithKey(null, $certFile, null, $san);
53
54include 'ServerClientTestCase.inc';
55ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
56?>
57--CLEAN--
58<?php
59@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'san_ipv6_peer_matching.pem.tmp');
60?>
61--EXPECTF--
62resource(%d) of type (stream)
63
64Warning: stream_socket_client(): Unable to locate peer certificate CN in %s on line %d
65
66Warning: stream_socket_client(): Failed to enable crypto in %s on line %d
67
68Warning: stream_socket_client(): Unable to connect to ssl://[::1]:64324 (Unknown error) in %s on line %d
69bool(false)
70