From 40bcef1dcb572498c98991d8adbbb2eae200006c Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Thu, 6 Apr 2023 20:45:18 -0700 Subject: [PATCH 01/79] Use XYZ0123456 team ID for tempEnt.plist Signed-off-by: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> --- AltStore/Resources/tempEnt.plist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AltStore/Resources/tempEnt.plist b/AltStore/Resources/tempEnt.plist index a7b3b7dc..8b3ff4bd 100644 --- a/AltStore/Resources/tempEnt.plist +++ b/AltStore/Resources/tempEnt.plist @@ -3,13 +3,13 @@ application-identifier - A72ZC8AJ5X.com.SideStore.SideStore + XYZ0123456.com.SideStore.SideStore aps-environment development com.apple.developer.siri com.apple.developer.team-identifier - A72ZC8AJ5X + XYZ0123456 com.apple.security.application-groups group.com.SideStore.SideStore From b3d827f56a2839ebb09d5222805fb5eb0f3ee44f Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Tue, 11 Apr 2023 21:04:07 -0700 Subject: [PATCH 02/79] refactor: remove minimuxerToOperationError in favor of extending MinimuxerError to be a LocalizedError and remove unused cases from OperationError --- AltStore/LaunchViewController.swift | 2 +- .../Operations/DeactivateAppOperation.swift | 2 +- AltStore/Operations/EnableJITOperation.swift | 2 +- AltStore/Operations/InstallAppOperation.swift | 2 +- AltStore/Operations/OperationError.swift | 135 ++++++++---------- AltStore/Operations/RefreshAppOperation.swift | 2 +- AltStore/Operations/RemoveAppOperation.swift | 2 +- AltStore/Operations/SendAppOperation.swift | 2 +- 8 files changed, 68 insertions(+), 81 deletions(-) diff --git a/AltStore/LaunchViewController.swift b/AltStore/LaunchViewController.swift index cece54c2..9c0abd06 100644 --- a/AltStore/LaunchViewController.swift +++ b/AltStore/LaunchViewController.swift @@ -153,7 +153,7 @@ final class LaunchViewController: RSTLaunchViewController, UIDocumentPickerDeleg try start(pairing_file, documentsDirectory) } catch { try! FileManager.default.removeItem(at: FileManager.default.documentsDirectory.appendingPathComponent("\(pairingFileName)")) - displayError("minimuxer failed to start, please restart SideStore. \(minimuxerToOperationError(error).failureReason ?? "UNKNOWN ERROR!!!!!! REPORT TO GITHUB ISSUES!")") + displayError("minimuxer failed to start, please restart SideStore. \((error as? LocalizedError)?.failureReason ?? "UNKNOWN ERROR!!!!!! REPORT TO GITHUB ISSUES!")") } start_auto_mounter(documentsDirectory) } diff --git a/AltStore/Operations/DeactivateAppOperation.swift b/AltStore/Operations/DeactivateAppOperation.swift index 5742ec87..6feec196 100644 --- a/AltStore/Operations/DeactivateAppOperation.swift +++ b/AltStore/Operations/DeactivateAppOperation.swift @@ -46,7 +46,7 @@ final class DeactivateAppOperation: ResultOperation do { try remove_provisioning_profile(profile) } catch { - return self.finish(.failure(minimuxerToOperationError(error))) + return self.finish(.failure(error)) } } diff --git a/AltStore/Operations/EnableJITOperation.swift b/AltStore/Operations/EnableJITOperation.swift index 1848109b..36081af1 100644 --- a/AltStore/Operations/EnableJITOperation.swift +++ b/AltStore/Operations/EnableJITOperation.swift @@ -48,7 +48,7 @@ final class EnableJITOperation: ResultOperation do { try debug_app(installedApp.resignedBundleIdentifier) } catch { - return self.finish(.failure(minimuxerToOperationError(error))) + return self.finish(.failure(error)) } self.finish(.success(())) diff --git a/AltStore/Operations/InstallAppOperation.swift b/AltStore/Operations/InstallAppOperation.swift index c9ef8d50..abe24a85 100644 --- a/AltStore/Operations/InstallAppOperation.swift +++ b/AltStore/Operations/InstallAppOperation.swift @@ -152,7 +152,7 @@ final class InstallAppOperation: ResultOperation do { try install_ipa(installedApp.bundleIdentifier) } catch { - return self.finish(.failure(minimuxerToOperationError(error))) + return self.finish(.failure(error)) } installedApp.refreshedDate = Date() diff --git a/AltStore/Operations/OperationError.swift b/AltStore/Operations/OperationError.swift index 4e7a86b2..8de1f0ff 100644 --- a/AltStore/Operations/OperationError.swift +++ b/AltStore/Operations/OperationError.swift @@ -34,21 +34,6 @@ enum OperationError: LocalizedError case openAppFailed(name: String) case missingAppGroup - case noDevice - case createService(name: String) - case getFromDevice(name: String) - case setArgument(name: String) - case afc - case install - case uninstall - case lookupApps - case detach - case attach - case functionArguments - case profileManage - case noConnection - case invalidPairingFile - var failureReason: String? { switch self { case .unknown: return NSLocalizedString("An unknown error occured.", comment: "") @@ -64,20 +49,6 @@ enum OperationError: LocalizedError case .openAppFailed(let name): return String(format: NSLocalizedString("SideStore was denied permission to launch %@.", comment: ""), name) case .missingAppGroup: return NSLocalizedString("SideStore's shared app group could not be found.", comment: "") case .maximumAppIDLimitReached: return NSLocalizedString("Cannot register more than 10 App IDs.", comment: "") - case .noDevice: return NSLocalizedString("Cannot fetch the device from the muxer", comment: "") - case .createService(let name): return String(format: NSLocalizedString("Cannot start a %@ server on the device.", comment: ""), name) - case .getFromDevice(let name): return String(format: NSLocalizedString("Cannot fetch %@ from the device.", comment: ""), name) - case .setArgument(let name): return String(format: NSLocalizedString("Cannot set %@ on the device.", comment: ""), name) - case .afc: return NSLocalizedString("AFC was unable to manage files on the device", comment: "") - case .install: return NSLocalizedString("Unable to install the app from the staging directory", comment: "") - case .uninstall: return NSLocalizedString("Unable to uninstall the app", comment: "") - case .lookupApps: return NSLocalizedString("Unable to fetch apps from the device", comment: "") - case .detach: return NSLocalizedString("Unable to detach from the app's process", comment: "") - case .attach: return NSLocalizedString("Unable to attach to the app's process", comment: "") - case .functionArguments: return NSLocalizedString("A function was passed invalid arguments", comment: "") - case .profileManage: return NSLocalizedString("Unable to manage profiles on the device", comment: "") - case .noConnection: return NSLocalizedString("Unable to connect to the device, make sure Wireguard is enabled and you're connected to WiFi", comment: "") - case .invalidPairingFile: return NSLocalizedString("Invalid pairing file. Your pairing file either didn't have a UDID, or it wasn't a valid plist. Please use jitterbugpair to generate it", comment: "") } } @@ -123,50 +94,66 @@ enum OperationError: LocalizedError } } -/// crashes if error is not a MinimuxerError -func minimuxerToOperationError(_ error: Error) -> OperationError { - switch error as! MinimuxerError { - case .NoDevice: - return OperationError.noDevice - case .NoConnection: - return OperationError.noConnection - case .PairingFile: - return OperationError.invalidPairingFile - case .CreateDebug: - return OperationError.createService(name: "debug") - case .CreateInstproxy: - return OperationError.createService(name: "instproxy") - case .LookupApps: - return OperationError.getFromDevice(name: "installed apps") - case .FindApp: - return OperationError.getFromDevice(name: "path to the app") - case .BundlePath: - return OperationError.getFromDevice(name: "bundle path") - case .MaxPacket: - return OperationError.setArgument(name: "max packet") - case .WorkingDirectory: - return OperationError.setArgument(name: "working directory") - case .Argv: - return OperationError.setArgument(name: "argv") - case .LaunchSuccess: - return OperationError.getFromDevice(name: "launch success") - case .Detach: - return OperationError.detach - case .Attach: - return OperationError.attach - case .CreateAfc: - return OperationError.createService(name: "AFC") - case .RwAfc: - return OperationError.afc - case .InstallApp: - return OperationError.install - case .UninstallApp: - return OperationError.uninstall - case .CreateMisagent: - return OperationError.createService(name: "misagent") - case .ProfileInstall: - return OperationError.profileManage - case .ProfileRemove: - return OperationError.profileManage +extension MinimuxerError: LocalizedError { + public var failureReason: String? { + switch self { + case .NoDevice: + return NSLocalizedString("Cannot fetch the device from the muxer", comment: "") + case .NoConnection: + return NSLocalizedString("Unable to connect to the device, make sure Wireguard is enabled and you're connected to WiFi", comment: "") + case .PairingFile: + return NSLocalizedString("Invalid pairing file. Your pairing file either didn't have a UDID, or it wasn't a valid plist. Please use jitterbugpair to generate it", comment: "") + + case .CreateDebug: + return self.createService(name: "debug") + case .LookupApps: + return self.getFromDevice(name: "installed apps") + case .FindApp: + return self.getFromDevice(name: "path to the app") + case .BundlePath: + return self.getFromDevice(name: "bundle path") + case .MaxPacket: + return self.setArgument(name: "max packet") + case .WorkingDirectory: + return self.setArgument(name: "working directory") + case .Argv: + return self.setArgument(name: "argv") + case .LaunchSuccess: + return self.getFromDevice(name: "launch success") + case .Detach: + return NSLocalizedString("Unable to detach from the app's process", comment: "") + case .Attach: + return NSLocalizedString("Unable to attach to the app's process", comment: "") + + case .CreateInstproxy: + return self.createService(name: "instproxy") + case .CreateAfc: + return self.createService(name: "AFC") + case .RwAfc: + return NSLocalizedString("AFC was unable to manage files on the device", comment: "") + case .InstallApp: + return NSLocalizedString("Unable to install the app from the staging directory", comment: "") + case .UninstallApp: + return NSLocalizedString("Unable to uninstall the app", comment: "") + + case .CreateMisagent: + return self.createService(name: "misagent") + case .ProfileInstall: + return NSLocalizedString("Unable to manage profiles on the device", comment: "") + case .ProfileRemove: + return NSLocalizedString("Unable to manage profiles on the device", comment: "") + } + } + + fileprivate func createService(name: String) -> String { + return String(format: NSLocalizedString("Cannot start a %@ server on the device.", comment: ""), name) + } + + fileprivate func getFromDevice(name: String) -> String { + return String(format: NSLocalizedString("Cannot fetch %@ from the device.", comment: ""), name) + } + + fileprivate func setArgument(name: String) -> String { + return String(format: NSLocalizedString("Cannot set %@ on the device.", comment: ""), name) } } diff --git a/AltStore/Operations/RefreshAppOperation.swift b/AltStore/Operations/RefreshAppOperation.swift index 7747d237..edf6a9e5 100644 --- a/AltStore/Operations/RefreshAppOperation.swift +++ b/AltStore/Operations/RefreshAppOperation.swift @@ -52,7 +52,7 @@ final class RefreshAppOperation: ResultOperation let bytes = p.value.data.toRustByteSlice() try install_provisioning_profile(bytes.forRust()) } catch { - return self.finish(.failure(minimuxerToOperationError(error))) + return self.finish(.failure(error)) } self.progress.completedUnitCount += 1 diff --git a/AltStore/Operations/RemoveAppOperation.swift b/AltStore/Operations/RemoveAppOperation.swift index 042828ec..46400cfa 100644 --- a/AltStore/Operations/RemoveAppOperation.swift +++ b/AltStore/Operations/RemoveAppOperation.swift @@ -41,7 +41,7 @@ final class RemoveAppOperation: ResultOperation do { try remove_app(resignedBundleIdentifier) } catch { - return self.finish(.failure(minimuxerToOperationError(error))) + return self.finish(.failure(error)) } DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in diff --git a/AltStore/Operations/SendAppOperation.swift b/AltStore/Operations/SendAppOperation.swift index dd366968..afa5e57f 100644 --- a/AltStore/Operations/SendAppOperation.swift +++ b/AltStore/Operations/SendAppOperation.swift @@ -50,7 +50,7 @@ final class SendAppOperation: ResultOperation<()> let bytes = Data(data).toRustByteSlice() try yeet_app_afc(app.bundleIdentifier, bytes.forRust()) } catch { - return self.finish(.failure(minimuxerToOperationError(error))) + return self.finish(.failure(error)) } self.progress.completedUnitCount += 1 From d79b166a6a80dd99e36b001a983dcff4ecd06ef5 Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Tue, 11 Apr 2023 21:05:53 -0700 Subject: [PATCH 03/79] chore: Remove old apps.json/app.json files --- AltStore.xcodeproj/project.pbxproj | 2 - AltStore/Resources/apps.json | 269 ----------------------------- app.json | 79 --------- 3 files changed, 350 deletions(-) delete mode 100644 AltStore/Resources/apps.json delete mode 100644 app.json diff --git a/AltStore.xcodeproj/project.pbxproj b/AltStore.xcodeproj/project.pbxproj index 8a12bc50..96c93b3d 100644 --- a/AltStore.xcodeproj/project.pbxproj +++ b/AltStore.xcodeproj/project.pbxproj @@ -729,7 +729,6 @@ BF9ABA4A22DD137F008935CF /* NavigationBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationBar.swift; sourceTree = ""; }; BF9ABA4C22DD16DE008935CF /* PillButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PillButton.swift; sourceTree = ""; }; BFA8172A23C5633D001B5953 /* FetchAnisetteDataOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchAnisetteDataOperation.swift; sourceTree = ""; }; - BFB1169C22932DB100BB457C /* apps.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = apps.json; sourceTree = ""; }; BFB39B5B252BC10E00D1BE50 /* Managed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Managed.swift; sourceTree = ""; }; BFB4323E22DE852000B7F8BC /* UpdateCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = UpdateCollectionViewCell.xib; sourceTree = ""; }; BFB6B21D231870160022A802 /* NewsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewsViewController.swift; sourceTree = ""; }; @@ -1619,7 +1618,6 @@ isa = PBXGroup; children = ( BF44EEF2246B3A17002A52F2 /* AltBackup.ipa */, - BFB1169C22932DB100BB457C /* apps.json */, BFD247762284B9A700981D42 /* Assets.xcassets */, BF770E6822BD57DD002A40FE /* Silence.m4a */, ); diff --git a/AltStore/Resources/apps.json b/AltStore/Resources/apps.json deleted file mode 100644 index c7a3bad2..00000000 --- a/AltStore/Resources/apps.json +++ /dev/null @@ -1,269 +0,0 @@ -{ - "name": "AltStore", - "identifier": "com.rileytestut.AltStore", - "sourceURL": "https://cdn.altstore.io/file/altstore/apps.json", - "apps": [ - { - "name": "AltStore", - "bundleIdentifier": "com.rileytestut.AltStore", - "developerName": "Riley Testut", - "version": "1.5.1", - "versionDate": "2022-07-14T12:00:00-05:00", - "versionDescription": "This update fixes the following issues:\n\n• Using Apple IDs that contain capital letters\n• Using Apple IDs with 2FA enabled without any trusted devices\n• Repeatedly asking some users to sign in every refresh\n• \"Incorrect Apple ID or password\" error after changing Apple ID email address\n• “Application is missing application-identifier” error when sideloading or (de-)activating certain apps\n• Potential crash when receiving unknown error codes from AltServer", - "downloadURL": "https://cdn.altstore.io/file/altstore/apps/altstore/1_5_1.ipa", - "localizedDescription": "AltStore is an alternative app store for non-jailbroken devices. \n\nThis version of AltStore allows you to install Delta, an all-in-one emulator for iOS, as well as sideload other .ipa files from the Files app.", - "iconURL": "https://user-images.githubusercontent.com/705880/65270980-1eb96f80-dad1-11e9-9367-78ccd25ceb02.png", - "tintColor": "018084", - "size": 5465976, - "screenshotURLs": [ - "https://user-images.githubusercontent.com/705880/78942028-acf54300-7a6d-11ea-821c-5bb7a9b3e73a.PNG", - "https://user-images.githubusercontent.com/705880/78942222-0fe6da00-7a6e-11ea-9f2a-dda16157583c.PNG", - "https://user-images.githubusercontent.com/705880/65605577-332cba80-df5e-11e9-9f00-b369ce974f71.PNG" - ], - "permissions": [ - { - "type": "background-fetch", - "usageDescription": "AltStore periodically refreshes apps in the background to prevent them from expiring." - }, - { - "type": "background-audio", - "usageDescription": "Allows AltStore to run longer than 30 seconds when refreshing apps in background." - } - ] - }, - { - "name": "AltStore", - "bundleIdentifier": "com.rileytestut.AltStore.Beta", - "developerName": "Riley Testut", - "subtitle": "An alternative App Store for iOS.", - "version": "1.6b2", - "versionDate": "2022-09-21T13:00:00-05:00", - "versionDescription": "• Fixed “error migrating persistent store” issue on launch\n\nPREVIOUS VERSION\n\nLock Screen Widget (iOS 16+)\n• Counts down days until AltStore expires\n• Comes in 2 different styles: “icon” and “text”\n\nError Log\n• View past errors in more detail\n• Tap an error to copy the error message or error code\n• Search for error code directly in AltStore FAQ", - "downloadURL": "https://cdn.altstore.io/file/altstore/apps/altstore/1_6_b2.ipa", - "localizedDescription": "AltStore is an alternative app store for non-jailbroken devices. \n\nThis beta release of AltStore adds support for 3rd party sources, allowing you to download apps from other developers directly through AltStore.", - "iconURL": "https://user-images.githubusercontent.com/705880/65270980-1eb96f80-dad1-11e9-9367-78ccd25ceb02.png", - "tintColor": "018084", - "size": 5465933, - "beta": true, - "screenshotURLs": [ - "https://user-images.githubusercontent.com/705880/78942028-acf54300-7a6d-11ea-821c-5bb7a9b3e73a.PNG", - "https://user-images.githubusercontent.com/705880/78942222-0fe6da00-7a6e-11ea-9f2a-dda16157583c.PNG", - "https://user-images.githubusercontent.com/705880/65605577-332cba80-df5e-11e9-9f00-b369ce974f71.PNG" - ], - "permissions": [ - { - "type": "background-fetch", - "usageDescription": "AltStore periodically refreshes apps in the background to prevent them from expiring." - }, - { - "type": "background-audio", - "usageDescription": "Allows AltStore to run longer than 30 seconds when refreshing apps in background." - } - ] - }, - { - "name": "Delta", - "bundleIdentifier": "com.rileytestut.Delta", - "developerName": "Riley Testut", - "subtitle": "Classic games in your pocket.", - "version": "1.3.1", - "versionDate": "2021-12-02T13:30:00-08:00", - "versionDescription": "• Fixes game artwork not loading\n• Fixes using deprecated DeSmuME core over melonDS core for some users", - "downloadURL": "https://cdn.altstore.io/file/altstore/apps/delta/1_3_1.ipa", - "localizedDescription": "Delta is an all-in-one emulator for iOS. Delta builds upon the strengths of its predecessor, GBA4iOS, while expanding to include support for more game systems such as NES, SNES, and N64.\n\nFEATURES\n\nSupported Game Systems\n• Nintendo Entertainment System\n• Super Nintendo Entertainment System\n• Nintendo 64\n• Game Boy (Color)\n• Game Boy Advance\n• Nintendo DS\n• And plenty more to come!\n\nController Support\n• Supports PS4, PS5, Xbox One S, Xbox Series X, and MFi game controllers.\n• Supports bluetooth (and wired) keyboards, as well as the Apple Smart Keyboard.\n• Completely customize button mappings on a per-system, per-controller basis.\n• Map buttons to special “Quick Save”, “Quick Load,” and “Fast Forward” actions.\n\nSave States\n• Save and load save states for any game from the pause menu.\n• Lock save states to prevent them from being accidentally overwritten.\n• Automatically makes backup save states to ensure you never lose your progress.\n• Support for “Quick Saves,” save states that can be quickly saved/loaded with a single button press (requires external controller).\n\nCheats\n• Supports various types of cheat codes for each supported system:\n• NES: Game Genie\n• SNES: Game Genie, Pro Action Replay\n• N64: GameShark\n• GBC: Game Genie, GameShark\n• GBA: Action Replay, Code Breaker, GameShark\n• DS: Action Replay\n\nDelta Sync\n• Sync your games, game saves, save states, cheats, controller skins, and controller mappings between devices.\n• View version histories of everything you sync and optionally restore them to earlier versions.\n• Supports both Google Drive and Dropbox.\n\nCustom Controller Skins\n• Beautiful built-in controller skins for all systems.\n• Import controller skins made by others, or even make your own to share with the world!\n\nHold Button\n• Choose buttons for Delta to hold down on your behalf, freeing up your thumbs to press other buttons instead.\n• Perfect for games that typically require one button be held down constantly (ex: run button in Mario games, or the A button in Mario Kart).\n\nFast Forward\n• Speed through slower parts of games by running the game much faster than normal.\n• Easily enable or disable from the pause menu, or optionally with a mapped button on an external controller.\n\n3D/Haptic Touch\n• Use 3D or Haptic Touch to “peek” at games, save states, and cheat codes.\n• App icon shortcuts allow quick access to your most recently played games, or optionally customize the shortcuts to always include certain games.\n\nGame Artwork\n• Automatically displays appropriate box art for imported games.\n• Change a game’s artwork to anything you want, or select from the built-in game artwork database.\n\nMisc.\n• Gyroscope support (WarioWare: Twisted! only)\n• Microphone support (DS only)\n• Support for delta:// URL scheme to jump directly into a specific game.\n\n**Delta and AltStore LLC are in no way affiliated with Nintendo. The name \"Nintendo\" and all associated game console names are registered trademarks of Nintendo Co., Ltd.**", - "iconURL": "https://user-images.githubusercontent.com/705880/63391976-4d311700-c37a-11e9-91a8-4fb0c454413d.png", - "tintColor": "8A28F7", - "size": 19739373, - "permissions": [ - { - "type": "photos", - "usageDescription": "Allows Delta to use images from your Photo Library as game artwork." - } - ], - "screenshotURLs": [ - "https://user-images.githubusercontent.com/705880/65600448-f7d9be00-df54-11e9-9e3e-d4c31296da94.PNG", - "https://user-images.githubusercontent.com/705880/65813009-f2ae8600-e183-11e9-9eb7-704effc11173.png", - "https://user-images.githubusercontent.com/705880/65601117-58b5c600-df56-11e9-9c19-9a5ba5da54cf.PNG", - "https://user-images.githubusercontent.com/705880/65601125-5b182000-df56-11e9-9e7e-261480e893c0.PNG" - ] - }, - { - "name": "Delta", - "bundleIdentifier": "com.rileytestut.Delta.Beta", - "developerName": "Riley Testut", - "subtitle": "Classic games in your pocket.", - "version": "1.4b2", - "versionDate": "2022-08-16T08:00:00-05:00", - "versionDescription": "NEW\n• Supports Split View and Stage Manager multitasking on iPad\n• Automatically pauses + resumes emulation when switching between foreground apps with Stage Manager\n• Optimized full screen-width controller skins when using Split View, Slide Over, or Stage Manager\n• Supports controller skins with new `placement` parameter\n• Supports controller skins with custom screens that don’t have explicit `outputFrame`\n\nFIXED\n• Fixed not detecting keyboard presses when remapping inputs\n• Fixed potential crash rendering game screen after changing EAGLContext\n• Fixed incorrect game screen frame when software keyboard appears on iOS 16\n• Fixed software keyboard sometimes appearing when not emulating anything", - "downloadURL": "https://cdn.altstore.io/file/altstore/apps/delta/1_4_b2.ipa", - "localizedDescription": "The next consoles for Delta are coming: this beta version of Delta brings support for playing Nintendo DS and Sega Genesis games!\n\nPlease report any issues you find to support@altstore.io. Thanks!", - "iconURL": "https://user-images.githubusercontent.com/705880/63391976-4d311700-c37a-11e9-91a8-4fb0c454413d.png", - "tintColor": "8A28F7", - "size": 42968657, - "beta": true, - "permissions": [ - { - "type": "photos", - "usageDescription": "Allows Delta to use images from your Photo Library as game artwork." - } - ], - "screenshotURLs": [ - "https://user-images.githubusercontent.com/705880/65600448-f7d9be00-df54-11e9-9e3e-d4c31296da94.PNG", - "https://user-images.githubusercontent.com/705880/65601942-e5ad4f00-df57-11e9-9255-1463e0296e46.PNG", - "https://user-images.githubusercontent.com/705880/65813009-f2ae8600-e183-11e9-9eb7-704effc11173.png", - "https://user-images.githubusercontent.com/705880/65601117-58b5c600-df56-11e9-9c19-9a5ba5da54cf.PNG" - ] - }, - { - "name": "Clip", - "bundleIdentifier": "com.rileytestut.Clip", - "subtitle": "Manage your clipboard history with ease.", - "developerName": "Riley Testut", - "version": "1.0", - "versionDate": "2020-06-17T12:30:00-07:00", - "versionDescription": "Initial version 🎉", - "downloadURL": "https://f000.backblazeb2.com/file/altstore/apps/clip/1_0.ipa", - "localizedDescription": "Clip is a simple clipboard manager for iOS. \n\nUnlike other clipboard managers, Clip can continue monitoring your clipboard while in the background. No longer do you need to remember to manually open or share to an app to save your clipboard; just copy and paste as you would normally do, and Clip will have your back.\n\nIn addition to background monitoring, Clip also has these features:\n\n• Save text, URLs, and images copied to the clipboard.\n• Copy, delete, or share any clippings saved to Clip.\n• Customizable history limit.\n\nDownload Clip today, and never worry about losing your clipboard again!", - "iconURL": "https://user-images.githubusercontent.com/705880/63391981-5326f800-c37a-11e9-99d8-760fd06bb601.png", - "tintColor": "EC008C", - "size": 445056, - "permissions": [ - { - "type": "background-audio", - "usageDescription": "Allows Clip to continuously monitor your clipboard in the background." - } - ], - "screenshotURLs": [ - "https://user-images.githubusercontent.com/705880/63391950-34286600-c37a-11e9-965f-832efe3da507.png", - "https://user-images.githubusercontent.com/705880/70830209-8e738980-1da4-11ea-8b3b-6e5fbc78adff.png" - ] - }, - { - "name": "Clip", - "bundleIdentifier": "com.rileytestut.Clip.Beta", - "subtitle": "Manage your clipboard history with ease.", - "developerName": "Riley Testut", - "version": "1.1b1", - "versionDate": "2020-06-17T12:30:00-07:00", - "versionDescription": "This update adds a Custom Keyboard app extension for quick access to clippings when editing text.\n\nTo enable the keyboard, go to Settings > General > Keyboard > Keyboards > Add New Keyboard... and add \"ClipBoard\". Once added, make sure to then enable \"Allow Full Access\" for ClipBoard so it can access your clippings.", - "downloadURL": "https://f000.backblazeb2.com/file/altstore/apps/clip/1_1_b1.ipa", - "localizedDescription": "Clip is a simple clipboard manager for iOS. \n\nUnlike other clipboard managers, Clip can continue monitoring your clipboard while in the background. No longer do you need to remember to manually open or share to an app to save your clipboard; just copy and paste as you would normally do, and Clip will have your back.\n\nIn addition to background monitoring, Clip also has these features:\n\n• Save text, URLs, and images copied to the clipboard.\n• Copy, delete, or share any clippings saved to Clip.\n• Customizable history limit.\n\nDownload Clip today, and never worry about losing your clipboard again!", - "iconURL": "https://user-images.githubusercontent.com/705880/63391981-5326f800-c37a-11e9-99d8-760fd06bb601.png", - "tintColor": "EC008C", - "size": 462771, - "beta": true, - "permissions": [ - { - "type": "background-audio", - "usageDescription": "Allows Clip to continuously monitor your clipboard in the background." - } - ], - "screenshotURLs": [ - "https://user-images.githubusercontent.com/705880/63391950-34286600-c37a-11e9-965f-832efe3da507.png", - "https://user-images.githubusercontent.com/705880/70830209-8e738980-1da4-11ea-8b3b-6e5fbc78adff.png", - "https://user-images.githubusercontent.com/705880/84842227-70a80b00-aff9-11ea-8b04-bedb1f49c4a7.PNG", - "https://user-images.githubusercontent.com/705880/84842231-7271ce80-aff9-11ea-9272-e128aeceb95b.PNG" - ] - } - ], - "news": [ - { - "title": "Delta Gaining DS Support", - "identifier": "delta-ds-support", - "caption": "Available this Saturday for patrons, coming soon for everyone else.", - "tintColor": "8A28F7", - "imageURL": "https://user-images.githubusercontent.com/705880/65603159-0676a400-df5a-11e9-882e-dc5566f4d50a.png", - "date": "2019-09-25", - "notify": false - }, - { - "title": "Delta Now Available", - "identifier": "delta-now-available", - "caption": "Finally, relive your favorite NES, SNES, GB(C), GBA, and N64 games.", - "tintColor": "8A28F7", - "imageURL": "https://user-images.githubusercontent.com/705880/65604130-c1ec0800-df5b-11e9-8150-7657c474e3c3.png", - "appID": "com.rileytestut.Delta", - "date": "2019-09-28", - "notify": true - }, - { - "title": "Sideloading is Here!", - "identifier": "sideloading-is-here", - "caption": "Update to AltStore 1.3 to install any app directly from Files.", - "tintColor": "018084", - "imageURL": "https://user-images.githubusercontent.com/705880/79022069-02932380-7b32-11ea-8bad-49907cb97ece.png", - "date": "2020-04-10T13:00:00-07:00", - "notify": true - }, - { - "title": "iOS 13.4 Fixes App Crashes", - "identifier": "ios-13-4-now-available", - "caption": "Update to iOS 13.4 to fix some sideloaded apps crashing on launch.", - "tintColor": "34C759", - "date": "2020-04-10T13:30:00-07:00", - "notify": false - }, - { - "title": "Clip Now Available!", - "identifier": "clip-now-available", - "caption": "Finally, a clipboard manager that can run in the background — no jailbreak required.", - "tintColor": "EC008C", - "imageURL": "https://user-images.githubusercontent.com/705880/65606598-04afdf00-df60-11e9-8f93-af6345d39557.png", - "appID": "com.rileytestut.Clip", - "date": "2020-06-17", - "notify": true - }, - { - "title": "Delta, Meet Nintendo DS", - "identifier": "delta-meet-ds", - "caption": "Update to Delta 1.3 to relive all your favorite Nintendo DS games.", - "tintColor": "8A28F7", - "imageURL": "https://user-images.githubusercontent.com/705880/115617602-6ce2b600-a2a6-11eb-984e-2197a30c71e2.png", - "appID": "com.rileytestut.Delta", - "date": "2021-04-21", - "notify": true - }, - { - "title": "#StandWithUkraine", - "identifier": "support-ukraine", - "caption": "Find out how you can help support those impacted by the Russian invasion.", - "tintColor": "003e80", - "imageURL": "https://user-images.githubusercontent.com/705880/156053447-a158cac7-df5f-4497-8025-15c3c2e10b48.png", - "url": "https://linktr.ee/razomforukraine", - "date": "2022-03-01", - "notify": false - }, - { - "title": "The Biggest AltServer Update Yet!", - "identifier": "altserver-1-5", - "caption": "Update to AltServer 1.5 to use AltJIT and other exciting new features.", - "tintColor": "018084", - "imageURL": "https://user-images.githubusercontent.com/705880/166509576-744be578-6868-4b7d-b4fd-b9418c084327.png", - "url": "https://faq.altstore.io/release-notes/altserver", - "date": "2022-05-03", - "notify": true - }, - { - "title": "More Apps in AltStore!", - "identifier": "trusted-sources", - "caption": "Update to AltStore 1.5 to easily download some of our favorite apps.", - "tintColor": "00CAB3", - "imageURL": "https://user-images.githubusercontent.com/705880/167026375-ddcb004f-7160-405c-b3e3-87a6795d2f43.png", - "url": "https://faq.altstore.io/release-notes/altstore", - "date": "2022-05-05", - "notify": true - }, - { - "title": "New to AltStore?", - "identifier": "updated-faq", - "caption": "Check out our updated guide to learn how to sideload apps!", - "tintColor": "018084", - "url": "https://faq.altstore.io", - "date": "2022-07-28", - "notify": false - } - ], - "userInfo": { - "patreonAccessToken": "uqoDoTxH8dY1ImE8tK76wxrzKk67gjyjBAcK8sD3RLU" - } -} diff --git a/app.json b/app.json deleted file mode 100644 index f0b7dabb..00000000 --- a/app.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "name": "SideStore Offical", - "identifier": "com.SideStore.SideStore", - "sourceURL": "https://apps.sidestore.io/", - "apps": [ - { - "name": "SideStore", - "bundleIdentifier": "com.SideStore.SideStore", - "developerName": "SideStore Team", - "version": "0.1.1", - "versionDate": "2022-010-15T12:00:00-05:00", - "versionDescription": "If you see this then please sideload the new version of SideStore via AltServer!", - "downloadURL": "https://github.com/SideStore/SideStore/releases/download/0.1.1/SideStore.ipa", - "localizedDescription": "SideStore is an alternative app store for non-jailbroken devices. \n\nSideStore allows you to sideload other .ipa files and apps from the Files app or via the SideStore Library", - "iconURL": "https://raw.githubusercontent.com/SideStore/apps.json/main/105070799.jpeg", - "tintColor": "8043FF", - "size": 5465976, - "screenshotURLs": [ - "https://user-images.githubusercontent.com/705880/78942028-acf54300-7a6d-11ea-821c-5bb7a9b3e73a.PNG", - "https://user-images.githubusercontent.com/705880/78942222-0fe6da00-7a6e-11ea-9f2a-dda16157583c.PNG", - "https://user-images.githubusercontent.com/705880/65605577-332cba80-df5e-11e9-9f00-b369ce974f71.PNG" - ], - "permissions": [ - { - "type": "background-fetch", - "usageDescription": "SideStore periodically refreshes apps in the background to prevent them from expiring." - }, - { - "type": "background-audio", - "usageDescription": "Allows SideStore to run longer than 30 seconds when refreshing apps in background." - } - ] - } - ], - "news": [ - { - "title": "Rick on the rocks", - "identifier": "rick", - "caption": "never gonna give ya rocks", - "tintColor": "912F8D", - "imageURL": "https://variety.com/wp-content/uploads/2021/07/Rick-Astley-Never-Gonna-Give-You-Up.png?w=681&h=383&crop=1", - "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", - "date": "2022-05-06", - "notify": false - }, - { - "title": "Rick waves his arms around", - "identifier": "no", - "caption": "never gonna", - "tintColor": "912F8D", - "imageURL": "https://variety.com/wp-content/uploads/2021/07/Rick-Astley-Never-Gonna-Give-You-Up.png?w=681&h=383&crop=1", - "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", - "date": "2022-05-05", - "notify": false - }, - { - "title": "#StandWithUkraine", - "identifier": "support-ukraine", - "caption": "Find out how you can help support those impacted by the Russian invasion.", - "tintColor": "003e80", - "imageURL": "https://user-images.githubusercontent.com/705880/156053447-a158cac7-df5f-4497-8025-15c3c2e10b48.png", - "url": "https://linktr.ee/razomforukraine", - "date": "2022-03-01", - "notify": false - }, - { - "title": "New to SideStore?", - "identifier": "updated-faq", - "caption": "Good luck!", - "tintColor": "8043FF", - "url": "https://faq.sidestore.io", - "date": "2050-07-28", - "notify": false - } - ], - "userInfo": { - "patreonAccessToken": "uqoDoTxH8dY1ImE8tK76wxrzKk67gjyjBAcK8sD3RLU" - } -} From 00f7a684a31e009103ca8b372329edad467af7f6 Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Tue, 11 Apr 2023 21:09:32 -0700 Subject: [PATCH 04/79] [skip ci] chore: rename tempEnt.plist to ReleaseEntitlements.plist to reduce future confusion --- AltStore/Resources/{tempEnt.plist => ReleaseEntitlements.plist} | 0 Makefile | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename AltStore/Resources/{tempEnt.plist => ReleaseEntitlements.plist} (100%) diff --git a/AltStore/Resources/tempEnt.plist b/AltStore/Resources/ReleaseEntitlements.plist similarity index 100% rename from AltStore/Resources/tempEnt.plist rename to AltStore/Resources/ReleaseEntitlements.plist diff --git a/Makefile b/Makefile index 503859bf..3163b86c 100644 --- a/Makefile +++ b/Makefile @@ -170,7 +170,7 @@ build: fakesign: rm -rf archive.xcarchive/Products/Applications/SideStore.app/Frameworks/AltStoreCore.framework/Frameworks/ - ldid -SAltStore/Resources/tempEnt.plist archive.xcarchive/Products/Applications/SideStore.app/SideStore + ldid -SAltStore/Resources/ReleaseEntitlements.plist archive.xcarchive/Products/Applications/SideStore.app/SideStore ipa: mkdir Payload From 536f775baab49bccb59ffd21b93da3790e7af361 Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Tue, 11 Apr 2023 21:12:01 -0700 Subject: [PATCH 05/79] Revert "Don't reinstall on first SideStore refresh" This reverts commit 40e1225b875922d8d0dfe0e713434e4150a26e03. --- AltStore/Managing Apps/AppManager.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/AltStore/Managing Apps/AppManager.swift b/AltStore/Managing Apps/AppManager.swift index f6fb71ce..5bf39ed2 100644 --- a/AltStore/Managing Apps/AppManager.swift +++ b/AltStore/Managing Apps/AppManager.swift @@ -874,11 +874,7 @@ private extension AppManager // Check if backup app is installed in place of real app. let uti = UTTypeCopyDeclaration(app.installedBackupAppUTI as CFString)?.takeRetainedValue() as NSDictionary? - // for some reason, `app.certificateSerialNumber != group.context.certificate?.serialNumber` is true on first SideStore refresh - // in most cases, the first refresh gets stuck since it is a full reinstall, and to fix it you must exit to home screen - // which finishes it but removes all app data - // so we want to ensure we don't reinstall for SideStore if it's true (it will still reinstall if needsResign is true) - if (app.certificateSerialNumber != group.context.certificate?.serialNumber && app.bundleIdentifier != StoreApp.altstoreAppID) || + if app.certificateSerialNumber != group.context.certificate?.serialNumber || uti != nil || app.needsResign { From 3dd0735305e281b6920a120d8ae5574b1a14067a Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Tue, 11 Apr 2023 21:50:15 -0700 Subject: [PATCH 06/79] fix: always reinstall when refreshing ourselves --- AltStore/Managing Apps/AppManager.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/AltStore/Managing Apps/AppManager.swift b/AltStore/Managing Apps/AppManager.swift index 5bf39ed2..fc28cfba 100644 --- a/AltStore/Managing Apps/AppManager.swift +++ b/AltStore/Managing Apps/AppManager.swift @@ -876,7 +876,9 @@ private extension AppManager if app.certificateSerialNumber != group.context.certificate?.serialNumber || uti != nil || - app.needsResign + app.needsResign || + // We need to reinstall ourselves on refresh to ensure the new provisioning profile is used + app.bundleIdentifier == StoreApp.altstoreAppID { // Resign app instead of just refreshing profiles because either: // * Refreshing using different certificate From 8a97c409facda05aa676527b8cc2021fa5438ffb Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Wed, 12 Apr 2023 07:46:14 -0700 Subject: [PATCH 07/79] fix: add .AltWidget to app group ID when modifying for SideStore --- .../FetchProvisioningProfilesOperation.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/AltStore/Operations/FetchProvisioningProfilesOperation.swift b/AltStore/Operations/FetchProvisioningProfilesOperation.swift index 955282f4..2782a467 100644 --- a/AltStore/Operations/FetchProvisioningProfilesOperation.swift +++ b/AltStore/Operations/FetchProvisioningProfilesOperation.swift @@ -394,17 +394,26 @@ extension FetchProvisioningProfilesOperation } } + // Make sure we add .AltWidget for the widget + var altStoreAppGroupID = Bundle.baseAltStoreAppGroupID + for (_, group) in applicationGroups.enumerated() { + if group.contains("AltWidget") { + altStoreAppGroupID += ".AltWidget" + break + } + } + // Potentially updating app groups for this specific AltStore. // Find the (unique) AltStore app group, then replace it // with the correct "base" app group ID. // Otherwise, we may append a duplicate team identifier to the end. if let index = applicationGroups.firstIndex(where: { $0.contains(Bundle.baseAltStoreAppGroupID) }) { - applicationGroups[index] = Bundle.baseAltStoreAppGroupID + applicationGroups[index] = altStoreAppGroupID } else { - applicationGroups.append(Bundle.baseAltStoreAppGroupID) + applicationGroups.append(altStoreAppGroupID) } } print("Application groups: \(applicationGroups)") From 0178c63f6ae3273ce227f147308eb2039de5fd14 Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Wed, 12 Apr 2023 19:53:27 -0700 Subject: [PATCH 08/79] fix: hopefully reduce ApplicationVerificationFailed errors by removing _CodeSignature folders since those may cause a problem --- AltStore/Operations/ResignAppOperation.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/AltStore/Operations/ResignAppOperation.swift b/AltStore/Operations/ResignAppOperation.swift index a6098e00..12760205 100644 --- a/AltStore/Operations/ResignAppOperation.swift +++ b/AltStore/Operations/ResignAppOperation.swift @@ -148,6 +148,14 @@ private extension ResignAppOperation infoDictionary[Bundle.Info.exportedUTIs] = exportedUTIs try (infoDictionary as NSDictionary).write(to: bundle.infoPlistURL) + + // Remove _CodeSignature folder (if it exists) because it will be added when resigning and it may have files that aren't overwritten when resigning + // These files might be the cause of some ApplicationVerificationFailed errors + let codeSignaturePath = bundle.bundleURL.appendingPathComponent("_CodeSignature").absoluteString + if FileManager.default.fileExists(atPath: codeSignaturePath) { + try FileManager.default.removeItem(atPath: codeSignaturePath) + print("Removed _CodeSignature folder at \(codeSignaturePath)") + } } DispatchQueue.global().async { From 1ca3aa3cdb50e73e830411850b843be926755e57 Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Thu, 13 Apr 2023 07:20:36 -0700 Subject: [PATCH 09/79] fix: force close SideStore after 3 seconds if still reinstalling --- AltStore/Operations/InstallAppOperation.swift | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/AltStore/Operations/InstallAppOperation.swift b/AltStore/Operations/InstallAppOperation.swift index abe24a85..41deab1a 100644 --- a/AltStore/Operations/InstallAppOperation.swift +++ b/AltStore/Operations/InstallAppOperation.swift @@ -149,9 +149,45 @@ final class InstallAppOperation: ResultOperation }) } + // Since reinstalling ourself will hang until we leave the app, force quit after 3 seconds if still installing + var installing = true + if installedApp.storeApp?.bundleIdentifier == Bundle.Info.appbundleIdentifier { + DispatchQueue.main.asyncAfter(deadline: .now() + 3) { + if installing { + print("We are still installing after 3 seconds") + + let alert = UIAlertController(title: "Finish Refresh", message: "To finish refreshing, SideStore must force close itself. Please reopen SideStore after continuing!", preferredStyle: .alert) + alert.addAction(UIAlertAction(title: NSLocalizedString("Continue", comment: ""), style: .default, handler: { _ in + if installing { + print("Closing SideStore since we are still installing") + exit(0) + } else { + print("Not closing SideStore since installing finished") + } + })) + + let keyWindow = UIApplication.shared.windows.filter { $0.isKeyWindow }.first + if var topController = keyWindow?.rootViewController { + while let presentedViewController = topController.presentedViewController { + topController = presentedViewController + } + + topController.present(alert, animated: true) + } else { + print("No key window? Closing SideStore") + exit(0) + } + } else { + print("Installing finished") + } + } + } + do { try install_ipa(installedApp.bundleIdentifier) + installing = false } catch { + installing = false return self.finish(.failure(error)) } From 51ed87086ab6165d3461a86656941edfb80f0983 Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Thu, 13 Apr 2023 07:30:20 -0700 Subject: [PATCH 10/79] [skip ci] ci: fully rename SideStore.ipa, even after extracting the artifact zip --- .github/workflows/beta.yml | 27 +++++++++++++++------------ .github/workflows/nightly.yml | 27 +++++++++++++++------------ .github/workflows/pr.yml | 7 +++++-- .github/workflows/stable.yml | 27 +++++++++++++++------------ 4 files changed, 50 insertions(+), 38 deletions(-) diff --git a/.github/workflows/beta.yml b/.github/workflows/beta.yml index 1973681b..e5792b55 100644 --- a/.github/workflows/beta.yml +++ b/.github/workflows/beta.yml @@ -48,18 +48,6 @@ jobs: - name: Convert to IPA run: make ipa - - name: Upload SideStore.ipa Artifact - uses: actions/upload-artifact@v3.1.0 - with: - name: SideStore-${{ steps.version.outputs.version }}.ipa - path: SideStore.ipa - - - name: Upload *.dSYM Artifact - uses: actions/upload-artifact@v3.1.0 - with: - name: SideStore-dSYM - path: ./*.dSYM/ - - name: Get current date id: date run: echo "date=$(date -u +'%c')" >> $GITHUB_OUTPUT @@ -91,3 +79,18 @@ jobs: Built at (UTC date): `${{ steps.date_altstore.outputs.date }}` Commit SHA: `${{ github.sha }}` Version: `${{ steps.version.outputs.version }}` + + - name: Add version to IPA file name + run: mv SideStore.ipa SideStore-${{ steps.version.outputs.version }}.ipa + + - name: Upload SideStore.ipa Artifact + uses: actions/upload-artifact@v3.1.0 + with: + name: SideStore-${{ steps.version.outputs.version }}.ipa + path: SideStore-${{ steps.version.outputs.version }}.ipa + + - name: Upload *.dSYM Artifact + uses: actions/upload-artifact@v3.1.0 + with: + name: SideStore-${{ steps.version.outputs.version }}-dSYM + path: ./*.dSYM/ diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 96acefed..aea20363 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -57,18 +57,6 @@ jobs: - name: Convert to IPA run: make ipa - - name: Upload SideStore.ipa Artifact - uses: actions/upload-artifact@v3.1.0 - with: - name: SideStore-${{ steps.version.outputs.version }}.ipa - path: SideStore.ipa - - - name: Upload *.dSYM Artifact - uses: actions/upload-artifact@v3.1.0 - with: - name: SideStore-dSYM - path: ./*.dSYM/ - - name: Get current date id: date run: echo "date=$(date -u +'%c')" >> $GITHUB_OUTPUT @@ -99,5 +87,20 @@ jobs: Commit SHA: `${{ github.sha }}` Version: `${{ steps.version.outputs.version }}` + - name: Add version to IPA file name + run: mv SideStore.ipa SideStore-${{ steps.version.outputs.version }}.ipa + + - name: Upload SideStore.ipa Artifact + uses: actions/upload-artifact@v3.1.0 + with: + name: SideStore-${{ steps.version.outputs.version }}.ipa + path: SideStore-${{ steps.version.outputs.version }}.ipa + + - name: Upload *.dSYM Artifact + uses: actions/upload-artifact@v3.1.0 + with: + name: SideStore-${{ steps.version.outputs.version }}-dSYM + path: ./*.dSYM/ + - name: Reset cache for apps.sidestore.io/nightly run: sleep 10 && curl https://apps.sidestore.io/reset-cache/nightly/${{ secrets.SIDESOURCE_KEY }} diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 7e3df0eb..6befcfbb 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -48,14 +48,17 @@ jobs: - name: Convert to IPA run: make ipa + - name: Add version to IPA file name + run: mv SideStore.ipa SideStore-${{ steps.version.outputs.version }}.ipa + - name: Upload SideStore.ipa Artifact uses: actions/upload-artifact@v3.1.0 with: name: SideStore-${{ steps.version.outputs.version }}.ipa - path: SideStore.ipa + path: SideStore-${{ steps.version.outputs.version }}.ipa - name: Upload *.dSYM Artifact uses: actions/upload-artifact@v3.1.0 with: - name: SideStore-dSYM + name: SideStore-${{ steps.version.outputs.version }}-dSYM path: ./*.dSYM/ diff --git a/.github/workflows/stable.yml b/.github/workflows/stable.yml index 06a759ae..d1a6d1e5 100644 --- a/.github/workflows/stable.yml +++ b/.github/workflows/stable.yml @@ -48,18 +48,6 @@ jobs: - name: Convert to IPA run: make ipa - - name: Upload SideStore.ipa Artifact - uses: actions/upload-artifact@v3.1.0 - with: - name: SideStore-${{ steps.version.outputs.version }}.ipa - path: SideStore.ipa - - - name: Upload *.dSYM Artifact - uses: actions/upload-artifact@v3.1.0 - with: - name: SideStore-dSYM - path: ./*.dSYM/ - - name: Get current date id: date run: echo "date=$(date -u +'%c')" >> $GITHUB_OUTPUT @@ -88,3 +76,18 @@ jobs: Built at (UTC date): `${{ steps.date_altstore.outputs.date }}` Commit SHA: `${{ github.sha }}` Version: `${{ steps.version.outputs.version }}` + + - name: Add version to IPA file name + run: mv SideStore.ipa SideStore-${{ steps.version.outputs.version }}.ipa + + - name: Upload SideStore.ipa Artifact + uses: actions/upload-artifact@v3.1.0 + with: + name: SideStore-${{ steps.version.outputs.version }}.ipa + path: SideStore-${{ steps.version.outputs.version }}.ipa + + - name: Upload *.dSYM Artifact + uses: actions/upload-artifact@v3.1.0 + with: + name: SideStore-${{ steps.version.outputs.version }}-dSYM + path: ./*.dSYM/ From f519d22d81b837a522add8e654aa8f80d96496b8 Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Thu, 13 Apr 2023 21:21:51 -0700 Subject: [PATCH 11/79] fix: removing _CodeSignature folder before resigning --- AltStore/Operations/ResignAppOperation.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AltStore/Operations/ResignAppOperation.swift b/AltStore/Operations/ResignAppOperation.swift index 12760205..59336d86 100644 --- a/AltStore/Operations/ResignAppOperation.swift +++ b/AltStore/Operations/ResignAppOperation.swift @@ -151,7 +151,7 @@ private extension ResignAppOperation // Remove _CodeSignature folder (if it exists) because it will be added when resigning and it may have files that aren't overwritten when resigning // These files might be the cause of some ApplicationVerificationFailed errors - let codeSignaturePath = bundle.bundleURL.appendingPathComponent("_CodeSignature").absoluteString + let codeSignaturePath = bundle.bundleURL.appendingPathComponent("_CodeSignature").absoluteString.replacingOccurrences(of: "file://", with: "") if FileManager.default.fileExists(atPath: codeSignaturePath) { try FileManager.default.removeItem(atPath: codeSignaturePath) print("Removed _CodeSignature folder at \(codeSignaturePath)") From ee5ddd426481bed99652945755476e138b194b6b Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Sun, 16 Apr 2023 09:29:12 -0700 Subject: [PATCH 12/79] fix: use a notification instead of an alert for force close --- AltStore/Operations/InstallAppOperation.swift | 29 +++++-------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/AltStore/Operations/InstallAppOperation.swift b/AltStore/Operations/InstallAppOperation.swift index 41deab1a..12db3326 100644 --- a/AltStore/Operations/InstallAppOperation.swift +++ b/AltStore/Operations/InstallAppOperation.swift @@ -154,29 +154,14 @@ final class InstallAppOperation: ResultOperation if installedApp.storeApp?.bundleIdentifier == Bundle.Info.appbundleIdentifier { DispatchQueue.main.asyncAfter(deadline: .now() + 3) { if installing { - print("We are still installing after 3 seconds") + print("We are still installing after 3 seconds, requesting notification and then closing") - let alert = UIAlertController(title: "Finish Refresh", message: "To finish refreshing, SideStore must force close itself. Please reopen SideStore after continuing!", preferredStyle: .alert) - alert.addAction(UIAlertAction(title: NSLocalizedString("Continue", comment: ""), style: .default, handler: { _ in - if installing { - print("Closing SideStore since we are still installing") - exit(0) - } else { - print("Not closing SideStore since installing finished") - } - })) - - let keyWindow = UIApplication.shared.windows.filter { $0.isKeyWindow }.first - if var topController = keyWindow?.rootViewController { - while let presentedViewController = topController.presentedViewController { - topController = presentedViewController - } - - topController.present(alert, animated: true) - } else { - print("No key window? Closing SideStore") - exit(0) - } + var content = UNMutableNotificationContent() + content.title = "Refreshing..." + content.body = "To finish refreshing, SideStore must force close itself. Please reopen SideStore after it is done refreshing!" + let notification = UNNotificationRequest(identifier: Bundle.Info.appbundleIdentifier + ".FinishRefreshNotification", content: content, trigger: UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)) + UNUserNotificationCenter.current().add(notification) + exit(0) } else { print("Installing finished") } From 07533e0365b04f3d797e2ea0e73287a84969dc96 Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Sun, 16 Apr 2023 10:07:04 -0700 Subject: [PATCH 13/79] fix: ensure minimuxer is started when refreshing in the background --- AltStore/Operations/BackgroundRefreshAppsOperation.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/AltStore/Operations/BackgroundRefreshAppsOperation.swift b/AltStore/Operations/BackgroundRefreshAppsOperation.swift index 0b3aa209..e38a9a1c 100644 --- a/AltStore/Operations/BackgroundRefreshAppsOperation.swift +++ b/AltStore/Operations/BackgroundRefreshAppsOperation.swift @@ -11,6 +11,7 @@ import CoreData import AltStoreCore import EmotionalDamage +import minimuxer enum RefreshError: LocalizedError { @@ -97,6 +98,14 @@ final class BackgroundRefreshAppsOperation: ResultOperation<[String: Result Date: Sat, 6 May 2023 19:25:37 -0700 Subject: [PATCH 14/79] fix: open Safari instead of force closing and provide a fallback for users with notifications disabled --- AltStore/Operations/InstallAppOperation.swift | 59 +++++++++++++++---- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/AltStore/Operations/InstallAppOperation.swift b/AltStore/Operations/InstallAppOperation.swift index 12db3326..bc866498 100644 --- a/AltStore/Operations/InstallAppOperation.swift +++ b/AltStore/Operations/InstallAppOperation.swift @@ -149,21 +149,58 @@ final class InstallAppOperation: ResultOperation }) } - // Since reinstalling ourself will hang until we leave the app, force quit after 3 seconds if still installing var installing = true if installedApp.storeApp?.bundleIdentifier == Bundle.Info.appbundleIdentifier { + // Reinstalling ourself will hang until we leave the app, so we need to exit it without force closing DispatchQueue.main.asyncAfter(deadline: .now() + 3) { - if installing { - print("We are still installing after 3 seconds, requesting notification and then closing") - - var content = UNMutableNotificationContent() - content.title = "Refreshing..." - content.body = "To finish refreshing, SideStore must force close itself. Please reopen SideStore after it is done refreshing!" - let notification = UNNotificationRequest(identifier: Bundle.Info.appbundleIdentifier + ".FinishRefreshNotification", content: content, trigger: UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)) - UNUserNotificationCenter.current().add(notification) - exit(0) - } else { + if UIApplication.shared.applicationState != .active { + print("We are not in the foreground, let's not do anything") + return + } + if !installing { print("Installing finished") + return + } + print("We are still installing after 3 seconds") + + UNUserNotificationCenter.current().getNotificationSettings { settings in + switch (settings.authorizationStatus) { + case .authorized, .ephemeral, .provisional: + print("Notifications are enabled") + + let content = UNMutableNotificationContent() + content.title = "Refreshing..." + content.body = "To finish refreshing, SideStore must be moved to the background, which it does by opening Safari. Please reopen SideStore after it is done refreshing!" + let notification = UNNotificationRequest(identifier: Bundle.Info.appbundleIdentifier + ".FinishRefreshNotification", content: content, trigger: UNTimeIntervalNotificationTrigger(timeInterval: 2, repeats: false)) + UNUserNotificationCenter.current().add(notification) + + DispatchQueue.main.async { UIApplication.shared.open(URL(string: "x-web-search://")!) } + + break + default: + print("Notifications are not enabled") + + let alert = UIAlertController(title: "Finish Refresh", message: "To finish refreshing, SideStore must be moved to the background. To do this, you can either go to the Home Screen or open Safari by pressing Continue. Please reopen SideStore after doing this.", preferredStyle: .alert) + alert.addAction(UIAlertAction(title: NSLocalizedString("Continue", comment: ""), style: .default, handler: { _ in + print("Opening Safari") + DispatchQueue.main.async { UIApplication.shared.open(URL(string: "x-web-search://")!) } + })) + + DispatchQueue.main.async { + let keyWindow = UIApplication.shared.windows.filter { $0.isKeyWindow }.first + if var topController = keyWindow?.rootViewController { + while let presentedViewController = topController.presentedViewController { + topController = presentedViewController + } + topController.present(alert, animated: true) + } else { + print("No key window? Let's just open Safari") + UIApplication.shared.open(URL(string: "x-web-search://")!) + } + } + + break + } } } } From 1c0d0be62214ac75d565c26f117a89b84bb148ce Mon Sep 17 00:00:00 2001 From: SoY0ung <32095074+SoY0ung@users.noreply.github.com> Date: Sun, 14 May 2023 02:55:36 +0800 Subject: [PATCH 15/79] Fix 'The name for this app is invalid' error This error is related to App ID creation failure. App ID name must be an ascii text. It is not allowed to create an App ID with non-ascii text like Chinese, Japanese. If the name is NOT an ascii text, using bundleID instead. --- .../FetchProvisioningProfilesOperation.swift | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/AltStore/Operations/FetchProvisioningProfilesOperation.swift b/AltStore/Operations/FetchProvisioningProfilesOperation.swift index 2782a467..69f47449 100644 --- a/AltStore/Operations/FetchProvisioningProfilesOperation.swift +++ b/AltStore/Operations/FetchProvisioningProfilesOperation.swift @@ -268,8 +268,17 @@ extension FetchProvisioningProfilesOperation } } } + //App ID name must be ascii. If the name is not ascii, using bundleID instead + let appIDName: String + if containsNonASCII(text: name) { + //Contains non ASCII (Such as Chinese/Japanese...), using bundleID + appIDName = bundleIdentifier + }else { + //ASCII text, keep going as usual + appIDName = name + } - ALTAppleAPI.shared.addAppID(withName: name, bundleIdentifier: bundleIdentifier, team: team, session: session) { (appID, error) in + ALTAppleAPI.shared.addAppID(withName: appIDName, bundleIdentifier: bundleIdentifier, team: team, session: session) { (appID, error) in do { do @@ -514,3 +523,13 @@ extension FetchProvisioningProfilesOperation } } } + +func containsNonASCII(text: String) -> Bool { + let ascii = CharacterSet(charactersIn: "\0"..."~") + for scalar in text.unicodeScalars { + if !ascii.contains(scalar) { + return true + } + } + return false +} From 84e2284f5691d58f0808723d071b49cb44fb348e Mon Sep 17 00:00:00 2001 From: SoY0ung <32095074+SoY0ung@users.noreply.github.com> Date: Sun, 14 May 2023 19:06:22 +0800 Subject: [PATCH 16/79] Optimizing function calls Thanks for @ktprograms advice --- .../FetchProvisioningProfilesOperation.swift | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/AltStore/Operations/FetchProvisioningProfilesOperation.swift b/AltStore/Operations/FetchProvisioningProfilesOperation.swift index 69f47449..89663226 100644 --- a/AltStore/Operations/FetchProvisioningProfilesOperation.swift +++ b/AltStore/Operations/FetchProvisioningProfilesOperation.swift @@ -270,7 +270,7 @@ extension FetchProvisioningProfilesOperation } //App ID name must be ascii. If the name is not ascii, using bundleID instead let appIDName: String - if containsNonASCII(text: name) { + if !name.allSatisfy({ $0.isASCII }) { //Contains non ASCII (Such as Chinese/Japanese...), using bundleID appIDName = bundleIdentifier }else { @@ -523,13 +523,3 @@ extension FetchProvisioningProfilesOperation } } } - -func containsNonASCII(text: String) -> Bool { - let ascii = CharacterSet(charactersIn: "\0"..."~") - for scalar in text.unicodeScalars { - if !ascii.contains(scalar) { - return true - } - } - return false -} From ed2270ff46feb210a609797dd84ab50c584ca9b6 Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Thu, 18 May 2023 01:30:18 -0700 Subject: [PATCH 17/79] Anisette V3 (#324) * initial anisette V3 implementation * update V3 urls and log version * fix crash where FetchAnisetteDataOperation.clientInfo would be nil when getting anisette V3 without provisioning first * move adi.pb reset to its own button instead of doing it on sign out * fallback to V1 if client_info fails * make sure to unwrap optional strings * feat(anisette): update v3 usage, improve error messages and names, report v3 errors to the user * refactor(anisette): reduce duplicate JSON to anisette code * fixes(anisette v3): improve errors, fix v3 server check, fix some edge cases where SideStore could crash and instead return an error, retry on -45061 --- AltStore.xcodeproj/project.pbxproj | 17 + .../xcshareddata/swiftpm/Package.resolved | 9 + .../FetchAnisetteDataOperation.swift | 435 +++++++++++++++++- AltStore/Operations/OperationError.swift | 7 + AltStore/Settings/Settings.storyboard | 39 +- .../Settings/SettingsViewController.swift | 20 + AltStoreCore/Components/Keychain.swift | 6 + .../Extensions/UserDefaults+AltStore.swift | 1 + 8 files changed, 510 insertions(+), 24 deletions(-) diff --git a/AltStore.xcodeproj/project.pbxproj b/AltStore.xcodeproj/project.pbxproj index 96c93b3d..721362b6 100644 --- a/AltStore.xcodeproj/project.pbxproj +++ b/AltStore.xcodeproj/project.pbxproj @@ -19,6 +19,7 @@ 19B9B7452845E6DF0076EF69 /* SelectTeamViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19B9B7442845E6DF0076EF69 /* SelectTeamViewController.swift */; }; 4879A95F2861046500FC1BBD /* AltSign in Frameworks */ = {isa = PBXBuildFile; productRef = 4879A95E2861046500FC1BBD /* AltSign */; }; 4879A9622861049C00FC1BBD /* OpenSSL in Frameworks */ = {isa = PBXBuildFile; productRef = 4879A9612861049C00FC1BBD /* OpenSSL */; }; + 9922FFEC29B501C50020F868 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = 9922FFEB29B501C50020F868 /* Starscream */; }; 99C4EF4D2979132100CB538D /* SemanticVersion in Frameworks */ = {isa = PBXBuildFile; productRef = 99C4EF4C2979132100CB538D /* SemanticVersion */; }; 99F87D0529D8B4E200B40039 /* minimuxer-helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9961EC2D29BE9F2E00AF2C6F /* minimuxer-helpers.swift */; }; 99F87D1829D8E4C900B40039 /* SwiftBridgeCore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99F87D1629D8E4C900B40039 /* SwiftBridgeCore.swift */; }; @@ -921,6 +922,7 @@ B3146ED2284F581E00BBC3FD /* Roxas.framework in Frameworks */, D533E8B72727841800A9B5DD /* libAppleArchive.tbd in Frameworks */, B3C395F9284F362400DA9E2F /* AppCenterCrashes in Frameworks */, + 9922FFEC29B501C50020F868 /* Starscream in Frameworks */, D533E8BE2727BBF800A9B5DD /* libcurl.a in Frameworks */, 4879A9622861049C00FC1BBD /* OpenSSL in Frameworks */, B3C395F4284F35DD00DA9E2F /* Nuke in Frameworks */, @@ -1991,6 +1993,7 @@ B3C395F6284F362400DA9E2F /* AppCenterAnalytics */, B3C395F8284F362400DA9E2F /* AppCenterCrashes */, 4879A9612861049C00FC1BBD /* OpenSSL */, + 9922FFEB29B501C50020F868 /* Starscream */, ); productName = AltStore; productReference = BFD2476A2284B9A500981D42 /* SideStore.app */; @@ -2062,6 +2065,7 @@ 4879A95D2861046500FC1BBD /* XCRemoteSwiftPackageReference "AltSign" */, 4879A9602861049C00FC1BBD /* XCRemoteSwiftPackageReference "OpenSSL" */, 99C4EF472978D52400CB538D /* XCRemoteSwiftPackageReference "SemanticVersion" */, + 9922FFEA29B501C50020F868 /* XCRemoteSwiftPackageReference "Starscream" */, ); productRefGroup = BFD2476B2284B9A500981D42 /* Products */; projectDirPath = ""; @@ -3367,6 +3371,14 @@ minimumVersion = 1.1.180; }; }; + 9922FFEA29B501C50020F868 /* XCRemoteSwiftPackageReference "Starscream" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/daltoniam/Starscream.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 4.0.0; + }; + }; 99C4EF472978D52400CB538D /* XCRemoteSwiftPackageReference "SemanticVersion" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/SwiftPackageIndex/SemanticVersion.git"; @@ -3446,6 +3458,11 @@ package = 4879A9602861049C00FC1BBD /* XCRemoteSwiftPackageReference "OpenSSL" */; productName = OpenSSL; }; + 9922FFEB29B501C50020F868 /* Starscream */ = { + isa = XCSwiftPackageProductDependency; + package = 9922FFEA29B501C50020F868 /* XCRemoteSwiftPackageReference "Starscream" */; + productName = Starscream; + }; 99C4EF4C2979132100CB538D /* SemanticVersion */ = { isa = XCSwiftPackageProductDependency; package = 99C4EF472978D52400CB538D /* XCRemoteSwiftPackageReference "SemanticVersion" */; diff --git a/AltStore.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/AltStore.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 410b636e..93b37443 100644 --- a/AltStore.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/AltStore.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -81,6 +81,15 @@ "version" : "2.1.0" } }, + { + "identity" : "starscream", + "kind" : "remoteSourceControl", + "location" : "https://github.com/daltoniam/Starscream.git", + "state" : { + "revision" : "df8d82047f6654d8e4b655d1b1525c64e1059d21", + "version" : "4.0.4" + } + }, { "identity" : "stprivilegedtask", "kind" : "remoteSourceControl", diff --git a/AltStore/Operations/FetchAnisetteDataOperation.swift b/AltStore/Operations/FetchAnisetteDataOperation.swift index 4a121751..a0b899c6 100644 --- a/AltStore/Operations/FetchAnisetteDataOperation.swift +++ b/AltStore/Operations/FetchAnisetteDataOperation.swift @@ -7,15 +7,28 @@ // import Foundation +import CommonCrypto +import Starscream import AltStoreCore import AltSign import Roxas @objc(FetchAnisetteDataOperation) -final class FetchAnisetteDataOperation: ResultOperation +final class FetchAnisetteDataOperation: ResultOperation, WebSocketDelegate { let context: OperationContext + var socket: WebSocket! + + var url: URL? + var startProvisioningURL: URL? + var endProvisioningURL: URL? + + var clientInfo: String? + var userAgent: String? + + var mdLu: String? + var deviceId: String? init(context: OperationContext) { @@ -32,32 +45,412 @@ final class FetchAnisetteDataOperation: ResultOperation return } - let url = AnisetteManager.currentURL - DLOG("Anisette URL: %@", url.absoluteString) + self.url = AnisetteManager.currentURL + print("Anisette URL: \(self.url!.absoluteString)") - let task = URLSession.shared.dataTask(with: url) { data, response, error in - guard let data = data, error == nil else { return } - - do { - // make sure this JSON is in the format we expect - // convert data to json - if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: String] { - // try to read out a dictionary - //for some reason serial number isn't needed but it doesn't work unless it has a value - let formattedJSON: [String: String] = ["machineID": json["X-Apple-I-MD-M"]!, "oneTimePassword": json["X-Apple-I-MD"]!, "localUserID": json["X-Apple-I-MD-LU"]!, "routingInfo": json["X-Apple-I-MD-RINFO"]!, "deviceUniqueIdentifier": json["X-Mme-Device-Id"]!, "deviceDescription": json["X-MMe-Client-Info"]!, "date": json["X-Apple-I-Client-Time"]!, "locale": json["X-Apple-Locale"]!, "timeZone": json["X-Apple-I-TimeZone"]!, "deviceSerialNumber": "1"] - - if let anisette = ALTAnisetteData(json: formattedJSON) { - DLOG("Anisette used: %@", formattedJSON) - self.finish(.success(anisette)) - } + if let identifier = Keychain.shared.identifier, + let adiPb = Keychain.shared.adiPb { + fetchAnisetteV3(identifier, adiPb) + } else { + provision() + } + } + + // MARK: - COMMON + + func extractAnisetteData(_ data: Data, _ response: HTTPURLResponse?, v3: Bool) throws { + // make sure this JSON is in the format we expect + // convert data to json + if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: String] { + if v3 { + if json["result"] == "GetHeadersError" { + let message = json["message"] + print("Error getting V3 headers: \(message ?? "no message")") + if let message = message, + message.contains("-45061") { + print("Error message contains -45061 (not provisioned), resetting adi.pb and retrying") + Keychain.shared.adiPb = nil + return provision() + } else { throw OperationError.anisetteV3Error(message: message ?? "Unknown error") } } + } + + // try to read out a dictionary + // for some reason serial number isn't needed but it doesn't work unless it has a value + var formattedJSON: [String: String] = ["deviceSerialNumber": "0"] + if let machineID = json["X-Apple-I-MD-M"] { formattedJSON["machineID"] = machineID } + if let oneTimePassword = json["X-Apple-I-MD"] { formattedJSON["oneTimePassword"] = oneTimePassword } + if let routingInfo = json["X-Apple-I-MD-RINFO"] { formattedJSON["routingInfo"] = routingInfo } + + if v3 { + formattedJSON["deviceDescription"] = self.clientInfo! + formattedJSON["localUserID"] = self.mdLu! + formattedJSON["deviceUniqueIdentifier"] = self.deviceId! + + // Generate date stuff on client + let formatter = DateFormatter() + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.calendar = Calendar(identifier: .gregorian) + formatter.timeZone = TimeZone.current + formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'" + let dateString = formatter.string(from: Date()) + formattedJSON["date"] = dateString + formattedJSON["locale"] = Locale.current.identifier + formattedJSON["timeZone"] = TimeZone.current.abbreviation() + } else { + if let deviceDescription = json["X-MMe-Client-Info"] { formattedJSON["deviceDescription"] = deviceDescription } + if let localUserID = json["X-Apple-I-MD-LU"] { formattedJSON["localUserID"] = localUserID } + if let deviceUniqueIdentifier = json["X-Mme-Device-Id"] { formattedJSON["deviceUniqueIdentifier"] = deviceUniqueIdentifier } + + if let date = json["X-Apple-I-Client-Time"] { formattedJSON["date"] = date } + if let locale = json["X-Apple-Locale"] { formattedJSON["locale"] = locale } + if let timeZone = json["X-Apple-I-TimeZone"] { formattedJSON["timeZone"] = timeZone } + } + + if let response = response, + let version = response.value(forHTTPHeaderField: "Implementation-Version") { + print("Implementation-Version: \(version)") + } else { print("No Implementation-Version header") } + + print("Anisette used: \(formattedJSON)") + print("Original JSON: \(json)") + if let anisette = ALTAnisetteData(json: formattedJSON) { + print("Anisette is valid!") + self.finish(.success(anisette)) + } else { + print("Anisette is invalid!!!!") + if v3 { + throw OperationError.anisetteV3Error(message: "Invalid anisette (the returned data may not have all the required fields)") + } else { + throw OperationError.anisetteV1Error(message: "Invalid anisette (the returned data may not have all the required fields)") + } + } + } else { + if v3 { + throw OperationError.anisetteV3Error(message: "Invalid anisette (the returned data may not be in JSON)") + } else { + throw OperationError.anisetteV1Error(message: "Invalid anisette (the returned data may not be in JSON)") + } + } + } + + // MARK: - V1 + + func handleV1() { + print("Server is V1") + + if UserDefaults.shared.trustedServerURL == AnisetteManager.currentURLString { + print("Server has already been trusted, fetching anisette") + return self.fetchAnisetteV1() + } + + print("Alerting user about outdated server") + let alert = UIAlertController(title: "WARNING: Outdated anisette server", message: "We've detected you are using an older anisette server. Using this server has a higher likelihood of locking your account and causing other issues. Are you sure you want to continue?", preferredStyle: UIAlertController.Style.alert) + alert.addAction(UIAlertAction(title: "Continue", style: UIAlertAction.Style.destructive, handler: { action in + print("Fetching anisette via V1") + UserDefaults.shared.trustedServerURL = AnisetteManager.currentURLString + self.fetchAnisetteV1() + })) + alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel, handler: { action in + print("Cancelled anisette operation") + self.finish(.failure(OperationError.cancelled)) + })) + + let keyWindow = UIApplication.shared.windows.filter { $0.isKeyWindow }.first + + DispatchQueue.main.async { + if let presentingController = keyWindow?.rootViewController?.presentedViewController { + presentingController.present(alert, animated: true) + } else { + keyWindow?.rootViewController?.present(alert, animated: true) + } + } + } + + func fetchAnisetteV1() { + print("Fetching anisette V1") + URLSession.shared.dataTask(with: self.url!) { data, response, error in + do { + guard let data = data, error == nil else { throw OperationError.anisetteV1Error(message: "Unable to fetch data\(error != nil ? " (\(error!.localizedDescription))" : "")") } + + try self.extractAnisetteData(data, response as? HTTPURLResponse, v3: false) } catch let error as NSError { print("Failed to load: \(error.localizedDescription)") self.finish(.failure(error)) } - + }.resume() + } + + // MARK: - V3: PROVISIONING + + func provision() { + fetchClientInfo { + print("Getting provisioning URLs") + var request = self.buildAppleRequest(url: URL(string: "https://gsa.apple.com/grandslam/GsService2/lookup")!) + request.httpMethod = "GET" + URLSession.shared.dataTask(with: request) { data, response, error in + if let data = data, + let plist = try? PropertyListSerialization.propertyList(from: data, format: nil) as? Dictionary>, + let startProvisioningString = plist["urls"]?["midStartProvisioning"] as? String, + let startProvisioningURL = URL(string: startProvisioningString), + let endProvisioningString = plist["urls"]?["midFinishProvisioning"] as? String, + let endProvisioningURL = URL(string: endProvisioningString) { + self.startProvisioningURL = startProvisioningURL + self.endProvisioningURL = endProvisioningURL + print("startProvisioningURL: \(self.startProvisioningURL!.absoluteString)") + print("endProvisioningURL: \(self.endProvisioningURL!.absoluteString)") + print("Starting a provisioning session") + self.startProvisioningSession() + } else { + print("Apple didn't give valid URLs! Got response: \(String(data: data ?? Data("nothing".utf8), encoding: .utf8) ?? "not utf8")") + self.finish(.failure(OperationError.provisioningError(result: "Apple didn't give valid URLs. Please try again later", message: nil))) + } + }.resume() + } + } + + func startProvisioningSession() { + let provisioningSessionURL = self.url!.appendingPathComponent("v3").appendingPathComponent("provisioning_session") + var wsRequest = URLRequest(url: provisioningSessionURL) + wsRequest.timeoutInterval = 5 + self.socket = WebSocket(request: wsRequest) + self.socket.delegate = self + self.socket.connect() + } + + func didReceive(event: WebSocketEvent, client: WebSocket) { + switch event { + case .text(let string): + do { + if let json = try JSONSerialization.jsonObject(with: string.data(using: .utf8)!, options: []) as? [String: Any] { + guard let result = json["result"] as? String else { + print("The server didn't give us a result") + client.disconnect(closeCode: 0) + self.finish(.failure(OperationError.provisioningError(result: "The server didn't give us a result", message: nil))) + return + } + print("Received result: \(result)") + switch result { + case "GiveIdentifier": + print("Giving identifier") + client.json(["identifier": Keychain.shared.identifier!]) + + case "GiveStartProvisioningData": + print("Getting start provisioning data") + let body = [ + "Header": [String: Any](), + "Request": [String: Any](), + ] + var request = self.buildAppleRequest(url: self.startProvisioningURL!) + request.httpMethod = "POST" + request.httpBody = try! PropertyListSerialization.data(fromPropertyList: body, format: .xml, options: 0) + URLSession.shared.dataTask(with: request) { data, response, error in + if let data = data, + let plist = try? PropertyListSerialization.propertyList(from: data, format: nil) as? Dictionary>, + let spim = plist["Response"]?["spim"] as? String { + print("Giving start provisioning data") + client.json(["spim": spim]) + } else { + print("Apple didn't give valid start provisioning data! Got response: \(String(data: data ?? Data("nothing".utf8), encoding: .utf8) ?? "not utf8")") + client.disconnect(closeCode: 0) + self.finish(.failure(OperationError.provisioningError(result: "Apple didn't give valid start provisioning data. Please try again later", message: nil))) + } + }.resume() + + case "GiveEndProvisioningData": + print("Getting end provisioning data") + guard let cpim = json["cpim"] as? String else { + print("The server didn't give us a cpim") + client.disconnect(closeCode: 0) + self.finish(.failure(OperationError.provisioningError(result: "The server didn't give us a cpim", message: nil))) + return + } + let body = [ + "Header": [String: Any](), + "Request": [ + "cpim": cpim, + ], + ] + var request = self.buildAppleRequest(url: self.endProvisioningURL!) + request.httpMethod = "POST" + request.httpBody = try! PropertyListSerialization.data(fromPropertyList: body, format: .xml, options: 0) + URLSession.shared.dataTask(with: request) { data, response, error in + if let data = data, + let plist = try? PropertyListSerialization.propertyList(from: data, format: nil) as? Dictionary>, + let ptm = plist["Response"]?["ptm"] as? String, + let tk = plist["Response"]?["tk"] as? String { + print("Giving end provisioning data") + client.json(["ptm": ptm, "tk": tk]) + } else { + print("Apple didn't give valid end provisioning data! Got response: \(String(data: data ?? Data("nothing".utf8), encoding: .utf8) ?? "not utf8")") + client.disconnect(closeCode: 0) + self.finish(.failure(OperationError.provisioningError(result: "Apple didn't give valid end provisioning data. Please try again later", message: nil))) + } + }.resume() + + case "ProvisioningSuccess": + print("Provisioning succeeded!") + client.disconnect(closeCode: 0) + guard let adiPb = json["adi_pb"] as? String else { + print("The server didn't give us an adi.pb file") + self.finish(.failure(OperationError.provisioningError(result: "The server didn't give us an adi.pb file", message: nil))) + return + } + Keychain.shared.adiPb = adiPb + self.fetchAnisetteV3(Keychain.shared.identifier!, Keychain.shared.adiPb!) + + default: + if result.contains("Error") || result.contains("Invalid") || result == "ClosingPerRequest" || result == "Timeout" || result == "TextOnly" { + print("Failing because of \(result)") + self.finish(.failure(OperationError.provisioningError(result: result, message: json["message"] as? String))) + } + } + } + } catch let error as NSError { + print("Failed to handle text: \(error.localizedDescription)") + self.finish(.failure(OperationError.provisioningError(result: error.localizedDescription, message: nil))) + } + + case .connected: + print("Connected") + + case .disconnected(let string, let code): + print("Disconnected: \(code); \(string)") + + case .error(let error): + print("Got error: \(String(describing: error))") + + default: + print("Unknown event: \(event)") + } + } + + func buildAppleRequest(url: URL) -> URLRequest { + var request = URLRequest(url: url) + request.setValue(self.clientInfo!, forHTTPHeaderField: "X-Mme-Client-Info") + request.setValue(self.userAgent!, forHTTPHeaderField: "User-Agent") + request.setValue("text/x-xml-plist", forHTTPHeaderField: "Content-Type") + request.setValue("*/*", forHTTPHeaderField: "Accept") + + request.setValue(self.mdLu!, forHTTPHeaderField: "X-Apple-I-MD-LU") + request.setValue(self.deviceId!, forHTTPHeaderField: "X-Mme-Device-Id") + + let formatter = DateFormatter() + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.calendar = Calendar(identifier: .gregorian) + formatter.timeZone = TimeZone(identifier: "UTC") + formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'" + let dateString = formatter.string(from: Date()) + request.setValue(dateString, forHTTPHeaderField: "X-Apple-I-Client-Time") + request.setValue(Locale.current.identifier, forHTTPHeaderField: "X-Apple-Locale") + request.setValue(TimeZone.current.abbreviation(), forHTTPHeaderField: "X-Apple-I-TimeZone") + return request + } + + // MARK: - V3: FETCHING + + func fetchClientInfo(_ callback: @escaping () -> Void) { + if self.clientInfo != nil && + self.userAgent != nil && + self.mdLu != nil && + self.deviceId != nil && + Keychain.shared.identifier != nil { + print("Skipping client_info fetch since all the properties we need aren't nil") + return callback() + } + print("Trying to get client_info") + let clientInfoURL = self.url!.appendingPathComponent("v3").appendingPathComponent("client_info") + URLSession.shared.dataTask(with: clientInfoURL) { data, response, error in + do { + guard let data = data, error == nil else { + return self.finish(.failure(OperationError.anisetteV3Error(message: "Couldn't fetch client info. The server may be down\(error != nil ? " (\(error!.localizedDescription))" : "")"))) + } + + if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: String] { + if let clientInfo = json["client_info"] { + print("Server is V3") + + self.clientInfo = clientInfo + self.userAgent = json["user_agent"]! + print("Client-Info: \(self.clientInfo!)") + print("User-Agent: \(self.userAgent!)") + + if Keychain.shared.identifier == nil { + print("Generating identifier") + var bytes = [Int8](repeating: 0, count: 16) + let status = SecRandomCopyBytes(kSecRandomDefault, bytes.count, &bytes) + + if status != errSecSuccess { + print("ERROR GENERATING IDENTIFIER!!! \(status)") + return self.finish(.failure(OperationError.provisioningError(result: "Couldn't generate identifier", message: nil))) + } + + Keychain.shared.identifier = Data(bytes: &bytes, count: bytes.count).base64EncodedString() + } + + let decoded = Data(base64Encoded: Keychain.shared.identifier!)! + self.mdLu = decoded.sha256().hexEncodedString() + print("X-Apple-I-MD-LU: \(self.mdLu!)") + let uuid: UUID = decoded.object() + self.deviceId = uuid.uuidString.uppercased() + print("X-Mme-Device-Id: \(self.deviceId!)") + + callback() + } else { self.handleV1() } + } else { self.finish(.failure(OperationError.anisetteV3Error(message: "Couldn't fetch client info. The returned data may not be in JSON"))) } + } catch let error as NSError { + print("Failed to load: \(error.localizedDescription)") + self.handleV1() + } + }.resume() + } + + func fetchAnisetteV3(_ identifier: String, _ adiPb: String) { + fetchClientInfo { + print("Fetching anisette V3") + var request = URLRequest(url: self.url!.appendingPathComponent("v3").appendingPathComponent("get_headers")) + request.httpMethod = "POST" + request.httpBody = try! JSONSerialization.data(withJSONObject: [ + "identifier": identifier, + "adi_pb": adiPb + ], options: []) + request.setValue("application/json", forHTTPHeaderField: "Content-Type") + URLSession.shared.dataTask(with: request) { data, response, error in + do { + guard let data = data, error == nil else { throw OperationError.anisetteV3Error(message: "Couldn't fetch anisette") } + + try self.extractAnisetteData(data, response as? HTTPURLResponse, v3: true) + } catch let error as NSError { + print("Failed to load: \(error.localizedDescription)") + self.finish(.failure(error)) + } + }.resume() } - - task.resume() } } + +extension WebSocket { + func json(_ dictionary: [String: String]) { + let data = try! JSONSerialization.data(withJSONObject: dictionary, options: []) + self.write(string: String(data: data, encoding: .utf8)!) + } +} + +extension Data { + // https://stackoverflow.com/a/25391020 + func sha256() -> Data { + var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH)) + self.withUnsafeBytes { + _ = CC_SHA256($0.baseAddress, CC_LONG(self.count), &hash) + } + return Data(hash) + } + + // https://stackoverflow.com/a/40089462 + func hexEncodedString() -> String { + return self.map { String(format: "%02hhX", $0) }.joined() + } + + // https://stackoverflow.com/a/59127761 + func object() -> T { self.withUnsafeBytes { $0.load(as: T.self) } } +} diff --git a/AltStore/Operations/OperationError.swift b/AltStore/Operations/OperationError.swift index 8de1f0ff..7829502a 100644 --- a/AltStore/Operations/OperationError.swift +++ b/AltStore/Operations/OperationError.swift @@ -34,6 +34,10 @@ enum OperationError: LocalizedError case openAppFailed(name: String) case missingAppGroup + case anisetteV1Error(message: String) + case provisioningError(result: String, message: String?) + case anisetteV3Error(message: String) + var failureReason: String? { switch self { case .unknown: return NSLocalizedString("An unknown error occured.", comment: "") @@ -49,6 +53,9 @@ enum OperationError: LocalizedError case .openAppFailed(let name): return String(format: NSLocalizedString("SideStore was denied permission to launch %@.", comment: ""), name) case .missingAppGroup: return NSLocalizedString("SideStore's shared app group could not be found.", comment: "") case .maximumAppIDLimitReached: return NSLocalizedString("Cannot register more than 10 App IDs.", comment: "") + case .anisetteV1Error(let message): return String(format: NSLocalizedString("An error occurred when getting anisette data from a V1 server: %@. Try using another anisette server.", comment: ""), message) + case .provisioningError(let result, let message): return String(format: NSLocalizedString("An error occurred when provisioning: %@%@. Please try again. If the issue persists, report it on GitHub Issues!", comment: ""), result, message != nil ? (" (" + message! + ")") : "") + case .anisetteV3Error(let message): return String(format: NSLocalizedString("An error occurred when getting anisette data from a V3 server: %@. Please try again. If the issue persists, report it on GitHub Issues!", comment: ""), message) } } diff --git a/AltStore/Settings/Settings.storyboard b/AltStore/Settings/Settings.storyboard index ccf9515c..42ec9e33 100644 --- a/AltStore/Settings/Settings.storyboard +++ b/AltStore/Settings/Settings.storyboard @@ -21,7 +21,7 @@