xref: /PHP-8.1/ext/openssl/tests/bug68265.phpt (revision b8731767)
1--TEST--
2Bug #68265: SAN match fails with trailing DNS dot
3--EXTENSIONS--
4openssl
5--SKIPIF--
6<?php
7if (!function_exists("proc_open")) die("skip no proc_open");
8?>
9--FILE--
10<?php
11$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'bug68265.pem.tmp';
12$san = 'DNS:debs.ak-online.be., DNS:debs.ak-online.net.';
13
14$serverCode = <<<'CODE'
15    $serverUri = "ssl://127.0.0.1:0";
16    $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
17    $serverCtx = stream_context_create(['ssl' => [
18        'local_cert' => '%s',
19    ]]);
20
21    $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
22    phpt_notify_server_start($server);
23
24    stream_socket_accept($server, 30);
25CODE;
26$serverCode = sprintf($serverCode, $certFile);
27
28$clientCode = <<<'CODE'
29    $serverUri = "ssl://{{ ADDR }}";
30    $clientFlags = STREAM_CLIENT_CONNECT;
31    $clientCtx = stream_context_create(['ssl' => [
32        'verify_peer' => false,
33        'verify_peer_name' => true,
34        'peer_name' => 'debs.ak-online.net',
35    ]]);
36
37    var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
38CODE;
39
40include 'CertificateGenerator.inc';
41$certificateGenerator = new CertificateGenerator();
42$certificateGenerator->saveNewCertAsFileWithKey('test.com', $certFile, null, $san);
43
44include 'ServerClientTestCase.inc';
45ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
46?>
47--CLEAN--
48<?php
49@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'bug68265.pem.tmp');
50?>
51--EXPECTF--
52resource(%d) of type (stream)
53