From 181c3768610bd184d1bc88e0026addcac3ea87d3 Mon Sep 17 00:00:00 2001 From: Massimo Cireddu Date: Wed, 9 Oct 2019 11:10:22 +0200 Subject: [PATCH] Adding optional key password parameter Signed-off-by: Massimo Cireddu --- src/Client.php | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/Client.php b/src/Client.php index e85d085..9fe07a8 100644 --- a/src/Client.php +++ b/src/Client.php @@ -42,6 +42,11 @@ class Client extends \SoapClient */ protected static $privateKey = null; + /** + * CA certificate + */ + protected static $privateKeyPassword = null; + /** * Client certificate */ @@ -84,7 +89,15 @@ public static function setPrivateKey( $file ) { self::$privateKey = $file; } - + + /** + * Set private key + */ + public static function setPrivateKeyPassword( $password ) + { + self::$privateKeyPassword = $password; + } + /** * Set client cert */ @@ -92,7 +105,7 @@ public static function setClientCert( $file ) { self::$clientCert = $file; } - + /** * Set CA cert */ @@ -155,21 +168,25 @@ public function __construct( $params = array() ) if (array_key_exists('key', $params)) { static::setPrivateKey($params['key']); } - + + if (array_key_exists('keyPassword', $params)) { + static::setPrivateKeyPassword($params['keyPassword']); + } + if (array_key_exists('cert', $params)) { static::setClientCert($params['cert']); } - + if (array_key_exists('ca_cert', $params)) { static::setCaCert($params['ca_cert']); } - + $options = array( 'location' => $endpoint, 'cache_wsdl' => WSDL_CACHE_NONE, 'trace' => true ); - + parent::__construct($wsdl, $options); } @@ -212,11 +229,14 @@ public function __doRequest( $request, $location, $action, $version, $one_way = curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); - + // https://forum.italia.it/t/sdicoop-configurazione-php-soapclient-soapserver-apache-per-invio-e-ricezione-di-test/5528/85 curl_setopt($ch, 226, false); - + curl_setopt($ch, CURLOPT_SSLKEY, self::$privateKey); + if (self::$privateKeyPassword != null) { + curl_setopt($ch, CURLOPT_SSLKEYPASSWD, self::$privateKeyPassword); + } curl_setopt($ch, CURLOPT_SSLCERT, self::$clientCert); curl_setopt($ch, CURLOPT_CAINFO, self::$caCert);