diff options
author | Thomas Vander Stichele <thomas (at) apestaart (dot) org> | 2012-07-02 13:28:44 +0200 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2012-09-23 16:45:53 -0700 |
commit | 01aaf70fc24e846a8f3b531441344cdfb02d9269 (patch) | |
tree | 716cd69566c7ab3f07c3993ad86ad68243aead04 | |
parent | 7f526044e0e0d767791d739b10a33b548af8578e (diff) |
show us the offending host key
(cherry picked from commit a753df8ea43c26114942147fde2f10f82da5ca29)
-rw-r--r-- | paramiko/hostkeys.py | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/paramiko/hostkeys.py b/paramiko/hostkeys.py index 70ccf43d..e739312a 100644 --- a/paramiko/hostkeys.py +++ b/paramiko/hostkeys.py @@ -21,6 +21,7 @@ L{HostKeys} """ import base64 +import binascii from Crypto.Hash import SHA, HMAC import UserDict @@ -29,6 +30,14 @@ from paramiko.dsskey import DSSKey from paramiko.rsakey import RSAKey +class InvalidHostKey(Exception): + + def __init__(self, line, exc): + self.line = line + self.exc = exc + self.args = (line, exc) + + class HostKeyEntry: """ Representation of a line in an OpenSSH-style "known hosts" file. @@ -63,12 +72,15 @@ class HostKeyEntry: # Decide what kind of key we're looking at and create an object # to hold it accordingly. - if keytype == 'ssh-rsa': - key = RSAKey(data=base64.decodestring(key)) - elif keytype == 'ssh-dss': - key = DSSKey(data=base64.decodestring(key)) - else: - return None + try: + if keytype == 'ssh-rsa': + key = RSAKey(data=base64.decodestring(key)) + elif keytype == 'ssh-dss': + key = DSSKey(data=base64.decodestring(key)) + else: + return None + except binascii.Error, e: + raise InvalidHostKey(line, e) return cls(names, key) from_line = classmethod(from_line) |