1--TEST-- 2TLSv1.1 and TLSv1.2 bitwise stream crypto flag assignment 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 . 'stream_crypto_flags_002.pem.tmp'; 12$cacertFile = __DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_002-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 = 'stream_crypto_flags_002'; 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 var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx)); 47 48 stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT); 49 var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx)); 50 51 stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT); 52 var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx)); 53 54 stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLS_CLIENT); 55 var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx)); 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 . 'stream_crypto_flags_002.pem.tmp'); 70@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_002-ca.pem.tmp'); 71?> 72--EXPECTF-- 73resource(%d) of type (stream) 74resource(%d) of type (stream) 75resource(%d) of type (stream) 76resource(%d) of type (stream) 77