Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

Support SMS 2FA

Kabir Oberai33b13d3def97
diff --git a/Supersign/Sources/Supersign/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swift b/Supersign/Sources/Supersign/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swift
index 6862710..3274efa 100644
--- a/Supersign/Sources/Supersign/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swift
+++ b/Supersign/Sources/Supersign/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swift
@@ -35,16 +35,26 @@ class GrandSlamTwoFactorAuthenticateOperation {
self.delegate = delegate
}
- private func performSecondaryAuth() async throws {
- try await client.send(GrandSlamSecondaryAuthRequest(loginData: loginData))
- try await validateCode()
+ private func performSMSAuth() async throws {
+ // TODO: parse phone number list from o=complete req?
+ let phoneNumberID = "1"
+ try await client.send(GrandSlamSMSAuthRequest(loginData: loginData, phoneNumberID: phoneNumberID))
+ try await validateCode(phoneNumberID: phoneNumberID)
}
- private func validateCode() async throws {
+ private func validateCode(phoneNumberID: String? = nil) async throws {
guard let code = await self.delegate.fetchCode() else { throw Error.userCancelled }
- let request = GrandSlamValidateRequest(loginData: loginData, verificationCode: code)
+ let request: any GrandSlamRequest = if let phoneNumberID {
+ GrandSlamValidateSMSRequest(
+ loginData: loginData,
+ phoneNumberID: phoneNumberID,
+ verificationCode: code
+ )
+ } else {
+ GrandSlamValidateRequest(loginData: loginData, verificationCode: code)
+ }
do {
- try await client.send(request)
+ _ = try await client.send(request)
} catch let error as GrandSlamOperationError where error.code == -21669 {
throw Error.incorrectVerificationCode
}
@@ -59,10 +69,7 @@ class GrandSlamTwoFactorAuthenticateOperation {
func perform() async throws {
switch mode {
case .secondaryAuth:
- // TODO: We *should* be calling performSecondaryAuth – it does
- // seem like performTrustedDeviceAuth sometimes works here but
- // other times re-authenticating continues to 409
- try await self.performTrustedDeviceAuth()
+ try await self.performSMSAuth()
case .trustedDeviceSecondaryAuth:
try await self.performTrustedDeviceAuth()
case nil: // means 2FA was automatically requested
diff --git a/Supersign/Sources/Supersign/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swift b/Supersign/Sources/Supersign/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swift
index 24fddf7..dc8c721 100644
--- a/Supersign/Sources/Supersign/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swift
+++ b/Supersign/Sources/Supersign/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swift
@@ -29,3 +29,22 @@ struct GrandSlamSecondaryAuthRequest: GrandSlamTwoFactorRequest {
let loginData: GrandSlamLoginData
}
+
+struct GrandSlamSMSAuthRequest: GrandSlamTwoFactorRequest {
+ struct Decoder: GrandSlamDataDecoder {
+ static func decode(data: Data) throws {}
+ }
+
+ static let endpoint: GrandSlamEndpoint = .url(URL(string: "https://gsa.apple.com/auth/verify/phone/put?mode=sms")!)
+
+ let loginData: GrandSlamLoginData
+ let phoneNumberID: String
+
+ func method(deviceInfo: DeviceInfo, anisetteData: AnisetteData) -> GrandSlamMethod {
+ .post([
+ "serverInfo": [
+ "phoneNumber.id": phoneNumberID
+ ],
+ ])
+ }
+}
diff --git a/Supersign/Sources/Supersign/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift b/Supersign/Sources/Supersign/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift
index 8c2abc8..50411cc 100644
--- a/Supersign/Sources/Supersign/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift
+++ b/Supersign/Sources/Supersign/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift
@@ -22,3 +22,28 @@ struct GrandSlamValidateRequest: GrandSlamTwoFactorRequest {
["security-code": verificationCode]
}
}
+
+struct GrandSlamValidateSMSRequest: GrandSlamTwoFactorRequest {
+ struct Decoder: GrandSlamDataDecoder {
+ static func decode(data: Data) throws {}
+ }
+
+ static let endpoint: GrandSlamEndpoint = .url(URL(
+ string: "https://gsa.apple.com/auth/verify/phone/securitycode?referrer=/auth/verify/phone/put"
+ )!)
+
+ let loginData: GrandSlamLoginData
+ let phoneNumberID: String
+ let verificationCode: String
+
+ func method(deviceInfo: DeviceInfo, anisetteData: AnisetteData) -> GrandSlamMethod {
+ .post([
+ "securityCode.code": verificationCode,
+ "serverInfo": [
+ "mode": "sms",
+ "phoneNumber.id": phoneNumberID
+ ]
+ ])
+ }
+}
+
diff --git a/Supersign/Sources/Supersign/GrandSlam/Requests/GrandSlamTwoFactorRequest.swift b/Supersign/Sources/Supersign/GrandSlam/Requests/GrandSlamTwoFactorRequest.swift
index e9665d2..a8861f5 100644
--- a/Supersign/Sources/Supersign/GrandSlam/Requests/GrandSlamTwoFactorRequest.swift
+++ b/Supersign/Sources/Supersign/GrandSlam/Requests/GrandSlamTwoFactorRequest.swift
@@ -18,7 +18,8 @@ extension GrandSlamTwoFactorRequest {
var extraHeaders: [String: String] { [:] }
func configure(request: inout HTTPRequest, deviceInfo: DeviceInfo, anisetteData: AnisetteData) {
- request.headers["Accept"] = "text/x-xml-plist"
+ request.headers["Accept"] = "application/x-buddyml"
+ request.headers["Content-Type"] = "application/x-plist"
request.headers["X-Apple-App-Info"] = "com.apple.gs.xcode.auth"
request.headers[DeviceInfo.xcodeVersionKey] = DeviceInfo.xcodeVersion
request.headers["X-Apple-Identity-Token"] = loginData.identityToken