IF Commons GitHub

targets/ssh/hostkeys

Written to: 2 requirements: 2 proved, 0 partly, 0 failing, 0 with no test recorded. 0007-ssh-coverage FR-005, 0007-ssh-coverage FR-006

The host keys and the key tools of OpenSSH as typed helpers (commons headless 0007-ssh-coverage FR-005): the argument vectors of ssh-keyscan -T 8 [-p], ssh-keygen -lf -, -y, -R and -Y find-principals, and generation, and the parsing of what they write (the keys a host showed, deduplicated and in the order that makes ed25519 first, a fingerprint with its size, its comment and its type), and the text of a known-hosts file for the keys pinned for a host. They only make arguments and read text: nothing here runs a program, and nothing records a key as trusted: that is the verb of first contact, which a person confirms.

import { parseFingerprint, parseScan } from "./hostkeys.ts";
parseFingerprint("256 SHA256:abc alpha (ED25519)\n"); // { bits: 256, fingerprint: "SHA256:abc", comment: "alpha", type: "ED25519" }
parseScan("alpha ssh-ed25519 AAAA\n")[0]?.type; // "ssh-ed25519"

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

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

SCAN_TIMEOUT_SECconstno test imports it
const SCAN_TIMEOUT_SEC: 8

The seconds ssh-keyscan waits for a host.

HostKeytypeno test imports it
type HostKey = { readonly host: string; readonly type: string; readonly key: string; readonly line: string };

One key a host showed, as a line of a known-hosts file.

scanArgvfunction
function scanArgv(t: Target): readonly string[]

The arguments that fetch the keys a host shows: ssh-keyscan -T 8 [-p port] -- <address>.

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

parseScanfunction
function parseScan(text: string): readonly HostKey[]

The keys in what ssh-keyscan wrote: comment lines and what is not a key are left out, the same key once, and ed25519 first (then the other types in a fixed order, the rest in the order shown).

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

FINGERPRINT_ARGVconst
const FINGERPRINT_ARGV: readonly string[]

The arguments that make the fingerprint of the key or keys on the standard input: ssh-keygen -l -f -.

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

Fingerprinttypeno test imports it
type Fingerprint = { readonly bits: number; readonly fingerprint: string; readonly comment: string; readonly type: string };

A fingerprint as ssh-keygen -l writes it.

parseFingerprintfunction
function parseFingerprint(text: string): Fingerprint | undefined

The fingerprint in the output of ssh-keygen -l (256 SHA256:... comment (ED25519)), or undefined where there is none.

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

publicKeyArgvfunction
function publicKeyArgv(privateKeyFile: string): readonly string[]

The arguments that make the public key of a private key file: ssh-keygen -y -f <file>; the file is named, never read here.

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

knownHostNamefunction
function knownHostName(t: Target): string

The host as a known-hosts file names it: the address, or [address]:port for a port other than 22.

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

removeHostArgvfunction
function removeHostArgv(t: Target, knownHostsFile: string): readonly string[]

The arguments that remove a host from a known-hosts file: ssh-keygen -R <host> -f <file>.

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

findPrincipalsArgvfunction
function findPrincipalsArgv(allowedSigners: string, signatureFile: string): readonly string[]

The arguments that find who signed: ssh-keygen -Y find-principals -s <signature> -f <allowed signers>.

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

KeygenInputtypeno test imports it
type KeygenInput = { readonly type: "ed25519" | "rsa"; readonly comment: string; readonly file: string; readonly bits?: number };

What a key is made with.

keygenArgvfunction
function keygenArgv(i: KeygenInput): readonly string[]

The arguments that make a key with no passphrase: ssh-keygen -q -t <type> [-b bits] -N "" -C <comment> -f <file>. A key a person protects with a passphrase is made by the person, interactively.

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

pinnedKnownHostsfunction
function pinnedKnownHosts(t: Target, keys: readonly HostKey[]): string

The text of a known-hosts file for the keys pinned for a target: one line for each, the host as the file names it ([address]:port where the port is not 22). Used as the file of the family pinned.

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

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