Skip to content

Commit

Permalink
[CurlFactory] Prevent undefined offset when using array for ssl_key o…
Browse files Browse the repository at this point in the history
…ptions (#2348)

* Test & changes to CurlFactory

* Code style and cleanup

* Restore import order

* Bugfix
  • Loading branch information
Andrew Clark authored and Nyholm committed Oct 24, 2019
1 parent 0cf5794 commit ac157c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Handler/CurlFactory.php
Expand Up @@ -454,11 +454,16 @@ private function applyHandlerOptions(EasyHandle $easy, array &$conf)
}

if (isset($options['ssl_key'])) {
$sslKey = $options['ssl_key'];
if (is_array($sslKey)) {
$conf[CURLOPT_SSLKEYPASSWD] = $sslKey[1];
$sslKey = $sslKey[0];
if (is_array($options['ssl_key'])) {
if (count($options['ssl_key']) === 2) {
list($sslKey, $conf[CURLOPT_SSLKEYPASSWD]) = $options['ssl_key'];
} else {
list($sslKey) = $options['ssl_key'];
}
}

$sslKey = isset($sslKey) ? $sslKey: $options['ssl_key'];

if (!file_exists($sslKey)) {
throw new \InvalidArgumentException(
"SSL private key not found: {$sslKey}"
Expand Down
8 changes: 8 additions & 0 deletions tests/Handler/CurlFactoryTest.php
Expand Up @@ -216,6 +216,14 @@ public function testAddsSslKeyWithPassword()
$this->assertEquals('test', $_SERVER['_curl'][CURLOPT_SSLKEYPASSWD]);
}

public function testAddsSslKeyWhenUsingArraySyntaxButNoPassword()
{
$f = new Handler\CurlFactory(3);
$f->create(new Psr7\Request('GET', Server::$url), ['ssl_key' => [__FILE__]]);

$this->assertEquals(__FILE__, $_SERVER['_curl'][CURLOPT_SSLKEY]);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage SSL certificate not found: /does/not/exist
Expand Down

0 comments on commit ac157c5

Please sign in to comment.