-
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.
- Loading branch information
1 parent
27cf054
commit eaef2ca
Showing
5 changed files
with
82 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,52 @@ | ||
use base64::{engine::general_purpose::STANDARD, Engine}; | ||
use bitwarden_crypto::{ | ||
AsymmetricEncString, AsymmetricPublicCryptoKey, DeviceKey, EncString, SymmetricCryptoKey, | ||
TrustDeviceResponse, UserKey, | ||
}; | ||
|
||
use crate::{error::Result, Client}; | ||
|
||
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(); | ||
|
||
// Generate a new user key and key pair, and encrypt the user key with the org public key for | ||
// admin password reset | ||
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 | ||
}; | ||
|
||
// Initialize the crypto with the generated user key, this way it doesn't need to leave the | ||
// client | ||
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