From 664a0fb4a87b87de62e83426b0a3708b3e1cd38c Mon Sep 17 00:00:00 2001 From: Tom Nguyen Date: Wed, 13 May 2015 06:06:46 +0000 Subject: [PATCH] Added support for ca certificate --- apns.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/apns.py b/apns.py index 826135f..aaf3145 100644 --- a/apns.py +++ b/apns.py @@ -95,7 +95,7 @@ class APNs(object): """A class representing an Apple Push Notification service connection""" - def __init__(self, use_sandbox=False, cert_file=None, key_file=None, enhanced=False): + def __init__(self, use_sandbox=False, cert_file=None, key_file=None, enhanced=False, ca_certs=None): """ Set use_sandbox to True to use the sandbox (test) APNs servers. Default is False. @@ -104,6 +104,7 @@ def __init__(self, use_sandbox=False, cert_file=None, key_file=None, enhanced=Fa self.use_sandbox = use_sandbox self.cert_file = cert_file self.key_file = key_file + self.ca_certs = ca_certs self._feedback_connection = None self._gateway_connection = None self.enhanced = enhanced @@ -157,7 +158,8 @@ def feedback_server(self): self._feedback_connection = FeedbackConnection( use_sandbox = self.use_sandbox, cert_file = self.cert_file, - key_file = self.key_file + key_file = self.key_file, + ca_certs = self.ca_certs ) return self._feedback_connection @@ -168,6 +170,7 @@ def gateway_server(self): use_sandbox = self.use_sandbox, cert_file = self.cert_file, key_file = self.key_file, + ca_certs = self.ca_certs, enhanced = self.enhanced ) return self._gateway_connection @@ -177,10 +180,11 @@ class APNsConnection(object): """ A generic connection class for communicating with the APNs """ - def __init__(self, cert_file=None, key_file=None, timeout=None, enhanced=False): + def __init__(self, cert_file=None, key_file=None, timeout=None, enhanced=False, ca_certs=None): super(APNsConnection, self).__init__() self.cert_file = cert_file self.key_file = key_file + self.ca_certs = ca_certs self.timeout = timeout self._socket = None self._ssl = None @@ -210,6 +214,7 @@ def _connect(self): self._last_activity_time = time.time() self._socket.setblocking(False) self._ssl = wrap_socket(self._socket, self.key_file, self.cert_file, + ca_certs=self.ca_certs, do_handshake_on_connect=False) while True: try: @@ -227,7 +232,7 @@ def _connect(self): # Fallback for 'SSLError: _ssl.c:489: The handshake operation timed out' for i in xrange(3): try: - self._ssl = wrap_socket(self._socket, self.key_file, self.cert_file) + self._ssl = wrap_socket(self._socket, self.key_file, self.cert_file, ca_certs=self.ca_certs) break except SSLError, ex: if ex.args[0] == SSL_ERROR_WANT_READ: