Skip to content

deb: check Release signatures against a configured keyring - #152

Merged
andrew merged 2 commits into
git-pkgs:mainfrom
simonchrz:feat/deb-release-signature
Nov 24, 2026
Merged

andrew merged 2 commits into
git-pkgs:mainfrom
simonchrz:feat/deb-release-signature

Conversation

@simonchrz

@simonchrz simonchrz commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #145.

WithDebianKeyring(archiveURL, keyring) gives an archive an OpenPGP keyring, binary or one or more armored blocks. With one, InRelease must be clearsigned by one of its keys, a Release without InRelease needs a valid Release.gpg, and a suite with neither, a signed Release without SHA256 sums, or one whose Valid-Until has passed, is refused. Of several signatures, one that verifies is enough, as in apt. Only the signed text is parsed. Archives without a keyring are read as before, and the README says nothing is verified then.

This adds github.com/ProtonMail/go-crypto, since x/crypto/openpgp is deprecated. It isn't imported by the packages tested under TinyGo.

WithDebianKeyring gives an archive an OpenPGP keyring. Its InRelease
must then be clearsigned by one of the keys, a Release without InRelease
needs a valid Release.gpg, and a suite with neither is refused. Only the
signed text is read. Archives without a keyring are read as before.

Uses github.com/ProtonMail/go-crypto, as x/crypto/openpgp is deprecated.
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ec8e8530-eaa5-490a-822b-5567c77d0146
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. The opt-in shape is right and the tests cover the tampering cases well. To answer the question on #145: yes, ProtonMail/go-crypto is fine as a dependency.

Three things before it merges, two inline and one here.

Valid-Until should be checked in this PR. With a keyring set, a Release whose Valid-Until is in the past should be refused, so an old validly signed Release can't be replayed. A Release without the field is accepted as now. Please add a test for an expired one.

Comment thread internal/deb/signature.go Outdated
if block == nil {
return nil, fmt.Errorf("%w: malformed clearsigned message", ErrUnsigned)
}
if _, err := block.VerifySignature(r.keyring, nil); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one signature gets tried. VerifyDetachedSignature stops at the first signature packet whose issuer is in the keyring and returns that one's result, so if that key is expired or revoked the Release is refused even when another signature on it is good. Debian's InRelease files carry several signatures (bookworm currently has three), and apt accepts any good one.

I reproduced it with clearsign.EncodeMulti over an expired key followed by a current key: with both in the keyring the result is ErrBadSignature: openpgp: key expired, and with only the current key it passes.

Please read the signature packets and verify each in turn, accepting the first that verifies, here and in verifyDetached, and add a two-signer test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6816eb1: the signature packets are split and each is verified in turn, the first good one is accepted, for both InRelease and Release.gpg. Added your EncodeMulti case (expired key then current key) and a detached one with two signatures, binary and armored.

Comment thread internal/deb/signature.go Outdated

func readKeyring(data []byte) (openpgp.EntityList, error) {
if bytes.Contains(data, []byte("-----BEGIN PGP")) {
return openpgp.ReadArmoredKeyRing(bytes.NewReader(data))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadArmoredKeyRing decodes a single armor block, so a keyring made by concatenating .asc files (say archive-key-12.asc and release-12.asc) loads only the first key and reports no error. A Release signed by a later key then fails with signature made by unknown entity.

Please loop armor.Decode until EOF and append each block's keys, with a test for two concatenated blocks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6816eb1: each armored block is decoded and its keys appended. armor.Decode says it may read past its block, so the data is split at each armor header rather than decoding repeatedly from one reader. Test with two concatenated .asc blocks.

With a keyring, a signed Release whose Valid-Until has passed is refused,
so an old one can't be replayed; one without the field is read as before.

Each signature on InRelease or Release.gpg is now tried in turn and the
first that verifies is enough, as apt does. go-crypto checked only the
first signature whose issuer was in the keyring, so one by an expired
key refused a Release that also had a good signature.

A keyring of concatenated armored blocks now loads every block's keys,
not just the first.
@simonchrz

Copy link
Copy Markdown
Contributor Author

Thanks. All three are in 6816eb1: a Valid-Until in the past is refused when a keyring is set (a Release without it is read as before), every signature is tried and the first good one is enough, and concatenated armored keyrings load all their keys.

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All three round-one points are fixed in 6816eb1 with tests that reproduce the original failures. Thanks.

@andrew
andrew merged commit 3c12a5b into git-pkgs:main Nov 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deb: verify the InRelease signature

2 participants