Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Foundation

/// The public keys the updater trusts to sign firmware releases (ADR 0012): the maintainer's primary key and the
/// offline backup key. Empty until the owner makes them (docs/FIRMWARE-RELEASE-SIGNING.md); until then every
/// fetched release is refused as signed by an unknown key, and the built-in firmware is used.
/// offline backup key, made by the owner on 2026-11-23 (docs/FIRMWARE-RELEASE-SIGNING.md). Public halves only.
public enum ReleaseKeys {
/// Each entry: (id, public key as 64 hex characters), as `firmware-release public-key` prints it.
static let listed: [(id: String, hex: String)] = []
static let listed: [(id: String, hex: String)] = [
("primary", "26739c2c075965fd9a99330f97c3b09a28d11f85c1fa4d81bd5495cb67c1a5f8"),
("backup", "2e972a79fd40b287a151166dcdc723d07e84afe9ffc933fb211c670873c07cbe"),
]

public static var trusted: [TrustedKey] {
listed.compactMap { entry in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ func publish(_ release: FakeFeed, on github: FakeGitHub) {
on: github)
}

@Test func withTheAppsKeysStillEmptyAWholeReleaseOffersTheBuiltInFirmwareAndSaysTheKeyIsUnknown() async throws {
/// With the owner's keys in the app (#689): a release signed by another key under the name "primary" offers the
/// built-in firmware and says the signature doesn't check out.
@Test func aReleaseSignedByAnImpostorPrimaryKeyOffersTheBuiltInFirmware() async throws {
let github = FakeGitHub()
publish(release(panelVersion: "1.1.0", sha: "bbbbbbb", signedBy: TestKey(id: "primary"), name: "deck-panel-1.1.0-bbbbbbb.bin"),
on: github)
let offer = await FirmwareOffer.fetch(http: github, over: try builtIn(panelVersion: "1.0.0", sha: "aaaaaaa"),
cache: temporaryFolder())
#expect(offer.source == "Firmware built into this app: deck panel 1.0.0")
#expect(offer.reason == "The newest release is signed with a key this app doesn't trust yet, so the firmware built into this app is offered.")
#expect(offer.reason == "The newest release's signature doesn't check out, so the firmware built into this app is offered.")
}

@Test func gitHubTimingOutOffersTheBuiltInFirmwareAndSaysItCouldntBeReached() async throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ func anythingWrongTalkingToGitHubIsUnreachableAndTheBuiltInStays(_ fault: String
#expect(outcome.catalog.newestPanel()?.version == FirmwareVersion("1.0.0"))
}

/// Until the owner adds their keys (docs/FIRMWARE-RELEASE-SIGNING.md), the app trusts none: a release that reaches it
/// whole is refused as signed with a key it doesn't know.
@Test func withTheAppsKeysStillEmptyEveryReleaseIsAnUnknownKey() async throws {
/// With the owner's keys in the app (#689): a release naming "primary" that isn't signed by the owner's primary key
/// is refused, its signature doesn't check out.
@Test func aReleaseNamingThePrimaryKeyButNotSignedByItIsRefused() async throws {
let github = publishedGitHub()
serve("manifest.json", Data(#"{"format": 1, "key": "primary", "lowest_allowed": {}, "catalog": {}, "files": []}"#.utf8), on: github)
let outcome = await ReleaseFetcher(feed: GitHubReleaseFeed(http: github), trusting: ReleaseKeys.trusted, cache: temporaryFolder())
.fetch(over: try builtIn(panelVersion: "1.0.0", sha: "aaaaaaa"))
#expect(outcome.refusal == .unknownKey("primary"))
#expect(outcome.refusal == .badSignature)
}

// Where the feed goes is its own rule, not the JSON's: an asset only from this repo's download URL on github.com, and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ import Testing
#expect(ReleaseKeys.listed.allSatisfy { ["primary", "backup"].contains($0.id) && $0.hex.count == 64 })
#expect(Set(ReleaseKeys.listed.map(\.id)).count == ReleaseKeys.listed.count)
}

/// The owner's keys (#689, made 2026-11-23): the public halves `firmware-release public-key` printed, copied here
/// from that output, so a changed or dropped key in ReleaseKeys.swift fails.
@Test func theAppTrustsTheOwnersPrimaryAndBackupKeys() {
let hex = ReleaseKeys.trusted.map { key in (key.id, key.publicKey.map { String(format: "%02x", $0) }.joined()) }
#expect(hex.map(\.0) == ["primary", "backup"])
#expect(hex.map(\.1) == [
"26739c2c075965fd9a99330f97c3b09a28d11f85c1fa4d81bd5495cb67c1a5f8",
"2e972a79fd40b287a151166dcdc723d07e84afe9ffc933fb211c670873c07cbe",
])
}
2 changes: 2 additions & 0 deletions docs/FIRMWARE-RELEASE-SIGNING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ swift run firmware-release new-key --id backup --out /Volumes/<USB stick>/backup
for each key. Each prints `<id> <64 hex characters>`. Put both in `listed` in
`Sources/FirmwareRelease/ReleaseKeys.swift`, as `("primary", "<hex>"), ("backup", "<hex>")`, in a pull request.
Public keys aren't secret. A test fails on a mistyped key.
Done 2026-11-23: the owner's primary and backup public keys are in `ReleaseKeys.swift`, and the deck panel's
`release_keys.h` (#690) must hold the same pair.

## Each release: one command

Expand Down
Loading