Skip to content

Use constant-time comparison for host key bytes - #2674

Open
aroh3006 wants to merge 2 commits into
paramiko:mainfrom
aroh3006:fix/host-key-constant-time-compare
Open

aroh3006 wants to merge 2 commits into
paramiko:mainfrom
aroh3006:fix/host-key-constant-time-compare

Conversation

@aroh3006

Copy link
Copy Markdown

Fixes #2585.

Host key comparisons in hostkeys.py and transport.py use == and != on the raw key bytes, which short-circuit on the first differing byte and leak timing information. constant_time_bytes_eq already exists in paramiko.util and is already used for hashed hostname matching in hostkeys.py, just not for the key bytes themselves.

Switched both comparisons to use it. Added a test that a same-type key with different bytes is still correctly rejected by HostKeys.check, not just that it stops crashing. The existing host key mismatch tests in test_client.py cover the transport.py path.

Ran test_hostkeys.py, test_util.py, and the host_key tests in test_client.py, flake8, and black, all clean.

hostkeys.py and transport.py both compare host key bytes with ==/!=,
which short-circuit on the first differing byte. Every other key
comparison in the codebase already goes through
paramiko.util.constant_time_bytes_eq for exactly this reason (see
_hostname_matches a few lines above the hostkeys.py change); these two
spots were just missed.

Closes paramiko#2585
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Host key comparison uses non-constant-time == instead of constant_time_bytes_eq

2 participants