Verifies downloaded app’s build version matches source (if provided)

This commit is contained in:
Riley Testut
2023-05-18 15:55:26 -05:00
committed by Magesh K
parent 3aa041d2ad
commit 07bc34ae7a
2 changed files with 15 additions and 1 deletions

View File

@@ -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)

View File

@@ -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