From 1af7e94e93861882f35faf6d062d244d355928a7 Mon Sep 17 00:00:00 2001 From: Pouyan Azari Date: Mon, 18 Dec 2017 13:02:28 +0100 Subject: [PATCH] allows the client to use self signed certificates with strict ssl. --- src/Httpful/Request.php | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Httpful/Request.php b/src/Httpful/Request.php index 563728c..aabd298 100644 --- a/src/Httpful/Request.php +++ b/src/Httpful/Request.php @@ -33,6 +33,8 @@ class Request $headers = array(), $raw_headers = '', $strict_ssl = false, + $use_ca_cert = false, + $ca_cert_path, $content_type, $expected_type, $additional_curl_opts = array(), @@ -443,6 +445,33 @@ public function withStrictSSL() return $this->strictSSL(true); } + /** + * Should the ca cert be used + * @param $caCert + * @return Request + */ + public function caCert($caCert){ + $this->use_ca_cert = $caCert; + return $this; + } + public function withoutCaCert(){ + return $this->caCert(false); + } + public function withCaCert(){ + return $this->caCert(true); + } + + /** + * Adds the ca cert path + * + * @param string $caCertPath The CA certificate path + * @return Request + */ + public function withCaCertPath($caCertPath){ + $this->ca_cert_path = $caCertPath; + return $this; + } + /** * Use proxy configuration * @param string $proxy_host Hostname or address of the proxy @@ -885,7 +914,13 @@ public function _curlPrep() curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, $this->max_redirects); } - + // use ca path for self signed certificates + if ($this->use_ca_cert){ + if(!file_exists($this->ca_cert_path)){ + throw new \Exception('Could not read CA Certificate'); + } + curl_setopt(CURLOPT_CAPATH, $this->ca_cert_path); + } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->strict_ssl); // zero is safe for all curl versions $verifyValue = $this->strict_ssl + 0;