aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-04-08 04:05:36 -0400
committerJesse Luehrs <doy@tozt.net>2020-04-08 04:05:36 -0400
commitc255e08021bf722558988b5a08c8e1427488c618 (patch)
tree5b1110908f5853f1e79f85afa359b8e51d87d270 /src
parentbc04f794ca08395577d507c0a746d3d7b01e29dc (diff)
downloadrbw-c255e08021bf722558988b5a08c8e1427488c618.tar.gz
rbw-c255e08021bf722558988b5a08c8e1427488c618.zip
also use cipherstring objects
Diffstat (limited to 'src')
-rw-r--r--src/actions.rs15
-rw-r--r--src/bin/agent.rs7
2 files changed, 13 insertions, 9 deletions
diff --git a/src/actions.rs b/src/actions.rs
index 10ce357..3658139 100644
--- a/src/actions.rs
+++ b/src/actions.rs
@@ -3,7 +3,12 @@ use crate::prelude::*;
pub async fn login(
email: &str,
password: &crate::locked::Password,
-) -> Result<(String, u32, String, crate::locked::Keys)> {
+) -> Result<(
+ String,
+ u32,
+ crate::cipherstring::CipherString,
+ crate::locked::Keys,
+)> {
let client =
crate::api::Client::new_self_hosted("https://bitwarden.tozt.net");
@@ -14,9 +19,9 @@ pub async fn login(
let (access_token, _refresh_token, protected_key) = client
.login(&identity.email, &identity.master_password_hash)
.await?;
- let protected_key_cs =
+ let protected_key =
crate::cipherstring::CipherString::new(&protected_key)?;
- let master_keys = protected_key_cs.decrypt_locked(&identity.keys)?;
+ let master_keys = protected_key.decrypt_locked(&identity.keys)?;
Ok((
access_token,
@@ -30,13 +35,11 @@ pub async fn unlock(
email: &str,
password: &crate::locked::Password,
iterations: u32,
- protected_key: String,
+ protected_key: &crate::cipherstring::CipherString,
) -> Result<crate::locked::Keys> {
let identity =
crate::identity::Identity::new(email, password, iterations)?;
- let protected_key =
- crate::cipherstring::CipherString::new(&protected_key)?;
let master_keys = protected_key.decrypt_locked(&identity.keys)?;
Ok(crate::locked::Keys::new(master_keys))
diff --git a/src/bin/agent.rs b/src/bin/agent.rs
index 262a826..9ee5f32 100644
--- a/src/bin/agent.rs
+++ b/src/bin/agent.rs
@@ -74,7 +74,7 @@ async fn unlock(
email,
&password,
state.iterations.unwrap(),
- state.protected_key.as_ref().unwrap().to_string(),
+ state.protected_key.as_ref().unwrap(),
)
.await
.unwrap();
@@ -93,7 +93,8 @@ async fn sync(
rbw::actions::sync(state.access_token.as_ref().unwrap())
.await
.unwrap();
- state.protected_key = Some(protected_key);
+ state.protected_key =
+ Some(rbw::cipherstring::CipherString::new(&protected_key).unwrap());
println!("{}", serde_json::to_string(&ciphers).unwrap());
state.ciphers = ciphers;
@@ -151,7 +152,7 @@ struct State {
// these should be in a state file
iterations: Option<u32>,
- protected_key: Option<String>,
+ protected_key: Option<rbw::cipherstring::CipherString>,
ciphers: Vec<rbw::api::Cipher>,
}