1--TEST-- 2Capture SSL session meta array in stream context 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$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'session_meta_capture.pem.tmp'; 11$cacertFile = __DIR__ . DIRECTORY_SEPARATOR . 'session_meta_capture-ca.pem.tmp'; 12 13$serverCode = <<<'CODE' 14 $serverUri = "ssl://127.0.0.1:64321"; 15 $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN; 16 $serverCtx = stream_context_create(['ssl' => [ 17 'local_cert' => '%s' 18 ]]); 19 20 $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx); 21 phpt_notify(); 22 23 @stream_socket_accept($server, 1); 24 @stream_socket_accept($server, 1); 25 @stream_socket_accept($server, 1); 26 @stream_socket_accept($server, 1); 27CODE; 28$serverCode = sprintf($serverCode, $certFile); 29 30$peerName = 'session_meta_capture'; 31$clientCode = <<<'CODE' 32 $serverUri = "ssl://127.0.0.1:64321"; 33 $clientFlags = STREAM_CLIENT_CONNECT; 34 $clientCtx = stream_context_create(['ssl' => [ 35 'verify_peer' => true, 36 'cafile' => '%s', 37 'peer_name' => '%s', 38 'capture_session_meta' => true, 39 ]]); 40 41 phpt_wait(); 42 43 stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT); 44 @stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx); 45 $meta = stream_context_get_options($clientCtx)['ssl']['session_meta']; 46 var_dump($meta['protocol']); 47 48 stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT); 49 @stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx); 50 $meta = stream_context_get_options($clientCtx)['ssl']['session_meta']; 51 var_dump($meta['protocol']); 52 53 stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT); 54 @stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx); 55 $meta = stream_context_get_options($clientCtx)['ssl']['session_meta']; 56 var_dump($meta['protocol']); 57CODE; 58$clientCode = sprintf($clientCode, $cacertFile, $peerName); 59 60include 'CertificateGenerator.inc'; 61$certificateGenerator = new CertificateGenerator(); 62$certificateGenerator->saveCaCert($cacertFile); 63$certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile); 64 65include 'ServerClientTestCase.inc'; 66ServerClientTestCase::getInstance()->run($clientCode, $serverCode); 67?> 68--CLEAN-- 69<?php 70@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'session_meta_capture.pem.tmp'); 71@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'session_meta_capture-ca.pem.tmp'); 72?> 73--EXPECT-- 74string(5) "TLSv1" 75string(7) "TLSv1.1" 76string(7) "TLSv1.2" 77