Line 0
Link Here
|
|
|
1 |
--- paramiko/client.py.orig 2017-07-30 14:38:18 UTC |
2 |
+++ paramiko/client.py |
3 |
@@ -331,6 +331,30 @@ class SSHClient (ClosingContextManager): |
4 |
t = self._transport = Transport( |
5 |
sock, gss_kex=gss_kex, gss_deleg_creds=gss_deleg_creds) |
6 |
t.use_compression(compress=compress) |
7 |
+ |
8 |
+ if port == SSH_PORT: |
9 |
+ server_hostkey_name = hostname |
10 |
+ else: |
11 |
+ server_hostkey_name = "[%s]:%d" % (hostname, port) |
12 |
+ |
13 |
+ # if we already have a host key stored, change our key preference |
14 |
+ known_host_keys = {} |
15 |
+ known_host_keys.update( |
16 |
+ self._system_host_keys.get(server_hostkey_name, {}) |
17 |
+ ) |
18 |
+ known_host_keys.update( |
19 |
+ self.get_host_keys().get(server_hostkey_name, {}) |
20 |
+ ) |
21 |
+ |
22 |
+ if known_host_keys: |
23 |
+ # order the keys as follows: known keys in preferred-keys order, |
24 |
+ # then unknown keys in preferred-keys order |
25 |
+ valid_known_keys = [k for k in t._preferred_keys |
26 |
+ if k in known_host_keys] |
27 |
+ t._preferred_keys = (valid_known_keys |
28 |
+ + [k for k in t._preferred_keys |
29 |
+ if k not in valid_known_keys]) |
30 |
+ |
31 |
if gss_kex and gss_host is None: |
32 |
t.set_gss_host(hostname) |
33 |
elif gss_kex and gss_host is not None: |
34 |
@@ -344,10 +368,6 @@ class SSHClient (ClosingContextManager): |
35 |
if auth_timeout is not None: |
36 |
t.auth_timeout = auth_timeout |
37 |
|
38 |
- if port == SSH_PORT: |
39 |
- server_hostkey_name = hostname |
40 |
- else: |
41 |
- server_hostkey_name = "[%s]:%d" % (hostname, port) |
42 |
our_server_keys = None |
43 |
|
44 |
# If GSS-API Key Exchange is performed we are not required to check the |