Skip to content

Commit 84b04c4

Browse files
authored
fix: fix leftover inconsistent env var in tauri signer sign command (#14759)
1 parent 897529d commit 84b04c4

File tree

3 files changed

+70
-20
lines changed

3 files changed

+70
-20
lines changed

.changes/signing-env-vars.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"tauri-cli": patch:enhance
3+
"@tauri-apps/cli": patch:enhance
4+
---
5+
6+
Added new environment variables for `tauri signer sign` command, to align with existing environment variables used in `tauri build`, `tauri bundle` and `tauri signer generate`
7+
- `TAURI_SIGNING_PRIVATE_KEY`
8+
- `TAURI_SIGNING_PRIVATE_KEY_PATH`
9+
- `TAURI_SIGNING_PRIVATE_KEY_PASSWORD`
10+
11+
The old environment variables are deprecated and will be removed in a future release.
12+
- `TAURI_PRIVATE_KEY`
13+
- `TAURI_PRIVATE_KEY_PATH`
14+
- `TAURI_PRIVATE_KEY_PASSWORD`

crates/tauri-cli/src/signer/generate.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,29 @@ pub fn command(mut options: Options) -> Result<()> {
3939
save_keypair(options.force, output_path, &keypair.sk, &keypair.pk)
4040
.expect("Unable to write keypair");
4141

42-
println!(
43-
"\nYour keypair was generated successfully\nPrivate: {} (Keep it secret!)\nPublic: {}\n---------------------------",
44-
display_path(secret_path),
45-
display_path(public_path)
46-
)
42+
println!();
43+
println!("Your keypair was generated successfully:");
44+
println!("Private: {} (Keep it secret!)", display_path(secret_path));
45+
println!("Public: {}", display_path(public_path));
46+
println!("---------------------------")
4747
} else {
48-
println!(
49-
"\nYour secret key was generated successfully - Keep it secret!\n{}\n\n",
50-
keypair.sk
51-
);
52-
println!(
53-
"Your public key was generated successfully:\n{}\n\nAdd the public key in your tauri.conf.json\n---------------------------\n",
54-
keypair.pk
55-
);
48+
println!();
49+
println!("Your keys were generated successfully!",);
50+
println!();
51+
println!("Private: (Keep it secret!)");
52+
println!("{}", keypair.sk);
53+
println!();
54+
println!("Public:");
55+
println!("{}", keypair.pk);
5656
}
5757

58-
println!("\nEnvironment variables used to sign:");
59-
println!("`TAURI_SIGNING_PRIVATE_KEY` Path or String of your private key");
60-
println!("`TAURI_SIGNING_PRIVATE_KEY_PASSWORD` Your private key password (optional)");
61-
println!("\nATTENTION: If you lose your private key OR password, you'll not be able to sign your update package and updates will not work.\n---------------------------\n");
58+
println!();
59+
println!("Environment variables used to sign:");
60+
println!("- `TAURI_SIGNING_PRIVATE_KEY`: String of your private key");
61+
println!("- `TAURI_SIGNING_PRIVATE_KEY_PATH`: Path to your private key file");
62+
println!("- `TAURI_SIGNING_PRIVATE_KEY_PASSWORD`: Your private key password (optional if key has no password)");
63+
println!();
64+
println!("ATTENTION: If you lose your private key OR password, you'll not be able to sign your update package and updates will not work");
6265

6366
Ok(())
6467
}

crates/tauri-cli/src/signer/sign.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,58 @@ pub struct Options {
2121
short = 'k',
2222
long,
2323
conflicts_with("private_key_path"),
24-
env = "TAURI_PRIVATE_KEY"
24+
env = "TAURI_SIGNING_PRIVATE_KEY"
2525
)]
2626
private_key: Option<String>,
2727
/// Load the private key from a file
2828
#[clap(
2929
short = 'f',
3030
long,
3131
conflicts_with("private_key"),
32-
env = "TAURI_PRIVATE_KEY_PATH"
32+
env = "TAURI_SIGNING_PRIVATE_KEY_PATH"
3333
)]
3434
private_key_path: Option<PathBuf>,
3535
/// Set private key password when signing
36-
#[clap(short, long, env = "TAURI_PRIVATE_KEY_PASSWORD")]
36+
#[clap(short, long, env = "TAURI_SIGNING_PRIVATE_KEY_PASSWORD")]
3737
password: Option<String>,
3838
/// Sign the specified file
3939
file: PathBuf,
4040
}
4141

42+
// Backwards compatibility with old env vars
43+
// TODO: remove in v3.0
44+
fn backward_env_vars(mut options: Options) -> Options {
45+
let get_env = |old, new| {
46+
if let Ok(old_value) = std::env::var(old) {
47+
println!(
48+
"\x1b[33mWarning: The environment variable '{old}' is deprecated. Please use '{new}' instead.\x1b[0m",
49+
);
50+
Some(old_value)
51+
} else {
52+
None
53+
}
54+
};
55+
56+
options.private_key = options
57+
.private_key
58+
.or_else(|| get_env("TAURI_PRIVATE_KEY", "TAURI_SIGNING_PRIVATE_KEY"));
59+
60+
options.private_key_path = options.private_key_path.or_else(|| {
61+
get_env("TAURI_PRIVATE_KEY_PATH", "TAURI_SIGNING_PRIVATE_KEY_PATH").map(PathBuf::from)
62+
});
63+
64+
options.password = options.password.or_else(|| {
65+
get_env(
66+
"TAURI_PRIVATE_KEY_PASSWORD",
67+
"TAURI_SIGNING_PRIVATE_KEY_PASSWORD",
68+
)
69+
});
70+
options
71+
}
72+
4273
pub fn command(mut options: Options) -> Result<()> {
74+
options = backward_env_vars(options);
75+
4376
options.private_key = if let Some(private_key) = options.private_key_path {
4477
Some(std::fs::read_to_string(Path::new(&private_key)).expect("Unable to extract private key"))
4578
} else {

0 commit comments

Comments
 (0)