feat: update script-verify.rs
This commit is contained in:
14
script-verify-rs/Cargo.lock
generated
14
script-verify-rs/Cargo.lock
generated
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if args.json {
|
||||
println!("{}", serde_json::to_string_pretty(&script_verifications).unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20250123T234559+08:00.MEUCIQDhj1MHHjBdFiK9lxMV
|
||||
// EGE3RMJMcRR521i3y0ZifmIYVgIgMHdfszarXyn1fjyY2zo2y22OmXb7VTzFVbD/mdK0/mw=
|
||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20250909T231004+08:00.MEQCIDSni3F6bS8F9SD6tjdL
|
||||
// 6P8BkVrqJn1FwKUhro7nbJHWAiAVvDq/M4qpb1LutG0sw8zqx2dNeOpzDRNneEkumUsOlg==
|
||||
|
||||
Reference in New Issue
Block a user