Skip to content

Commit 9c28c63

Browse files
committed
MAGETWO-61531: Paypal SSL Curl communication error, TLS 1.2 required for https://*.paypal.com
- adding configurable curl minimum tls 1.2 version
1 parent d491a45 commit 9c28c63

File tree

1 file changed

+26
-8
lines changed
  • lib/internal/Magento/Framework/HTTP/Client

1 file changed

+26
-8
lines changed

lib/internal/Magento/Framework/HTTP/Client/Curl.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
* Class to work with HTTP protocol using curl library
1010
*
1111
* @author Magento Core Team <[email protected]>
12+
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
1213
*/
1314
class Curl implements \Magento\Framework\HTTP\ClientInterface
1415
{
16+
const SSL_VERSION = 6;
17+
1518
/**
1619
* Max supported protocol by curl CURL_SSLVERSION_TLSv1_2
1720
* @var int
1821
*/
19-
private static $sslVersion = 6;
22+
private $sslVersion;
2023

2124
/**
2225
* Hostname
@@ -86,7 +89,7 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface
8689

8790
/**
8891
* Curl
89-
* @var object
92+
* @var resource
9093
*/
9194
protected $_ch;
9295

@@ -117,10 +120,11 @@ public function setTimeout($value)
117120
}
118121

119122
/**
120-
* Constructor
123+
* @param int|null $sslVersion
121124
*/
122-
public function __construct()
125+
public function __construct($sslVersion = null)
123126
{
127+
$this->sslVersion = $sslVersion;
124128
}
125129

126130
/**
@@ -377,10 +381,9 @@ protected function makeRequest($method, $uri, $params = [])
377381
$this->curlOption(CURLOPT_PORT, $this->_port);
378382
}
379383

380-
//$this->curlOption(CURLOPT_HEADER, 1);
381384
$this->curlOption(CURLOPT_RETURNTRANSFER, 1);
382385
$this->curlOption(CURLOPT_HEADERFUNCTION, [$this, 'parseHeaders']);
383-
$this->curlOption(CURLOPT_SSLVERSION, self::$sslVersion);
386+
$this->setSSLVersion($this->sslVersion);
384387

385388
if (count($this->_curlUserOptions)) {
386389
foreach ($this->_curlUserOptions as $k => $v) {
@@ -415,18 +418,18 @@ public function doError($string)
415418
* @param resource $ch curl handle, not needed
416419
* @param string $data
417420
* @return int
421+
* @throws \Exception
418422
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
419423
*/
420424
protected function parseHeaders($ch, $data)
421425
{
422426
if ($this->_headerCount == 0) {
423427
$line = explode(" ", trim($data), 3);
424428
if (count($line) != 3) {
425-
return $this->doError("Invalid response line returned from server: " . $data);
429+
$this->doError("Invalid response line returned from server: " . $data);
426430
}
427431
$this->_responseStatus = intval($line[1]);
428432
} else {
429-
//var_dump($data);
430433
$name = $value = '';
431434
$out = explode(": ", trim($data), 2);
432435
if (count($out) == 2) {
@@ -493,4 +496,19 @@ public function setOption($name, $value)
493496
{
494497
$this->_curlUserOptions[$name] = $value;
495498
}
499+
500+
/**
501+
* Set ssl version to specified version or default
502+
*
503+
* @param int $sslVersion
504+
* @return void
505+
*/
506+
private function setSSLVersion($sslVersion)
507+
{
508+
if ($sslVersion) {
509+
$this->sslVersion = $sslVersion;
510+
} else {
511+
$this->sslVersion = self::SSL_VERSION;
512+
}
513+
}
496514
}

0 commit comments

Comments
 (0)