diff --git a/PhpAmqpLib/Connection/AMQPConnectionConfig.php b/PhpAmqpLib/Connection/AMQPConnectionConfig.php index dade64d8..d0718c5d 100644 --- a/PhpAmqpLib/Connection/AMQPConnectionConfig.php +++ b/PhpAmqpLib/Connection/AMQPConnectionConfig.php @@ -105,8 +105,8 @@ final class AMQPConnectionConfig /** @var string|null */ private $sslKey; - /** @var bool */ - private $sslVerify = true; + /** @var bool|null */ + private $sslVerify; /** @var bool|null */ private $sslVerifyName; @@ -461,12 +461,12 @@ public function setSslKey(?string $sslKey): void $this->sslKey = $sslKey; } - public function getSslVerify(): bool + public function getSslVerify(): ?bool { return $this->sslVerify; } - public function setSslVerify(bool $sslVerify): void + public function setSslVerify(?bool $sslVerify): void { $this->sslVerify = $sslVerify; } diff --git a/PhpAmqpLib/Connection/AMQPSSLConnection.php b/PhpAmqpLib/Connection/AMQPSSLConnection.php index 4a88ffbc..7eb12c3a 100644 --- a/PhpAmqpLib/Connection/AMQPSSLConnection.php +++ b/PhpAmqpLib/Connection/AMQPSSLConnection.php @@ -28,9 +28,10 @@ public function __construct( ?AMQPConnectionConfig $config = null ) { if (empty($ssl_options)) { - $ssl_options = ['verify_peer' => true]; + $ssl_context = null; + } else { + $ssl_context = $this->createSslContext($ssl_options); } - $ssl_context = $this->createSslContext($ssl_options); parent::__construct( $host, $port, diff --git a/PhpAmqpLib/Wire/IO/StreamIO.php b/PhpAmqpLib/Wire/IO/StreamIO.php index 03507a8b..46a5c2ed 100644 --- a/PhpAmqpLib/Wire/IO/StreamIO.php +++ b/PhpAmqpLib/Wire/IO/StreamIO.php @@ -54,7 +54,7 @@ public function __construct( $context = stream_context_create(); } - $this->protocol = $ssl_protocol ?? 'tcp'; + $this->protocol = 'tcp'; $this->host = $host; $this->port = $port; $this->connection_timeout = $connection_timeout; @@ -67,6 +67,15 @@ public function __construct( $this->canDispatchPcntlSignal = $this->isPcntlSignalEnabled(); stream_context_set_option($this->context, 'socket', 'tcp_nodelay', true); + + $options = stream_context_get_options($this->context); + if (!empty($options['ssl'])) { + if (isset($ssl_protocol)) { + $this->protocol = $ssl_protocol; + } else { + $this->protocol = 'ssl'; + } + } } /** diff --git a/tests/Functional/AbstractConnectionTest.php b/tests/Functional/AbstractConnectionTest.php index e9afa955..bfe57a9e 100644 --- a/tests/Functional/AbstractConnectionTest.php +++ b/tests/Functional/AbstractConnectionTest.php @@ -31,7 +31,7 @@ protected function conection_create( $config->setSslCaPath($options['ssl']['capath'] ?? null); $config->setSslCert($options['ssl']['local_cert'] ?? null); $config->setSslKey($options['ssl']['local_pk'] ?? null); - $config->setSslVerify($options['ssl']['verify_peer'] ?? false); + $config->setSslVerify($options['ssl']['verify_peer'] ?? null); $config->setSslVerifyName($options['ssl']['verify_peer_name'] ?? null); $config->setSslPassPhrase($options['ssl']['passphrase'] ?? null); $config->setSslCiphers($options['ssl']['ciphers'] ?? null);