|
|
@@ -12,7 +12,7 @@ use std::io::prelude::*;
|
|
12
|
12
|
use std::path::Path;
|
|
13
|
13
|
|
|
14
|
14
|
#[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)]
|
|
15
|
|
-pub struct License {
|
|
|
15
|
+pub struct Machine {
|
|
16
|
16
|
#[serde(default)]
|
|
17
|
17
|
hostname: String,
|
|
18
|
18
|
#[serde(default)]
|
|
|
@@ -24,7 +24,7 @@ pub struct License {
|
|
24
|
24
|
#[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)]
|
|
25
|
25
|
pub struct Post {
|
|
26
|
26
|
#[serde(default)]
|
|
27
|
|
- lic: License,
|
|
|
27
|
+ machine: Machine,
|
|
28
|
28
|
#[serde(default)]
|
|
29
|
29
|
email: String,
|
|
30
|
30
|
#[serde(default)]
|
|
|
@@ -36,12 +36,12 @@ pub struct Post {
|
|
36
|
36
|
const LICENSE_FILE: &'static str = ".license.txt";
|
|
37
|
37
|
|
|
38
|
38
|
pub fn check_lic(email: &str) -> bool {
|
|
39
|
|
- let lic = get_lic();
|
|
|
39
|
+ let machine = get_lic();
|
|
40
|
40
|
let path = Path::new(LICENSE_FILE);
|
|
41
|
41
|
if Path::is_file(&path) {
|
|
42
|
42
|
let contents = std::fs::read_to_string(&path).unwrap_or("".to_owned());
|
|
43
|
|
- if let Ok(old_lic) = dec_lic(&contents) {
|
|
44
|
|
- if lic == old_lic {
|
|
|
43
|
+ if let Ok(old_lic) = dec_machine(&contents) {
|
|
|
44
|
+ if machine == old_lic {
|
|
45
|
45
|
return true;
|
|
46
|
46
|
}
|
|
47
|
47
|
}
|
|
|
@@ -52,10 +52,10 @@ pub fn check_lic(email: &str) -> bool {
|
|
52
|
52
|
return false;
|
|
53
|
53
|
}
|
|
54
|
54
|
|
|
55
|
|
- match check_email(lic.clone(), email.to_owned()) {
|
|
|
55
|
+ match check_email(machine.clone(), email.to_owned()) {
|
|
56
|
56
|
Ok(v) => {
|
|
57
|
57
|
if v {
|
|
58
|
|
- write_lic(&lic);
|
|
|
58
|
+ write_lic(&machine);
|
|
59
|
59
|
}
|
|
60
|
60
|
return v;
|
|
61
|
61
|
}
|
|
|
@@ -66,8 +66,8 @@ pub fn check_lic(email: &str) -> bool {
|
|
66
|
66
|
}
|
|
67
|
67
|
}
|
|
68
|
68
|
|
|
69
|
|
-fn write_lic(lic: &License) {
|
|
70
|
|
- if let Ok(s) = enc_lic(&lic) {
|
|
|
69
|
+fn write_lic(machine: &Machine) {
|
|
|
70
|
+ if let Ok(s) = enc_machine(&machine) {
|
|
71
|
71
|
if let Ok(mut f) = std::fs::File::create(LICENSE_FILE) {
|
|
72
|
72
|
f.write_all(s.as_bytes()).ok();
|
|
73
|
73
|
f.sync_all().ok();
|
|
|
@@ -75,7 +75,7 @@ fn write_lic(lic: &License) {
|
|
75
|
75
|
}
|
|
76
|
76
|
}
|
|
77
|
77
|
|
|
78
|
|
-fn check_email(lic: License, email: String) -> ResultType<bool> {
|
|
|
78
|
+fn check_email(machine: Machine, email: String) -> ResultType<bool> {
|
|
79
|
79
|
log::info!("Checking email with the server ...");
|
|
80
|
80
|
let mut rng = rand::thread_rng();
|
|
81
|
81
|
let nonce: usize = rng.gen();
|
|
|
@@ -83,7 +83,7 @@ fn check_email(lic: License, email: String) -> ResultType<bool> {
|
|
83
|
83
|
let resp = Client::new()
|
|
84
|
84
|
.post("http://rustdesk.com/api/check-email")
|
|
85
|
85
|
.json(&Post {
|
|
86
|
|
- lic,
|
|
|
86
|
+ machine,
|
|
87
|
87
|
email,
|
|
88
|
88
|
nonce,
|
|
89
|
89
|
..Default::default()
|
|
|
@@ -101,7 +101,7 @@ fn check_email(lic: License, email: String) -> ResultType<bool> {
|
|
101
|
101
|
Ok(true)
|
|
102
|
102
|
}
|
|
103
|
103
|
|
|
104
|
|
-fn get_lic() -> License {
|
|
|
104
|
+fn get_lic() -> Machine {
|
|
105
|
105
|
let hostname = whoami::hostname();
|
|
106
|
106
|
let uid = machine_uid::get().unwrap_or("".to_owned());
|
|
107
|
107
|
let mac = if let Ok(Some(ma)) = mac_address::get_mac_address() {
|
|
|
@@ -109,11 +109,11 @@ fn get_lic() -> License {
|
|
109
|
109
|
} else {
|
|
110
|
110
|
"".to_owned()
|
|
111
|
111
|
};
|
|
112
|
|
- License { hostname, uid, mac }
|
|
|
112
|
+ Machine { hostname, uid, mac }
|
|
113
|
113
|
}
|
|
114
|
114
|
|
|
115
|
|
-fn enc_lic(lic: &License) -> ResultType<String> {
|
|
116
|
|
- let tmp = serde_json::to_vec::<License>(lic)?;
|
|
|
115
|
+fn enc_machine(machine: &Machine) -> ResultType<String> {
|
|
|
116
|
+ let tmp = serde_json::to_vec::<Machine>(machine)?;
|
|
117
|
117
|
const SK: &[u64] = &[
|
|
118
|
118
|
139, 164, 88, 86, 6, 123, 221, 248, 96, 36, 106, 207, 99, 124, 27, 196, 5, 159, 58, 253,
|
|
119
|
119
|
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> {
|
|
129
|
129
|
Ok(tmp)
|
|
130
|
130
|
}
|
|
131
|
131
|
|
|
132
|
|
-fn dec_lic(s: &str) -> ResultType<License> {
|
|
|
132
|
+fn dec_machine(s: &str) -> ResultType<Machine> {
|
|
133
|
133
|
let tmp: String = s.chars().rev().collect();
|
|
134
|
134
|
const PK: &[u64] = &[
|
|
135
|
135
|
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> {
|
|
140
|
140
|
pk_[..].copy_from_slice(&pk);
|
|
141
|
141
|
let pk = sign::PublicKey(pk_);
|
|
142
|
142
|
if let Ok(data) = sign::verify(&base64::decode_config(tmp, base64::URL_SAFE_NO_PAD)?, &pk) {
|
|
143
|
|
- Ok(serde_json::from_slice::<License>(&data)?)
|
|
|
143
|
+ Ok(serde_json::from_slice::<Machine>(&data)?)
|
|
144
|
144
|
} else {
|
|
145
|
145
|
bail!("sign:verify failed");
|
|
146
|
146
|
}
|