From 1b213841e9bbcbc27899f8d010cb2d6059fe868c Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Sat, 14 Aug 2021 20:47:29 -0400 Subject: [PATCH] fixes SDA manifest parsing compatibility --- src/accountmanager.rs | 46 +++++++++++++++---- .../fixtures/maFiles/1-account/1234.maFile | 1 + .../fixtures/maFiles/1-account/manifest.json | 1 + 3 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 steamguard/src/fixtures/maFiles/1-account/1234.maFile create mode 100644 steamguard/src/fixtures/maFiles/1-account/manifest.json diff --git a/src/accountmanager.rs b/src/accountmanager.rs index 5d62762..e4f2826 100644 --- a/src/accountmanager.rs +++ b/src/accountmanager.rs @@ -31,12 +31,21 @@ pub struct Manifest { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ManifestEntry { - pub encryption_iv: Option, - pub encryption_salt: Option, pub filename: String, - #[serde(rename = "steamid")] + #[serde(default, rename = "steamid")] pub steam_id: u64, + #[serde(default)] pub account_name: String, + #[serde(default, flatten)] + pub encryption: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct EntryEncryptionParams { + #[serde(rename = "encryption_iv")] + pub iv: String, + #[serde(rename = "encryption_salt")] + pub salt: String, } impl Default for Manifest { @@ -76,16 +85,13 @@ impl Manifest { } pub fn load_accounts(&mut self) -> anyhow::Result<()> { - for entry in &self.entries { + for entry in &mut self.entries { let path = Path::new(&self.folder).join(&entry.filename); debug!("loading account: {:?}", path); let file = File::open(path)?; let reader = BufReader::new(file); let account: SteamGuardAccount = serde_json::from_reader(reader)?; - ensure!( - account.account_name == entry.account_name, - "Account name in file does not match manifest entry." - ); + entry.account_name = account.account_name.clone(); self.accounts.push(Arc::new(Mutex::new(account))); } Ok(()) @@ -98,8 +104,7 @@ impl Manifest { filename: format!("{}.maFile", &account.account_name), steam_id: steamid, account_name: account.account_name.clone(), - encryption_iv: None, - encryption_salt: None, + encryption: None, }); self.accounts.push(Arc::new(Mutex::new(account))); } @@ -243,4 +248,25 @@ mod tests { "secret" ); } + + #[test] + fn test_sda_compatibility_1() { + let path = Path::new("steamguard/src/fixtures/maFiles/1-account/manifest.json"); + assert!(path.is_file()); + let result = Manifest::load(path); + assert!(matches!(result, Ok(_))); + let mut manifest = result.unwrap(); + assert!(matches!(manifest.entries.last().unwrap().encryption, None)); + assert!(matches!(manifest.load_accounts(), Ok(_))); + assert_eq!( + manifest.entries.last().unwrap().account_name, + manifest + .accounts + .last() + .unwrap() + .lock() + .unwrap() + .account_name + ); + } } diff --git a/steamguard/src/fixtures/maFiles/1-account/1234.maFile b/steamguard/src/fixtures/maFiles/1-account/1234.maFile new file mode 100644 index 0000000..8576895 --- /dev/null +++ b/steamguard/src/fixtures/maFiles/1-account/1234.maFile @@ -0,0 +1 @@ +{"shared_secret":"secret1234","serial_number":"kljasfhds","revocation_code":"R12345","uri":"otpauth://totp/Steam:example?secret=ASDF&issuer=Steam","server_time":1602522478,"account_name":"example","token_gid":"jkkjlhkhjgf","identity_secret":"kjsdlwowiqe=","secret_1":"sklduhfgsdlkjhf=","status":1,"device_id":"android:99d2ad0e-4bad-4247-b111-26393aae0be3","fully_enrolled":true,"Session":{"SessionID":"a;lskdjf","SteamLogin":"983498437543","SteamLoginSecure":"dlkjdsl;j%7C%32984730298","WebCookie":";lkjsed;klfjas98093","OAuthToken":"asdk;lf;dsjlkfd","SteamID":1234}} \ No newline at end of file diff --git a/steamguard/src/fixtures/maFiles/1-account/manifest.json b/steamguard/src/fixtures/maFiles/1-account/manifest.json new file mode 100644 index 0000000..7c2ed9f --- /dev/null +++ b/steamguard/src/fixtures/maFiles/1-account/manifest.json @@ -0,0 +1 @@ +{"encrypted":false,"first_run":true,"entries":[{"encryption_iv":null,"encryption_salt":null,"filename":"1234.maFile","steamid":1234}],"periodic_checking":false,"periodic_checking_interval":5,"periodic_checking_checkall":false,"auto_confirm_market_transactions":false,"auto_confirm_trades":false} \ No newline at end of file