def send(self, payload): # ensure payload is proper check_payload(payload) endpoint = payload.pop('endpoint') # encrypt payload enc_payload = process_payload(SYSID, payload) # get websocket for endpoint ws = self._get_ws(endpoint) # send encrypted payload ws.send(enc_payload)
def send(self, payload): # ensure payload is proper check_payload(payload) endpoint = payload.pop('endpoint') # encrypt payload enc_payload = process_payload(SYSID, payload) # send encrypted payload url = self.base_url + endpoint + '/' + SYSID response = self.session.request('POST', url, data=enc_payload) response.raise_for_status() # decrypt response dec_payload = unprocess_payload(SYSID, response.content) return dec_payload
async def rekey(request, sysid): """ Handle a client rekey request. """ payload = unprocess_payload(sysid, request.body) new_key = payload['key'] if not new_key: new_key = gen_random_key(int(payload['length'])) return_payload = process_payload(sysid, {'key': new_key}) # set new key globally for server set_key(sysid, new_key) return response.text(return_payload)
async def rekey(request, ws, sysid): """ Handle a client rekey request. """ data = await ws.recv() payload = unprocess_payload(sysid, data) new_key = payload['key'] if not new_key: new_key = gen_random_key(int(payload['length'])) return_payload = process_payload(sysid, {'key': new_key}) # set new key globally for server set_key(sysid, new_key) await ws.send(return_payload)