xref: /PHP-8.1/ext/openssl/tests/tls_wrapper.phpt (revision 3ea57cf8)
1--TEST--
2tls stream wrapper
3--EXTENSIONS--
4openssl
5--SKIPIF--
6<?php
7if (!function_exists("proc_open")) die("skip no proc_open");
8if (OPENSSL_VERSION_NUMBER < 0x10101000) die("skip OpenSSL v1.1.1 required");
9?>
10--FILE--
11<?php
12$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'tls_wrapper.pem.tmp';
13
14$serverCode = <<<'CODE'
15    $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN;
16    $ctx = stream_context_create(['ssl' => [
17        'local_cert' => '%s',
18        'security_level' => 0,
19    ]]);
20
21    $server = stream_socket_server('tls://127.0.0.1:64321', $errno, $errstr, $flags, $ctx);
22    phpt_notify();
23
24    for ($i = 0; $i < (phpt_has_sslv3() ? 6 : 5); $i++) {
25        @stream_socket_accept($server, 3);
26    }
27CODE;
28$serverCode = sprintf($serverCode, $certFile);
29
30$clientCode = <<<'CODE'
31    $flags = STREAM_CLIENT_CONNECT;
32    $ctx = stream_context_create(['ssl' => [
33        'verify_peer' => false,
34        'verify_peer_name' => false,
35        'security_level' => 0,
36    ]]);
37
38    phpt_wait();
39
40    $client = stream_socket_client("tlsv1.0://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx);
41    var_dump($client);
42
43    $client = @stream_socket_client("sslv3://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx);
44    var_dump($client);
45
46    $client = @stream_socket_client("tlsv1.1://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx);
47    var_dump($client);
48
49    $client = @stream_socket_client("tlsv1.2://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx);
50    var_dump($client);
51
52    $client = @stream_socket_client("ssl://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx);
53    var_dump($client);
54
55    $client = @stream_socket_client("tls://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx);
56    var_dump($client);
57CODE;
58
59include 'CertificateGenerator.inc';
60$certificateGenerator = new CertificateGenerator();
61$certificateGenerator->saveNewCertAsFileWithKey('tls_wrapper', $certFile);
62
63include 'ServerClientTestCase.inc';
64ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
65?>
66--CLEAN--
67<?php
68@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'tls_wrapper.pem.tmp');
69?>
70--EXPECTF--
71resource(%d) of type (stream)
72bool(false)
73resource(%d) of type (stream)
74resource(%d) of type (stream)
75resource(%d) of type (stream)
76resource(%d) of type (stream)
77