xref: /PHP-7.0/ext/openssl/tests/bug65538_001.phpt (revision d0a6f8c6)
1--TEST--
2Bug #65538: SSL context "cafile" supports stream wrappers
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    $client = @stream_socket_accept($server);
20    if ($client) {
21        $in = '';
22        while (!preg_match('/\r?\n\r?\n/', $in)) {
23            $in .= fread($client, 2048);
24        }
25        $response = "HTTP/1.0 200 OK\r\n"
26                  . "Content-Type: text/plain\r\n"
27                  . "Content-Length: 12\r\n"
28                  . "Connection: close\r\n"
29                  . "\r\n"
30                  . "Hello World!";
31        fwrite($client, $response);
32        fclose($client);
33    }
34CODE;
35
36$clientCode = <<<'CODE'
37    $serverUri = "https://127.0.0.1:64321/";
38    $clientCtx = stream_context_create(['ssl' => [
39        'cafile' => 'file://' . __DIR__ . '/bug54992-ca.pem',
40        'peer_name' => 'bug54992.local',
41    ]]);
42
43    phpt_wait();
44    $html = file_get_contents($serverUri, false, $clientCtx);
45
46    var_dump($html);
47CODE;
48
49include 'ServerClientTestCase.inc';
50ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
51--EXPECT--
52string(12) "Hello World!"
53