trim private key

This commit is contained in:
rustdesk 2024-01-31 11:30:42 +08:00
parent 94ae51458c
commit 79f0eb497b
2 changed files with 4 additions and 2 deletions

Binary file not shown.

View File

@ -113,7 +113,8 @@ pub fn gen_sk(wait: u64) -> (String, Option<sign::SecretKey>) {
if let Ok(mut file) = std::fs::File::open(sk_file) { if let Ok(mut file) = std::fs::File::open(sk_file) {
let mut contents = String::new(); let mut contents = String::new();
if file.read_to_string(&mut contents).is_ok() { if file.read_to_string(&mut contents).is_ok() {
let sk = base64::decode(&contents).unwrap_or_default(); let contents = contents.trim();
let sk = base64::decode(contents).unwrap_or_default();
if sk.len() == sign::SECRETKEYBYTES { if sk.len() == sign::SECRETKEYBYTES {
let mut tmp = [0u8; sign::SECRETKEYBYTES]; let mut tmp = [0u8; sign::SECRETKEYBYTES];
tmp[..].copy_from_slice(&sk); tmp[..].copy_from_slice(&sk);
@ -121,7 +122,8 @@ pub fn gen_sk(wait: u64) -> (String, Option<sign::SecretKey>) {
log::info!("Private key comes from {}", sk_file); log::info!("Private key comes from {}", sk_file);
return (pk, Some(sign::SecretKey(tmp))); return (pk, Some(sign::SecretKey(tmp)));
} else { } else {
log::error!("Malformed private key. You probably have a trailing newline in the secret key file."); // don't use log here, since it is async
println!("Fatal error: malformed private key in {sk_file}.");
std::process::exit(1); std::process::exit(1);
} }
} }