-
Notifications
You must be signed in to change notification settings - Fork 11
[PM-22845] Add account key rotation #313
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
Open
quexten
wants to merge
2
commits into
main
Choose a base branch
from
km/cose-key-rotation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 @@ | ||
use base64::{engine::general_purpose::STANDARD, Engine}; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
#[cfg(feature = "wasm")] | ||
use tsify_next::Tsify; | ||
|
||
use crate::{ | ||
CoseSerializable, CryptoError, EncString, KeyEncryptable, KeyStoreContext, SymmetricCryptoKey, | ||
}; | ||
|
||
/// Rotated set of account keys | ||
#[derive(Serialize, Deserialize, Debug, JsonSchema)] | ||
#[serde(rename_all = "camelCase", deny_unknown_fields)] | ||
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))] | ||
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))] | ||
pub struct RotateUserKeysResponse { | ||
/// The verifying key | ||
verifying_key: String, | ||
/// Signing key, encrypted with a symmetric key (user key, org key) | ||
signing_key: EncString, | ||
/// The user's public key, signed by the signing key | ||
signed_public_key: String, | ||
// The user's public key, without signature | ||
public_key: String, | ||
// The user's private key, encrypted with the user key | ||
private_key: EncString, | ||
} | ||
|
||
/// Re-encrypts the user's keys with the provided symmetric key for a v2 user. | ||
pub fn get_v2_rotated_account_keys<Ids: crate::KeyIds>( | ||
new_user_key: SymmetricCryptoKey, | ||
current_user_private_key_id: Ids::Asymmetric, | ||
current_user_signing_key_id: Ids::Signing, | ||
ctx: &KeyStoreContext<Ids>, | ||
) -> Result<RotateUserKeysResponse, CryptoError> { | ||
let signing_key = ctx.get_signing_key(current_user_signing_key_id)?; | ||
let private_key = ctx.get_asymmetric_key(current_user_private_key_id)?; | ||
let signed_public_key: Vec<u8> = ctx | ||
.make_signed_public_key(current_user_private_key_id, current_user_signing_key_id)? | ||
.into(); | ||
|
||
Ok(RotateUserKeysResponse { | ||
verifying_key: STANDARD.encode(signing_key.to_verifying_key().to_cose()), | ||
signing_key: signing_key.to_cose().encrypt_with_key(&new_user_key)?, | ||
signed_public_key: STANDARD.encode(&signed_public_key), | ||
public_key: STANDARD.encode(private_key.to_public_key().to_der()?), | ||
private_key: private_key.to_der()?.encrypt_with_key(&new_user_key)?, | ||
}) | ||
} | ||
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
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.
question: Key rotation feels very application bound and not like a low level cryptographic primitive? I think this is further enhanced by bitwarden-core just acting as a wrapper around this function.
I presume this was done to avoid making
get_asymetric_key
and `get_signing_key public?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.
Yes;
As far as I understand we do not want any further new uses that expose keys out of
bitwarden-crypto
, so this had to go into the crypto crate to achieve that. Is there another pattern we can use here? (Maybe we do allow (non-deprecated) getting wrapped(encrypted) keys out of a context?)