summaryrefslogtreecommitdiff
path: root/paramiko/hostkeys.py
diff options
context:
space:
mode:
authorJeremy T. Bouse <jbouse@debian.org>2013-05-25 00:04:32 -0400
committerJeremy T. Bouse <jbouse@debian.org>2013-05-25 00:04:32 -0400
commit1a716ed46d1d556d4ba6798608ab498320acd886 (patch)
treedbcb23de26387e312f7ea09085330eca90e15853 /paramiko/hostkeys.py
parenta88b8c8c0f591a3bfa8d7984343a27815184f495 (diff)
downloadpython-paramiko-1a716ed46d1d556d4ba6798608ab498320acd886.tar
python-paramiko-1a716ed46d1d556d4ba6798608ab498320acd886.tar.gz
Imported Upstream version 1.10.1upstream/1.10.1
Diffstat (limited to 'paramiko/hostkeys.py')
-rw-r--r--paramiko/hostkeys.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/paramiko/hostkeys.py b/paramiko/hostkeys.py
index 70ccf43..e739312 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)