feat(tests,clear_signing): update definition fixtures from dev
What changed, and why it matters
This commit updates an internal helper script used to refresh test data for Ethereum 'clear signing' definitions. It adds an optional --dev mode so developers can fetch unsigned development definitions from an internal-only server and verify them with development keys. There is no change to the firmware that runs on customer devices, no change to production signature verification, and no disclosed security issue.
No security action required. Treat as a normal development tooling change. If reviewing, confirm the dev verification path is only reachable via the --dev flag and that dev keys are not used in production builds.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies tools/snippets/eth_defs_refresh_json.py and its README. It adds a –dev flag, a DEV_URL pointing to an internal-only bucket, and a verify_dev() helper that validates definitions signed with all three development keys (sigmask 0b111) instead of the usual single combined dev key. Production verification logic is unchanged. The script is a test/development utility, not part of the shipped firmware or production wallet code.
Changed components
tools/snippets/eth_defs_refresh_json.pytools/snippets/README.mdInspect captured patch +61 / −9
### tools/snippets/README.md
@@ -27,6 +27,8 @@ These scripts do not need to have a high standard, but each of those should have
(`common/tests/fixtures/ethereum/definitions`) with the latest production ones
from `data.trezor.io`, so the tests reflect what customers see.
- Verifies the production signatures; definitions missing upstream are kept and reported.
+- With `--dev`, fetches the dev definitions (`dev.firmware.sldev.cz`, internal network only)
+ and verifies them with the development keys instead.
## [eth_defs_dat_to_json.py](./eth_defs_dat_to_json.py)
- Converts a single signed `.dat` definition into the JSON fixture format, reusing
### tools/snippets/eth_defs_refresh_json.py
@@ -23,10 +23,13 @@
from pathlib import Path
import click
+import requests
-from trezorlib import definitions, messages, protobuf
+from trezorlib import cosi, definitions, merkle_tree, messages, protobuf
+from trezorlib.testing.common import PRIVATE_KEYS_DEV
PROD_URL = "https://data.trezor.io/firmware/definitions/v2/"
+DEV_URL = "https://dev.firmware.sldev.cz/unsigned/v2/definitions/"
MESSAGE_TYPES: dict[messages.DefinitionType, type[protobuf.MessageType]] = {
messages.DefinitionType.ETHEREUM_NETWORK: messages.EthereumNetworkInfo,
@@ -44,14 +47,38 @@
/ "definitions"
)
+# trezor/definitions dev-signs with all three development keys (sigmask 0b111),
+# unlike `Definition.verify(dev=True)`, which expects a single combined key.
+# TODO: definitions should also sign with a single key, for dev.
+DEV_DEPLOY_PUBLIC_KEYS = [cosi.pubkey_from_privkey(k) for k in PRIVATE_KEYS_DEV]
+
+
+def verify_dev(definition: definitions.Definition) -> None:
+ """Verify a definition signed by the dev deployment of trezor/definitions,
+ or by the local test helpers."""
+ if definition.sigmask != 0b111:
+ definition.verify(dev=True)
+ return
+ root = merkle_tree.evaluate_proof(definition.payload.build(), definition.proof)
+ cosi.verify(
+ definition.signature,
+ root,
+ len(DEV_DEPLOY_PUBLIC_KEYS),
+ DEV_DEPLOY_PUBLIC_KEYS,
+ definition.sigmask,
+ )
+
def dat_to_dict(dat: bytes, dev: bool = False) -> dict:
"""Verify a signed definition (production keys unless `dev`) and decode it
into the JSON fixture format (definition type and message)."""
definition = definitions.Definition.parse(dat)
if len(definition.build()) != len(dat):
raise ValueError("trailing data after the definition")
- definition.verify(dev=dev)
+ if dev:
+ verify_dev(definition)
+ else:
+ definition.verify()
payload = definition.payload
msg_type = MESSAGE_TYPES[payload.data_type]
msg = protobuf.load_message(io.BytesIO(payload.data), msg_type)
@@ -70,32 +97,55 @@ def dat_to_dict(dat: bytes, dev: bool = False) -> dict:
type=click.Path(exists=True, file_okay=False, resolve_path=True, path_type=Path),
default=DEFAULT_DIR,
)
-@click.option("-u", "--url", default=PROD_URL, show_default=True, help="Base URL.")
-def refresh(directory: Path, url: str) -> None:
+@click.option(
+ "-u",
+ "--url",
+ help=f"Base URL. [default: {PROD_URL}, or {DEV_URL} with --dev]",
+)
+@click.option(
+ "--dev",
+ is_flag=True,
+ help="Fetch the dev definitions",
+)
+def refresh(directory: Path, url: str | None, dev: bool) -> None:
"""Refresh the JSON definitions under DIRECTORY with the latest ones
- published at URL, i.e. what customers currently see.
+ published at URL, i.e. what customers currently see (or, with --dev, what
+ the dev deployment currently serves; internal network only).
Only existing files are refreshed; definitions that are missing upstream
are left untouched and reported. DIRECTORY defaults to the Ethereum
definitions in the common test fixtures."""
- source = definitions.UrlSource(url)
- updated, missing = [], []
+ source = definitions.UrlSource(url or (DEV_URL if dev else PROD_URL))
+ updated, missing, denied = [], [], 0
json_files = sorted(directory.rglob("*.json"))
for json_path in json_files:
rel = json_path.relative_to(directory)
- dat = source.fetch_path(*rel.with_suffix(".dat").parts)
+ try:
+ dat = source.fetch_path(*rel.with_suffix(".dat").parts)
+ except requests.HTTPError as e:
+ # the dev bucket answers 403 (not 404) for objects that do not exist
+ if dev and e.response is not None and e.response.status_code in (401, 403):
+ denied += 1
+ dat = None
+ else:
+ raise click.ClickException(f"{rel}: {e}") from e
if dat is None:
missing.append(rel)
continue
try:
- converted = dat_to_dict(dat)
+ converted = dat_to_dict(dat, dev=dev)
except Exception as e:
raise click.ClickException(f"{rel}: {e}") from e
new_text = json.dumps(converted, indent=2) + "\n"
if json_path.read_text() != new_text:
json_path.write_text(new_text)
updated.append(rel)
+ if json_files and denied == len(json_files):
+ raise click.ClickException(
+ "Dev definitions can only be accessed from the internal network."
+ )
+
for rel in updated:
click.echo(f"updated: {rel}")
for rel in missing:Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.