Example #1
0
    def test_exchange(self):
        alice_to_bob = self.alice.generate()
        assert self.alice._has_public()

        bob_to_alice = self.bob.generate()
        assert self.bob._has_public()

        assert self.alice._private_key != 0
        assert self.bob._private_key != 0
        assert self.alice._private_key != self.bob._private_key

        assert self.alice._public_key != 0
        assert self.bob._public_key != 0
        assert self.alice._public_key != self.bob._public_key

        self.alice.import_peer_public(bob_to_alice)
        assert self.alice._has_peers_public() is True
        assert self.alice._peer_public_key == self.bob._public_key

        self.bob.import_peer_public(alice_to_bob)
        assert self.bob._has_peers_public() is True
        assert self.bob._peer_public_key == self.alice._public_key

        alice_secret = self.alice.generate_secret()
        bob_secret = self.bob.generate_secret()
        assert alice_secret == bob_secret
        assert alice_secret == self.alice.shared_secret
        assert bob_secret == self.bob.shared_secret

        self.eve._public_key = self.alice._public_key
        self.eve._peer_public_key = self.bob._public_key
        with pytest.raises(TLSError):
            self.eve.generate_secret()
        self.eve._public_key = ECPoint(0, 0, 0)
        self.eve._private_key = self.alice._private_key
        assert self.eve.generate_secret() == alice_secret
Example #2
0
 def test_bool(self, point):
     assert bool(point) is True
     assert bool(ECPoint(0, 0, 0)) is False
Example #3
0
 def test_eq_zero(self):
     zero = ECPoint(0, 0, 0)
     assert (zero == 1) is False
     assert (zero == 0) is True
     assert (zero == ECPoint(0, 0, 0)) is True
Example #4
0
 def test_eq_point(self, point, xyz):
     assert (point == ECPoint(*xyz)) is True
     assert (point == ECPoint(0, 0, 0)) is False
Example #5
0
 def point(self, xyz):
     return ECPoint(*xyz)
Example #6
0
 def test_export_public_key_to_point_without_key(self, cipher):
     assert cipher.export_public_key("POINT") == 0
     assert cipher.export_public_key("POINT") == ECPoint(0, 0, 0)
Example #7
0
 def test_hash(self, point):
     zero = ECPoint(0, 0, 0)
     assert hash(zero) == hash(zero)
     assert hash(point) == hash(point)
     assert hash(zero) != hash(point)