def connect(self, user, host, port, method, password=None, key=None): logging.info( "Client Verbindung mit folgenden Parametern wird hergestellt: Remote Address: %s; Port: %s; Username: %s; Password: %s; Key: %s; Agent: %s", host, port, user, password, ('None' if key is None else 'not None'), str(self.session.agent) ) if not host: raise MissingHostException() sshclient = SSHClient( host, port, method, password, user, key, self.session ) if sshclient.connect(): self.session.ssh_client = sshclient self.session.sftp_client = SFTPClient.from_client(sshclient) return paramiko.AUTH_SUCCESSFUL logging.debug('connection failed!') return paramiko.AUTH_FAILED
def connect(self, user, host, port, method, password=None, key=None): def get_agent_pubkeys(): keys = self.session.agent.get_keys() keys_parsed = [] for k in keys: ssh_pub_key = SSHKey("{} {}".format(k.get_name(), k.get_base64())) ssh_pub_key.parse() keys_parsed.append((k.get_name(), ssh_pub_key, k.can_sign())) return keys_parsed if not self.args.auth_hide_credentials: ssh_keys = None keys_formatted = "" if self.session.agent: ssh_keys = get_agent_pubkeys() keys_formatted = "\n".join(["\t\tAgent-Key: {} {} {}bits, can sign: {}".format(k[0], k[1].hash_sha256(), k[1].bits, k[2]) for k in ssh_keys]) logging.info( "\n".join(( "Client connection established with parameters:", "\tRemote Address: %s", "\tPort: %s", "\tUsername: %s", "\tPassword: %s", "\tKey: %s", "\tAgent: %s", "%s" )), host, port, user, password, ('None' if key is None else 'not None'), "available keys: {}".format(len(ssh_keys)) if ssh_keys else 'no agent', keys_formatted ) if not host: raise MissingHostException() sshclient = SSHClient( host, port, method, password, user, key, self.session ) if sshclient.connect(): self.session.ssh_client = sshclient self.session.sftp_client = SFTPClient.from_client(sshclient) return paramiko.AUTH_SUCCESSFUL logging.warning('connection failed!') return paramiko.AUTH_FAILED
def connect(self, user, host, port, method, password=None, key=None): logging.info( "\n".join(("Client connection established with parameters:", "\tRemote Address: %s", "\tPort: %s", "\tUsername: %s", "\tPassword: %s", "\tKey: %s", "\tAgent: %s")), host, port, user, password, ('None' if key is None else 'not None'), str(self.session.agent)) if not host: raise MissingHostException() sshclient = SSHClient(host, port, method, password, user, key, self.session) if sshclient.connect(): self.session.ssh_client = sshclient self.session.sftp_client = SFTPClient.from_client(sshclient) return paramiko.AUTH_SUCCESSFUL logging.debug('connection failed!') return paramiko.AUTH_FAILED