aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-10-27 20:51:54 -0400
committerJesse Luehrs <doy@tozt.net>2021-10-27 21:02:21 -0400
commit7b95f7b9d84c44ca273c1a1ce7ab62925d4a5def (patch)
tree5a61f1f41fbe2aeeb2520d83bd292123d7a84fc9
parent9acabc3a7497e3eb3536992212d34f77a649ae16 (diff)
downloadrbw-7b95f7b9d84c44ca273c1a1ce7ab62925d4a5def.tar.gz
rbw-7b95f7b9d84c44ca273c1a1ce7ab62925d4a5def.zip
use a persistent device id
-rw-r--r--src/actions.rs1
-rw-r--r--src/api.rs5
-rw-r--r--src/config.rs17
3 files changed, 19 insertions, 4 deletions
diff --git a/src/actions.rs b/src/actions.rs
index dc4f9df..b65226c 100644
--- a/src/actions.rs
+++ b/src/actions.rs
@@ -14,6 +14,7 @@ pub async fn login(
let (access_token, refresh_token, protected_key) = client
.login(
email,
+ &config.device_id,
&creds.to_hashed(email, iterations)?,
two_factor_token,
two_factor_provider,
diff --git a/src/api.rs b/src/api.rs
index 62a4a55..f4198b5 100644
--- a/src/api.rs
+++ b/src/api.rs
@@ -579,6 +579,7 @@ impl Client {
pub async fn login(
&self,
email: &str,
+ device_id: &str,
creds: &crate::locked::HashedLoginCredentials,
two_factor_token: Option<&str>,
two_factor_provider: Option<TwoFactorProviderType>,
@@ -612,9 +613,7 @@ impl Client {
client_secret: client_secret
.map(|secret| String::from_utf8(secret.to_vec()).unwrap()),
device_type: 8,
- device_identifier: uuid::Uuid::new_v4()
- .to_hyphenated()
- .to_string(),
+ device_identifier: device_id.to_string(),
device_name: "rbw".to_string(),
device_push_token: "".to_string(),
two_factor_token: two_factor_token
diff --git a/src/config.rs b/src/config.rs
index c6e0787..bbc39f7 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -12,6 +12,8 @@ pub struct Config {
pub lock_timeout: u64,
#[serde(default = "default_pinentry")]
pub pinentry: String,
+ #[serde(default = "stub_device_id")]
+ pub device_id: String,
}
impl Default for Config {
@@ -22,6 +24,7 @@ impl Default for Config {
identity_url: Default::default(),
lock_timeout: default_lock_timeout(),
pinentry: default_pinentry(),
+ device_id: default_device_id(),
}
}
}
@@ -34,6 +37,14 @@ pub fn default_pinentry() -> String {
"pinentry".to_string()
}
+fn default_device_id() -> String {
+ uuid::Uuid::new_v4().to_hyphenated().to_string()
+}
+
+fn stub_device_id() -> String {
+ String::from("fix")
+}
+
impl Config {
pub fn new() -> Self {
Self::default()
@@ -116,10 +127,14 @@ impl Config {
}
pub fn validate() -> Result<()> {
- let config = Self::load()?;
+ let mut config = Self::load()?;
if config.email.is_none() {
return Err(Error::ConfigMissingEmail);
}
+ if config.device_id == stub_device_id() {
+ config.device_id = default_device_id();
+ config.save()?;
+ }
Ok(())
}