IF Commons GitHub

targets/ssh/hostkey

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0005-reach-and-targets FR-006

The first contact with a host (commons headless 0005-reach-and-targets FR-006; 0007-ssh-coverage FR-002): a host key that does not match is refused and never accepted for the person, and a host not yet known is learned only by a verb of its own that a person runs. scanHost fetches what the host shows (through ssh-keyscan and ssh-keygen -l) and gives the fingerprints; acceptHostKey writes the host to the repository's known hosts only where the person gave the fingerprint they checked and it is one of those the host showed. Nothing is accepted by a flag that says yes to everything; StrictHostKeyChecking=accept-new is not written anywhere.

import { acceptHostKey } from "./hostkey.ts";
// const r = await acceptHostKey(alpha, scan, "SHA256:...", (line) => appendToKnownHosts(line));

Source: commons/headless/src/targets/ssh/hostkey.ts

3 of 3 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

ScannedKeytype
type ScannedKey = { readonly line: string; readonly fingerprint: string };

What a host showed: each key's line as a known-hosts file holds it, and its fingerprint.

Imported by 18 tests of the run (18 passed, 0 failed): the library's results

scanHostfunction
function scanHost(t: Target, run: RunLocal): Promise<Result<readonly ScannedKey[], string>>

The fingerprints of the keys a host shows, through ssh-keygen -l (one call for each line, so that a line is never mistaken for another); ed25519 first.

Imported by 27 tests of the run (27 passed, 0 failed): the library's results

acceptHostKeyfunction
function acceptHostKey(t: Target, scanned: readonly ScannedKey[], expected: string, append: (line: string) => void | Promise<void>): Promise<Result<readonly ScannedKey[], string>>

Writes a host to the known hosts only if expected, the fingerprint a person checked by another way, is one that the host showed; append writes the line (the caller's: the repository's known-hosts file). A fingerprint that is not among them writes nothing, and says what the host showed.

Imported by 27 tests of the run (27 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.