Skip to content

Commit a3eb631

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

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

deployer/host/paramiko_connect_patch.py

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@
1111
from paramiko.transport import Transport
1212
from paramiko.resource import ResourceManager
1313
from paramiko.ssh_exception import BadHostKeyException
14+
from paramiko.py3compat import string_types
1415

1516

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

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

3138
progress_bar_callback(2) # Creating socket
3239
sock = socket.socket(af, socket.SOCK_STREAM)
33-
3440
if timeout is not None:
3541
try:
3642
sock.settimeout(timeout)
@@ -39,10 +45,18 @@ def connect(self, hostname, port=SSH_PORT, username=None, password=None, pkey=No
3945
retry_on_signal(lambda: sock.connect(addr))
4046

4147
progress_bar_callback(3) # Creating transport
42-
t = self._transport = Transport(sock)
48+
t = self._transport = Transport(sock, gss_kex=gss_kex, gss_deleg_creds=gss_deleg_creds)
4349
t.use_compression(compress=compress)
50+
if gss_kex and gss_host is None:
51+
t.set_gss_host(hostname)
52+
elif gss_kex and gss_host is not None:
53+
t.set_gss_host(gss_host)
54+
else:
55+
pass
4456
if self._log_channel is not None:
4557
t.set_log_channel(self._log_channel)
58+
if banner_timeout is not None:
59+
t.banner_timeout = banner_timeout
4660
t.start_client()
4761
ResourceManager.register(self, t)
4862

@@ -54,27 +68,38 @@ def connect(self, hostname, port=SSH_PORT, username=None, password=None, pkey=No
5468
server_hostkey_name = hostname
5569
else:
5670
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
6571

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

6991
if username is None:
7092
username = getpass.getuser()
7193

7294
if key_filename is None:
7395
key_filenames = []
74-
elif isinstance(key_filename, (str, unicode)):
75-
key_filenames = [ key_filename ]
96+
elif isinstance(key_filename, string_types):
97+
key_filenames = [key_filename]
7698
else:
7799
key_filenames = key_filename
100+
if gss_host is None:
101+
gss_host = hostname
78102

79103
progress_bar_callback(5) # Authenticate
80-
self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
104+
self._auth(username, password, pkey, key_filenames, allow_agent,
105+
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='[email protected]',
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)