feat: update script-verify.rs

This commit is contained in:
2025-09-09 23:11:08 +08:00
parent db816cc1e1
commit f74931f8bd
5 changed files with 113 additions and 32 deletions

View File

@@ -74,19 +74,19 @@
},
"osssendfile.rs": {
"script_name": "osssendfile.rs",
"script_length": 14012,
"script_sha256": "8998ca6866eb91be97b1d21aef8a74dd5a8d9072dca466fda81e952c0918df27",
"script_length": 14019,
"script_sha256": "2f18f0f2e66f05a0218347e72df5e9115e4ce469602693da06963afead464749",
"script_full_url": "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/osssendfile-rs/src/main.rs",
"publish_time": 1737272563311,
"update_time": 1750428425868
"update_time": 1757430653322
},
"post.rs": {
"script_name": "post.rs",
"script_length": 10655,
"script_sha256": "d99f7d9fd1d0c0b333c30e1cf87cd21bba3d069d2c850f4910ccffe0d486b27a",
"script_length": 10669,
"script_sha256": "0448ecd3ddcb76ce18c20bd3eb8106c108c6775b88400f179b875772acaf7678",
"script_full_url": "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/post-rs/src/main.rs",
"publish_time": 1737272563311,
"update_time": 1737647377227
"update_time": 1757430653320
},
"rpm-read.rs": {
"script_name": "rpm-read.rs",
@@ -106,11 +106,11 @@
},
"script-verify.rs": {
"script_name": "script-verify.rs",
"script_length": 2549,
"script_sha256": "157db0a7c444b46f97dc91fcd02fd2c081b1da5d9d5e335a9361747983244066",
"script_length": 5783,
"script_sha256": "f864fe6ab80437e363859fb6fb3721b7368421868ef3980c68a5c8aa60c0d6f9",
"script_full_url": "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/script-verify-rs/src/main.rs",
"publish_time": 1737563113466,
"update_time": 1737647377228
"update_time": 1757430653323
},
"sync.rs": {
"script_name": "sync.rs",

View File

@@ -41,13 +41,13 @@
},
"osssendfile-rs": {
"script_name": "osssendfile-rs",
"script_length": 14012,
"script_sha256": "8998ca6866eb91be97b1d21aef8a74dd5a8d9072dca466fda81e952c0918df27"
"script_length": 14019,
"script_sha256": "2f18f0f2e66f05a0218347e72df5e9115e4ce469602693da06963afead464749"
},
"post-rs": {
"script_name": "post-rs",
"script_length": 10655,
"script_sha256": "d99f7d9fd1d0c0b333c30e1cf87cd21bba3d069d2c850f4910ccffe0d486b27a"
"script_length": 10669,
"script_sha256": "0448ecd3ddcb76ce18c20bd3eb8106c108c6775b88400f179b875772acaf7678"
},
"rpm-read-rs": {
"script_name": "rpm-read-rs",
@@ -61,8 +61,8 @@
},
"script-verify-rs": {
"script_name": "script-verify-rs",
"script_length": 2549,
"script_sha256": "157db0a7c444b46f97dc91fcd02fd2c081b1da5d9d5e335a9361747983244066"
"script_length": 5783,
"script_sha256": "f864fe6ab80437e363859fb6fb3721b7368421868ef3980c68a5c8aa60c0d6f9"
},
"sync-rs": {
"script_name": "sync-rs",

View File

@@ -671,6 +671,8 @@ dependencies = [
"clap",
"rust_util",
"script-sign",
"serde",
"serde_json",
]
[[package]]
@@ -689,18 +691,18 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.217"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.217"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [
"proc-macro2",
"quote",
@@ -709,9 +711,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.137"
version = "1.0.143"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "930cfb6e6abf99298aaad7d29abbef7a9999a9a8806a40088f55f0dcec03146b"
checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a"
dependencies = [
"itoa",
"memchr",

View File

@@ -7,3 +7,5 @@ edition = "2021"
clap = { version = "4.5", features = ["derive"] }
rust_util = "0.6"
script-sign = "0.1"
serde = { version = "1.0", features = ["serde_derive"] }
serde_json = "1.0"

View File

@@ -5,24 +5,45 @@
//! clap = { version = "4.5", features = ["derive"] }
//! rust_util = "0.6"
//! script-sign = "0.1"
//! serde = { version = "1.0", features = ["serde_derive"] }
//! serde_json = "1.0"
//! ```
use clap::Parser;
use rust_util::{failure, information, success, warning};
use rust_util::{failure, information, success, util_msg, warning};
use script_sign::{KeyMap, Script};
use std::fs;
use std::path::PathBuf;
use serde::Serialize;
/// Script signing tool
#[derive(Parser, Debug)]
#[command(version, about, long_about = None, bin_name = "script-verify.rs")]
struct Args {
/// JSON outputs
#[arg(long)]
json: bool,
/// Script file path
scripts: Vec<PathBuf>,
}
#[derive(Clone, Debug, Serialize)]
struct ScriptVerification {
name: String,
success: bool,
#[serde(skip_serializing_if = "Option::is_none")]
sign_key_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
sign_time: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
message: Option<String>,
}
fn main() {
let args = Args::parse();
if args.json {
util_msg::set_logger_std_out(false);
}
let key_map = KeyMap::system();
let total_scripts = args.scripts.len();
@@ -31,23 +52,40 @@ fn main() {
return;
}
let mut script_verifications = vec![];
for (i, script_path) in args.scripts.iter().enumerate() {
let script_path_display = script_path.display().to_string();
information!(
"Verifying {}/{}: {}",
(i + 1),
total_scripts,
script_path.display()
script_path_display
);
if !script_path.is_file() {
warning!("Not a file: {}", script_path.display());
warning!("Not a file: {}", script_path_display);
script_verifications.push(ScriptVerification {
name: script_path_display.clone(),
success: false,
sign_key_id: None,
sign_time: None,
message: Some(format!("Not a file: {}", script_path_display)),
});
continue;
}
let script_content = match fs::read_to_string(script_path) {
Ok(script_content) => script_content,
Err(e) => {
warning!("Read script: {} failed: {}", script_path.display(), e);
warning!("Read script: {} failed: {}", script_path_display, e);
script_verifications.push(ScriptVerification {
name: script_path_display.clone(),
success: false,
sign_key_id: None,
sign_time: None,
message: Some(format!("Read script: {} failed: {}", script_path_display, e)),
});
continue;
}
};
@@ -55,7 +93,14 @@ fn main() {
let script = match Script::parse(&script_content) {
Ok(script) => script,
Err(e) => {
warning!("Read script: {} failed: {}", script_path.display(), e);
warning!("Read script: {} failed: {}", script_path_display, e);
script_verifications.push(ScriptVerification {
name: script_path_display.clone(),
success: false,
sign_key_id: None,
sign_time: None,
message: Some(format!("Read script: {} failed: {}", script_path_display, e)),
});
continue;
}
};
@@ -65,23 +110,55 @@ fn main() {
Ok(true) => {
success!(
"Verify script success: {}, key ID: {}, sign date: {}",
script_path.display(),
script_path_display,
signature.key_id,
signature.time
);
script_verifications.push(ScriptVerification {
name: script_path_display.clone(),
success: true,
sign_key_id: Some(signature.key_id.clone()),
sign_time: Some(signature.time.clone()),
message: None,
});
}
Ok(false) => {
failure!("Verify script failed: {}", script_path.display());
failure!("Verify script failed: {}", script_path_display);
script_verifications.push(ScriptVerification {
name: script_path_display.clone(),
success: false,
sign_key_id: None,
sign_time: None,
message: Some(format!("Verify script failed: {}", script_path_display)),
});
}
Err(e) => {
warning!("Verify script: {} failed: {}", script_path.display(), e);
warning!("Verify script: {} failed: {}", script_path_display, e);
script_verifications.push(ScriptVerification {
name: script_path_display.clone(),
success: false,
sign_key_id: None,
sign_time: None,
message: Some(format!("Verify script: {} failed: {}", script_path_display, e)),
});
}
}
} else {
warning!("Script is not signed: {}", script_path.display());
}
warning!("Script is not signed: {}", script_path_display);
script_verifications.push(ScriptVerification {
name: script_path_display.clone(),
success: false,
sign_key_id: None,
sign_time: None,
message: Some(format!("Script is not signed: {}", script_path_display)),
});
}
}
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20250123T234559+08:00.MEUCIQDhj1MHHjBdFiK9lxMV
// EGE3RMJMcRR521i3y0ZifmIYVgIgMHdfszarXyn1fjyY2zo2y22OmXb7VTzFVbD/mdK0/mw=
if args.json {
println!("{}", serde_json::to_string_pretty(&script_verifications).unwrap());
}
}
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20250909T231004+08:00.MEQCIDSni3F6bS8F9SD6tjdL
// 6P8BkVrqJn1FwKUhro7nbJHWAiAVvDq/M4qpb1LutG0sw8zqx2dNeOpzDRNneEkumUsOlg==