Example #1
0
    def start_client(self):
        self.sock = socket.socket()
        self.sock.connect(("localhost", 23400))

        # handshake
        chs = ClientHandshake()
        self.sock.send(chs.as_bytes())

        # verify server handshake
        datagram = self.sock.recv(144)
        shs = ServerHandshake(chs.eph_pk, datagram)
        try:
            shs.verify()
        except Exception as e:
            traceback.print_exc()
            sys.exit(1)

        # harvest info from handshaeks
        print("Handshake phase complete.")
        rx_key, tx_key = pysodium.crypto_kx_server_session_keys(
            chs.eph_pk, chs.eph_sk, shs.eph_pk)
        self.sb = SecretBox(rx_key, tx_key)

        # send an update
        self.sock.send(self.sb.encrypt(DummyPacket()))

        while True:
            print("receiving...")
            sys.stdout.flush()
            data = self.sock.recv(1024)
            if not data: break
            print("len:", len(data))
            print(data)
            sys.stdout.flush()
Example #2
0
    def test_crypto_kx(self):
        if not pysodium.sodium_version_check(1, 0, 12): return
        client_pk, client_sk = pysodium.crypto_kx_keypair()
        server_pk, server_sk = pysodium.crypto_kx_keypair()

        crx, ctx = pysodium.crypto_kx_client_session_keys(client_pk, client_sk, server_pk)
        srx, stx = pysodium.crypto_kx_server_session_keys(server_pk, server_sk, client_pk)

        self.assertEqual(crx, stx)
        self.assertEqual(ctx, srx)
Example #3
0
    def test_crypto_kx(self):
        if not pysodium.sodium_version_check(1, 0, 12): return
        client_pk, client_sk = pysodium.crypto_kx_keypair()
        server_pk, server_sk = pysodium.crypto_kx_keypair()

        crx, ctx = pysodium.crypto_kx_client_session_keys(client_pk, client_sk, server_pk)
        srx, stx = pysodium.crypto_kx_server_session_keys(server_pk, server_sk, client_pk)

        self.assertEqual(crx, stx)
        self.assertEqual(ctx, srx)