Skip to content

feat(events): add signed event firmware OTA endpoint - #110

Draft
RCGV1 wants to merge 2 commits into
meshtastic:masterfrom
RCGV1:codex/event-ota-contract
Draft

feat(events): add signed event firmware OTA endpoint#110
RCGV1 wants to merge 2 commits into
meshtastic:masterfrom
RCGV1:codex/event-ota-contract

Conversation

@RCGV1

@RCGV1 RCGV1 commented Jul 29, 2026

Copy link
Copy Markdown
Member

Status

Warning

Currently untested with a physical event-firmware OTA round trip. This endpoint is fail-closed and returns 503 until Meshtastic configures a project-owned Ed25519 signing key. The listed DEF CON target must complete hardware validation before that secret is enabled.

Summary

  • Adds GET /resource/eventFirmware/:edition/ota for per-edition signed OTA contracts.
  • Signs the exact JSON payload bytes with Ed25519 and returns a keyId, base64 payload, and base64 signature.
  • Adds exact T-Beam S3 Core DEF CON 34 and return-to-standard artifacts using commit-pinned URLs, verified byte counts, and SHA-256 digests.
  • Validates release identity, whole-second UTC timestamps and real calendar dates, edition/release uniqueness, exact target uniqueness, release/artifact version consistency, immutable approved origins, architecture metadata, byte ceilings, and signing key identifiers.
  • Returns 404 for unknown editions, 502 for invalid release data, and 503 when signing infrastructure is unavailable.
  • Runs the contract tests in API CI.

Why

The display manifest is not an authorization boundary for executable firmware. Apple and future clients need an independently signed contract that selects one exact device artifact, verifies it before OTA, and carries an explicit standard-firmware return image.

Validation

  • pnpm test: 10 tests passed
  • pnpm build: passed
  • pnpm biome ci on every changed source/config file: passed
  • jq empty data/eventFirmwareOTA.json: passed
  • API CI quality and build: passed
  • Both commit-pinned artifacts return HTTP 200 with the signed byte counts.

The repository-wide Biome run still reports two pre-existing warnings in src/lib/mqtt.ts and src/services/gateway.ts; this PR does not touch them.

Dependencies

Deployment Notes

Before enabling this endpoint in production:

  1. Generate and custody a project-owned Ed25519 release key.
  2. Configure EVENT_FIRMWARE_SIGNING_KEY_ID and EVENT_FIRMWARE_SIGNING_PRIVATE_KEY_PEM.
  3. Ship the corresponding raw public key in clients.
  4. Complete the physical event-to-standard OTA matrix for every listed target.

nRF artifacts are intentionally absent. The current Apple app cannot prove the installed nRF bootloader version, so those devices must continue to use the web flasher.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds event firmware OTA contract data, strict validation, Ed25519 signing, an edition-based HTTP endpoint, environment configuration, tests, and CI execution for the new test script.

Changes

Event firmware OTA

Layer / File(s) Summary
OTA contract data and validation
src/lib/eventFirmwareOTA.ts, data/eventFirmwareOTA.json
Defines OTA contract types, validates artifact metadata and release timestamps, loads and caches the dataset, and supports normalized edition lookup.
Contract signing and HTTP route
src/lib/eventFirmwareOTA.ts, .env.example, src/routes/eventFirmwareOTA.ts, src/routes/index.ts, src/index.ts
Signs validated contracts with Ed25519 and serves them from resource/eventFirmware/:edition/ota with configured error responses and cache headers.
Signing and validation test coverage
tests/eventFirmwareOTA.test.ts, package.json, .github/workflows/ci.yml
Tests signing, lookup, and validation failures, adds the test script, and runs tests in CI after building.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Poem

I’m a rabbit with firmware tucked neat,
Signing OTA contracts makes hops complete.
Keys guard the payload, checks catch the flaws,
Routes carry releases with crisp little paws,
And CI tests every leap in the logs.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a signed event firmware OTA endpoint.

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

