Merge pull request #10 from vhorky/feature/curl-ssl-version

Soap client option allows setting CURLOPT_SSLVERSION
This commit is contained in:
milanmimra 2017-09-21 10:54:15 +02:00 committed by GitHub
commit 073028f160
6 changed files with 78 additions and 6 deletions

View File

@ -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),

View File

@ -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;
}
}

View File

@ -34,7 +34,8 @@ class CurlOptionsBuilder
self::DEFAULT_CONNECTION_TIMEOUT,
$soapClientOptions->getProxy(),
self::getHttpAuthOptions($soapClientOptions),
self::getSslCertificateOptions($soapClientOptions)
self::getSslCertificateOptions($soapClientOptions),
$soapClientOptions->getSslVersion()
);
}

View File

@ -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

View File

@ -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;
}
}

View File

@ -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();