Skip to content

tests: re-sign repository_data with an expiry in 2050 - #3058

Open
yarrrly wants to merge 1 commit into
theupdateframework:developfrom
yarrrly:repository-data-expiry-2050
Open

yarrrly wants to merge 1 commit into
theupdateframework:developfrom
yarrrly:repository-data-expiry-2050

Conversation

@yarrrly

@yarrrly yarrrly commented Nov 23, 2026

Copy link
Copy Markdown

Description of the changes being introduced by the pull request:

The metadata in tests/repository_data expires at 2030-01-01T00:00:00Z. Once the clock passes it, 28 of the 208 tests error, 27 of them with ExpiredMetadataError: Final root.json is expired. Debian's archive rebuild with the clock set to 2030-08-09 hit the same error: https://bugs.debian.org/1127133

This moves expires to 2050-01-01 (generated_data and fishy_rolenames already expire in 2050) and re-signs the 13 files with the keys in tests/repository_data/keystore. Apart from expires and the signatures, only the snapshot hash in the two timestamp.json files changes. git diff --text shows the JSON diff, which GitHub hides (*.json binary). In test_api.py the two values that depend on these files are updated: the expected expiry and the blake2b-256 of snapshot.json.

To check, from the repository root with time-machine installed:

python3 -c "import time_machine, unittest; time_machine.travel('2030-01-02', tick=True).start(); unittest.main(module=None, argv=['unittest', 'discover'])"

On develop this gives FAILED (errors=28). With this change it passes, also with the clock at 2049-12-31. At today's date the suite, coverage (98%), ruff and mypy give the same results as before.

If you would rather have the script in the tree (see #1806), I can add it.

Script used to re-sign (run from the repository root)
"""Move the expiry of tests/repository_data metadata and re-sign it.

Run from the repository root. Only "expires", the signatures and the
snapshot hash in timestamp.json change.
"""

import os
import shutil
from datetime import UTC, datetime

from securesystemslib.signer import CryptoSigner

from tuf.api.metadata import Metadata, MetaFile
from tuf.api.serialization.json import JSONSerializer

EXPIRY = datetime(2050, 1, 1, tzinfo=UTC)
DATA = os.path.join("tests", "repository_data")
REPO = os.path.join(DATA, "repository", "metadata")
CLIENT = os.path.join(DATA, "client", "test_repository1", "metadata", "current")

# role: (delegating role, key file); timestamp last, it hashes snapshot.json
SIGNERS = {
    "root": ("root", "root_key"),
    "targets": ("root", "targets_key"),
    "role1": ("targets", "delegation_key"),
    "role2": ("role1", "delegation_key"),
    "snapshot": ("root", "snapshot_key"),
    "timestamp": ("root", "timestamp_key"),
}


def resign(md_dir: str) -> None:
    """Re-sign the six top-level and delegated roles in md_dir."""
    md = {
        r: Metadata.from_file(os.path.join(md_dir, f"{r}.json"))
        for r in SIGNERS
    }
    for role, (delegator, keyfile) in SIGNERS.items():
        md[role].signed.expires = EXPIRY
        if role == "timestamp":
            with open(os.path.join(md_dir, "snapshot.json"), "rb") as f:
                old = md[role].signed.snapshot_meta
                md[role].signed.snapshot_meta = MetaFile.from_data(
                    old.version, f.read(), list(old.hashes)
                )
        keyid = next(iter(md[role].signatures))
        parent = md[delegator].signed
        key = (
            parent.get_key(keyid)
            if delegator == "root"
            else parent.delegations.keys[keyid]
        )
        uri = f"file2:{os.path.join(DATA, 'keystore', keyfile)}"
        md[role].sign(CryptoSigner.from_priv_key_uri(uri, key))
        # write into the existing file to keep its mode
        with open(os.path.join(md_dir, f"{role}.json"), "wb") as f:
            f.write(md[role].to_bytes(JSONSerializer(compact=False)))


resign(REPO)
resign(CLIENT)  # client role2.json differs from the repository copy
# root uses RSA-PSS (randomized): keep the three root files identical
for dst in (
    os.path.join(REPO, "1.root.json"),
    os.path.join(CLIENT, "root.json"),
):
    shutil.copyfile(os.path.join(REPO, "root.json"), dst)

The metadata in tests/repository_data expires on 2030-01-01. From then
on 28 tests in test_trusted_metadata_set and test_updater_ng error,
mostly with "ExpiredMetadataError: Final root.json is expired".

Move the expiry to 2050-01-01, like generated_data and fishy_rolenames,
and re-sign the files with the keys in tests/repository_data/keystore.
Besides "expires" and the signatures, only the snapshot hash in
timestamp.json changes. Update the two values in test_api.py that depend
on these files: the expected expiry and the blake2b-256 of snapshot.json.

Signed-off-by: yarrrly <yarrrly@users.noreply.github.com>
@yarrrly
yarrrly requested a review from a team as a code owner November 23, 2026 06:53

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.

1 participant