com php-src: Add tests for Bug #65538: ext/openssl/tests/bug65538.phar ext/openssl/tests/bug65538_001.phpt ext/o penssl/tests/bug65538_002.phpt
ext/openss l/tests/bug65538_003.phpt

From: Date: Sun, 16 Feb 2014 16:20:43 +0000
Subject: com php-src: Add tests for Bug #65538: ext/openssl/tests/bug65538.phar ext/openssl/tests/bug65538_001.phpt ext/o penssl/tests/bug65538_002.phpt
ext/openss l/tests/bug65538_003.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-76123@lists.php.net to get a copy of this message
Commit: 2a83295b14658dfac2f7733c03b941d184521889 Author: Daniel Lowrey <rdlowrey@php.net> Sun, 16 Feb 2014 08:38:39 -0700 Parents: c7220dc6c54f6d3fb57eb5c096f2195749489120 Branches: PHP-5.6 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=2a83295b14658dfac2f7733c03b941d184521889 Log: Add tests for Bug #65538 Bugs: https://bugs.php.net/65538 Changed paths: A ext/openssl/tests/bug65538.phar A ext/openssl/tests/bug65538_001.phpt A ext/openssl/tests/bug65538_002.phpt A ext/openssl/tests/bug65538_003.phpt Diff: diff --git a/ext/openssl/tests/bug65538.phar b/ext/openssl/tests/bug65538.phar new file mode 100644 index 0000000..ae0bd29 Binary files /dev/null and b/ext/openssl/tests/bug65538.phar differ diff --git a/ext/openssl/tests/bug65538_001.phpt b/ext/openssl/tests/bug65538_001.phpt new file mode 100644 index 0000000..45a0203 --- /dev/null +++ b/ext/openssl/tests/bug65538_001.phpt @@ -0,0 +1,51 @@ +--TEST-- +Bug #65538 SSL context "cafile" supports stream wrappers +--SKIPIF-- +<?php +if (!extension_loaded('openssl')) die('skip, openssl required'); +if (!extension_loaded('pcntl')) die('skip, pcntl required'); +?> +--FILE-- +<?php +$serverCtx = stream_context_create(['ssl' => [ + 'local_cert' => __DIR__ . '/bug54992.pem' +]]); +$serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN; +$server = stream_socket_server('ssl://127.0.0.1:64321', $errno, $errstr, $serverFlags, $serverCtx); + +$pid = pcntl_fork(); + +if ($pid == -1) { + die('could not fork'); +} else if ($pid) { + $clientCtx = stream_context_create(['ssl' => [ + 'cafile' => 'file://' . __DIR__ . '/bug54992-ca.pem', + 'CN_match' => 'bug54992.local' + ]]); + $html = file_get_contents('https://127.0.0.1:64321', false, $clientCtx); + var_dump($html); +} else { + @pcntl_wait($status); + + $client = @stream_socket_accept($server); + if ($client) { + $in = ''; + while (!preg_match('/\r?\n\r?\n/', $in)) { + $in .= fread($client, 2048); + } + $response = <<<EOS +HTTP/1.0 200 OK +Content-Type: text/plain +Content-Length: 12 +Connection: close + +Hello World! +EOS; + + fwrite($client, $response); + fclose($client); + } +} +?> +--EXPECTF-- +string(12) "Hello World!" diff --git a/ext/openssl/tests/bug65538_002.phpt b/ext/openssl/tests/bug65538_002.phpt new file mode 100644 index 0000000..05c2f0a --- /dev/null +++ b/ext/openssl/tests/bug65538_002.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #65538 SSL context "cafile" disallows URL stream wrappers +--SKIPIF-- +<?php +if (!extension_loaded('openssl')) die('skip, openssl required'); +if (!extension_loaded('pcntl')) die('skip, pcntl required'); +?> +--FILE-- +<?php +$clientCtx = stream_context_create(['ssl' => [ + 'cafile' => 'http://curl.haxx.se/ca/cacert.pem' +]]); +file_get_contents('https://github.com', false, $clientCtx); +?> +--EXPECTF-- +Warning: remote cafile streams are disabled for security purposes in %s on line %d + +Warning: file_get_contents(): failed to create an SSL handle in %s on line %d + +Warning: file_get_contents(): Failed to enable crypto in %s on line %d + +Warning: file_get_contents(%s): failed to open stream: operation failed in %s on line %d diff --git a/ext/openssl/tests/bug65538_003.phpt b/ext/openssl/tests/bug65538_003.phpt new file mode 100644 index 0000000..c522d02 --- /dev/null +++ b/ext/openssl/tests/bug65538_003.phpt @@ -0,0 +1,52 @@ +--TEST-- +Bug #65538 SSL context "cafile" supports phar wrapper +--SKIPIF-- +<?php +if (!extension_loaded('openssl')) die('skip, openssl required'); +if (!extension_loaded('pcntl')) die('skip, pcntl required'); +if (!extension_loaded('phar')) die('skip, phar required'); +?> +--FILE-- +<?php +$serverCtx = stream_context_create(['ssl' => [ + 'local_cert' => __DIR__ . '/bug54992.pem' +]]); +$serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN; +$server = stream_socket_server('ssl://127.0.0.1:64321', $errno, $errstr, $serverFlags, $serverCtx); + +$pid = pcntl_fork(); + +if ($pid == -1) { + die('could not fork'); +} else if ($pid) { + $clientCtx = stream_context_create(['ssl' => [ + 'cafile' => 'phar://' . __DIR__ . '/bug65538.phar/bug54992-ca.pem', + 'CN_match' => 'bug54992.local' + ]]); + $html = file_get_contents('https://127.0.0.1:64321', false, $clientCtx); + var_dump($html); +} else { + @pcntl_wait($status); + + $client = @stream_socket_accept($server); + if ($client) { + $in = ''; + while (!preg_match('/\r?\n\r?\n/', $in)) { + $in .= fread($client, 2048); + } + $response = <<<EOS +HTTP/1.0 200 OK +Content-Type: text/plain +Content-Length: 12 +Connection: close + +Hello World! +EOS; + + fwrite($client, $response); + fclose($client); + } +} +?> +--EXPECTF-- +string(12) "Hello World!"

« previous php.cvs (#76123) next »