コード例 #1
0
    def test_export(self, tempdir):
        user_id = "ephemeral"
        device_id = "DEVICEID"

        file = path.join(tempdir, "keys_file")

        store = DefaultStore(user_id, device_id, tempdir, "")
        olm = Olm(user_id, device_id, store)
        olm.create_outbound_group_session(TEST_ROOM)

        out_session = olm.outbound_group_sessions[TEST_ROOM]

        assert olm.inbound_group_store.get(
            TEST_ROOM, olm.account.identity_keys["curve25519"], out_session.id)
        olm.export_keys(file, "pass")

        alice_store = DefaultStore("alice", device_id, tempdir, "")
        alice = Olm("alice", device_id, alice_store)

        assert not alice.inbound_group_store.get(
            TEST_ROOM, olm.account.identity_keys["curve25519"], out_session.id)

        alice.import_keys(file, "pass")

        assert alice.inbound_group_store.get(
            TEST_ROOM, olm.account.identity_keys["curve25519"], out_session.id)
コード例 #2
0
    def test_invalid_json(self, tempdir):
        device_id = "DEVICEID"
        file = path.join(tempdir, "keys_file")

        encrypt_and_save(b"{sessions: [{}]}", file, "pass", count=10)

        alice_store = DefaultStore("alice", device_id, tempdir, "")
        alice = Olm("alice", device_id, alice_store)

        with pytest.raises(EncryptionError):
            alice.import_keys(file, "pass")
コード例 #3
0
    def test_unencrypted_import(self, tempdir):
        device_id = "DEVICEID"
        file = path.join(tempdir, "keys_file")

        with open(file, "w") as f:
            f.write("{}")

        alice_store = DefaultStore("alice", device_id, tempdir, "")
        alice = Olm("alice", device_id, alice_store)
        with pytest.raises(EncryptionError):
            alice.import_keys(file, "pass")
コード例 #4
0
    def test_invalid_json_schema(self, tempdir):
        device_id = "DEVICEID"
        file = path.join(tempdir, "keys_file")

        payload = {"sessions": [{"algorithm": "test"}]}

        encrypt_and_save(json.dumps(payload).encode(), file, "pass", count=10)

        alice_store = DefaultStore("alice", device_id, tempdir, "")
        alice = Olm("alice", device_id, alice_store)

        with pytest.raises(EncryptionError):
            alice.import_keys(file, "pass")