Skip to content

Commit

Permalink
trim private key
Browse files Browse the repository at this point in the history
  • Loading branch information
rustdesk committed Jan 31, 2024
1 parent 94ae514 commit 79f0eb4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Binary file modified db_v2.sqlite3
Binary file not shown.
6 changes: 4 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,17 @@ pub fn gen_sk(wait: u64) -> (String, Option<sign::SecretKey>) {
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);
let pk = base64::encode(&tmp[sign::SECRETKEYBYTES / 2..]);
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);
}
}
Expand Down

0 comments on commit 79f0eb4

Please sign in to comment.