Browse Source

trim private key

rustdesk 2 years ago
parent
commit
79f0eb497b
2 changed files with 4 additions and 2 deletions
  1. BIN
      db_v2.sqlite3
  2. 4 2
      src/common.rs

BIN
db_v2.sqlite3


+ 4 - 2
src/common.rs

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