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

Fix multi-call SSL verify propagation in cURL #312

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
28 changes: 14 additions & 14 deletions library/Requests/Transport/cURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,6 @@ public function request($url, $headers = array(), $data = array(), $options = ar
$this->response_byte_limit = $options['max_bytes'];
}

if (isset($options['verify'])) {
if ($options['verify'] === false) {
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->handle, CURLOPT_SSL_VERIFYPEER, 0);
}
elseif (is_string($options['verify'])) {
curl_setopt($this->handle, CURLOPT_CAINFO, $options['verify']);
}
}

if (isset($options['verifyname']) && $options['verifyname'] === false) {
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
}

curl_exec($this->handle);
$response = $this->response_data;

Expand Down Expand Up @@ -390,6 +376,20 @@ protected function setup_handle($url, $headers, $data, $options) {
curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array(&$this, 'stream_body'));
curl_setopt($this->handle, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE);
}

if (isset($options['verify'])) {
if ($options['verify'] === false) {
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->handle, CURLOPT_SSL_VERIFYPEER, 0);
}
elseif (is_string($options['verify'])) {
curl_setopt($this->handle, CURLOPT_CAINFO, $options['verify']);
}
}

if (isset($options['verifyname']) && $options['verifyname'] === false) {
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions library/Requests/Transport/fsockopen.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public function request($url, $headers = array(), $data = array(), $options = ar
if (isset($options['verify'])) {
if ($options['verify'] === false) {
$context_options['verify_peer'] = false;
$context_options['verify_peer_name'] = false;
$verifyname = false;
}
elseif (is_string($options['verify'])) {
$context_options['cafile'] = $options['verify'];
Expand Down
28 changes: 28 additions & 0 deletions tests/Transport/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,34 @@ public function testMultipleToFile() {
unlink($requests['post']['options']['filename']);
}

public function testMultipleWithNoVerify() {
if ($this->skip_https) {
$this->markTestSkipped('SSL support is not available.');
return;
}

$requests = array(
'test1' => array(
'url' => 'https://wrong.host.badssl.com/',
'options' => array('verify' => false),
),
'test2' => array(
'url' => 'https://wrong.host.badssl.com/'
),
);

$responses = Requests::request_multiple($requests, $this->getOptions());

// test1
$this->assertNotEmpty($responses['test1']);
$this->assertInstanceOf('Requests_Response', $responses['test1']);
$this->assertEquals(200, $responses['test1']->status_code);

// test2
$this->assertNotEmpty($responses['test2']);
$this->assertInstanceOf('Requests_Exception', $responses['test2']);
}

public function testAlternatePort() {
$request = Requests::get('http://portquiz.net:8080/', array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
Expand Down