-
Notifications
You must be signed in to change notification settings - Fork 9
Unify WASM crypto client with mobile #226
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
use bitwarden_crypto::CryptoError; | ||
#[cfg(feature = "internal")] | ||
use bitwarden_crypto::{EncString, UnsignedSharedKey}; | ||
#[cfg(feature = "wasm")] | ||
use wasm_bindgen::prelude::*; | ||
|
||
use super::crypto::{ | ||
derive_key_connector, make_key_pair, verify_asymmetric_keys, DeriveKeyConnectorError, | ||
|
@@ -16,10 +18,12 @@ | |
use crate::{client::encryption_settings::EncryptionSettingsError, Client}; | ||
|
||
/// A client for the crypto operations. | ||
#[cfg_attr(feature = "wasm", wasm_bindgen)] | ||
pub struct CryptoClient { | ||
pub(crate) client: crate::Client, | ||
} | ||
|
||
#[cfg_attr(feature = "wasm", wasm_bindgen)] | ||
impl CryptoClient { | ||
/// Initialization method for the user crypto. Needs to be called before any other crypto | ||
/// operations. | ||
|
@@ -39,6 +43,24 @@ | |
initialize_org_crypto(&self.client, req).await | ||
} | ||
|
||
/// Generates a new key pair and encrypts the private key with the provided user key. | ||
/// Crypto initialization not required. | ||
pub fn make_key_pair(&self, user_key: String) -> Result<MakeKeyPairResponse, CryptoError> { | ||
make_key_pair(user_key) | ||
} | ||
|
||
/// Verifies a user's asymmetric keys by decrypting the private key with the provided user | ||
/// key. Returns if the private key is decryptable and if it is a valid matching key. | ||
/// Crypto initialization not required. | ||
pub fn verify_asymmetric_keys( | ||
&self, | ||
request: VerifyAsymmetricKeysRequest, | ||
) -> Result<VerifyAsymmetricKeysResponse, CryptoError> { | ||
verify_asymmetric_keys(request) | ||
} | ||
} | ||
|
||
impl CryptoClient { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've split the We could also export all of them if we wanted, but to keep the PR simple I only include the ones actually in use. |
||
/// Get the uses's decrypted encryption key. Note: It's very important | ||
/// to keep this key safe, as it can be used to decrypt all of the user's data | ||
pub async fn get_user_encryption_key(&self) -> Result<String, MobileCryptoError> { | ||
|
@@ -86,21 +108,6 @@ | |
) -> Result<String, DeriveKeyConnectorError> { | ||
derive_key_connector(request) | ||
} | ||
|
||
/// Generates a new key pair and encrypts the private key with the provided user key. | ||
pub fn make_key_pair(&self, user_key: String) -> Result<MakeKeyPairResponse, CryptoError> { | ||
make_key_pair(user_key) | ||
} | ||
|
||
/// Verifies a user's asymmetric keys by decrypting the private key with the provided user | ||
/// key. Returns if the private key is decryptable and if it is a valid matching key. | ||
/// Crypto initialization not required. | ||
pub fn verify_asymmetric_keys( | ||
&self, | ||
request: VerifyAsymmetricKeysRequest, | ||
) -> Result<VerifyAsymmetricKeysResponse, CryptoError> { | ||
verify_asymmetric_keys(request) | ||
} | ||
} | ||
|
||
impl Client { | ||
|
This file was deleted.
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.
This dep is used internally for the wasm-bindgen macro as cryptoclient has some async functions.