def _build_certificate(self, cert_id): if cert_id is None: return None try: certificate = CloudStoreHelper().get_document(cert_id, Certificate) if certificate is None: raise Exception("as2 certificate is null") if certificate.type == CertificateType.public: certificate.local_file_path = os.path.join( self.conf['app_root_dir'], "cert", "public", certificate.thumbprint + ".pem") else: certificate.local_file_path = os.path.join( self.conf['app_root_dir'], "cert", "private", certificate.thumbprint + ".pem") if not is_none_or_whitespace(certificate.pass_phrase): certificate.pass_phrase = SMIMEHelper.aes_decrypt( certificate.pass_phrase, self.conf['app_secure_key']) if os.path.exists(certificate.local_file_path): return certificate local_path = os.path.dirname(certificate.local_file_path) if not os.path.exists(local_path): os.makedirs(local_path) if not DFSHelper.download2file(certificate.dfs_file_path, certificate.local_file_path): raise Exception("download certificate file from dfs failed") return certificate except: raise Exception( "get as2 certificate failed; certificate-id: {id}, due to {msg}" .format(id=cert_id, msg=sys.exc_info()[1]))
def test_aes_decrypt(self): plain = SMIMEHelper.aes_decrypt(data='gvTFH3+s+OqiyC0Lq5VhbA==', key='f290f63f-7310-4bd2-ac7d-17fd866354d1') assert_not_equal(None, plain) assert_equal('123456', plain)