djacobs / PyAPNs

Python library for interacting with the Apple Push Notification service (APNs)
http://pypi.python.org/pypi/apns/
MIT License
1.22k stars 376 forks source link

Why we need key and cert when i get all together #102

Closed marijang closed 9 years ago

marijang commented 9 years ago
import time
import math
import random
from apns import APNs, Frame, Payload

apns = APNs(use_sandbox=True, cert_file='CertProduction.pem', key_file='KeyProduction.pem')

# Send a notification
token_hex = '14a9d626e6585b80c1be071de9b99dab4d7c137be51552b792b52b285e513f32'

# Send a notification
payload = Payload(alert="Hello World!", sound="default", badge=1)
apns.gateway_server.send_notification(token_hex, payload)

For my code i get this error

Traceback (most recent call last): File "C:\env\test\sendpush.py", line 15, in apns.gateway_server.send_notification(token_hex, payload) File "C:\Python27\lib\site-packages\apns.py", line 536, in send_notification self.write(self._get_notification(token_hex, payload)) File "C:\Python27\lib\site-packages\apns.py", line 270, in write return self._connection().write(string) File "C:\Python27\lib\site-packages\apns.py", line 252, in _connection self._connect() File "C:\Python27\lib\site-packages\apns.py", line 228, in _connect self._ssl = wrap_socket(self._socket, self.key_file, self.cert_file) File "C:\Python27\lib\ssl.py", line 891, in wrap_socket ciphers=ciphers) File "C:\Python27\lib\ssl.py", line 509, in init self._context.load_cert_chain(certfile, keyfile) ssl.SSLError: [SSL] PEM lib (_ssl.c:2506)

Why i need to have cert and key file?

jimhorng commented 9 years ago

Seems your pem file has incorrect data, normally, you can just append key pem file into cert pem file and supply cert_file only. If your question is why APNS need cert and key? that's SSL certificate's nature to authenticate and decrypt/encrypt the data on both end. FYR.

marijang commented 9 years ago

So i can call like this?

apns = APNs(use_sandbox=True, cert_file='CertANDKeyProduction.pem')

jimhorng commented 9 years ago

Yes, you can.

marijang commented 9 years ago

i create pem on mac and my python instalation is on widows server. Do i need to generate pem on windows machine?

djacobs commented 9 years ago

This is a support request, not a package bug, so I am closing.