aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-05-03 01:07:58 -0400
committerJesse Luehrs <doy@tozt.net>2020-05-03 01:07:58 -0400
commite28b23f713fda315d28aaf6a375a720aae166f78 (patch)
tree4e4d833a234a06e1c3efbd21030a8ac9984a2ae0
parent047550f2368d134c9d5dca60aeb0b56fe151a323 (diff)
downloadrbw-e28b23f713fda315d28aaf6a375a720aae166f78.tar.gz
rbw-e28b23f713fda315d28aaf6a375a720aae166f78.zip
save the private key to the local db
-rw-r--r--src/actions.rs4
-rw-r--r--src/api.rs10
-rw-r--r--src/bin/rbw-agent/actions.rs3
-rw-r--r--src/db.rs1
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>, (String, Vec<crate::db::Entry>))> {
+) -> Result<(Option<String>, (String, String, Vec<crate::db::Entry>))> {
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<crate::db::Entry>)> {
+) -> Result<(String, String, Vec<crate::db::Entry>)> {
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<crate::db::Entry>)> {
+ ) -> Result<(String, String, Vec<crate::db::Entry>)> {
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<u32>,
pub protected_key: Option<String>,
+ pub protected_private_key: Option<String>,
pub entries: Vec<Entry>,
}