14

I'm trying to implement push notifications for iphone based on PyAPNs

When I run it on local but it blocks and prompts me to enter the passphrase manually and doesn't work until I do

I don't know how to set it up so to work without prompt

This is my code:

from apns import APNs, Payload
import optparse
import os


certificate_file = here(".." + app.fichier_PEM.url   )        
token_hex = '0c99bb3d077eeacdc04667d38dd10ca1a'
pass_phrase = app.mot_de_passe



apns = APNs(use_sandbox=True, cert_file= certificate_file)
payload = Payload(alert = message.decode('utf-8'), sound="default", badge=1)
apns.gateway_server.send_notification(token_hex, payload)


# Get feedback messages
for (token_hex, fail_time) in apns.feedback_server.items():
    print "fail: "+fail_time
icodebuster
  • 8,890
  • 7
  • 62
  • 65
Armance
  • 5,350
  • 14
  • 57
  • 80

2 Answers2

25

When you create a .pem file without phrase specify -nodes

To Create .pem file without phrase

openssl pkcs12 -nocerts -out Pro_Key.pem -in App.p12 -nodes

To Create .pem file with phrase

openssl pkcs12 -nocerts -out Pro_Key.pem -in App.p12

If you have a .pem file with password you can get rid of its password for PyAPNs using the following

openssl rsa -in haspassword.pem -out nopassword.pem

Refer

for make certificates and other configurations.

Some Python library for interacting with the Apple Push Notification service (APNs)

icodebuster
  • 8,890
  • 7
  • 62
  • 65
  • The p12 file which you are using. You did you follow raywenderlich tuts – icodebuster Dec 04 '13 at 12:50
  • No ,the pem file and passphrase are sent to me separately by the client. So if I understand in the process of creation of the pem file should contain the passphrase? but wouldnt that be in contradiction of what is the purpose of passphrase in first place (security)? – Armance Dec 04 '13 at 12:57
  • 1
    @ArmanceWissal If you're going to hardcode the passphrase into your code, it seems to me that you might as well just remove the passphrase from the certificate altogether. What security are you gaining if the passphrase-encrypted certificate is sitting on the same machine with the passphrase? **Also check the update answer on how to remove password from existing .pem file** – icodebuster Dec 04 '13 at 13:59
  • I would like to remove it but the client refuses so I really need to input the paraphrase in my code – Armance Dec 04 '13 at 14:03
  • Is it possible to use PHP. or show [this](https://github.com/djacobs/PyAPNs/issues/19) to the client :) – icodebuster Dec 04 '13 at 14:05
  • No the whole app is already developped in python. I will show him but you know how clients are,he won't listen to me. Is that mean that there is no way I can code the passphrase? I can change the pyApns plugin if there is another one that can solve my issue.Thanks – Armance Dec 04 '13 at 14:15
  • Also take a look at https://bitbucket.org/sardarnl/apns-client/ this wrapper takes password. – icodebuster Dec 04 '13 at 14:56
0

Try to use

apns = APNs(use_sandbox=True, cert_file='XYZCert.pem', key_file='XYZKey.pem')

where you specify both the certificate and the private key.

quik_silv
  • 2,397
  • 2
  • 15
  • 21