PyAPN 创建 PEM 文件的正确方法 [英] PyAPN right way to create PEM files

查看:33
本文介绍了PyAPN 创建 PEM 文件的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这可能是由于缺乏更好的知识,但我似乎无法运行它.到目前为止,如何为 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.p12key.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!

推荐答案

好的,经过一些谷歌搜索和尝试和错误,我终于得到了一个发送确认 Sent push message to APNS gateway fromPyAPNs.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