-->

Creating .pem file from pushnotification with PHP

2020-08-01 04:04发布

问题:

i'm trying to implement push notification in my application, for this i tried to use easyApns, i follow the steps, and implement the classes on my linux based. but unfortunately i stil betting some errors related to certificates.

my error is:

Warning: stream_socket_client() [function.stream-socket-client]: SSL operation failed with code 1. OpenSSL Error messages: error:14094416:SSL routines:SSL3_READ_BYTES:sslv3 alert certificate unknown in /var/www/html/apns/classes/class_APNS.php on line 401

Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /var/www/html/apns/classes/class_APNS.php on line 401

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /var/www/html/apns/classes/class_APNS.php on line 401

Notice: Failed to connect to APNS: 0 . 1) APNS::__construct -> File: apns.php (line 50) 2) APNS::_fetchMessages -> File: class_APNS.php (line 217) 3) APNS::_pushMessage -> File: class_APNS.php (line 376) 4) APNS::_triggerError -> File: class_APNS.php (line 405) in /var/www/html/apns/classes/class_APNS.php on line 509

i gusse it's an error related to the certificate (the .pem file)

my .pem file wa generated using the following command

openssl pkcs12 -in apns-dev-cert.p12 -out apns-dev-cert.pem -nodes -clcerts

and it was placed on the server (linux based) and given chmod 644 privileges

should i do any thing else.....

回答1:

Are you able to connect to apns using your certificate? try following command to check that:

$ openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert YourSSLCertAndPrivateKey.pem -debug -showcerts -CAfile server-ca-cert.pem

If the command terminates, you are not able to connect. If it continues running and lets you type into the socket, you have connected successfully.



回答2:

I have found out that for the command to work it is necessary to :

  1. create a certificate signing request (.csr) and upload it to the apple dev portal
  2. download the provided .p12 license
  3. transform it to a pem file using the certificate + your machine private key
  4. download and install the certificate from Entrust

reference: https://developer.apple.com/library/ios/#technotes/tn2265/_index.html



回答3:

I have the same issue. Downloaded the .p12 file then $ openssl pkcs12 -in apns-dev-cert.p12 -out apns-dev-cert.pem -nodes -clcerts then using Nilesh command: $ openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert YourSSLCertAndPrivateKey.pem -debug -showcerts -CAfile server-ca-cert.pem then i get this error

unable to load client certificate private key file 140405386606400:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:696:Expecting: ANY PRIVATE KEY

thanks



回答4:

Double check that before to generate the .pem, you export correctly the "2" items from Keychain:

Apple Development IOS Push Services + user name key.

Then export the2 items