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