1--TEST--
2TLSv1.1 and TLSv1.2 bitwise stream crypto flag assignment
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_002.pem.tmp';
11$cacertFile = __DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_002-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        'security_level' => 1,
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_002';
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        'security_level' => 1,
40    ]]);
41
42    phpt_wait();
43
44    stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT);
45    var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx));
46
47    stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT);
48    var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx));
49
50    stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT);
51    var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx));
52
53    stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLS_CLIENT);
54    var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx));
55CODE;
56$clientCode = sprintf($clientCode, $cacertFile, $peerName);
57
58include 'CertificateGenerator.inc';
59$certificateGenerator = new CertificateGenerator();
60$certificateGenerator->saveCaCert($cacertFile);
61$certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile);
62
63include 'ServerClientTestCase.inc';
64ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
65?>
66--CLEAN--
67<?php
68@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_002.pem.tmp');
69@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_002-ca.pem.tmp');
70?>
71--EXPECTF--
72resource(%d) of type (stream)
73resource(%d) of type (stream)
74resource(%d) of type (stream)
75resource(%d) of type (stream)
76