Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 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
70 changes: 0 additions & 70 deletions macOS/AGENTS.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@
password: Data, reply: @escaping @Sendable (Data?, NSError?) -> Void
)

/// `bindingDigest` is the digest of the plan the app approved; the
/// imported package must carry exactly it.
func submit(
packageDirectory: FileHandle,
bindingDigest: String,
operation: String,
machineOwner: String,
password: Data,
Expand Down Expand Up @@ -545,6 +548,7 @@

proxy.submit(
packageDirectory: directoryHandle,
bindingDigest: handoff.bindingDigest,
operation: operation.rawValue,
machineOwner: authorization.username,
password: authorization.password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
public let metadataURL: URL
public let payloadURL: URL
public let restoreImageURL: URL
/// The binding digest of the plan this package was written for. It
/// travels to the helper beside the package, never from its files.
public let bindingDigest: String
}

public protocol EngineHandoffSubmitting: Sendable {
Expand Down Expand Up @@ -192,7 +195,8 @@
payloadURL: package.appendingPathComponent(
assets.payload.artifact.fileName
),
restoreImageURL: package.appendingPathComponent(RestoreImageHelper.fileName)
restoreImageURL: package.appendingPathComponent(RestoreImageHelper.fileName),
bindingDigest: invocation.candidateIdentity.bindingDigest
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,16 @@
/// `progress` is optional and advisory: when a connected app exports the
/// journal callback, the helper tails the run's journal and forwards whole
/// lines. Passing nil reproduces the previous behavior exactly.
/// `bindingDigest` is the digest the caller approved; a package that
/// carries another one is refused before any artifact is copied. The
/// digest and the package directory come from the same caller in one
/// call, so this binds the package to what that caller approved and
/// stops the directory's contents from changing after approval; it does
/// not stop the caller itself from submitting an older self-consistent
/// package with that package's own digest.
public func submit(
packageDirectory: FileHandle,
bindingDigest: String,
authorization: MachineOwnerAuthorization,
operation: EngineHandoffOperation = .install,
progress: (any EngineJournalProgressSink)? = nil
Expand All @@ -475,7 +483,7 @@
return try await InstallerTimingRecorder.attempt(operation.rawValue) {
try await executeSubmittedPackage(
packageDirectory: packageDirectory, authorization: authorization, operation: operation,
progress: progress, jobIdentifier: nil, installConf: nil)
progress: progress, admission: .bindingDigest(bindingDigest), installConf: nil)
}.0
}

Expand All @@ -496,18 +504,23 @@
try await InstallerTimingRecorder.attempt(operation.rawValue, observe: observe) {
try await executeSubmittedPackage(
packageDirectory: packageDirectory, authorization: authorization,
operation: operation, progress: nil, jobIdentifier: identifier,
operation: operation, progress: nil, admission: .job(identifier),
installConf: installConf)
}
}
}

private enum SubmittedPackageAdmission {
case job(UUID)
case bindingDigest(String)
}

private func executeSubmittedPackage(
packageDirectory: FileHandle,
authorization: MachineOwnerAuthorization,
operation: EngineHandoffOperation,
progress: (any EngineJournalProgressSink)?,
jobIdentifier: UUID?,
admission: SubmittedPackageAdmission,
installConf: InstallConf?
) async throws -> (Data, InstallConfHandoff) {
try requireNoInterruptedRemoval()
Expand All @@ -520,17 +533,31 @@
throw ClosedEngineHelperError.invalidMachineOwnerCredentials
}

let expectedBindingDigest: String? =
switch admission {
case .job: nil
case .bindingDigest(let approved): approved
}
let package = try InstallerPerformance.measure("helper_import") {
try importer.prepare(from: packageDirectory, in: workingDirectory)
try importer.prepare(
from: packageDirectory, in: workingDirectory,
expectedBindingDigest: expectedBindingDigest)
}
var registeredPackage = false
defer {
if !registeredPackage { try? FileManager.default.removeItem(at: package.packageURL) }
}

