[Checkins]
SVN: zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/urllib2sftp.py
Fixed a bug in handling multiple host keys for a given host.
Jim Fulton
jim at zope.com
Thu Mar 15 16:13:55 EDT 2007
Log message for revision 73207:
Fixed a bug in handling multiple host keys for a given host.
Changed:
U zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/urllib2sftp.py
-=-
Modified: zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/urllib2sftp.py
===================================================================
--- zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/urllib2sftp.py 2007-03-15 19:47:20 UTC (rev 73206)
+++ zc.buildoutsftp/branches/dev/src/zc/buildoutsftp/urllib2sftp.py 2007-03-15 20:13:54 UTC (rev 73207)
@@ -98,13 +98,10 @@
host = urllib.unquote(host or '')
- hostkey = _get_hosts_keys()
- hostkey = hostkey.get(host)
- if hostkey is None:
+ host_keys = _get_hosts_keys().get(host)
+ if host_keys is None:
raise paramiko.AuthenticationException(
"No stored host key", host)
- [hostkeytype] = list(hostkey)
- hostkey = hostkey[hostkeytype]
if pw is not None:
trans = paramiko.Transport((host, port))
@@ -113,7 +110,7 @@
for key in paramiko.Agent().get_keys():
trans = paramiko.Transport((host, port))
try:
- trans.connect(username=user, pkey=key, hostkey=hostkey)
+ trans.connect(username=user, pkey=key)
break
except paramiko.AuthenticationException:
trans.close()
@@ -121,6 +118,13 @@
raise paramiko.AuthenticationException(
"Authentication failed.")
+ # Check host key
+ remote_server_key = trans.get_remote_server_key()
+ host_key = host_keys.get(remote_server_key.get_name())
+ if host_key != remote_server_key:
+ raise paramiko.AuthenticationException(
+ "Remote server authentication failed.", host)
+
sftp = paramiko.SFTPClient.from_transport(trans)
path = req.get_selector()
More information about the Checkins
mailing list