Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around failing test case detecting EOF on TLS 1.3 socket streams #201

Merged
merged 1 commit into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions tests/FunctionalSecureServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -718,21 +718,4 @@ private function createPromiseForEvent(EventEmitterInterface $emitter, $event, $
});
});
}

private function supportsTls13()
{
// TLS 1.3 is supported as of OpenSSL 1.1.1 (https://www.openssl.org/blog/blog/2018/09/11/release111/)
// The OpenSSL library version can only be obtained by parsing output from phpinfo().
// OPENSSL_VERSION_TEXT refers to header version which does not necessarily match actual library version
// see php -i | grep OpenSSL
// OpenSSL Library Version => OpenSSL 1.1.1 11 Sep 2018
ob_start();
phpinfo(INFO_MODULES);
$info = ob_get_clean();

if (preg_match('/OpenSSL Library Version => OpenSSL (\S+)/', $info, $match)) {
return version_compare($match[1], '1.1.1', '>=');
}
return false;
}
}
17 changes: 17 additions & 0 deletions tests/SecureIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ public function testSendSmallDataToServerReceivesOneChunk()

public function testSendDataWithEndToServerReceivesAllData()
{
// PHP can report EOF on TLS 1.3 stream before consuming all data, so
// we explicitly use older TLS version instead. Selecting TLS version
// requires PHP 5.6+, so skip legacy versions if TLS 1.3 is supported.
// Continue if TLS 1.3 is not supported anyway.
if ($this->supportsTls13()) {
if (!defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
$this->markTestSkipped('TLS 1.3 supported, but this legacy PHP version does not support explicit choice');
}

$this->connector = new SecureConnector(new TcpConnector($this->loop), $this->loop, array(
'verify_peer' => false,
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
));
}

$disconnected = new Deferred();
$this->server->on('connection', function (ConnectionInterface $peer) use ($disconnected) {
$received = '';
Expand All @@ -113,6 +128,7 @@ public function testSendDataWithEndToServerReceivesAllData()
// await server to report connection "close" event
$received = Block\await($disconnected->promise(), $this->loop, self::TIMEOUT);

$this->assertEquals(strlen($data), strlen($received));
$this->assertEquals($data, $received);
}

Expand All @@ -136,6 +152,7 @@ public function testSendDataWithoutEndingToServerReceivesAllData()

$client->close();

$this->assertEquals(strlen($data), strlen($received));
$this->assertEquals($data, $received);
}

Expand Down
17 changes: 17 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,21 @@ public function setExpectedException($exception, $exceptionMessage = '', $except
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
}
}

protected function supportsTls13()
{
// TLS 1.3 is supported as of OpenSSL 1.1.1 (https://www.openssl.org/blog/blog/2018/09/11/release111/)
// The OpenSSL library version can only be obtained by parsing output from phpinfo().
// OPENSSL_VERSION_TEXT refers to header version which does not necessarily match actual library version
// see php -i | grep OpenSSL
// OpenSSL Library Version => OpenSSL 1.1.1 11 Sep 2018
ob_start();
phpinfo(INFO_MODULES);
$info = ob_get_clean();

if (preg_match('/OpenSSL Library Version => OpenSSL ([\d\.]+)/', $info, $match)) {
return version_compare($match[1], '1.1.1', '>=');
}
return false;
}
}