Skip to content

Commit b2ba7a3

Browse files
author
linyuan.yang
committed
keystore
1 parent 2d08738 commit b2ba7a3

18 files changed

Lines changed: 1389 additions & 463 deletions

File tree

‎packages/app/src-tauri/Cargo.lock‎

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/app/src-tauri/Cargo.toml‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ url = "2"
2727
sha1 = "0.10"
2828
digest = "0.10"
2929
base64 = "0.22"
30+
# Keystore 工具:解析证书元信息(只做解析,勿开 verify/ring feature)
31+
x509-parser = "0.18"
32+
md-5 = "0.10"
3033
rand = "0.8"
3134
ssh-key = { version = "0.6.7", default-features = false, features = ["std", "ed25519", "rsa", "encryption", "getrandom"] }
3235
urlencoding = "2"
@@ -40,7 +43,7 @@ tauri-plugin-clipboard-manager = "2.3.2"
4043
sysinfo = "0.39.6"
4144

4245
[target.'cfg(target_os = "windows")'.dependencies]
43-
windows = { version = "0.62", features = ["Win32_Foundation", "Win32_Graphics_Dwm", "Win32_NetworkManagement_IpHelper", "Win32_Networking_WinSock", "Win32_Security", "Win32_System_Registry", "Win32_System_RestartManager", "Win32_System_Threading", "Win32_UI_Shell", "Win32_UI_WindowsAndMessaging"] }
46+
windows = { version = "0.62", features = ["Win32_Foundation", "Win32_Graphics_Dwm", "Win32_NetworkManagement_IpHelper", "Win32_Networking_WinSock", "Win32_Security", "Win32_Storage", "Win32_System_IO", "Win32_System_Registry", "Win32_System_RestartManager", "Win32_System_Threading", "Win32_UI_Shell", "Win32_UI_WindowsAndMessaging"] }
4447

4548
[target.'cfg(target_os = "macos")'.dependencies]
4649
objc2-foundation = { version = "0.3.2", features = ["NSProcessInfo"] }
@@ -49,7 +52,14 @@ screencapturekit = { version = "8", features = ["macos_14_0"] }
4952
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
5053
tauri-plugin-single-instance = "2"
5154

55+
# dev 下只保留行号调试信息:本 crate 的全量 debuginfo 会让 PDB 巨大,
56+
# 触发 MSVC 14.50 link.exe 的 LNK1318("意外的 PDB 错误: OK (0)")回归 bug。
57+
# line-tables-only 仍支持断点与调用栈行号。
58+
[profile.dev]
59+
debug = "line-tables-only"
60+
5261
# dev 下也优化依赖(PNG 编码 / 截图捕获等),显著加快 tauri dev 的截图速度;
5362
# 只优化依赖、不优化本 crate,增量编译仍快。
5463
[profile.dev.package."*"]
5564
opt-level = 3
65+
debug = false

‎packages/app/src-tauri/src/lib.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod common;
22
mod logging;
33
mod tools;
44
mod tray;
5+
mod utils;
56

