Ejemplo n.º 1
0
def open_backup_file(file_path, private_key):
    backup_file_text = file_path.read_text()
    backup_file_json = json.loads(backup_file_text)
    meta_data = backup_file_json["meta_data"]
    meta_data_bytes = json.dumps(meta_data).encode()
    sig = backup_file_json["signature"]

    backup_pk = master_sk_to_backup_sk(private_key)
    my_pubkey = backup_pk.get_g1()
    key_base_64 = base64.b64encode(bytes(backup_pk))
    f = Fernet(key_base_64)

    encrypted_data = backup_file_json["data"].encode()
    msg = std_hash(encrypted_data) + std_hash(meta_data_bytes)

    signature = SignatureMPL.from_bytes(hexstr_to_bytes(sig))
    pubkey = PublicKeyMPL.from_bytes(hexstr_to_bytes(meta_data["pubkey"]))

    sig_match_my = AugSchemeMPL.verify(my_pubkey, msg, signature)
    sig_match_backup = AugSchemeMPL.verify(pubkey, msg, signature)

    assert sig_match_my is True
    assert sig_match_backup is True

    data_bytes = f.decrypt(encrypted_data)
    data_text = data_bytes.decode()
    data_json = json.loads(data_text)
    unencrypted = {}
    unencrypted["data"] = data_json
    unencrypted["meta_data"] = meta_data
    return unencrypted
Ejemplo n.º 2
0
def validate_alert(text: str, pubkey: str) -> bool:
    json_obj = json.loads(text)
    data = json_obj["data"]
    message = bytes(data, "UTF-8")
    signature = json_obj["signature"]
    signature = SignatureMPL.from_bytes(hexstr_to_bytes(signature))
    pubkey_bls = PublicKeyMPL.from_bytes(hexstr_to_bytes(pubkey))
    sig_match_my = AugSchemeMPL.verify(pubkey_bls, message, signature)

    return sig_match_my