Skip to content
New issue

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

By clicking “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? Sign in to your account

[CurlFactory] Prevent undefined offset when using array for ssl_key options #2348

Merged
merged 4 commits into from Oct 24, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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