Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

fix(steam): check Valve's signature with a codesign requirement, also before Setup copies Steam

raymondchinsa64dc1eaff04
diff --git a/app/Sources/BridgeplayApp/Model/SetupChecks.swift b/app/Sources/BridgeplayApp/Model/SetupChecks.swift
index 11d5450..9a13733 100644
--- a/app/Sources/BridgeplayApp/Model/SetupChecks.swift
+++ b/app/Sources/BridgeplayApp/Model/SetupChecks.swift
@@ -79,11 +79,21 @@ enum SetupChecks {
}
report(String(localized: "Installing Steam"))
try DiskImage.withMounted(download) { volume in
- try Shell.check("/usr/bin/ditto", [volume.appending(path: "Steam.app").path(percentEncoded: false),
- app.path(percentEncoded: false)])
+ try copySteam(from: volume, to: app)
}
}
+ // The download carries no quarantine, so nothing else looks at it before it runs: the
+ // copy in the image has to carry Valve's signature before it reaches /Applications.
+ static func copySteam(
+ from volume: URL, to app: URL,
+ verify: (URL) throws -> Void = { try SteamRepair.verifyValveSignature($0, step: step) }
+ ) throws {
+ let mounted = volume.appending(path: "Steam.app")
+ try verify(mounted)
+ try Shell.check("/usr/bin/ditto", [mounted.path(percentEncoded: false), app.path(percentEncoded: false)])
+ }
+
static let step = String(localized: "Install Steam")
}
diff --git a/app/Sources/BridgeplayApp/Model/SteamRepair.swift b/app/Sources/BridgeplayApp/Model/SteamRepair.swift
index c7cfcf8..1d44a30 100644
--- a/app/Sources/BridgeplayApp/Model/SteamRepair.swift
+++ b/app/Sources/BridgeplayApp/Model/SteamRepair.swift
@@ -41,7 +41,7 @@ enum SteamRepair {
static let valveTeam = "MXGJJ98X76"
static let valveIdentifier = "com.valvesoftware.steam"
- private static let step = String(localized: "Repair Steam")
+ static let step = String(localized: "Repair Steam")
static func run(
manifest suppliedManifest: ValvePackageManifest? = nil,
@@ -148,7 +148,13 @@ enum SteamRepair {
return staged
}
- static func verifyValveSignature(_ url: URL) throws {
+ // Requirements codesign evaluates against the certificate chain itself. Text that
+ // `codesign -dvv` prints can be claimed by any self-signed certificate; an anchor in
+ // Apple's root plus Valve's team in the leaf cannot.
+ static let valveRequirement = "=anchor apple generic and certificate leaf[subject.OU] = \"\(valveTeam)\""
+ static let steamRequirement = "=identifier \"\(valveIdentifier)\""
+
+ static func verifyValveSignature(_ url: URL, step: String = step) throws {
let path = url.path(percentEncoded: false)
let strict = try Shell.run("/usr/bin/codesign", ["--verify", "--strict", path])
@@ -160,22 +166,15 @@ enum SteamRepair {
)
}
- let described = try Shell.run("/usr/bin/codesign", ["-dvv", path])
- let text = described.stdout + described.stderr
-
- let fields = Set(
- text.split(separator: "\n").map {
- $0.trimmingCharacters(in: .whitespacesAndNewlines)
- }
- )
-
- guard fields.contains("TeamIdentifier=\(valveTeam)") else {
+ let signed = try Shell.run("/usr/bin/codesign", ["--verify", "-R", valveRequirement, path])
+ guard signed.succeeded else {
throw StepFailure(
step: step,
detail: String(localized: "\(path) is not signed by Valve. Expected TeamIdentifier=\(valveTeam).")
)
}
- guard fields.contains("Identifier=\(valveIdentifier)") else {
+ let named = try Shell.run("/usr/bin/codesign", ["--verify", "-R", steamRequirement, path])
+ guard named.succeeded else {
throw StepFailure(
step: step,
detail: String(localized: "\(path) is not the Steam bundle. Expected Identifier=\(valveIdentifier).")
@@ -185,7 +184,7 @@ enum SteamRepair {
static func replace(
_ app: URL, with staged: URL,
- verify: (URL) throws -> Void = verifyValveSignature
+ verify: (URL) throws -> Void = { try verifyValveSignature($0) }
) throws {
let files = FileManager.default
try WriteRefused.catching(app) {
diff --git a/app/Tests/BridgeplayAppTests/SteamRepairTests.swift b/app/Tests/BridgeplayAppTests/SteamRepairTests.swift
index a32f562..f749247 100644
--- a/app/Tests/BridgeplayAppTests/SteamRepairTests.swift
+++ b/app/Tests/BridgeplayAppTests/SteamRepairTests.swift
@@ -122,6 +122,30 @@ struct SteamRepairTests {
#expect(throws: StepFailure.self) { try SteamRepair.verifyValveSignature(copy) }
}
+ // Setup's download of steam.dmg goes through the same gate before Steam.app is copied.
+ @Test("Setup copies Steam out of the image only when Valve signed it")
+ func setupCopiesOnlyValveSignedSteam() async throws {
+ let work = try scratchDirectory("repair")
+ defer { try? FileManager.default.removeItem(at: work) }
+ let staged = try await stagedStockBundle(into: work)
+
+ let installed = work.appending(path: "apps/Steam.app")
+ try FileManager.default.createDirectory(at: installed.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try SetupChecks.copySteam(from: staged.deletingLastPathComponent(), to: installed)
+ #expect(throws: Never.self) { try SteamRepair.verifyValveSignature(installed) }
+
+ let forged = work.appending(path: "image/Steam.app")
+ try FileManager.default.createDirectory(at: forged.deletingLastPathComponent(), withIntermediateDirectories: true)
+ try FileManager.default.copyItem(at: staged, to: forged)
+ try Shell.check("/usr/bin/codesign", ["-f", "-s", "-", forged.path(percentEncoded: false)])
+ let refused = work.appending(path: "refused/Steam.app")
+ let failure = try #require(throws: StepFailure.self) {
+ try SetupChecks.copySteam(from: forged.deletingLastPathComponent(), to: refused)
+ }
+ #expect(failure.step == SetupChecks.step)
+ #expect(!FileManager.default.fileExists(atPath: refused.path(percentEncoded: false)))
+ }
+
@Test("A manifest with no bundle row cannot repair")
func refusesManifestWithoutBundle() async throws {
let real = try ValvePackageManifest.bundled()