Exemplo n.º 1
0
def test_sign_incorrect_pubkey(local_params):
    sig = sign(b"*****@*****.**")

    # Generate a distinct public key
    other_params = LocalParams.generate()
    while other_params.sig.pk == local_params.sig.pk:
        other_params = LocalParams.generate()

    assert not verify_signature(other_params.sig.pk, sig, b"*****@*****.**")
Exemplo n.º 2
0
def test_vrf_incorrect_pubkey(local_params):
    vrf = compute_vrf(b"*****@*****.**")

    # Generate a distinct public key
    other_params = LocalParams.generate()
    while other_params.vrf.pk == local_params.vrf.pk:
        other_params = LocalParams.generate()

    assert not verify_vrf(other_params.vrf.pk, vrf, b"*****@*****.**")
Exemplo n.º 3
0
def test_read_claim_from_other_chain():
    for i in range(1, 100):
        alice_params = LocalParams.generate()
        alice_state = State()
        alice_store = {}
        alice_chain = Chain(alice_store, None)
        alice_state.identity_info = "Hi, I'm " + pet2ascii(alice_params.dh.pk)
        with alice_params.as_default():
            alice_head = alice_state.commit(alice_chain)
        alice_chain = Chain(alice_store, alice_head)

        bob_params = LocalParams.generate()
        bob_state = State()
        bob_store = {}
        bob_chain = Chain(bob_store, None)
        bob_state.identity_info = "Hi, I'm " + pet2ascii(bob_params.dh.pk)
        with bob_params.as_default():
            bob_head = bob_state.commit(bob_chain)
        bob_chain = Chain(bob_store, bob_head)

        bob_pk = bob_params.dh.pk

        with alice_params.as_default():
            alice_state[b"bobs_key"] = b"123abc"
            alice_state.grant_access(bob_pk, [b"bobs_key"])
            alice_head = alice_state.commit(alice_chain)
        alice_chain = Chain(alice_store, alice_head)

        with alice_params.as_default():
            value = View(alice_chain)[b'bobs_key'].decode('utf-8')

        assert value == "123abc"

        with bob_params.as_default():
            value = View(alice_chain)[b'bobs_key'].decode('utf-8')

        assert value == "123abc"
Exemplo n.º 4
0
 def init_crypto_identity(self):
     identity_file = os.path.join(self.accountdir, 'identity.json')
     if not os.path.exists(identity_file):
         self.params = LocalParams.generate()
         self.state = State()
         self.state.identity_info = "Hi, I'm " + pet2ascii(
             self.params.dh.pk)
         assert self.head_imprint is None
         self.commit_to_chain()
         assert self.head_imprint
         with open(identity_file, 'w') as fp:
             json.dump(self.params.private_export(), fp)
     else:
         with open(identity_file, 'r') as fp:
             params_raw = json.load(fp)
             self.params = LocalParams.from_dict(params_raw)
         self._load_state()
Exemplo n.º 5
0
def local_params():
    with LocalParams.generate().as_default() as params:
        yield params