Exemple #1
0
    def _begin_session(self, stdin, stdout, stderr):
        """Begin processing a new session"""

        # pylint: disable=no-self-use

        action = stdin.channel.get_command()
        if not action:
            action = 'echo'

        if action == 'echo':
            yield from echo(stdin, stdout)
        elif action == 'echo_stderr':
            yield from echo(stdin, stdout, stderr)
        elif action == 'close':
            yield from stdin.read(1)
            stdout.write('\n')
        elif action == 'disconnect':
            stdout.write((yield from stdin.read(1)))

            raise asyncssh.DisconnectError(asyncssh.DISC_CONNECTION_LOST,
                                           'Connection lost')
        else:
            stdin.channel.exit(255)

        stdin.channel.close()
        yield from stdin.channel.wait_closed()
Exemple #2
0
    async def _begin_session(self, stdin, stdout, stderr):
        """Begin processing a new session"""

        # pylint: disable=no-self-use

        action = stdin.channel.get_command()
        if not action:
            action = 'echo'

        if action == 'echo':
            await echo(stdin, stdout)
        elif action == 'echo_stderr':
            await echo(stdin, stdout, stderr)
        elif action == 'close':
            await stdin.read(1)
            stdout.write('\n')
        elif action == 'disconnect':
            stdout.write((await stdin.read(1)))
            raise asyncssh.ConnectionLost('Connection lost')
        elif action == 'custom_disconnect':
            await stdin.read(1)
            raise asyncssh.DisconnectError(99, 'Disconnect')
        else:
            stdin.channel.exit(255)

        stdin.channel.close()
        await stdin.channel.wait_closed()
Exemple #3
0
def bail(count=True, custom_raise_f=None):
    if count:
        global ACTIVE_CONS
        ACTIVE_CONS -= 1
        logging.info(f'CONN CLOSED, TOTAL {ACTIVE_CONS}')

    if not custom_raise_f:
        raise asyncssh.DisconnectError(RAISE_WITH, RAISE_MSG)

    custom_raise_f()
Exemple #4
0
    def begin_auth(self, username):
        """The client has started authentication with the given username."""
        self.username = username
        try:
            self.authorized_keys = asyncssh.read_authorized_keys(KEYS_FILE)
        except Exception as e:
            # No point in continuing without authorized keys
            logging.error("Failed to read key file: %s", e)
            raise asyncssh.DisconnectError(
                asyncssh.DISC_NO_MORE_AUTH_METHODS_AVAILABLE,
                "Invalid server configuration", "en")

        # Auth required
        return True
Exemple #5
0
    def begin_auth(self, username):
        """The client has started authentication with the given username."""
        self.username = username
        try:
            self.authorized_keys = asyncssh.read_authorized_keys(
                config.AUTHORIZED_KEYS_FILE)
        except FileNotFoundError:
            logging.info("Generating authorized keys file")
            with open(config.AUTHORIZED_KEYS_FILE, 'w'):
                pass
            return True
        except ValueError:
            logging.info("Authorized keys file is empty")
            return True
        except Exception as e:
            # No point in continuing without authorized keys
            logging.error("Failed to read key file: %s", e)
            raise asyncssh.DisconnectError(
                asyncssh.DISC_NO_MORE_AUTH_METHODS_AVAILABLE,
                "Invalid server configuration", "en")

        # Auth required
        return True
 def validate_password(self, username, password):
     print('Login attempt from %s with username %s and password %s' %
           (self._conn.get_extra_info('peername')[0], username, password))
     # Sleep, then disconnect
     time.sleep(random.randint(0, 5))
     raise asyncssh.DisconnectError(10, "Connection lost")
Exemple #7
0
 def validate_password(self, username, password):
     print(f'Login attempt from {self._conn.get_extra_info("peername")[0]} with username {username} and password {password}')
     time.sleep(random.randint(0,5))
     raise asyncssh.DisconnectError(10,"Connection lost")