| 1 | # sigverify |
| 2 | |
| 3 | sigverify verifies OpenSSH signatures and refuses any FIDO security-key signature made without a |
| 4 | touch. It reads standard SSHSIG, the format `ssh-keygen -Y sign` writes and git uses for SSH-signed |
| 5 | tags. It is a Go library (`the-valley/sigverify`) and a command (`sigverify`). |
| 6 | |
| 7 | sigverify judges one signature at a time and keeps no state. What a host must do around it to gate |
| 8 | releases safely is in [The caller's contract](#the-callers-contract). |
| 9 | |
| 10 | ## Why the verifier must check for a touch |
| 11 | |
| 12 | The operator's approvals and host releases are meant to be authorized by a touch on a hardware key. |
| 13 | Agents and the interactive coordinator run as the operator's Unix user. They can do anything the |
| 14 | operator's files allow, so the touch is the one step they cannot perform. |
| 15 | |
| 16 | A security key signs authenticator data, not the message itself. That data holds the message's hash |
| 17 | and a flags byte. The user-presence bit (UP, `0x01`) is set only when someone touched the key. The |
| 18 | user-verification bit (UV, `0x04`) is set only when the key also checked a PIN or biometric. Both |
| 19 | bits are inside the signed bytes, so nobody can change them after signing. |
| 20 | |
| 21 | Whether the key asks for a touch is decided by a flag in the key stub, the private key file on disk. |
| 22 | Anything running as the operator can clear that flag, either with |
| 23 | `ssh-keygen -p -O no-touch-required` (OpenSSH 10.5) or by editing the stub's bytes. The plugged-in |
| 24 | key then signs without a touch, and the signature records UP as clear. Clearing the stub's |
| 25 | verify-required flag the same way drops the PIN, and the signature records UV as clear. |
| 26 | |
| 27 | Standard verification never looks at the bits: |
| 28 | |
| 29 | - `ssh-keygen -Y verify` logs the flags at debug level and accepts the signature. |
| 30 | - `git verify-tag` with `gpg.format=ssh` calls `ssh-keygen -Y verify`, so it accepts it too. |
| 31 | - An allowed-signers file cannot ask for a touch. Its only options are `cert-authority`, |
| 32 | `namespaces`, `valid-after` and `valid-before`. |
| 33 | |
| 34 | So the presence check has to be in the verifier. sigverify does it on every security-key signature, |
| 35 | and nothing turns it off. |
| 36 | |
| 37 | ## Signer classes |
| 38 | |
| 39 | Every line of the allowed-signers file names a signer of one class: |
| 40 | |
| 41 | - **`fido-sk`**: a FIDO security key, `sk-ssh-ed25519@openssh.com` or |
| 42 | `sk-ecdsa-sha2-nistp256@openssh.com`. Its signatures carry UP and UV, and UP is always required. |
| 43 | - **`tkey-signer`**: a Tillitis TKey, on a line marked `tkey-signer`. The line's key must be |
| 44 | `ssh-ed25519`. |
| 45 | - **`software`**: any other key: `ssh-ed25519`, ECDSA, or RSA of at least 2048 bits. Its signatures |
| 46 | prove nothing about presence. |
| 47 | |
| 48 | A TKey signature is plain `ssh-ed25519` and carries no flags. It can still be trusted to need a |
| 49 | touch, for two reasons. The stock `tkey-device-signer` app requires a touch for every signature. And |
| 50 | the TKey derives its ed25519 key from the hash of the app it runs, so an app built to skip the touch |
| 51 | has a different key. The `tkey-signer` line pins the key, and so pins the app. The marker may carry |
| 52 | the app's version for bookkeeping, as `tkey-signer="1.0.0"`. sigverify reports the version and never |
| 53 | compares it with anything. Upgrading the app changes the key, so it is a planned trust-root |
| 54 | rotation. |
| 55 | |
| 56 | Each call names the classes it accepts. By default only `fido-sk` signers verify. A call accepts |
| 57 | other classes only when it asks for them, with `--allow-class`. Giving `--allow-class` replaces the |
| 58 | default. So: |
| 59 | |
| 60 | - A release or an approval uses the default. A TKey listed in the same file cannot sign it. |
| 61 | - A trust-root change passes `--allow-class tkey-signer`. A security key cannot sign it. |
| 62 | - `--allow-non-sk` adds `software`. It never makes an unmarked key count as a TKey: only a |
| 63 | `tkey-signer` line does that. |
| 64 | |
| 65 | A TKey cannot prove user verification, so `--require-uv` refuses TKey signatures. |
| 66 | |
| 67 | ## What is verified |
| 68 | |
| 69 | A signature is accepted only if every one of these holds, checked in this order: |
| 70 | |
| 71 | 1. It is a well-formed SSHSIG, armored or raw, with hash `sha256` or `sha512`. |
| 72 | 2. Its namespace is the one the caller names. The git-tag command always uses `git`. |
| 73 | 3. The signature verifies over the message. |
| 74 | 4. A line of the allowed-signers file lists the key, and all of these hold for that line: |
| 75 | - Its class is one the call accepts. |
| 76 | - Its principals match the principal the caller names. A principal is required. `--any-principal` |
| 77 | skips this check, and then even a line whose principals are all negated, such as `!*`, |
| 78 | authorizes its key. |
| 79 | - Its `namespaces`, if present, match the namespace. |
| 80 | - The verify time falls between its `valid-after` and `valid-before`. |
| 81 | |
| 82 | Principal and namespace patterns use OpenSSH's own matching rules, and the tests compare them |
| 83 | with `ssh-keygen`. |
| 84 | |
| 85 | 5. A `fido-sk` signature has UP set. |
| 86 | 6. The signature has UV set, if the caller passes `--require-uv` or any matching line carries |
| 87 | `verify-required`. Only a `fido-sk` signature can. |
| 88 | |
| 89 | A success reports the principal, the signer class, the key type, the key's SHA256 fingerprint and, |
| 90 | for a security key, the authenticator flags and the signature counter. |
| 91 | |
| 92 | sigverify trusts the allowed-signers file completely. Anyone can make a software key in the |
| 93 | security-key format, and its signatures would carry whatever flags its maker chose. sigverify does |
| 94 | not check the enrollment attestation that would tell the two apart. So whoever can write the file |
| 95 | can sign anything; requirement 1 of the caller's contract is about this. sigverify also does not |
| 96 | track the signature counter, so it does not detect a replayed signature or a cloned key. |
| 97 | |
| 98 | ## What is refused |
| 99 | |
| 100 | Each refusal has a stable reason that callers can match on. |
| 101 | |
| 102 | | Reason | Meaning | |
| 103 | | ----------------------- | --------------------------------------------------------------------- | |
| 104 | | `malformed` | The signature, or the tag object holding it, cannot be read. | |
| 105 | | `unsigned` | The git tag has no signature, or is a lightweight tag. | |
| 106 | | `wrong-namespace` | The signature was made for another namespace. | |
| 107 | | `unsupported-key` | The key type is not one listed above, such as a certificate. | |
| 108 | | `bad-signature` | The signature does not verify over this message. | |
| 109 | | `unknown-key` | No allowed-signers line lists the key. | |
| 110 | | `class-not-allowed` | The key is listed, but only in a class the call does not accept. | |
| 111 | | `principal-not-allowed` | The key is listed, but not for the requested principal. | |
| 112 | | `namespace-not-allowed` | The key's line restricts it to other namespaces. | |
| 113 | | `not-yet-valid` | The verify time is before the key's `valid-after`. | |
| 114 | | `expired` | The verify time is after the key's `valid-before`. | |
| 115 | | `no-user-presence` | A genuine security-key signature made without a touch. | |
| 116 | | `no-user-verification` | UV is required and the signature does not prove it. | |
| 117 | | `tag-name-mismatch` | The tag object was signed under another name than the one it has now. | |
| 118 | | `target-not-commit` | The signed tag points at a tag, tree or blob, not a commit. | |
| 119 | | `target-missing` | The commit the signed tag points at is not in the repository. | |
| 120 | |
| 121 | A `no-user-presence` refusal means the key really did sign, without a touch. Something running as |
| 122 | the key's owner is using the key, and the refusal names the key's fingerprint on stderr for that |
| 123 | reason. |
| 124 | |
| 125 | ## Encodings |
| 126 | |
| 127 | sigverify accepts one encoding for each signature, and refuses the rest: |
| 128 | |
| 129 | - Armored base64 must be canonical: no stray padding bits, and nothing but line breaks inside the |
| 130 | armor. |
| 131 | - Nothing but whitespace may follow the armor footer. |
| 132 | - Integers must be in their minimal encoding, without redundant leading zero bytes. |
| 133 | - An RSA signature must be exactly as long as the key's modulus. |
| 134 | |
| 135 | One field is accepted in any form. The SSHSIG envelope has a reserved field, which `ssh-keygen` |
| 136 | reads and ignores, and so does sigverify. The bytes a key signs always hold an empty reserved field, |
| 137 | so whatever the envelope carries there cannot change what was signed. |
| 138 | |
| 139 | These rules leave signature bytes malleable in ways no verifier can prevent. An ECDSA signature has |
| 140 | two valid forms, and the reserved field can hold anything. None of this changes what was signed. |
| 141 | |
| 142 | ## Differences from ssh-keygen |
| 143 | |
| 144 | sigverify is stricter than `ssh-keygen -Y verify` in these ways: |
| 145 | |
| 146 | - It enforces UP, and UV when required. |
| 147 | - It requires a principal unless told otherwise. |
| 148 | - It refuses an allowed-signers file with any line it cannot parse, including unknown options. |
| 149 | ssh-keygen skips such a line, so a typo could silently drop a signer's restrictions. |
| 150 | - It refuses an allowed-signers file with a `no-touch-required` option on any line. |
| 151 | - It adds two allowed-signers options, `verify-required` and `tkey-signer`. `verify-required` is the |
| 152 | keyword sshd uses in `authorized_keys`. ssh-keygen does not know either one, and skips any line |
| 153 | carrying them. |
| 154 | - It does not verify certificates. A `cert-authority` line never matches, so a certificate signature |
| 155 | is refused. |
| 156 | - It refuses RSA keys under 2048 bits, and the encodings described above. |
| 157 | |
| 158 | The git-tag command also differs from `git verify-tag`: |
| 159 | |
| 160 | - It judges the validity window at the current time, or at `--verify-time`. git uses the tagger |
| 161 | date, which the signer chooses, so a key past its `valid-before` could sign a backdated tag. |
| 162 | - It refuses a tag whose signed name differs from the ref it was found under. Without this check, a |
| 163 | signed tag for an old release could be published again under a new release's name. |
| 164 | - It requires the tag to point at a commit, and that commit to be in the repository. |
| 165 | - It looks the tag up only as `refs/tags/NAME`. A name git would resolve elsewhere, such as a |
| 166 | remote-tracking ref, is not a tag. |
| 167 | - It runs git with replacement refs disabled. A replacement ref makes git read one object in place |
| 168 | of another, so it could otherwise substitute a different tag object or commit. |
| 169 | - It runs git in an environment of its own, inheriting nothing from the caller. Variables such as |
| 170 | `GIT_DIR`, `GIT_OBJECT_DIRECTORY` or `GIT_CONFIG_PARAMETERS` could otherwise send git to other |
| 171 | objects. User and system git configuration are not read. |
| 172 | - The Nix package compiles the absolute path of its git into the binary, so no `PATH` decides which |
| 173 | git runs. |
| 174 | |
| 175 | git refuses a repository owned by a user other than the one running it, and sigverify does not |
| 176 | override that. |
| 177 | |
| 178 | ## Using the command |
| 179 | |
| 180 | ``` |
| 181 | sigverify verify --namespace NS --signature FILE --allowed-signers FILE \ |
| 182 | (--principal ID | --any-principal) [--allow-class CLASS]... [--allow-non-sk] \ |
| 183 | [--require-uv] [--verify-time TIME] < message |
| 184 | |
| 185 | sigverify git-tag --repo DIR --tag NAME --allowed-signers FILE \ |
| 186 | (--principal ID | --any-principal) [--allow-class CLASS]... [--allow-non-sk] \ |
| 187 | [--require-uv] [--verify-time TIME] |
| 188 | ``` |
| 189 | |
| 190 | The exit status is 0 for verified, 1 for refused, and 2 for an error. An error means nothing was |
| 191 | judged: bad usage, an unreadable or invalid allowed-signers file, a missing tag, a git failure, or a |
| 192 | report that could not be written to stdout. |
| 193 | |
| 194 | The output depends on the exit status: |
| 195 | |
| 196 | - **0:** stdout is `verified`, followed by lines of the form `name value`. The whole report goes out |
| 197 | in one write. If that write fails, the exit status is 2, never 0. |
| 198 | - **1:** stdout is exactly one line, `refused <reason>`. stderr explains the refusal in a sentence. |
| 199 | Nothing about a refused tag's target appears anywhere, because none of it is authenticated. |
| 200 | - **2:** stdout is empty, and stderr says what went wrong. |
| 201 | |
| 202 | A verified release tag looks like this: |
| 203 | |
| 204 | ``` |
| 205 | $ sigverify git-tag --repo /srv/git/cosmo.git --tag v2026.10.04 \ |
| 206 | --allowed-signers /etc/cosmo/release-signers --principal release@cosmo --require-uv |
| 207 | verified |
| 208 | namespace git |
| 209 | principal release@cosmo |
| 210 | class fido-sk |
| 211 | key-type sk-ssh-ed25519@openssh.com |
| 212 | fingerprint SHA256:... |
| 213 | flags 0x05 |
| 214 | user-presence yes |
| 215 | user-verification yes |
| 216 | counter 42 |
| 217 | tag v2026.10.04 |
| 218 | commit 5d1c... |
| 219 | ``` |
| 220 | |
| 221 | The flake exposes the command as `packages.<system>.sigverify`, for `x86_64-linux` and |
| 222 | `aarch64-linux`. Its checks are defined for both systems. |
| 223 | |
| 224 | ## The caller's contract |
| 225 | |
| 226 | sigverify answers one question: does this signature verify against this file, under this policy? |
| 227 | These requirements are for the host-side caller that turns that answer into an activated release, |
| 228 | such as cosmo's converge. Each one closes a hole that sigverify cannot close by itself. |
| 229 | |
| 230 | 1. **Keep every trust root out of the operator account's reach.** The operator account must not be |
| 231 | able to write any of these: |
| 232 | - the allowed-signers file |
| 233 | - every parent directory of that file, and the target of any symlink on its path |
| 234 | - the sigverify binary |
| 235 | - the invocation policy: the flags the caller passes |
| 236 | - the activation service |
| 237 | - the rollback state of requirement 4 |
| 238 | |
| 239 | Each must be owned by root and not writable by the operator, or be in the Nix store of the |
| 240 | running system. Never take any of them from the candidate release being verified. Whoever can |
| 241 | write the allowed-signers file can list a software key in security-key format and sign any |
| 242 | release with UP and UV set. |
| 243 | |
| 244 | 2. **Verify releases with a principal and with UV.** Always pass `--principal` with the release |
| 245 | principal. Always pass `--require-uv`, or mark every release signer `verify-required` in the |
| 246 | protected allowed-signers file. Never pass `--any-principal`, `--allow-non-sk` or `--allow-class` |
| 247 | for a release. |
| 248 | |
| 249 | 3. **Apply exactly what was verified.** |
| 250 | - Act only on exit status 0 and a complete report, which starts with `verified` and has a |
| 251 | `commit` line. |
| 252 | - Use only the commit id on the `commit` line. Never resolve the tag name again, because a ref |
| 253 | can move after verification. |
| 254 | - Keep replacement refs disabled through fetch, checkout and build, with |
| 255 | `GIT_NO_REPLACE_OBJECTS=1` or `git --no-replace-objects`. A replacement ref makes git produce a |
| 256 | different commit's contents under the verified commit id. |
| 257 | - Run git with a sanitized environment throughout: no inherited `GIT_*` variables, and no user or |
| 258 | system configuration. |
| 259 | |
| 260 | 4. **Refuse rollback.** |
| 261 | - Derive a release sequence number from authenticated content: the verified tag name. Bind it to |
| 262 | the release stream and to the commit. |
| 263 | - Under an exclusive activation lock, compare it with the last accepted release in durable, |
| 264 | protected state. Reject a lower sequence. Reject an equal sequence that names a different |
| 265 | commit. Accept an equal sequence with the same commit only as an explicit retry of that |
| 266 | release. |
| 267 | - Write the accepted sequence and commit to that state crash-safely before activating. Hold the |
| 268 | lock until activation finishes, so an older activation cannot complete after a newer one. |
| 269 | - An authorized rollback is a newly signed release with a higher sequence that points at the |
| 270 | older commit. |
| 271 | |
| 272 | 5. **Never identify a release by its signature bytes.** Do not use the raw signature, or the bytes |
| 273 | of the tag object, to identify a release or to detect a replay. The same signed content can be |
| 274 | encoded more than one way (see [Encodings](#encodings)). Identify a release by its verified tag |
| 275 | name and commit id. |
| 276 | |
| 277 | ## Tests |
| 278 | |
| 279 | `nix flake check` runs two checks. `sigverify-unit` runs the Go tests. `sigverify-e2e` runs the |
| 280 | packaged command over a real signed tag, with an empty environment and no git on `PATH`. Both are |
| 281 | defined for `x86_64-linux` and `aarch64-linux`. `nix flake check` builds the checks for the |
| 282 | machine's own system. |
| 283 | `nix build .#checks.aarch64-linux.sigverify-unit .#checks.aarch64-linux.sigverify-e2e` runs the ARM |
| 284 | ones on an aarch64 builder, or on an x86 machine with aarch64 emulation. |
| 285 | |
| 286 | The tests need no hardware. Security-key signatures come from two sources: |
| 287 | |
| 288 | - `internal/skforge` derives keys from seed strings and makes signatures with chosen flags. It |
| 289 | rebuilds the signed bytes independently of the verifier, and it can take a signature apart and |
| 290 | alter one field. |
| 291 | - OpenSSH's `sk-dummy` is the software authenticator from OpenSSH's own regression suite. The checks |
| 292 | build it from the same source as the `ssh-keygen` they run. With it, real `ssh-keygen` makes |
| 293 | touchless signatures for ed25519-sk and ecdsa-sk keys: from keys generated with |
| 294 | `no-touch-required`, and from stubs whose flags are cleared after the keys were made. A cleared |
| 295 | verify-required flag gives a signature without UV. |
| 296 | |
| 297 | Some tests record that `ssh-keygen -Y verify` or `git verify-tag` accepts a signature sigverify |
| 298 | refuses. Those expectations are in subtests named `interop: ...`. If a future OpenSSH or git starts |
| 299 | refusing silent signatures, only those subtests fail. That failure is a change upstream, not a |
| 300 | sigverify regression. |
| 301 | |
| 302 | The tests compare sigverify's verdicts with `ssh-keygen -Y verify` across namespaces and validity |
| 303 | windows, and with `ssh-keygen -Y match-principals` across principal patterns. Outside nix, |
| 304 | `go test ./...` skips the `sk-dummy` cases unless `SIGVERIFY_SK_PROVIDER` names the provider. |