67
use tauri::Manager;
78
use tray::{setup_tray, show_main};
@@ -67,8 +68,7 @@ pub fn run() {
6768
tools::port_check::port_check_kill,
6869
tools::keystore_gen::keystore_check_java,
6970
tools::keystore_gen::keystore_generate,
70-
tools::keystore_info::keystore_key_hash,
71-
tools::keystore_info::keystore_info_list,
71+
tools::keystore_info::keystore_file_info,
7272
tools::save_file::read_image_file,
7373
tools::save_file::save_base64_file,
7474
tools::screenshot::screenshot_clear,

‎packages/app/src-tauri/src/tools/hosts/mod.rs‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn hosts_write_impl(_content: &str) -> Result<(), String> {
4545
#[cfg(windows)]
4646
pub(super) mod windows_impl {
4747
use super::HostsReadResult;
48-
use std::{fs, os::windows::process::CommandExt, path::PathBuf};
48+
use std::{fs, path::PathBuf};
4949

5050
fn hosts_path() -> PathBuf {
5151
let system_root = std::env::var("SystemRoot").unwrap_or_else(|_| r"C:\Windows".into());
@@ -92,11 +92,9 @@ pub(super) mod windows_impl {
9292

9393
/// 尽力刷新 DNS 缓存,让 hosts 修改立即对新解析生效;失败只记日志。
9494
fn flush_dns_cache() {
95-
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
96-
let result = std::process::Command::new("ipconfig")
97-
.arg("/flushdns")
98-
.creation_flags(CREATE_NO_WINDOW)
99-
.output();
95+
let mut cmd = std::process::Command::new("ipconfig");
96+
cmd.arg("/flushdns");
97+
let result = crate::utils::command::run(&mut cmd);
10098
match result {
10199
Ok(output) if output.status.success() => log::debug!("已刷新 DNS 解析缓存"),
102100
Ok(output) => log::warn!("刷新 DNS 缓存失败(exit {:?}),可手动执行 ipconfig /flushdns", output.status.code()),

‎packages/app/src-tauri/src/tools/keystore_gen/mod.rs‎

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -79,33 +79,33 @@ pub async fn keystore_generate(
7979

8080
let dname_str = format_dname(&dname);
8181

82-
let output = Command::new(&keytool)
83-
.args([
84-
"-genkeypair",
85-
"-keystore",
86-
&path,
87-
"-storetype",
88-
"PKCS12",
89-
"-alias",
90-
&alias,
91-
"-keyalg",
92-
"RSA",
93-
"-keysize",
94-
"2048",
95-
"-validity",
96-
&validity_days.to_string(),
97-
"-storepass:env",
98-
"KS_STORE_PASS",
99-
"-keypass:env",
100-
"KS_KEY_PASS",
101-
"-dname",
102-
&dname_str,
103-
"-noprompt",
104-
])
105-
.env("KS_STORE_PASS", &store_password)
106-
.env("KS_KEY_PASS", &key_password)
107-
.output()
108-
.map_err(|e| format!("调用 keytool 失败: {e}"))?;
82+
let mut cmd = Command::new(&keytool);
83+
cmd.args([
84+
"-genkeypair",
85+
"-keystore",
86+
&path,
87+
"-storetype",
88+
"PKCS12",
89+
"-alias",
90+
&alias,
91+
"-keyalg",
92+
"RSA",
93+
"-keysize",
94+
"2048",
95+
"-validity",
96+
&validity_days.to_string(),
97+
"-storepass:env",
98+
"KS_STORE_PASS",
99+
"-keypass:env",
100+
"KS_KEY_PASS",
101+
"-dname",
102+
&dname_str,
103+
"-noprompt",
104+
])
105+
.env("KS_STORE_PASS", &store_password)
106+
.env("KS_KEY_PASS", &key_password);
107+
108+
let output = crate::utils::command::run(&mut cmd).map_err(|e| format!("调用 keytool 失败: {e}"))?;
109109

110110
if !output.status.success() {
111111
let stderr = String::from_utf8_lossy(&output.stderr);
@@ -120,7 +120,8 @@ pub async fn keystore_generate(
120120
let bytes = std::fs::read(&target).map_err(|e| format!("读取生成的 keystore 失败: {e}"))?;
121121
let b64 = base64::engine::general_purpose::STANDARD.encode(&bytes);
122122

123-
let list_output = Command::new(&keytool)
123+
let mut list_cmd = Command::new(&keytool);
124+
list_cmd
124125
.args([
125126
"-list",
126127
"-v",
@@ -131,9 +132,9 @@ pub async fn keystore_generate(
131132
"-storepass:env",
132133
"KS_STORE_PASS",
133134
])
134-
.env("KS_STORE_PASS", &store_password)
135-
.output()
136-
.map_err(|e| format!("读取指纹失败: {e}"))?;
135+
.env("KS_STORE_PASS", &store_password);
136+
137+
let list_output = crate::utils::command::run(&mut list_cmd).map_err(|e| format!("读取指纹失败: {e}"))?;
137138

138139
let list_text = String::from_utf8_lossy(&list_output.stdout);
139140
let fp_sha256 = extract_fingerprint(&list_text, "SHA256:")

0 commit comments

Comments
 (0)