1--TEST--
2Specific protocol method specification
3--SKIPIF--
4<?php
5if (!extension_loaded("openssl")) die("skip openssl not loaded");
6if (!function_exists("proc_open")) die("skip no proc_open");
7?>
8--FILE--
9<?php
10$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_004.pem.tmp';
11$cacertFile = __DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_004-ca.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        'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_0_SERVER,
19    ]]);
20
21    $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
22    phpt_notify();
23
24    @stream_socket_accept($server, 1);
25    @stream_socket_accept($server, 1);
26    @stream_socket_accept($server, 1);
27    @stream_socket_accept($server, 1);
28CODE;
29$serverCode = sprintf($serverCode, $certFile);
30
31$peerName = 'stream_crypto_flags_004';
32$clientCode = <<<'CODE'
33    $serverUri = "ssl://127.0.0.1:64321";
34    $clientFlags = STREAM_CLIENT_CONNECT;
35    $clientCtx = stream_context_create(['ssl' => [
36        'verify_peer' => true,
37        'cafile' => '%s',
38        'peer_name' => '%s',
39    ]]);
40
41    phpt_wait();
42
43    // Should succeed because the SSLv23 handshake here is compatible with the
44    // TLSv1 hello method employed in the server
45    var_dump(@stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
46
47    // Should fail because the TLSv1.1 hello method is not supported
48    stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT);
49    var_dump(@stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
50
51    // Should fail because the TLSv1.2 hello method is not supported
52    stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT);
53    var_dump(@stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
54
55    // Should succeed because we use the same TLSv1 hello
56    stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT);
57    var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
58CODE;
59$clientCode = sprintf($clientCode, $cacertFile, $peerName);
60
61include 'CertificateGenerator.inc';
62$certificateGenerator = new CertificateGenerator();
63$certificateGenerator->saveCaCert($cacertFile);
64$certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile);
65
66include 'ServerClientTestCase.inc';
67ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
68?>
69--CLEAN--
70<?php
71@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_004.pem.tmp');
72@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_004-ca.pem.tmp');
73?>
74--EXPECTF--
75resource(%d) of type (stream)
76bool(false)
77bool(false)
78resource(%d) of type (stream)
79