1--TEST--
2Basic bitwise stream crypto context 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_001.pem.tmp';
11$cacertFile = __DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_001-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    ]]);
19
20    $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
21    phpt_notify();
22
23    @stream_socket_accept($server, 1);
24    @stream_socket_accept($server, 1);
25    @stream_socket_accept($server, 1);
26CODE;
27$serverCode = sprintf($serverCode, $certFile);
28
29$peerName = 'stream_crypto_flags_001';
30$clientCode = <<<'CODE'
31    $serverUri = "ssl://127.0.0.1:64321";
32    $clientFlags = STREAM_CLIENT_CONNECT;
33    $clientCtx = stream_context_create(['ssl' => [
34        'verify_peer' => true,
35        'cafile' => '%s',
36        'peer_name' => '%s',
37    ]]);
38
39    phpt_wait();
40
41    stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT);
42    var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
43
44    stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLS_CLIENT);
45    var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx));
46CODE;
47$clientCode = sprintf($clientCode, $cacertFile, $peerName);
48
49include 'CertificateGenerator.inc';
50$certificateGenerator = new CertificateGenerator();
51$certificateGenerator->saveCaCert($cacertFile);
52$certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile);
53
54include 'ServerClientTestCase.inc';
55ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
56?>
57--CLEAN--
58<?php
59@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_001.pem.tmp');
60@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_001-ca.pem.tmp');
61?>
62--EXPECTF--
63resource(%d) of type (stream)
64resource(%d) of type (stream)
65