1--TEST--
2Capture SSL session meta array in stream context for TLSv1.3
3--SKIPIF--
4<?php
5if (!extension_loaded("openssl")) die("skip openssl not loaded");
6if (!function_exists("proc_open")) die("skip no proc_open");
7if (OPENSSL_VERSION_NUMBER < 0x10101000) die("skip OpenSSL v1.1.1 required");
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        'capture_session_meta' => true,
38    ]]);
39
40    phpt_wait();
41
42    stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT);
43    @stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx);
44    $meta = stream_context_get_options($clientCtx)['ssl']['session_meta'];
45    var_dump($meta['protocol']);
46CODE;
47$clientCode = sprintf($clientCode, $cacertFile, $peerName);
48
49include 'CertificateGenerator.inc';
50$certificateGenerator = new CertificateGenerator();
51$certificateGenerator->saveCaCert($cacertFile);
52$certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile);
53
54include 'ServerClientTestCase.inc';
55ServerClientTestCase::getInstance()->run($clientCode, $serverCode);
56?>
57--EXPECT--
58string(7) "TLSv1.3"
59