| 1 |
from django.core.exceptions import ImproperlyConfigured |
| 2 |
|
| 3 |
|
| 4 |
class BaseConfig(object): |
| 5 |
def get_apns_certificate(self, application_id=None): |
| 6 |
raise NotImplementedError |
| 7 |
|
| 8 |
def get_apns_use_sandbox(self, application_id=None): |
| 9 |
raise NotImplementedError |
| 10 |
|
| 11 |
def get_apns_use_alternative_port(self, application_id=None): |
| 12 |
raise NotImplementedError |
| 13 |
|
| 14 |
def get_fcm_api_key(self, application_id=None): |
| 15 |
raise NotImplementedError |
| 16 |
|
| 17 |
def get_gcm_api_key(self, application_id=None): |
| 18 |
raise NotImplementedError |
| 19 |
|
| 20 |
def get_wns_package_security_id(self, application_id=None): |
| 21 |
raise NotImplementedError |
| 22 |
|
| 23 |
def get_wns_secret_key(self, application_id=None): |
| 24 |
raise NotImplementedError |
| 25 |
|
| 26 |
def get_post_url(self, cloud_type, application_id=None): |
| 27 |
raise NotImplementedError |
| 28 |
|
| 29 |
def get_error_timeout(self, cloud_type, application_id=None): |
| 30 |
raise NotImplementedError |
| 31 |
|
| 32 |
def get_max_recipients(self, cloud_type, application_id=None): |
| 33 |
raise NotImplementedError |
| 34 |
|
| 35 |
def get_applications(self): |
| 36 |
"""Returns a collection containing the configured applications.""" |
| 37 |
|
| 38 |
raise NotImplementedError |
| 39 |
|
| 40 |
|
| 41 |
def check_apns_certificate(ss): |
| 42 |
mode = "start" |
| 43 |
for s in ss.split("\n"): |
| 44 |
if mode == "start": |
| 45 |
if "BEGIN RSA PRIVATE KEY" in s or "BEGIN PRIVATE KEY" in s: |
| 46 |
mode = "key" |
| 47 |
elif mode == "key": |
| 48 |
if "END RSA PRIVATE KEY" in s or "END PRIVATE KEY" in s: |
| 49 |
mode = "end" |
| 50 |
break |
| 51 |
elif s.startswith("Proc-Type") and "ENCRYPTED" in s: |
| 52 |
raise ImproperlyConfigured("Encrypted APNS private keys are not supported") |
| 53 |
|
| 54 |
if mode != "end": |
| 55 |
raise ImproperlyConfigured("The APNS certificate doesn't contain a private key") |