added report signature and fixed client_version in server

This commit is contained in:
2026-03-25 12:45:50 +01:00
parent 4b0ccce606
commit 6a0340686d
4 changed files with 51 additions and 11 deletions

10
Cargo.lock generated
View File

@@ -422,6 +422,15 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
[[package]]
name = "enable-ansi-support"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea7457668b3da8a4b702f3d79e131aa3e81cd7e81cc95fb2d54fce9f182ecc77"
dependencies = [
"windows-sys 0.61.2",
]
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.35" version = "0.8.35"
@@ -1872,6 +1881,7 @@ dependencies = [
"colored", "colored",
"cpal", "cpal",
"display-info", "display-info",
"enable-ansi-support",
"mac_address", "mac_address",
"num_cpus", "num_cpus",
"reqwest", "reqwest",

View File

@@ -9,6 +9,7 @@ clap = { version = "4.6.0", features = ["cargo", "derive"] }
colored = "3.1.1" colored = "3.1.1"
cpal = { version = "0.17.3", optional = true } cpal = { version = "0.17.3", optional = true }
display-info = { version = "0.5.9", optional = true } display-info = { version = "0.5.9", optional = true }
enable-ansi-support = "0.3.1"
mac_address = "1.1.8" mac_address = "1.1.8"
num_cpus = "1.17.0" num_cpus = "1.17.0"
reqwest = { version = "0.13.2", features = ["blocking", "json"] } reqwest = { version = "0.13.2", features = ["blocking", "json"] }

View File

@@ -46,6 +46,8 @@ pub struct FullReport {
pub timestamp: String, pub timestamp: String,
pub slimes: Option<HashMap<String, Vec<String>>>, pub slimes: Option<HashMap<String, Vec<String>>>,
pub benchmark: Option<BenchmarkReport>, pub benchmark: Option<BenchmarkReport>,
pub client_version: String,
pub signature: String,
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@@ -70,14 +72,19 @@ async fn submit(
let raw_json = serde_json::to_string(&payload) let raw_json = serde_json::to_string(&payload)
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
sqlx::query("INSERT INTO reports (mac_address, score, timestamp, data) VALUES (?, ?, ?, ?)") sqlx::query(
.bind(payload.mac_address) "INSERT INTO reports (mac_address, score, timestamp, client_version, signature, data)
.bind(score as i64) VALUES (?, ?, ?, ?, ?, ?)",
.bind(payload.timestamp) )
.bind(raw_json) .bind(&payload.mac_address)
.execute(&state.db) .bind(score as i64)
.await .bind(&payload.timestamp)
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; .bind(&payload.client_version)
.bind(&payload.signature)
.bind(raw_json)
.execute(&state.db)
.await
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
Ok(StatusCode::CREATED) Ok(StatusCode::CREATED)
} }
@@ -142,6 +149,8 @@ async fn main() -> anyhow::Result<()> {
mac_address TEXT NOT NULL, mac_address TEXT NOT NULL,
score INTEGER NOT NULL, score INTEGER NOT NULL,
timestamp TEXT NOT NULL, timestamp TEXT NOT NULL,
client_version TEXT NOT NULL,
signature TEXT,
data TEXT NOT NULL data TEXT NOT NULL
);", );",
) )

View File

@@ -58,6 +58,7 @@ struct FullReport {
slimes: Option<HashMap<String, Vec<String>>>, slimes: Option<HashMap<String, Vec<String>>>,
benchmark: Option<BenchmarkReport>, benchmark: Option<BenchmarkReport>,
client_version: String, client_version: String,
signature: String,
} }
#[derive(Serialize)] #[derive(Serialize)]
@@ -69,6 +70,9 @@ struct BenchmarkReport {
} }
fn main() { fn main() {
#[cfg(windows)]
let _ = enable_ansi_support::enable_ansi_support();
let cli = Cli::parse(); let cli = Cli::parse();
let mut report = FullReport { let mut report = FullReport {
mac_address: get_mac_address() mac_address: get_mac_address()
@@ -80,6 +84,7 @@ fn main() {
slimes: None, slimes: None,
benchmark: None, benchmark: None,
client_version: crate_version!().to_string(), client_version: crate_version!().to_string(),
signature: String::new(),
}; };
vprintln!( vprintln!(
@@ -152,18 +157,33 @@ fn main() {
} }
if !cli.offline { if !cli.offline {
let json_payload = serde_json::to_string_pretty(&report).unwrap();
vprintln!(cli.verbose, "Generated JSON report: {:?}", &json_payload);
println!(); println!();
if !confirm_upload() { if !confirm_upload() {
return; return;
} }
report.signature = sign_upload();
let json_payload = serde_json::to_string_pretty(&report).unwrap();
vprintln!(cli.verbose, "Generated JSON report: {:?}", &json_payload);
send_to_server(&cli.server_url, &report); send_to_server(&cli.server_url, &report);
} }
} }
fn sign_upload() -> String {
print!("Please sign your report, it should allow to identify it (or leave empty): ");
io::stdout().flush().unwrap();
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
let input = input.trim().to_string();
input
}
fn confirm_upload() -> bool { fn confirm_upload() -> bool {
print!("Send data to leaderboard server? [Y/n] "); print!("Send data to leaderboard server? [Y/n] ");
io::stdout().flush().unwrap(); io::stdout().flush().unwrap();