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