django_ses/utils.py
def certificate(self):
        """
        Retrieves the certificate used to sign the event message.

        :returns: None if the cert cannot be retrieved. Else, gets the cert
        caches it, and returns it, or simply returns it if already cached.
        """
        cert_url = self._get_cert_url()
        if not cert_url:
            return None

        if cert_url in _CERT_CACHE:
            return _CERT_CACHE[cert_url]

        # Only load certificates from a certain domain?
        # Without some kind of trusted domain check, any old joe could
        # craft a event message and sign it using his own certificate
        # and we would happily load and verify it.
        try:
            import requests
            from requests import RequestException
        except ImportError:
            raise ImproperlyConfigured(self._REQ_DEP_TMPL % "`requests`")

        try:
            from cryptography import x509
        except ImportError:
            raise ImproperlyConfigured(self._REQ_DEP_TMPL % "`cryptography`")

        # We use requests because it verifies the https certificate when
        # retrieving the signing certificate. If https was somehow hijacked
        # then all bets are off.
        try:
            response = requests.get(cert_url, timeout=10)
            response.raise_for_status()
        except RequestException as exc:
            logger.warning(
                "Network error downloading certificate from " "%s: %s",
                cert_url,
                exc,
            )
            _CERT_CACHE[cert_url] = None
            return _CERT_CACHE[cert_url]

        # Handle errors loading the certificate.
        # If the certificate is invalid then return
        # false as we couldn't verify the message.
        try:
            _CERT_CACHE[cert_url] = x509.load_pem_x509_certificate(response.content)
        except ValueError as e:
            logger.warning('Could not load certificate from %s: "%s"', cert_url, e)
            _CERT_CACHE[cert_url] = None

        return _CERT_CACHE[cert_url]

        Retrieves the certificate used to sign the event message.

        :returns: None if the cert cannot be retrieved. Else, gets the cert
        caches it, and returns it, or simply returns it if already cached.
        
Retrieves the certificate used to sign the event message.
Retrieves the certificate used to sign the event message .
def certificate(self):
        cert_url = self._get_cert_url()
        if not cert_url:
            return None
        if cert_url in _CERT_CACHE:
            return _CERT_CACHE[cert_url]
        try:
            import requests
            from requests import RequestException
        except ImportError:
            raise ImproperlyConfigured(self._REQ_DEP_TMPL % "`requests`")
        try:
            from cryptography import x509
        except ImportError:
            raise ImproperlyConfigured(self._REQ_DEP_TMPL % "`cryptography`")
        try:
            response = requests.get(cert_url, timeout=10)
            response.raise_for_status()
        except RequestException as exc:
            logger.warning(
                "Network error downloading certificate from " "%s: %s",
                cert_url,
                exc,
            )
            _CERT_CACHE[cert_url] = None
            return _CERT_CACHE[cert_url]
        try:
            _CERT_CACHE[cert_url] = x509.load_pem_x509_certificate(response.content)
        except ValueError as e:
            logger.warning('Could not load certificate from %s: "%s"', cert_url, e)
            _CERT_CACHE[cert_url] = None
        return _CERT_CACHE[cert_url]
def certificate ( self ) : cert_url = self . _get_cert_url ( ) if not cert_url : return None if cert_url in _CERT_CACHE : return _CERT_CACHE [ cert_url ] try : import requests from requests import RequestException except ImportError : raise ImproperlyConfigured ( self . _REQ_DEP_TMPL % "`requests`" ) try : from cryptography import x509 except ImportError : raise ImproperlyConfigured ( self . _REQ_DEP_TMPL % "`cryptography`" ) try : response = requests . get ( cert_url , timeout = 10 ) response . raise_for_status ( ) except RequestException as exc : logger . warning ( "Network error downloading certificate from " "%s: %s" , cert_url , exc , ) _CERT_CACHE [ cert_url ] = None return _CERT_CACHE [ cert_url ] try : _CERT_CACHE [ cert_url ] = x509 . load_pem_x509_certificate ( response . content ) except ValueError as e : logger . warning ( 'Could not load certificate from %s: "%s"' , cert_url , e ) _CERT_CACHE [ cert_url ] = None return _CERT_CACHE [ cert_url ]
Retrieves the certificate used to sign the event message.
Retrieves the certificate used to sign the event message .
"""
        Retrieves the certificate used to sign the event message.

        :returns: None if the cert cannot be retrieved. Else, gets the cert
        caches it, and returns it, or simply returns it if already cached.
        """ # Only load certificates from a certain domain? # Without some kind of trusted domain check, any old joe could # craft a event message and sign it using his own certificate # and we would happily load and verify it. # We use requests because it verifies the https certificate when # retrieving the signing certificate. If https was somehow hijacked # then all bets are off. # Handle errors loading the certificate. # If the certificate is invalid then return # false as we couldn't verify the message.
None if the cert cannot be retrieved. Else, gets the cert
caches it, and returns it, or simply returns it if already cached.
None if the cert cannot be retrieved . Else gets the cert caches it and returns it or simply returns it if already cached .
self