Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get PHP to connect to TLSv1.2 only site [duplicate]

Tags:

php

curl

ssl

I'm trying to connect using curl in PHP to Pronto Cycle Share (using PHP 5.6.2). This site works in the browser and from command line curl.

According to SSL Labs, it is only accepting TLS 1.2.

In PHP, using CURL (version 7.28.1) PHP fails to negotiate and gives me Curl error: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure

Using file_get_contents, the code:

$ctx = stream_context_create([
'ssl' => [
    'crypto_method' => STREAM_CRYPTO_METHOD_TLS_CLIENT
  ],
]);
$html = file_get_contents($url, false, $ctx);

Returns:

Message:  file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure

print_r(OPENSSL_VERSION_TEXT) says OpenSSL 0.9.8r 8 Feb 2011, so that's fairly old. I'm using MAMP PRO on the Mac.

Is there any way to connect to this server using simple PHP methods?

like image 969
MattC Avatar asked Jan 01 '26 09:01

MattC


1 Answers

Your version of cURL doesn't support TLS 1.2, you need to upgrade.

CURL_SSLVERSION_TLSv1_0 (4), CURL_SSLVERSION_TLSv1_1 (5) or CURL_SSLVERSION_TLSv1_2 (6) only work for PHP versions using curl 7.34 or newer.

Source

like image 124
Sammitch Avatar answered Jan 03 '26 14:01

Sammitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!