How to force a certain TLS version in a PHP stream context for the ssl:// transport? -


how can force tlsv1.0 in php stream context when trying access https url?

i’m looking along lines of this:

$context = stream_context_create(   array(     'ssl' => array(       'protocol_version' => 'tls1',     ),   )); file_get_contents('https://example.com/test', false, $context); 

background

actually i’m facing an issue in ubuntu 12.04 when working php’s soapclient. unfortunately, server i’m trying connect support sslv3.0/tlsv1.0 , fails on default tlsv1.1 negotiation. therefore i’d explicitly set protocol of ssl:// transport tlsv1.0.

php 5.6+ users

this new feature documented on php 5.6 openssl changes page.

at time of writing this, php5.6 in beta1 , isn't overly useful. people of future - lucky you!

the future upon us. php 5.6 thing , use should encouraged. aware deprecates used things mysql_* functions care should taken when upgrading.

everyone else

@toubsen correct in answer - isn't directly possible. elaborate on suggested workarounds... when working around problem supplier's api server wasn't correctly negotiating tlsv1.2 down supported tlsv1.0, sending small subset of ciphers seemed allow negotiation complete correctly. stream context code is:

$context = stream_context_create(     [         'ssl' => [             'ciphers' => 'dhe-rsa-aes256-sha:dhe-dss-aes256-sha:aes256-sha:krb5-des-cbc3-md5:krb5-des-cbc3-sha:edh-rsa-des-cbc3-sha:edh-dss-des-cbc3-sha:des-cbc3-sha:des-cbc3-md5:dhe-rsa-aes128-sha:dhe-dss-aes128-sha:aes128-sha:rc2-cbc-md5:krb5-rc4-md5:krb5-rc4-sha:rc4-sha:rc4-md5:rc4-md5:krb5-des-cbc-md5:krb5-des-cbc-sha:edh-rsa-des-cbc-sha:edh-dss-des-cbc-sha:des-cbc-sha:des-cbc-md5:exp-krb5-rc2-cbc-md5:exp-krb5-des-cbc-md5:exp-krb5-rc2-cbc-sha:exp-krb5-des-cbc-sha:exp-edh-rsa-des-cbc-sha:exp-edh-dss-des-cbc-sha:exp-des-cbc-sha:exp-rc2-cbc-md5:exp-rc2-cbc-md5:exp-krb5-rc4-md5:exp-krb5-rc4-sha:exp-rc4-md5:exp-rc4-md5',         ],     ] ); 

soap users

php's soap client doesn't use curl, nor seem use default context set stream_context_set_default. such, created context needs passed soapclient constructor in 2nd parameter such:

$soap_client = new soapclient('http://webservices.site.com/wsdlfile.wsdl', array('stream_context' => $context)); 

why ciphers?

running command openssl ciphers on server gives list of supported ciphers in above format. running openssl ciphers -v tells tlsv1.2 specific. above list compiled of non-tlsv1.2 ciphers reported openssl.

openssl ciphers -v | grep -v 'tlsv1.2' | cut -d ' ' -f 1 | tr "\n" ':'


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -