mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-07 15:46:11 +03:00
gsa: update user agent
This commit is contained in:
@@ -4,7 +4,7 @@ import ConcurrencyExtras
|
||||
import Dependencies
|
||||
|
||||
public protocol RawADIProvider: Sendable {
|
||||
func clientInfo() async throws -> String
|
||||
func clientInfo() async throws -> ClientInfoWithUserAgent
|
||||
|
||||
func startProvisioning(
|
||||
spim: Data,
|
||||
@@ -18,6 +18,11 @@ public protocol RawADIProvider: Sendable {
|
||||
) async throws -> (machineID: Data, otp: Data)
|
||||
}
|
||||
|
||||
public struct ClientInfoWithUserAgent: Sendable {
|
||||
public let clientInfo: String
|
||||
public let akdUserAgent: String
|
||||
}
|
||||
|
||||
private struct UnimplementedRawADIProvider: RawADIProvider {
|
||||
func startProvisioning(
|
||||
spim: Data,
|
||||
@@ -36,8 +41,8 @@ private struct UnimplementedRawADIProvider: RawADIProvider {
|
||||
return try await closure(userID, &routingInfo, provisioningInfo)
|
||||
}
|
||||
|
||||
func clientInfo() async throws -> String {
|
||||
let closure: () async throws -> String = unimplemented()
|
||||
func clientInfo() async throws -> ClientInfoWithUserAgent {
|
||||
let closure: () async throws -> ClientInfoWithUserAgent = unimplemented()
|
||||
return try await closure()
|
||||
}
|
||||
}
|
||||
@@ -80,7 +85,7 @@ public struct ADIDataProvider: AnisetteDataProvider {
|
||||
private let localUserUID: UUID
|
||||
private let localUserID: String
|
||||
|
||||
private let _clientInfo = LockIsolated<String?>(nil)
|
||||
private let _clientInfo = LockIsolated<ClientInfoWithUserAgent?>(nil)
|
||||
|
||||
public init() {
|
||||
@Dependency(\.keyValueStorage) var storage
|
||||
@@ -145,7 +150,7 @@ public struct ADIDataProvider: AnisetteDataProvider {
|
||||
return encoder
|
||||
}()
|
||||
|
||||
private func clientInfo() async throws -> String {
|
||||
private func clientInfo() async throws -> ClientInfoWithUserAgent {
|
||||
if let clientInfo = _clientInfo.value { return clientInfo }
|
||||
let clientInfo = try await rawProvider.clientInfo()
|
||||
_clientInfo.setValue(clientInfo)
|
||||
@@ -275,9 +280,11 @@ public struct ADIDataProvider: AnisetteDataProvider {
|
||||
}
|
||||
|
||||
public func deviceInfo() async throws -> DeviceInfo {
|
||||
DeviceInfo(
|
||||
let clientInfo = try await clientInfo()
|
||||
return DeviceInfo(
|
||||
deviceID: localUserUID.uuidString,
|
||||
clientInfo: try await clientInfo(),
|
||||
clientInfo: clientInfo.clientInfo,
|
||||
akdUserAgent: clientInfo.akdUserAgent,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import Foundation
|
||||
public struct DeviceInfo: Codable, Sendable {
|
||||
public static let xcodeVersionKey = "X-Xcode-Version"
|
||||
public static let xcodeVersion = "26.5 (17F42)"
|
||||
public static let akdUserAgent = "akd/1.0 CFNetwork/808.1.4"
|
||||
|
||||
public static let deviceIDKey = "X-Mme-Device-Id"
|
||||
public let deviceID: String
|
||||
@@ -11,6 +10,8 @@ public struct DeviceInfo: Codable, Sendable {
|
||||
public static let clientInfoKey = "X-MMe-Client-Info"
|
||||
public let clientInfo: String
|
||||
|
||||
public let akdUserAgent: String
|
||||
|
||||
public var dictionary: [String: String] {
|
||||
[
|
||||
Self.clientInfoKey: clientInfo,
|
||||
|
||||
@@ -27,15 +27,19 @@ struct OmnisetteADIProvider: RawADIProvider {
|
||||
return encoder
|
||||
}()
|
||||
|
||||
func clientInfo() async throws -> String {
|
||||
func clientInfo() async throws -> ClientInfoWithUserAgent {
|
||||
struct ClientInfo: Decodable {
|
||||
let clientInfo: String
|
||||
let userAgent: String
|
||||
}
|
||||
let body = try await client.makeRequest(
|
||||
HTTPRequest(url: url.appendingPathComponent("v3/client_info"))
|
||||
).body
|
||||
let clientInfo = try Self.decoder.decode(ClientInfo.self, from: body)
|
||||
return clientInfo.clientInfo
|
||||
return ClientInfoWithUserAgent(
|
||||
clientInfo: clientInfo.clientInfo,
|
||||
akdUserAgent: clientInfo.userAgent,
|
||||
)
|
||||
}
|
||||
|
||||
func startProvisioning(spim: Data, userID: UUID) async throws -> (RawADIProvisioningSession, Data) {
|
||||
|
||||
@@ -31,7 +31,7 @@ actor GrandSlamLookupManager {
|
||||
|
||||
var request = HTTPRequest(url: Self.lookupURL)
|
||||
request.headerFields = [
|
||||
.userAgent: DeviceInfo.akdUserAgent,
|
||||
.userAgent: deviceInfo.akdUserAgent,
|
||||
.init(AnisetteData.iLocaleKey)!: Locale.current.identifier,
|
||||
.init(AnisetteData.timeZoneKey)!: TimeZone.current.identifier,
|
||||
.init("X-Apple-I-TimeZone-Offset")!: "\(TimeZone.current.secondsFromGMT())"
|
||||
|
||||
@@ -71,7 +71,7 @@ extension GrandSlamOperationRequest {
|
||||
|
||||
func configure(request: inout HTTPRequest, anisetteData: AnisetteData) {
|
||||
request.headerFields[.accept] = "*/*"
|
||||
request.headerFields[.userAgent] = DeviceInfo.akdUserAgent
|
||||
request.headerFields[.userAgent] = anisetteData.deviceInfo.akdUserAgent
|
||||
}
|
||||
|
||||
func method(anisetteData: AnisetteData) -> GrandSlamMethod {
|
||||
|
||||
@@ -20,7 +20,7 @@ extension GrandSlamTwoFactorRequest {
|
||||
func configure(request: inout HTTPRequest, anisetteData: AnisetteData) {
|
||||
request.headerFields[.accept] = "application/x-buddyml"
|
||||
request.headerFields[.contentType] = "application/x-plist"
|
||||
request.headerFields[.userAgent] = DeviceInfo.akdUserAgent
|
||||
request.headerFields[.userAgent] = anisetteData.deviceInfo.akdUserAgent
|
||||
request.headerFields[.init("X-Apple-App-Info")!] = "com.apple.gs.xcode.auth"
|
||||
request.headerFields[.init(DeviceInfo.xcodeVersionKey)!] = DeviceInfo.xcodeVersion
|
||||
request.headerFields[.init("X-Apple-Identity-Token")!] = loginData.identityToken
|
||||
|
||||
Reference in New Issue
Block a user