|
| 1 | +--TEST-- |
| 2 | +TLSv1.1 and TLSv1.2 bitwise stream crypto flag assignment |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +if (!extension_loaded("openssl")) die("skip"); |
| 6 | +if (!function_exists('pcntl_fork')) die("skip no fork"); |
| 7 | +if (OPENSSL_VERSION_NUMBER < 0x10001001) die("skip OpenSSLv1.0.1 required"); |
| 8 | +--FILE-- |
| 9 | +<?php |
| 10 | +$flags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN; |
| 11 | +$ctx = stream_context_create(['ssl' => [ |
| 12 | + 'local_cert' => __DIR__ . '/bug54992.pem', |
| 13 | + 'allow_self_signed' => true |
| 14 | +]]); |
| 15 | +$server = stream_socket_server('ssl://127.0.0.1:64321', $errno, $errstr, $flags, $ctx); |
| 16 | +var_dump($server); |
| 17 | + |
| 18 | +$pid = pcntl_fork(); |
| 19 | +if ($pid == -1) { |
| 20 | + die('could not fork'); |
| 21 | +} else if ($pid) { |
| 22 | + |
| 23 | + // Base SSL context values |
| 24 | + $sslCtxVars = array( |
| 25 | + 'verify_peer' => TRUE, |
| 26 | + 'cafile' => __DIR__ . '/bug54992-ca.pem', |
| 27 | + 'CN_match' => 'bug54992.local', // common name from the server's "local_cert" PEM file |
| 28 | + ); |
| 29 | + |
| 30 | + // TLSv1 |
| 31 | + $ctxCopy = $sslCtxVars; |
| 32 | + $ctxCopy['crypto_method'] = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT; |
| 33 | + $ctx = stream_context_create(array('ssl' => $ctxCopy)); |
| 34 | + var_dump(stream_socket_client("ssl://127.0.0.1:64321", $errno, $errstr, 1, STREAM_CLIENT_CONNECT, $ctx)); |
| 35 | + |
| 36 | + // TLSv1.1 |
| 37 | + $ctxCopy = $sslCtxVars; |
| 38 | + $ctxCopy['crypto_method'] = STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT; |
| 39 | + $ctx = stream_context_create(array('ssl' => $ctxCopy)); |
| 40 | + var_dump(stream_socket_client("ssl://127.0.0.1:64321", $errno, $errstr, 1, STREAM_CLIENT_CONNECT, $ctx)); |
| 41 | + |
| 42 | + // TLSv1.2 |
| 43 | + $ctxCopy = $sslCtxVars; |
| 44 | + $ctxCopy['crypto_method'] = STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; |
| 45 | + $ctx = stream_context_create(array('ssl' => $ctxCopy)); |
| 46 | + var_dump(stream_socket_client("ssl://127.0.0.1:64321", $errno, $errstr, 1, STREAM_CLIENT_CONNECT, $ctx)); |
| 47 | + |
| 48 | + // TLS (any) |
| 49 | + $ctxCopy = $sslCtxVars; |
| 50 | + $ctxCopy['crypto_method'] = STREAM_CRYPTO_METHOD_TLS_CLIENT; |
| 51 | + $ctx = stream_context_create(array('ssl' => $ctxCopy)); |
| 52 | + var_dump(stream_socket_client("ssl://127.0.0.1:64321", $errno, $errstr, 1, STREAM_CLIENT_CONNECT, $ctx)); |
| 53 | + |
| 54 | +} else { |
| 55 | + @pcntl_wait($status); |
| 56 | + @stream_socket_accept($server, 1); |
| 57 | + @stream_socket_accept($server, 1); |
| 58 | + @stream_socket_accept($server, 1); |
| 59 | + @stream_socket_accept($server, 1); |
| 60 | +} |
| 61 | +--EXPECTF-- |
| 62 | +resource(%d) of type (stream) |
| 63 | +resource(%d) of type (stream) |
| 64 | +resource(%d) of type (stream) |
| 65 | +resource(%d) of type (stream) |
| 66 | +resource(%d) of type (stream) |
| 67 | + |
0 commit comments