Skip to content
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
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ matrix:
- php: hhvm-nightly
fast_finish: true

before_script:
- composer install --dev --prefer-source
sudo: false

install:
- composer install

script:
- phpunit --coverage-text
22 changes: 17 additions & 5 deletions src/SecureConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,26 @@ public function __construct(ConnectorInterface $connector, LoopInterface $loop)

public function create($host, $port)
{
return $this->connector->create($host, $port)->then(function (Stream $stream) use ($host) {
$context = array(
'SNI_enabled' => true,
'peer_name' => $host
);

// legacy PHP < 5.6 ignores peer_name and requires legacy context options instead
if (PHP_VERSION_ID < 50600) {
$context += array(
'SNI_server_name' => $host,
'CN_match' => $host
);
}

return $this->connector->create($host, $port)->then(function (Stream $stream) use ($context) {
// (unencrypted) TCP/IP connection succeeded

// set required SSL/TLS context options
$resource = $stream->stream;
stream_context_set_option($resource, 'ssl', 'SNI_enabled', true);
stream_context_set_option($resource, 'ssl', 'SNI_server_name', $host);
stream_context_set_option($resource, 'ssl', 'peer_name', $host);
foreach ($context as $name => $value) {
stream_context_set_option($stream->stream, 'ssl', $name, $value);
}

// try to enable encryption
return $this->streamEncryption->enable($stream)->then(null, function ($error) use ($stream) {
Expand Down