Commit 70b1140
feat(cert_authority): M19.1 — parse hashed known_hosts entries (FR-84 read) (#22)
Replaces the M14-era "skip hashed entries" stub with a real parser
for OpenSSH's `HashKnownHosts yes` format (PRD §5.8.8 FR-84 read
side).
src/cert_authority.rs (~120 lines net):
- New pub struct `HashedHost { salt: [u8;20], hash: [u8;20],
fingerprint: String }` with `pub fn matches(&self, host: &str)
-> bool` running HMAC-SHA1(self.salt, host.as_bytes()) and
comparing in constant time via `Hmac::verify_slice`.
- New `KnownHostsFile.hashed: Vec<HashedHost>` field, populated by
the parser alongside the existing direct/cert_authorities/revoked
classes. Backward-compatible (additive) — existing consumers
that destructure `KnownHostsFile { direct, cert_authorities,
revoked }` get an `unused field` warning at most; pattern matches
with `..` keep working.
- New private `parse_hashed_token(token) -> Option<([u8;20], [u8;20])>`
decodes a single `|1|<base64-salt>|<base64-hash>` token. Returns
None for any deviation from the expected form (missing prefix,
missing inner `|`, base64 decode failure, wrong byte length) —
callers warn-and-skip on None instead of erroring.
- The line-level skip at the top of parse_known_hosts is gone;
`|1|...` detection moved into the per-token loop so a comma-
separated host column can mix hashed and plaintext tokens (each
token is classified independently and lands in either `hashed`
or `direct` with a shared fingerprint).
Cargo.toml:
- Direct deps: `hmac = "0.12"`, `sha1 = "0.10"`, `base64 = "0.22"`.
All three were already pulled transitively via ssh-key/russh;
declaring them keeps intent legible in cargo tree.
- Dev-deps: same three crates so the integration test builder
can construct fixtures programmatically.
tests/test_hashed_hosts.rs (new, ~180 lines):
- 8 hermetic tests, all using a programmatic fixture builder
that runs the same HMAC-SHA1 computation Anvil uses at runtime.
This proves the parser+matcher round-trip without committing
pre-generated golden bytes that future maintainers can't audit.
- Covers: single-line parse, single-host match, mismatch /
empty-string / substring rejection, mixed file with hashed
+ plaintext + comments, malformed-token warn-and-skip, multi-
host column with one hash per token, Clone+Eq derive stability,
and case-sensitivity-by-design (no implicit case-folding —
callers lower-case before matches() if they want OpenSSH's
hostfile.c::lowercase semantics).
The HMAC-SHA1 here is a privacy primitive (file-readable host
enumeration resistance), NOT a security primitive. SHA-1
collisions don't matter — salt is per-line and 160 bits, input is
a low-entropy hostname, and the threat model is exactly OpenSSH's:
hide the host list from a casual file reader. Documented inline
in cert_authority.rs's module doc-comment.
Plan: M19.1 of anvil-gitway-milestone-plan.md.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 746ae4b commit 70b1140
4 files changed
Lines changed: 312 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
36 | 44 | | |
37 | 45 | | |
38 | 46 | | |
| |||
66 | 74 | | |
67 | 75 | | |
68 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
69 | 85 | | |
70 | 86 | | |
71 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
35 | 50 | | |
| 51 | + | |
36 | 52 | | |
37 | 53 | | |
38 | 54 | | |
| |||
86 | 102 | | |
87 | 103 | | |
88 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
89 | 149 | | |
90 | 150 | | |
91 | 151 | | |
| |||
95 | 155 | | |
96 | 156 | | |
97 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
98 | 162 | | |
99 | 163 | | |
100 | 164 | | |
| |||
119 | 183 | | |
120 | 184 | | |
121 | 185 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | 186 | | |
130 | 187 | | |
131 | 188 | | |
| |||
135 | 192 | | |
136 | 193 | | |
137 | 194 | | |
138 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
139 | 198 | | |
140 | 199 | | |
141 | 200 | | |
| |||
147 | 206 | | |
148 | 207 | | |
149 | 208 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
155 | 232 | | |
156 | 233 | | |
157 | 234 | | |
158 | 235 | | |
159 | 236 | | |
160 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
161 | 254 | | |
162 | 255 | | |
163 | 256 | | |
| |||
0 commit comments