Ejemplo 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"*****@*****.**")
Ejemplo 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"*****@*****.**")
Ejemplo n.º 3
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()
Ejemplo n.º 4
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"
Ejemplo n.º 5
0
def test_local_params_private_export(local_params):
    G = PublicParams.get_default().ec_group
    public_exported = local_params.public_export()
    private_exported = local_params.private_export()

    assert public_exported != private_exported
    for key, val in public_exported.items():
        assert private_exported[key] == val

    # check that export contains no bytes and is json dumpable
    data = json.dumps(private_exported)
    imp = json.loads(data)

    local_params1 = LocalParams.from_dict(imp)

    assert local_params1.vrf.sk == local_params.vrf.sk
    assert local_params1.sig.sk == local_params.sig.sk
Ejemplo n.º 6
0
def test_local_params_public_export(local_params):
    G = PublicParams.get_default().ec_group
    exported = local_params.public_export()

    for key in exported:
        assert not key.endswith("_sk")

    local_params1 = LocalParams.from_dict(exported)

    assert local_params1.vrf.pk == local_params.vrf.pk
    assert local_params1.sig.pk == local_params.sig.pk
    assert local_params1.dh.pk == local_params.dh.pk
    assert local_params1.rescue.pk == local_params.rescue.pk
    assert local_params1.vrf.sk is None
    assert local_params1.sig.sk is None
    assert local_params1.dh.sk is None
    assert local_params1.rescue.sk is None
Ejemplo n.º 7
0
def local_params():
    with LocalParams.generate().as_default() as params:
        yield params