Repository navigation
deb: check Release signatures against a configured keyring - #152
Conversation
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.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
andrew
left a comment
There was a problem hiding this comment.
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.
| if block == nil { | ||
| return nil, fmt.Errorf("%w: malformed clearsigned message", ErrUnsigned) | ||
| } | ||
| if _, err := block.VerifySignature(r.keyring, nil); err != nil { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
|
||
| func readKeyring(data []byte) (openpgp.EntityList, error) { | ||
| if bytes.Contains(data, []byte("-----BEGIN PGP")) { | ||
| return openpgp.ReadArmoredKeyRing(bytes.NewReader(data)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
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. |
Fixes #145.
WithDebianKeyring(archiveURL, keyring)gives an archive an OpenPGP keyring, binary or one or more armored blocks. With one,InReleasemust be clearsigned by one of its keys, aReleasewithoutInReleaseneeds a validRelease.gpg, and a suite with neither, a signed Release without SHA256 sums, or one whoseValid-Untilhas 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, sincex/crypto/openpgpis deprecated. It isn't imported by the packages tested under TinyGo.