def test_session(self): account = OlmAccount() session = OutboundSession(account, BOB_CURVE, BOB_ONETIME) assert session.id == Session.from_pickle(session.pickle(), session.creation_time).id assert not session.expired
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