Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 76eee28

Browse filesBrowse files
authored
fix: throw exception on stream_socket_enable_crypto() warning (#1158)
1 parent 0ed3ecc commit 76eee28
Copy full SHA for 76eee28

File tree

Expand file treeCollapse file tree

2 files changed

+21
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-7
lines changed
Open diff view settings
Collapse file

‎PhpAmqpLib/Wire/IO/StreamIO.php‎

Copy file name to clipboardExpand all lines: PhpAmqpLib/Wire/IO/StreamIO.php
+21-6Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function connect()
139139

140140
$options = stream_context_get_options($context);
141141
if (isset($options['ssl']['crypto_method'])) {
142-
$this->enable_crypto();
142+
$this->enableCrypto();
143143
}
144144

145145
$this->heartbeat = $this->initial_heartbeat;
@@ -432,16 +432,31 @@ protected function extract_error_code($message)
432432
return 0;
433433
}
434434

435-
private function enable_crypto(): void
435+
/**
436+
* @throws AMQPIOException
437+
*/
438+
private function enableCrypto(): void
436439
{
437440
$timeout_at = time() + ($this->read_timeout + $this->write_timeout) * 2; // 2 round-trips during handshake
438441

439-
do {
440-
$enabled = stream_socket_enable_crypto($this->sock, true);
441-
} while ($enabled !== true && time() < $timeout_at);
442+
try {
443+
$this->setErrorHandler();
444+
do {
445+
$enabled = stream_socket_enable_crypto($this->sock, true);
446+
if ($enabled === true) {
447+
return;
448+
}
449+
$this->throwOnError();
450+
usleep(1e3);
451+
} while ($enabled === 0 && time() < $timeout_at);
452+
} catch (\ErrorException $exception) {
453+
throw new AMQPIOException($exception->getMessage(), $exception->getCode(), $exception);
454+
} finally {
455+
$this->restoreErrorHandler();
456+
}
442457

443458
if ($enabled !== true) {
444-
throw new AMQPIOException('Can not enable crypto');
459+
throw new AMQPIOException('Could not enable socket crypto');
445460
}
446461
}
447462
}
Collapse file

‎tests/Unit/Connection/AMQPConnectionConfigTest.php‎

Copy file name to clipboardExpand all lines: tests/Unit/Connection/AMQPConnectionConfigTest.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public function external_auth_with_user_credentials()
5050
public function secure_with_incorrect_crypto_method()
5151
{
5252
$this->expectException(AMQPIOException::class);
53-
$this->expectExceptionMessage('Can not enable crypto');
5453

5554
$cert_dir = realpath(__DIR__ . "/../../certs");
5655
$config = new AMQPConnectionConfig();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.