-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Type of change ``` - [ ] Bug fix - [x] New feature development - [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc) - [ ] Build/deploy pipeline (DevOps) - [ ] Other ``` ## Objective Add support in the SDK to create the keys necessary for the just in time user for TDE
- Loading branch information
1 parent
51a5140
commit 0ae0226
Showing
5 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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,51 @@ | ||
use base64::{engine::general_purpose::STANDARD, Engine}; | ||
use bitwarden_crypto::{ | ||
AsymmetricEncString, AsymmetricPublicCryptoKey, DeviceKey, EncString, SymmetricCryptoKey, | ||
TrustDeviceResponse, UserKey, | ||
}; | ||
|
||
use crate::{error::Result, Client}; | ||
|
||
/// This function generates a new user key and key pair, initializes the client's crypto with the | ||
/// generated user key, and encrypts the user key with the organization public key for admin | ||
/// password reset. If remember_device is true, it also generates a device key. | ||
pub(super) fn make_register_tde_keys( | ||
client: &mut Client, | ||
org_public_key: String, | ||
remember_device: bool, | ||
) -> Result<RegisterTdeKeyResponse> { | ||
let public_key = AsymmetricPublicCryptoKey::from_der(&STANDARD.decode(org_public_key)?)?; | ||
|
||
let mut rng = rand::thread_rng(); | ||
|
||
let user_key = UserKey::new(SymmetricCryptoKey::generate(&mut rng)); | ||
let key_pair = user_key.make_key_pair()?; | ||
|
||
let admin_reset = | ||
AsymmetricEncString::encrypt_rsa2048_oaep_sha1(&user_key.0.to_vec(), &public_key)?; | ||
|
||
let device_key = if remember_device { | ||
Some(DeviceKey::trust_device(&user_key.0)?) | ||
} else { | ||
None | ||
}; | ||
|
||
client.initialize_user_crypto_decrypted_key(user_key.0, key_pair.private.clone())?; | ||
|
||
Ok(RegisterTdeKeyResponse { | ||
private_key: key_pair.private, | ||
public_key: key_pair.public, | ||
|
||
admin_reset, | ||
device_key, | ||
}) | ||
} | ||
|
||
#[cfg_attr(feature = "mobile", derive(uniffi::Record))] | ||
pub struct RegisterTdeKeyResponse { | ||
pub private_key: EncString, | ||
pub public_key: String, | ||
|
||
pub admin_reset: AsymmetricEncString, | ||
pub device_key: Option<TrustDeviceResponse>, | ||
} |
This file contains 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