Merge pull request #90 from dyc3/manifest-unit-tests2
fixes SDA manifest parsing compatibility
This commit is contained in:
commit
ac3811ddbd
3 changed files with 38 additions and 10 deletions
|
@ -31,12 +31,21 @@ pub struct Manifest {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct ManifestEntry {
|
pub struct ManifestEntry {
|
||||||
pub encryption_iv: Option<String>,
|
|
||||||
pub encryption_salt: Option<String>,
|
|
||||||
pub filename: String,
|
pub filename: String,
|
||||||
#[serde(rename = "steamid")]
|
#[serde(default, rename = "steamid")]
|
||||||
pub steam_id: u64,
|
pub steam_id: u64,
|
||||||
|
#[serde(default)]
|
||||||
pub account_name: String,
|
pub account_name: String,
|
||||||
|
#[serde(default, flatten)]
|
||||||
|
pub encryption: Option<EntryEncryptionParams>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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 {
|
impl Default for Manifest {
|
||||||
|
@ -76,16 +85,13 @@ impl Manifest {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_accounts(&mut self) -> anyhow::Result<()> {
|
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);
|
let path = Path::new(&self.folder).join(&entry.filename);
|
||||||
debug!("loading account: {:?}", path);
|
debug!("loading account: {:?}", path);
|
||||||
let file = File::open(path)?;
|
let file = File::open(path)?;
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
let account: SteamGuardAccount = serde_json::from_reader(reader)?;
|
let account: SteamGuardAccount = serde_json::from_reader(reader)?;
|
||||||
ensure!(
|
entry.account_name = account.account_name.clone();
|
||||||
account.account_name == entry.account_name,
|
|
||||||
"Account name in file does not match manifest entry."
|
|
||||||
);
|
|
||||||
self.accounts.push(Arc::new(Mutex::new(account)));
|
self.accounts.push(Arc::new(Mutex::new(account)));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -98,8 +104,7 @@ impl Manifest {
|
||||||
filename: format!("{}.maFile", &account.account_name),
|
filename: format!("{}.maFile", &account.account_name),
|
||||||
steam_id: steamid,
|
steam_id: steamid,
|
||||||
account_name: account.account_name.clone(),
|
account_name: account.account_name.clone(),
|
||||||
encryption_iv: None,
|
encryption: None,
|
||||||
encryption_salt: None,
|
|
||||||
});
|
});
|
||||||
self.accounts.push(Arc::new(Mutex::new(account)));
|
self.accounts.push(Arc::new(Mutex::new(account)));
|
||||||
}
|
}
|
||||||
|
@ -243,4 +248,25 @@ mod tests {
|
||||||
"secret"
|
"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
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
1
steamguard/src/fixtures/maFiles/1-account/1234.maFile
Normal file
1
steamguard/src/fixtures/maFiles/1-account/1234.maFile
Normal file
|
@ -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}}
|
1
steamguard/src/fixtures/maFiles/1-account/manifest.json
Normal file
1
steamguard/src/fixtures/maFiles/1-account/manifest.json
Normal file
|
@ -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}
|
Loading…
Reference in a new issue