Using TLS v1.2 for curling on Amazon AWS

I use this PHP function below to use curl to communicate with an external API

function api_post($url, $data = array()) {

global $api_key;
global $password;

$data = json_encode($data);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Accept: application/json'
));

curl_setopt($ch, CURLOPT_USERPWD, $api_key . ':' . $password);

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

$response = curl_exec($ch);

return $response;   
}

The api I'm talking to is going to insist on using tls v1.2, which is fine, except that my code uses version 1.0.

This is fine if I do this from my local server, but on a production server (Amazon Web Services EC2 instance on AWS Elastic Beanstalk) this is not the case. I suppose this has something to do with setting up my server, but I have no idea what and how to fix it.

Here is a curl snippet from my PHPinfo. Maybe I need to update it or something else? But how would I do that?

enter image description here

+4
2

, , , - .

, . , curl, , , curl 7.34 .

curl_setopt($ch, CURLOPT_SSLVERSION, 6);

, curl? , , Linux, , , . 7.38 TLS v1.2, .

0

TLS ,

bool curl_setopt ( resource $ch , int $option , mixed $value )

: http://php.net/manual/en/function.curl-setopt.php

TLS v1.2

curl_setopt ($setuploginurl, CURLOPT_SSLVERSION, 6); 

CURLOPT_SSLVERSION: CURL_SSLVERSION_DEFAULT (0), CURL_SSLVERSION_TLSv1 (1), CURL_SSLVERSION_SSLv2 (2), CURL_SSLVERSION_SSLv3 (3), CURL_SSLVERSION_TLSv1_0 (4), CURL_SSLVERSION_TLSv1_1 (5) CURL_SSLVERSION_TLSv1_2 (6).

0

Source: https://habr.com/ru/post/1619488/


All Articles