1--TEST-- 2Specific protocol method specification 3--SKIPIF-- 4<?php 5if (!extension_loaded("openssl")) die("skip openssl not loaded"); 6if (!function_exists("proc_open")) die("skip no proc_open"); 7--FILE-- 8<?php 9$serverCode = <<<'CODE' 10 $serverUri = "ssl://127.0.0.1:64321"; 11 $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN; 12 $serverCtx = stream_context_create(['ssl' => [ 13 'local_cert' => __DIR__ . '/bug54992.pem', 14 'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_0_SERVER, 15 ]]); 16 17 $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx); 18 phpt_notify(); 19 20 @stream_socket_accept($server, 1); 21 @stream_socket_accept($server, 1); 22 @stream_socket_accept($server, 1); 23 @stream_socket_accept($server, 1); 24CODE; 25 26$clientCode = <<<'CODE' 27 $serverUri = "ssl://127.0.0.1:64321"; 28 $clientFlags = STREAM_CLIENT_CONNECT; 29 $clientCtx = stream_context_create(['ssl' => [ 30 'verify_peer' => true, 31 'cafile' => __DIR__ . '/bug54992-ca.pem', 32 'peer_name' => 'bug54992.local', 33 ]]); 34 35 phpt_wait(); 36 37 // Should succeed because the SSLv23 handshake here is compatible with the 38 // TLSv1 hello method employed in the server 39 var_dump(@stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx)); 40 41 // Should fail because the TLSv1.1 hello method is not supported 42 stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT); 43 var_dump(@stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx)); 44 45 // Should fail because the TLSv1.2 hello method is not supported 46 stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT); 47 var_dump(@stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx)); 48 49 // Should succeed because we use the same TLSv1 hello 50 stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT); 51 var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx)); 52CODE; 53 54include 'ServerClientTestCase.inc'; 55ServerClientTestCase::getInstance()->run($clientCode, $serverCode); 56--EXPECTF-- 57resource(%d) of type (stream) 58bool(false) 59bool(false) 60resource(%d) of type (stream) 61