PyAPN创建PEM文件的正确方法 [英] PyAPN right way to create PEM files
问题描述
我知道这可能是由于缺乏更好的知识而引起的,但是我似乎无法正常运行.
到目前为止,什么是正确的方法,如何为PyAPN
创建正确的证书/pem
文件?在不同的日期有太多的说明报告了不同的方法-我很困惑.
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.
我在Mac上分别将Apple推送证书和私钥导出到了cert.p12
和key.p12
中.然后,我运行下面的命令,并将其上传到我的服务器.
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
这是我修改后的apns-send.py
:
certificate_file = '/path/to/apnsCerts/cert.pem'
key_file = '/path/to/apnsCerts/key.pem'`
我尝试:
./apns-send.py -p fc0112d3936f738d9d4c197c50dbf80304ab13fca4ab19d539ecacf65ce58b34 -m 'Hello World'
但是它失败了:
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!
推荐答案
好吧,经过一些谷歌搜索,反复试验和错误之后,我终于弄明白了从PyAPNs
获得发送确认Sent push message to APNS gateway
.
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
.
以下是我必须调整pem
文件的步骤.
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
使用mergedPushCertificate.pem
作为证书并键入PyAPN.
基于 https://github.com/project-imas/mdm-server/问题/6
Use mergedPushCertificate.pem
as certificate and key in PyAPNs.
Based on https://github.com/project-imas/mdm-server/issues/6
这篇关于PyAPN创建PEM文件的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!