show us the offending host key
(cherry picked from commit a753df8ea43c26114942147fde2f10f82da5ca29)
This commit is contained in:
parent
7f526044e0
commit
01aaf70fc2
|
@ -21,6 +21,7 @@ L{HostKeys}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
import binascii
|
||||||
from Crypto.Hash import SHA, HMAC
|
from Crypto.Hash import SHA, HMAC
|
||||||
import UserDict
|
import UserDict
|
||||||
|
|
||||||
|
@ -29,6 +30,14 @@ from paramiko.dsskey import DSSKey
|
||||||
from paramiko.rsakey import RSAKey
|
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:
|
class HostKeyEntry:
|
||||||
"""
|
"""
|
||||||
Representation of a line in an OpenSSH-style "known hosts" file.
|
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
|
# Decide what kind of key we're looking at and create an object
|
||||||
# to hold it accordingly.
|
# to hold it accordingly.
|
||||||
if keytype == 'ssh-rsa':
|
try:
|
||||||
key = RSAKey(data=base64.decodestring(key))
|
if keytype == 'ssh-rsa':
|
||||||
elif keytype == 'ssh-dss':
|
key = RSAKey(data=base64.decodestring(key))
|
||||||
key = DSSKey(data=base64.decodestring(key))
|
elif keytype == 'ssh-dss':
|
||||||
else:
|
key = DSSKey(data=base64.decodestring(key))
|
||||||
return None
|
else:
|
||||||
|
return None
|
||||||
|
except binascii.Error, e:
|
||||||
|
raise InvalidHostKey(line, e)
|
||||||
|
|
||||||
return cls(names, key)
|
return cls(names, key)
|
||||||
from_line = classmethod(from_line)
|
from_line = classmethod(from_line)
|
||||||
|
|
Loading…
Reference in New Issue