generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 75
[PM-23277] Force KDF updates if below minimums #1880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2bcffef
[PM-23576] Add Update KDF API request
matt-livefront dab89e9
[PM-23576] Add update KDF logic
matt-livefront ce363b9
[PM-23277] Force KDF updates if below minimums
matt-livefront 417cdcd
[PM-23576] Add check for has master password
matt-livefront 2b099d3
[PM-23576] Save updated KDF to user's account
matt-livefront 2fd1b69
[PM-23576] Update error handling behavior
matt-livefront bc8cf8b
[PM-23576] Add flight recorder log when upgrading KDF config
matt-livefront 65ddc98
[PM-23576] Update tests
matt-livefront c5ab4e6
[PM-23576] Sync before KDF update
matt-livefront 5575424
Merge branch 'main' into matt/PM-23576-update-kdf
matt-livefront File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
BitwardenShared/Core/Auth/Models/Domains/KdfConfigTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import XCTest | ||
|
||
@testable import BitwardenShared | ||
|
||
class KdfConfigTests: BitwardenTestCase { | ||
// MARK: Tests | ||
|
||
/// `init(kdf:)` initializes `KdfConfig` from `BitwardenSdk.Kdf` when using `argon2id`. | ||
func test_init_kdf_argon2() { | ||
let subject = KdfConfig(kdf: .argon2id(iterations: 3, memory: 64, parallelism: 4)) | ||
XCTAssertEqual( | ||
subject, | ||
KdfConfig( | ||
kdfType: .argon2id, | ||
iterations: 3, | ||
memory: 64, | ||
parallelism: 4 | ||
) | ||
) | ||
} | ||
|
||
/// `init(kdf:)` initializes `KdfConfig` from `BitwardenSdk.Kdf` when using `pbkdf2`. | ||
func test_init_kdf_pbkdf2() { | ||
let subject = KdfConfig(kdf: .pbkdf2(iterations: 600_000)) | ||
XCTAssertEqual( | ||
subject, | ||
KdfConfig( | ||
kdfType: .pbkdf2sha256, | ||
iterations: 600_000, | ||
memory: nil, | ||
parallelism: nil | ||
) | ||
) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
BitwardenShared/Core/Auth/Models/Request/MasterPasswordAuthenticationDataRequestModel.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import BitwardenSdk | ||
|
||
// MARK: - MasterPasswordAuthenticationDataRequestModel | ||
|
||
/// A request model for a user's master password authentication data. | ||
/// | ||
struct MasterPasswordAuthenticationDataRequestModel: Encodable, Equatable { | ||
// MARK: Properties | ||
|
||
/// The KDF settings. | ||
let kdf: KdfConfig | ||
|
||
/// The master password hash. | ||
let masterPasswordAuthenticationHash: String | ||
|
||
/// The salt used to compute the master password hash. | ||
let salt: String | ||
} | ||
|
||
extension MasterPasswordAuthenticationDataRequestModel { | ||
/// Initialize `MasterPasswordAuthenticationDataRequestModel` from `MasterPasswordAuthenticationData`. | ||
/// | ||
/// - Parameter authenticationData: The `MasterPasswordAuthenticationData` used to initialize a | ||
/// `MasterPasswordAuthenticationDataRequestModel`. | ||
/// | ||
init(authenticationData: MasterPasswordAuthenticationData) { | ||
self.init( | ||
kdf: KdfConfig(kdf: authenticationData.kdf), | ||
masterPasswordAuthenticationHash: authenticationData.masterPasswordAuthenticationHash, | ||
salt: authenticationData.salt | ||
) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
BitwardenShared/Core/Auth/Models/Request/MasterPasswordUnlockDataRequestModel.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import BitwardenSdk | ||
|
||
// MARK: - MasterPasswordUnlockDataRequestModel | ||
|
||
/// A request model for a user's unlock data. | ||
/// | ||
struct MasterPasswordUnlockDataRequestModel: Encodable, Equatable { | ||
// MARK: Properties | ||
|
||
/// The KDF settings. | ||
let kdf: KdfConfig | ||
|
||
/// The user's master key encrypted with their user key. | ||
let masterKeyWrappedUserKey: String | ||
|
||
/// The salt used to encrypt the user key. | ||
let salt: String | ||
} | ||
|
||
extension MasterPasswordUnlockDataRequestModel { | ||
/// Initialize `MasterPasswordUnlockDataRequestModel` from `MasterPasswordUnlockData`. | ||
/// | ||
/// - Parameter authenticationData: The `MasterPasswordUnlockData` used to initialize a | ||
/// `MasterPasswordUnlockDataRequestModel`. | ||
/// | ||
init(unlockData: MasterPasswordUnlockData) { | ||
self.init( | ||
kdf: KdfConfig(kdf: unlockData.kdf), | ||
masterKeyWrappedUserKey: unlockData.masterKeyWrappedUserKey, | ||
salt: unlockData.salt | ||
) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
BitwardenShared/Core/Auth/Models/Request/UpdateKdfRequestModel.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import BitwardenSdk | ||
import Networking | ||
|
||
// MARK: - UpdateKdfRequestModel | ||
|
||
/// The request body for an update KDF request. | ||
/// | ||
struct UpdateKdfRequestModel: JSONRequestBody, Equatable { | ||
// MARK: Properties | ||
|
||
/// The user's data for authentication. | ||
let authenticationData: MasterPasswordAuthenticationDataRequestModel | ||
|
||
/// The user's key. | ||
let key: String | ||
|
||
/// The hash of the old master password. | ||
let masterPasswordHash: String | ||
|
||
/// The hash of the new master password. | ||
let newMasterPasswordHash: String | ||
|
||
/// The user's data for unlock. | ||
let unlockData: MasterPasswordUnlockDataRequestModel | ||
} | ||
|
||
extension UpdateKdfRequestModel { | ||
/// Initialize `UpdateKdfRequestModel` from `UpdateKdfResponse`. | ||
/// | ||
/// - Parameter response: The `UpdateKdfResponse` used to initialize a `UpdateKdfRequestModel`. | ||
/// | ||
init(response: UpdateKdfResponse) { | ||
self.init( | ||
authenticationData: MasterPasswordAuthenticationDataRequestModel( | ||
authenticationData: response.masterPasswordAuthenticationData | ||
), | ||
key: response.masterPasswordUnlockData.masterKeyWrappedUserKey, | ||
masterPasswordHash: response.oldMasterPasswordAuthenticationData.masterPasswordAuthenticationHash, | ||
newMasterPasswordHash: response.masterPasswordAuthenticationData.masterPasswordAuthenticationHash, | ||
unlockData: MasterPasswordUnlockDataRequestModel( | ||
unlockData: response.masterPasswordUnlockData | ||
) | ||
) | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
BitwardenShared/Core/Auth/Models/Request/UpdateKdfRequestModelTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import BitwardenSdk | ||
import XCTest | ||
|
||
@testable import BitwardenShared | ||
|
||
class UpdateKdfRequestModelTests: BitwardenTestCase { | ||
// MARK: Tests | ||
|
||
/// `init(response:)` initializes `UpdateKdfRequestModel` from a `UpdateKdfResponse`. | ||
func test_init_response() { | ||
let subject = UpdateKdfRequestModel( | ||
response: UpdateKdfResponse( | ||
masterPasswordAuthenticationData: MasterPasswordAuthenticationData( | ||
kdf: .pbkdf2(iterations: 600_000), | ||
salt: "AUTHENTICATION_SALT", | ||
masterPasswordAuthenticationHash: "MASTER_PASSWORD_AUTHENTICATION_HASH" | ||
), | ||
masterPasswordUnlockData: MasterPasswordUnlockData( | ||
kdf: .argon2id(iterations: 3, memory: 64, parallelism: 4), | ||
masterKeyWrappedUserKey: "MASTER_KEY_WRAPPED_USER_KEY", | ||
salt: "UNLOCK_SALT" | ||
), | ||
oldMasterPasswordAuthenticationData: MasterPasswordAuthenticationData( | ||
kdf: .pbkdf2(iterations: 100_000), | ||
salt: "OLD_SALT", | ||
masterPasswordAuthenticationHash: "OLD_MASTER_PASSWORD_AUTHENTICATION_HASH" | ||
) | ||
) | ||
) | ||
XCTAssertEqual( | ||
subject, | ||
UpdateKdfRequestModel( | ||
authenticationData: MasterPasswordAuthenticationDataRequestModel( | ||
kdf: KdfConfig(kdfType: .pbkdf2sha256, iterations: 600_000), | ||
masterPasswordAuthenticationHash: "MASTER_PASSWORD_AUTHENTICATION_HASH", | ||
salt: "AUTHENTICATION_SALT" | ||
), | ||
key: "MASTER_KEY_WRAPPED_USER_KEY", | ||
masterPasswordHash: "OLD_MASTER_PASSWORD_AUTHENTICATION_HASH", | ||
newMasterPasswordHash: "MASTER_PASSWORD_AUTHENTICATION_HASH", | ||
unlockData: MasterPasswordUnlockDataRequestModel( | ||
kdf: KdfConfig(kdfType: .argon2id, iterations: 3, memory: 64, parallelism: 4), | ||
masterKeyWrappedUserKey: "MASTER_KEY_WRAPPED_USER_KEY", | ||
salt: "UNLOCK_SALT" | ||
) | ||
) | ||
) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
Updatingโฆ
Last time someone unify all
...
(3 dots) toโฆ
character