ddn.net.ssh.known_hosts

known_hosts parsing and host trust matching.

Parses the OpenSSH known_hosts format - plain and hashed host patterns, wildcard and negated patterns, markers, comments - and answers whether a presented host key is trusted, unknown, changed, or revoked for a target (host, port) plus optional caller aliases.

Policy notes:

  • Parsing is strict: a malformed file throws instead of being

    silently skipped, so trust decisions fail closed.

  • Entries whose key type has no enabled public-data parser -

    ecdsa-sha2-nistp384/nistp521, certificate, and security-key types - are skipped the way OpenSSH ignores key types it does not use; the enabled profile never negotiates them, so they cannot match a presented key.

  • A matched @revoked entry marks the host revoked and

    overrides everything else.

  • @cert-authority entries never act as plain trusted

    keys; they surface as a distinct unsupported outcome while certificate validation is out of scope.

  • The file is never modified; there is no accept-new

    behaviour here.

Types 5

Outcome of a known_hosts lookup for a presented key.

noMatchNo pattern matched the target
trustedA pattern matched and the presented key equals the stored key
changedA pattern matched but the stored key differs from the presented one
revokedA matching entry is marked revoked
certAuthorityOnly certificate-authority entries matched (unsupported here)

known_hosts limits from the support matrix.

lineMax = 16384Maximum bytes per line
entriesMax = 8192Maximum number of entries

One parsed known_hosts entry.

Fields
bool revokedTrue when marked @revoked
bool certAuthorityTrue when marked @cert-authority
string[] patternsHost pattern field items, negation flags included
string keyTypeKey-format name from the line
const(ubyte)[] keyBlobDecoded key blob

A parsed known_hosts database.

Methods
SshKnownHosts parse(string contents) static @safeParses known_hosts contents strictly.
SshKnownHostsResult check(string host, ushort port, const(ubyte)[] keyBlob, string[] aliases = null) const @safeLooks up a presented key for a target host.
size_t entryCount() @property const @safe pure nothrowReturns: the number of parsed entries.
Constructors

A pinned set of host keys: exact blobs, nothing else matches.

Methods
bool isPinned(const(ubyte)[] keyBlob) const @safeChecks whether the presented blob is one of the pinned keys.
Constructors
this(scope const(ubyte)[][] blobs)Constructs a pinned-key set from exact key blobs.