From 5e0f429e84c54de55aaef9e0c1df8a7faa317b5a Mon Sep 17 00:00:00 2001 From: opentrade Date: Tue, 6 Apr 2021 16:18:09 +0800 Subject: [PATCH 01/14] remove uuid back compatibility --- libs/hbb_common | 2 +- src/rendezvous_server.rs | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/libs/hbb_common b/libs/hbb_common index 002939a..7bf9906 160000 --- a/libs/hbb_common +++ b/libs/hbb_common @@ -1 +1 @@ -Subproject commit 002939a1037c786d2651a779492a7c813ea4e54a +Subproject commit 7bf9906c1fabc2e4437871715db4ef7883fca3d4 diff --git a/src/rendezvous_server.rs b/src/rendezvous_server.rs index 75e670e..94daf88 100644 --- a/src/rendezvous_server.rs +++ b/src/rendezvous_server.rs @@ -321,6 +321,27 @@ impl RendezvousServer { } break; } + Some(rendezvous_message::Union::register_pk(rk)) => { + if rk.uuid.is_empty() { + break; + } + let mut res = register_pk_response::Result::OK; + if let Some(peer) = rs.pm.get(&rk.id).await { + if peer.uuid != rk.uuid { + res = register_pk_response::Result::ID_EXISTS; + } + } + let mut msg_out = RendezvousMessage::new(); + msg_out.set_register_pk_response(RegisterPkResponse { + result: res.into(), + ..Default::default() + }); + if let Some(tcp) = sender.as_mut() { + if let Ok(bytes) = msg_out.write_to_bytes() { + allow_err!(tcp.send(Bytes::from(bytes)).await); + } + } + } _ => { break; } @@ -372,7 +393,7 @@ impl RendezvousServer { let id = rk.id; let mut res = register_pk_response::Result::OK; if let Some(peer) = self.pm.get(&id).await { - if !peer.uuid.is_empty() && peer.uuid != rk.uuid { + if peer.uuid != rk.uuid { log::warn!( "Peer {} uuid mismatch: {:?} vs {:?}", id, @@ -380,7 +401,7 @@ impl RendezvousServer { peer.uuid ); res = register_pk_response::Result::UUID_MISMATCH; - } else if peer.uuid.is_empty() || peer.pk != rk.pk { + } else if peer.pk != rk.pk { self.pm.update_pk(id, addr, rk.uuid, rk.pk); } } else { From 710f0b2681b27644512a5c0626012320c4a5b545 Mon Sep 17 00:00:00 2001 From: opentrade Date: Tue, 6 Apr 2021 17:08:37 +0800 Subject: [PATCH 02/14] INVALID_ID_FORMAT --- Cargo.lock | 1 + libs/hbb_common | 2 +- src/rendezvous_server.rs | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5e0c0b4..42578e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -514,6 +514,7 @@ dependencies = [ "protobuf-codegen-pure", "quinn", "rand", + "regex", "serde", "serde_derive", "serde_json", diff --git a/libs/hbb_common b/libs/hbb_common index 7bf9906..4d5b935 160000 --- a/libs/hbb_common +++ b/libs/hbb_common @@ -1 +1 @@ -Subproject commit 7bf9906c1fabc2e4437871715db4ef7883fca3d4 +Subproject commit 4d5b935f16abe33e106b13f30877edb2960f53e9 diff --git a/src/rendezvous_server.rs b/src/rendezvous_server.rs index 94daf88..79ed121 100644 --- a/src/rendezvous_server.rs +++ b/src/rendezvous_server.rs @@ -392,7 +392,9 @@ impl RendezvousServer { } let id = rk.id; let mut res = register_pk_response::Result::OK; - if let Some(peer) = self.pm.get(&id).await { + if !hbb_common::is_valid_custom_id(&id) { + res = register_pk_response::Result::INVALID_ID_FORMAT; + } else if let Some(peer) = self.pm.get(&id).await { if peer.uuid != rk.uuid { log::warn!( "Peer {} uuid mismatch: {:?} vs {:?}", From 92bd9c325053c5b21fb424a45eae7215160ed610 Mon Sep 17 00:00:00 2001 From: opentrade Date: Thu, 8 Apr 2021 00:33:30 +0800 Subject: [PATCH 03/14] change-id option --- libs/hbb_common | 2 +- src/main.rs | 3 +++ src/rendezvous_server.rs | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libs/hbb_common b/libs/hbb_common index 4d5b935..20bea85 160000 --- a/libs/hbb_common +++ b/libs/hbb_common @@ -1 +1 @@ -Subproject commit 4d5b935f16abe33e106b13f30877edb2960f53e9 +Subproject commit 20bea85903acbd701aed45d195e9206f2ea09edf diff --git a/src/main.rs b/src/main.rs index 96e0376..888fa11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ fn main() -> ResultType<()> { -R, --rendezvous-servers=[HOSTS] 'Sets rendezvous servers, seperated by colon' -u, --software-url=[URL] 'Sets download url of RustDesk software of newest version' -r, --relay-servers=[HOST] 'Sets the default relay servers, seperated by colon' + -C, --change-id=[BOOL(default=Y)] 'Sets if support to change id' -k, --key=[KEY] 'Only allow the client with the same key'", DEFAULT_PORT, ); @@ -50,6 +51,7 @@ fn main() -> ResultType<()> { .map(|x| x.to_owned()) .collect(); let serial: i32 = get_arg("serial", "").parse().unwrap_or(0); + let id_change_support: bool = get_arg("change-id", "Y").to_uppercase() == "Y"; let rendezvous_servers: Vec = get_arg("rendezvous-servers", "") .split(",") .filter(|x| !x.is_empty() && test_if_valid_server(x, "rendezvous-server").is_ok()) @@ -69,6 +71,7 @@ fn main() -> ResultType<()> { get_arg("software-url", ""), &get_arg("key", ""), stop, + id_change_support, )?; Ok(()) } diff --git a/src/rendezvous_server.rs b/src/rendezvous_server.rs index 79ed121..2908475 100644 --- a/src/rendezvous_server.rs +++ b/src/rendezvous_server.rs @@ -164,6 +164,7 @@ impl RendezvousServer { software_url: String, key: &str, stop: Arc>, + id_change_support: bool, ) -> ResultType<()> { if !key.is_empty() { log::info!("Key: {}", key); @@ -171,6 +172,7 @@ impl RendezvousServer { log::info!("Listening on tcp/udp {}", addr); log::info!("Listening on tcp {}, extra port for NAT test", addr2); log::info!("relay-servers={:?}", relay_servers); + log::info!("change-id={:?}", id_change_support); let mut socket = FramedSocket::new(addr).await?; let (tx, mut rx) = mpsc::unbounded_channel::<(RendezvousMessage, SocketAddr)>(); let version = hbb_common::get_version_from_url(&software_url); @@ -202,6 +204,7 @@ impl RendezvousServer { &mut socket, key, stop.clone(), + id_change_support, ) .await; } @@ -215,6 +218,7 @@ impl RendezvousServer { socket: &mut FramedSocket, key: &str, stop: Arc>, + id_change_support: bool, ) { let mut timer = interval(Duration::from_millis(100)); loop { @@ -326,7 +330,9 @@ impl RendezvousServer { break; } let mut res = register_pk_response::Result::OK; - if let Some(peer) = rs.pm.get(&rk.id).await { + if !id_change_support { + res = register_pk_response::Result::NOT_SUPPORT; + } else if let Some(peer) = rs.pm.get(&rk.id).await { if peer.uuid != rk.uuid { res = register_pk_response::Result::ID_EXISTS; } From c7bac6b8592a993d8a0b03db28f2fdc7b4c0f589 Mon Sep 17 00:00:00 2001 From: open-trade Date: Thu, 8 Apr 2021 12:23:37 +0800 Subject: [PATCH 04/14] fix --- src/rendezvous_server.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rendezvous_server.rs b/src/rendezvous_server.rs index 2908475..b7e02e1 100644 --- a/src/rendezvous_server.rs +++ b/src/rendezvous_server.rs @@ -332,6 +332,8 @@ impl RendezvousServer { let mut res = register_pk_response::Result::OK; if !id_change_support { res = register_pk_response::Result::NOT_SUPPORT; + } else if !hbb_common::is_valid_custom_id(&rk.id) { + res = register_pk_response::Result::INVALID_ID_FORMAT; } else if let Some(peer) = rs.pm.get(&rk.id).await { if peer.uuid != rk.uuid { res = register_pk_response::Result::ID_EXISTS; @@ -398,9 +400,7 @@ impl RendezvousServer { } let id = rk.id; let mut res = register_pk_response::Result::OK; - if !hbb_common::is_valid_custom_id(&id) { - res = register_pk_response::Result::INVALID_ID_FORMAT; - } else if let Some(peer) = self.pm.get(&id).await { + if let Some(peer) = self.pm.get(&id).await { if peer.uuid != rk.uuid { log::warn!( "Peer {} uuid mismatch: {:?} vs {:?}", From 34a55668f39f281b6240c48f06be968362695205 Mon Sep 17 00:00:00 2001 From: open-trade Date: Thu, 8 Apr 2021 14:52:30 +0800 Subject: [PATCH 05/14] bug fix --- src/rendezvous_server.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/rendezvous_server.rs b/src/rendezvous_server.rs index b7e02e1..dff17e6 100644 --- a/src/rendezvous_server.rs +++ b/src/rendezvous_server.rs @@ -640,6 +640,17 @@ impl RendezvousServer { }, }; let socket_addr = AddrMangle::encode(addr); + let relay_server = { + if self.relay_servers.is_empty() { + "".to_owned() + } else { + let i = unsafe { + ROTATION_RELAY_SERVER += 1; + ROTATION_RELAY_SERVER % self.relay_servers.len() + }; + self.relay_servers[i].clone() + } + }; if same_intranet { log::debug!( "Fetch local addr {:?} {:?} request from {:?}", @@ -647,13 +658,9 @@ impl RendezvousServer { &peer.socket_addr, &addr ); - let i = unsafe { - ROTATION_RELAY_SERVER += 1; - ROTATION_RELAY_SERVER % self.relay_servers.len() - }; msg_out.set_fetch_local_addr(FetchLocalAddr { socket_addr, - relay_server: self.relay_servers[i].clone(), + relay_server, ..Default::default() }); } else { @@ -663,14 +670,10 @@ impl RendezvousServer { &peer.socket_addr, &addr ); - let i = unsafe { - ROTATION_RELAY_SERVER += 1; - ROTATION_RELAY_SERVER % self.relay_servers.len() - }; msg_out.set_punch_hole(PunchHole { socket_addr, nat_type: ph.nat_type, - relay_server: self.relay_servers[i].clone(), + relay_server, ..Default::default() }); } From 25554dd3186cab764e499614a637f71be75b5d46 Mon Sep 17 00:00:00 2001 From: opentrade Date: Thu, 8 Apr 2021 17:53:56 +0800 Subject: [PATCH 06/14] lic draft --- Cargo.lock | 585 +++++++++++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 2 +- src/hbbr.rs | 8 +- src/lic.rs | 6 + src/main.rs | 7 +- 5 files changed, 578 insertions(+), 30 deletions(-) create mode 100644 src/lic.rs diff --git a/Cargo.lock b/Cargo.lock index 42578e8..0a7d169 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -124,6 +124,12 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" +[[package]] +name = "bytes" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" + [[package]] name = "cc" version = "1.0.65" @@ -202,7 +208,17 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" dependencies = [ - "core-foundation-sys", + "core-foundation-sys 0.7.0", + "libc", +] + +[[package]] +name = "core-foundation" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" +dependencies = [ + "core-foundation-sys 0.8.2", "libc", ] @@ -212,6 +228,12 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" +[[package]] +name = "core-foundation-sys" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" + [[package]] name = "crossbeam-utils" version = "0.8.1" @@ -290,7 +312,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b391911b9a786312a10cb9d2b3d0735adfd5a8113eb3648de26a75e91b0826c" dependencies = [ - "rand", + "rand 0.7.3", ] [[package]] @@ -299,6 +321,15 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "encoding_rs" +version = "0.8.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "env_logger" version = "0.7.1" @@ -347,7 +378,7 @@ checksum = "0c122a393ea57648015bf06fbd3d372378992e86b9ff5a7a497b076a28c79efe" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall", + "redox_syscall 0.1.57", "winapi 0.3.9", ] @@ -357,6 +388,31 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -476,7 +532,18 @@ checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" dependencies = [ "cfg-if 0.1.10", "libc", - "wasi", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.10.2+wasi-snapshot-preview1", ] [[package]] @@ -485,6 +552,26 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "h2" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" +dependencies = [ + "bytes 0.5.6", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", + "tracing-futures", +] + [[package]] name = "hashbrown" version = "0.9.1" @@ -499,7 +586,7 @@ name = "hbb_common" version = "0.1.0" dependencies = [ "anyhow", - "bytes", + "bytes 0.5.6", "confy", "directories-next", "dirs-next", @@ -513,7 +600,7 @@ dependencies = [ "protobuf", "protobuf-codegen-pure", "quinn", - "rand", + "rand 0.7.3", "regex", "serde", "serde_derive", @@ -531,10 +618,10 @@ dependencies = [ name = "hbbs" version = "1.1.3" dependencies = [ - "cc", "clap", "hbb_common", "lazy_static", + "reqwest", "rocksdb", "rust-ini", "serde", @@ -551,6 +638,39 @@ dependencies = [ "libc", ] +[[package]] +name = "http" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" +dependencies = [ + "bytes 1.0.1", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" +dependencies = [ + "bytes 0.5.6", + "http", +] + +[[package]] +name = "httparse" +version = "1.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc35c995b9d93ec174cf9a27d425c7892722101e14993cd227fdb51d70cf9589" + +[[package]] +name = "httpdate" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" + [[package]] name = "humantime" version = "1.3.0" @@ -566,6 +686,64 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a" +[[package]] +name = "hyper" +version = "0.13.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a6f157065790a3ed2f88679250419b5cdd96e714a0d65f7797fd337186e96bb" +dependencies = [ + "bytes 0.5.6", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed" +dependencies = [ + "bytes 0.5.6", + "hyper", + "native-tls", + "tokio", + "tokio-tls", +] + +[[package]] +name = "idna" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "iovec" version = "0.1.4" @@ -575,6 +753,12 @@ dependencies = [ "libc", ] +[[package]] +name = "ipnet" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" + [[package]] name = "itertools" version = "0.9.0" @@ -688,12 +872,34 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "matches" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" + [[package]] name = "memchr" version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mime_guess" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "mio" version = "0.6.22" @@ -758,6 +964,24 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "native-tls" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework 2.2.0", + "security-framework-sys 2.2.0", + "tempfile", +] + [[package]] name = "net2" version = "0.2.36" @@ -807,12 +1031,39 @@ version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" +[[package]] +name = "openssl" +version = "0.10.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a61075b62a23fef5a29815de7536d940aa35ce96d18ce0cc5076272db678a577" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-sys", +] + [[package]] name = "openssl-probe" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" +[[package]] +name = "openssl-sys" +version = "0.9.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "313752393519e876837e09e1fa183ddef0be7735868dced3196f4472d536277f" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "ordered-multimap" version = "0.3.1" @@ -829,6 +1080,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + [[package]] name = "pin-project" version = "1.0.2" @@ -958,7 +1215,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88de58d76d8f82fb28e5c89302119c102bb5b9ce57b034186b559b63ba147a0f" dependencies = [ - "bytes", + "bytes 0.5.6", "err-derive", "futures", "libc", @@ -976,10 +1233,10 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0ea0a358c179c6b7af34805c675d1664a9c6a234a7acd7efdbb32d2f39d3d2a" dependencies = [ - "bytes", + "bytes 0.5.6", "ct-logs", "err-derive", - "rand", + "rand 0.7.3", "ring", "rustls", "rustls-native-certs", @@ -1003,11 +1260,23 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.15", "libc", - "rand_chacha", - "rand_core", - "rand_hc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc 0.2.0", +] + +[[package]] +name = "rand" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +dependencies = [ + "libc", + "rand_chacha 0.3.0", + "rand_core 0.6.2", + "rand_hc 0.3.0", ] [[package]] @@ -1017,7 +1286,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.2", ] [[package]] @@ -1026,7 +1305,16 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.15", +] + +[[package]] +name = "rand_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +dependencies = [ + "getrandom 0.2.2", ] [[package]] @@ -1035,7 +1323,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +dependencies = [ + "rand_core 0.6.2", ] [[package]] @@ -1044,14 +1341,23 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +[[package]] +name = "redox_syscall" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" +dependencies = [ + "bitflags", +] + [[package]] name = "redox_users" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" dependencies = [ - "getrandom", - "redox_syscall", + "getrandom 0.1.15", + "redox_syscall 0.1.57", "rust-argon2", ] @@ -1073,6 +1379,50 @@ version = "0.6.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "reqwest" +version = "0.10.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0718f81a8e14c4dbb3b34cf23dc6aaf9ab8a0dfec160c534b3dbca1aaa21f47c" +dependencies = [ + "base64 0.13.0", + "bytes 0.5.6", + "encoding_rs", + "futures-core", + "futures-util", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "mime_guess", + "native-tls", + "percent-encoding", + "pin-project-lite 0.2.0", + "serde", + "serde_urlencoded", + "tokio", + "tokio-tls", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "ring" version = "0.16.18" @@ -1148,7 +1498,7 @@ dependencies = [ "openssl-probe", "rustls", "schannel", - "security-framework", + "security-framework 0.4.4", ] [[package]] @@ -1190,10 +1540,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535" dependencies = [ "bitflags", - "core-foundation", - "core-foundation-sys", + "core-foundation 0.7.0", + "core-foundation-sys 0.7.0", "libc", - "security-framework-sys", + "security-framework-sys 0.4.3", +] + +[[package]] +name = "security-framework" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3670b1d2fdf6084d192bc71ead7aabe6c06aa2ea3fbd9cc3ac111fa5c2b1bd84" +dependencies = [ + "bitflags", + "core-foundation 0.9.1", + "core-foundation-sys 0.8.2", + "libc", + "security-framework-sys 2.2.0", ] [[package]] @@ -1202,7 +1565,17 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" dependencies = [ - "core-foundation-sys", + "core-foundation-sys 0.7.0", + "libc", +] + +[[package]] +name = "security-framework-sys" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3676258fd3cfe2c9a0ec99ce3038798d847ce3e4bb17746373eb9f0f1ac16339" +dependencies = [ + "core-foundation-sys 0.8.2", "libc", ] @@ -1234,6 +1607,18 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "shlex" version = "0.1.1" @@ -1263,7 +1648,7 @@ checksum = "2c29947abdee2a218277abeca306f25789c938e500ea5a9d4b12a5a504466902" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall", + "redox_syscall 0.1.57", "winapi 0.3.9", ] @@ -1313,6 +1698,20 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "tempfile" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "rand 0.8.3", + "redox_syscall 0.2.5", + "remove_dir_all", + "winapi 0.3.9", +] + [[package]] name = "termcolor" version = "1.1.2" @@ -1340,13 +1739,28 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "tinyvec" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + [[package]] name = "tokio" version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6d7ad61edd59bfcc7e80dababf0f4aed2e6d5e0ba1659356ae889752dfc12ff" dependencies = [ - "bytes", + "bytes 0.5.6", "fnv", "futures-core", "iovec", @@ -1375,13 +1789,23 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-util" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" dependencies = [ - "bytes", + "bytes 0.5.6", "futures-core", "futures-io", "futures-sink", @@ -1399,6 +1823,12 @@ dependencies = [ "serde", ] +[[package]] +name = "tower-service" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" + [[package]] name = "tracing" version = "0.1.22" @@ -1406,6 +1836,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" dependencies = [ "cfg-if 1.0.0", + "log", "pin-project-lite 0.2.0", "tracing-attributes", "tracing-core", @@ -1431,6 +1862,49 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" +dependencies = [ + "matches", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-width" version = "0.1.8" @@ -1449,6 +1923,24 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +[[package]] +name = "url" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "vcpkg" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" + [[package]] name = "vec_map" version = "0.8.2" @@ -1461,12 +1953,28 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + [[package]] name = "wasm-bindgen" version = "0.2.68" @@ -1474,6 +1982,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42" dependencies = [ "cfg-if 0.1.10", + "serde", + "serde_json", "wasm-bindgen-macro", ] @@ -1492,6 +2002,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7866cab0aa01de1edf8b5d7936938a7e397ee50ce24119aef3e1eaa3b6171da" +dependencies = [ + "cfg-if 0.1.10", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.68" @@ -1593,6 +2115,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "winreg" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "ws2_32-sys" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index af34518..875dc3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,9 +19,9 @@ serde_json = "1.0" lazy_static = "1.4" clap = "2.33" rust-ini = "0.16" +reqwest = "0.10" [build-dependencies] -cc = "1.0" hbb_common = { path = "libs/hbb_common" } [workspace] diff --git a/src/hbbr.rs b/src/hbbr.rs index c2ac21b..f0633a2 100644 --- a/src/hbbr.rs +++ b/src/hbbr.rs @@ -3,14 +3,17 @@ mod relay_server; use hbb_common::{env_logger::*, ResultType}; use relay_server::*; use std::sync::{Arc, Mutex}; +mod lic; fn main() -> ResultType<()> { init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info")); let args = format!( "-p, --port=[NUMBER(default={})] 'Sets the listening port' -k, --key=[KEY] 'Only allow the client with the same key' + {} ", - DEFAULT_PORT + DEFAULT_PORT, + lic::EMAIL_ARG ); let matches = App::new("hbbr") .version(hbbs::VERSION) @@ -18,6 +21,9 @@ fn main() -> ResultType<()> { .about("RustDesk Relay Server") .args_from_usage(&args) .get_matches(); + if !lic::check_lic(matches.value_of("email").unwrap_or("")) { + return Ok(()); + } let stop: Arc> = Default::default(); start( matches.value_of("port").unwrap_or(DEFAULT_PORT), diff --git a/src/lic.rs b/src/lic.rs new file mode 100644 index 0000000..74f7d76 --- /dev/null +++ b/src/lic.rs @@ -0,0 +1,6 @@ +pub fn check_lic(email: &str) -> bool { + true +} + +pub const EMAIL_ARG: &'static str = + "-m, --email=[EMAIL] 'Sets your email address registered with RustDesk'"; diff --git a/src/main.rs b/src/main.rs index 888fa11..16de822 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use clap::App; use hbb_common::{env_logger::*, log, ResultType}; use hbbs::*; +mod lic; use ini::Ini; use std::sync::{Arc, Mutex}; @@ -17,8 +18,9 @@ fn main() -> ResultType<()> { -u, --software-url=[URL] 'Sets download url of RustDesk software of newest version' -r, --relay-servers=[HOST] 'Sets the default relay servers, seperated by colon' -C, --change-id=[BOOL(default=Y)] 'Sets if support to change id' + {} -k, --key=[KEY] 'Only allow the client with the same key'", - DEFAULT_PORT, + DEFAULT_PORT, lic::EMAIL_ARG ); let matches = App::new("hbbs") .version(crate::VERSION) @@ -62,6 +64,9 @@ fn main() -> ResultType<()> { log::info!("serial={}", serial); log::info!("rendezvous-servers={:?}", rendezvous_servers); let stop: Arc> = Default::default(); + if !lic::check_lic(&get_arg("email", "")) { + return Ok(()); + } RendezvousServer::start( &addr, &addr2, From 1282e730af7cbc493fce53af757caf87e9ca7a4f Mon Sep 17 00:00:00 2001 From: opentrade Date: Thu, 8 Apr 2021 18:59:57 +0800 Subject: [PATCH 07/14] working on lic --- Cargo.lock | 30 +++++++++++++++++- Cargo.toml | 4 +++ libs/hbb_common | 2 +- src/lic.rs | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 3 +- 5 files changed, 120 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a7d169..89b72c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -618,15 +618,19 @@ dependencies = [ name = "hbbs" version = "1.1.3" dependencies = [ + "base64 0.13.0", "clap", "hbb_common", "lazy_static", + "mac_address", + "machine-uid", "reqwest", "rocksdb", "rust-ini", "serde", "serde_derive", "serde_json", + "whoami", ] [[package]] @@ -872,6 +876,15 @@ dependencies = [ "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]] name = "matches" version = "0.1.8" @@ -1420,7 +1433,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "winreg", + "winreg 0.7.0", ] [[package]] @@ -2072,6 +2085,12 @@ dependencies = [ "libc", ] +[[package]] +name = "whoami" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7884773ab69074615cb8f8425d0e53f11710786158704fca70f53e71b0e05504" + [[package]] name = "winapi" version = "0.2.8" @@ -2115,6 +2134,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "winreg" version = "0.7.0" diff --git a/Cargo.toml b/Cargo.toml index 875dc3b..cb543ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,10 @@ lazy_static = "1.4" clap = "2.33" rust-ini = "0.16" reqwest = "0.10" +machine-uid = "0.2" +mac_address = "1.1" +whoami = "0.9" +base64 = "0.13" [build-dependencies] hbb_common = { path = "libs/hbb_common" } diff --git a/libs/hbb_common b/libs/hbb_common index 20bea85..98257ca 160000 --- a/libs/hbb_common +++ b/libs/hbb_common @@ -1 +1 @@ -Subproject commit 20bea85903acbd701aed45d195e9206f2ea09edf +Subproject commit 98257ca5b799ecae53e2fc3ec20bb997a2f6206c diff --git a/src/lic.rs b/src/lic.rs index 74f7d76..67a8745 100644 --- a/src/lic.rs +++ b/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 { + 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 } +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 { + let tmp = serde_json::to_vec::(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 = 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 { + 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 = 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::(&data)?) + } else { + bail!("sign:verify failed"); + } +} + pub const EMAIL_ARG: &'static str = "-m, --email=[EMAIL] 'Sets your email address registered with RustDesk'"; diff --git a/src/main.rs b/src/main.rs index 16de822..0b8c919 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,8 @@ fn main() -> ResultType<()> { -C, --change-id=[BOOL(default=Y)] 'Sets if support to change id' {} -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") .version(crate::VERSION) From da372f276d3813d427df678b5c3bf3a44dc67bc1 Mon Sep 17 00:00:00 2001 From: opentrade Date: Fri, 9 Apr 2021 12:27:22 +0800 Subject: [PATCH 08/14] check_email --- Cargo.lock | 1 + Cargo.toml | 2 +- src/lic.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89b72c2..83271c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1426,6 +1426,7 @@ dependencies = [ "percent-encoding", "pin-project-lite 0.2.0", "serde", + "serde_json", "serde_urlencoded", "tokio", "tokio-tls", diff --git a/Cargo.toml b/Cargo.toml index cb543ee..60b39f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ serde_json = "1.0" lazy_static = "1.4" clap = "2.33" rust-ini = "0.16" -reqwest = "0.10" +reqwest = { version = "0.10", features = ["json", "blocking"] } machine-uid = "0.2" mac_address = "1.1" whoami = "0.9" diff --git a/src/lic.rs b/src/lic.rs index 67a8745..85a2cad 100644 --- a/src/lic.rs +++ b/src/lic.rs @@ -6,11 +6,21 @@ use std::path::Path; #[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)] pub struct License { #[serde(default)] - pub hostname: String, + hostname: String, #[serde(default)] - pub uid: String, + uid: String, #[serde(default)] - pub mac: String, + mac: String, +} + +#[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)] +pub struct Post { + #[serde(default)] + lic: License, + #[serde(default)] + email: String, + #[serde(default)] + status: String, } const LICENSE_FILE: &'static str = ".license.txt"; @@ -32,16 +42,47 @@ pub fn check_lic(email: &str) -> bool { return false; } + match check_email(lic.clone(), email.to_owned()) { + Ok(v) => { + if v { + write_lic(&lic); + } + return v; + } + Err(err) => { + log::error!("{}", err); + return false; + } + } +} + +fn write_lic(lic: &License) { if let Ok(s) = enc_lic(&lic) { - if let Ok(mut f) = std::fs::File::create(path) { + if let Ok(mut f) = std::fs::File::create(LICENSE_FILE) { f.write_all(s.as_bytes()).ok(); f.sync_all().ok(); } } - true } -pub fn get_lic() -> License { +fn check_email(lic: License, email: String) -> ResultType { + use reqwest::blocking::Client; + let p: Post = Client::new() + .post("http://rustdesk.com/api/check-email") + .json(&Post { + lic, + email, + ..Default::default() + }) + .send()? + .json()?; + if !p.status.is_empty() { + bail!("{}", p.status); + } + Ok(true) +} + +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() { @@ -52,7 +93,7 @@ pub fn get_lic() -> License { License { hostname, uid, mac } } -pub fn enc_lic(lic: &License) -> ResultType { +fn enc_lic(lic: &License) -> ResultType { let tmp = serde_json::to_vec::(lic)?; const SK: &[u64] = &[ 139, 164, 88, 86, 6, 123, 221, 248, 96, 36, 106, 207, 99, 124, 27, 196, 5, 159, 58, 253, @@ -69,7 +110,7 @@ pub fn enc_lic(lic: &License) -> ResultType { Ok(tmp) } -pub fn dec_lic(s: &str) -> ResultType { +fn dec_lic(s: &str) -> ResultType { 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, From 4662b05d73a1ec44a63388010a0aa5ea0d6a0916 Mon Sep 17 00:00:00 2001 From: opentrade Date: Fri, 9 Apr 2021 18:02:10 +0800 Subject: [PATCH 09/14] dec not working yet --- Cargo.lock | 1 + Cargo.toml | 1 + src/lic.rs | 42 ++++++++++++++++++++++++++++++++++++------ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83271c5..2553df2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -624,6 +624,7 @@ dependencies = [ "lazy_static", "mac_address", "machine-uid", + "rand 0.8.3", "reqwest", "rocksdb", "rust-ini", diff --git a/Cargo.toml b/Cargo.toml index 60b39f3..b56b91c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ machine-uid = "0.2" mac_address = "1.1" whoami = "0.9" base64 = "0.13" +rand = "0.8" [build-dependencies] hbb_common = { path = "libs/hbb_common" } diff --git a/src/lic.rs b/src/lic.rs index 85a2cad..c579dab 100644 --- a/src/lic.rs +++ b/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 std::io::prelude::*; use std::path::Path; @@ -21,6 +29,8 @@ pub struct Post { email: String, #[serde(default)] status: String, + #[serde(default)] + nonce: usize, } const LICENSE_FILE: &'static str = ".license.txt"; @@ -66,18 +76,27 @@ fn write_lic(lic: &License) { } fn check_email(lic: License, email: String) -> ResultType { + log::info!("Checking email with the server ..."); + let mut rng = rand::thread_rng(); + let nonce: usize = rng.gen(); use reqwest::blocking::Client; - let p: Post = Client::new() + let resp = Client::new() .post("http://rustdesk.com/api/check-email") .json(&Post { lic, email, + nonce, ..Default::default() }) - .send()? - .json()?; - if !p.status.is_empty() { - bail!("{}", p.status); + .send()?; + if resp.status().is_success() { + let text = base64::decode(resp.text()?)?; + let p = dec_data(&text, nonce)?; + if !p.status.is_empty() { + bail!("{}", p.status); + } + } else { + bail!("Server error: {}", resp.status()); } Ok(true) } @@ -127,5 +146,16 @@ fn dec_lic(s: &str) -> ResultType { } } +fn dec_data(data: &[u8], n: usize) -> ResultType { + 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::(&res)?); + } + bail!("Encryption error"); +} + pub const EMAIL_ARG: &'static str = "-m, --email=[EMAIL] 'Sets your email address registered with RustDesk'"; From 321bccc19e1644d8e69f41efe0e30117b2288021 Mon Sep 17 00:00:00 2001 From: opentrade Date: Sat, 10 Apr 2021 01:16:02 +0800 Subject: [PATCH 10/14] works --- libs/hbb_common | 2 +- src/lic.rs | 34 +++++++++++++++++----------------- src/main.rs | 6 +++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/libs/hbb_common b/libs/hbb_common index 98257ca..9948718 160000 --- a/libs/hbb_common +++ b/libs/hbb_common @@ -1 +1 @@ -Subproject commit 98257ca5b799ecae53e2fc3ec20bb997a2f6206c +Subproject commit 99487187a6b25380b9a412f040f43f319ece7545 diff --git a/src/lic.rs b/src/lic.rs index c579dab..452a60f 100644 --- a/src/lic.rs +++ b/src/lic.rs @@ -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 { +fn check_email(machine: Machine, email: String) -> ResultType { 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 { 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 { 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 { - let tmp = serde_json::to_vec::(lic)?; +fn enc_machine(machine: &Machine) -> ResultType { + let tmp = serde_json::to_vec::(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 { Ok(tmp) } -fn dec_lic(s: &str) -> ResultType { +fn dec_machine(s: &str) -> ResultType { 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 { 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::(&data)?) + Ok(serde_json::from_slice::(&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 = 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> = Default::default(); - if !lic::check_lic(&get_arg("email", "")) { - return Ok(()); - } RendezvousServer::start( &addr, &addr2, From b1a37379c8a93c3d194415a5f0900845498bfc99 Mon Sep 17 00:00:00 2001 From: opentrade Date: Sat, 10 Apr 2021 01:42:35 +0800 Subject: [PATCH 11/14] compile warn --- src/lic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lic.rs b/src/lic.rs index 452a60f..ad164b6 100644 --- a/src/lic.rs +++ b/src/lic.rs @@ -1,7 +1,7 @@ use hbb_common::{ bail, log, sodiumoxide::crypto::{ - secretbox::{self, Key, Nonce}, + secretbox::{self, Nonce}, sign, }, ResultType, From c5e102fa6ec8bf080f50d6c46850de2e6c31df9c Mon Sep 17 00:00:00 2001 From: opentrade Date: Sat, 10 Apr 2021 10:41:27 +0800 Subject: [PATCH 12/14] Only ed25519 --- Cargo.lock | 8 ++++- Cargo.toml | 2 +- src/lic.rs | 102 +++++++++++++---------------------------------------- 3 files changed, 33 insertions(+), 79 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2553df2..ac87061 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -245,6 +245,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "cryptoxide" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46212f5d1792f89c3e866fb10636139464060110c568edd7f73ab5e9f736c26d" + [[package]] name = "ct-logs" version = "0.6.0" @@ -620,11 +626,11 @@ version = "1.1.3" dependencies = [ "base64 0.13.0", "clap", + "cryptoxide", "hbb_common", "lazy_static", "mac_address", "machine-uid", - "rand 0.8.3", "reqwest", "rocksdb", "rust-ini", diff --git a/Cargo.toml b/Cargo.toml index b56b91c..fb8e43c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ machine-uid = "0.2" mac_address = "1.1" whoami = "0.9" base64 = "0.13" -rand = "0.8" +cryptoxide = "0.3" [build-dependencies] hbb_common = { path = "libs/hbb_common" } diff --git a/src/lic.rs b/src/lic.rs index ad164b6..9f36063 100644 --- a/src/lic.rs +++ b/src/lic.rs @@ -1,12 +1,4 @@ -use hbb_common::{ - bail, log, - sodiumoxide::crypto::{ - secretbox::{self, Nonce}, - sign, - }, - ResultType, -}; -use rand::Rng; +use hbb_common::{bail, log, ResultType}; use serde_derive::{Deserialize, Serialize}; use std::io::prelude::*; use std::path::Path; @@ -24,13 +16,11 @@ pub struct Machine { #[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)] pub struct Post { #[serde(default)] - machine: Machine, + machine: String, #[serde(default)] email: String, #[serde(default)] status: String, - #[serde(default)] - nonce: usize, } const LICENSE_FILE: &'static str = ".license.txt"; @@ -40,10 +30,8 @@ pub fn check_lic(email: &str) -> bool { 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_machine(&contents) { - if machine == old_lic { - return true; - } + if verify(&contents, &machine) { + return true; } } @@ -52,11 +40,8 @@ pub fn check_lic(email: &str) -> bool { return false; } - match check_email(machine.clone(), email.to_owned()) { + match check_email(machine, email.to_owned()) { Ok(v) => { - if v { - write_lic(&machine); - } return v; } Err(err) => { @@ -66,96 +51,59 @@ pub fn check_lic(email: &str) -> bool { } } -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(); - } +fn write_lic(lic: &str) { + if let Ok(mut f) = std::fs::File::create(LICENSE_FILE) { + f.write_all(lic.as_bytes()).ok(); + f.sync_all().ok(); } } -fn check_email(machine: Machine, email: String) -> ResultType { +fn check_email(machine: String, email: String) -> ResultType { log::info!("Checking email with the server ..."); - let mut rng = rand::thread_rng(); - let nonce: usize = rng.gen(); use reqwest::blocking::Client; let resp = Client::new() .post("http://rustdesk.com/api/check-email") .json(&Post { - machine, + machine: machine.clone(), email, - nonce, ..Default::default() }) .send()?; if resp.status().is_success() { - let text = base64::decode(resp.text()?)?; - let p = dec_data(&text, nonce)?; + let p: Post = resp.json()?; + if !verify(&p.machine, &machine) { + bail!("Verification failure"); + } if !p.status.is_empty() { bail!("{}", p.status); } + write_lic(&p.machine); } else { bail!("Server error: {}", resp.status()); } Ok(true) } -fn get_lic() -> Machine { +fn get_lic() -> String { 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) + base64::encode(ma.bytes()) } else { "".to_owned() }; - Machine { hostname, uid, mac } + serde_json::to_string(&Machine { hostname, uid, mac }).unwrap() } -fn enc_machine(machine: &Machine) -> ResultType { - let tmp = serde_json::to_vec::(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, - 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 = 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) -} - -fn dec_machine(s: &str) -> ResultType { - 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 = 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::(&data)?) +fn verify(enc_str: &str, msg: &str) -> bool { + if let Ok(data) = base64::decode(enc_str) { + let key = + b"\xf1T\xc0\x1c\xffee\x86,S*\xd9.\x91\xcd\x85\x12:\xec\xa9 \x99:\x8a\xa2S\x1f Yy\x93R"; + cryptoxide::ed25519::verify(msg.as_bytes(), &key[..], &data) } else { - bail!("sign:verify failed"); + false } } -fn dec_data(data: &[u8], n: usize) -> ResultType { - 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::(&res)?); - } - bail!("Encryption error"); -} - pub const EMAIL_ARG: &'static str = "-m, --email=[EMAIL] 'Sets your email address registered with RustDesk'"; From ea98675b216f34f26d7cba4ba4d7746643be0978 Mon Sep 17 00:00:00 2001 From: opentrade Date: Sat, 10 Apr 2021 10:56:58 +0800 Subject: [PATCH 13/14] minreq to remove libssl dep so that easy to deploy --- Cargo.lock | 593 ++++------------------------------------------------- Cargo.toml | 2 +- src/lic.rs | 29 +-- 3 files changed, 54 insertions(+), 570 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ac87061..6b4e29f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -124,12 +124,6 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" -[[package]] -name = "bytes" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" - [[package]] name = "cc" version = "1.0.65" @@ -208,17 +202,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" dependencies = [ - "core-foundation-sys 0.7.0", - "libc", -] - -[[package]] -name = "core-foundation" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" -dependencies = [ - "core-foundation-sys 0.8.2", + "core-foundation-sys", "libc", ] @@ -228,12 +212,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" -[[package]] -name = "core-foundation-sys" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" - [[package]] name = "crossbeam-utils" version = "0.8.1" @@ -318,7 +296,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b391911b9a786312a10cb9d2b3d0735adfd5a8113eb3648de26a75e91b0826c" dependencies = [ - "rand 0.7.3", + "rand", ] [[package]] @@ -327,15 +305,6 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" -[[package]] -name = "encoding_rs" -version = "0.8.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "env_logger" version = "0.7.1" @@ -384,7 +353,7 @@ checksum = "0c122a393ea57648015bf06fbd3d372378992e86b9ff5a7a497b076a28c79efe" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall 0.1.57", + "redox_syscall", "winapi 0.3.9", ] @@ -394,31 +363,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - -[[package]] -name = "form_urlencoded" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" -dependencies = [ - "matches", - "percent-encoding", -] - [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -538,18 +482,7 @@ checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" dependencies = [ "cfg-if 0.1.10", "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - -[[package]] -name = "getrandom" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -558,26 +491,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -[[package]] -name = "h2" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" -dependencies = [ - "bytes 0.5.6", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", - "tracing-futures", -] - [[package]] name = "hashbrown" version = "0.9.1" @@ -592,7 +505,7 @@ name = "hbb_common" version = "0.1.0" dependencies = [ "anyhow", - "bytes 0.5.6", + "bytes", "confy", "directories-next", "dirs-next", @@ -606,7 +519,7 @@ dependencies = [ "protobuf", "protobuf-codegen-pure", "quinn", - "rand 0.7.3", + "rand", "regex", "serde", "serde_derive", @@ -631,7 +544,7 @@ dependencies = [ "lazy_static", "mac_address", "machine-uid", - "reqwest", + "minreq", "rocksdb", "rust-ini", "serde", @@ -649,39 +562,6 @@ dependencies = [ "libc", ] -[[package]] -name = "http" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" -dependencies = [ - "bytes 1.0.1", - "fnv", - "itoa", -] - -[[package]] -name = "http-body" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" -dependencies = [ - "bytes 0.5.6", - "http", -] - -[[package]] -name = "httparse" -version = "1.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc35c995b9d93ec174cf9a27d425c7892722101e14993cd227fdb51d70cf9589" - -[[package]] -name = "httpdate" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" - [[package]] name = "humantime" version = "1.3.0" @@ -697,64 +577,6 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a" -[[package]] -name = "hyper" -version = "0.13.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a6f157065790a3ed2f88679250419b5cdd96e714a0d65f7797fd337186e96bb" -dependencies = [ - "bytes 0.5.6", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-tls" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed" -dependencies = [ - "bytes 0.5.6", - "hyper", - "native-tls", - "tokio", - "tokio-tls", -] - -[[package]] -name = "idna" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "indexmap" -version = "1.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" -dependencies = [ - "autocfg", - "hashbrown", -] - [[package]] name = "iovec" version = "0.1.4" @@ -764,12 +586,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ipnet" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" - [[package]] name = "itertools" version = "0.9.0" @@ -889,15 +705,9 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f1595709b0a7386bcd56ba34d250d626e5503917d05d32cdccddcd68603e212" dependencies = [ - "winreg 0.6.2", + "winreg", ] -[[package]] -name = "matches" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" - [[package]] name = "memchr" version = "2.3.4" @@ -905,19 +715,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] -name = "mime" -version = "0.3.16" +name = "minreq" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" - -[[package]] -name = "mime_guess" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" +checksum = "781e56f7d29192378f0a04948b1e6aec67ce561273b2dd26ac510bbe88d7be70" dependencies = [ - "mime", - "unicase", + "punycode", ] [[package]] @@ -984,24 +787,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "native-tls" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework 2.2.0", - "security-framework-sys 2.2.0", - "tempfile", -] - [[package]] name = "net2" version = "0.2.36" @@ -1051,39 +836,12 @@ version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" -[[package]] -name = "openssl" -version = "0.10.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a61075b62a23fef5a29815de7536d940aa35ce96d18ce0cc5076272db678a577" -dependencies = [ - "bitflags", - "cfg-if 1.0.0", - "foreign-types", - "libc", - "once_cell", - "openssl-sys", -] - [[package]] name = "openssl-probe" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" -[[package]] -name = "openssl-sys" -version = "0.9.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "313752393519e876837e09e1fa183ddef0be7735868dced3196f4472d536277f" -dependencies = [ - "autocfg", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "ordered-multimap" version = "0.3.1" @@ -1100,12 +858,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" -[[package]] -name = "percent-encoding" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" - [[package]] name = "pin-project" version = "1.0.2" @@ -1223,6 +975,12 @@ dependencies = [ "protobuf-codegen", ] +[[package]] +name = "punycode" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9e1dcb320d6839f6edb64f7a4a59d39b30480d4d1765b56873f7c858538a5fe" + [[package]] name = "quick-error" version = "1.2.3" @@ -1235,7 +993,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88de58d76d8f82fb28e5c89302119c102bb5b9ce57b034186b559b63ba147a0f" dependencies = [ - "bytes 0.5.6", + "bytes", "err-derive", "futures", "libc", @@ -1253,10 +1011,10 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0ea0a358c179c6b7af34805c675d1664a9c6a234a7acd7efdbb32d2f39d3d2a" dependencies = [ - "bytes 0.5.6", + "bytes", "ct-logs", "err-derive", - "rand 0.7.3", + "rand", "ring", "rustls", "rustls-native-certs", @@ -1280,23 +1038,11 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom 0.1.15", + "getrandom", "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc 0.2.0", -] - -[[package]] -name = "rand" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" -dependencies = [ - "libc", - "rand_chacha 0.3.0", - "rand_core 0.6.2", - "rand_hc 0.3.0", + "rand_chacha", + "rand_core", + "rand_hc", ] [[package]] @@ -1306,17 +1052,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core 0.5.1", -] - -[[package]] -name = "rand_chacha" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.2", + "rand_core", ] [[package]] @@ -1325,16 +1061,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom 0.1.15", -] - -[[package]] -name = "rand_core" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" -dependencies = [ - "getrandom 0.2.2", + "getrandom", ] [[package]] @@ -1343,16 +1070,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core 0.5.1", -] - -[[package]] -name = "rand_hc" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" -dependencies = [ - "rand_core 0.6.2", + "rand_core", ] [[package]] @@ -1361,23 +1079,14 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" -[[package]] -name = "redox_syscall" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" -dependencies = [ - "bitflags", -] - [[package]] name = "redox_users" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" dependencies = [ - "getrandom 0.1.15", - "redox_syscall 0.1.57", + "getrandom", + "redox_syscall", "rust-argon2", ] @@ -1399,51 +1108,6 @@ version = "0.6.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi 0.3.9", -] - -[[package]] -name = "reqwest" -version = "0.10.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0718f81a8e14c4dbb3b34cf23dc6aaf9ab8a0dfec160c534b3dbca1aaa21f47c" -dependencies = [ - "base64 0.13.0", - "bytes 0.5.6", - "encoding_rs", - "futures-core", - "futures-util", - "http", - "http-body", - "hyper", - "hyper-tls", - "ipnet", - "js-sys", - "lazy_static", - "log", - "mime", - "mime_guess", - "native-tls", - "percent-encoding", - "pin-project-lite 0.2.0", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-tls", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg 0.7.0", -] - [[package]] name = "ring" version = "0.16.18" @@ -1519,7 +1183,7 @@ dependencies = [ "openssl-probe", "rustls", "schannel", - "security-framework 0.4.4", + "security-framework", ] [[package]] @@ -1561,23 +1225,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535" dependencies = [ "bitflags", - "core-foundation 0.7.0", - "core-foundation-sys 0.7.0", + "core-foundation", + "core-foundation-sys", "libc", - "security-framework-sys 0.4.3", -] - -[[package]] -name = "security-framework" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3670b1d2fdf6084d192bc71ead7aabe6c06aa2ea3fbd9cc3ac111fa5c2b1bd84" -dependencies = [ - "bitflags", - "core-foundation 0.9.1", - "core-foundation-sys 0.8.2", - "libc", - "security-framework-sys 2.2.0", + "security-framework-sys", ] [[package]] @@ -1586,17 +1237,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" dependencies = [ - "core-foundation-sys 0.7.0", - "libc", -] - -[[package]] -name = "security-framework-sys" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3676258fd3cfe2c9a0ec99ce3038798d847ce3e4bb17746373eb9f0f1ac16339" -dependencies = [ - "core-foundation-sys 0.8.2", + "core-foundation-sys", "libc", ] @@ -1628,18 +1269,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_urlencoded" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] - [[package]] name = "shlex" version = "0.1.1" @@ -1669,7 +1298,7 @@ checksum = "2c29947abdee2a218277abeca306f25789c938e500ea5a9d4b12a5a504466902" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall 0.1.57", + "redox_syscall", "winapi 0.3.9", ] @@ -1719,20 +1348,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "tempfile" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "rand 0.8.3", - "redox_syscall 0.2.5", - "remove_dir_all", - "winapi 0.3.9", -] - [[package]] name = "termcolor" version = "1.1.2" @@ -1760,28 +1375,13 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "tinyvec" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" - [[package]] name = "tokio" version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6d7ad61edd59bfcc7e80dababf0f4aed2e6d5e0ba1659356ae889752dfc12ff" dependencies = [ - "bytes 0.5.6", + "bytes", "fnv", "futures-core", "iovec", @@ -1810,23 +1410,13 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-util" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" dependencies = [ - "bytes 0.5.6", + "bytes", "futures-core", "futures-io", "futures-sink", @@ -1844,12 +1434,6 @@ dependencies = [ "serde", ] -[[package]] -name = "tower-service" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" - [[package]] name = "tracing" version = "0.1.22" @@ -1857,7 +1441,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" dependencies = [ "cfg-if 1.0.0", - "log", "pin-project-lite 0.2.0", "tracing-attributes", "tracing-core", @@ -1883,49 +1466,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project", - "tracing", -] - -[[package]] -name = "try-lock" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" - -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" -dependencies = [ - "matches", -] - -[[package]] -name = "unicode-normalization" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-width" version = "0.1.8" @@ -1944,24 +1484,6 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" -[[package]] -name = "url" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" -dependencies = [ - "form_urlencoded", - "idna", - "matches", - "percent-encoding", -] - -[[package]] -name = "vcpkg" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" - [[package]] name = "vec_map" version = "0.8.2" @@ -1974,28 +1496,12 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" -[[package]] -name = "want" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log", - "try-lock", -] - [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" -[[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" - [[package]] name = "wasm-bindgen" version = "0.2.68" @@ -2003,8 +1509,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ac64ead5ea5f05873d7c12b545865ca2b8d28adfc50a49b84770a3a97265d42" dependencies = [ "cfg-if 0.1.10", - "serde", - "serde_json", "wasm-bindgen-macro", ] @@ -2023,18 +1527,6 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7866cab0aa01de1edf8b5d7936938a7e397ee50ce24119aef3e1eaa3b6171da" -dependencies = [ - "cfg-if 0.1.10", - "js-sys", - "wasm-bindgen", - "web-sys", -] - [[package]] name = "wasm-bindgen-macro" version = "0.2.68" @@ -2151,15 +1643,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "winreg" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "ws2_32-sys" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index fb8e43c..f48d688 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ serde_json = "1.0" lazy_static = "1.4" clap = "2.33" rust-ini = "0.16" -reqwest = { version = "0.10", features = ["json", "blocking"] } +minreq = { version = "2.3.1", features = ["punycode"] } machine-uid = "0.2" mac_address = "1.1" whoami = "0.9" diff --git a/src/lic.rs b/src/lic.rs index 9f36063..acda22c 100644 --- a/src/lic.rs +++ b/src/lic.rs @@ -60,26 +60,27 @@ fn write_lic(lic: &str) { fn check_email(machine: String, email: String) -> ResultType { log::info!("Checking email with the server ..."); - use reqwest::blocking::Client; - let resp = Client::new() - .post("http://rustdesk.com/api/check-email") - .json(&Post { - machine: machine.clone(), - email, - ..Default::default() - }) + let resp = minreq::post("http://rustdesk.com/api/check-email") + .with_body( + serde_json::to_string(&Post { + machine: machine.clone(), + email, + ..Default::default() + }) + .unwrap(), + ) .send()?; - if resp.status().is_success() { - let p: Post = resp.json()?; - if !verify(&p.machine, &machine) { - bail!("Verification failure"); - } + if resp.reason_phrase == "OK" { + let p: Post = serde_json::from_str(&resp.as_str()?)?; if !p.status.is_empty() { bail!("{}", p.status); } + if !verify(&p.machine, &machine) { + bail!("Verification failure"); + } write_lic(&p.machine); } else { - bail!("Server error: {}", resp.status()); + bail!("Server error: {}", resp.reason_phrase); } Ok(true) } From cefbec9a1c3a2e30413e99011363dda1b24e9c7b Mon Sep 17 00:00:00 2001 From: opentrade Date: Sat, 10 Apr 2021 22:35:14 +0800 Subject: [PATCH 14/14] rustdesk.com/server --- src/lic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lic.rs b/src/lic.rs index acda22c..2970c0d 100644 --- a/src/lic.rs +++ b/src/lic.rs @@ -36,7 +36,7 @@ pub fn check_lic(email: &str) -> bool { } if email.is_empty() { - log::error!("Registered email required."); + log::error!("Registered email required (-m option). Please visit https://rustdesk.com/server for more infomration."); return false; }