def test_session_store_order(self): alice = OlmAccount() bob = OlmAccount() bob_curve = bob.identity_keys["curve25519"] bob.generate_one_time_keys(2) store = SessionStore() first, second = bob.one_time_keys["curve25519"].values() session2 = OutboundSession(alice, bob_curve, second) session = OutboundSession(alice, bob_curve, first) assert session.id != session2.id assert session not in store assert store.add(bob_curve, session) assert len(store[bob_curve]) == 1 assert session in store assert store.add(bob_curve, session2) is True print(store.values()) assert len(store[bob_curve]) == 2 session_a, session_b = store[bob_curve] assert session_a.use_time > session_b.use_time
def test_olm_session_encryption(self): alice = OlmAccount() bob = OlmAccount() plaintext = "It's a secret to everybody" bob_curve = bob.identity_keys["curve25519"] bob.generate_one_time_keys(1) bob_onetime = list(bob.one_time_keys["curve25519"].values())[0] session = OutboundSession(alice, bob_curve, bob_onetime) creation_time = session.use_time # Encrypt a message and check that the use time increased. message = session.encrypt(plaintext) assert session.use_time >= creation_time inbound = InboundSession(bob, message) creation_time = inbound.use_time # Decrypt a message and check that the use time increased. decrypted_plaintext = inbound.decrypt(message) assert inbound.use_time >= creation_time assert decrypted_plaintext == plaintext pickle = inbound.pickle("") unpickled = Session.from_pickle(pickle, inbound.creation_time, "", inbound.use_time) use_time = unpickled.use_time message = unpickled.encrypt(plaintext) assert unpickled.use_time > use_time pickle = session.pickle("") unpickled = Session.from_pickle(pickle, session.creation_time, "", session.use_time) use_time = unpickled.use_time decrypted_plaintext = unpickled.decrypt(message) assert unpickled.use_time >= use_time assert decrypted_plaintext == plaintext