Skip to content
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

[BUG] - <title> HostKeys.add() duplicates entries instead of overriding existing ones #2355

Open
uchihaMadara-7 opened this issue Feb 9, 2024 · 0 comments · May be fixed by #2359
Open

[BUG] - <title> HostKeys.add() duplicates entries instead of overriding existing ones #2355

uchihaMadara-7 opened this issue Feb 9, 2024 · 0 comments · May be fixed by #2359
Labels

Comments

@uchihaMadara-7
Copy link

Are you using paramiko as a client or server?

Client

What feature(s) aren't working right?

known_hosts

What version(s) of paramiko are you using?

3.0.0

What version(s) of Python are you using?

3.8.10

What operating system and version are you using?

Ubuntu 20.04.6 LTS

If you're connecting as a client, which SSH server are you connecting to?

No response

If you're using paramiko as part of another tool, which tool/version?

No response

Expected/desired behavior

When adding an existing host key using HostKeys.add(), the method should replace the existing entry with the new key instead of creating a duplicate entry. This only happens when hostname is a hash instead of direct hostname
e.g. |1|bWQqxa0HhZfj+3UAZfCvBYFsE8U=|RkKbwD+FTzftt4HkaaFY+SHJqn7=

Actual behavior

Instead of overriding the existing entry, the HostKeys.add() method duplicates the entry, resulting in multiple entries for the same hostname-key pair. This only happens when hostname is a hash instead of direct hostname
e.g. |1|bWQqxa0HhZfj+3UAZfCvBYFsE8U=|RkKbwD+FTzftt4HkaaFY+SHJqn7=

How to reproduce

Use the HostKeys.add() method to add a host key for a specific hostname (which is present in ~/.ssh/known_hosts with hash)
Repeat the above step with the same hostname but a different key.
Verify the contents of the HostKeys object.

This is my scenario:
Was adding the following key:
ecdsa-sha2-nistp256
AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzd --skipped-- +zt/6DTB45+Q/oPiRvRs4l4ZqCm+/Shk=

after adding got the old key twice:
Feb 09 13:54:54: INFO : ecdsa-sha2-nistp256
Feb 09 13:54:54 : INFO : AAAAE2VjZHNhLXNoYTItbmlzdHA --skipped-- C/3Po+kRAWGNogj8pcQLJZMw=
Feb 09 13:54:54 : INFO : ecdsa-sha2-nistp256
Feb 09 13:54:54 : INFO : AAAAE2VjZHNhLXNoYTItbmlzdHA --skipped-- C/3Po+kRAWGNogj8pcQLJZMw=

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant