Skip to content

Commit

Permalink
define default ssl context parameter and ensure ssl connection is alw…
Browse files Browse the repository at this point in the history
…ays secure
  • Loading branch information
ramunasd authored and lukebakken committed Jan 13, 2023
1 parent fc04c9f commit 26b4c34
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
8 changes: 4 additions & 4 deletions PhpAmqpLib/Connection/AMQPConnectionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ final class AMQPConnectionConfig
/** @var string|null */
private $sslKey;

/** @var bool|null */
private $sslVerify;
/** @var bool */
private $sslVerify = true;

/** @var bool|null */
private $sslVerifyName;
Expand Down Expand Up @@ -440,12 +440,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
5 changes: 4 additions & 1 deletion PhpAmqpLib/Connection/AMQPSSLConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public function __construct(
$ssl_protocol = 'ssl',
?AMQPConnectionConfig $config = null
) {
$ssl_context = empty($ssl_options) ? null : $this->createSslContext($ssl_options);
if (empty($ssl_options)) {
$ssl_options = ['verify_peer' => true];
}
$ssl_context = $this->createSslContext($ssl_options);
parent::__construct(
$host,
$port,
Expand Down
11 changes: 1 addition & 10 deletions 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 = 'tcp';
$this->protocol = $ssl_protocol ?? 'tcp';
$this->host = $host;
$this->port = $port;
$this->connection_timeout = $connection_timeout;
Expand All @@ -67,15 +67,6 @@ 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'] ?? null);
$config->setSslVerify($options['ssl']['verify_peer'] ?? false);
$config->setSslVerifyName($options['ssl']['verify_peer_name'] ?? null);
$config->setSslPassPhrase($options['ssl']['passphrase'] ?? null);
$config->setSslCiphers($options['ssl']['ciphers'] ?? null);
Expand Down

0 comments on commit 26b4c34

Please sign in to comment.