|
|
@@ -1,4 +1,12 @@
|
|
1
|
|
-use hbb_common::{bail, log, sodiumoxide::crypto::sign, ResultType};
|
|
|
1
|
+use hbb_common::{
|
|
|
2
|
+ bail, log,
|
|
|
3
|
+ sodiumoxide::crypto::{
|
|
|
4
|
+ secretbox::{self, Key, Nonce},
|
|
|
5
|
+ sign,
|
|
|
6
|
+ },
|
|
|
7
|
+ ResultType,
|
|
|
8
|
+};
|
|
|
9
|
+use rand::Rng;
|
|
2
|
10
|
use serde_derive::{Deserialize, Serialize};
|
|
3
|
11
|
use std::io::prelude::*;
|
|
4
|
12
|
use std::path::Path;
|
|
|
@@ -21,6 +29,8 @@ pub struct Post {
|
|
21
|
29
|
email: String,
|
|
22
|
30
|
#[serde(default)]
|
|
23
|
31
|
status: String,
|
|
|
32
|
+ #[serde(default)]
|
|
|
33
|
+ nonce: usize,
|
|
24
|
34
|
}
|
|
25
|
35
|
|
|
26
|
36
|
const LICENSE_FILE: &'static str = ".license.txt";
|
|
|
@@ -66,18 +76,27 @@ fn write_lic(lic: &License) {
|
|
66
|
76
|
}
|
|
67
|
77
|
|
|
68
|
78
|
fn check_email(lic: License, email: String) -> ResultType<bool> {
|
|
|
79
|
+ log::info!("Checking email with the server ...");
|
|
|
80
|
+ let mut rng = rand::thread_rng();
|
|
|
81
|
+ let nonce: usize = rng.gen();
|
|
69
|
82
|
use reqwest::blocking::Client;
|
|
70
|
|
- let p: Post = Client::new()
|
|
|
83
|
+ let resp = Client::new()
|
|
71
|
84
|
.post("http://rustdesk.com/api/check-email")
|
|
72
|
85
|
.json(&Post {
|
|
73
|
86
|
lic,
|
|
74
|
87
|
email,
|
|
|
88
|
+ nonce,
|
|
75
|
89
|
..Default::default()
|
|
76
|
90
|
})
|
|
77
|
|
- .send()?
|
|
78
|
|
- .json()?;
|
|
79
|
|
- if !p.status.is_empty() {
|
|
80
|
|
- bail!("{}", p.status);
|
|
|
91
|
+ .send()?;
|
|
|
92
|
+ if resp.status().is_success() {
|
|
|
93
|
+ let text = base64::decode(resp.text()?)?;
|
|
|
94
|
+ let p = dec_data(&text, nonce)?;
|
|
|
95
|
+ if !p.status.is_empty() {
|
|
|
96
|
+ bail!("{}", p.status);
|
|
|
97
|
+ }
|
|
|
98
|
+ } else {
|
|
|
99
|
+ bail!("Server error: {}", resp.status());
|
|
81
|
100
|
}
|
|
82
|
101
|
Ok(true)
|
|
83
|
102
|
}
|
|
|
@@ -127,5 +146,16 @@ fn dec_lic(s: &str) -> ResultType<License> {
|
|
127
|
146
|
}
|
|
128
|
147
|
}
|
|
129
|
148
|
|
|
|
149
|
+fn dec_data(data: &[u8], n: usize) -> ResultType<Post> {
|
|
|
150
|
+ let key = b"\xa94\xb4\xb4\xda\xf82\x96\x8b\xb0\x9d\x04d\"\x94T\xa6\xdb\xf6\xd5i=Y.\xf5\xf5i\xa9\x14\x91\xa7\xa9";
|
|
|
151
|
+ let mut nonce = Nonce([0u8; secretbox::NONCEBYTES]);
|
|
|
152
|
+ nonce.0[..std::mem::size_of_val(&n)].copy_from_slice(&n.to_le_bytes());
|
|
|
153
|
+ let key = secretbox::Key(*key);
|
|
|
154
|
+ if let Ok(res) = secretbox::open(&data, &nonce, &key) {
|
|
|
155
|
+ return Ok(serde_json::from_slice::<Post>(&res)?);
|
|
|
156
|
+ }
|
|
|
157
|
+ bail!("Encryption error");
|
|
|
158
|
+}
|
|
|
159
|
+
|
|
130
|
160
|
pub const EMAIL_ARG: &'static str =
|
|
131
|
161
|
"-m, --email=[EMAIL] 'Sets your email address registered with RustDesk'";
|