Skip to content

Handling broken entries in known_hosts #490

Closed

Description

@martintopholm

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.

Activity

  1. bitprophet commented on Feb 27, 2015

    @bitprophet
    Member

    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...

  2. martintopholm commented on Mar 2, 2015

    @martintopholm
    ContributorAuthor

    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).

  3. added this to the milestone on Mar 17, 2015
  4. added 2 commits that reference this issue on Sep 30, 2015
    669ecbd
    fb258f8
  5. added a commit that references this issue on Jun 7, 2018
    dd458ab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions