Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.
Clean up GrandSlam code
kabiroberai4bf1281e5c7e
diff --git a/Supersign/GrandSlam/Crypto/SRPClient.swift b/Supersign/GrandSlam/Crypto/SRPClient.swiftindex 94f3906..4f3cbeb 100644--- a/Supersign/GrandSlam/Crypto/SRPClient.swift+++ b/Supersign/GrandSlam/Crypto/SRPClient.swift@@ -37,9 +37,9 @@ class SRPClient {// MARK: - SRP- func startAuthenticationAndGetA() -> Data {+ func publicKey() -> Data {var length = 0- return Data(bytesNoCopy: srp_client_start_auth_and_get_a(raw, &length), count: length, deallocator: .free)+ return Data(bytesNoCopy: srp_client_copy_public_key(raw, &length), count: length, deallocator: .free)}func processChallenge(@@ -47,21 +47,21 @@ class SRPClient {password: String,salt: Data,iterations: Int,- bData: Data,+ serverPublicKey key: Data,isS2K: Bool) -> Data? {salt.withUnsafeBytes { saltBuf in- bData.withUnsafeBytes { bDataBuf in+ key.withUnsafeBytes { keyBuf inlet saltBound = saltBuf.bindMemory(to: Int8.self)- let bDataBound = bDataBuf.bindMemory(to: Int8.self)+ let keyBound = keyBuf.bindMemory(to: Int8.self)var length = 0return srp_client_process_challenge(raw,username, password,saltBound.baseAddress!, saltBound.count,.init(iterations),- bDataBound.baseAddress!,- bDataBound.count,+ keyBound.baseAddress!,+ keyBound.count,isS2K,&length).map { Data(bytesNoCopy: $0, count: length, deallocator: .free) }@@ -69,10 +69,10 @@ class SRPClient {}}- func verify(m2: Data) -> Bool {- m2.withUnsafeBytes { buf in+ func verify(hamk: Data) -> Bool {+ hamk.withUnsafeBytes { buf inlet bound = buf.bindMemory(to: Int8.self)- return srp_client_verify_session_m2(raw, bound.baseAddress!, bound.count)+ return srp_client_verify_session_HAMK(raw, bound.baseAddress!, bound.count)}}diff --git a/Supersign/GrandSlam/Operations/GrandSlamAuthenticateOperation.swift b/Supersign/GrandSlam/Operations/GrandSlamAuthenticateOperation.swiftindex 788b51d..8236b4e 100644--- a/Supersign/GrandSlam/Operations/GrandSlamAuthenticateOperation.swift+++ b/Supersign/GrandSlam/Operations/GrandSlamAuthenticateOperation.swift@@ -83,7 +83,7 @@ class GrandSlamAuthenticateOperation {completeResponse.sc.map(srpClient.add(data:))srpClient.add(string: "|")- guard srpClient.verify(m2: completeResponse.m2Data) && srpClient.verify(negProto: completeResponse.negProto)+ guard srpClient.verify(hamk: completeResponse.hamk) && srpClient.verify(negProto: completeResponse.negProto)else { return completion(.failure(Error.invalidSession)) }guard let rawLoginResponse = srpClient.decrypt(cbc: completeResponse.encryptedResponse) else {@@ -131,7 +131,7 @@ class GrandSlamAuthenticateOperation {password: password,salt: initResponse.salt,iterations: initResponse.iterations,- bData: initResponse.bData,+ serverPublicKey: initResponse.serverPublicKey,isS2K: isS2K)guard let m1Data = mDataRaw else { return completion(.failure(Error.failedChallenge)) }@@ -151,9 +151,9 @@ class GrandSlamAuthenticateOperation {srpClient.add(string: GrandSlamAuthInitRequest.protocols.joined(separator: ","))srpClient.add(string: "|")- let aData = srpClient.startAuthenticationAndGetA()+ let publicKey = srpClient.publicKey()- let initRequest = GrandSlamAuthInitRequest(username: username, aData: aData)+ let initRequest = GrandSlamAuthInitRequest(username: username, publicKey: publicKey)client.send(initRequest) { result inguard let response = result.get(withErrorHandler: completion) else { return }self.authenticateStage2(initResponse: response, completion: completion)diff --git a/Supersign/GrandSlam/Requests/Concrete/GrandSlamAuthCompleteRequest.swift b/Supersign/GrandSlam/Requests/Concrete/GrandSlamAuthCompleteRequest.swiftindex 57f1e26..8aa8723 100644--- a/Supersign/GrandSlam/Requests/Concrete/GrandSlamAuthCompleteRequest.swift+++ b/Supersign/GrandSlam/Requests/Concrete/GrandSlamAuthCompleteRequest.swift@@ -12,13 +12,13 @@ struct GrandSlamAuthCompleteRequest: GrandSlamOperationRequest {typealias Decoder = GrandSlamOperationDecoder<Value>struct Value: Decodable {- let m2Data: Data+ let hamk: Datalet encryptedResponse: Datalet negProto: Datalet sc: Data?private enum CodingKeys: String, CodingKey {- case m2Data = "M2"+ case hamk = "M2"case encryptedResponse = "spd"case negProto = "np"case scdiff --git a/Supersign/GrandSlam/Requests/Concrete/GrandSlamAuthInitRequest.swift b/Supersign/GrandSlam/Requests/Concrete/GrandSlamAuthInitRequest.swiftindex e8a55d9..7b523c4 100644--- a/Supersign/GrandSlam/Requests/Concrete/GrandSlamAuthInitRequest.swift+++ b/Supersign/GrandSlam/Requests/Concrete/GrandSlamAuthInitRequest.swift@@ -16,14 +16,14 @@ struct GrandSlamAuthInitRequest: GrandSlamOperationRequest {let cookie: Stringlet salt: Datalet iterations: Int- let bData: Data+ let serverPublicKey: Dataprivate enum CodingKeys: String, CodingKey {case selectedProtocol = "sp"case cookie = "c"case salt = "s"case iterations = "i"- case bData = "B"+ case serverPublicKey = "B"}}@@ -32,12 +32,12 @@ struct GrandSlamAuthInitRequest: GrandSlamOperationRequest {static let protocols: [String] = GrandSlamAuthProtocol.allCases.map { $0.rawValue }let username: String- let aData: Data+ let publicKey: Datavar parameters: [String: Any] {["ps": Self.protocols,- "A2k": aData,+ "A2k": publicKey,]}diff --git a/SupersignTests/Tests/SupersignGrandSlamTests.swift b/SupersignTests/Tests/SupersignGrandSlamTests.swiftindex 8222b7f..01aee35 100644--- a/SupersignTests/Tests/SupersignGrandSlamTests.swift+++ b/SupersignTests/Tests/SupersignGrandSlamTests.swift@@ -23,10 +23,7 @@ class SupersignGrandSlamTests: XCTestCase {override func setUp() {super.setUp()- client = GrandSlamClient(- deviceInfo: Config.current.deviceInfo,- customAnisetteDataProvider: DirectAnisetteDataProvider()- )+ client = .test()authenticator = TwoFactorAuthenticator()}diff --git a/SupersignTests/Utilities/DeveloperServicesClient+Testing.swift b/SupersignTests/Utilities/DeveloperServicesClient+Testing.swiftindex f60a5f4..ff551e3 100644--- a/SupersignTests/Utilities/DeveloperServicesClient+Testing.swift+++ b/SupersignTests/Utilities/DeveloperServicesClient+Testing.swift@@ -8,11 +8,25 @@import Foundationimport XCTest-import Supersign+@testable import Supersign++extension TCPAnisetteDataProvider {++ static func test() -> TCPAnisetteDataProvider {+ TCPAnisetteDataProvider(localPort: 4321)+ }++}++extension GrandSlamClient {++ static func test() -> GrandSlamClient {+ GrandSlamClient(+ deviceInfo: Config.current.deviceInfo,+ customAnisetteDataProvider: TCPAnisetteDataProvider.test()+ )+ }-struct CredentialsManagerMock: DeveloperServicesCredentialsManager {- // store login in memory- public var token: DeveloperServicesCredentialsToken?}extension DeveloperServicesClient {@@ -21,7 +35,7 @@ extension DeveloperServicesClient {DeveloperServicesClient(loginToken: Config.current.appleID.token,deviceInfo: Config.current.deviceInfo,- customAnisetteDataProvider: DirectAnisetteDataProvider()+ customAnisetteDataProvider: TCPAnisetteDataProvider.test())}