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