diff --git a/AltStore.xcodeproj/project.pbxproj b/AltStore.xcodeproj/project.pbxproj index 1aee238d..4daf0e30 100644 --- a/AltStore.xcodeproj/project.pbxproj +++ b/AltStore.xcodeproj/project.pbxproj @@ -358,6 +358,7 @@ D58D5F2E26DFE68E00E55E38 /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = D58D5F2D26DFE68E00E55E38 /* LaunchAtLogin */; }; D593F1942717749A006E82DE /* PatchAppOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D593F1932717749A006E82DE /* PatchAppOperation.swift */; }; D5DAE0942804B0B80034D8D4 /* ScreenshotProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5DAE0932804B0B80034D8D4 /* ScreenshotProcessor.swift */; }; + D5E1E7C128077DE90016FC96 /* FetchTrustedSourcesOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5E1E7C028077DE90016FC96 /* FetchTrustedSourcesOperation.swift */; }; D5F2F6A92720B7C20081CCF5 /* PatchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5F2F6A82720B7C20081CCF5 /* PatchViewController.swift */; }; /* End PBXBuildFile section */ @@ -818,6 +819,7 @@ D57F2C9326E01BC700B9FA39 /* UIDevice+Vibration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIDevice+Vibration.swift"; sourceTree = ""; }; D593F1932717749A006E82DE /* PatchAppOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PatchAppOperation.swift; sourceTree = ""; }; D5DAE0932804B0B80034D8D4 /* ScreenshotProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenshotProcessor.swift; sourceTree = ""; }; + D5E1E7C028077DE90016FC96 /* FetchTrustedSourcesOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchTrustedSourcesOperation.swift; sourceTree = ""; }; D5F2F6A82720B7C20081CCF5 /* PatchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PatchViewController.swift; sourceTree = ""; }; EA79A60285C6AF5848AA16E9 /* Pods-AltStore.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AltStore.debug.xcconfig"; path = "Target Support Files/Pods-AltStore/Pods-AltStore.debug.xcconfig"; sourceTree = ""; }; FC3822AB1C4CF1D4CDF7445D /* Pods_AltServer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AltServer.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1675,6 +1677,7 @@ BFDBBD7F246CB84F004ED2F3 /* RemoveAppBackupOperation.swift */, BFF00D312501BDA100746320 /* BackgroundRefreshAppsOperation.swift */, D57F2C9026E0070200B9FA39 /* EnableJITOperation.swift */, + D5E1E7C028077DE90016FC96 /* FetchTrustedSourcesOperation.swift */, BF7B44062725A4B8005288A4 /* Patch App */, ); path = Operations; @@ -2547,6 +2550,7 @@ BFE6073A231ADF82002B0E8E /* SettingsViewController.swift in Sources */, D57F2C9126E0070200B9FA39 /* EnableJITOperation.swift in Sources */, BF8CAE4E248AEABA004D6CCE /* UIDevice+Jailbreak.swift in Sources */, + D5E1E7C128077DE90016FC96 /* FetchTrustedSourcesOperation.swift in Sources */, BFE338DF22F0EADB002E24B9 /* FetchSourceOperation.swift in Sources */, BFB6B21E231870160022A802 /* NewsViewController.swift in Sources */, BFC57A652416C72400EB891E /* DeactivateAppOperation.swift in Sources */, diff --git a/AltStore/Managing Apps/AppManager.swift b/AltStore/Managing Apps/AppManager.swift index 072d8651..3939d58a 100644 --- a/AltStore/Managing Apps/AppManager.swift +++ b/AltStore/Managing Apps/AppManager.swift @@ -394,6 +394,16 @@ extension AppManager self.run([fetchAppIDsOperation], context: authenticationOperation.context) } + @discardableResult + func fetchTrustedSources(completionHandler: @escaping (Result<[FetchTrustedSourcesOperation.TrustedSource], Error>) -> Void) -> FetchTrustedSourcesOperation + { + let fetchTrustedSourcesOperation = FetchTrustedSourcesOperation() + fetchTrustedSourcesOperation.resultHandler = completionHandler + self.run([fetchTrustedSourcesOperation], context: nil) + + return fetchTrustedSourcesOperation + } + @discardableResult func install(_ app: T, presentingViewController: UIViewController?, context: AuthenticatedOperationContext = AuthenticatedOperationContext(), completionHandler: @escaping (Result) -> Void) -> RefreshGroup { diff --git a/AltStore/Operations/FetchTrustedSourcesOperation.swift b/AltStore/Operations/FetchTrustedSourcesOperation.swift new file mode 100644 index 00000000..8d57ec89 --- /dev/null +++ b/AltStore/Operations/FetchTrustedSourcesOperation.swift @@ -0,0 +1,57 @@ +// +// FetchTrustedSourcesOperation.swift +// AltStore +// +// Created by Riley Testut on 4/13/22. +// Copyright © 2022 Riley Testut. All rights reserved. +// + +import Foundation + +private extension URL +{ + #if STAGING + static let trustedSources = URL(string: "https://f000.backblazeb2.com/file/altstore-staging/altstore/trustedsources.json")! + #else + static let trustedSources = URL(string: "https://cdn.altstore.io/file/altstore/altstore/trustedsources.json")! + #endif +} + +extension FetchTrustedSourcesOperation +{ + struct TrustedSource: Decodable + { + var identifier: String + var sourceURL: URL? + } + + private struct Response: Decodable + { + var version: Int + var sources: [FetchTrustedSourcesOperation.TrustedSource] + } +} + +class FetchTrustedSourcesOperation: ResultOperation<[FetchTrustedSourcesOperation.TrustedSource]> +{ + override func main() + { + super.main() + + let dataTask = URLSession.shared.dataTask(with: .trustedSources) { (data, response, error) in + do + { + guard let data = data else { throw error! } + + let response = try Foundation.JSONDecoder().decode(Response.self, from: data) + self.finish(.success(response.sources)) + } + catch + { + self.finish(.failure(error)) + } + } + + dataTask.resume() + } +}