@xiaolikt/ai-vault 0.12.3 → 0.12.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Cargo.lock CHANGED
@@ -14,7 +14,7 @@ dependencies = [
14
14
 
15
15
  [[package]]
16
16
  name = "ai-vault"
17
- version = "0.12.3"
17
+ version = "0.12.4"
18
18
  dependencies = [
19
19
  "base64",
20
20
  "chacha20poly1305",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "ai-vault"
3
- version = "0.12.3"
3
+ version = "0.12.4"
4
4
  edition = "2021"
5
5
  description = "Machine-wide encrypted secret store shared by AI coding agents"
6
6
  license = "MIT"
@@ -0,0 +1,82 @@
1
+ //! Build steps for the one platform that needs a second binary.
2
+ //!
3
+ //! `crates/ai-vault/windows/dialog.cs` is the CLI's dialog program: a small
4
+ //! WinForms application that the Rust side starts and talks to over stdin and
5
+ //! stdout. Building it from the Rust build keeps it honest — the binary lands
6
+ //! beside `ai-vault.exe`, and `cargo build` is still all there is to do.
7
+ //!
8
+ //! Nothing here touches the Rust build when it cannot run: a host without the
9
+ //! C# compiler still builds `ai-vault.exe`, and the Windows dialogs fall back to
10
+ //! the PowerShell scripts in `dialog.rs` (slower, same windows).
11
+
12
+ use std::path::PathBuf;
13
+ use std::process::Command;
14
+
15
+ fn main() {
16
+ println!("cargo:rerun-if-changed=windows/dialog.cs");
17
+
18
+ // Only a Windows build has a dialog program; emit nothing anywhere else.
19
+ if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") {
20
+ return;
21
+ }
22
+
23
+ let source = PathBuf::from("windows").join("dialog.cs");
24
+ let Some(out_dir) = std::env::var_os("OUT_DIR") else { return };
25
+ // OUT_DIR is <target>/<profile>/build/<pkg>-<hash>/out: four levels up is
26
+ // <target>/<profile>, the directory the binaries go in, which is where the
27
+ // CLI looks for it. (Nth is counted from zero, "out" being the first.)
28
+ let bin_dir = PathBuf::from(&out_dir)
29
+ .ancestors()
30
+ .nth(4)
31
+ .map(PathBuf::from)
32
+ .filter(|dir| dir.is_dir())
33
+ .unwrap_or_else(|| PathBuf::from(&out_dir));
34
+ let output = bin_dir.join("dialog.exe");
35
+
36
+ match compile(&source, &output) {
37
+ Ok(()) => {}
38
+ Err(why) => {
39
+ // The Linux and macOS builds never get here; a Windows host without
40
+ // csc does, and keeps working with the fallback.
41
+ println!("cargo:warning=the Windows dialog program was not built ({why}); the PowerShell dialogs will be used");
42
+ }
43
+ }
44
+ }
45
+
46
+ fn compile(source: &PathBuf, output: &PathBuf) -> Result<(), String> {
47
+ let csc = std::env::var_os("CSC")
48
+ .map(PathBuf::from)
49
+ .or_else(|| {
50
+ std::env::var_os("SystemRoot").map(|root| {
51
+ let base = PathBuf::from(root);
52
+ // The C# 5 compiler that ships with the framework: enough for
53
+ // this file, and no SDK to install.
54
+ let path = base.join("Microsoft.NET").join("Framework64").join("v4.0.30319").join("csc.exe");
55
+ if path.is_file() {
56
+ path
57
+ } else {
58
+ base.join("Microsoft.NET").join("Framework").join("v4.0.30319").join("csc.exe")
59
+ }
60
+ })
61
+ })
62
+ .filter(|path| path.is_file())
63
+ .ok_or("no csc.exe (the .NET Framework C# compiler) on this machine")?;
64
+
65
+ if let Some(parent) = output.parent() {
66
+ let _ = std::fs::create_dir_all(parent);
67
+ }
68
+ let status = Command::new(&csc)
69
+ .arg("/nologo")
70
+ .arg("/target:winexe")
71
+ .arg("/optimize+")
72
+ .arg(format!("/out:{}", output.display()))
73
+ .arg("/r:System.Windows.Forms.dll")
74
+ .arg("/r:System.Drawing.dll")
75
+ .arg(source)
76
+ .status()
77
+ .map_err(|error| format!("cannot run {}: {error}", csc.display()))?;
78
+ if !status.success() {
79
+ return Err(format!("csc exited with {status}"));
80
+ }
81
+ Ok(())
82
+ }
@@ -476,8 +476,10 @@ fn read_approval() -> Result<bool, Fault> {
476
476
  Ok(matches!(answer.as_str(), "y" | "yes" | "allow" | "允许" | "1" | "true"))
477
477
  }
478
478
 
479
+ /// The master password, in a window that can show what was typed: a typo in it
480
+ /// is expensive.
479
481
  fn ask_password(title: &str, label: &str) -> Result<String, Fault> {
480
- match dialog::prompt_secret(title, label) {
482
+ match dialog::prompt_secret(title, label, true) {
481
483
  Answer::Value(value) => Ok(value),
482
484
  Answer::Cancelled => Err(Fault::Denied("cancelled: no password entered".into())),
483
485
  Answer::NoUi => Err(Fault::NeedsUi("password")),
@@ -491,7 +493,7 @@ fn ask_password(title: &str, label: &str) -> Result<String, Fault> {
491
493
  /// The field is reported in the error's text, which the host reads after the
492
494
  /// `needs-ui: password` line.
493
495
  fn ask_field_password(field: &str, title: &str, label: &str) -> Result<String, Fault> {
494
- match dialog::prompt_secret(title, label) {
496
+ match dialog::prompt_secret(title, label, false) {
495
497
  Answer::Value(value) => Ok(value),
496
498
  Answer::Cancelled => Err(Fault::Denied("cancelled: no password entered".into())),
497
499
  Answer::NoUi => Err(Fault::NeedsUiField(field.to_string())),
@@ -707,6 +709,39 @@ fn which(program: &str) -> bool {
707
709
  })
708
710
  }
709
711
 
712
+ /// What a master password must be, and a word of advice on what it should be.
713
+ /// One key derives the store's key, so its strength is the strength of the
714
+ /// whole store; the floor is eight characters, as it has always been.
715
+ fn check_master_password(password: &str) -> Result<(), Fault> {
716
+ let length = password.chars().count();
717
+ if length < 8 {
718
+ return Err(Fault::Usage(tr(
719
+ "the master password must be at least 8 characters",
720
+ "主密码至少需要 8 个字符",
721
+ ).to_string()));
722
+ }
723
+ let classes = [
724
+ password.chars().any(|c| c.is_ascii_lowercase()),
725
+ password.chars().any(|c| c.is_ascii_uppercase()),
726
+ password.chars().any(|c| c.is_ascii_digit()),
727
+ password.chars().any(|c| !c.is_ascii_alphanumeric()),
728
+ ]
729
+ .iter()
730
+ .filter(|present| **present)
731
+ .count();
732
+ let strong = length >= 16 || (length >= 12 && classes >= 3);
733
+ if !strong {
734
+ eprintln!(
735
+ "ai-vault: {}",
736
+ tr(
737
+ "advice: a passphrase of four unrelated words is both stronger and easier to remember than a short password.",
738
+ "建议:四个互不相关的词组成的长口令,比短短一个密码既更安全也更好记。",
739
+ )
740
+ );
741
+ }
742
+ Ok(())
743
+ }
744
+
710
745
  fn init(paths: &Paths, out: &Out, password_stdin: bool, requester: &str, idle_min: Option<i64>) -> Outcome {
711
746
  if paths.store().exists() {
712
747
  return Err(Fault::Error(format!(
@@ -717,9 +752,15 @@ fn init(paths: &Paths, out: &Out, password_stdin: bool, requester: &str, idle_mi
717
752
  let password = if password_stdin {
718
753
  read_password()?
719
754
  } else {
720
- let first = ask_password(tr("ai-vault · set master password", "ai-vault · 创建主密码"), tr("at least 8 characters", "至少 8 位"))?;
721
- if first.len() < 8 {
722
- return Err(Fault::Usage("the master password must be at least 8 characters".into()));
755
+ let first = ask_password(
756
+ tr("ai-vault · set master password", "ai-vault · 创建主密码"),
757
+ tr(
758
+ "Choose a long passphrase, not a word: this one key protects every secret in the store.",
759
+ "请选一句足够长的口令,而不是一个单词:这一把钥匙保护库里所有密码。",
760
+ ),
761
+ )?;
762
+ if let Err(fault) = check_master_password(&first) {
763
+ return Err(fault);
723
764
  }
724
765
  let again = ask_password(tr("ai-vault · confirm master password", "ai-vault · 确认主密码"), tr("type it again", "再输入一次"))?;
725
766
  if again != first {