Skip to content
This repository was archived by the owner on Dec 21, 2022. It is now read-only.

Commit 5ea6509

Browse files
Updated paramiko patch. (Compatibility with latest paramiko version.)
1 parent 76cce3e commit 5ea6509

2 files changed

Lines changed: 41 additions & 18 deletions

File tree

deployer/host/paramiko_connect_patch.py

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
from paramiko.resource import ResourceManager
1313
from paramiko.ssh_exception import BadHostKeyException
1414

15-
1615
def connect(self, hostname, port=SSH_PORT, username=None, password=None, pkey=None,
1716
key_filename=None, timeout=None, allow_agent=True, look_for_keys=True,
18-
compress=False, sock=None, progress_bar_callback=None):
17+
compress=False, sock=None, gss_auth=False, gss_kex=False,
18+
gss_deleg_creds=True, gss_host=None, banner_timeout=None,
19+
progress_bar_callback=None):
20+
"""
21+
Patched ``paramiko.client.SSHClient.connect``.
22+
This adds callbacks for the connection progress bar.
23+
"""
1924
if not sock:
2025
progress_bar_callback(1) # Resolving DNS
2126

@@ -30,7 +35,6 @@ def connect(self, hostname, port=SSH_PORT, username=None, password=None, pkey=No
3035

3136
progress_bar_callback(2) # Creating socket
3237
sock = socket.socket(af, socket.SOCK_STREAM)
33-
3438
if timeout is not None:
3539
try:
3640
sock.settimeout(timeout)
@@ -39,10 +43,18 @@ def connect(self, hostname, port=SSH_PORT, username=None, password=None, pkey=No
3943
retry_on_signal(lambda: sock.connect(addr))
4044

4145
progress_bar_callback(3) # Creating transport
42-
t = self._transport = Transport(sock)
46+
t = self._transport = Transport(sock, gss_kex=gss_kex, gss_deleg_creds=gss_deleg_creds)
4347
t.use_compression(compress=compress)
48+
if gss_kex and gss_host is None:
49+
t.set_gss_host(hostname)
50+
elif gss_kex and gss_host is not None:
51+
t.set_gss_host(gss_host)
52+
else:
53+
pass
4454
if self._log_channel is not None:
4555
t.set_log_channel(self._log_channel)
56+
if banner_timeout is not None:
57+
t.banner_timeout = banner_timeout
4658
t.start_client()
4759
ResourceManager.register(self, t)
4860

@@ -54,27 +66,38 @@ def connect(self, hostname, port=SSH_PORT, username=None, password=None, pkey=No
5466
server_hostkey_name = hostname
5567
else:
5668
server_hostkey_name = "[%s]:%d" % (hostname, port)
57-
our_server_key = self._system_host_keys.get(server_hostkey_name, {}).get(keytype, None)
58-
if our_server_key is None:
59-
our_server_key = self._host_keys.get(server_hostkey_name, {}).get(keytype, None)
60-
if our_server_key is None:
61-
# will raise exception if the key is rejected; let that fall out
62-
self._policy.missing_host_key(self, server_hostkey_name, server_key)
63-
# if the callback returns, assume the key is ok
64-
our_server_key = server_key
6569

66-
if server_key != our_server_key:
67-
raise BadHostKeyException(hostname, server_key, our_server_key)
70+
# If GSS-API Key Exchange is performed we are not required to check the
71+
# host key, because the host is authenticated via GSS-API / SSPI as
72+
# well as our client.
73+
if not self._transport.use_gss_kex:
74+
our_server_key = self._system_host_keys.get(server_hostkey_name,
75+
{}).get(keytype, None)
76+
if our_server_key is None:
77+
our_server_key = self._host_keys.get(server_hostkey_name,
78+
{}).get(keytype, None)
79+
if our_server_key is None:
80+
# will raise exception if the key is rejected; let that fall out
81+
self._policy.missing_host_key(self, server_hostkey_name,
82+
server_key)
83+
# if the callback returns, assume the key is ok
84+
our_server_key = server_key
85+
86+
if server_key != our_server_key:
87+
raise BadHostKeyException(hostname, server_key, our_server_key)
6888

6989
if username is None:
7090
username = getpass.getuser()
7191

7292
if key_filename is None:
7393
key_filenames = []
74-
elif isinstance(key_filename, (str, unicode)):
75-
key_filenames = [ key_filename ]
94+
elif isinstance(key_filename, string_types):
95+
key_filenames = [key_filename]
7696
else:
7797
key_filenames = key_filename
98+
if gss_host is None:
99+
gss_host = hostname
78100

79101
progress_bar_callback(5) # Authenticate
80-
self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
102+
self._auth(username, password, pkey, key_filenames, allow_agent,
103+
look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
author_email='jonathan.slenders@mobilevikings.com',
3838
packages=find_packages('.'),
3939
install_requires = [
40-
'paramiko>=1.12.0',
40+
'paramiko>=1.15.1',
4141
'Twisted>=12.2.0',
4242
'pexpect==3.0',
4343
'Pygments>=1.5',

0 commit comments

Comments
 (0)