Skip to content

Commit

Permalink
Change: Add workaround for non-standard SSH ports
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchDrage committed Feb 2, 2023
1 parent 1f206aa commit 35713ad
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions gvm/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ def _ssh_authentication_input_loop(
add = input()
while True:
if add == "yes":
hostkeys.add(self.hostname, key.get_name(), key)
if self.port == 22:
hostkeys.add(self.hostname, key.get_name(), key)
elif self.port != 22:
hostkeys.add("[" + self.hostname + "]:" + str(self.port), key.get_name(), key)
# ask user if the key should be added permanently
print(
f"Do you want to add {self.hostname} "
Expand Down Expand Up @@ -331,12 +334,21 @@ def _ssh_authentication(self) -> None:
f"the known_hosts file: {e}"
) from None
hostkeys = self._socket.get_host_keys()
if not hostkeys.lookup(self.hostname):
# Key not found, so connect to remote and fetch the key
# with the paramiko Transport protocol
key = self._get_remote_host_key()

self._ssh_authentication_input_loop(hostkeys=hostkeys, key=key)
# Switch based on SSH Port
if self.port == 22:
if not hostkeys.lookup(self.hostname):
# Key not found, so connect to remote and fetch the key
# with the paramiko Transport protocol
key = self._get_remote_host_key()

self._ssh_authentication_input_loop(hostkeys=hostkeys, key=key)
elif self.port != 22:
if not hostkeys.lookup("[" + self.hostname + "]:" + str(self.port)):
# Key not found, so connect to remote and fetch the key
# with the paramiko Transport protocol
key = self._get_remote_host_key()

self._ssh_authentication_input_loop(hostkeys=hostkeys, key=key)

def connect(self) -> None:
"""
Expand Down

0 comments on commit 35713ad

Please sign in to comment.