def test_decryption():
    key = bytes.fromhex("00112233445566778899aabbccddeeff")
    data = bytes.fromhex(
        "6cc6527f1d3d56c79d6b130beb76fe90cf170663be65a0952fc3ec7c280a8512"
        "c989288a55d64514663c85725aff0224633301b7c48bc9d1d14b8b77c77c9920")
    plaintext = decrypt(key, data)
    assert plaintext == b"just some random boring test data"
Esempio n. 2
0
def add_readings(mac_address: str) -> Response:
    key = get_device_key(mac_address)
    body = decrypt(key, request.get_data())
    body_parsed = json.loads(body.replace(b"'", b'"'))
    handle_readings(mac_address, convert_readings(mac_address, body_parsed))
    response = f"current_time={int(time.time())}&last_config_change={get_device_last_config_change(mac_address)}"
    response_enc = encrypt(key, bytes(response, encoding='utf-8'))
    return Response(response_enc, status=201, content_type=CONTENT_TYPE)
Esempio n. 3
0
def get_config(mac_address: str) -> Response:
    key = get_device_key(mac_address)
    _body = decrypt(key, request.get_data())
    response = f"current_time={int(time.time())}&{get_device_config(mac_address)}"
    response_enc = encrypt(key, bytes(response, encoding='utf-8'))
    return Response(response_enc, content_type=CONTENT_TYPE)
def test_encryption_and_decryption():
    key = bytes.fromhex("0123456789abcdef0123456789abcdef")
    data = b"another chunk of boring test data for encryption, long enough to fill multiple blocks"
    encrypted = encrypt(key, data)
    decrypted = decrypt(key, encrypted)
    assert decrypted == data