From 69d8a58854ea6a7cd822a568ba3b6aab70719f7d Mon Sep 17 00:00:00 2001 From: Carsten Karbach <c.karbach@fz-juelich.de> Date: Mon, 6 Nov 2017 11:22:24 +0100 Subject: [PATCH] Add SSL certificate support in configuration and api client --- lib/ApiClient.php | 6 ++++ lib/Configuration.php | 79 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/lib/ApiClient.php b/lib/ApiClient.php index fb7472c..36bc858 100644 --- a/lib/ApiClient.php +++ b/lib/ApiClient.php @@ -178,6 +178,12 @@ class ApiClient curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); } + + if(! empty($this->config->getCertificate())){ + curl_setopt($curl, CURLOPT_SSLCERT, $this->config->getCertificate()); + curl_setopt($curl, CURLOPT_SSLKEY, $this->config->getCertificateKey()); + curl_setopt($curl, CURLOPT_SSLKEYPASSWD, $this->config->getCertificatePassphrase()); + } if ($this->config->getCurlProxyHost()) { curl_setopt($curl, CURLOPT_PROXY, $this->config->getCurlProxyHost()); diff --git a/lib/Configuration.php b/lib/Configuration.php index 2273b10..040b49b 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -141,6 +141,24 @@ class Configuration */ protected $sslVerification = true; + /** + * Path to client certificate + * @var string path to client certificate + */ + protected $certificate = null; + + /** + * Path to client certificate key file + * @var string path to client certificate key file + */ + protected $certificateKey = null; + + /** + * passphrase for the certificate key file + * @var string passphrase for the certificate key file + */ + protected $certificatePassphrase = null; + /** * Curl proxy host * @@ -690,6 +708,67 @@ class Configuration { return $this->sslVerification; } + + /** + * Sets certificate file for client certificate + * + * @param string $certificate path to client certificate + * @return Configuration + */ + public function setCertificate($certificate) + { + $this->certificate = $certificate; + return $this; + } + + /** + * + * @return string certificate file for client certificate + */ + public function getCertificate() + { + return $this->certificate; + } + + /** + * Set certificate key file + * @param string $certificatekey certificate key file + * @return \Swagger\Client\Configuration + */ + public function setCertificateKey($certificatekey) + { + $this->certificateKey = $certificatekey; + return $this; + } + + /** + * + * @return string certificate key file + */ + public function getCertificateKey() + { + return $this->certificateKey; + } + + /** + * Set passphrase for client certificate key file + * @param string $passphrase passphrase for client certificate key file + * @return \Swagger\Client\Configuration + */ + public function setCertificatePassphrase($passphrase) + { + $this->certificatePassphrase = $passphrase; + return $this; + } + + /** + * + * @return string passphrase for client certificate key file + */ + public function getCertificatePassphrase() + { + return $this->certificatePassphrase; + } /** * Gets the default configuration instance -- GitLab