diff --git a/lib/Cake/Network/CakeSocket.php b/lib/Cake/Network/CakeSocket.php index c208805c8..7a9d27588 100644 --- a/lib/Cake/Network/CakeSocket.php +++ b/lib/Cake/Network/CakeSocket.php @@ -94,14 +94,10 @@ class CakeSocket { 'sslv3_client' => STREAM_CRYPTO_METHOD_SSLv3_CLIENT, 'sslv23_client' => STREAM_CRYPTO_METHOD_SSLv23_CLIENT, 'tls_client' => STREAM_CRYPTO_METHOD_TLS_CLIENT, - 'tlsv1_1_client' => STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT, - 'tlsv1_2_client' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT, 'sslv2_server' => STREAM_CRYPTO_METHOD_SSLv2_SERVER, 'sslv3_server' => STREAM_CRYPTO_METHOD_SSLv3_SERVER, 'sslv23_server' => STREAM_CRYPTO_METHOD_SSLv23_SERVER, 'tls_server' => STREAM_CRYPTO_METHOD_TLS_SERVER, - 'tlsv1_1_server' => STREAM_CRYPTO_METHOD_TLSv1_1_SERVER, - 'tlsv1_2_server' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER // @codingStandardsIgnoreEnd ); @@ -121,6 +117,20 @@ class CakeSocket { */ public function __construct($config = array()) { $this->config = array_merge($this->_baseConfig, $config); + + // These TLS versions are not supported by older PHP versions, + // so we have to conditionally set them if they are supported. + $conditionalCrypto = array( + 'tlsv1_1_client' => 'STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT', + 'tlsv1_2_client' => 'STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT', + 'tlsv1_1_server' => 'STREAM_CRYPTO_METHOD_TLSv1_1_SERVER', + 'tlsv1_2_server' => 'STREAM_CRYPTO_METHOD_TLSv1_2_SERVER' + ); + foreach ($conditionalCrypto as $key => $const) { + if (defined($const)) { + $this->_encryptMethods[$key] = constant($const); + } + } } /** diff --git a/lib/Cake/Test/Case/Network/CakeSocketTest.php b/lib/Cake/Test/Case/Network/CakeSocketTest.php index c678d9c5b..43a4c3936 100644 --- a/lib/Cake/Test/Case/Network/CakeSocketTest.php +++ b/lib/Cake/Test/Case/Network/CakeSocketTest.php @@ -54,11 +54,12 @@ class CakeSocketTest extends CakeTestCase { $this->Socket = new CakeSocket(); $config = $this->Socket->config; $this->assertSame($config, array( - 'persistent' => false, - 'host' => 'localhost', - 'protocol' => 'tcp', - 'port' => 80, - 'timeout' => 30 + 'persistent' => false, + 'host' => 'localhost', + 'protocol' => 'tcp', + 'port' => 80, + 'timeout' => 30, + 'cryptoType' => 'tls', )); $this->Socket->reset(); @@ -324,6 +325,20 @@ class CakeSocketTest extends CakeTestCase { $this->Socket->disconnect(); } +/** + * testEnableCrypto tlsv1_1 + * + * @return void + */ + public function testEnableCryptoTlsV11() { + $this->skipIf(!defined('STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT'), 'TLS1.1 is not supported on this system'); + + // testing on tls server + $this->_connectSocketToSslTls(); + $this->assertTrue($this->Socket->enableCrypto('tlsv1_1', 'client')); + $this->Socket->disconnect(); + } + /** * testEnableCryptoExceptionEnableTwice *