Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Sources/XKit/DeveloperServices/DeveloperServicesClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public struct DeveloperServicesClient: Sendable {
}
}

@Dependency(\.deviceInfoProvider) var deviceInfoProvider
@Dependency(\.anisetteDataProvider) var anisetteDataProvider
@Dependency(\.httpClient) var httpClient

Expand All @@ -76,8 +75,6 @@ public struct DeveloperServicesClient: Sendable {
throw Error.malformedRequest
}

let deviceInfo = try deviceInfoProvider.fetch()

var httpRequest = HTTPRequest(method: .post, url: url)
let acceptedLanguages = Locale.preferredLanguages.joined(separator: ", ")

Expand All @@ -88,8 +85,6 @@ public struct DeveloperServicesClient: Sendable {
request.methodOverride.map { httpRequest.headerFields[.init("X-HTTP-Method-Override")!] = $0 }

httpRequest.headerFields[.init(DeviceInfo.xcodeVersionKey)!] = DeviceInfo.xcodeVersion
httpRequest.headerFields[.init(DeviceInfo.clientInfoKey)!] = deviceInfo.clientInfo.clientString
httpRequest.headerFields[.init(DeviceInfo.deviceIDKey)!] = deviceInfo.deviceID

httpRequest.headerFields[.init("X-Apple-I-Identity-Id")!] = loginToken.adsid
httpRequest.headerFields[.init("X-Apple-App-Info")!] = AppTokenKey.xcode.rawValue
Expand All @@ -103,8 +98,6 @@ public struct DeveloperServicesClient: Sendable {

let (_, data) = try await httpClient.makeRequest(httpRequest, body: body)

// String(data: data, encoding: .utf8).map { print("\(url): \($0)") }

let decoded: R.Response = try request.apiVersion.decode(response: data)

return try await request.parse(decoded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public struct XcodeAuthData: Sendable {
}

public struct DeveloperAPIXcodeAuthMiddleware: ClientMiddleware {
@Dependency(\.deviceInfoProvider) private var deviceInfoProvider
@Dependency(\.anisetteDataProvider) private var anisetteDataProvider

public var authData: XcodeAuthData
Expand All @@ -130,7 +129,7 @@ public struct DeveloperAPIXcodeAuthMiddleware: ClientMiddleware {
) async throws -> (HTTPResponse, HTTPBody?) {
var request = request

let deviceInfo = try deviceInfoProvider.fetch()
let anisetteData = try await anisetteDataProvider.fetchAnisetteData()

// General
request.headerFields[.acceptLanguage] = Locale.preferredLanguages.joined(separator: ", ")
Expand All @@ -142,17 +141,12 @@ public struct DeveloperAPIXcodeAuthMiddleware: ClientMiddleware {
request.headerFields[.userAgent] = "Xcode"
request.headerFields[.init(DeviceInfo.xcodeVersionKey)!] = DeviceInfo.xcodeVersion

// MobileMe identity
request.headerFields[.init(DeviceInfo.clientInfoKey)!] = deviceInfo.clientInfo.clientString
request.headerFields[.init(DeviceInfo.deviceIDKey)!] = deviceInfo.deviceID

// GrandSlam authentication
request.headerFields[.init("X-Apple-App-Info")!] = AppTokenKey.xcode.rawValue
request.headerFields[.init("X-Apple-I-Identity-Id")!] = authData.loginToken.adsid
request.headerFields[.init("X-Apple-GS-Token")!] = authData.loginToken.token

// Anisette
let anisetteData = try await anisetteDataProvider.fetchAnisetteData()
for (key, value) in anisetteData.dictionary {
request.headerFields[.init(key)!] = value
}
Expand Down
32 changes: 16 additions & 16 deletions Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ public protocol RawADIProvider: Sendable {
) async throws -> (machineID: Data, otp: Data)
}

extension RawADIProvider {
public func clientInfo() async throws -> String {
// Looks like Apple detects attempts to use a macOS client string on Windows :/
"""
<PC> <Windows;6.2(0,0);9200> <com.apple.AuthKitWin/1 (com.apple.iCloud/7.21)>
"""
}
}

private struct UnimplementedRawADIProvider: RawADIProvider {
func startProvisioning(
spim: Data,
Expand All @@ -44,6 +35,11 @@ private struct UnimplementedRawADIProvider: RawADIProvider {
let closure: (UUID, inout UInt64, Data) async throws -> (Data, Data) = unimplemented()
return try await closure(userID, &routingInfo, provisioningInfo)
}

func clientInfo() async throws -> String {
let closure: () async throws -> String = unimplemented()
return try await closure()
}
}

private enum RawADIProviderDependencyKey: DependencyKey {
Expand Down Expand Up @@ -179,15 +175,12 @@ public struct ADIDataProvider: AnisetteDataProvider {
]
request.headerFields[.init("X-MMe-Country")!] = Locale.current.region?.identifier

request.headerFields[.init(DeviceInfo.clientInfoKey)!] = try await clientInfo()
request.headerFields[.init(DeviceInfo.deviceIDKey)!] = self.localUserUID.uuidString
// request.headers[DeviceInfo.clientInfoKey] = self.deviceInfo.clientInfo.clientString
// self.deviceInfo.dictionary.forEach { request.headers[$0] = $1 }
for (key, value) in try await deviceInfo().dictionary {
request.headerFields[.init(key)!] = value
}

let (_, response) = try await self.httpClient.makeRequest(request, body: body)

// print(String(data: response, encoding: .utf8) ?? "<no utf8 data>")

return try GrandSlamOperationDecoder<Response>.decode(data: response)
}

Expand Down Expand Up @@ -239,7 +232,7 @@ public struct ADIDataProvider: AnisetteDataProvider {
machineID: mid.base64EncodedString(),
localUserID: self.localUserID,
oneTimePassword: otp.base64EncodedString(),
deviceID: self.localUserUID.uuidString
deviceInfo: try await deviceInfo(),
)
}

Expand Down Expand Up @@ -287,6 +280,13 @@ public struct ADIDataProvider: AnisetteDataProvider {
)
}

public func deviceInfo() async throws -> DeviceInfo {
DeviceInfo(
deviceID: localUserUID.uuidString,
clientInfo: try await clientInfo(),
)
}

}

public struct ADIError: Error, CustomStringConvertible {
Expand Down
12 changes: 4 additions & 8 deletions Sources/XKit/GrandSlam/Anisette/AnisetteData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,17 @@ public struct AnisetteData {
static let oneTimePasswordKey = "X-Apple-I-MD"
public let oneTimePassword: String

static let deviceIDKey = "X-Mme-Device-Id"
public var deviceID: String?
public let deviceInfo: DeviceInfo

var dictionary: [String: String] {
public var dictionary: [String: String] {
// GSA doesn't like "en_US@rg=..."; it has to be just "en_US".
let localeIdentifier = if let language = locale.language.languageCode?.identifier,
let region = locale.region?.identifier {
"\(language)_\(region)"
} else {
"en_US"
}
var dictionary = [
return [
Self.localeKey: localeIdentifier,
Self.timeZoneKey: timeZone.abbreviation() ?? "UTC",
Self.clientTimeKey: Self.dateFormatter.string(from: clientTime),
Expand All @@ -69,10 +68,7 @@ public struct AnisetteData {
Self.localUserIDKey: localUserID,
Self.oneTimePasswordKey: oneTimePassword,
]
if let deviceID {
dictionary[Self.deviceIDKey] = deviceID
}
return dictionary
.merging(deviceInfo.dictionary) { _, b in b }
}

}
7 changes: 7 additions & 0 deletions Sources/XKit/GrandSlam/Anisette/AnisetteDataProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public protocol AnisetteDataProvider: Sendable {
func resetProvisioning() async
func provisioningData() -> ProvisioningData?

func deviceInfo() async throws -> DeviceInfo

func fetchAnisetteData() async throws -> AnisetteData
}

Expand Down Expand Up @@ -54,4 +56,9 @@ private struct UnimplementedAnisetteDataProvider: AnisetteDataProvider {
let closure: () async throws -> AnisetteData = unimplemented()
return try await closure()
}

func deviceInfo() async throws -> DeviceInfo {
let closure: () async throws -> DeviceInfo = unimplemented()
return try await closure()
}
}
102 changes: 0 additions & 102 deletions Sources/XKit/GrandSlam/Anisette/DeviceInfo+Fetching.swift

This file was deleted.

Loading
Loading