def test_server_auth_methods(self): """Test server auth methods""" with self.subTest('No auth methods'): server_conn = _AuthServerStub() self.assertEqual(get_server_auth_methods(server_conn), []) server_conn.close() with self.subTest('All auth methods'): gss_host = '1' if gss_available else None server_conn = _AuthServerStub(gss_host=gss_host, public_key_auth=True, password_auth=True, kbdint_auth=True) if gss_available: # pragma: no branch self.assertEqual(get_server_auth_methods(server_conn), [b'gssapi-keyex', b'gssapi-with-mic', b'publickey', b'keyboard-interactive', b'password']) else: # pragma: no cover self.assertEqual(get_server_auth_methods(server_conn), [b'publickey', b'keyboard-interactive', b'password']) server_conn.close() with self.subTest('Unknown auth method'): server_conn = _AuthServerStub() self.assertEqual(lookup_server_auth(server_conn, 'user', b'xxx', SSHPacket(b'')), None) server_conn.close()
def test_server_auth_methods(self): """Test server auth methods""" with self.subTest('No auth methods'): server_conn = _AuthServerStub() self.assertEqual(get_server_auth_methods(server_conn), []) server_conn.close() with self.subTest('All auth methods'): gss_host = '1' if gss_available else None server_conn = _AuthServerStub(gss_host=gss_host, host_based_auth=True, public_key_auth=True, password_auth=True, kbdint_auth=True) if gss_available: # pragma: no branch self.assertEqual(get_server_auth_methods(server_conn), [b'gssapi-keyex', b'gssapi-with-mic', b'hostbased', b'publickey', b'keyboard-interactive', b'password']) else: # pragma: no cover self.assertEqual(get_server_auth_methods(server_conn), [b'hostbased', b'publickey', b'keyboard-interactive', b'password']) server_conn.close() with self.subTest('Unknown auth method'): server_conn = _AuthServerStub() self.assertEqual(lookup_server_auth(server_conn, 'user', b'xxx', SSHPacket(b'')), None) server_conn.close()
def test_server_auth_methods(self): """Test server auth methods""" with self.subTest('No auth methods'): server_conn = _AuthServerStub() self.assertEqual(get_server_auth_methods(server_conn), []) server_conn.close() with self.subTest('All auth methods'): server_conn = _AuthServerStub(public_key_auth=True, password_auth=True, kbdint_auth=True) self.assertEqual(get_server_auth_methods(server_conn), [b'publickey', b'keyboard-interactive', b'password']) server_conn.close() with self.subTest('Unknown auth method'): server_conn = _AuthServerStub() self.assertEqual(lookup_server_auth(server_conn, 'user', b'xxx', SSHPacket(b'')), None) server_conn.close()
def process_packet(self, data): """Process an incoming packet""" packet = SSHPacket(data) pkttype = packet.get_byte() if pkttype == MSG_USERAUTH_REQUEST: _ = packet.get_string() # username _ = packet.get_string() # service method = packet.get_string() if self._auth: self._auth.cancel() if self._override_gss_mech: self.send_packet(MSG_USERAUTH_GSSAPI_RESPONSE, String('mismatch')) elif self._override_pk_ok: self.send_packet(MSG_USERAUTH_PK_OK, String(''), String('')) else: self._auth = lookup_server_auth(self, 'user', method, packet) else: self._auth.process_packet(pkttype, None, packet)
def test_server_auth_methods(self): """Test server auth methods""" with self.subTest('No auth methods'): server_conn = _AuthServerStub() self.assertEqual(get_server_auth_methods(server_conn), []) server_conn.close() with self.subTest('All auth methods'): server_conn = _AuthServerStub(public_key_auth=True, password_auth=True, kbdint_auth=True) self.assertEqual( get_server_auth_methods(server_conn), [b'publickey', b'keyboard-interactive', b'password']) server_conn.close() with self.subTest('Unknown auth method'): server_conn = _AuthServerStub() self.assertEqual( lookup_server_auth(server_conn, 'user', b'xxx', SSHPacket(b'')), None) server_conn.close()
def process_packet(self, data): """Process an incoming packet""" packet = SSHPacket(data) pkttype = packet.get_byte() if pkttype == MSG_USERAUTH_REQUEST: _ = packet.get_string() # username _ = packet.get_string() # service method = packet.get_string() if self._auth: self._auth.cancel() if self._override_pk_ok: self.send_packet(Byte(MSG_USERAUTH_PK_OK), String(''), String('')) else: self._auth = lookup_server_auth(self, 'user', method, packet) else: try: self._auth.process_packet(pkttype, packet) except DisconnectError as exc: self.connection_lost(exc)