known_hosts
Parse OpenSSH known_hosts files.
Warning
Experimental: built on the pinned pre-release ssh-key 0.7.0-rc.12.
from oxcrypto.ssh.openssh import OPENSSH
with open("known_hosts", "rb") as f:
for entry in OPENSSH.OPENSSH.load_known_hosts(f.read()):
print(entry.marker, entry.hosts, entry.algorithm)load_known_hosts returns one KnownHost per key line and skips blank lines
and # comments. Each entry has:
marker:"@cert-authority","@revoked"orNone.hosts: the comma-separated host patterns, or an empty list when the host name is hashed.hashed_host:(salt, hash)for a hashed|1|salt|hashhost name, orNone. The hash is HMAC-SHA1 of the host name keyed with the salt.algorithm,commentandpublic_key(), which returns an oxcrypto public key.
Host patterns are returned, not matched. A malformed line raises
ValueError.