Skip to content

Amqp add ssl pass phrase option #249

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Merged
merged 4 commits into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions pkg/amqp-lib/AmqpConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,22 @@ private function establishConnection()
if (false == $this->connection) {
if ($this->config->getOption('stream')) {
if ($this->config->isSslOn()) {
$sslOptions = array_filter([
'cafile' => $this->config->getSslCaCert(),
'local_cert' => $this->config->getSslCert(),
'local_pk' => $this->config->getSslKey(),
'verify_peer' => $this->config->isSslVerify(),
'verify_peer_name' => $this->config->isSslVerify(),
'passphrase' => $this->getConfig()->getSslPassPhrase(),
], function ($value) { return '' !== $value; });

$con = new AMQPSSLConnection(
$this->config->getHost(),
$this->config->getPort(),
$this->config->getUser(),
$this->config->getPass(),
$this->config->getVHost(),
[
'cafile' => $this->config->getSslCaCert(),
'local_cert' => $this->config->getSslCert(),
'local_pk' => $this->config->getSslKey(),
'verify_peer' => $this->config->isSslVerify(),
'verify_peer_name' => $this->config->isSslVerify(),
],
$sslOptions,
[
'insist' => $this->config->getOption('insist'),
'login_method' => $this->config->getOption('login_method'),
Expand Down
25 changes: 18 additions & 7 deletions pkg/amqp-tools/ConnectionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* ssl_cacert - Location of Certificate Authority file on local filesystem which should be used with the verify_peer context option to authenticate the identity of the remote peer. A string.
* ssl_cert - Path to local certificate file on filesystem. It must be a PEM encoded file which contains your certificate and private key. A string
* ssl_key - Path to local private key file on filesystem in case of separate files for certificate (local_cert) and private key. A string.
* ssl_passphrase - Passphrase with which your local_cert file was encoded. A string
*
* 2. null - in this case it tries to connect to localhost with default settings
* 3. amqp: same as 2.
Expand Down Expand Up @@ -81,9 +82,10 @@ public function __construct($config = null)
'qos_prefetch_count' => 1,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
];

$this->addSupportedScheme('amqp');
Expand Down Expand Up @@ -158,6 +160,7 @@ public function parse()
$config['ssl_cacert'] = (string) $config['ssl_cacert'];
$config['ssl_cert'] = (string) $config['ssl_cert'];
$config['ssl_key'] = (string) $config['ssl_key'];
$config['ssl_passphrase'] = (string) $config['ssl_passphrase'];

$this->config = $config;

Expand Down Expand Up @@ -293,34 +296,42 @@ public function isSslVerify()
}

/**
* @return bool
* @return string
*/
public function getSslCaCert()
{
return $this->getOption('ssl_cacert');
}

/**
* @return bool
* @return string
*/
public function getSslCert()
{
return $this->getOption('ssl_cert');
}

/**
* @return bool
* @return string
*/
public function getSslKey()
{
return $this->getOption('ssl_key');
}

/**
* @return string
*/
public function getSslPassPhrase()
{
return $this->getOption('ssl_passphrase');
}

/**
* @param string $name
* @param mixed $default
*
* @return bool
* @return mixed
*/
public function getOption($name, $default = null)
{
Expand Down
112 changes: 64 additions & 48 deletions pkg/amqp-tools/Tests/ConnectionConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ public function testShouldParseEmptyDsnWithDriverSet()
'heartbeat' => 0.0,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
], $config->getConfig());
}

Expand Down Expand Up @@ -102,9 +103,10 @@ public function testShouldParseCustomDsnWithDriverSet()
'heartbeat' => 0.0,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
], $config->getConfig());
}

Expand Down Expand Up @@ -143,9 +145,10 @@ public static function provideConfigs()
'heartbeat' => 0.0,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
],
];

Expand All @@ -168,9 +171,10 @@ public static function provideConfigs()
'heartbeat' => 0.0,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
],
];

Expand All @@ -193,9 +197,10 @@ public static function provideConfigs()
'heartbeat' => 0.0,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
],
];

Expand All @@ -218,9 +223,10 @@ public static function provideConfigs()
'heartbeat' => 0.0,
'ssl_on' => true,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
],
];

Expand All @@ -243,9 +249,10 @@ public static function provideConfigs()
'heartbeat' => 0.0,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
],
];

Expand All @@ -268,9 +275,10 @@ public static function provideConfigs()
'heartbeat' => 0.0,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
],
];

Expand All @@ -293,9 +301,10 @@ public static function provideConfigs()
'heartbeat' => 23.3,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
],
];

Expand All @@ -318,9 +327,10 @@ public static function provideConfigs()
'heartbeat' => 0.0,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
],
];

Expand All @@ -343,9 +353,10 @@ public static function provideConfigs()
'heartbeat' => 0.0,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
],
];

Expand All @@ -368,9 +379,10 @@ public static function provideConfigs()
'heartbeat' => 0.0,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
],
];

Expand All @@ -393,9 +405,10 @@ public static function provideConfigs()
'heartbeat' => 0.0,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
],
];

Expand All @@ -418,9 +431,10 @@ public static function provideConfigs()
'heartbeat' => 0.0,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
],
];

Expand Down Expand Up @@ -449,9 +463,10 @@ public static function provideConfigs()
'heartbeat' => 0.0,
'ssl_on' => false,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
],
];

Expand All @@ -477,9 +492,10 @@ public static function provideConfigs()
'heartbeat' => 0.0,
'ssl_on' => true,
'ssl_verify' => true,
'ssl_cacert' => null,
'ssl_cert' => null,
'ssl_key' => null,
'ssl_cacert' => '',
'ssl_cert' => '',
'ssl_key' => '',
'ssl_passphrase' => '',
],
];
}
Expand Down