Repository navigation
Add SSH host-key probing and pinning, moved from the Home Assistant integration - #67
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Moves the SSH host-key probe from the Home Assistant integration into the client and lets
NanoKVMSSHtrust one pinned key, so a caller can do trust-on-first-use for a new device without its own paramiko client.Changes
probe_host_key(host, port=22, timeout=10)reads the server's host key from the SSH handshake, without logging in, and returns anSSHHostKeywithhost,known_hosts_lineand an OpenSSH-stylefingerprint(SHA256:...). Failures raiseNanoKVMSSHConnectionError.NanoKVMSSH(host_key=...)takes one known-hosts line and trusts only that key: the system known-hosts file isn't loaded. The key applies to the host being connected to, whatever names its line carries, so a device that changed address keeps its key. An invalid line raisesValueErrorup front; a different server key raisesNanoKVMSSHConnectionError, as withknown_hosts=.docs/ssh.mdgains a "Trusting a new device" section.Notes
NanoKVMSSH(host, host_key=line),authenticate(), thendisconnect(). Storing the approved key stays in the integration.Behaviour changes
None. All methods and parameters are additions.
Testing
515 unit tests pass, 8 of them new. The probe, the pinned login and the rejection of a different key run against a real in-process paramiko SSH server. Against devices:
probe_host_key()returned the same ED25519 fingerprint asssh-keyscan, and a login pinned to that key succeeded.