[Django]-APNS issue with django

5👍

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

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

Basically, use OpenSSL.SSL.TLSv1_METHOD if you’re using python or something similar in other languages.

Although 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 SSL 3.0 support in production on October 29th, 2014 due to the poodle flaw.

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

👤KVISH

-1👍

I have worked on APN using python-django, for this 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()

Hopefully this would work for you.

Leave a comment