if let jobIdentifier {
// Either way the package must carry the binding digest its caller sent
// outside the package: in the job's ticket, or with a direct submission.
switch admission {
case .job(let jobIdentifier):
try jobs.admitted(jobIdentifier, package: package)
registeredPackage = true
case .bindingDigest(let approved):
guard package.bindingDigest == approved else {
throw EngineHandoffImportError.bindingMismatch
}
}

return try await executeImportedPackage(
Expand Down Expand Up @@ -922,6 +949,7 @@

public func submit(
packageDirectory: FileHandle,
bindingDigest: String,
operation: String,
machineOwner: String,
password: Data,
Expand Down Expand Up @@ -949,6 +977,7 @@
)
let response = try await server.submit(
packageDirectory: packageDirectory,
bindingDigest: bindingDigest,
authorization: authorization,
operation: operation,
progress: sink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,13 @@
repairManifestDigest: nil, requiredHumanSteps: request.requiredHumanSteps)
}

/// `expectedBindingDigest`, when given, is the digest the caller approved
/// outside the package; a package carrying another one is refused right
/// after its control files are read, before any artifact is copied.
public func prepare(
from packageDirectory: FileHandle,
in destinationDirectory: URL
in destinationDirectory: URL,
expectedBindingDigest: String? = nil
) throws -> ImportedEngineHandoffPackage {
let sourceDescriptor = packageDirectory.fileDescriptor
try validateSourceDirectory(sourceDescriptor)
Expand All @@ -189,6 +193,9 @@
request: request,
identity: identity
)
if let expectedBindingDigest, identity.bindingDigest != expectedBindingDigest {
throw EngineHandoffImportError.bindingMismatch
}
// Older packages carried an engine archive or a repair manifest for the
// retired engine. A new submission must name only native execution.
guard manifest.format == 2, manifest.engine == nil, manifest.repairManifest == nil,
Expand Down Expand Up @@ -752,7 +759,25 @@
: manifest.format == 2 && manifest.engine == nil
&& identity.engineDigest == NativeExecutionIdentity.digest
&& request.engineVersion == NativeExecutionIdentity.version
// The binding digest is recomputed, not only compared between the files:
// the value the app approved then fixes every field it covers.
let bindingDigest = CandidateBoundPlanIdentity.makeBindingDigest(
trustRootFingerprint: identity.trustRootFingerprint,
catalogSequence: identity.catalogSequence,
catalogPayloadDigest: identity.catalogPayloadDigest,
planDigest: request.planDigest,
deviceIdentifier: request.deviceIdentifier,
storeIdentifier: request.storeIdentifier,
layoutDigest: request.layoutDigest,
candidateKind: request.candidateKind,
sourceIdentifier: request.sourceIdentifier,
offsetBytes: request.offsetBytes,
lengthBytes: request.lengthBytes,
engineDigest: identity.engineDigest,
metadataDigest: identity.metadataDigest,
payloadDigest: identity.payloadDigest)
guard manifest.bindingDigest == identity.bindingDigest,
identity.bindingDigest == bindingDigest,
request.planDigest == identity.planDigest,
request.planDigest == lengthPrefixedDigest(planFields),
engineBound,
Expand Down
76 changes: 56 additions & 20 deletions macOS/Sources/AuroraAppleInstaller/InstallerIdentity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,62 @@ public struct CandidateBoundPlanIdentity: Equatable, Sendable {
sourceIdentifier = plan.sourceIdentifier
offsetBytes = plan.offsetBytes
lengthBytes = plan.lengthBytes
bindingDigest =
InstallerDigest.lengthPrefixedSHA256([
// A fixed domain separator: changing it changes every binding digest.
"omarchy.apple.candidate-bound-plan",
"1",
trustRootFingerprint,
String(catalogIdentity.sequence),
catalogIdentity.payloadDigest,
plan.planDigest,
plan.deviceIdentifier,
plan.storeIdentifier,
plan.layoutDigest,
plan.candidateKind,
plan.sourceIdentifier,
String(plan.offsetBytes),
String(plan.lengthBytes),
plan.engineDigest,
plan.metadataDigest,
plan.payloadDigest,
]).rawValue
bindingDigest = Self.makeBindingDigest(
trustRootFingerprint: trustRootFingerprint,
catalogSequence: catalogIdentity.sequence,
catalogPayloadDigest: catalogIdentity.payloadDigest,
planDigest: plan.planDigest,
deviceIdentifier: plan.deviceIdentifier,
storeIdentifier: plan.storeIdentifier,
layoutDigest: plan.layoutDigest,
candidateKind: plan.candidateKind,
sourceIdentifier: plan.sourceIdentifier,
offsetBytes: plan.offsetBytes,
lengthBytes: plan.lengthBytes,
engineDigest: plan.engineDigest,
metadataDigest: plan.metadataDigest,
payloadDigest: plan.payloadDigest)
}

/// The only definition of the binding digest. The app computes it for the
/// plan it approves; the helper recomputes it from the control files of a
/// package, so a package is admitted only when its fields give the digest
/// it carries.
static func makeBindingDigest(
trustRootFingerprint: String,
catalogSequence: UInt64,
catalogPayloadDigest: String,
planDigest: String,
deviceIdentifier: String,
storeIdentifier: String,
layoutDigest: String,
candidateKind: String,
sourceIdentifier: String,
offsetBytes: UInt64,
lengthBytes: UInt64,
engineDigest: String,
metadataDigest: String,
payloadDigest: String
) -> String {
InstallerDigest.lengthPrefixedSHA256([
// A fixed domain separator: changing it changes every binding digest.
"omarchy.apple.candidate-bound-plan",
"1",
trustRootFingerprint,
String(catalogSequence),
catalogPayloadDigest,
planDigest,
deviceIdentifier,
storeIdentifier,
layoutDigest,
candidateKind,
sourceIdentifier,
String(offsetBytes),
String(lengthBytes),
engineDigest,
metadataDigest,
payloadDigest,
]).rawValue
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,8 @@
XCTFail("Concurrent removal accepted")
} catch { XCTAssertEqual(error as? ClosedEngineHelperError, .busy) }
do {
_ = try await service.submit(packageDirectory: .standardInput, authorization: auth)
_ = try await service.submit(
packageDirectory: .standardInput, bindingDigest: "", authorization: auth)
XCTFail("Concurrent install accepted")
} catch { XCTAssertEqual(error as? ClosedEngineHelperError, .busy) }
disk.resume.signal()
Expand Down
Loading
Loading