@@ -54,7 +54,7 @@ public class Client {
54
54
let iterations = srpInit. iteration
55
55
56
56
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 {
58
58
return Fail ( error: AuthenticationError . srpInvalidPublicKey)
59
59
. eraseToAnyPublisher ( )
60
60
}
@@ -308,9 +308,14 @@ public class Client {
308
308
return Data ( hash)
309
309
}
310
310
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 ? {
312
312
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
+ // the legacy s2k_fo protocol requires hex-encoding the digest before performing PBKDF2.
317
+ case . s2k_fo: Data ( hashedPasswordDataRaw. hexEncodedString ( ) . lowercased ( ) . utf8)
318
+ }
314
319
315
320
var derivedKeyData = Data ( repeating: 0 , count: keyByteCount)
316
321
let derivedCount = derivedKeyData. count
@@ -584,6 +589,7 @@ public struct ServerSRPInitResponse: Decodable {
584
589
let salt : String
585
590
let b : String
586
591
let c : String
592
+ let `protocol` : SRPProtocol
587
593
}
588
594
589
595
0 commit comments