From e28b23f713fda315d28aaf6a375a720aae166f78 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 3 May 2020 01:07:58 -0400 Subject: save the private key to the local db --- src/actions.rs | 4 ++-- src/api.rs | 10 ++++++++-- src/bin/rbw-agent/actions.rs | 3 ++- src/db.rs | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/actions.rs b/src/actions.rs index 67a9523..861d734 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -49,7 +49,7 @@ pub async fn unlock( pub async fn sync( access_token: &str, refresh_token: &str, -) -> Result<(Option, (String, Vec))> { +) -> Result<(Option, (String, String, Vec))> { with_exchange_refresh_token_async( access_token, refresh_token, @@ -63,7 +63,7 @@ pub async fn sync( async fn sync_once( access_token: &str, -) -> Result<(String, Vec)> { +) -> Result<(String, String, Vec)> { let config = crate::config::Config::load_async().await?; let client = crate::api::Client::new(&config.base_url(), &config.identity_url()); diff --git a/src/api.rs b/src/api.rs index 768b005..41ed7be 100644 --- a/src/api.rs +++ b/src/api.rs @@ -146,6 +146,8 @@ impl SyncResCipher { struct SyncResProfile { #[serde(rename = "Key")] key: String, + #[serde(rename = "PrivateKey")] + private_key: String, } #[derive(serde::Deserialize, Debug, Clone)] @@ -319,7 +321,7 @@ impl Client { pub async fn sync( &self, access_token: &str, - ) -> Result<(String, Vec)> { + ) -> Result<(String, String, Vec)> { let client = reqwest::Client::new(); let res = client .get(&self.api_url("/sync")) @@ -337,7 +339,11 @@ impl Client { .iter() .filter_map(|cipher| cipher.to_entry(&folders)) .collect(); - Ok((sync_res.profile.key, ciphers)) + Ok(( + sync_res.profile.key, + sync_res.profile.private_key, + ciphers, + )) } reqwest::StatusCode::UNAUTHORIZED => { Err(Error::RequestUnauthorized) diff --git a/src/bin/rbw-agent/actions.rs b/src/bin/rbw-agent/actions.rs index afe76c8..d17f5f1 100644 --- a/src/bin/rbw-agent/actions.rs +++ b/src/bin/rbw-agent/actions.rs @@ -189,7 +189,7 @@ pub async fn sync(sock: &mut crate::sock::Sock) -> anyhow::Result<()> { } else { return Err(anyhow::anyhow!("failed to find refresh token in db")); }; - let (access_token, (protected_key, entries)) = + let (access_token, (protected_key, protected_private_key, entries)) = rbw::actions::sync(&access_token, &refresh_token) .await .context("failed to sync database from server")?; @@ -197,6 +197,7 @@ pub async fn sync(sock: &mut crate::sock::Sock) -> anyhow::Result<()> { db.access_token = Some(access_token); } db.protected_key = Some(protected_key); + db.protected_private_key = Some(protected_private_key); db.entries = entries; db.save_async(&email) .await diff --git a/src/db.rs b/src/db.rs index 51fecd1..af7a29c 100644 --- a/src/db.rs +++ b/src/db.rs @@ -32,6 +32,7 @@ pub struct Db { pub iterations: Option, pub protected_key: Option, + pub protected_private_key: Option, pub entries: Vec, } -- cgit v1.2.3-54-g00ecf