1--TEST--
2Capture SSL session meta array in stream context for TLSv1.3
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 . 'session_meta_capture_tlsv13.pem.tmp';
12$cacertFile = __DIR__ . DIRECTORY_SEPARATOR . 'session_meta_capture_tlsv13-ca.pem.tmp';
13
14$serverCode = <<<'CODE'
15    $serverUri = "ssl://127.0.0.1:64321";
16    $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN;
17    $serverCtx = stream_context_create(['ssl' => [
18        'local_cert' => '%s',
19        'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_SERVER,
20    ]]);
21
22    $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx);
23    phpt_notify();
24
25    @stream_socket_accept($server, 1);
26CODE;
27$serverCode = sprintf($serverCode, $certFile);
28
29$peerName = 'session_meta_capture_tlsv13';
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_3_CLIENT);
42    $stream = stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx);
43    var_dump(stream_get_meta_data($stream)['crypto']['protocol']);
44CODE;
45$clientCode = sprintf($clientCode, $cacertFile, $peerName);
46
47include 'CertificateGenerator.inc';
48$certificateGenerator = new CertificateGenerator();
49$certificateGenerator->saveCaCert($cacertFile);
50$certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile);
51
52include 'ServerClientTestCase.inc';
53ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
54?>
55--EXPECT--
56string(7) "TLSv1.3"
57