Exemple #1
0
    def test_curve25519dh_errors(self):
        """Unit test error conditions in Curve25519DH key exchange"""

        try:
            from asyncssh.crypto import Curve25519DH
        except ImportError:  # pragma: no cover
            return

        client_conn, server_conn = \
            _KexClientStub.make_pair(b'curve25519-sha256')

        with self.subTest('Invalid client public key'):
            with self.assertRaises(asyncssh.ProtocolError):
                server_conn.simulate_ecdh_init(b'')

        with self.subTest('Invalid server public key'):
            with self.assertRaises(asyncssh.ProtocolError):
                host_key = server_conn.get_server_host_key()
                client_conn.simulate_ecdh_reply(host_key.public_data, b'', b'')

        with self.subTest('Invalid signature'):
            with self.assertRaises(asyncssh.KeyExchangeFailed):
                host_key = server_conn.get_server_host_key()
                server_pub = Curve25519DH().get_public()
                client_conn.simulate_ecdh_reply(host_key.public_data,
                                                server_pub, b'')

        client_conn.close()
        server_conn.close()
    async def test_curve25519dh_errors(self):
        """Unit test error conditions in Curve25519DH key exchange"""

        client_conn, server_conn = \
            _KexClientStub.make_pair(b'curve25519-sha256')

        with self.subTest('Invalid client public key'):
            with self.assertRaises(asyncssh.ProtocolError):
                server_conn.simulate_ecdh_init(b'')

        with self.subTest('Invalid server public key'):
            with self.assertRaises(asyncssh.ProtocolError):
                host_key = server_conn.get_server_host_key()
                client_conn.simulate_ecdh_reply(host_key.public_data, b'', b'')

        with self.subTest('Invalid peer public key'):
            with self.assertRaises(asyncssh.ProtocolError):
                host_key = server_conn.get_server_host_key()
                server_pub = b'\x01' + 31 * b'\x00'
                client_conn.simulate_ecdh_reply(host_key.public_data,
                                                server_pub, b'')

        with self.subTest('Invalid signature'):
            with self.assertRaises(asyncssh.KeyExchangeFailed):
                host_key = server_conn.get_server_host_key()
                server_pub = Curve25519DH().get_public()
                client_conn.simulate_ecdh_reply(host_key.public_data,
                                                server_pub, b'')

        client_conn.close()
        server_conn.close()