1--TEST-- 2Bug #65538: SSL context "cafile" supports phar wrapper 3--EXTENSIONS-- 4openssl 5phar 6--SKIPIF-- 7<?php 8if (!function_exists("proc_open")) die("skip no proc_open"); 9?> 10--INI-- 11phar.readonly=0 12--FILE-- 13<?php 14$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'bug65538_003.pem.tmp'; 15 16$cacertFile = 'bug65538_003-ca.pem'; 17$cacertPhar = __DIR__ . DIRECTORY_SEPARATOR . 'bug65538_003-ca.phar.tmp'; 18 19$serverCode = <<<'CODE' 20 $serverUri = "ssl://127.0.0.1:64321"; 21 $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN; 22 $serverCtx = stream_context_create(['ssl' => [ 23 'local_cert' => '%s', 24 ]]); 25 26 $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx); 27 phpt_notify(); 28 29 $client = @stream_socket_accept($server); 30 if ($client) { 31 $in = ''; 32 while (!preg_match('/\r?\n\r?\n/', $in)) { 33 $in .= fread($client, 2048); 34 } 35 $response = "HTTP/1.0 200 OK\r\n" 36 . "Content-Type: text/plain\r\n" 37 . "Content-Length: 12\r\n" 38 . "Connection: close\r\n" 39 . "\r\n" 40 . "Hello World!"; 41 fwrite($client, $response); 42 fclose($client); 43 } 44CODE; 45$serverCode = sprintf($serverCode, $certFile); 46 47$peerName = 'bug65538_003'; 48$clientCode = <<<'CODE' 49 $serverUri = "https://127.0.0.1:64321/"; 50 $clientCtx = stream_context_create(['ssl' => [ 51 'cafile' => 'phar://%s/%s', 52 'peer_name' => '%s', 53 ]]); 54 55 phpt_wait(); 56 $html = file_get_contents($serverUri, false, $clientCtx); 57 58 var_dump($html); 59CODE; 60$clientCode = sprintf($clientCode, $cacertPhar, $cacertFile, $peerName); 61 62include 'CertificateGenerator.inc'; 63$certificateGenerator = new CertificateGenerator(); 64$certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile); 65 66$phar = new Phar($cacertPhar); 67$phar->addFromString($cacertFile, $certificateGenerator->getCaCert()); 68 69include 'ServerClientTestCase.inc'; 70ServerClientTestCase::getInstance()->run($clientCode, $serverCode); 71?> 72--CLEAN-- 73<?php 74@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'bug65538_003.pem.tmp'); 75@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'bug65538_003-ca.phar.tmp'); 76?> 77--EXPECT-- 78string(12) "Hello World!" 79