diff --git a/src/BeSimple/SoapClient/Curl/Curl.php b/src/BeSimple/SoapClient/Curl/Curl.php index 3c36f4e..702df40 100644 --- a/src/BeSimple/SoapClient/Curl/Curl.php +++ b/src/BeSimple/SoapClient/Curl/Curl.php @@ -4,7 +4,6 @@ namespace BeSimple\SoapClient\Curl; use BeSimple\SoapClient\Curl\Http\HttpAuthenticationBasicOptions; use BeSimple\SoapClient\Curl\Http\HttpAuthenticationDigestOptions; -use BeSimple\SoapClient\Curl\Http\SslCertificateOptions; use Exception; class Curl @@ -141,6 +140,11 @@ class Curl curl_setopt($curlSession, CURLOPT_CAPATH, $sslCertificateOptions->hasCertificateAuthorityPath()); } } + + if ($options->hasSslVersion()) { + curl_setopt($curlSession, CURLOPT_SSLVERSION, $options->getSslVersion()); + } + $executeSoapCallResponse = $this->executeHttpCall($curlSession, $options); $httpRequestHeadersAsString = curl_getinfo($curlSession, CURLINFO_HEADER_OUT); @@ -159,7 +163,7 @@ class Curl $httpResponseCode ); - if (!is_integer($httpResponseCode) || $httpResponseCode >= 400 || $httpResponseCode === 0) { + if (!is_int($httpResponseCode) || $httpResponseCode >= 400 || $httpResponseCode === 0) { return new CurlResponse( $this->normalizeStringOrFalse($httpRequestHeadersAsString), diff --git a/src/BeSimple/SoapClient/Curl/CurlOptions.php b/src/BeSimple/SoapClient/Curl/CurlOptions.php index 78ca445..a3bd84f 100644 --- a/src/BeSimple/SoapClient/Curl/CurlOptions.php +++ b/src/BeSimple/SoapClient/Curl/CurlOptions.php @@ -2,9 +2,9 @@ namespace BeSimple\SoapClient\Curl; +use BeSimple\SoapClient\Curl\Http\HttpAuthenticationBasicOptions; use BeSimple\SoapClient\Curl\Http\HttpAuthenticationDigestOptions; use BeSimple\SoapClient\Curl\Http\HttpAuthenticationInterface; -use BeSimple\SoapClient\Curl\Http\HttpAuthenticationBasicOptions; use BeSimple\SoapClient\Curl\Http\SslCertificateOptions; use BeSimple\SoapClient\SoapServerProxy\SoapServerProxy; @@ -22,6 +22,7 @@ class CurlOptions private $proxy; private $httpAuthentication; private $sslCertificateOptions; + private $sslVersion; /** * @param string $userAgent @@ -31,6 +32,7 @@ class CurlOptions * @param SoapServerProxy|null $proxy * @param HttpAuthenticationInterface|null $httpAuthentication * @param SslCertificateOptions|null $sslCertificateOptions + * @param int $sslVersion */ public function __construct( $userAgent, @@ -39,7 +41,8 @@ class CurlOptions $connectionTimeout, SoapServerProxy $proxy = null, HttpAuthenticationInterface $httpAuthentication = null, - SslCertificateOptions $sslCertificateOptions = null + SslCertificateOptions $sslCertificateOptions = null, + $sslVersion = null ) { $this->userAgent = $userAgent; $this->followLocationMaxRedirects = $followLocationMaxRedirects; @@ -48,6 +51,7 @@ class CurlOptions $this->proxy = $proxy; $this->httpAuthentication = $httpAuthentication; $this->sslCertificateOptions = $sslCertificateOptions; + $this->sslVersion = $sslVersion; } public function getUserAgent() @@ -123,4 +127,14 @@ class CurlOptions return false; } + + public function hasSslVersion() + { + return $this->sslVersion !== null; + } + + public function getSslVersion() + { + return $this->sslVersion; + } } diff --git a/src/BeSimple/SoapClient/Curl/CurlOptionsBuilder.php b/src/BeSimple/SoapClient/Curl/CurlOptionsBuilder.php index f76ebe1..093c038 100644 --- a/src/BeSimple/SoapClient/Curl/CurlOptionsBuilder.php +++ b/src/BeSimple/SoapClient/Curl/CurlOptionsBuilder.php @@ -34,7 +34,8 @@ class CurlOptionsBuilder self::DEFAULT_CONNECTION_TIMEOUT, $soapClientOptions->getProxy(), self::getHttpAuthOptions($soapClientOptions), - self::getSslCertificateOptions($soapClientOptions) + self::getSslCertificateOptions($soapClientOptions), + $soapClientOptions->getSslVersion() ); } diff --git a/src/BeSimple/SoapClient/SoapClientOptionsBuilder.php b/src/BeSimple/SoapClient/SoapClientOptionsBuilder.php index 3c277ac..0e84761 100644 --- a/src/BeSimple/SoapClient/SoapClientOptionsBuilder.php +++ b/src/BeSimple/SoapClient/SoapClientOptionsBuilder.php @@ -82,6 +82,28 @@ class SoapClientOptionsBuilder ); } + /** + * @param $endpointLocation + * @param SoapServerAuthenticationInterface $authentication + * @return SoapClientOptions + */ + public static function createWithAuthenticationAndEndpointLocationAndSslVersionV3( + $endpointLocation, + SoapServerAuthenticationInterface $authentication + ) { + return new SoapClientOptions( + SoapClientOptions::SOAP_CLIENT_TRACE_ON, + SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON, + CurlOptions::DEFAULT_USER_AGENT, + SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE, + $authentication, + SoapClientOptions::SOAP_CLIENT_PROXY_NONE, + $endpointLocation, + false, + CURL_SSLVERSION_SSLv3 + ); + } + /** * @param SoapServerAuthenticationInterface $authentication * @param bool $resolveRemoteIncludes diff --git a/src/BeSimple/SoapClient/SoapOptions/SoapClientOptions.php b/src/BeSimple/SoapClient/SoapOptions/SoapClientOptions.php index 6b6cd4b..664e0b5 100644 --- a/src/BeSimple/SoapClient/SoapOptions/SoapClientOptions.php +++ b/src/BeSimple/SoapClient/SoapOptions/SoapClientOptions.php @@ -31,6 +31,7 @@ class SoapClientOptions private $proxy; private $location; private $resolveRemoteIncludes; + private $sslVersion; /** * @param bool $trace = self::SOAP_CLIENT_TRACE_ON|self::SOAP_CLIENT_TRACE_OFF @@ -41,6 +42,7 @@ class SoapClientOptions * @param SoapServerProxy|null $proxy * @param string|null $location * @param bool $resolveRemoteIncludes = self::SOAP_CLIENT_RESOLVE_REMOTE_INCLUDES_ON|self::SOAP_CLIENT_RESOLVE_REMOTE_INCLUDES_OFF + * @param int $sslVersion */ public function __construct( $trace, @@ -50,7 +52,8 @@ class SoapClientOptions SoapServerAuthenticationInterface $authentication = null, SoapServerProxy $proxy = null, $location = null, - $resolveRemoteIncludes = false + $resolveRemoteIncludes = false, + $sslVersion = null ) { $this->trace = $trace; $this->exceptions = $exceptions; @@ -60,6 +63,7 @@ class SoapClientOptions $this->proxy = $proxy; $this->location = $location; $this->resolveRemoteIncludes = $resolveRemoteIncludes; + $this->sslVersion = $sslVersion; } public function getTrace() @@ -154,4 +158,9 @@ class SoapClientOptions return $optionsAsArray; } + + public function getSslVersion() + { + return $this->sslVersion; + } } diff --git a/tests/BeSimple/SoapClient/SoapClientBuilderTest.php b/tests/BeSimple/SoapClient/SoapClientBuilderTest.php index 38db6fb..a37cb5f 100644 --- a/tests/BeSimple/SoapClient/SoapClientBuilderTest.php +++ b/tests/BeSimple/SoapClient/SoapClientBuilderTest.php @@ -4,6 +4,7 @@ namespace BeSimple\SoapClient; use BeSimple\SoapClient\Curl\CurlOptions; use BeSimple\SoapClient\SoapOptions\SoapClientOptions; +use BeSimple\SoapClient\SoapServerAuthentication\SoapServerAuthenticationBasic; use BeSimple\SoapCommon\ClassMap; use BeSimple\SoapCommon\SoapOptions\SoapOptions; use BeSimple\SoapCommon\SoapOptionsBuilder; @@ -87,6 +88,27 @@ class SoapClientBuilderTest extends PHPUnit_Framework_TestCase self::assertInstanceOf(SoapClient::class, $soapClient); } + public function testCreateOptionsWithAuthenticationAndEndpointLocationAndSslVersionV3() + { + $authentication = new SoapServerAuthenticationBasic('', ''); + $soapClientOptions = SoapClientOptionsBuilder::createWithAuthenticationAndEndpointLocationAndSslVersionV3('', $authentication); + + self::assertSame(CURL_SSLVERSION_SSLv3, $soapClientOptions->getSslVersion()); + } + + public function testConstructSoapClientWithAuthenticationAndEndpointLocationAndSslVersionV3() + { + $authentication = new SoapServerAuthenticationBasic('', ''); + $soapOptions = SoapOptionsBuilder::createWithDefaults(self::TEST_LOCAL_WSDL_UK); + + $soapClient = $this->getSoapBuilder()->build( + SoapClientOptionsBuilder::createWithAuthenticationAndEndpointLocationAndSslVersionV3('', $authentication), + $soapOptions + ); + + self::assertInstanceOf(SoapClient::class, $soapClient); + } + private function getSoapBuilder() { return new SoapClientBuilder();