New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling broken entries in known_hosts #490

Closed
martintopholm opened this Issue Feb 23, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@martintopholm
Contributor

martintopholm commented Feb 23, 2015

When broken entries exists in known_hosts, paramiko raises SSHException
with "Invalid key".

echo "example.net ssh-rsa AAAA" >>known_hosts
python2
>>> import paramiko
>>> hostkeys = paramiko.HostKeys()
>>> hostkeys.load('known_hosts')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mph/.local/lib/python2.7/site-packages/paramiko/hostkeys.py", line 99, in load
    e = HostKeyEntry.from_line(line, lineno)
  File "/home/mph/.local/lib/python2.7/site-packages/paramiko/hostkeys.py", line 327, in from_line
    key = RSAKey(data=decodebytes(key))
  File "/home/mph/.local/lib/python2.7/site-packages/paramiko/rsakey.py", line 65, in __init__
    raise SSHException('Invalid key')
paramiko.ssh_exception.SSHException: Invalid key

It would be nice if paramiko would ignore unparsable lines in known_hosts
or provide the file and line in the error message.

@bitprophet

This comment has been minimized.

Member

bitprophet commented Feb 27, 2015

Fair point. Also, OpenSSH's implementation certainly doesn't seem to be as picky, and we generally use them as a guide for behavior. I'd merge a PR that implements this. EDIT: should also see if any have been submitted previously first...

@martintopholm

This comment has been minimized.

Contributor

martintopholm commented Mar 2, 2015

On Fri, 27 Feb 2015, Jeff Forcier wrote:

[...] EDIT: should also see if any have been submitted previously first...

Related pull requests include #404 (Add informative BadHostKeyException).

@bitprophet bitprophet added this to the 1.13.4 / 1.14.3 / 1.15.3 milestone Mar 17, 2015

bitprophet added a commit that referenced this issue Sep 30, 2015

dkhapun pushed a commit to cyberx-labs/paramiko that referenced this issue Jun 7, 2018

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 paramiko#490.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment