forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
244 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--TEST-- | ||
Capture SSL session meta array in stream context for TLSv1.3 | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("openssl")) die("skip openssl not loaded"); | ||
if (!function_exists("proc_open")) die("skip no proc_open"); | ||
if (OPENSSL_VERSION_NUMBER < 0x10101000) die("skip OpenSSL v1.1.1 required"); | ||
?> | ||
--FILE-- | ||
<?php | ||
$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'session_meta_capture_tlsv13.pem.tmp'; | ||
$cacertFile = __DIR__ . DIRECTORY_SEPARATOR . 'session_meta_capture_tlsv13-ca.pem.tmp'; | ||
|
||
$serverCode = <<<'CODE' | ||
$serverUri = "ssl://127.0.0.1:64321"; | ||
$serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN; | ||
$serverCtx = stream_context_create(['ssl' => [ | ||
'local_cert' => '%s', | ||
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_SERVER, | ||
]]); | ||
$server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx); | ||
phpt_notify(); | ||
@stream_socket_accept($server, 1); | ||
CODE; | ||
$serverCode = sprintf($serverCode, $certFile); | ||
|
||
$peerName = 'session_meta_capture_tlsv13'; | ||
$clientCode = <<<'CODE' | ||
$serverUri = "ssl://127.0.0.1:64321"; | ||
$clientFlags = STREAM_CLIENT_CONNECT; | ||
$clientCtx = stream_context_create(['ssl' => [ | ||
'verify_peer' => true, | ||
'cafile' => '%s', | ||
'peer_name' => '%s', | ||
'capture_session_meta' => true, | ||
]]); | ||
phpt_wait(); | ||
stream_context_set_option($clientCtx, 'ssl', 'crypto_method', STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT); | ||
@stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx); | ||
$meta = stream_context_get_options($clientCtx)['ssl']['session_meta']; | ||
var_dump($meta['protocol']); | ||
CODE; | ||
$clientCode = sprintf($clientCode, $cacertFile, $peerName); | ||
|
||
include 'CertificateGenerator.inc'; | ||
$certificateGenerator = new CertificateGenerator(); | ||
$certificateGenerator->saveCaCert($cacertFile); | ||
$certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile); | ||
|
||
include 'ServerClientTestCase.inc'; | ||
ServerClientTestCase::getInstance()->run($clientCode, $serverCode); | ||
?> | ||
--EXPECT-- | ||
string(7) "TLSv1.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--TEST-- | ||
tls stream wrapper when TLS 1.3 available | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("openssl")) die("skip openssl not loaded"); | ||
if (!function_exists("proc_open")) die("skip no proc_open"); | ||
if (OPENSSL_VERSION_NUMBER < 0x10101000) die("skip OpenSSL v1.1.1 required"); | ||
?> | ||
--FILE-- | ||
<?php | ||
$serverCode = <<<'CODE' | ||
$flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN; | ||
$ctx = stream_context_create(['ssl' => [ | ||
'local_cert' => __DIR__ . '/streams_crypto_method.pem', | ||
]]); | ||
$server = stream_socket_server('tls://127.0.0.1:64321', $errno, $errstr, $flags, $ctx); | ||
phpt_notify(); | ||
for ($i = 0; $i < (phpt_has_sslv3() ? 7 : 6); $i++) { | ||
@stream_socket_accept($server, 3); | ||
} | ||
CODE; | ||
|
||
$clientCode = <<<'CODE' | ||
$flags = STREAM_CLIENT_CONNECT; | ||
$ctx = stream_context_create(['ssl' => [ | ||
'verify_peer' => false, | ||
'verify_peer_name' => false, | ||
]]); | ||
phpt_wait(); | ||
$client = stream_socket_client("tlsv1.0://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx); | ||
var_dump($client); | ||
$client = @stream_socket_client("sslv3://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx); | ||
var_dump($client); | ||
$client = @stream_socket_client("tlsv1.1://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx); | ||
var_dump($client); | ||
$client = @stream_socket_client("tlsv1.2://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx); | ||
var_dump($client); | ||
$client = @stream_socket_client("tlsv1.3://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx); | ||
var_dump($client); | ||
$client = @stream_socket_client("ssl://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx); | ||
var_dump($client); | ||
$client = @stream_socket_client("tls://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx); | ||
var_dump($client); | ||
CODE; | ||
|
||
include 'ServerClientTestCase.inc'; | ||
ServerClientTestCase::getInstance()->run($clientCode, $serverCode); | ||
?> | ||
--EXPECTF-- | ||
resource(%d) of type (stream) | ||
bool(false) | ||
resource(%d) of type (stream) | ||
resource(%d) of type (stream) | ||
resource(%d) of type (stream) | ||
resource(%d) of type (stream) | ||
resource(%d) of type (stream) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--TEST-- | ||
tlsv1.3 stream wrapper | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("openssl")) die("skip openssl not loaded"); | ||
if (!function_exists("proc_open")) die("skip no proc_open"); | ||
if (OPENSSL_VERSION_NUMBER < 0x10101000) die("skip OpenSSL v1.1.1 required"); | ||
?> | ||
--FILE-- | ||
<?php | ||
$serverCode = <<<'CODE' | ||
$flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN; | ||
$ctx = stream_context_create(['ssl' => [ | ||
'local_cert' => __DIR__ . '/streams_crypto_method.pem', | ||
]]); | ||
$server = stream_socket_server('tlsv1.3://127.0.0.1:64321', $errno, $errstr, $flags, $ctx); | ||
phpt_notify(); | ||
for ($i=0; $i < 3; $i++) { | ||
@stream_socket_accept($server, 3); | ||
} | ||
CODE; | ||
|
||
$clientCode = <<<'CODE' | ||
$flags = STREAM_CLIENT_CONNECT; | ||
$ctx = stream_context_create(['ssl' => [ | ||
'verify_peer' => false, | ||
'verify_peer_name' => false, | ||
]]); | ||
phpt_wait(); | ||
$client = stream_socket_client("tlsv1.3://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx); | ||
var_dump($client); | ||
$client = @stream_socket_client("tlsv1.0://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx); | ||
var_dump($client); | ||
$client = @stream_socket_client("tlsv1.2://127.0.0.1:64321", $errno, $errstr, 3, $flags, $ctx); | ||
var_dump($client); | ||
CODE; | ||
|
||
include 'ServerClientTestCase.inc'; | ||
ServerClientTestCase::getInstance()->run($clientCode, $serverCode); | ||
?> | ||
--EXPECTF-- | ||
resource(%d) of type (stream) | ||
bool(false) | ||
bool(false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters