From 54a3f8724b63c8dad46a35baad9f11f997cc3c62 Mon Sep 17 00:00:00 2001 From: Richard van den Berg Date: Tue, 17 Mar 2015 13:40:36 +0100 Subject: [PATCH] Addapted quick hack from issue #2057 for 2.6.3 --- lib/Cake/Network/CakeSocket.php | 30 +++++++++++++++++++++++++++- lib/Cake/Network/Http/HttpSocket.php | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeSocket.php b/lib/Cake/Network/CakeSocket.php index d428a74cb..8b3c92e5f 100644 --- a/lib/Cake/Network/CakeSocket.php +++ b/lib/Cake/Network/CakeSocket.php @@ -130,7 +130,7 @@ class CakeSocket { } $scheme = null; - if (!empty($this->config['protocol']) && strpos($this->config['host'], '://') === false) { + if (!empty($this->config['protocol']) && strpos($this->config['host'], '://') === false && empty($this->config['proxy'])) { $scheme = $this->config['protocol'] . '://'; } @@ -170,6 +170,34 @@ class CakeSocket { if ($this->connected) { stream_set_timeout($this->connection, $this->config['timeout']); } + + + if (!empty($this->config['request']) && $this->config['request']['uri']['scheme'] == 'https' && !empty($this->config['proxy'])) { + $req = array(); + $req[] = 'CONNECT '. $this->config['request']['uri']['host'] . ':' . $this->config['request']['uri']['port'] . ' HTTP/1.1'; + $req[] = 'Host: ' . $this->config['host']; + $req[] = 'User-Agent: php proxy'; + + fwrite($this->connection, implode("\r\n", $req)."\r\n\r\n"); + + while(true) { + $s = rtrim(fgets($this->connection, 4096)); + if(preg_match('/^$/', $s)) { + break; + } + } + + $modes = array(STREAM_CRYPTO_METHOD_TLS_CLIENT, + STREAM_CRYPTO_METHOD_SSLv3_CLIENT, + STREAM_CRYPTO_METHOD_SSLv23_CLIENT, + STREAM_CRYPTO_METHOD_SSLv2_CLIENT); + $success = false; + foreach($modes as $mode) { + $success = stream_socket_enable_crypto($this->connection, true, $mode); + if ($success) break; + } + } + return $this->connected; } diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index 16fc0edcf..ff176359f 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/lib/Cake/Network/Http/HttpSocket.php @@ -652,6 +652,7 @@ class HttpSocket extends CakeSocket { } $this->config['host'] = $this->_proxy['host']; $this->config['port'] = $this->_proxy['port']; + $this->config['proxy'] = true; if (empty($this->_proxy['method']) || !isset($this->_proxy['user'], $this->_proxy['pass'])) { return;