summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Topholm <mph@one.com>2015-03-02 07:17:50 +0100
committerJeff Forcier <jeff@bitprophet.org>2015-09-30 14:16:28 -0700
commit669ecbd66f1218e5c93f6a53a25ea062c7b0b947 (patch)
tree13b30c2ba11ebe07a43fb81b47944526c793281a
parent48dc72b87567152ac8d45b4bad2bdd0d4ad3ac8b (diff)
Silently ignore invalid keys in HostKeys.load()
When broken entries exists in known_hosts, paramiko raises SSHException with "Invalid key". This patch catches the exception during HostKeys.load() and continues to next line. This should fix #490.
-rw-r--r--paramiko/hostkeys.py6
-rw-r--r--tests/test_hostkeys.py1
2 files changed, 6 insertions, 1 deletions
diff --git a/paramiko/hostkeys.py b/paramiko/hostkeys.py
index 84868875..7e2d22cf 100644
--- a/paramiko/hostkeys.py
+++ b/paramiko/hostkeys.py
@@ -19,6 +19,7 @@
import binascii
import os
+import ssh_exception
from hashlib import sha1
from hmac import HMAC
@@ -96,7 +97,10 @@ class HostKeys (MutableMapping):
line = line.strip()
if (len(line) == 0) or (line[0] == '#'):
continue
- e = HostKeyEntry.from_line(line, lineno)
+ try:
+ e = HostKeyEntry.from_line(line, lineno)
+ except ssh_exception.SSHException:
+ continue
if e is not None:
_hostnames = e.hostnames
for h in _hostnames:
diff --git a/tests/test_hostkeys.py b/tests/test_hostkeys.py
index 0ee1bbf0..2bdcad9c 100644
--- a/tests/test_hostkeys.py
+++ b/tests/test_hostkeys.py
@@ -31,6 +31,7 @@ test_hosts_file = """\
secure.example.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA1PD6U2/TVxET6lkpKhOk5r\
9q/kAYG6sP9f5zuUYP8i7FOFp/6ncCEbbtg/lB+A3iidyxoSWl+9jtoyyDOOVX4UIDV9G11Ml8om3\
D+jrpI9cycZHqilK0HmxDeCuxbwyMuaCygU9gS2qoRvNLWZk70OpIKSSpBo0Wl3/XUmz9uhc=
+broken.example.com ssh-rsa AAAA
happy.example.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEA8bP1ZA7DCZDB9J0s50l31M\
BGQ3GQ/Fc7SX6gkpXkwcZryoi4kNFhHu5LvHcZPdxXV1D+uTMfGS1eyd2Yz/DoNWXNAl8TI0cAsW\
5ymME3bQ4J/k1IKxCtz/bAlAqFgKoc+EolMziDYqWIATtW0rYTJvzGAzTmMj80/QpsFH+Pc2M=