xref: /PHP-8.2/ext/openssl/tests/bug76705.phpt (revision 74859783)
1--TEST--
2Bug #76705: unusable ssl => peer_fingerprint in stream_context_create()
3--EXTENSIONS--
4openssl
5--SKIPIF--
6<?php
7if (!function_exists("proc_open")) die("skip no proc_open");
8?>
9--FILE--
10<?php
11$serverCode = <<<'CODE'
12    $serverUri = "ssl://127.0.0.1:64323";
13    $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
14    $serverCtx = stream_context_create(['ssl' => [
15        'local_cert' => __DIR__ . '/bug76705.pem'
16    ]]);
17
18    $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
19    phpt_notify();
20
21    @stream_socket_accept($server, 1);
22CODE;
23
24$clientCode = <<<'CODE'
25    $serverUri = "ssl://127.0.0.1:64323";
26    $clientFlags = STREAM_CLIENT_CONNECT;
27    $clientCtx = stream_context_create(['ssl' => [
28        'verify_peer'       => true,
29        'peer_name'         => 'openssl.php.net',
30        'allow_self_signed' => true,
31        'peer_fingerprint'  => [
32            'sha256' => '4A524F3617E41BCCA1370ED9E89C9A7A83C28F0F342C490296D362869BDF1DA8',
33        ]
34    ]]);
35
36    phpt_wait();
37    var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx));
38CODE;
39
40include 'ServerClientTestCase.inc';
41ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
42?>
43--EXPECTF--
44resource(%d) of type (stream)
45