问题
I know this might be due to lack of better knowledge, but I seem not to be able to get this running.
What is the right way as of today how to create the correct certificates / pem
files for PyAPN
? There are so many instructions at different dates that report different approaches - I am confused.
I exported the Apple push certificate and the private key into cert.p12
and key.p12
respectively on my mac. Then I ran the commands below and uploaded them to my server.
openssl pkcs12 -nocerts -out key.pem -in key.p12
openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12
Here's my modified apns-send.py
:
certificate_file = '/path/to/apnsCerts/cert.pem'
key_file = '/path/to/apnsCerts/key.pem'`
I try:
./apns-send.py -p fc0112d3936f738d9d4c197c50dbf80304ab13fca4ab19d539ecacf65ce58b34 -m 'Hello World'
Yet it fails with:
Traceback (most recent call last):
File "./apns-send.py", line 45, in <module>
apns.gateway_server.send_notification(options.push_token, payload)
File "/buyo/push/ios/apns.py", line 543, in send_notification
self.write(self._get_notification(token_hex, payload))
File "/buyo/push/ios/apns.py", line 267, in write
return self._connection().write(string)
File "/buyo/push/ios/apns.py", line 248, in _connection
self._connect()
File "/buyo/push/ios/apns.py", line 224, in _connect
self._ssl = wrap_socket(self._socket, self.key_file, self.cert_file)
File "/usr/lib/python2.7/ssl.py", line 487, in wrap_socket
ciphers=ciphers)
File "/usr/lib/python2.7/ssl.py", line 241, in __init__
ciphers)
ssl.SSLError: [Errno 336265218] _ssl.c:355: error:140B0002:SSL routines:SSL_CTX_use_PrivateKey_file:system lib
I appreciate any help or suggestions where it could fail. Thanks in advance!
回答1:
Ok, after some googling and trial and errors I finally have gotten through to get a send confirmation Sent push message to APNS gateway
from PyAPNs
.
Here are the steps how I had to adjust my pem
files.
openssl pkcs12 -in cert.p12 -out cert.pem -clcerts -nokeys
openssl pkcs12 -in key.p12 -out key.pem -nocerts
openssl rsa -in key.pem -out keyNoPasswd.pem
cat keyNoPasswd.pem > mergedPushCertificate.pem
cat cert.pem >> mergedPushCertificate.pem
Use mergedPushCertificate.pem
as certificate and key in PyAPNs.
Based on https://github.com/project-imas/mdm-server/issues/6
来源:https://stackoverflow.com/questions/42350151/pyapn-right-way-to-create-pem-files