diff options
author | opentrade <[email protected]> | 2021-04-10 01:16:02 +0800 |
---|---|---|
committer | opentrade <[email protected]> | 2021-04-10 01:16:02 +0800 |
commit | 321bccc19e1644d8e69f41efe0e30117b2288021 (patch) | |
tree | 5dac4d41de3598399ea583b71ad232dcca2db8be | |
parent | 4662b05d73a1ec44a63388010a0aa5ea0d6a0916 (diff) | |
download | rustdesk-server-321bccc19e1644d8e69f41efe0e30117b2288021.tar.gz rustdesk-server-321bccc19e1644d8e69f41efe0e30117b2288021.zip |
works
m--------- | libs/hbb_common | 0 | ||||
-rw-r--r-- | src/lic.rs | 34 | ||||
-rw-r--r-- | src/main.rs | 6 |
3 files changed, 20 insertions, 20 deletions
diff --git a/libs/hbb_common b/libs/hbb_common -Subproject 98257ca5b799ecae53e2fc3ec20bb997a2f6206 +Subproject 99487187a6b25380b9a412f040f43f319ece754 @@ -12,7 +12,7 @@ use std::io::prelude::*; use std::path::Path; #[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)] -pub struct License { +pub struct Machine { #[serde(default)] hostname: String, #[serde(default)] @@ -24,7 +24,7 @@ pub struct License { #[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)] pub struct Post { #[serde(default)] - lic: License, + machine: Machine, #[serde(default)] email: String, #[serde(default)] @@ -36,12 +36,12 @@ pub struct Post { const LICENSE_FILE: &'static str = ".license.txt"; pub fn check_lic(email: &str) -> bool { - let lic = get_lic(); + let machine = get_lic(); let path = Path::new(LICENSE_FILE); if Path::is_file(&path) { let contents = std::fs::read_to_string(&path).unwrap_or("".to_owned()); - if let Ok(old_lic) = dec_lic(&contents) { - if lic == old_lic { + if let Ok(old_lic) = dec_machine(&contents) { + if machine == old_lic { return true; } } @@ -52,10 +52,10 @@ pub fn check_lic(email: &str) -> bool { return false; } - match check_email(lic.clone(), email.to_owned()) { + match check_email(machine.clone(), email.to_owned()) { Ok(v) => { if v { - write_lic(&lic); + write_lic(&machine); } return v; } @@ -66,8 +66,8 @@ pub fn check_lic(email: &str) -> bool { } } -fn write_lic(lic: &License) { - if let Ok(s) = enc_lic(&lic) { +fn write_lic(machine: &Machine) { + if let Ok(s) = enc_machine(&machine) { if let Ok(mut f) = std::fs::File::create(LICENSE_FILE) { f.write_all(s.as_bytes()).ok(); f.sync_all().ok(); @@ -75,7 +75,7 @@ fn write_lic(lic: &License) { } } -fn check_email(lic: License, email: String) -> ResultType<bool> { +fn check_email(machine: Machine, email: String) -> ResultType<bool> { log::info!("Checking email with the server ..."); let mut rng = rand::thread_rng(); let nonce: usize = rng.gen(); @@ -83,7 +83,7 @@ fn check_email(lic: License, email: String) -> ResultType<bool> { let resp = Client::new() .post("http://rustdesk.com/api/check-email") .json(&Post { - lic, + machine, email, nonce, ..Default::default() @@ -101,7 +101,7 @@ fn check_email(lic: License, email: String) -> ResultType<bool> { Ok(true) } -fn get_lic() -> License { +fn get_lic() -> Machine { let hostname = whoami::hostname(); let uid = machine_uid::get().unwrap_or("".to_owned()); let mac = if let Ok(Some(ma)) = mac_address::get_mac_address() { @@ -109,11 +109,11 @@ fn get_lic() -> License { } else { "".to_owned() }; - License { hostname, uid, mac } + Machine { hostname, uid, mac } } -fn enc_lic(lic: &License) -> ResultType<String> { - let tmp = serde_json::to_vec::<License>(lic)?; +fn enc_machine(machine: &Machine) -> ResultType<String> { + let tmp = serde_json::to_vec::<Machine>(machine)?; const SK: &[u64] = &[ 139, 164, 88, 86, 6, 123, 221, 248, 96, 36, 106, 207, 99, 124, 27, 196, 5, 159, 58, 253, 238, 94, 3, 184, 237, 236, 122, 59, 205, 95, 6, 189, 88, 168, 68, 104, 60, 5, 163, 198, @@ -129,7 +129,7 @@ fn enc_lic(lic: &License) -> ResultType<String> { Ok(tmp) } -fn dec_lic(s: &str) -> ResultType<License> { +fn dec_machine(s: &str) -> ResultType<Machine> { let tmp: String = s.chars().rev().collect(); const PK: &[u64] = &[ 88, 168, 68, 104, 60, 5, 163, 198, 165, 38, 12, 85, 114, 203, 96, 163, 70, 48, 0, 131, 57, @@ -140,7 +140,7 @@ fn dec_lic(s: &str) -> ResultType<License> { pk_[..].copy_from_slice(&pk); let pk = sign::PublicKey(pk_); if let Ok(data) = sign::verify(&base64::decode_config(tmp, base64::URL_SAFE_NO_PAD)?, &pk) { - Ok(serde_json::from_slice::<License>(&data)?) + Ok(serde_json::from_slice::<Machine>(&data)?) } else { bail!("sign:verify failed"); } diff --git a/src/main.rs b/src/main.rs index 0b8c919..808c8fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,6 +47,9 @@ fn main() -> ResultType<()> { } return default.to_owned(); }; + if !lic::check_lic(&get_arg("email", "")) { + return Ok(()); + } let port = get_arg("port", DEFAULT_PORT); let relay_servers: Vec<String> = get_arg("relay-servers", "") .split(",") @@ -65,9 +68,6 @@ fn main() -> ResultType<()> { log::info!("serial={}", serial); log::info!("rendezvous-servers={:?}", rendezvous_servers); let stop: Arc<Mutex<bool>> = Default::default(); - if !lic::check_lic(&get_arg("email", "")) { - return Ok(()); - } RendezvousServer::start( &addr, &addr2, |