xref: /PHP-8.3/ext/openssl/tests/bug69215.phpt (revision 74859783)
1--TEST--
2Bug #69215: Crypto servers should send client CA list
3--EXTENSIONS--
4openssl
5--SKIPIF--
6<?php
7if (!function_exists("proc_open")) die("skip no proc_open");
8?>
9--FILE--
10<?php
11$caCertFile = __DIR__ . DIRECTORY_SEPARATOR . 'bug69215-ca.pem.tmp';
12$clientCertFile = __DIR__ . DIRECTORY_SEPARATOR . 'bug69215-client.pem.tmp';
13$serverCertFile = __DIR__ . DIRECTORY_SEPARATOR . 'bug69215-server.pem.tmp';
14
15$serverCode = <<<'CODE'
16    $serverUri = "ssl://127.0.0.1:64321";
17    $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
18    $serverCtx = stream_context_create(['ssl' => [
19        'local_cert' => '%s',
20        'cafile' => '%s',
21        'verify_peer' => true,
22        'verify_peer_name' => true,
23        'peer_name' => 'bug69215-client',
24    ]]);
25
26    $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
27    phpt_notify();
28
29    stream_socket_accept($server, 30);
30CODE;
31$serverCode = sprintf($serverCode, $serverCertFile, $caCertFile);
32
33$clientCode = <<<'CODE'
34    $serverUri = "ssl://127.0.0.1:64321";
35    $clientFlags = STREAM_CLIENT_CONNECT;
36    $clientCtx = stream_context_create(['ssl' => [
37        'local_cert' => '%s',
38        'cafile' => '%s',
39        'verify_peer' => true,
40        'verify_peer_name' => true,
41        'peer_name' => 'bug69215-server',
42    ]]);
43
44    phpt_wait();
45
46    var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
47CODE;
48$clientCode = sprintf($clientCode, $clientCertFile, $caCertFile);
49
50include 'CertificateGenerator.inc';
51$certificateGenerator = new CertificateGenerator();
52$certificateGenerator->saveCaCert($caCertFile);
53$certificateGenerator->saveNewCertAsFileWithKey('bug69215-client', $clientCertFile);
54$certificateGenerator->saveNewCertAsFileWithKey('bug69215-server', $serverCertFile);
55
56include 'ServerClientTestCase.inc';
57ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
58?>
59--CLEAN--
60<?php
61@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'bug69215-ca.pem.tmp');
62@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'bug69215-client.pem.tmp');
63@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'bug69215-server.pem.tmp');
64?>
65--EXPECTF--
66resource(%d) of type (stream)
67