mirror of
https://github.com/rustdesk/rustdesk-server.git
synced 2025-07-03 08:15:25 +00:00
dec not working yet
This commit is contained in:
parent
da372f276d
commit
4662b05d73
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -624,6 +624,7 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
"mac_address",
|
"mac_address",
|
||||||
"machine-uid",
|
"machine-uid",
|
||||||
|
"rand 0.8.3",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rocksdb",
|
"rocksdb",
|
||||||
"rust-ini",
|
"rust-ini",
|
||||||
|
@ -24,6 +24,7 @@ machine-uid = "0.2"
|
|||||||
mac_address = "1.1"
|
mac_address = "1.1"
|
||||||
whoami = "0.9"
|
whoami = "0.9"
|
||||||
base64 = "0.13"
|
base64 = "0.13"
|
||||||
|
rand = "0.8"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
hbb_common = { path = "libs/hbb_common" }
|
hbb_common = { path = "libs/hbb_common" }
|
||||||
|
42
src/lic.rs
42
src/lic.rs
@ -1,4 +1,12 @@
|
|||||||
use hbb_common::{bail, log, sodiumoxide::crypto::sign, ResultType};
|
use hbb_common::{
|
||||||
|
bail, log,
|
||||||
|
sodiumoxide::crypto::{
|
||||||
|
secretbox::{self, Key, Nonce},
|
||||||
|
sign,
|
||||||
|
},
|
||||||
|
ResultType,
|
||||||
|
};
|
||||||
|
use rand::Rng;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
@ -21,6 +29,8 @@ pub struct Post {
|
|||||||
email: String,
|
email: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
status: String,
|
status: String,
|
||||||
|
#[serde(default)]
|
||||||
|
nonce: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
const LICENSE_FILE: &'static str = ".license.txt";
|
const LICENSE_FILE: &'static str = ".license.txt";
|
||||||
@ -66,18 +76,27 @@ fn write_lic(lic: &License) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_email(lic: License, email: String) -> ResultType<bool> {
|
fn check_email(lic: License, email: String) -> ResultType<bool> {
|
||||||
|
log::info!("Checking email with the server ...");
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
let nonce: usize = rng.gen();
|
||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
let p: Post = Client::new()
|
let resp = Client::new()
|
||||||
.post("http://rustdesk.com/api/check-email")
|
.post("http://rustdesk.com/api/check-email")
|
||||||
.json(&Post {
|
.json(&Post {
|
||||||
lic,
|
lic,
|
||||||
email,
|
email,
|
||||||
|
nonce,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.send()?
|
.send()?;
|
||||||
.json()?;
|
if resp.status().is_success() {
|
||||||
if !p.status.is_empty() {
|
let text = base64::decode(resp.text()?)?;
|
||||||
bail!("{}", p.status);
|
let p = dec_data(&text, nonce)?;
|
||||||
|
if !p.status.is_empty() {
|
||||||
|
bail!("{}", p.status);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bail!("Server error: {}", resp.status());
|
||||||
}
|
}
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
@ -127,5 +146,16 @@ fn dec_lic(s: &str) -> ResultType<License> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dec_data(data: &[u8], n: usize) -> ResultType<Post> {
|
||||||
|
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";
|
||||||
|
let mut nonce = Nonce([0u8; secretbox::NONCEBYTES]);
|
||||||
|
nonce.0[..std::mem::size_of_val(&n)].copy_from_slice(&n.to_le_bytes());
|
||||||
|
let key = secretbox::Key(*key);
|
||||||
|
if let Ok(res) = secretbox::open(&data, &nonce, &key) {
|
||||||
|
return Ok(serde_json::from_slice::<Post>(&res)?);
|
||||||
|
}
|
||||||
|
bail!("Encryption error");
|
||||||
|
}
|
||||||
|
|
||||||
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'";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user