APNS question with django

I am using the following project to include APNS in my project:

https://github.com/stephenmuss/django-ios-notifications

I can send and receive push notifications on my production app, but there are strange problems in sandboxes that I cannot solve. He is not constantly connecting to the push service. When I manually execute _connect()

in classes APNService

or FeedbackService

, I get the following error:

  File "/Users/MyUser/git/prod/django/ios_notifications/models.py", line 56, in _connect
    self.connection.do_handshake()
Error: [('SSL routines', 'SSL3_READ_BYTES', 'sslv3 alert handshake failure')]

      

I tried re-creating the APN certificate several times and kept getting the same error. Is there something else that I am missing?

I am using gateway.push.apple.com and gateway.sandbox.push.apple.com endpoints to connect to the service. Is there anything else I should look into? I read the following:

Apns php error "Failed to connect to APNS: 110 Connection timed out.

Converting PKCS # 12 certificate to PEM using OpenSSL

PHP usage error for iPhone APNS

+3


source to share


2 answers


It turns out Apple changed the ssl context from SSL3 to TLSv1 in development. They will do it in Production eventually (not sure when). The following link shows my pull request that was accepted into the above project:

https://github.com/stephenmuss/django-ios-notifications/commit/879d589c032b935ab2921b099fd3286440bc174e

Basically, use OpenSSL.SSL.TLSv1_METHOD

if you are using python or something similar in other languages.

Although it OpenSSL.SSL.SSLv3_METHOD

works in production, it may not work in the near future. OpenSSL.SSL.TLSv1_METHOD

works in production and development.



UPDATE

Apple will remove support for SSL 3.0 in production on October 29, 2014 due to lack of poodle.

https://developer.apple.com/news/?id=10222014a

+5


source


I was working on APN using python-django, for that you need three things: URL, PORT and Certificate provided by Apple for authentication.

views.py



import socket, ssl, json, struct

theCertfile = '/tmp/abc.cert'      ## absolute path where certificate file is placed.
ios_url = 'gateway.push.apple.com'
ios_port = 2195
deviceToken = '3234t54tgwg34g'    ## ios device token to which you want to send notification

def ios_push(msg, theCertfile, ios_url, ios_port, deviceToken):

    thePayLoad = {
               'aps': {
                    'alert':msg,
                    'sound':'default',
                    'badge':0,
                    },
             }

    theHost = ( ios_url, ios_port )
    data = json.dumps( thePayLoad )

    deviceToken = deviceToken.replace(' ','')
    byteToken = deviceToken.decode('hex') # Python 2

    theFormat = '!BH32sH%ds' % len(data)
    theNotification = struct.pack( theFormat, 0, 32, byteToken, len(data), data )

    # Create our connection using the certfile saved locally
    ssl_sock = ssl.wrap_socket( socket.socket( socket.AF_INET, socket.SOCK_STREAM ), certfile = theCertfile )
    ssl_sock.connect( theHost )

    # Write out our data
    ssl_sock.write( theNotification )

    # Close the connection -- apple would prefer that we keep
    # a connection open and push data as needed.
    ssl_sock.close()

      

Hope this works for you.

-1


source







All Articles