1--TEST-- 2TLSv1.1 and TLSv1.2 bitwise stream crypto flag assignment 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 . 'stream_crypto_flags_002.pem.tmp'; 11$cacertFile = __DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_002-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 = 'stream_crypto_flags_002'; 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 ]]); 39 40 phpt_wait(); 41 42 stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT); 43 var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx)); 44 45 stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_1_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_2_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_TLS_CLIENT); 52 var_dump(stream_socket_client($serverUri, $errno, $errstr, 2, $clientFlags, $clientCtx)); 53CODE; 54$clientCode = sprintf($clientCode, $cacertFile, $peerName); 55 56include 'CertificateGenerator.inc'; 57$certificateGenerator = new CertificateGenerator(); 58$certificateGenerator->saveCaCert($cacertFile); 59$certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile); 60 61include 'ServerClientTestCase.inc'; 62ServerClientTestCase::getInstance()->run($clientCode, $serverCode); 63?> 64--CLEAN-- 65<?php 66@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_002.pem.tmp'); 67@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'stream_crypto_flags_002-ca.pem.tmp'); 68?> 69--EXPECTF-- 70resource(%d) of type (stream) 71resource(%d) of type (stream) 72resource(%d) of type (stream) 73resource(%d) of type (stream) 74