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