From cd9faf48f3d85b59eac559262b35314fa7d6268f Mon Sep 17 00:00:00 2001 From: rustdesk Date: Thu, 20 Jan 2022 12:48:55 +0800 Subject: [PATCH] new pk --- src/client.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/client.rs b/src/client.rs index 11a14b2ff..3b7251f2f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -324,13 +324,9 @@ impl Client { async fn secure_connection(peer_id: &str, pk: Vec, conn: &mut Stream) -> ResultType<()> { let mut pk = pk; - const RS_PK: &[u8; 32] = &[ - 177, 155, 15, 73, 116, 147, 172, 11, 55, 38, 92, 168, 30, 116, 213, 196, 12, 134, 130, - 170, 181, 161, 192, 176, 132, 229, 139, 178, 17, 165, 150, 51, - ]; - if !pk.is_empty() { - let tmp = sign::PublicKey(*RS_PK); - if let Ok(data) = sign::verify(&pk, &tmp) { + let rs_pk = get_rs_pk("OeVuKk5nlHiXp+APNn0Y3pC1Iwpwn44JGqrQCsWqmBw="); + if !pk.is_empty() && rs_pk.is_some() { + if let Ok(data) = sign::verify(&pk, &rs_pk.unwrap()) { pk = data; } else { log::error!("Handshake failed: invalid public key from rendezvous server"); @@ -1226,3 +1222,15 @@ pub fn check_if_retry(msgtype: &str, title: &str, text: &str) -> bool { && !text.to_lowercase().contains("mismatch") && !text.to_lowercase().contains("manually") } + +#[inline] +fn get_rs_pk(str_base64: &str) -> Option { + if let Ok(pk) = base64::decode(str_base64) { + if pk.len() == sign::PUBLICKEYBYTES { + let mut tmp = [0u8; sign::PUBLICKEYBYTES]; + tmp[..].copy_from_slice(&pk); + return Some(sign::PublicKey(tmp)); + } + } + None +}