aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-05-03 02:38:01 -0400
committerJesse Luehrs <doy@tozt.net>2020-05-03 02:38:01 -0400
commit1b0b0e9eaa546f50f6916cc631edaaa7dc8442e8 (patch)
treeb464713fdc59bbdb9006842a03de9cbddbd1dddf
parente89ecaf0792dea1d36b6f071cb32bf79665c8e37 (diff)
downloadrbw-1b0b0e9eaa546f50f6916cc631edaaa7dc8442e8.tar.gz
rbw-1b0b0e9eaa546f50f6916cc631edaaa7dc8442e8.zip
also store org keys in the local db
-rw-r--r--src/actions.rs17
-rw-r--r--src/api.rs24
-rw-r--r--src/bin/rbw-agent/actions.rs11
-rw-r--r--src/db.rs1
4 files changed, 46 insertions, 7 deletions
diff --git a/src/actions.rs b/src/actions.rs
index 9284677..b891670 100644
--- a/src/actions.rs
+++ b/src/actions.rs
@@ -49,7 +49,15 @@ pub async fn unlock(
pub async fn sync(
access_token: &str,
refresh_token: &str,
-) -> Result<(Option<String>, (String, String, Vec<crate::db::Entry>))> {
+) -> Result<(
+ Option<String>,
+ (
+ String,
+ String,
+ std::collections::HashMap<String, String>,
+ Vec<crate::db::Entry>,
+ ),
+)> {
with_exchange_refresh_token_async(
access_token,
refresh_token,
@@ -63,7 +71,12 @@ pub async fn sync(
async fn sync_once(
access_token: &str,
-) -> Result<(String, String, Vec<crate::db::Entry>)> {
+) -> Result<(
+ String,
+ String,
+ std::collections::HashMap<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 41ed7be..03b9c6d 100644
--- a/src/api.rs
+++ b/src/api.rs
@@ -148,6 +148,16 @@ struct SyncResProfile {
key: String,
#[serde(rename = "PrivateKey")]
private_key: String,
+ #[serde(rename = "Organizations")]
+ organizations: Vec<SyncResProfileOrganization>,
+}
+
+#[derive(serde::Deserialize, Debug)]
+struct SyncResProfileOrganization {
+ #[serde(rename = "Id")]
+ id: String,
+ #[serde(rename = "Key")]
+ key: String,
}
#[derive(serde::Deserialize, Debug, Clone)]
@@ -321,7 +331,12 @@ impl Client {
pub async fn sync(
&self,
access_token: &str,
- ) -> Result<(String, String, Vec<crate::db::Entry>)> {
+ ) -> Result<(
+ String,
+ String,
+ std::collections::HashMap<String, String>,
+ Vec<crate::db::Entry>,
+ )> {
let client = reqwest::Client::new();
let res = client
.get(&self.api_url("/sync"))
@@ -339,9 +354,16 @@ impl Client {
.iter()
.filter_map(|cipher| cipher.to_entry(&folders))
.collect();
+ let org_keys = sync_res
+ .profile
+ .organizations
+ .iter()
+ .map(|org| (org.id.clone(), org.key.clone()))
+ .collect();
Ok((
sync_res.profile.key,
sync_res.profile.private_key,
+ org_keys,
ciphers,
))
}
diff --git a/src/bin/rbw-agent/actions.rs b/src/bin/rbw-agent/actions.rs
index 5b3444d..e24d044 100644
--- a/src/bin/rbw-agent/actions.rs
+++ b/src/bin/rbw-agent/actions.rs
@@ -189,15 +189,18 @@ 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, protected_private_key, entries)) =
- rbw::actions::sync(&access_token, &refresh_token)
- .await
- .context("failed to sync database from server")?;
+ let (
+ access_token,
+ (protected_key, protected_private_key, protected_org_keys, entries),
+ ) = rbw::actions::sync(&access_token, &refresh_token)
+ .await
+ .context("failed to sync database from server")?;
if let Some(access_token) = access_token {
db.access_token = Some(access_token);
}
db.protected_key = Some(protected_key);
db.protected_private_key = Some(protected_private_key);
+ db.protected_org_keys = protected_org_keys;
db.entries = entries;
db.save_async(&email)
.await
diff --git a/src/db.rs b/src/db.rs
index af7a29c..5f200ab 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -33,6 +33,7 @@ pub struct Db {
pub iterations: Option<u32>,
pub protected_key: Option<String>,
pub protected_private_key: Option<String>,
+ pub protected_org_keys: std::collections::HashMap<String, String>,
pub entries: Vec<Entry>,
}