I'm having problem with using APNS with PHP on Linux server. I am using simplepush.php
example script with this stream_context
settings ($passphrase is set):
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert','/var/www/html/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
stream_context_set_option($ctx, 'ssl', 'cafile', '/usr/lib/ssl/certs/Entrust_Root_Certification_Authority.pem');
and trying to connect on gateway.sandbox.push.apple.com:2195
:
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp){
exit("Failed to connect: $err $errstr" . PHP_EOL);
}
When I run the script it says:
PHP Warning: stream_socket_client(): Failed to enable crypto in /var/www/html/test2.php on line 27
PHP Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /var/www/html/test2.php on line 27
Failed to connect: 0
Telnet test:
Trying 17.172.232.46...
Connected to gateway.sandbox.push-apple.com.akadns.net.
Escape character is '^]'.
Server's entrust certificates:
/usr/lib/ssl/certs/Entrust.net_Global_Secure_Personal_CA.pem
/usr/lib/ssl/certs/Entrust.net_Global_Secure_Server_CA.pem
/usr/lib/ssl/certs/Entrust.net_Premium_2048_Secure_Server_CA.pem
/usr/lib/ssl/certs/Entrust.net_Secure_Personal_CA.pem
/usr/lib/ssl/certs/Entrust.net_Secure_Server_CA.pem
/usr/lib/ssl/certs/Entrust_Root_Certification_Authority.pem
777 permission are given on all certificates and also to ck.pem
file which is located in the same folder as simplepush.php
file (/var/www/html)
Also, I believe that ck.pem
is valid certificate, because this connections success when the call is executed from Mac terminal.
SSL connection from terminal:
azureuser@myserver:/var/www/html$ openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert /var/www/html/ck.pem -CAfile /usr/lib/ssl/certs/Entrust_Root_Certification_Authority.pem
Enter pass phrase for /var/www/html/ck.pem:
CONNECTED(00000003)
depth=2 O = Entrust.net, OU = www.entrust.net/CPS_2048 incorp. by ref. (limits liab.), OU = (c) 1999 Entrust.net Limited, CN = Entrust.net Certification Authority (2048)
verify return:1
depth=1 C = US, O = "Entrust, Inc.", OU = www.entrust.net/rpa is incorporated by reference, OU = "(c) 2009 Entrust, Inc.", CN = Entrust Certification Authority - L1C
verify return:1
depth=0 C = US, ST = California, L = Cupertino, O = Apple Inc., CN = gateway.sandbox.push.apple.com
verify return:1
140195332839072:error:140790E5:SSL routines:SSL23_WRITE:ssl handshake failure:s23_lib.c:177:
---
Certificate chain
0 s:/C=US/ST=California/L=Cupertino/O=Apple Inc./CN=gateway.sandbox.push.apple.com
i:/C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
1 s:/C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
i:/O=Entrust.net/OU=www.entrust.net/CPS_2048 incorp. by ref. (limits liab.)/OU=(c) 1999 Entrust.net Limited/CN=Entrust.net Certification Authority (2048)
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIFMzCCBBugAwIBAgIETCMmsDANBgkqhkiG9w0BAQUFADCBsTELMAkGA1UEBhMC
VVMxFjAUBgNVBAoTDUVudHJ1c3QsIEluYy4xOTA3BgNVBAsTMHd3dy5lbnRydXN0
Lm5ldC9ycGEgaXMgaW5jb3Jwb3JhdGVkIGJ5IHJlZmVyZW5jZTEfMB0GA1UECxMW
KGMpIDIwMDkgRW50cnVzdCwgSW5jLjEuMCwGA1UEAxMlRW50cnVzdCBDZXJ0aWZp
Y2F0aW9uIEF1dGhvcml0eSAtIEwxQzAeFw0xNDA1MjMxNzQyNDJaFw0xNjA1MjQw
NzA1MTNaMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRIwEAYD
VQQHEwlDdXBlcnRpbm8xEzARBgNVBAoTCkFwcGxlIEluYy4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oeqRXQ2b4Um3dT/LPmzMkKmgEt9epKNBLA6lSkL+IzEnF
wLQCHkL3BgvV20n5D8syzREV+8RKmSqiYmrF8dFq8cDcstu2joEKd173EfrymWW1
fMeaYTbjrn+vNkgM94+M4c/JnIDOhiPPbeAx9TESQZH+/6S98hrbuPIIlmaOJsOT
GMOUWeOTHXTCfGb1EM4SPVcyCW28TlWUBl8miqnsEO8g95jZZ25wFANlVxhfxBnP
fwUYU5NTM3h0xi3rIlXwAKD6zLKipcQ/YXRx7oMYnAm53tfU2MxV
-----END CERTIFICATE-----
subject=/C=US/ST=California/L=Cupertino/O=Apple Inc./CN=gateway.sandbox.push.apple.com
issuer=/C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
---
Acceptable client certificate CA names
/C=US/O=Apple Inc./OU=Apple Certification Authority/CN=Apple Root CA
/C=US/O=Apple Inc./OU=Apple Worldwide Developer Relations/CN=Apple Worldwide Developer Relations Certification Authority
/C=US/O=Apple Inc./OU=Apple Certification Authority/CN=Apple Application Integration Certification Authority
---
SSL handshake has read 3143 bytes and written 2032 bytes
---
New, TLSv1/SSLv3, Cipher is AES256-SHA
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
Protocol : TLSv1.2
Cipher : AES256-SHA
Session-ID:
Session-ID-ctx:
Master-Key: 40C185D8F81ABD51E8BAF4BA863949A6A006AE80CEE04E2989A2E0269764A14107F0D3933E2A1A65D6825C61934F51F8
Key-Arg : None
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1455228997
Timeout : 300 (sec)
Verify return code: 0 (ok)
---
Only thing that caught my eye here is this part:
routines:SSL23_WRITE:ssl handshake failure:s23_lib.c:177:
I read that it is some sort of bug on ubuntu version, and that it can be fixed by doing ssl downgrade, but I don't really believe if that actually can be a reason.
Conclusion:
- Root certificates that apns is requesting are set
ck.pem
is valid certificate (using password) and also absolute paths are set for certificates in thesimplepush.php
filetelnet
to apns is working (ports are open)- Permissions (777) are set for
ck.pem
,simplepush.php
and all the root certificates openssl s_client ...
is returningVerify return code: 0 (ok)
and the only suspicious thing is thatssl handshake failure:s23_lib.c:177
I am missing something here (probably on my server configuration) but I ran out of ideas what it might be, and now it has become so frustrating :)
NOTE: I understand this topic could be a duplicate, but I searched a lot about all that associated with apns push, and read many topics related to this problem, and now I'm pretty sure that I have everything set and configured on server, but I'm still missing something.
Do you have any ideas what might cause this problem? Thanks in advance.