From 05b944c40b9b282b566cff185af586424fe2ba0c Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Thu, 25 Mar 2021 19:47:44 -0400 Subject: [PATCH] add working manifest loading --- Cargo.lock | 5 +++-- Cargo.toml | 1 + src/accountmanager.rs | 34 +++++++++++++++++++++++++++++----- src/main.rs | 35 +++++++++++++++++++++-------------- src/steamapi.rs | 14 ++++++++------ 5 files changed, 62 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18e16eb..dd57b04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1145,9 +1145,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "standback" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "decebb311175fdaf1bf8a14583716e93163c566db2ead1c1d608c3e1e4313cb8" +checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" dependencies = [ "version_check", ] @@ -1213,6 +1213,7 @@ dependencies = [ "rsa", "serde", "serde_json", + "standback", "text_io", ] diff --git a/Cargo.toml b/Cargo.toml index acd79a2..654ae9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" rsa = "0.3" rand = "0.7.3" # rsa is not compatible with rand 0.8: https://github.com/RustCrypto/RSA/issues/81 +standback = "0.2.17" # required to fix a compilation error on a transient dependency \ No newline at end of file diff --git a/src/accountmanager.rs b/src/accountmanager.rs index 60466eb..c2cda60 100644 --- a/src/accountmanager.rs +++ b/src/accountmanager.rs @@ -1,4 +1,8 @@ +use std::fs::File; +use std::io::BufReader; +use std::path::Path; use serde::{Serialize, Deserialize}; +use std::error::Error; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Manifest { @@ -11,16 +15,36 @@ pub struct Manifest { pub auto_confirm_market_transactions: bool, pub auto_confirm_trades: bool, - #[serde(skip)] - pub accounts: Vec + // #[serde(skip)] + // pub accounts: Vec, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ManifestEntry { - pub encryption_iv: String, - pub encryption_salt: String, + pub encryption_iv: Option, + pub encryption_salt: Option, pub filename: String, + #[serde(rename = "steamid")] pub steam_id: u64, } - +impl Manifest { + pub fn load(path: &Path) -> Result> { + match File::open(path) { + Ok(file) => { + let reader = BufReader::new(file); + match serde_json::from_reader(reader) { + Ok(manifest) => { + return Ok(manifest); + } + Err(e) => { + return Err(Box::new(e)); + } + } + } + Err(e) => { + return Err(Box::new(e)); + } + } + } +} diff --git a/src/main.rs b/src/main.rs index a04b62a..0a52188 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,27 +3,34 @@ use io::Write; use steamguard_cli::*; use ::std::*; use text_io::read; +use std::path::Path; mod steamapi; +mod accountmanager; fn main() { println!("Hello, world!"); - let server_time = steamapi::get_server_time(); - println!("server time: {}", server_time); + // let server_time = steamapi::get_server_time(); + // println!("server time: {}", server_time); - let mut account = SteamGuardAccount::new(); - account.shared_secret = parse_shared_secret(String::from("K5I0Fmm+sN0yF41vIslTVm+0nPE=")); + // let mut account = SteamGuardAccount::new(); + // account.shared_secret = parse_shared_secret(String::from("K5I0Fmm+sN0yF41vIslTVm+0nPE=")); - let code = account.generate_code(server_time); - println!("{}", code); + // let code = account.generate_code(server_time); + // println!("{}", code); - print!("Username: "); - let _ = std::io::stdout().flush(); - let username: String = read!("{}\n"); - let password = rpassword::prompt_password_stdout("Password: ").unwrap(); - // println!("{}:{}", username, password); - let login = steamapi::UserLogin::new(username, password); - let result = login.login(); - println!("result: {:?}", result); + // print!("Username: "); + // let _ = std::io::stdout().flush(); + // let username: String = read!("{}\n"); + // let password = rpassword::prompt_password_stdout("Password: ").unwrap(); + // // println!("{}:{}", username, password); + // let login = steamapi::UserLogin::new(username, password); + // let result = login.login(); + // println!("result: {:?}", result); + + let path = Path::new("test_maFiles/manifest.json"); + let manifest = accountmanager::Manifest::load(path); + + println!("{:?}", manifest); } diff --git a/src/steamapi.rs b/src/steamapi.rs index a98e8eb..88f45ac 100644 --- a/src/steamapi.rs +++ b/src/steamapi.rs @@ -101,9 +101,9 @@ impl UserLogin { .send(); } - pub fn login(&self) -> LoginResult { + pub fn login(&mut self) -> LoginResult { if self.captcha_required && self.captcha_text.len() == 0 { - return LoginResult::NeedCaptcha{captcha_gid: self.captcha_gid}; + return LoginResult::NeedCaptcha{captcha_gid: self.captcha_gid.clone()}; } let url = "https://steamcommunity.com".parse::().unwrap(); @@ -187,12 +187,12 @@ impl UserLogin { } if login_resp.captcha_needed { - self.captcha_gid = login_resp.captcha_gid; - return LoginResult::NeedCaptcha{ captcha_gid: self.captcha_gid }; + self.captcha_gid = login_resp.captcha_gid.clone(); + return LoginResult::NeedCaptcha{ captcha_gid: self.captcha_gid.clone() }; } if login_resp.emailauth_needed { - self.steam_id = login_resp.emailsteamid; + self.steam_id = login_resp.emailsteamid.clone(); return LoginResult::NeedEmail; } @@ -204,7 +204,7 @@ impl UserLogin { return LoginResult::BadCredentials; } - let oauth: OAuthData = serde_json::from_str(login_resp.oauth).unwrap(); + let oauth: OAuthData = serde_json::from_str(login_resp.oauth.as_str()).unwrap(); let session = self.build_session(oauth); return LoginResult::Ok{session}; @@ -222,6 +222,7 @@ impl UserLogin { } } +#[derive(Debug, Clone, Deserialize)] struct OAuthData { oauth_token: String, steamid: u64, @@ -230,6 +231,7 @@ struct OAuthData { webcookie: String, } +#[derive(Debug, Clone, Deserialize)] pub struct Session { pub session_id: String, pub steam_login: String,