Reputation: 33
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"]
Upvotes: 2
Views: 1422
Reputation: 66
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.
Upvotes: 2
Reputation: 165
We had a similar error, just like you say it started with development and yesterday it happened in production as well.
We solved by updating curl on the server. Try launching the same curl on your machine, for example on my Mac push are working fine with this version:
curl 7.64.1 (x86_64-apple-darwin19.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.39.2
While on the server with an older curl version we had the same error security library failure. If you can't update curl, try adding this parameters to the call
--tls-max 1.2
Upvotes: 0