def create_request(self, url, **kwargs): headers = kwargs['headers'] data = kwargs['data'] params = { 'certificate': self.local_certificate, 'digest_algo': 'SHA1', 'signature_algo': 'RSA-SHA1', 'msg_encrypt_algo': 'AES', 'key_encrypt_algo': 'RSA', 'payload': data, 'remote_public_key': self.server_certificate.public_key, 'url': url, 'is_request': True, 'headers': headers } rm = OutboundMessage(**params) rm.encrypt() (headers, content) = rm.to_message_data() return (url, headers, content)
def process_response(self, request, response): prt_list = PROTECT_LIST + ['/session_token/'] if response.status_code == 403: return response if not (request.path in prt_list): return None server_cert = DjangoCertificateModel.get() params = { 'certificate': server_cert, 'digest_algo': 'SHA1', 'signature_algo': 'RSA-SHA1', 'msg_encrypt_algo': 'AES', 'key_encrypt_algo': 'RSA', 'payload': response.content, 'remote_public_key': self.client_certificate.public_key, 'is_request': False, 'url': '', 'headers': {}, } response_msg = OutboundMessage(**params) response_msg.encrypt() (headers, encrypted) = response_msg.to_message_data() # insert headers fetched above into the response headers # and replace the content with above encrypted content. for key in headers.keys(): response[key] = headers[key] response.content = encrypted.encode('hex') return response