Пример #1
0
 def test_inbound_with_id(self):
     plaintext = "It's a secret to everybody"
     alice, bob, session = self._create_session()
     message = session.encrypt(plaintext)
     alice_id = alice.identity_keys["curve25519"]
     bob_session = InboundSession(bob, message, alice_id)
     assert plaintext == bob_session.decrypt(message)
Пример #2
0
    def test_invalid_unicode_decrypt(self):
        alice, bob, session = self._create_session()
        message = session.encrypt(b"\xed")

        bob_session = InboundSession(bob, message)
        plaintext = bob_session.decrypt(message)
        assert plaintext == u"�"
Пример #3
0
    def test_doesnt_match(self):
        plaintext = "It's a secret to everybody"
        alice, bob, session = self._create_session()
        message = session.encrypt(plaintext)
        alice_id = alice.identity_keys["curve25519"]
        bob_session = InboundSession(bob, message, alice_id)

        _, _, new_session = self._create_session()

        new_message = new_session.encrypt(plaintext)
        assert bob_session.matches(new_message) is False
Пример #4
0
    def test_matches(self):
        plaintext = "It's a secret to everybody"
        alice, bob, session = self._create_session()
        message = session.encrypt(plaintext)
        alice_id = alice.identity_keys["curve25519"]
        bob_session = InboundSession(bob, message, alice_id)
        assert plaintext == bob_session.decrypt(message)

        message_2nd = session.encrypt("Hey! Listen!")

        assert bob_session.matches(message_2nd) is True
        assert bob_session.matches(message_2nd, alice_id) is True
Пример #5
0
    def test_encrypt(self):
        plaintext = "It's a secret to everybody"
        alice, bob, session = self._create_session()
        message = session.encrypt(plaintext)

        assert (repr(message) == "OlmPreKeyMessage({})".format(
            message.ciphertext))

        assert (str(message) == "PRE_KEY {}".format(message.ciphertext))

        bob_session = InboundSession(bob, message)
        assert plaintext == bob_session.decrypt(message)
Пример #6
0
    def test_two_messages(self):
        plaintext = "It's a secret to everybody"
        alice, bob, session = self._create_session()
        message = session.encrypt(plaintext)
        alice_id = alice.identity_keys["curve25519"]
        bob_session = InboundSession(bob, message, alice_id)
        bob.remove_one_time_keys(bob_session)
        assert plaintext == bob_session.decrypt(message)

        bob_plaintext = "Grumble, Grumble"
        bob_message = bob_session.encrypt(bob_plaintext)

        assert (repr(bob_message)
                == "OlmMessage({})".format(bob_message.ciphertext))

        assert bob_plaintext == session.decrypt(bob_message)
Пример #7
0
    def test_invalid(self):
        alice, bob, session = self._create_session()
        message = OlmMessage("x")

        with pytest.raises(TypeError):
            session.matches(message)

        message = OlmPreKeyMessage("x")
        message.ciphertext = ""

        with pytest.raises(ValueError):
            session.matches(message)

        with pytest.raises(ValueError):
            InboundSession(bob, message)

        with pytest.raises(ValueError):
            OutboundSession(alice, "", "x")

        with pytest.raises(ValueError):
            OutboundSession(alice, "x", "")