Skip to content

Commit

Permalink
Improve TLS server error messages when incoming connection fails
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Sep 27, 2018
1 parent 003aa6c commit 4e2d23f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/SecureServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ function ($conn) use ($that) {
$that->emit('connection', array($conn));
},
function ($error) use ($that, $connection) {
$error = new \RuntimeException(
'Connection from ' . $connection->getRemoteAddress() . ' failed during TLS handshake: ' . $error->getMessage(),
$error->getCode(),
$error
);

$that->emit('error', array($error));
$connection->end();
}
Expand Down
8 changes: 6 additions & 2 deletions tests/FunctionalSecureServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,10 @@ public function testEmitsErrorIfConnectionIsClosedBeforeHandshake()

$error = Block\await($errorEvent, $loop, self::TIMEOUT);

// Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshak
$this->assertTrue($error instanceof \RuntimeException);
$this->assertEquals('Connection lost during TLS handshake', $error->getMessage());
$this->assertStringStartsWith('Connection from tcp://', $error->getMessage());
$this->assertStringEndsWith('failed during TLS handshake: Connection lost during TLS handshake', $error->getMessage());
$this->assertEquals(defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 0, $error->getCode());
}

Expand All @@ -445,8 +447,10 @@ public function testEmitsErrorIfConnectionIsClosedWithIncompleteHandshake()

$error = Block\await($errorEvent, $loop, self::TIMEOUT);

// Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshak
$this->assertTrue($error instanceof \RuntimeException);
$this->assertEquals('Connection lost during TLS handshake', $error->getMessage());
$this->assertStringStartsWith('Connection from tcp://', $error->getMessage());
$this->assertStringEndsWith('failed during TLS handshake: Connection lost during TLS handshake', $error->getMessage());
$this->assertEquals(defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 0, $error->getCode());
}

Expand Down

0 comments on commit 4e2d23f

Please sign in to comment.