python apns-client 的一些小问题

来源:互联网 发布:坑爹淘宝买家秀 编辑:程序博客网 时间:2024/05/22 11:51

apns-client 地址:https://bitbucket.org/sardarnl/apns-client

你搜到这里应该已经知道apns-client是个什么,下面我来说一下我碰到的一些问题。


一、OpenSSL.crypto.error: [] (类似是这样,当时我没有记录,如果有空我回去看一下具体是什么错误回来改一下。)

我还没有仔细看OpenSSL所以也没法说这个问题的细节,但是在apnsclient/certificate.py下的BaseCertificate().__init__里可以看到注释。

大意是certificate是在BEGIN/END CERTIFICATE之间,key在BEGEIN/END RSA PRIVATE KEY之间,看不懂前面一句的打开你的两个文件看一下就知道了。

我解决这个问题的方法是直接把这两部分粘到一个文件里,传进去当cert_file


二、OpenSSL.SSL.Error: [('SSL routines', 'SSL3_READ_BYTES', 'sslv3 alert handshake failure')]

这个问题着实已经超出我的能力范畴,还好社区有大神解决了。


apnsclient/backends/stdio.py

 class Certificate(BaseCertificate):
     """ pyOpenSSL certificate implementation. """
 
-    def load_context(self, cert_string=None, cert_file=None, key_string=None, key_file=None, passphrase=None):
+    def load_context(self, cert_string=None, cert_file=None, key_string=None, key_file=None, passphrase=None, context_method=OpenSSL.SSL.TLSv1_METHOD):
         """ Initialize and load certificate context. """
-        context = OpenSSL.SSL.Context(OpenSSL.SSL.SSLv3_METHOD)
+        context = OpenSSL.SSL.Context(context_method)
         if passphrase is not None and not isinstance(passphrase, six.binary_type):
             passphrase = six.b(passphrase)
         

复制粘贴效果不好,这个pull request的链接:https://bitbucket.org/sardarnl/apns-client/pull-request/11/add-option-to-configure-certificate/diff

直接改一下就好了。

写个文章记录一下。

0 0
原创粉丝点击