コード例 #1
0
ファイル: sas_test.py プロジェクト: rudis/matrix-nio
    def test_client_invalid_key(self, olm_machine):
        alice_device = OlmDevice(olm_machine.user_id, olm_machine.device_id,
                                 olm_machine.account.identity_keys)
        bob_sas = Sas(
            bob_id,
            bob_device_id,
            faker.olm_key_pair()["ed25519"],
            alice_device,
        )

        start = {
            "sender": bob_id,
            "content": bob_sas.start_verification().content
        }
        start_event = KeyVerificationStart.from_dict(start)

        assert olm_machine.device_store[bob_id][bob_device_id]
        olm_machine.handle_key_verification(start_event)

        alice_sas = olm_machine.key_verifications[start_event.transaction_id]

        accept = {
            "sender": olm_machine.user_id,
            "content": alice_sas.accept_verification().content
        }
        accept_event = KeyVerificationAccept.from_dict(accept)

        bob_sas.receive_accept_event(accept_event)

        bob_key = {"sender": bob_id, "content": bob_sas.share_key().content}
        bob_key_event = KeyVerificationKey.from_dict(bob_key)

        olm_machine.handle_key_verification(bob_key_event)

        alice_key = {
            "sender": alice_id,
            "content": alice_sas.share_key().content
        }
        alice_key_event = KeyVerificationKey.from_dict(alice_key)
        bob_sas.receive_key_event(alice_key_event)

        assert alice_sas.other_key_set
        assert bob_sas.other_key_set

        bob_sas.accept_sas()

        bob_mac = {"sender": bob_id, "content": bob_sas.get_mac().content}

        bob_mac_event = KeyVerificationMac.from_dict(bob_mac)

        olm_machine.handle_key_verification(bob_mac_event)
        assert alice_sas.state == SasState.canceled
        assert not alice_sas.verified

        with pytest.raises(LocalProtocolError):
            alice_sas.accept_sas()
コード例 #2
0
    def test_key(self):
        user_id = faker.mx_id()
        device_id = faker.device_id()
        fp_key = faker.olm_key_pair()["ed25519"]
        key = Ed25519Key(user_id, device_id, fp_key)

        assert (key.to_line() == "{} {} matrix-ed25519 {}\n".format(
            user_id, device_id, fp_key))

        loaded_key = Key.from_line(key.to_line())
        assert isinstance(loaded_key, Ed25519Key)

        assert key.user_id == loaded_key.user_id
        assert key.device_id == loaded_key.device_id
        assert key.key == loaded_key.key
        assert key == loaded_key
コード例 #3
0
ファイル: sas_test.py プロジェクト: kechpaja/matrix-nio
import pytest

from nio.crypto import Sas, SasState, OlmDevice
from nio.exceptions import LocalProtocolError
from nio.events import (KeyVerificationStart, KeyVerificationAccept,
                        KeyVerificationKey, KeyVerificationMac)
from helpers import faker

alice_id = faker.mx_id()
alice_device_id = faker.device_id()
alice_keys = faker.olm_key_pair()

bob_id = faker.mx_id()
bob_device_id = faker.device_id()
bob_keys = faker.olm_key_pair()

alice_device = OlmDevice(alice_id, alice_device_id, alice_keys["ed25519"],
                         alice_keys["curve25519"])

bob_device = OlmDevice(bob_id, bob_device_id, bob_keys["ed25519"],
                       bob_keys["curve25519"])


class TestClass(object):
    def test_sas_creation(self):
        alice = Sas(alice_id, alice_device_id, alice_keys["ed25519"],
                    bob_device)

        with pytest.raises(LocalProtocolError):
            alice.accept_verification()