Skip to content

apt: an expired or revoked signing key is refused, and stops signing when it expires - #922

Open
schmitch wants to merge 2 commits into
mainfrom
claude/768-apt-signing-key-expiry
Open

schmitch wants to merge 2 commits into
mainfrom
claude/768-apt-signing-key-expiry

Conversation

@schmitch

Copy link
Copy Markdown
Member

Fixes #768

Problem

Importing a repository signing key accepted any v4 Ed25519 key with a key that may sign, and signer() took the newest subkey with the signing flag. Neither looked at expiry or revocation, so InRelease and Release.gpg were signed with a key apt refuses (EXPKEYSIG, REVKEYSIG) and apt-get update failed for every client.

What changes

Reading the certificate (crates/server/src/indexes/signing.rs, Certificate). Validity is read from the key's own signatures, and only from ones that verify with the primary key; a signature that is merely present (another key's certification, a forged revocation) says nothing.

  • Primary key, revoked: a key revocation signature (0x20) that verifies.
  • Primary key, expiry: the key expiration time, counted from the key's creation time, in the newest direct key signature and in the newest self-certification of each user id that is not revoked. Verifiers differ in which of these they read (gpgv prefers the direct key signature, sqv the primary user id's), so the earliest one holds.
  • Subkey: the newest subkey binding signature (0x18) that verifies gives its flags and its expiry (from the subkey's creation time); any subkey revocation signature (0x28) that verifies revokes it.
  • A self-signature that itself expires holds no longer than that.

Import. A key whose primary key is expired or revoked is refused with the reason (the key expired on 2024-01-31 00:00 UTC, the key is revoked). Expired and revoked signing subkeys are skipped: the newest valid one signs, else the primary key if it may sign. When none is left the import is refused, naming each subkey and why.

Signing. signer() chooses among the keys valid now, on every signature. It still signs with Ed25519 only: if the key it would fall back to is of another algorithm, the key does not sign.

A key that expires after it was imported (the decision the issue leaves open):

  • It stops signing. The repository's other keys sign the next index; the expired key stays in key.asc / key.gpg. The server logs a warning naming the key and the reason.
  • When no key of the repository can sign, the index is not made: neither unsigned, nor with a signature every client refuses. Requests for the index files (InRelease, Release, Release.gpg, Packages, key.asc) answer 503 with a body naming the key and the reason, and the server logs an error. Package uploads and downloads go on. Adding a key (generated or imported) brings the index back.
  • An index made before the key expired is not remade until the repository changes; its signature of the expired key is what apt reports as EXPKEYSIG.
  • The administrator sees it in Signing keys: each key shows never expires, expires <date> (a warning badge within 30 days) or expired <date>. An expired key beside a valid one gets a warning notice; when every key has expired, a danger notice says nothing signs and what to do.

Admin API and UI. GET / POST /admin/repositories/{name}/signing-keys return expires_at (null for never): when the primary key expires, or the last of the keys that may sign. It is read from the stored certificate, so there is no migration and keys stored before this change show it too. The panel (web/src/components/SigningKeysPanel.tsx) shows it.

Docs and changelog. docs/apt.md (Signing keys) describes all of the above; fragment docs/changes/2.2.0/768.fixed.md. The issue was in Backlog and is moved to 2.2.0, the next release.

Tests

  • Unit (indexes::signing): expired primary, revoked primary, expired subkey, revoked subkey (each with a primary key that may sign, which takes over, and one that may not, which is refused), a key expiring later (accepted, expiry reported), signer_at no longer choosing a subkey or key that expired since the import, the newest self-signature holding whatever its position, and forged revocations and expiries being ignored.
  • Integration (crates/server/tests/apt.rs, signing_keys_expire): the admin API refuses expired and revoked keys with the reason and returns expires_at; a key expiring during the test drops out of InRelease and Release.gpg; with only that key left the index files answer 503 with the reason while uploads and downloads work; adding a key restores the index.
  • Web (SigningKeysPanel.test.tsx): the expiry labels and both notices.

The import tests and the integration test fail on main (the expired key is imported, 201 instead of 400) and pass here.

Checked by hand against GnuPG 2.4.4: keys made with gpg (expired primary, revoked primary, expired and revoked subkeys, an expiry extended with --quick-set-expire, future expiries) are refused or accepted as gpg --list-keys rates them, with the same expiry dates; the keys the unit tests build are rated the same by gpg --show-keys; and gpgv reports a good signature for each accepted key.

Not in this pull request

  • A signing subkey's back signature (0x19) is still not checked on import. gpg requires it, but it is not what the issue is about.
  • Extending an expiry in the administrator's keyring cannot be brought to the stored key: importing the same key again answers 409, as before. The docs say to add another key and delete the expired one.
  • .github/scripts/apt-e2e.sh (real apt-get) has no step for this, and I did not run it or the Playwright suite.

Generated by Claude Code

…when it expires

Importing a repository signing key accepted any v4 Ed25519 key with a key
that may sign, and the signer was the newest subkey with the signing flag,
whatever its expiry or revocation: InRelease and Release.gpg were signed
with a key apt refuses (EXPKEYSIG, REVKEYSIG).

The certificate's self-signatures now decide, each verified with the
primary key and the newest of its kind holding: the import refuses a key
whose primary key is expired or revoked, with the reason, and skips an
expired or revoked signing subkey (refusing the key when none that may sign
is left). The signer is chosen among the keys valid now, so a key that
expires after its import stops signing: the repository's other keys sign
the index, and with none left the index is not made and its files answer
503 with the reason. The admin API returns a key's expiry (expires_at) and
the signing keys panel shows it, and marks expired keys.

Fixes #768

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_012e6DJaQXxhrXDgeHFf6ZA1
The unit test of a key's shown expiry read the clock again for the expected
value, a second later than the key was made when the two reads fell on
either side of a second. The expected expiry is now the key's own creation
time plus its lifetime, in the integration test too, which also makes
another short-lived key when a slow machine let the first one expire before
its import, and checks the signature of the key about to expire only on an
index that was fetched before it did.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_012e6DJaQXxhrXDgeHFf6ZA1

This branch has not been deployed

No deployments
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.

apt: an imported signing key that is expired or revoked is accepted and signs indexes apt refuses

2 participants