示例#1
0
文件: test_kex.py 项目: ronf/asyncssh
    def test_key_exchange_algs(self):
        """Unit test key exchange algorithms"""

        for alg in get_kex_algs():
            with self.subTest(alg=alg):
                if alg.startswith(b'gss-'):
                    if gss_available: # pragma: no branch
                        yield from self._check_kex(alg + b'-mech', '1')
                else:
                    yield from self._check_kex(alg)

        if gss_available: # pragma: no branch
            for steps in range(4):
                with self.subTest('GSS key exchange', steps=steps):
                    yield from self._check_kex(b'gss-group1-sha1-mech',
                                               str(steps))

            with self.subTest('GSS with credential delegation'):
                yield from self._check_kex(b'gss-group1-sha1-mech',
                                           '1,delegate')

            with self.subTest('GSS with no host key'):
                yield from self._check_kex(b'gss-group1-sha1-mech',
                                           '1,no_host_key')

            with self.subTest('GSS with full host principal'):
                yield from self._check_kex(b'gss-group1-sha1-mech',
                                           'host/1@TEST')
示例#2
0
    def test_key_exchange_algs(self):
        """Unit test key exchange algorithms"""

        for alg in get_kex_algs():
            with self.subTest(alg=alg):
                if alg.startswith(b'gss-'):
                    if gss_available:  # pragma: no branch
                        yield from self._check_kex(alg + b'-mech', '1')
                else:
                    yield from self._check_kex(alg)

        if gss_available:  # pragma: no branch
            for steps in range(4):
                with self.subTest('GSS key exchange', steps=steps):
                    yield from self._check_kex(b'gss-group1-sha1-mech',
                                               str(steps))

            with self.subTest('GSS with credential delegation'):
                yield from self._check_kex(b'gss-group1-sha1-mech',
                                           '1,delegate')

            with self.subTest('GSS with no host key'):
                yield from self._check_kex(b'gss-group1-sha1-mech',
                                           '1,no_host_key')

            with self.subTest('GSS with full host principal'):
                yield from self._check_kex(b'gss-group1-sha1-mech',
                                           'host/1@TEST')
示例#3
0
    def test_kex_algs(self):
        """Test connecting with different key exchange algorithms"""

        for kex in get_kex_algs():
            kex = kex.decode('ascii')

            with self.subTest(kex_alg=kex):
                with (yield from self.connect(kex_algs=[kex])) as conn:
                    pass

                yield from conn.wait_closed()
示例#4
0
    def test_kex_algs(self):
        """Test connecting with different key exchange algorithms"""

        for kex in get_kex_algs():
            kex = kex.decode('ascii')

            with self.subTest(kex_alg=kex):
                with (yield from self.connect(kex_algs=[kex])) as conn:
                    pass

                yield from conn.wait_closed()
示例#5
0
    def test_kex_algs(self):
        """Test connecting with different key exchange algorithms"""

        for kex in get_kex_algs():
            kex = kex.decode('ascii')

            if kex.startswith('gss-') and not gss_available: # pragma: no cover
                continue

            with self.subTest(kex_alg=kex):
                with (yield from self.connect(kex_algs=[kex],
                                              gss_host='1')) as conn:
                    pass

                yield from conn.wait_closed()
示例#6
0
    def test_key_exchange_algs(self):
        """Unit test kex exchange algorithms"""

        for alg in get_kex_algs():
            with self.subTest(alg=alg):
                client_conn = _ClientConn(alg)
                server_conn = client_conn.get_peer()

                with self.subTest('Check matching keys'):
                    _Conn.process_packets()
                    self.assertEqual(client_conn.get_key(),
                                     server_conn.get_key())

                with self.subTest('Check bad init msg'):
                    with self.assertRaises(DisconnectError):
                        client_conn.process_packet(Byte(MSG_KEXDH_INIT))

                with self.subTest('Check bad reply msg'):
                    with self.assertRaises(DisconnectError):
                        server_conn.process_packet(Byte(MSG_KEXDH_REPLY))
示例#7
0
    def test_key_exchange_algs(self):
        """Unit test kex exchange algorithms"""

        for alg in get_kex_algs():
            with self.subTest(alg=alg):
                client_conn, server_conn = _KexClientStub.make_pair(alg)

                with self.subTest('Check matching keys'):
                    self.assertEqual((yield from client_conn.get_key()),
                                     (yield from server_conn.get_key()))

                with self.subTest('Check bad init msg'):
                    with self.assertRaises(DisconnectError):
                        client_conn.process_packet(Byte(MSG_KEXDH_INIT))

                with self.subTest('Check bad reply msg'):
                    with self.assertRaises(DisconnectError):
                        server_conn.process_packet(Byte(MSG_KEXDH_REPLY))

                client_conn.close()
                server_conn.close()
示例#8
0
    def test_key_exchange_algs(self):
        """Unit test kex exchange algorithms"""

        for alg in get_kex_algs():
            with self.subTest(alg=alg):
                client_conn, server_conn = _KexClientStub.make_pair(alg)

                with self.subTest('Check matching keys'):
                    self.assertEqual((yield from client_conn.get_key()),
                                     (yield from server_conn.get_key()))

                with self.subTest('Check bad init msg'):
                    with self.assertRaises(DisconnectError):
                        client_conn.process_packet(Byte(MSG_KEXDH_INIT))

                with self.subTest('Check bad reply msg'):
                    with self.assertRaises(DisconnectError):
                        server_conn.process_packet(Byte(MSG_KEXDH_REPLY))

                client_conn.close()
                server_conn.close()
示例#9
0
        def unsupported_kex_alg():
            """Patched version of get_kex_algs to test unsupported algorithm"""

            return [b'fail'] + get_kex_algs()
示例#10
0
        def unsupported_kex_alg():
            """Patched version of get_kex_algs to test unsupported algorithm"""

            return [b'fail'] + get_kex_algs()