1--TEST-- 2Peer verification enabled for client streams 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 . 'peer_verification.pem.tmp'; 12$cacertFile = __DIR__ . DIRECTORY_SEPARATOR . 'peer_verification-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 for ($i = 0; $i < 5; $i++) { 25 @stream_socket_accept($server, 1); 26 } 27CODE; 28$serverCode = sprintf($serverCode, $certFile); 29 30$peerName = 'peer_verification'; 31$clientCode = <<<'CODE' 32 $serverUri = "ssl://127.0.0.1:64321"; 33 $clientFlags = STREAM_CLIENT_CONNECT; 34 $caFile = '%s'; 35 36 phpt_wait(); 37 38 // Expected to fail -- untrusted server cert and no CA File present 39 var_dump(@stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags)); 40 41 // Expected to fail -- untrusted server cert and no CA File present 42 $clientCtx = stream_context_create(['ssl' => [ 43 'verify_peer' => true, 44 ]]); 45 var_dump(@stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx)); 46 47 // Should succeed with peer verification disabled in context 48 $clientCtx = stream_context_create(['ssl' => [ 49 'verify_peer' => false, 50 'verify_peer_name' => false, 51 ]]); 52 var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx)); 53 54 // Should succeed with CA file specified in context 55 $clientCtx = stream_context_create(['ssl' => [ 56 'cafile' => $caFile, 57 'peer_name' => '%s', 58 ]]); 59 var_dump(stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx)); 60CODE; 61$clientCode = sprintf($clientCode, $cacertFile, $peerName); 62 63include 'CertificateGenerator.inc'; 64$certificateGenerator = new CertificateGenerator(); 65$certificateGenerator->saveCaCert($cacertFile); 66$certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile); 67 68include 'ServerClientTestCase.inc'; 69ServerClientTestCase::getInstance()->run($clientCode, $serverCode); 70?> 71--CLEAN-- 72<?php 73@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'peer_verification.pem.tmp'); 74@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'peer_verification-ca.pem.tmp'); 75?> 76--EXPECTF-- 77bool(false) 78bool(false) 79resource(%d) of type (stream) 80resource(%d) of type (stream) 81