From 07bc34ae7a520756eb9f262b76595e1e1474b370 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Thu, 18 May 2023 15:55:26 -0500 Subject: [PATCH] =?UTF-8?q?Verifies=20downloaded=20app=E2=80=99s=20build?= =?UTF-8?q?=20version=20matches=20source=20(if=20provided)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AltStore/Operations/Errors/VerificationError.swift | 9 +++++++++ AltStore/Operations/VerifyAppOperation.swift | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/AltStore/Operations/Errors/VerificationError.swift b/AltStore/Operations/Errors/VerificationError.swift index 2a20dd95..c0173365 100644 --- a/AltStore/Operations/Errors/VerificationError.swift +++ b/AltStore/Operations/Errors/VerificationError.swift @@ -23,6 +23,7 @@ extension VerificationError case mismatchedHash = 3 case mismatchedVersion = 4 + case mismatchedBuildVersion = 5 case undeclaredPermissions = 6 case addedPermissions = 7 @@ -44,6 +45,10 @@ extension VerificationError VerificationError(code: .mismatchedVersion, app: app, version: version, expectedVersion: expectedVersion) } + static func mismatchedBuildVersion(_ version: String, expectedVersion: String, app: AppProtocol) -> VerificationError { + VerificationError(code: .mismatchedBuildVersion, app: app, version: version, expectedVersion: expectedVersion) + } + static func undeclaredPermissions(_ permissions: [any ALTAppPermission], app: AppProtocol) -> VerificationError { VerificationError(code: .undeclaredPermissions, app: app, permissions: permissions) } @@ -144,6 +149,10 @@ struct VerificationError: ALTLocalizedError let appName = self.$app.name ?? NSLocalizedString("the app", comment: "") return String(format: NSLocalizedString("The downloaded version of %@ does not match the version specified by the source.", comment: ""), appName) + case .mismatchedBuildVersion: + let appName = self.$app.name ?? NSLocalizedString("the app", comment: "") + return String(format: NSLocalizedString("The downloaded version of %@ does not match the build number specified by the source.", comment: ""), appName) + case .undeclaredPermissions: let appName = self.$app.name ?? NSLocalizedString("The app", comment: "") return String(format: NSLocalizedString("%@ requires additional permissions not specified by the source.", comment: ""), appName) diff --git a/AltStore/Operations/VerifyAppOperation.swift b/AltStore/Operations/VerifyAppOperation.swift index ef931de3..6c2a4879 100644 --- a/AltStore/Operations/VerifyAppOperation.swift +++ b/AltStore/Operations/VerifyAppOperation.swift @@ -201,9 +201,14 @@ private extension VerifyAppOperation func verifyDownloadedVersion(of app: ALTApplication, @AsyncManaged matches appVersion: AppVersion) async throws { - let version = await $appVersion.version + let (version, buildVersion) = await $appVersion.perform { ($0.version, $0.buildVersion) } guard version == app.version else { throw VerificationError.mismatchedVersion(app.version, expectedVersion: version, app: app) } + + if let buildVersion + { + guard buildVersion == app.buildVersion else { throw VerificationError.mismatchedBuildVersion(app.buildVersion, expectedVersion: buildVersion, app: app) } + } } func verifyPermissions(of app: ALTApplication, @AsyncManaged match appVersion: AppVersion) async throws