Exemplo n.º 1
0
 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
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
def ws_on_message(ws, message):
    WS_INCOMING[ws.endpoint].append(unprocess_payload(SYSID, message))