Comment @coderabbitai help to get the list of available commands.

@RCGV1

RCGV1 commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
tests/eventFirmwareOTA.test.ts (1)

55-65: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Assert the exact payload bytes and returned key ID.

This test checks decoded JSON equality and signature validity, but a regression that changes serialization or drops the key ID would still pass. Assert both protocol fields explicitly.

Proposed test additions
 const payload = Buffer.from(envelope.payload, "base64");
+assert.equal(envelope.keyId, "event-release-2026");
+assert.equal(payload.toString("utf8"), JSON.stringify(contract));
 assert.deepEqual(JSON.parse(payload.toString()), contract);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/eventFirmwareOTA.test.ts` around lines 55 - 65, Update the test around
verifySignature to assert that the decoded envelope payload bytes exactly match
the expected serialized contract, rather than only comparing parsed JSON, and
assert the returned key ID explicitly instead of checking only a boolean
signature result. Preserve the existing base64 decoding and signature
verification inputs.
package.json (1)

11-12: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Make test discovery shell-independent.

The unquoted tests/**/*.test.ts pattern can be expanded differently by the shell and may omit direct test files when nested test directories are added. Prefer tsx --test or quote the glob. tsx delegates to Node’s test runner, whose documentation recommends quoting command-line globs; tsx --test also auto-discovers TypeScript test files. (tsx.is)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` around lines 11 - 12, Update the package.json test script to
make test discovery shell-independent by relying on tsx --test auto-discovery or
by quoting the tests/**/*.test.ts glob. Preserve execution of both direct and
nested TypeScript test files.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/eventFirmwareOTA.ts`:
- Around line 195-197: Update the dataset-loading validation around
validateEventFirmwareOTAContract in the cached.contracts loop to track contract
editions and reject duplicate editions, including duplicate valid DEFCON
contracts, before endpoint selection can use the data. Preserve validation of
each contract while raising an error for any repeated edition.
- Around line 159-172: Update the timestamp validation in the validity-window
logic around ISO8601_RE and Date.parse to reject normalized calendar dates:
after parsing each timestamp, compare new Date(value).toISOString() with its
original value, and call fail when either comparison differs. Preserve the
existing finite-value and expiresAt-after-issuedAt checks.

In `@src/routes/eventFirmwareOTA.ts`:
- Around line 19-26: Update the catch handling in the eventFirmwareOTA route
around signEventFirmwareOTAContract to return HTTP 503 instead of 502 for local
signing configuration, key-type validation, or signing failures. Preserve the
existing error logging and JSON success response.

---

Nitpick comments:
In `@package.json`:
- Around line 11-12: Update the package.json test script to make test discovery
shell-independent by relying on tsx --test auto-discovery or by quoting the
tests/**/*.test.ts glob. Preserve execution of both direct and nested TypeScript
test files.

In `@tests/eventFirmwareOTA.test.ts`:
- Around line 55-65: Update the test around verifySignature to assert that the
decoded envelope payload bytes exactly match the expected serialized contract,
rather than only comparing parsed JSON, and assert the returned key ID
explicitly instead of checking only a boolean signature result. Preserve the
existing base64 decoding and signature verification inputs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c5b677df-1f16-40f7-b299-24e0db4b2765

📥 Commits

Reviewing files that changed from the base of the PR and between 6806e7e and f37b7e0.

📒 Files selected for processing (9)
  • .env.example
  • .github/workflows/ci.yml
  • data/eventFirmwareOTA.json
  • package.json
  • src/index.ts
  • src/lib/eventFirmwareOTA.ts
  • src/routes/eventFirmwareOTA.ts
  • src/routes/index.ts
  • tests/eventFirmwareOTA.test.ts

Comment thread src/lib/eventFirmwareOTA.ts
Comment thread src/lib/eventFirmwareOTA.ts Outdated
Comment thread src/routes/eventFirmwareOTA.ts Outdated
@RCGV1

RCGV1 commented Jul 29, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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