Repository navigation
fix: reject malformed prepend signatures and non-HSM keys, write -out atomically - #9
Conversation
… atomically ValidateSignatures now reads packets with packet.Read and only accepts binary-document signatures. Identity rejects sub-second lifetimes and creation times outside OpenPGP's uint32 range. NewKMSSigner requires an HSM protection level; KMSSigner rejects PSS and bounds each request with a timeout. The CLI writes -out via temp file and rename, refuses to overwrite the signed file, and cancels on SIGINT/SIGTERM. Adds fake-KMS, validation and CLI tests.
|
@codex review |
|
@codex security-review |
|
To use Codex here, create an environment for this repo. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex security-review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Testing
|
Fixes the findings from a code quality and security review of the module, and adds
AGENTS.md.What changed and why
ValidateSignaturesusedpacket.Reader.Next, which silently skips unknown, unsupported and marker packets. They were copied into the release signature, andgpg --verifythen failed (exit 2). Text and certification signatures were also accepted: gpg reports BAD for a certification signature, and with a text signature first it checks only that one, so the KMS signature goes unchecked.packet.Readand accept only binary-document signatures (type 0x00). A realgpg --detach-signsignature (gpg 2.4.8) still passes.Lifetimewas truncated to 0, meaning "never expires". ACreatedbefore 1970 or after 2106 silently wrapped around in the uint32 key field.Identity.validaterequires a lifetime in whole seconds and a creation time that fits the field.NewKMSSigneracceptedSOFTWAREand external keys, though the README says the key never leaves the HSM.HSMorHSM_SINGLE_TENANT.KMSSigner.Signreturned a PKCS#1 v1.5 signature when the caller asked for RSA-PSS.*rsa.PSSOptions.-outwas written withos.WriteFile: it followed symlinks, wasn't atomic, and could overwrite the file being signed.-outthat is the file to sign, or a symlink to it.-fingerprintpins "the identity".-keyand-created, not the user ID or-lifetime.AGENTS.mdis a contribution guide for AI agents: commands, layout, patterns, and the rule never to change the exported key bytes.Behaviour changes for consumers
gpg-releaseandgpg-terraform-providerhave protection levelHSM.-outneeds a writable directory, because the temp file is created next to it.-out /dev/stdoutno longer works. Both consumers write a normal file.-prependrejects files with non-signature packets or non-binary signatures. These used to produce a signature file that gpg rejected.-lifetimemust be whole seconds.35040his unaffected.Does the exported public key or fingerprint change?
No. Golden and compat tests pass unchanged, and
go test -run TestGoldenPublicKey -update .leavestestdata/clean.Tests
kms_test.go(new): a fake Cloud KMS server (httptest+option.WithEndpoint), sokms.gois tested for the first time. Covers a good signature with both HSM levels; and rejects a wrong algorithm, software, external or missing protection level, bad PEM or DER, a non-RSA key, PSS, SHA-512 or short digests, a corrupted KMS signature, and a hung request.gpgkms_test.go: lifetime and creation-time limits (including the largest valid values), a non-RSA signer, and aValidateSignaturestable (unknown and marker packets, public-key packet, text and certification signatures, empty and truncated input).cmd/gpgkms/main_test.go:-prependwith default armored output (old and new key both verify),public-key -armor=false, refusing-outequal to the input or a symlink to it, replacing a symlinked-outinstead of following it (mode 0644, no temp files left), and an expected error perTestRequiredFlagsrow. The "no out" row used to pass only because its input file did not exist.Every new test fails with the old
gpgkms.go,kms.goandcmd/gpgkms/main.go.Validation
gofmt -l .(empty),go vet ./...go test -race -shuffle=on -count=1 ./...go mod tidy -diff(root andtools/),go mod verifygo tool -modfile=tools/go.mod golangci-lint run ./...: 0 issuesgo tool -modfile=tools/go.mod govulncheck ./...: 0 vulnerabilities reachedGOOS=windows go vet ./...Not done here: checking that a prepended signature covers the signed file (it would need the old public key as a new input), and making
-fingerprintrequired forsign.Opened by Xum on behalf of @deansheather.