From fa0f3c12cd25350cef114b254a1febb6fbc33f23 Mon Sep 17 00:00:00 2001 From: LaoQi Date: Wed, 4 Nov 2020 00:31:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0HttpProfile=E4=B8=AD?= =?UTF-8?q?=E5=AF=B9https=E8=AF=B7=E6=B1=82=E6=98=AF=E5=90=A6=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E4=B8=A5=E6=A0=BC=E9=AA=8C=E8=AF=81=E7=9A=84=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/Http/HttpConnection.php | 1 + .../Common/Profile/HttpProfile.php | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/TencentCloud/Common/Http/HttpConnection.php b/src/TencentCloud/Common/Http/HttpConnection.php index 723b28af86..20090cffbb 100644 --- a/src/TencentCloud/Common/Http/HttpConnection.php +++ b/src/TencentCloud/Common/Http/HttpConnection.php @@ -39,6 +39,7 @@ private function getOptions() $options = ["allow_redirects" => false]; $options["timeout"] = $this->profile->getHttpProfile()->getReqTimeout(); $options["proxy"] = $this->profile->getHttpProfile()->getProxy(); + $options["verify"] = $this->profile->getHttpProfile()->getVerify(); return $options; } diff --git a/src/TencentCloud/Common/Profile/HttpProfile.php b/src/TencentCloud/Common/Profile/HttpProfile.php index 9f2721e2ac..b09ec585eb 100644 --- a/src/TencentCloud/Common/Profile/HttpProfile.php +++ b/src/TencentCloud/Common/Profile/HttpProfile.php @@ -76,6 +76,11 @@ class HttpProfile */ private $proxy; + /** + * @var string|bool 请求时验证SSL证书行为 + */ + private $verify; + /** * HttpProfile constructor. * @param string $protocol 请求协议 @@ -135,6 +140,17 @@ public function setProxy($proxy) $this->proxy = $proxy; } + /** + * 设置成 true 启用SSL证书验证,默认使用操作系统提供的CA包。 + * 设置成 false 禁用证书验证(这是不安全的!)。 + * 设置成字符串启用验证,并使用该字符串作为自定义证书CA包的路径 + * @param string|bool $verify 请求时验证SSL证书行为 + */ + public function setVerify($verify) + { + $this->verify = $verify; + } + /** * 获取请求方法 * @return null|string 请求方法 @@ -179,4 +195,13 @@ public function getProxy() { return $this->proxy; } + + /** + * 请求时验证SSL证书行为 + * @return bool|string + */ + public function getVerify() + { + return $this->verify; + } } From 7a789c1601195e6793f4e235b951d696e571016f Mon Sep 17 00:00:00 2001 From: LaoQi Date: Thu, 5 Nov 2020 17:39:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ssl=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E8=A1=8C=E4=B8=BA=E7=9A=84=E5=88=9D=E5=A7=8B=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/TencentCloud/Common/Profile/HttpProfile.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/TencentCloud/Common/Profile/HttpProfile.php b/src/TencentCloud/Common/Profile/HttpProfile.php index b09ec585eb..a5176bcef9 100644 --- a/src/TencentCloud/Common/Profile/HttpProfile.php +++ b/src/TencentCloud/Common/Profile/HttpProfile.php @@ -18,6 +18,8 @@ namespace TencentCloud\Common\Profile; +use GuzzleHttp\RequestOptions; + /** * http相关参数类 * Class HttpProfile @@ -83,10 +85,11 @@ class HttpProfile /** * HttpProfile constructor. - * @param string $protocol 请求协议 - * @param string $endpoint 请求接入点域名(xx.[region.]tencentcloudapi.com) + * @param string $protocol 请求协议 + * @param string $endpoint 请求接入点域名(xx.[region.]tencentcloudapi.com) * @param string $reqMethod http请求方法,目前支持POST GET * @param integer $reqTimeout 请求超时时间,单位:s + * @param string|bool $verify 请求时验证SSL证书行为 */ public function __construct($protocol = null, $endpoint = null, $reqMethod = null, $reqTimeout = null) { @@ -94,6 +97,7 @@ public function __construct($protocol = null, $endpoint = null, $reqMethod = nul $this->endpoint = $endpoint; $this->reqTimeout = $reqTimeout ? $reqTimeout : HttpProfile::$TM_MINUTE; $this->protocol = $protocol ? $protocol : HttpProfile::$REQ_HTTPS; + $this->verify = RequestOptions::VERIFY; } /**