mirror of
https://github.com/rustdesk/rustdesk-server.git
synced 2025-08-16 16:35:52 +00:00
working on lic
This commit is contained in:
parent
918dfc3bdd
commit
1282e730af
30
Cargo.lock
generated
30
Cargo.lock
generated
@ -618,15 +618,19 @@ dependencies = [
|
|||||||
name = "hbbs"
|
name = "hbbs"
|
||||||
version = "1.1.3"
|
version = "1.1.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"base64 0.13.0",
|
||||||
"clap",
|
"clap",
|
||||||
"hbb_common",
|
"hbb_common",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"mac_address",
|
||||||
|
"machine-uid",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rocksdb",
|
"rocksdb",
|
||||||
"rust-ini",
|
"rust-ini",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"whoami",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -872,6 +876,15 @@ dependencies = [
|
|||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "machine-uid"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1f1595709b0a7386bcd56ba34d250d626e5503917d05d32cdccddcd68603e212"
|
||||||
|
dependencies = [
|
||||||
|
"winreg 0.6.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "matches"
|
name = "matches"
|
||||||
version = "0.1.8"
|
version = "0.1.8"
|
||||||
@ -1420,7 +1433,7 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-futures",
|
"wasm-bindgen-futures",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"winreg",
|
"winreg 0.7.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2072,6 +2085,12 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "whoami"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7884773ab69074615cb8f8425d0e53f11710786158704fca70f53e71b0e05504"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
@ -2115,6 +2134,15 @@ version = "0.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winreg"
|
||||||
|
version = "0.6.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9"
|
||||||
|
dependencies = [
|
||||||
|
"winapi 0.3.9",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winreg"
|
name = "winreg"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
@ -20,6 +20,10 @@ lazy_static = "1.4"
|
|||||||
clap = "2.33"
|
clap = "2.33"
|
||||||
rust-ini = "0.16"
|
rust-ini = "0.16"
|
||||||
reqwest = "0.10"
|
reqwest = "0.10"
|
||||||
|
machine-uid = "0.2"
|
||||||
|
mac_address = "1.1"
|
||||||
|
whoami = "0.9"
|
||||||
|
base64 = "0.13"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
hbb_common = { path = "libs/hbb_common" }
|
hbb_common = { path = "libs/hbb_common" }
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 20bea85903acbd701aed45d195e9206f2ea09edf
|
Subproject commit 98257ca5b799ecae53e2fc3ec20bb997a2f6206c
|
84
src/lic.rs
84
src/lic.rs
@ -1,6 +1,90 @@
|
|||||||
|
use hbb_common::{bail, log, sodiumoxide::crypto::sign, ResultType};
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
use std::io::prelude::*;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct License {
|
||||||
|
#[serde(default)]
|
||||||
|
pub hostname: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub uid: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub mac: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
const LICENSE_FILE: &'static str = ".license.txt";
|
||||||
|
|
||||||
pub fn check_lic(email: &str) -> bool {
|
pub fn check_lic(email: &str) -> bool {
|
||||||
|
let lic = 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 {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if email.is_empty() {
|
||||||
|
log::error!("Registered email required.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(s) = enc_lic(&lic) {
|
||||||
|
if let Ok(mut f) = std::fs::File::create(path) {
|
||||||
|
f.write_all(s.as_bytes()).ok();
|
||||||
|
f.sync_all().ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_lic() -> License {
|
||||||
|
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() {
|
||||||
|
base64::encode_config(ma.bytes(), base64::URL_SAFE_NO_PAD)
|
||||||
|
} else {
|
||||||
|
"".to_owned()
|
||||||
|
};
|
||||||
|
License { hostname, uid, mac }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn enc_lic(lic: &License) -> ResultType<String> {
|
||||||
|
let tmp = serde_json::to_vec::<License>(lic)?;
|
||||||
|
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,
|
||||||
|
165, 38, 12, 85, 114, 203, 96, 163, 70, 48, 0, 131, 57, 12, 46, 129, 83, 17, 84, 193, 119,
|
||||||
|
197, 130, 103,
|
||||||
|
];
|
||||||
|
let sk: Vec<u8> = SK.iter().map(|x| *x as u8).collect();
|
||||||
|
let mut sk_ = [0u8; sign::SECRETKEYBYTES];
|
||||||
|
sk_[..].copy_from_slice(&sk);
|
||||||
|
let sk = sign::SecretKey(sk_);
|
||||||
|
let tmp = base64::encode_config(sign::sign(&tmp, &sk), base64::URL_SAFE_NO_PAD);
|
||||||
|
let tmp: String = tmp.chars().rev().collect();
|
||||||
|
Ok(tmp)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn dec_lic(s: &str) -> ResultType<License> {
|
||||||
|
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,
|
||||||
|
12, 46, 129, 83, 17, 84, 193, 119, 197, 130, 103,
|
||||||
|
];
|
||||||
|
let pk: Vec<u8> = PK.iter().map(|x| *x as u8).collect();
|
||||||
|
let mut pk_ = [0u8; sign::PUBLICKEYBYTES];
|
||||||
|
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)?)
|
||||||
|
} else {
|
||||||
|
bail!("sign:verify failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub const EMAIL_ARG: &'static str =
|
pub const EMAIL_ARG: &'static str =
|
||||||
"-m, --email=[EMAIL] 'Sets your email address registered with RustDesk'";
|
"-m, --email=[EMAIL] 'Sets your email address registered with RustDesk'";
|
||||||
|
@ -20,7 +20,8 @@ fn main() -> ResultType<()> {
|
|||||||
-C, --change-id=[BOOL(default=Y)] 'Sets if support to change id'
|
-C, --change-id=[BOOL(default=Y)] 'Sets if support to change id'
|
||||||
{}
|
{}
|
||||||
-k, --key=[KEY] 'Only allow the client with the same key'",
|
-k, --key=[KEY] 'Only allow the client with the same key'",
|
||||||
DEFAULT_PORT, lic::EMAIL_ARG
|
DEFAULT_PORT,
|
||||||
|
lic::EMAIL_ARG
|
||||||
);
|
);
|
||||||
let matches = App::new("hbbs")
|
let matches = App::new("hbbs")
|
||||||
.version(crate::VERSION)
|
.version(crate::VERSION)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user