Skip to content
Snippets Groups Projects
Commit 9c28c63a authored by Cristian Partica's avatar Cristian Partica
Browse files

MAGETWO-61531: Paypal SSL Curl communication error, TLS 1.2 required for https://*.paypal.com

- adding configurable curl minimum tls 1.2 version
parent d491a45f
Branches
No related merge requests found
...@@ -9,14 +9,17 @@ namespace Magento\Framework\HTTP\Client; ...@@ -9,14 +9,17 @@ namespace Magento\Framework\HTTP\Client;
* Class to work with HTTP protocol using curl library * Class to work with HTTP protocol using curl library
* *
* @author Magento Core Team <core@magentocommerce.com> * @author Magento Core Team <core@magentocommerce.com>
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/ */
class Curl implements \Magento\Framework\HTTP\ClientInterface class Curl implements \Magento\Framework\HTTP\ClientInterface
{ {
const SSL_VERSION = 6;
/** /**
* Max supported protocol by curl CURL_SSLVERSION_TLSv1_2 * Max supported protocol by curl CURL_SSLVERSION_TLSv1_2
* @var int * @var int
*/ */
private static $sslVersion = 6; private $sslVersion;
/** /**
* Hostname * Hostname
...@@ -86,7 +89,7 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface ...@@ -86,7 +89,7 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface
/** /**
* Curl * Curl
* @var object * @var resource
*/ */
protected $_ch; protected $_ch;
...@@ -117,10 +120,11 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface ...@@ -117,10 +120,11 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface
} }
/** /**
* Constructor * @param int|null $sslVersion
*/ */
public function __construct() public function __construct($sslVersion = null)
{ {
$this->sslVersion = $sslVersion;
} }
/** /**
...@@ -377,10 +381,9 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface ...@@ -377,10 +381,9 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface
$this->curlOption(CURLOPT_PORT, $this->_port); $this->curlOption(CURLOPT_PORT, $this->_port);
} }
//$this->curlOption(CURLOPT_HEADER, 1);
$this->curlOption(CURLOPT_RETURNTRANSFER, 1); $this->curlOption(CURLOPT_RETURNTRANSFER, 1);
$this->curlOption(CURLOPT_HEADERFUNCTION, [$this, 'parseHeaders']); $this->curlOption(CURLOPT_HEADERFUNCTION, [$this, 'parseHeaders']);
$this->curlOption(CURLOPT_SSLVERSION, self::$sslVersion); $this->setSSLVersion($this->sslVersion);
if (count($this->_curlUserOptions)) { if (count($this->_curlUserOptions)) {
foreach ($this->_curlUserOptions as $k => $v) { foreach ($this->_curlUserOptions as $k => $v) {
...@@ -415,6 +418,7 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface ...@@ -415,6 +418,7 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface
* @param resource $ch curl handle, not needed * @param resource $ch curl handle, not needed
* @param string $data * @param string $data
* @return int * @return int
* @throws \Exception
* @SuppressWarnings(PHPMD.UnusedFormalParameter) * @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/ */
protected function parseHeaders($ch, $data) protected function parseHeaders($ch, $data)
...@@ -422,11 +426,10 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface ...@@ -422,11 +426,10 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface
if ($this->_headerCount == 0) { if ($this->_headerCount == 0) {
$line = explode(" ", trim($data), 3); $line = explode(" ", trim($data), 3);
if (count($line) != 3) { if (count($line) != 3) {
return $this->doError("Invalid response line returned from server: " . $data); $this->doError("Invalid response line returned from server: " . $data);
} }
$this->_responseStatus = intval($line[1]); $this->_responseStatus = intval($line[1]);
} else { } else {
//var_dump($data);
$name = $value = ''; $name = $value = '';
$out = explode(": ", trim($data), 2); $out = explode(": ", trim($data), 2);
if (count($out) == 2) { if (count($out) == 2) {
...@@ -493,4 +496,19 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface ...@@ -493,4 +496,19 @@ class Curl implements \Magento\Framework\HTTP\ClientInterface
{ {
$this->_curlUserOptions[$name] = $value; $this->_curlUserOptions[$name] = $value;
} }
/**
* Set ssl version to specified version or default
*
* @param int $sslVersion
* @return void
*/
private function setSSLVersion($sslVersion)
{
if ($sslVersion) {
$this->sslVersion = $sslVersion;
} else {
$this->sslVersion = self::SSL_VERSION;
}
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment