1--TEST-- 2Specific crypto method for ssl:// transports. 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 . 'streams_crypto_method.pem.tmp'; 11 12$serverCode = <<<'CODE' 13 $serverUri = "ssl://127.0.0.1:64321"; 14 $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN; 15 $serverCtx = stream_context_create(['ssl' => [ 16 'local_cert' => '%s', 17 ]]); 18 19 $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx); 20 phpt_notify(); 21 22 $client = @stream_socket_accept($server); 23 if ($client) { 24 $in = ''; 25 while (!preg_match('/\r?\n\r?\n/', $in)) { 26 $in .= fread($client, 2048); 27 } 28 $response = "HTTP/1.0 200 OK\r\n" 29 . "Content-Type: text/plain\r\n" 30 . "Content-Length: 12\r\n" 31 . "Connection: close\r\n" 32 . "\r\n" 33 . "Hello World!"; 34 fwrite($client, $response); 35 fclose($client); 36 } 37CODE; 38$serverCode = sprintf($serverCode, $certFile); 39 40$clientCode = <<<'CODE' 41 $serverUri = "https://127.0.0.1:64321/"; 42 $clientFlags = STREAM_CLIENT_CONNECT; 43 $clientCtx = stream_context_create(['ssl' => [ 44 'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT, 45 'verify_peer' => false, 46 'verify_peer_name' => false 47 ]]); 48 49 phpt_wait(); 50 echo file_get_contents($serverUri, false, $clientCtx); 51CODE; 52 53include 'CertificateGenerator.inc'; 54$certificateGenerator = new CertificateGenerator(); 55$certificateGenerator->saveNewCertAsFileWithKey('streams_crypto_method', $certFile); 56 57include 'ServerClientTestCase.inc'; 58ServerClientTestCase::getInstance()->run($clientCode, $serverCode); 59?> 60--CLEAN-- 61<?php 62@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'streams_crypto_method.pem.tmp'); 63?> 64--EXPECT-- 65Hello World! 66