anisette: use XADI on macOS (#259)
- Commit
eacc35da986d1c72d2946a9747ebecc84871628c- Author
- Kabir Oberai <[email protected]>
- When
- 2026-09-20 07:04 UTC (2 months ago)
- Parents
0108899
## What does this PR do? Updates macOS build to use the fully-local XADI as the Anisette provider instead of Omnisette. Includes a one-time migration, logging the user out on macOS when they upgrade. ## How was it tested? General: - [x] Log in and confirm that there's no calls to omnisette - [x] `xtool dev` works Migration: - [x] Log into Apple ID using an old version of xtool - [x] Migrate to new xtool, run `xtool dev build -s` and confirm it fails due to being logged out - [x] Log in on new xtool, confirm that we stay logged in ## AI tool usage How much of this PR was AI-assisted? (check one) - [x] **0** - No AI was used to write code - [ ] **1** - I was assisted by AI. I reviewed the finished result. - [ ] **2** - I set the AI going and left it to it; nobody has read the result - no review, or AI review only <!-- If an AI agent is filling this in: declare the level honestly, and open as a draft if it is #2. Do not lower the declared level to get the PR reviewed. --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Authentication now supports tracking the anisette provider used to create Xcode tokens. * Xcode authentication tokens are automatically cleared when the provider changes, helping ensure users sign in again with current credentials. * Anisette provider identification is supported across macOS and Linux. * **Bug Fixes** * Improved authentication error messages, including clearer messaging for logout-related errors. * Prevented outdated Xcode authentication tokens from being reused after a provider change. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Diff
Package.swift
diff --git a/Package.swift b/Package.swiftindex cdacc74..47615c6 100644--- a/Package.swift+++ b/Package.swift@@ -120,7 +120,7 @@ let package = Package( "DeveloperAPI", "CXKit", "XUtils",- .product(name: "XADI", package: "xadi", condition: .when(platforms: [.linux])),+ .product(name: "XADI", package: "xadi", condition: .when(platforms: [.linux, .macOS])), .product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"), .product(name: "Dependencies", package: "swift-dependencies"), .product(name: "SwiftyMobileDevice", package: "SwiftyMobileDevice"),
Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swift
diff --git a/Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swift b/Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swiftindex 085730c..5d6bd67 100644--- a/Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swift+++ b/Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swift@@ -92,13 +92,10 @@ public struct ADIDataProvider: AnisetteDataProvider { private let _clientInfo = LockIsolated<String?>(nil) - public init(provisioningData: ProvisioningData? = nil) {+ public init() { @Dependency(\.keyValueStorage) var storage- if let provisioningData {- self.localUserUID = provisioningData.localUserUID- try? storage.setData(provisioningData.adiPb, forKey: Self.provisioningKey)- try? storage.setString("\(provisioningData.routingInfo)", forKey: Self.routingInfoKey)- } else if let localUserUIDString = try? storage.string(forKey: Self.localUserUIDKey),++ if let localUserUIDString = try? storage.string(forKey: Self.localUserUIDKey), let localUserUID = UUID(uuidString: localUserUIDString) { self.localUserUID = localUserUID } else {@@ -110,9 +107,15 @@ public struct ADIDataProvider: AnisetteDataProvider { self.localUserID = SHA256.hash(data: Data(localUserUID.uuidString.utf8)) .map { String(format: "%02X", $0) } .joined()++ if (try? storage.string(forKey: Self.providerIDKey)) != Self.providerID {+ self.resetProvisioning()+ try? storage.setString(Self.providerID, forKey: Self.providerIDKey)+ } } private static let localUserUIDKey = "XTLLocalUserUID"+ private static let providerIDKey = "XTLADIProviderID" private static let provisioningKey = "XTLProvisioningInfo" private static let routingInfoKey = "XTLRoutingInfo" @@ -245,6 +248,16 @@ public struct ADIDataProvider: AnisetteDataProvider { try? storage.setString(nil, forKey: Self.routingInfoKey) } + private static var providerID: String? {+ #if os(macOS)+ return "1"+ #else+ return nil+ #endif+ }++ public var providerID: String? { Self.providerID }+ public func provisioningData() -> ProvisioningData? { guard let provisioningInfo = try? storage.data(forKey: Self.provisioningKey), let routingInfoString = try? storage.string(forKey: Self.routingInfoKey),@@ -280,6 +293,23 @@ public struct ADIDataProvider: AnisetteDataProvider { } -public struct ADIError: Error {+public struct ADIError: Error, CustomStringConvertible { public var code: Int++ public var description: String {+ switch code {+ case -45061:+ return """+ You were logged out. Please log in again with `xtool auth`.++ If you see this repeatedly, please file an issue at https://github.com/xtool-org/xtool/issues/new/choose+ """+ default:+ return """+ Apple Anisette library returned error \(code). Please try logging in again with `xtool auth`.++ If this problem persists, file an issue at https://github.com/xtool-org/xtool/issues/new/choose+ """+ }+ } }
Sources/XKit/GrandSlam/Anisette/AnisetteDataProvider.swift
diff --git a/Sources/XKit/GrandSlam/Anisette/AnisetteDataProvider.swift b/Sources/XKit/GrandSlam/Anisette/AnisetteDataProvider.swiftindex 474bbb0..554eec8 100644--- a/Sources/XKit/GrandSlam/Anisette/AnisetteDataProvider.swift+++ b/Sources/XKit/GrandSlam/Anisette/AnisetteDataProvider.swift@@ -10,6 +10,14 @@ import Foundation import Dependencies public protocol AnisetteDataProvider: Sendable {+ /// Stored alongside login data. If the provider reports a new ID, we log out.+ /// + /// This is useful when switching Anisette provider implementations if the old+ /// implementation's provisioning data won't work with the new implementation.+ ///+ /// The default implementation returns `nil`.+ var providerID: String? { get }+ // This is a suggestion and not a requirement. func resetProvisioning() async func provisioningData() -> ProvisioningData?@@ -24,6 +32,7 @@ public struct ProvisioningData: Hashable, Codable, Sendable { } extension AnisetteDataProvider {+ public var providerID: String? { nil } public func provisioningData() -> ProvisioningData? { nil } public func resetProvisioning() async {} }
Sources/XToolSupport/AuthCommand.swift
diff --git a/Sources/XToolSupport/AuthCommand.swift b/Sources/XToolSupport/AuthCommand.swiftindex 40f8657..c0d028c 100644--- a/Sources/XToolSupport/AuthCommand.swift+++ b/Sources/XToolSupport/AuthCommand.swift@@ -111,12 +111,15 @@ struct AuthOperation { } ) + @Dependency(\.anisetteDataProvider) var anisetteProvider+ return AuthToken.xcode(.init( appleID: username, adsid: token.adsid, token: token.token, expiry: token.expiry,- teamID: team.id.rawValue+ teamID: team.id.rawValue,+ anisetteProviderID: anisetteProvider.providerID )) } }
Sources/XToolSupport/AuthToken.swift
diff --git a/Sources/XToolSupport/AuthToken.swift b/Sources/XToolSupport/AuthToken.swiftindex eef02e8..0319a7b 100644--- a/Sources/XToolSupport/AuthToken.swift+++ b/Sources/XToolSupport/AuthToken.swift@@ -9,6 +9,7 @@ enum AuthToken: Codable, CustomStringConvertible { var token: String var expiry: Date var teamID: String+ var anisetteProviderID: String? } struct AppStoreConnect: Codable {@@ -58,7 +59,18 @@ extension AuthToken { guard let data = try storage.data(forKey: "XTLAuthToken") else { return nil }- return try decoder.decode(AuthToken.self, from: data)+ let decoded = try decoder.decode(AuthToken.self, from: data)+ switch decoded {+ case .xcode(let xcode):+ @Dependency(\.anisetteDataProvider) var anisetteProvider+ guard xcode.anisetteProviderID == anisetteProvider.providerID else {+ try? clear()+ return nil+ }+ case .appStoreConnect:+ break+ }+ return decoded } static func clear() throws {
macOS/Support/XToolMac.entitlements
diff --git a/macOS/Support/XToolMac.entitlements b/macOS/Support/XToolMac.entitlementsindex 55d9160..5e84aca 100644--- a/macOS/Support/XToolMac.entitlements+++ b/macOS/Support/XToolMac.entitlements@@ -2,6 +2,8 @@ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict>+ <key>com.apple.security.cs.allow-unsigned-executable-memory</key>+ <true/> <key>keychain-access-groups</key> <array> <string>$(AppIdentifierPrefix)sh.xtool.keychain</string>