Files
SideStore/SideStoreApp/Sources/SideStoreAppKit/Operations/FetchAnisetteDataOperation.swift

59 lines
2.1 KiB
Swift
Raw Normal View History

//
// FetchAnisetteDataOperation.swift
// AltStore
//
// Created by Riley Testut on 1/7/20.
// Copyright © 2020 Riley Testut. All rights reserved.
//
import Foundation
import AltSign
2023-03-01 00:48:36 -05:00
import SideStoreCore
2023-03-01 14:36:52 -05:00
import RoxasUIKit
@objc(FetchAnisetteDataOperation)
2023-03-01 00:48:36 -05:00
final class FetchAnisetteDataOperation: ResultOperation<ALTAnisetteData> {
let context: OperationContext
2023-03-01 00:48:36 -05:00
init(context: OperationContext) {
self.context = context
}
2023-03-01 00:48:36 -05:00
override func main() {
super.main()
2023-03-01 00:48:36 -05:00
if let error = context.error {
finish(.failure(error))
return
}
2023-03-01 00:48:36 -05:00
let url = AnisetteManager.currentURL
DLOG("Anisette URL: %@", url.absoluteString)
2023-03-01 00:48:36 -05:00
let task = URLSession.shared.dataTask(with: url) { data, _, error in
guard let data = data, error == nil else { return }
2023-03-01 00:48:36 -05:00
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
2023-03-01 00:48:36 -05:00
// 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"]
2023-03-01 00:48:36 -05:00
if let anisette = ALTAnisetteData(json: formattedJSON) {
DLOG("Anisette used: %@", formattedJSON)
self.finish(.success(anisette))
}
}
} catch let error as NSError {
print("Failed to load: \(error.localizedDescription)")
self.finish(.failure(error))
}
}
2023-03-01 00:48:36 -05:00
task.resume()
}
}