1--TEST--
2Specific crypto method for ssl:// transports.
3--EXTENSIONS--
4openssl
5--SKIPIF--
6<?php
7if (!function_exists("proc_open")) die("skip no proc_open");
8?>
9--FILE--
10<?php
11$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'streams_crypto_method.pem.tmp';
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    $client = @stream_socket_accept($server);
24    if ($client) {
25        $in = '';
26        while (!preg_match('/\r?\n\r?\n/', $in)) {
27            $in .= fread($client, 2048);
28        }
29        $response = "HTTP/1.0 200 OK\r\n"
30                  . "Content-Type: text/plain\r\n"
31                  . "Content-Length: 12\r\n"
32                  . "Connection: close\r\n"
33                  . "\r\n"
34                  . "Hello World!";
35        fwrite($client, $response);
36        fclose($client);
37    }
38CODE;
39$serverCode = sprintf($serverCode, $certFile);
40
41$clientCode = <<<'CODE'
42    $serverUri = "https://127.0.0.1:64321/";
43    $clientFlags = STREAM_CLIENT_CONNECT;
44    $clientCtx = stream_context_create(['ssl' => [
45        'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT,
46        'verify_peer' => false,
47        'verify_peer_name' => false
48    ]]);
49
50    phpt_wait();
51    echo file_get_contents($serverUri, false, $clientCtx);
52CODE;
53
54include 'CertificateGenerator.inc';
55$certificateGenerator = new CertificateGenerator();
56$certificateGenerator->saveNewCertAsFileWithKey('streams_crypto_method', $certFile);
57
58include 'ServerClientTestCase.inc';
59ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
60?>
61--CLEAN--
62<?php
63@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'streams_crypto_method.pem.tmp');
64?>
65--EXPECT--
66Hello World!
67