add working manifest loading

This commit is contained in:
Carson McManus 2021-03-25 19:47:44 -04:00
parent 196e4ffdb8
commit 05b944c40b
5 changed files with 62 additions and 27 deletions

5
Cargo.lock generated
View file

@ -1145,9 +1145,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]] [[package]]
name = "standback" name = "standback"
version = "0.2.16" version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "decebb311175fdaf1bf8a14583716e93163c566db2ead1c1d608c3e1e4313cb8" checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff"
dependencies = [ dependencies = [
"version_check", "version_check",
] ]
@ -1213,6 +1213,7 @@ dependencies = [
"rsa", "rsa",
"serde", "serde",
"serde_json", "serde_json",
"standback",
"text_io", "text_io",
] ]

View file

@ -16,3 +16,4 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
rsa = "0.3" rsa = "0.3"
rand = "0.7.3" # rsa is not compatible with rand 0.8: https://github.com/RustCrypto/RSA/issues/81 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

View file

@ -1,4 +1,8 @@
use std::fs::File;
use std::io::BufReader;
use std::path::Path;
use serde::{Serialize, Deserialize}; use serde::{Serialize, Deserialize};
use std::error::Error;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Manifest { pub struct Manifest {
@ -11,16 +15,36 @@ pub struct Manifest {
pub auto_confirm_market_transactions: bool, pub auto_confirm_market_transactions: bool,
pub auto_confirm_trades: bool, pub auto_confirm_trades: bool,
#[serde(skip)] // #[serde(skip)]
pub accounts: Vec<SteamGuardAccount> // pub accounts: Vec<SteamGuardAccount>,
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ManifestEntry { pub struct ManifestEntry {
pub encryption_iv: String, pub encryption_iv: Option<String>,
pub encryption_salt: String, pub encryption_salt: Option<String>,
pub filename: String, pub filename: String,
#[serde(rename = "steamid")]
pub steam_id: u64, pub steam_id: u64,
} }
impl Manifest {
pub fn load(path: &Path) -> Result<Manifest, Box<dyn Error>> {
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));
}
}
}
}

View file

@ -3,27 +3,34 @@ use io::Write;
use steamguard_cli::*; use steamguard_cli::*;
use ::std::*; use ::std::*;
use text_io::read; use text_io::read;
use std::path::Path;
mod steamapi; mod steamapi;
mod accountmanager;
fn main() { fn main() {
println!("Hello, world!"); println!("Hello, world!");
let server_time = steamapi::get_server_time(); // let server_time = steamapi::get_server_time();
println!("server time: {}", server_time); // println!("server time: {}", server_time);
let mut account = SteamGuardAccount::new(); // let mut account = SteamGuardAccount::new();
account.shared_secret = parse_shared_secret(String::from("K5I0Fmm+sN0yF41vIslTVm+0nPE=")); // account.shared_secret = parse_shared_secret(String::from("K5I0Fmm+sN0yF41vIslTVm+0nPE="));
let code = account.generate_code(server_time); // let code = account.generate_code(server_time);
println!("{}", code); // println!("{}", code);
print!("Username: "); // print!("Username: ");
let _ = std::io::stdout().flush(); // let _ = std::io::stdout().flush();
let username: String = read!("{}\n"); // let username: String = read!("{}\n");
let password = rpassword::prompt_password_stdout("Password: ").unwrap(); // let password = rpassword::prompt_password_stdout("Password: ").unwrap();
// println!("{}:{}", username, password); // // println!("{}:{}", username, password);
let login = steamapi::UserLogin::new(username, password); // let login = steamapi::UserLogin::new(username, password);
let result = login.login(); // let result = login.login();
println!("result: {:?}", result); // println!("result: {:?}", result);
let path = Path::new("test_maFiles/manifest.json");
let manifest = accountmanager::Manifest::load(path);
println!("{:?}", manifest);
} }

View file

@ -101,9 +101,9 @@ impl UserLogin {
.send(); .send();
} }
pub fn login(&self) -> LoginResult { pub fn login(&mut self) -> LoginResult {
if self.captcha_required && self.captcha_text.len() == 0 { 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::<Url>().unwrap(); let url = "https://steamcommunity.com".parse::<Url>().unwrap();
@ -187,12 +187,12 @@ impl UserLogin {
} }
if login_resp.captcha_needed { if login_resp.captcha_needed {
self.captcha_gid = login_resp.captcha_gid; self.captcha_gid = login_resp.captcha_gid.clone();
return LoginResult::NeedCaptcha{ captcha_gid: self.captcha_gid }; return LoginResult::NeedCaptcha{ captcha_gid: self.captcha_gid.clone() };
} }
if login_resp.emailauth_needed { if login_resp.emailauth_needed {
self.steam_id = login_resp.emailsteamid; self.steam_id = login_resp.emailsteamid.clone();
return LoginResult::NeedEmail; return LoginResult::NeedEmail;
} }
@ -204,7 +204,7 @@ impl UserLogin {
return LoginResult::BadCredentials; 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); let session = self.build_session(oauth);
return LoginResult::Ok{session}; return LoginResult::Ok{session};
@ -222,6 +222,7 @@ impl UserLogin {
} }
} }
#[derive(Debug, Clone, Deserialize)]
struct OAuthData { struct OAuthData {
oauth_token: String, oauth_token: String,
steamid: u64, steamid: u64,
@ -230,6 +231,7 @@ struct OAuthData {
webcookie: String, webcookie: String,
} }
#[derive(Debug, Clone, Deserialize)]
pub struct Session { pub struct Session {
pub session_id: String, pub session_id: String,
pub steam_login: String, pub steam_login: String,