diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-04-06 06:35:30 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-04-06 06:35:30 -0400 |
commit | bc18bca5c67b4a678a31198877e39d57d97b1e0c (patch) | |
tree | 3dc31608586cbe0f7973d7aa730267d57224e6a1 /src/actions.rs | |
parent | 4ad2f0a0dc3abb4cb10a6b82ca6a1f3a829eb1fb (diff) | |
download | rbw-bc18bca5c67b4a678a31198877e39d57d97b1e0c.tar.gz rbw-bc18bca5c67b4a678a31198877e39d57d97b1e0c.zip |
factor out into an agent
Diffstat (limited to 'src/actions.rs')
-rw-r--r-- | src/actions.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/actions.rs b/src/actions.rs new file mode 100644 index 0000000..d7f3103 --- /dev/null +++ b/src/actions.rs @@ -0,0 +1,46 @@ +// TODO api needs to be async + +pub async fn login(email: &str, password: &str) -> (String, u32, String) { + let client = + crate::api::Client::new_self_hosted("https://bitwarden.tozt.net"); + + let iterations = client.prelogin(&email).await.unwrap(); + let identity = + crate::identity::Identity::new(&email, &password, iterations) + .unwrap(); + + let (access_token, _refresh_token, protected_key) = client + .login(&identity.email, &identity.master_password_hash) + .await + .unwrap(); + + (access_token, iterations, protected_key) +} + +pub async fn unlock( + email: &str, + password: &str, + iterations: u32, + protected_key: String, +) -> (Vec<u8>, Vec<u8>) { + let identity = + crate::identity::Identity::new(&email, &password, iterations) + .unwrap(); + + let protected_key = + crate::cipherstring::CipherString::new(&protected_key).unwrap(); + let master_key = protected_key + .decrypt(&identity.enc_key, &identity.mac_key) + .unwrap(); + + let enc_key = &master_key[0..32]; + let mac_key = &master_key[32..64]; + + (enc_key.to_vec(), mac_key.to_vec()) +} + +pub async fn sync(access_token: &str) -> (String, Vec<crate::api::Cipher>) { + let client = + crate::api::Client::new_self_hosted("https://bitwarden.tozt.net"); + client.sync(access_token).await.unwrap() +} |