Skip to content

Commit 659368c

Browse files
committed
Fix multi-call SSL verify propagation in cURL
The `request_multi` method does not take into account the verify option, unlike `request`. Moved the verify logic into `setup_handler` which does all the `curl_setopt` calls anyway and is called from both the multiple and single request options. With tests. Contigent on WordPress#310 for fsockopen verify fix. Fixes WordPress#294
1 parent 4055bc4 commit 659368c

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

library/Requests/Transport/cURL.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,6 @@ public function request($url, $headers = array(), $data = array(), $options = ar
145145
$this->response_byte_limit = $options['max_bytes'];
146146
}
147147

148-
if (isset($options['verify'])) {
149-
if ($options['verify'] === false) {
150-
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
151-
curl_setopt($this->handle, CURLOPT_SSL_VERIFYPEER, 0);
152-
}
153-
elseif (is_string($options['verify'])) {
154-
curl_setopt($this->handle, CURLOPT_CAINFO, $options['verify']);
155-
}
156-
}
157-
158-
if (isset($options['verifyname']) && $options['verifyname'] === false) {
159-
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
160-
}
161-
162148
curl_exec($this->handle);
163149
$response = $this->response_data;
164150

@@ -390,6 +376,20 @@ protected function setup_handle($url, $headers, $data, $options) {
390376
curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array(&$this, 'stream_body'));
391377
curl_setopt($this->handle, CURLOPT_BUFFERSIZE, Requests::BUFFER_SIZE);
392378
}
379+
380+
if (isset($options['verify'])) {
381+
if ($options['verify'] === false) {
382+
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
383+
curl_setopt($this->handle, CURLOPT_SSL_VERIFYPEER, 0);
384+
}
385+
elseif (is_string($options['verify'])) {
386+
curl_setopt($this->handle, CURLOPT_CAINFO, $options['verify']);
387+
}
388+
}
389+
390+
if (isset($options['verifyname']) && $options['verifyname'] === false) {
391+
curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0);
392+
}
393393
}
394394

395395
/**

library/Requests/Transport/fsockopen.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public function request($url, $headers = array(), $data = array(), $options = ar
9292
if (isset($options['verify'])) {
9393
if ($options['verify'] === false) {
9494
$context_options['verify_peer'] = false;
95+
$context_options['verify_peer_name'] = false;
96+
$verifyname = false;
9597
}
9698
elseif (is_string($options['verify'])) {
9799
$context_options['cafile'] = $options['verify'];

tests/Transport/Base.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,34 @@ public function testMultipleToFile() {
764764
unlink($requests['post']['options']['filename']);
765765
}
766766

767+
public function testMultipleWithNoVerify() {
768+
if ($this->skip_https) {
769+
$this->markTestSkipped('SSL support is not available.');
770+
return;
771+
}
772+
773+
$requests = array(
774+
'test1' => array(
775+
'url' => 'https://wrong.host.badssl.com/',
776+
'options' => array('verify' => false),
777+
),
778+
'test2' => array(
779+
'url' => 'https://wrong.host.badssl.com/'
780+
),
781+
);
782+
783+
$responses = Requests::request_multiple($requests, $this->getOptions());
784+
785+
// test1
786+
$this->assertNotEmpty($responses['test1']);
787+
$this->assertInstanceOf('Requests_Response', $responses['test1']);
788+
$this->assertEquals(200, $responses['test1']->status_code);
789+
790+
// test2
791+
$this->assertNotEmpty($responses['test2']);
792+
$this->assertInstanceOf('Requests_Exception', $responses['test2']);
793+
}
794+
767795
public function testAlternatePort() {
768796
$request = Requests::get('http://portquiz.net:8080/', array(), $this->getOptions());
769797
$this->assertEquals(200, $request->status_code);

0 commit comments

Comments
 (0)