1--TEST-- 2Bug #65538: SSL context "cafile" supports stream wrappers 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 . 'bug65538_001.pem.tmp'; 12$cacertFile = __DIR__ . DIRECTORY_SEPARATOR . 'bug65538_001-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 ]]); 20 21 $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx); 22 phpt_notify(); 23 24 $client = @stream_socket_accept($server); 25 if ($client) { 26 $in = ''; 27 while (!preg_match('/\r?\n\r?\n/', $in)) { 28 $in .= fread($client, 2048); 29 } 30 $response = "HTTP/1.0 200 OK\r\n" 31 . "Content-Type: text/plain\r\n" 32 . "Content-Length: 12\r\n" 33 . "Connection: close\r\n" 34 . "\r\n" 35 . "Hello World!"; 36 fwrite($client, $response); 37 fclose($client); 38 } 39CODE; 40$serverCode = sprintf($serverCode, $certFile); 41 42$peerName = 'bug65538_001'; 43$clientCode = <<<'CODE' 44 $serverUri = "https://127.0.0.1:64321/"; 45 $clientCtx = stream_context_create(['ssl' => [ 46 'cafile' => 'file://%s', 47 'peer_name' => '%s', 48 ]]); 49 50 phpt_wait(); 51 $html = file_get_contents($serverUri, false, $clientCtx); 52 53 var_dump($html); 54CODE; 55$clientCode = sprintf($clientCode, $cacertFile, $peerName); 56 57include 'CertificateGenerator.inc'; 58$certificateGenerator = new CertificateGenerator(); 59$certificateGenerator->saveCaCert($cacertFile); 60$certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile); 61 62include 'ServerClientTestCase.inc'; 63ServerClientTestCase::getInstance()->run($clientCode, $serverCode); 64?> 65--CLEAN-- 66<?php 67@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'bug65538_001.pem.tmp'); 68@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'bug65538_001-ca.pem.tmp'); 69?> 70--EXPECT-- 71string(12) "Hello World!" 72