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
7 changes: 7 additions & 0 deletions changelog.d/updater-signed-version-matches-release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Updates install only the version the app is signed as

- The self-updater staged a release after checking its hashes and code
signature but never compared the coordinator's `version` with the version the
app is signed as, so an older signed build offered under a newer version could
pass the no-downgrade check and install. Staging now requires the signed
app's `CFBundleShortVersionString` to equal the release's `version` exactly.
5 changes: 4 additions & 1 deletion docs/operations/provider-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,10 @@ a numeric one in the same position. Then `X.Y.Z-dev.branch.<run>` ranks above
latest.

An existing install's self-updater may not downgrade to a lower version, while a
fresh install takes the latest.
fresh install takes the latest. It compares the registered `version`, and stages
a bundle only when that `version` equals the `CFBundleShortVersionString` its
signature seals (`SelfUpdater`, `provider-swift/Sources/ProviderCore/Update/SelfUpdater.swift`),
so the registered version must be exactly the version the app was signed as.

### 6. Sign, Stage And Register Exact Bytes

Expand Down
7 changes: 5 additions & 2 deletions docs/provider/installation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Install, update, and uninstall the provider

> Last updated: 2026-11-11
> Last updated: 2026-11-13

How to put the `darkbloom` CLI on an Apple Silicon Mac with `scripts/install.sh`,
what the script verifies before it touches an existing install, how the binary
Expand Down Expand Up @@ -189,7 +189,10 @@ darkbloom update # download, verify, atomic replace, restart th
`GET {coordinator}/v1/releases/latest?platform=macos-arm64`, verifies the
SHA-256 of the bundle and, when published, of the binary and `mlx.metallib`,
verifies the code signature (production always constructs the updater with
`verifyCodeSignatures: true`), replaces the install, registers the new
`verifyCodeSignatures: true`), requires the signed app's
`CFBundleShortVersionString` to equal the release's `version` exactly (the
coordinator's version only labels the bundle, so an older signed build under a
newer label is refused), replaces the install, registers the new
`Darkbloom.app` with macOS LaunchServices (`LSRegisterURL`; App Attest reports
`is_supported_false` while LaunchServices still describes the replaced bundle,
see [attestation](./attestation.md#app-attest-without-darkbloom-mdm)), and — if
Expand Down
11 changes: 11 additions & 0 deletions provider-swift/Sources/ProviderCore/Update/SelfUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,17 @@ public struct SelfUpdater: Sendable {
deep: true,
policy: signaturePolicy
)
// The coordinator's `version` only labels the bundle; the
// Info.plist this signature seals names the build. An older
// signed release offered under a newer label otherwise passes
// every hash and signature check and installs as an update.
// Read before the runtime smoke runs any staged code.
let signedVersion = UpdateRecoveryStore.signedVersion(ofApp: extractedApp)
guard signedVersion == release.version else {
throw UpdateError.replaceFailed(
"\(identity.appBundleName) is signed as version \(signedVersion ?? "(none)"), "
+ "not release \(release.version)")
}
if verification.verifyRuntimeCapabilities {
try verifyRuntimeCapabilities(
app: extractedApp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ extension UpdateRecoveryStore {

/// The version an app is signed as: the `CFBundleShortVersionString` of its `Info.plist`, which the release lane
/// sets to the release version and the code signature seals. Nil when it names none.
func signedVersion(ofApp bundle: URL) -> String? {
static func signedVersion(ofApp bundle: URL) -> String? {
guard let data = try? Data(contentsOf: bundle.appendingPathComponent("Contents/Info.plist")),
let info = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any],
let version = info["CFBundleShortVersionString"] as? String, !version.isEmpty
Expand All @@ -70,7 +70,7 @@ extension UpdateRecoveryStore {

/// The version the installed app is signed as (`signedVersion(ofApp:)`).
func installedSignedVersion() -> String? {
signedVersion(ofApp: artifactPaths(root: installRoot).bundle)
Self.signedVersion(ofApp: artifactPaths(root: installRoot).bundle)
}

/// Whether the installed app is the app `record` names (the hashes `stagingContainsTarget` compares). Nil when it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ final class UpdateRecoveryStore: @unchecked Sendable {
/// that names no version, or does not verify, is removed (fail closed).
private func reconcileRollbackCopy(_ copy: VerifiedPredecessor, in state: inout UpdateRecoveryState,
now: Double) throws -> UpdateRecoveryReconciliation? {
let signed = try signedVersion(ofApp: resolvedRecoveryPath(copy.bundlePath))
let signed = try Self.signedVersion(ofApp: resolvedRecoveryPath(copy.bundlePath))
guard signed != copy.release.version else { return nil }
if let signed, (try? verifyPredecessor(copy)) != nil {
var relabelled = copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,14 @@ struct SelfUpdaterTests {
#expect(try LiveInferenceFixtures.buildProduct("darkbloom", testBundleURL: bundle) == active)
}

/// `signedVersion` is the app's `CFBundleShortVersionString`, sealed by its
/// signature; the release is labelled `releaseVersion`, by default the same.
private func makeSignedRuntimeFixture(
root: URL,
includeResource: Bool,
includeFanHelper: Bool = true
includeFanHelper: Bool = true,
signedVersion: String = "0.10.13",
releaseVersion: String? = nil
) throws -> (URL, ReleaseInfo, URL) {
let fm = FileManager.default
let stage = root.appendingPathComponent("signed-src", isDirectory: true)
Expand Down Expand Up @@ -436,6 +440,7 @@ struct SelfUpdaterTests {
"CFBundleExecutable": "darkbloom",
"CFBundlePackageType": "APPL",
"CFBundleVersion": "1",
"CFBundleShortVersionString": signedVersion,
]
try PropertyListSerialization.data(
fromPropertyList: info,
Expand Down Expand Up @@ -498,7 +503,7 @@ struct SelfUpdaterTests {
includeResource ? "signed-valid.tar.gz" : "signed-missing.tar.gz")
try runTarCreate(sourceDir: stage, tarball: tarball)
let release = ReleaseInfo(
version: "test",
version: releaseVersion ?? signedVersion,
platform: "macos-arm64",
url: "file://unused",
bundleHash: sha256Hex(try Data(contentsOf: tarball)),
Expand Down Expand Up @@ -552,6 +557,41 @@ struct SelfUpdaterTests {
atPath: missingInstall.appendingPathComponent("Darkbloom.app").path))
}

@Test("a signed app is staged only as the version it is signed as")
func signedVersionMustMatchRelease() throws {
_ = LiveInferenceFixtures.ensureMetallibColocated()
let root = FileManager.default.temporaryDirectory
.appendingPathComponent("self-updater-signed-version-\(UUID().uuidString)", isDirectory: true)
defer { try? FileManager.default.removeItem(at: root) }
let updater = SelfUpdater(coordinatorBaseURL: "https://api.example.test")

// An older signed build offered under a newer label: every hash and
// the signature verify, only the sealed version tells them apart.
let (relabelled, relabelledRelease, relabelledInstall) = try makeSignedRuntimeFixture(
root: root.appendingPathComponent("relabelled", isDirectory: true),
includeResource: true, signedVersion: "0.10.11", releaseVersion: "99.0.0")
guard case .failure(let error) = updater.stageSignedBundleForTesting(
from: relabelled, release: relabelledRelease, installDir: relabelledInstall)
else {
Issue.record("an app signed as 0.10.11 staged as release 99.0.0")
return
}
#expect("\(error)".contains("is signed as version 0.10.11, not release 99.0.0"))

// A prerelease version, as dev and staging releases are signed,
// stages when the release names it exactly.
let (prerelease, prereleaseRelease, prereleaseInstall) = try makeSignedRuntimeFixture(
root: root.appendingPathComponent("prerelease", isDirectory: true),
includeResource: true, signedVersion: "0.10.13-dev.branch.7")
guard case .success(let staged) = updater.stageSignedBundleForTesting(
from: prerelease, release: prereleaseRelease, installDir: prereleaseInstall)
else {
Issue.record("an app signed as its release's own version was refused")
return
}
staged.discard()
}

@Test("fan-capable signed app without its helper is rejected")
func signedAppRequiresFanHelper() throws {
_ = LiveInferenceFixtures.ensureMetallibColocated()
Expand Down
Loading