Skip to content

Commit

Permalink
Revert #1060
Browse files Browse the repository at this point in the history
Fixes #1065

Add deprecation error

Add non-TLS SSL test

Only trigger_error in version 8 and higher
  • Loading branch information
lukebakken committed Jan 18, 2023
1 parent c77c4f1 commit c2ef556
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
8 changes: 4 additions & 4 deletions PhpAmqpLib/Connection/AMQPConnectionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions PhpAmqpLib/Connection/AMQPSSLConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ public function __construct(
?AMQPConnectionConfig $config = null
) {
if (empty($ssl_options)) {
$ssl_options = ['verify_peer' => true];
if (version_compare(PHP_VERSION, '8.0.0') >= 0) {
trigger_error('Non-TLS instances of AMQPSSLConnection will be deprecated in version 4.0.0', E_USER_DEPRECATED);
}
$ssl_context = null;
} else {
$ssl_context = $this->createSslContext($ssl_options);
}
$ssl_context = $this->createSslContext($ssl_options);
parent::__construct(
$host,
$port,
Expand Down
11 changes: 10 additions & 1 deletion PhpAmqpLib/Wire/IO/StreamIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/AbstractConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion tests/Functional/Connection/SSLConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class SSLConnectionTest extends AbstractConnectionTest
*/
public function secure_connection_default_params($options)
{
$connection = $this->conection_create('ssl', HOST, 5671, $options);
$port = $options['port'] ?? 5671;
$connection = $this->conection_create('ssl', HOST, $port, $options);
self::assertTrue($connection->isConnected());
$channel = $connection->channel();
self::assertTrue($channel->is_open());
Expand Down Expand Up @@ -71,6 +72,12 @@ public function secure_connection_params()
$options
];

// #4 non-TLS options
$options = ['port' => 5672];
$sets[] = [
$options
];

return $sets;
}
}

0 comments on commit c2ef556

Please sign in to comment.