[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-41]
make get_remote_server_key() return a PKey object a good suggestion from roger binns: make get_remote_server_key() just return a pkey object instead of a tuple of strings. all the strings can be extracted from the pkey object, as well as other potentially useful things.
This commit is contained in:
parent
c6d5ba9c52
commit
ed72847ad1
6
demo.py
6
demo.py
|
@ -70,12 +70,12 @@ try:
|
|||
# print repr(t)
|
||||
|
||||
keys = load_host_keys()
|
||||
keytype, hostkey = t.get_remote_server_key()
|
||||
key = t.get_remote_server_key()
|
||||
if not keys.has_key(hostname):
|
||||
print '*** WARNING: Unknown host key!'
|
||||
elif not keys[hostname].has_key(keytype):
|
||||
elif not keys[hostname].has_key(key.get_name()):
|
||||
print '*** WARNING: Unknown host key!'
|
||||
elif keys[hostname][keytype] != hostkey:
|
||||
elif keys[hostname][key.get_name()] != str(key):
|
||||
print '*** WARNING: Host key has changed!!!'
|
||||
sys.exit(1)
|
||||
else:
|
||||
|
|
|
@ -342,22 +342,19 @@ class BaseTransport (threading.Thread):
|
|||
def get_remote_server_key(self):
|
||||
"""
|
||||
Return the host key of the server (in client mode).
|
||||
The type string is usually either C{"ssh-rsa"} or C{"ssh-dss"} and the
|
||||
key is an opaque string, which may be saved or used for comparison with
|
||||
previously-seen keys. (In other words, you don't need to worry about
|
||||
the content of the key, only that it compares equal to the key you
|
||||
expected to see.)
|
||||
|
||||
@note: Previously this call returned a tuple of (key type, key string).
|
||||
You can get the same effect by calling L{PKey.get_name} for the key
|
||||
type, and C{str(key)} for the key string.
|
||||
|
||||
@raise SSHException: if no session is currently active.
|
||||
|
||||
@return: tuple of (key type, key)
|
||||
@rtype: (string, string)
|
||||
@return: public key of the remote server.
|
||||
@rtype: L{PKey}
|
||||
"""
|
||||
if (not self.active) or (not self.initial_kex_done):
|
||||
raise SSHException('No existing session')
|
||||
key_msg = Message(self.host_key)
|
||||
key_type = key_msg.get_string()
|
||||
return key_type, self.host_key
|
||||
return self.host_key
|
||||
|
||||
def is_active(self):
|
||||
"""
|
||||
|
@ -826,7 +823,7 @@ class BaseTransport (threading.Thread):
|
|||
raise SSHException('Unknown host key type')
|
||||
if not key.verify_ssh_sig(self.H, Message(sig)):
|
||||
raise SSHException('Signature verification (%s) failed. Boo. Robey should debug this.' % self.host_key_type)
|
||||
self.host_key = host_key
|
||||
self.host_key = key
|
||||
|
||||
def _compute_key(self, id, nbytes):
|
||||
"id is 'A' - 'F' for the various keys used by ssh"
|
||||
|
|
Loading…
Reference in New Issue