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