mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-17 21:12:01 +03:00
Transfer signing info from mac to device when installing
This commit is contained in:
committed by
Kabir Oberai
Unverified
parent
92a0108c53
commit
68f2760372
@@ -81,14 +81,6 @@ final class Installer {
|
||||
}
|
||||
}
|
||||
|
||||
struct DeviceInfoError: LocalizedError {
|
||||
let info: String
|
||||
|
||||
var errorDescription: String? {
|
||||
"Device info: \(info)"
|
||||
}
|
||||
}
|
||||
|
||||
enum Message {
|
||||
case pairDevice
|
||||
case unlockDevice
|
||||
@@ -277,28 +269,27 @@ final class Installer {
|
||||
) {
|
||||
guard self.updateStage(to: "Preparing device") else { return }
|
||||
|
||||
let pairingKeys: Data
|
||||
|
||||
do {
|
||||
guard let pairingKeys = try fetchPairingKeys()
|
||||
guard let _pairingKeys = try fetchPairingKeys()
|
||||
else { return } // nil: user cancelled
|
||||
try Superconfig(
|
||||
udid: udid,
|
||||
pairingKeys: pairingKeys,
|
||||
deviceInfo: deviceInfo,
|
||||
preferredTeamID: team.id.rawValue,
|
||||
appleID: appleID,
|
||||
token: token
|
||||
).save(inAppDir: appDir)
|
||||
pairingKeys = _pairingKeys
|
||||
} catch {
|
||||
return completion(.failure(error))
|
||||
}
|
||||
|
||||
let signingInfoManager = KeyValueSigningInfoManager(
|
||||
storage: KeychainStorage(service: "com.kabiroberai.Supercharge-Installer.credentials")
|
||||
)
|
||||
|
||||
let context: SigningContext
|
||||
do {
|
||||
context = try SigningContext(
|
||||
udid: udid,
|
||||
teamID: team.id,
|
||||
client: client,
|
||||
signingInfoManager: MemoryBackedSigningInfoManager(),
|
||||
signingInfoManager: signingInfoManager,
|
||||
platform: .iOS
|
||||
)
|
||||
} catch {
|
||||
@@ -312,7 +303,20 @@ final class Installer {
|
||||
},
|
||||
progress: { progress in
|
||||
_ = self.updateProgress(to: progress, ignoreCancellation: true)
|
||||
}, completion: { result in
|
||||
},
|
||||
didProvision: {
|
||||
let info = try context.signingInfoManager.info(forTeamID: context.teamID)
|
||||
try Superconfig(
|
||||
udid: self.udid,
|
||||
pairingKeys: pairingKeys,
|
||||
deviceInfo: deviceInfo,
|
||||
preferredTeamID: team.id.rawValue,
|
||||
preferredSigningInfo: info,
|
||||
appleID: self.appleID,
|
||||
token: token
|
||||
).save(inAppDir: appDir)
|
||||
},
|
||||
completion: { result in
|
||||
guard result.get(withErrorHandler: self.completion) != nil else { return }
|
||||
self.packageAndInstall(
|
||||
deviceInfo: deviceInfo,
|
||||
@@ -352,8 +356,6 @@ final class Installer {
|
||||
let appDir = payload.implicitContents.first(where: { $0.pathExtension == "app" })
|
||||
else { return self.completion(.failure(Error.appExtractionFailed)) }
|
||||
|
||||
return completion(.failure(DeviceInfoError(info: DeviceInfo.deviceDesc())))
|
||||
|
||||
guard let deviceInfo = DeviceInfo.current() else {
|
||||
return completion(.failure(Error.deviceInfoFetchFailed))
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class SRPClient {
|
||||
final class SRPClient {
|
||||
|
||||
let raw = srp_client_create()
|
||||
deinit { srp_client_free(raw) }
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public class Certificate: Decodable {
|
||||
/// A certificate in DER format
|
||||
public final class Certificate: Codable {
|
||||
|
||||
public enum Error: Swift.Error {
|
||||
case invalidCertificate
|
||||
@@ -16,18 +17,13 @@ public class Certificate: Decodable {
|
||||
|
||||
let raw: certificate_t
|
||||
|
||||
private static func certificate(from data: Data) -> certificate_t? {
|
||||
data.withUnsafeBytes {
|
||||
guard let base = $0.baseAddress else { return nil }
|
||||
return certificate_create_from_data(base, $0.count)
|
||||
}
|
||||
}
|
||||
|
||||
public init(data: Data) throws {
|
||||
guard let certificate = Self.certificate(from: data) else {
|
||||
throw Error.invalidCertificate
|
||||
self.raw = try data.withUnsafeBytes { buf -> certificate_t in
|
||||
guard let base = buf.baseAddress,
|
||||
let cert = certificate_create_from_data(base, buf.count)
|
||||
else { throw Error.invalidCertificate }
|
||||
return cert
|
||||
}
|
||||
self.raw = certificate
|
||||
}
|
||||
|
||||
public init(contentsOf url: URL) throws {
|
||||
@@ -36,13 +32,15 @@ public class Certificate: Decodable {
|
||||
self.raw = certificate
|
||||
}
|
||||
|
||||
public required init(from decoder: Decoder) throws {
|
||||
public required convenience init(from decoder: Decoder) throws {
|
||||
let container = try decoder.singleValueContainer()
|
||||
let data = try container.decode(Data.self)
|
||||
guard let certificate = Self.certificate(from: data) else {
|
||||
throw Error.invalidCertificate
|
||||
}
|
||||
self.raw = certificate
|
||||
try self.init(data: data)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
try container.encode(data())
|
||||
}
|
||||
|
||||
deinit {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct PrivateKey {
|
||||
public struct PrivateKey: Codable {
|
||||
public let data: Data
|
||||
|
||||
public init(data: Data) {
|
||||
@@ -32,7 +32,7 @@ public struct CSR {
|
||||
}
|
||||
}
|
||||
|
||||
public class Keypair {
|
||||
public final class Keypair {
|
||||
|
||||
public enum Error: Swift.Error {
|
||||
case couldNotCreate
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public class Mobileprovision: Decodable {
|
||||
public final class Mobileprovision: Decodable {
|
||||
|
||||
public enum Error: Swift.Error {
|
||||
case invalidProfile
|
||||
|
||||
@@ -46,8 +46,15 @@ public struct Signer {
|
||||
provisioningDict: [URL: ProvisioningInfo],
|
||||
status: @escaping (String) -> Void,
|
||||
progress: @escaping (Double) -> Void,
|
||||
didProvision: @escaping () throws -> Void,
|
||||
completion: @escaping (Result<(), Swift.Error>) -> Void
|
||||
) {
|
||||
do {
|
||||
try didProvision()
|
||||
} catch {
|
||||
return completion(.failure(error))
|
||||
}
|
||||
|
||||
for (url, info) in provisioningDict {
|
||||
let infoPlist = url.appendingPathComponent("Info.plist")
|
||||
guard let dict = NSMutableDictionary(contentsOf: infoPlist) else {
|
||||
@@ -86,6 +93,7 @@ public struct Signer {
|
||||
app: URL,
|
||||
status: @escaping (String) -> Void,
|
||||
progress: @escaping (Double) -> Void,
|
||||
didProvision: @escaping () throws -> Void = {},
|
||||
completion: @escaping (Result<(), Swift.Error>) -> Void
|
||||
) {
|
||||
status(NSLocalizedString("signer.provisioning", value: "Provisioning", comment: ""))
|
||||
@@ -97,6 +105,7 @@ public struct Signer {
|
||||
provisioningDict: response.provisioningDict,
|
||||
status: status,
|
||||
progress: progress,
|
||||
didProvision: didProvision,
|
||||
completion: completion
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct SigningInfo {
|
||||
public struct SigningInfo: Codable {
|
||||
public let privateKey: PrivateKey
|
||||
public let certificate: Certificate
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public struct KeyValueSigningInfoManager: SigningInfoManager {
|
||||
}
|
||||
|
||||
private func key(_ teamID: DeveloperServicesTeam.ID, _ keyType: KeyType) -> String {
|
||||
"\(teamID).\(keyType.rawValue)"
|
||||
"\(teamID.rawValue).\(keyType.rawValue)"
|
||||
}
|
||||
|
||||
public let storage: KeyValueStorage
|
||||
|
||||
Reference in New Issue
Block a user