#NEWLINE# @ property #NEWLINE# def certificate( self ) : #NEWLINE# #INDENT# "\n        Retrieves the certificate used to sign the bounce message.\n\n        TODO: Cache the certificate based on the cert URL so we don't have to\n        retrieve it for each bounce message. *We would need to do it in a\n        secure way so that the cert couldn't be overwritten in the cache*\n        " #NEWLINE# if ( not hasattr ( self , '_certificate' ) ) : #NEWLINE# #INDENT# cert_url = self . _get_cert_url ( ) #NEWLINE# if ( not cert_url ) : #NEWLINE# #INDENT# self . _certificate = None #NEWLINE# return self . _certificate #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# import requests #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# raise ImproperlyConfigured ( 'requests is required for bounce message verification.' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# import M2Crypto #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# raise ImproperlyConfigured ( 'M2Crypto is required for bounce message verification.' ) #NEWLINE# #UNINDENT# response = requests . get ( cert_url ) #NEWLINE# if ( response . status_code != 200 ) : #NEWLINE# #INDENT# logger . warning ( 'Could not download certificate from %s: "%s"' , cert_url , response . status_code ) #NEWLINE# self . _certificate = None #NEWLINE# return e . _certificate #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . _certificate = M2Crypto . X509 . load_cert_string ( response . content ) #NEWLINE# #UNINDENT# except M2Crypto . X509 . X509Error as e : #NEWLINE# #INDENT# logger . warning ( 'Could not load certificate from %s: "%s"' , cert_url , e ) #NEWLINE# self . _certificate = None #NEWLINE# #UNINDENT# #UNINDENT# return self . _certificate