|
| 1 | +--TEST-- |
| 2 | +Specific crypto method for ssl:// transports. |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +if (!extension_loaded('openssl')) die('skip, openssl required'); |
| 6 | +if (!extension_loaded('pcntl')) die('skip, pcntl required'); |
| 7 | +?> |
| 8 | +--FILE-- |
| 9 | +<?php |
| 10 | +function client($port, $method) { |
| 11 | + $ctx = stream_context_create(); |
| 12 | + stream_context_set_option($ctx, 'ssl', 'crypto_method', $method); |
| 13 | + |
| 14 | + $fp = @fopen('https://127.0.0.1:' . $port . '/', 'r', false, $ctx); |
| 15 | + if ($fp) { |
| 16 | + fpassthru($fp); |
| 17 | + fclose($fp); |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +function server($port, $transport) { |
| 22 | + $context = stream_context_create(); |
| 23 | + |
| 24 | + stream_context_set_option($context, 'ssl', 'local_cert', dirname(__FILE__) . '/streams_crypto_method.pem'); |
| 25 | + stream_context_set_option($context, 'ssl', 'allow_self_signed', true); |
| 26 | + stream_context_set_option($context, 'ssl', 'verify_peer', false); |
| 27 | + |
| 28 | + $server = stream_socket_server($transport . '127.0.0.1:' . $port, $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN, $context); |
| 29 | + |
| 30 | + $client = @stream_socket_accept($server); |
| 31 | + |
| 32 | + if ($client) { |
| 33 | + $in = ''; |
| 34 | + while (!preg_match('/\r?\n\r?\n/', $in)) { |
| 35 | + $in .= fread($client, 2048); |
| 36 | + } |
| 37 | + |
| 38 | + $response = <<<EOS |
| 39 | +HTTP/1.1 200 OK |
| 40 | +Content-Type: text/plain |
| 41 | +Content-Length: 13 |
| 42 | +Connection: close |
| 43 | +
|
| 44 | +Hello World! |
| 45 | +
|
| 46 | +EOS; |
| 47 | + |
| 48 | + fwrite($client, $response); |
| 49 | + fclose($client); |
| 50 | + exit(); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +$port1 = rand(15000, 16000); |
| 55 | +$port2 = rand(16001, 17000); |
| 56 | + |
| 57 | +$pid1 = pcntl_fork(); |
| 58 | +$pid2 = pcntl_fork(); |
| 59 | + |
| 60 | +if ($pid1 == 0 && $pid2 != 0) { |
| 61 | + server($port1, 'sslv3://'); |
| 62 | + exit; |
| 63 | +} |
| 64 | + |
| 65 | +if ($pid1 != 0 && $pid2 == 0) { |
| 66 | + server($port2, 'sslv3://'); |
| 67 | + exit; |
| 68 | +} |
| 69 | + |
| 70 | +client($port1, STREAM_CRYPTO_METHOD_SSLv3_CLIENT); |
| 71 | +client($port2, STREAM_CRYPTO_METHOD_SSLv2_CLIENT); |
| 72 | + |
| 73 | +pcntl_waitpid($pid1, $status); |
| 74 | +pcntl_waitpid($pid2, $status); |
| 75 | +?> |
| 76 | +--EXPECTF-- |
| 77 | +Hello World! |
0 commit comments