xref: /PHP-7.2/ext/openssl/tests/tls_wrapper.phpt (revision 769d2d9b)
1--TEST--
2tls stream wrapper
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$serverCode = <<<'CODE'
11    $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN;
12    $ctx = stream_context_create(['ssl' => [
13        'local_cert' => __DIR__ . '/streams_crypto_method.pem',
14    ]]);
15
16    $server = stream_socket_server('tls://127.0.0.1:64321', $errno, $errstr, $flags, $ctx);
17    phpt_notify();
18
19    for ($i = 0; $i < (phpt_has_sslv3() ? 6 : 5); $i++) {
20        @stream_socket_accept($server, 3);
21    }
22CODE;
23
24$clientCode = <<<'CODE'
25    $flags = STREAM_CLIENT_CONNECT;
26    $ctx = stream_context_create(['ssl' => [
27        'verify_peer' => false,
28        'verify_peer_name' => false,
29    ]]);
30
31    phpt_wait();
32
33    $client = stream_socket_client("tlsv1.0://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx);
34    var_dump($client);
35
36    $client = @stream_socket_client("sslv3://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx);
37    var_dump($client);
38
39    $client = @stream_socket_client("tlsv1.1://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx);
40    var_dump($client);
41
42    $client = @stream_socket_client("tlsv1.2://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx);
43    var_dump($client);
44
45    $client = @stream_socket_client("ssl://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx);
46    var_dump($client);
47
48    $client = @stream_socket_client("tls://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx);
49    var_dump($client);
50CODE;
51
52include 'ServerClientTestCase.inc';
53ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
54?>
55--EXPECTF--
56resource(%d) of type (stream)
57bool(false)
58resource(%d) of type (stream)
59resource(%d) of type (stream)
60resource(%d) of type (stream)
61resource(%d) of type (stream)
62