Modern Apps git

← xtool.git

Support SMS 2FA

Commit
33b13d3def9799428510a1c4424872cf9b6f8362
Author
Kabir Oberai <[email protected]>
When
2024-11-17 00:39 UTC (2 years ago)
Parents
34bce7a

Diff

Supersign/Sources/Supersign/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swift
diff --git a/Supersign/Sources/Supersign/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swift b/Supersign/Sources/Supersign/GrandSlam/Operations/GrandSlamTwoFactorAuthenticateOperation.swiftindex 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
Supersign/Sources/Supersign/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swift
diff --git a/Supersign/Sources/Supersign/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swift b/Supersign/Sources/Supersign/GrandSlam/Requests/Concrete/GrandSlamTrustedDeviceRequest.swiftindex 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+            ],+        ])+    }+}
Supersign/Sources/Supersign/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift
diff --git a/Supersign/Sources/Supersign/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift b/Supersign/Sources/Supersign/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swiftindex 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+            ]+        ])+    }+}+
Supersign/Sources/Supersign/GrandSlam/Requests/GrandSlamTwoFactorRequest.swift
diff --git a/Supersign/Sources/Supersign/GrandSlam/Requests/GrandSlamTwoFactorRequest.swift b/Supersign/Sources/Supersign/GrandSlam/Requests/GrandSlamTwoFactorRequest.swiftindex 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