From 79f0eb497b4adaaadb51f6ba3a58978846fa5318 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Wed, 31 Jan 2024 11:30:42 +0800 Subject: [PATCH] trim private key --- db_v2.sqlite3 | Bin 24576 -> 24576 bytes src/common.rs | 6 ++++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/db_v2.sqlite3 b/db_v2.sqlite3 index 8a1b5ca8c219d4418791accebf4b48466720980f..5fae8e35a3dec174fa2884bf17738be97e3a60e7 100644 GIT binary patch delta 44 zcmZoTz}RqrQ6@OhC$l6~AuYcsH?c&)m_dMniHX5ML4kpRL1dzgGo#4Hgaz>cA)gD1 delta 44 zcmZoTz}RqrQ6@OhC$l6~AuYcsH?c&)m_dMnk&(ecL4kpRfp?;eGb8WDgaz>cArT9D diff --git a/src/common.rs b/src/common.rs index c2c63ba..2045177 100644 --- a/src/common.rs +++ b/src/common.rs @@ -113,7 +113,8 @@ pub fn gen_sk(wait: u64) -> (String, Option) { if let Ok(mut file) = std::fs::File::open(sk_file) { let mut contents = String::new(); 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 { let mut tmp = [0u8; sign::SECRETKEYBYTES]; tmp[..].copy_from_slice(&sk); @@ -121,7 +122,8 @@ pub fn gen_sk(wait: u64) -> (String, Option) { log::info!("Private key comes from {}", sk_file); return (pk, Some(sign::SecretKey(tmp))); } 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); } }