Skip to content

Commit 85c9bdb

Browse files
committed
Fix handling of s2k_fo
1 parent 0a02b29 commit 85c9bdb

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Xcodes/AppleAPI/Sources/AppleAPI/Client.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class Client {
5454
let iterations = srpInit.iteration
5555

5656
do {
57-
guard let encryptedPassword = self.pbkdf2(password: password, saltData: decodedSalt, keyByteCount: 32, prf: CCPseudoRandomAlgorithm(kCCPRFHmacAlgSHA256), rounds: iterations) else {
57+
guard let encryptedPassword = self.pbkdf2(password: password, saltData: decodedSalt, keyByteCount: 32, prf: CCPseudoRandomAlgorithm(kCCPRFHmacAlgSHA256), rounds: iterations, protocol: srpInit.protocol) else {
5858
return Fail(error: AuthenticationError.srpInvalidPublicKey)
5959
.eraseToAnyPublisher()
6060
}
@@ -308,9 +308,13 @@ public class Client {
308308
return Data(hash)
309309
}
310310

311-
private func pbkdf2(password: String, saltData: Data, keyByteCount: Int, prf: CCPseudoRandomAlgorithm, rounds: Int) -> Data? {
311+
private func pbkdf2(password: String, saltData: Data, keyByteCount: Int, prf: CCPseudoRandomAlgorithm, rounds: Int, protocol srpProtocol: SRPProtocol) -> Data? {
312312
guard let passwordData = password.data(using: .utf8) else { return nil }
313-
let hashedPasswordData = sha256(data: passwordData)
313+
let hashedPasswordDataRaw = sha256(data: passwordData)
314+
let hashedPasswordData = switch srpProtocol {
315+
case .s2k: hashedPasswordDataRaw
316+
case .s2k_fo: Data(hashedPasswordDataRaw.hexEncodedString().lowercased().utf8)
317+
}
314318

315319
var derivedKeyData = Data(repeating: 0, count: keyByteCount)
316320
let derivedCount = derivedKeyData.count
@@ -584,6 +588,7 @@ public struct ServerSRPInitResponse: Decodable {
584588
let salt: String
585589
let b: String
586590
let c: String
591+
let `protocol`: SRPProtocol
587592
}
588593

589594

0 commit comments

Comments
 (0)