mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-05 01:44:34 +03:00
enhance(cli): add context to public/secret key decoding errors (#11405)
* enhance(cli): add context to public/secret key decoding errors closes #10488 * Update .changes/cli-updater-errorr.md --------- Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>
This commit is contained in:
parent
e0d1307d3f
commit
1f311832ab
7
.changes/cli-updater-errorr.md
Normal file
7
.changes/cli-updater-errorr.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
"tauri-cli": "patch:enhance"
|
||||||
|
"@tauri-apps/cli": "patch:enhance"
|
||||||
|
---
|
||||||
|
|
||||||
|
Add more context for errors when decoding secret and public keys for signing updater artifacts.
|
||||||
|
|
@ -9,7 +9,6 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use base64::Engine;
|
|
||||||
use clap::{builder::PossibleValue, ArgAction, Parser, ValueEnum};
|
use clap::{builder::PossibleValue, ArgAction, Parser, ValueEnum};
|
||||||
use tauri_bundler::PackageType;
|
use tauri_bundler::PackageType;
|
||||||
use tauri_utils::platform::Target;
|
use tauri_utils::platform::Target;
|
||||||
@ -257,15 +256,14 @@ fn sign_updaters(
|
|||||||
// check if private_key points to a file...
|
// check if private_key points to a file...
|
||||||
let maybe_path = Path::new(&private_key);
|
let maybe_path = Path::new(&private_key);
|
||||||
let private_key = if maybe_path.exists() {
|
let private_key = if maybe_path.exists() {
|
||||||
std::fs::read_to_string(maybe_path)?
|
std::fs::read_to_string(maybe_path)
|
||||||
|
.with_context(|| format!("faild to read {}", maybe_path.display()))?
|
||||||
} else {
|
} else {
|
||||||
private_key
|
private_key
|
||||||
};
|
};
|
||||||
let secret_key = updater_signature::secret_key(private_key, password)?;
|
let secret_key =
|
||||||
|
updater_signature::secret_key(private_key, password).context("failed to decode secret key")?;
|
||||||
let pubkey = base64::engine::general_purpose::STANDARD.decode(pubkey)?;
|
let public_key = updater_signature::pub_key(pubkey).context("failed to decode pubkey")?;
|
||||||
let pub_key_decoded = String::from_utf8_lossy(&pubkey);
|
|
||||||
let public_key = minisign::PublicKeyBox::from_string(&pub_key_decoded)?.into_public_key()?;
|
|
||||||
|
|
||||||
let mut signed_paths = Vec::new();
|
let mut signed_paths = Vec::new();
|
||||||
for bundle in update_enabled_bundles {
|
for bundle in update_enabled_bundles {
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
use minisign::{sign, KeyPair as KP, SecretKey, SecretKeyBox, SignatureBox};
|
use minisign::{
|
||||||
|
sign, KeyPair as KP, PublicKey, PublicKeyBox, SecretKey, SecretKeyBox, SignatureBox,
|
||||||
|
};
|
||||||
use std::{
|
use std::{
|
||||||
fs::{self, File, OpenOptions},
|
fs::{self, File, OpenOptions},
|
||||||
io::{BufReader, BufWriter, Write},
|
io::{BufReader, BufWriter, Write},
|
||||||
@ -132,15 +134,24 @@ pub fn secret_key<S: AsRef<[u8]>>(
|
|||||||
private_key: S,
|
private_key: S,
|
||||||
password: Option<String>,
|
password: Option<String>,
|
||||||
) -> crate::Result<SecretKey> {
|
) -> crate::Result<SecretKey> {
|
||||||
let decoded_secret = decode_key(private_key)?;
|
let decoded_secret = decode_key(private_key).context("failed to decode base64 secret key")?;
|
||||||
let sk_box = SecretKeyBox::from_string(&decoded_secret)
|
let sk_box =
|
||||||
.with_context(|| "failed to load updater private key")?;
|
SecretKeyBox::from_string(&decoded_secret).context("failed to load updater private key")?;
|
||||||
let sk = sk_box
|
let sk = sk_box
|
||||||
.into_secret_key(password)
|
.into_secret_key(password)
|
||||||
.with_context(|| "incorrect updater private key password")?;
|
.context("incorrect updater private key password")?;
|
||||||
Ok(sk)
|
Ok(sk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Gets the updater secret key from the given private key and password.
|
||||||
|
pub fn pub_key<S: AsRef<[u8]>>(public_key: S) -> crate::Result<PublicKey> {
|
||||||
|
let decoded_publick = decode_key(public_key).context("failed to decode base64 pubkey")?;
|
||||||
|
let pk_box =
|
||||||
|
PublicKeyBox::from_string(&decoded_publick).context("failed to load updater pubkey")?;
|
||||||
|
let pk = pk_box.into_public_key()?;
|
||||||
|
Ok(pk)
|
||||||
|
}
|
||||||
|
|
||||||
fn unix_timestamp() -> u64 {
|
fn unix_timestamp() -> u64 {
|
||||||
let start = SystemTime::now();
|
let start = SystemTime::now();
|
||||||
let since_the_epoch = start
|
let since_the_epoch = start
|
||||||
|
Loading…
Reference in New Issue
Block a user