1--TEST--
2Testing peer fingerprint on connection
3--SKIPIF--
4<?php
5if (!extension_loaded("openssl")) die("skip openssl not loaded");
6if (!function_exists("proc_open")) die("skip no proc_open");
7--FILE--
8<?php
9$serverCode = <<<'CODE'
10    $serverUri = "ssl://127.0.0.1:64321";
11    $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
12    $serverCtx = stream_context_create(['ssl' => [
13        'local_cert' => __DIR__ . '/bug54992.pem'
14    ]]);
15
16    $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
17    phpt_notify();
18
19    @stream_socket_accept($server, 1);
20    @stream_socket_accept($server, 1);
21CODE;
22
23$clientCode = <<<'CODE'
24    $serverUri = "ssl://127.0.0.1:64321";
25    $clientFlags = STREAM_CLIENT_CONNECT;
26    $clientCtx = stream_context_create(['ssl' => [
27        'verify_peer'       => true,
28        'cafile'            => __DIR__ . '/bug54992-ca.pem',
29        'capture_peer_cert'    => true,
30        'peer_name'          => 'bug54992.local',
31    ]]);
32
33    phpt_wait();
34
35    // should be: 3610606deda596b3ae3859d33c4ce1d9
36    stream_context_set_option($clientCtx, 'ssl', 'peer_fingerprint', '3610606deda596b3ae3859d33c4ce1da');
37    var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx));
38
39    stream_context_set_option($clientCtx, 'ssl', 'peer_fingerprint', [
40        'sha256' => 'dffa72247ab7e44d94b2858528e3f67015925782148d2cf0b15cd82d1c931215',
41    ]);
42    var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx));
43CODE;
44
45include 'ServerClientTestCase.inc';
46ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
47--EXPECTF--
48Warning: stream_socket_client(): peer_fingerprint match failure in %s on line %d
49
50Warning: stream_socket_client(): Failed to enable crypto in %s on line %d
51
52Warning: stream_socket_client(): unable to connect to ssl://127.0.0.1:64321 (Unknown error) in %s on line %d
53bool(false)
54resource(%d) of type (stream)
55