Skip to content

Commit

Permalink
Add disabled algorithms support for client
Browse files Browse the repository at this point in the history
  • Loading branch information
miikaoskari committed Aug 28, 2024
1 parent fe83a68 commit 927bdd2
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/SSHLibrary/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def close(self):
pass

def login(self, username=None, password=None, allow_agent=False, look_for_keys=False, delay=None, proxy_cmd=None,
read_config=False, jumphost_connection=None, keep_alive_interval='0 seconds'):
read_config=False, jumphost_connection=None, keep_alive_interval='0 seconds', disabled_algorithms=None):
"""Logs into the remote host using password authentication.
This method reads the output from the remote host after logging in,
Expand Down Expand Up @@ -224,7 +224,7 @@ def login(self, username=None, password=None, allow_agent=False, look_for_keys=F
password = self._encode(password)
try:
self._login(username, password, allow_agent, look_for_keys, proxy_cmd, read_config,
jumphost_connection, keep_alive_interval)
jumphost_connection, keep_alive_interval, disabled_algorithms)
except SSHClientException:
self.client.close()
raise SSHClientException(f"Authentication failed for user '{self._decode(username)}'.")
Expand All @@ -249,7 +249,8 @@ def _read_login_output(self, delay):

def login_with_public_key(self, username, keyfile, password, allow_agent=False,
look_for_keys=False, delay=None, proxy_cmd=None,
jumphost_connection=None, read_config=False, keep_alive_interval='0 seconds'):
jumphost_connection=None, read_config=False, keep_alive_interval='0 seconds',
disabled_algorithms=None):
"""Logs into the remote host using the public key authentication.
This method reads the output from the remote host after logging in,
Expand Down Expand Up @@ -295,7 +296,8 @@ def login_with_public_key(self, username, keyfile, password, allow_agent=False,
self._login_with_public_key(username, keyfile, password,
allow_agent, look_for_keys,
proxy_cmd, jumphost_connection,
read_config, keep_alive_interval)
read_config, keep_alive_interval,
disabled_algorithms)
except SSHClientException:
self.client.close()
raise SSHClientException(f"Login with public key failed for user '{self._decode(username)}'.")
Expand Down Expand Up @@ -836,7 +838,7 @@ def _get_jumphost_tunnel(self, jumphost_connection):
return jumphost_transport.open_channel("direct-tcpip", dest_addr, jump_addr)

def _login(self, username, password, allow_agent=False, look_for_keys=False, proxy_cmd=None,
read_config=False, jumphost_connection=None, keep_alive_interval=None):
read_config=False, jumphost_connection=None, keep_alive_interval=None, disabled_algorithms=None):
if read_config:
hostname = self.config.host
self.config.host, username, self.config.port, proxy_cmd = \
Expand All @@ -857,7 +859,8 @@ def _login(self, username, password, allow_agent=False, look_for_keys=False, pro
self.client.connect(self.config.host, self.config.port, username,
password, look_for_keys=look_for_keys,
allow_agent=allow_agent,
timeout=float(self.config.timeout), sock=sock_tunnel)
timeout=float(self.config.timeout), sock=sock_tunnel,
disabled_algorithms=disabled_algorithms)
except paramiko.SSHException:
pass
transport = self.client.get_transport()
Expand All @@ -868,7 +871,8 @@ def _login(self, username, password, allow_agent=False, look_for_keys=False, pro
self.client.connect(self.config.host, self.config.port, username,
password, look_for_keys=look_for_keys,
allow_agent=allow_agent,
timeout=float(self.config.timeout), sock=sock_tunnel)
timeout=float(self.config.timeout), sock=sock_tunnel,
disabled_algorithms=disabled_algorithms)
transport = self.client.get_transport()
transport.set_keepalive(keep_alive_interval)
except paramiko.AuthenticationException:
Expand All @@ -886,7 +890,7 @@ def _login(self, username, password, allow_agent=False, look_for_keys=False, pro
raise SSHClientException

def _login_with_public_key(self, username, key_file, password, allow_agent, look_for_keys, proxy_cmd=None,
jumphost_connection=None, read_config=False, keep_alive_interval=None):
jumphost_connection=None, read_config=False, keep_alive_interval=None, disabled_algorithms=None):
if read_config:
hostname = self.config.host
self.config.host, username, self.config.port, key_file, proxy_cmd = \
Expand Down Expand Up @@ -915,7 +919,8 @@ def _login_with_public_key(self, username, key_file, password, allow_agent, look
allow_agent=allow_agent,
look_for_keys=look_for_keys,
timeout=float(self.config.timeout),
sock=sock_tunnel)
sock=sock_tunnel,
disabled_algorithms=disabled_algorithms)
transport = self.client.get_transport()
transport.set_keepalive(keep_alive_interval)
except paramiko.AuthenticationException:
Expand Down

0 comments on commit 927bdd2

Please sign in to comment.