Skip to content
Advertisement

PHP cURL error “security library failure.”

I’m using the following code to send an apns notification for iOS. It was working fine before but out of no where I started getting this response from cURL “security library failure.” with code 0.

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($sample_alert));
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_SSLCERT, $certificate);
    curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $pem_secret);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $response = curl_exec($ch);

This issue only seems to be happening in my development environment, no matter what data is passed in.

$url = “https://api.development.push.apple.com/3/device/$device_token”;

$sample_alert =

           {"aps":{"alert":"sample notif message","badge":"badge","sound":"default"}

$headers =

["apns-topic: apns.topic"]

Advertisement

Answer

We are facing same issue. Our machine is running CentOS 7, PHP 7, Curl 7.75.

We added the curl option curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_MAX_TLSv1_2);, to forcefully limit TLS to maximum version 1.2 but it does not work since our PHP version throws a warning that it does not know the constant CURL_SSLVERSION_MAX_TLSv1_2.

We had a workaround to use the integer value of the said constant instead of using the defined constant. Checked the value found at curl repo here.

CURL_SSLVERSION_MAX_TLSv1_2 is defined to be (CURL_SSLVERSION_TLSv1_2 << 16) which is 6 << 16 and turns out to be 393216

Thus, we added this curl option curl_setopt($ch, CURLOPT_SSLVERSION, 393216); and it successfully sent a request without the “security library failure” error.

PS. This is just a workaround to set the Maximum TLS version.

PPS. As stated in this manual, you should let curl use the default SSL versions. So use this at your own risk. This answer is just a workaround.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement