Add signature checking to requests

This commit is contained in:
Lncvrt committed 2026-02-28 12:57:10 -07:00
1 parent fbf87dceba
commit 6b7b2b198a
10 files changed
+118 -40

No files matched your search

+3
View File
@@ -30,6 +30,9 @@ sysinfo = "0.38.2"
sha2 = "0.10.9"
tauri-plugin-clipboard-manager = "2.3.2"
tauri-plugin-prevent-default = "4.0.4"
openssl = { version = "0.10.75", features = ["v110"] }
base64 = "0.22.1"
tauri-plugin-http = "2.5.7"
[target.'cfg(target_os = "linux")'.dependencies]
shlex = "1.3.0"
+14
View File
@@ -38,6 +38,20 @@
"allow": [
{ "path": "$APPLOCALDATA/game/**" }
]
},
{
"identifier": "http:default",
"allow": [
{ "url": "https://games.lncvrt.xyz/api/launcher/latest" },
{ "url": "https://games.lncvrt.xyz/api/launcher/versions" },
{ "url": "https://games.lncvrt.xyz/api/launcher/download" },
{ "url": "https://games.lncvrt.xyz/api/berrydash/account" },
{ "url": "https://games.lncvrt.xyz/api/berrydash/leaderboard/score" },
{ "url": "https://games.lncvrt.xyz/api/berrydash/leaderboard/berry" },
{ "url": "https://games.lncvrt.xyz/api/berrydash/leaderboard/coin" },
{ "url": "https://games.lncvrt.xyz/api/berrydash/leaderboard/legacy" },
{ "url": "https://games.lncvrt.xyz/api/berrydash/leaderboard/total" }
]
}
]
}
+32 -1
View File
@@ -1,4 +1,7 @@
use base64::{Engine as _, engine::general_purpose};
use futures_util::stream::StreamExt;
use openssl::pkey::PKey;
use openssl::sign::Verifier;
use sha2::{Digest, Sha512};
use std::fs;
use std::path::Path;
@@ -415,10 +418,33 @@ fn launch_game(
}
}
#[tauri::command]
fn verify_signature(body: String, signature: String, public_key: String) -> bool {
let Ok(pem) = general_purpose::STANDARD.decode(public_key) else {
return false;
};
let Ok(pubkey) = PKey::public_key_from_pem(&pem) else {
return false;
};
let Ok(sig) = general_purpose::STANDARD.decode(signature) else {
return false;
};
let mut verifier = match Verifier::new_without_digest(&pubkey) {
Ok(v) => v,
Err(_) => return false,
};
verifier
.verify_oneshot(&sig, body.as_bytes())
.unwrap_or(false)
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
#[allow(unused_variables)]
tauri::Builder::default()
.plugin(tauri_plugin_http::init())
.plugin(
tauri_plugin_prevent_default::Builder::new()
.with_flags(
@@ -448,7 +474,12 @@ pub fn run() {
.plugin(tauri_plugin_decorum::init())
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![download, launch_game, folder_size])
.invoke_handler(tauri::generate_handler![
download,
launch_game,
folder_size,
verify_signature
])
.setup(|app| {
#[cfg(target_os = "windows")]
{