mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-08 22:33:26 +01:00
fix: Account exporting/importing
This commit is contained in:
@@ -10,6 +10,8 @@ import UIKit
|
||||
import Roxas
|
||||
import minimuxer
|
||||
import WidgetKit
|
||||
|
||||
import AltSign
|
||||
import AltStoreCore
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
@@ -70,7 +72,9 @@ final class LaunchViewController: UIViewController, UIDocumentPickerDelegate {
|
||||
}
|
||||
|
||||
#if !targetEnvironment(simulator)
|
||||
guard let pf = PairingFileManager.shared.fetchPairingFile(presentingVC: self) else {
|
||||
|
||||
detectAndImportAccountFile()
|
||||
guard let pf = fetchPairingFile() else {
|
||||
displayError("Device pairing file not found.")
|
||||
return
|
||||
}
|
||||
@@ -102,6 +106,11 @@ final class LaunchViewController: UIViewController, UIDocumentPickerDelegate {
|
||||
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
||||
let url = urls[0]
|
||||
let isSecuredURL = url.startAccessingSecurityScopedResource() == true
|
||||
defer {
|
||||
if (isSecuredURL) {
|
||||
url.stopAccessingSecurityScopedResource()
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
let data = try Data(contentsOf: url)
|
||||
@@ -114,14 +123,68 @@ final class LaunchViewController: UIViewController, UIDocumentPickerDelegate {
|
||||
} catch {
|
||||
displayError("Unable to read pairing file")
|
||||
}
|
||||
|
||||
if isSecuredURL { url.stopAccessingSecurityScopedResource() }
|
||||
controller.dismiss(animated: true)
|
||||
|
||||
controller.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
|
||||
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
|
||||
displayError("Choosing a pairing file was cancelled. Please re-open the app and try again.")
|
||||
}
|
||||
|
||||
func start_minimuxer_threads(_ pairing_file: String) {
|
||||
target_minimuxer_address()
|
||||
let documentsDirectory = FileManager.default.documentsDirectory.absoluteString
|
||||
do {
|
||||
// enable minimuxer console logging only if enabled in settings
|
||||
let isMinimuxerConsoleLoggingEnabled = UserDefaults.standard.isMinimuxerConsoleLoggingEnabled
|
||||
try minimuxer.startWithLogger(pairing_file, documentsDirectory, isMinimuxerConsoleLoggingEnabled)
|
||||
} catch {
|
||||
try! FileManager.default.removeItem(at: FileManager.default.documentsDirectory.appendingPathComponent("\(pairingFileName)"))
|
||||
displayError("minimuxer failed to start, please restart SideStore. \((error as? LocalizedError)?.failureReason ?? "UNKNOWN ERROR!!!!!! REPORT TO GITHUB ISSUES!")")
|
||||
}
|
||||
start_auto_mounter(documentsDirectory)
|
||||
// Create destinationViewController now so view controllers can register for receiving Notifications.
|
||||
self.destinationViewController = self.storyboard!.instantiateViewController(withIdentifier: "tabBarController") as? TabBarController
|
||||
}
|
||||
|
||||
func importAccountAtFile(_ file: URL, remove: Bool = false) {
|
||||
_ = file.startAccessingSecurityScopedResource()
|
||||
defer { file.stopAccessingSecurityScopedResource() }
|
||||
guard let accountD = try? Data(contentsOf: file) else {
|
||||
let toastView = ToastView(text: NSLocalizedString("Could not read data from file!", comment: ""), detailText: "\(file)")
|
||||
return toastView.show(in: self)
|
||||
}
|
||||
guard let account = try? Foundation.JSONDecoder().decode(ImportedAccount.self, from: accountD) else {
|
||||
let toastView = ToastView(text: NSLocalizedString("Could not parse data from file!", comment: ""), detailText: "\(file)")
|
||||
return toastView.show(in: self)
|
||||
}
|
||||
print("We want to import this account probably: \(account)")
|
||||
if remove {
|
||||
try? FileManager.default.removeItem(at: file)
|
||||
}
|
||||
Keychain.shared.appleIDEmailAddress = account.email
|
||||
Keychain.shared.appleIDPassword = account.password
|
||||
Keychain.shared.adiPb = account.adiPB
|
||||
Keychain.shared.identifier = account.local_user
|
||||
if let altCert = ALTCertificate(p12Data: account.cert, password: account.certpass) {
|
||||
Keychain.shared.signingCertificate = altCert.encryptedP12Data(withPassword: "")!
|
||||
Keychain.shared.signingCertificatePassword = account.certpass
|
||||
let toastView = ToastView(text: NSLocalizedString("Successfully imported '\(account.email)'!", comment: ""), detailText: "SideStore should be fully operational!")
|
||||
return toastView.show(in: self)
|
||||
} else {
|
||||
let toastView = ToastView(text: NSLocalizedString("Failed to import account certificate!", comment: ""), detailText: "Failed to create ALTCertificate. Check if the password is correct. Still imported account/adi.pb details!")
|
||||
return toastView.show(in: self)
|
||||
}
|
||||
}
|
||||
|
||||
func detectAndImportAccountFile() {
|
||||
let accountFileURL = FileManager.default.documentsDirectory.appendingPathComponent("Account.sideconf")
|
||||
#if !DEBUG
|
||||
importAccountAtFile(accountFileURL, remove: true)
|
||||
#else
|
||||
importAccountAtFile(accountFileURL)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
extension LaunchViewController {
|
||||
|
||||
Reference in New Issue
Block a user