Ejemplo n.º 1
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
Ejemplo n.º 2
0
    def build_keys(self, keys, from_file=False):
        """Build and import a list of authorized keys"""

        auth_keys = '# Comment line\n   # Comment line with whitespace\n\n'

        for options in keys:
            options = options + ' ' if options else ''
            keynum = 1 if 'cert-authority' in options else 0

            auth_keys += '%s%s' % (options, self.keylist[keynum])

        if from_file:
            with open('authorized_keys', 'w') as f:
                f.write(auth_keys)

            return asyncssh.read_authorized_keys('authorized_keys')
        else:
            return asyncssh.import_authorized_keys(auth_keys)
Ejemplo n.º 3
0
    def build_keys(self, keys, from_file=False):
        """Build and import a list of authorized keys"""

        auth_keys = '# Comment line\n   # Comment line with whitespace\n\n'

        for options in keys:
            options = options + ' ' if options else ''
            keynum = 1 if 'cert-authority' in options else 0

            auth_keys += '%s%s' % (options, self.keylist[keynum])

        if from_file:
            with open('authorized_keys', 'w') as f:
                f.write(auth_keys)

            return asyncssh.read_authorized_keys('authorized_keys')
        else:
            return asyncssh.import_authorized_keys(auth_keys)
Ejemplo n.º 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(
                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
Ejemplo n.º 5
0
        def server_factory():
            """Return an SSH server which calls set_authorized_keys"""

            authorized_keys = asyncssh.read_authorized_keys('authorized_keys')
            return _PublicKeyServer(authorized_keys=authorized_keys)
Ejemplo n.º 6
0
        def server_factory():
            """Return an SSH server which calls set_authorized_keys"""

            authorized_keys = asyncssh.read_authorized_keys('authorized_keys')
            return _PublicKeyServer(authorized_keys=authorized_keys)