From 7b95f7b9d84c44ca273c1a1ce7ab62925d4a5def Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 27 Oct 2021 20:51:54 -0400 Subject: use a persistent device id --- src/actions.rs | 1 + src/api.rs | 5 ++--- src/config.rs | 17 ++++++++++++++++- 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, @@ -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(()) } -- cgit v1.2.3-54-g00ecf