Skip to content

Commit

Permalink
Merge branch 'master' into einarnn-iosxe-yangpush
Browse files Browse the repository at this point in the history
  • Loading branch information
einarnn committed Aug 17, 2019
2 parents 0de18ae + 131c088 commit 9eb00a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Expand Up @@ -4,8 +4,6 @@ python:
- '3.5'
- '3.6'
- '3.7'
dist: xenial
sudo: true
install:
- pip install .
- pip install -r requirements.txt
Expand Down
20 changes: 7 additions & 13 deletions ncclient/transport/ssh.py
Expand Up @@ -43,7 +43,6 @@
logger = logging.getLogger("ncclient.transport.ssh")

PORT_NETCONF_DEFAULT = 830
PORT_SSH_DEFAULT = 22

BUF_SIZE = 4096
# v1.0: RFC 4742
Expand Down Expand Up @@ -189,7 +188,7 @@ def connect(
*host* is the hostname or IP address to connect to
*port* is by default 830 (PORT_NETCONF_DEFAULT), but some devices use the default SSH port of 22 (PORT_SSH_DEFAULT) so this may need to be specified
*port* is by default 830 (PORT_NETCONF_DEFAULT), but some devices use the default SSH port of 22 so this may need to be specified
*timeout* is an optional timeout for socket connect
Expand Down Expand Up @@ -316,11 +315,9 @@ def connect(
elif self._host_keys:
# Else set preferred host keys to those we possess for the host
# (avoids situation where known_hosts contains a valid key for the host, but that key type is not selected during negotiation)
if port == PORT_SSH_DEFAULT:
known_hosts_lookup = host
else:
known_hosts_lookup = '[%s]:%s' % (host, port)
known_host_keys_for_this_host = self._host_keys.lookup(known_hosts_lookup)
known_host_keys_for_this_host = self._host_keys.lookup(host) or {}
host_port = '[%s]:%s' % (host, port)
known_host_keys_for_this_host.update(self._host_keys.lookup(host_port) or {})
if known_host_keys_for_this_host:
self._transport._preferred_keys = [x.key.get_name() for x in known_host_keys_for_this_host._entries]

Expand All @@ -338,21 +335,18 @@ def connect(

# For looking up entries for nonstandard (22) ssh ports in known_hosts
# we enclose host in brackets and append port number
if port == PORT_SSH_DEFAULT:
known_hosts_lookup = host
else:
known_hosts_lookup = '[%s]:%s' % (host, port)
known_hosts_lookups = [host, '[%s]:%s' % (host, port)]

if hostkey_b64:
# If hostkey specified, remote host /must/ use that hostkey
if(hostkey_obj.get_name() == server_key_obj.get_name() and hostkey_obj.asbytes() == server_key_obj.asbytes()):
is_known_host = True
else:
# Check known_hosts
is_known_host = self._host_keys.check(known_hosts_lookup, server_key_obj)
is_known_host = any(self._host_keys.check(lookup, server_key_obj) for lookup in known_hosts_lookups)

if not is_known_host and not unknown_host_cb(host, fingerprint):
raise SSHUnknownHostError(known_hosts_lookup, fingerprint)
raise SSHUnknownHostError(known_hosts_lookup[0], fingerprint)

# Authenticating with our private key/identity
if key_filename is None:
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Expand Up @@ -55,11 +55,10 @@
license=__licence__,
platforms=["Posix; OS X; Windows"],
keywords=['NETCONF', 'NETCONF Python client', 'Juniper Optimization', 'Cisco NXOS Optimization'],
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
Expand Down

0 comments on commit 9eb00a7

Please sign in to comment.