コード例 #1
0
ファイル: sas_test.py プロジェクト: kechpaja/matrix-nio
    def test_sas_invalid_commitment(self):
        alice = Sas(
            alice_id,
            alice_device_id,
            alice_keys["ed25519"],
            bob_device,
        )
        start = {"sender": alice_id, "content": alice.start_verification()}
        start_event = KeyVerificationStart.from_dict(start)

        bob = Sas.from_key_verification_start(bob_id, bob_device_id,
                                              bob_keys["ed25519"],
                                              alice_device, start_event)

        accept = {"sender": bob_id, "content": bob.accept_verification()}
        accept_event = KeyVerificationAccept.from_dict(accept)
        alice.receive_accept_event(accept_event)

        alice_key = {"sender": alice_id, "content": alice.share_key()}

        key_event = KeyVerificationKey.from_dict(alice_key)
        assert isinstance(key_event, KeyVerificationKey)
        bob.receive_key_event(key_event)
        assert bob.state == SasState.key_received

        bob_key = {"sender": bob_id, "content": bob.share_key()}

        bob_key["content"]["key"] = alice.pubkey

        key_event = KeyVerificationKey.from_dict(bob_key)
        assert isinstance(key_event, KeyVerificationKey)
        alice.receive_key_event(key_event)
        assert alice.state == SasState.canceled
コード例 #2
0
ファイル: sas_test.py プロジェクト: kechpaja/matrix-nio
    def test_sas_share_keys(self):
        alice = Sas(
            alice_id,
            alice_device_id,
            alice_keys["ed25519"],
            bob_device,
        )
        start = {"sender": alice_id, "content": alice.start_verification()}
        start_event = KeyVerificationStart.from_dict(start)

        bob = Sas.from_key_verification_start(bob_id, bob_device_id,
                                              bob_keys["ed25519"],
                                              alice_device, start_event)

        accept = {"sender": bob_id, "content": bob.accept_verification()}
        accept_event = KeyVerificationAccept.from_dict(accept)
        alice.receive_accept_event(accept_event)

        alice_key = {"sender": alice_id, "content": alice.share_key()}

        key_event = KeyVerificationKey.from_dict(alice_key)
        assert isinstance(key_event, KeyVerificationKey)
        bob.receive_key_event(key_event)
        assert bob.state == SasState.key_received

        bob_key = {"sender": bob_id, "content": bob.share_key()}

        key_event = KeyVerificationKey.from_dict(bob_key)
        assert isinstance(key_event, KeyVerificationKey)
        alice.receive_key_event(key_event)
        assert alice.state == SasState.key_received
        assert alice.get_emoji() == bob.get_emoji()
コード例 #3
0
ファイル: sas_test.py プロジェクト: rudis/matrix-nio
    def test_client_full_sas(self, olm_machine):
        alice_device = OlmDevice(olm_machine.user_id, olm_machine.device_id,
                                 olm_machine.account.identity_keys)
        bob_device = olm_machine.device_store[bob_id][bob_device_id]
        bob_sas = Sas(
            bob_id,
            bob_device_id,
            bob_device.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.mac_received
        assert not alice_sas.verified

        alice_sas.accept_sas()
        assert alice_sas.verified
        bob_mac_event.keys = "fake_keys"
        olm_machine.handle_key_verification(bob_mac_event)
        assert alice_sas.verified
コード例 #4
0
ファイル: sas_test.py プロジェクト: rudis/matrix-nio
    def test_sas_accept(self):
        alice = Sas(
            alice_id,
            alice_device_id,
            alice_keys["ed25519"],
            bob_device,
        )
        start = {
            "sender": alice_id,
            "content": alice.start_verification().content
        }
        start_event = KeyVerificationStart.from_dict(start)

        bob = Sas.from_key_verification_start(bob_id, bob_device,
                                              bob_keys["ed25519"],
                                              alice_device, start_event)

        accept = {
            "sender": bob_id,
            "content": bob.accept_verification().content
        }
        accept_event = KeyVerificationAccept.from_dict(accept)
        assert isinstance(accept_event, KeyVerificationAccept)
        alice.receive_accept_event(accept_event)
        assert alice.state == SasState.accepted
コード例 #5
0
    def test_sas_decimals(self):
        alice = Sas(
            alice_id,
            alice_device_id,
            alice_keys["ed25519"],
            bob_device,
        )
        start = {
            "sender": alice_id,
            "content": alice.start_verification().content
        }
        start_event = KeyVerificationStart.from_dict(start)

        bob = Sas.from_key_verification_start(bob_id, bob_device_id,
                                              bob_keys["ed25519"],
                                              alice_device, start_event)

        accept = {
            "sender": bob_id,
            "content": bob.accept_verification().content
        }
        accept_event = KeyVerificationAccept.from_dict(accept)
        alice.receive_accept_event(accept_event)

        alice.set_their_pubkey(bob.pubkey)
        bob.set_their_pubkey(alice.pubkey)

        assert alice.get_decimals() == bob.get_decimals()
コード例 #6
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()
コード例 #7
0
ファイル: sas_test.py プロジェクト: rudis/matrix-nio
    def test_sas_not_ok_events(self):
        alice = Sas(
            alice_id,
            alice_device_id,
            alice_keys["ed25519"],
            bob_device,
        )
        start = {
            "sender": alice_id,
            "content": alice.start_verification().content
        }
        start_event = KeyVerificationStart.from_dict(start)

        bob = Sas.from_key_verification_start(bob_id, bob_device_id,
                                              bob_keys["ed25519"],
                                              alice_device, start_event)
        accept = {
            "sender": bob_id,
            "content": bob.accept_verification().content
        }
        accept_event = KeyVerificationAccept.from_dict(accept)
        accept_event.sender = faker.mx_id()
        alice.receive_accept_event(accept_event)
        assert alice.canceled

        alice.state = SasState.created
        accept_event.sender = bob_id
        accept_event.transaction_id = "fake_id"
        alice.receive_accept_event(accept_event)
        assert alice.canceled

        accept_event.transaction_id = alice.transaction_id
        alice.receive_accept_event(accept_event)
        assert alice.canceled

        alice.state = SasState.created
        accept_event.hash = "fake_hash"
        alice.receive_accept_event(accept_event)
        assert alice.canceled

        alice.state = SasState.created
        accept_event.hash = Sas._hash_v1
        alice.receive_accept_event(accept_event)
        alice_key = {"sender": alice_id, "content": alice.share_key().content}
        alice_key_event = KeyVerificationKey.from_dict(alice_key)

        alice_key_event.sender = faker.mx_id()
        bob.receive_key_event(alice_key_event)
        assert bob.canceled

        bob.set_their_pubkey(alice.pubkey)
        bob.state = SasState.key_received
        bob.chosen_mac_method = Sas._mac_normal

        alice.chosen_mac_method = Sas._mac_normal
        alice.set_their_pubkey(bob.pubkey)
        alice.state = SasState.key_received

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

        mac_event = KeyVerificationMac.from_dict(bob_mac)

        mac_event.sender = faker.mx_id()
        alice.receive_mac_event(mac_event)
        assert alice.canceled