rustdesk лет назад: 4
Родитель
Сommit
26d926838f
3 измененных файлов с 85 добавлено и 14 удалено
  1. 70 12
      Cargo.lock
  2. 1 0
      Cargo.toml
  3. 14 2
      src/lic.rs

+ 70 - 12
Cargo.lock

@@ -296,7 +296,7 @@ version = "0.2.2"
296
 source = "registry+https://github.com/rust-lang/crates.io-index"
296
 source = "registry+https://github.com/rust-lang/crates.io-index"
297
 checksum = "1b391911b9a786312a10cb9d2b3d0735adfd5a8113eb3648de26a75e91b0826c"
297
 checksum = "1b391911b9a786312a10cb9d2b3d0735adfd5a8113eb3648de26a75e91b0826c"
298
 dependencies = [
298
 dependencies = [
299
- "rand",
299
+ "rand 0.7.3",
300
 ]
300
 ]
301
 
301
 
302
 [[package]]
302
 [[package]]
@@ -482,7 +482,18 @@ checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
482
 dependencies = [
482
 dependencies = [
483
  "cfg-if 0.1.10",
483
  "cfg-if 0.1.10",
484
  "libc",
484
  "libc",
485
- "wasi",
485
+ "wasi 0.9.0+wasi-snapshot-preview1",
486
+]
487
+
488
+[[package]]
489
+name = "getrandom"
490
+version = "0.2.2"
491
+source = "registry+https://github.com/rust-lang/crates.io-index"
492
+checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
493
+dependencies = [
494
+ "cfg-if 1.0.0",
495
+ "libc",
496
+ "wasi 0.10.2+wasi-snapshot-preview1",
486
 ]
497
 ]
487
 
498
 
488
 [[package]]
499
 [[package]]
@@ -519,7 +530,7 @@ dependencies = [
519
  "protobuf",
530
  "protobuf",
520
  "protobuf-codegen-pure",
531
  "protobuf-codegen-pure",
521
  "quinn",
532
  "quinn",
522
- "rand",
533
+ "rand 0.7.3",
523
  "regex",
534
  "regex",
524
  "serde",
535
  "serde",
525
  "serde_derive",
536
  "serde_derive",
@@ -545,6 +556,7 @@ dependencies = [
545
  "mac_address",
556
  "mac_address",
546
  "machine-uid",
557
  "machine-uid",
547
  "minreq",
558
  "minreq",
559
+ "rand 0.8.3",
548
  "rocksdb",
560
  "rocksdb",
549
  "rust-ini",
561
  "rust-ini",
550
  "serde",
562
  "serde",
@@ -1014,7 +1026,7 @@ dependencies = [
1014
  "bytes",
1026
  "bytes",
1015
  "ct-logs",
1027
  "ct-logs",
1016
  "err-derive",
1028
  "err-derive",
1017
- "rand",
1029
+ "rand 0.7.3",
1018
  "ring",
1030
  "ring",
1019
  "rustls",
1031
  "rustls",
1020
  "rustls-native-certs",
1032
  "rustls-native-certs",
@@ -1038,11 +1050,23 @@ version = "0.7.3"
1038
 source = "registry+https://github.com/rust-lang/crates.io-index"
1050
 source = "registry+https://github.com/rust-lang/crates.io-index"
1039
 checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
1051
 checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
1040
 dependencies = [
1052
 dependencies = [
1041
- "getrandom",
1053
+ "getrandom 0.1.15",
1054
+ "libc",
1055
+ "rand_chacha 0.2.2",
1056
+ "rand_core 0.5.1",
1057
+ "rand_hc 0.2.0",
1058
+]
1059
+
1060
+[[package]]
1061
+name = "rand"
1062
+version = "0.8.3"
1063
+source = "registry+https://github.com/rust-lang/crates.io-index"
1064
+checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
1065
+dependencies = [
1042
  "libc",
1066
  "libc",
1043
- "rand_chacha",
1044
- "rand_core",
1045
- "rand_hc",
1067
+ "rand_chacha 0.3.0",
1068
+ "rand_core 0.6.2",
1069
+ "rand_hc 0.3.0",
1046
 ]
1070
 ]
1047
 
1071
 
1048
 [[package]]
1072
 [[package]]
@@ -1052,7 +1076,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1052
 checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
1076
 checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
1053
 dependencies = [
1077
 dependencies = [
1054
  "ppv-lite86",
1078
  "ppv-lite86",
1055
- "rand_core",
1079
+ "rand_core 0.5.1",
1080
+]
1081
+
1082
+[[package]]
1083
+name = "rand_chacha"
1084
+version = "0.3.0"
1085
+source = "registry+https://github.com/rust-lang/crates.io-index"
1086
+checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
1087
+dependencies = [
1088
+ "ppv-lite86",
1089
+ "rand_core 0.6.2",
1056
 ]
1090
 ]
1057
 
1091
 
1058
 [[package]]
1092
 [[package]]
@@ -1061,7 +1095,16 @@ version = "0.5.1"
1061
 source = "registry+https://github.com/rust-lang/crates.io-index"
1095
 source = "registry+https://github.com/rust-lang/crates.io-index"
1062
 checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
1096
 checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
1063
 dependencies = [
1097
 dependencies = [
1064
- "getrandom",
1098
+ "getrandom 0.1.15",
1099
+]
1100
+
1101
+[[package]]
1102
+name = "rand_core"
1103
+version = "0.6.2"
1104
+source = "registry+https://github.com/rust-lang/crates.io-index"
1105
+checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
1106
+dependencies = [
1107
+ "getrandom 0.2.2",
1065
 ]
1108
 ]
1066
 
1109
 
1067
 [[package]]
1110
 [[package]]
@@ -1070,7 +1113,16 @@ version = "0.2.0"
1070
 source = "registry+https://github.com/rust-lang/crates.io-index"
1113
 source = "registry+https://github.com/rust-lang/crates.io-index"
1071
 checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
1114
 checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
1072
 dependencies = [
1115
 dependencies = [
1073
- "rand_core",
1116
+ "rand_core 0.5.1",
1117
+]
1118
+
1119
+[[package]]
1120
+name = "rand_hc"
1121
+version = "0.3.0"
1122
+source = "registry+https://github.com/rust-lang/crates.io-index"
1123
+checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
1124
+dependencies = [
1125
+ "rand_core 0.6.2",
1074
 ]
1126
 ]
1075
 
1127
 
1076
 [[package]]
1128
 [[package]]
@@ -1085,7 +1137,7 @@ version = "0.3.5"
1085
 source = "registry+https://github.com/rust-lang/crates.io-index"
1137
 source = "registry+https://github.com/rust-lang/crates.io-index"
1086
 checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d"
1138
 checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d"
1087
 dependencies = [
1139
 dependencies = [
1088
- "getrandom",
1140
+ "getrandom 0.1.15",
1089
  "redox_syscall",
1141
  "redox_syscall",
1090
  "rust-argon2",
1142
  "rust-argon2",
1091
 ]
1143
 ]
@@ -1502,6 +1554,12 @@ version = "0.9.0+wasi-snapshot-preview1"
1502
 source = "registry+https://github.com/rust-lang/crates.io-index"
1554
 source = "registry+https://github.com/rust-lang/crates.io-index"
1503
 checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
1555
 checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
1504
 
1556
 
1557
+[[package]]
1558
+name = "wasi"
1559
+version = "0.10.2+wasi-snapshot-preview1"
1560
+source = "registry+https://github.com/rust-lang/crates.io-index"
1561
+checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
1562
+
1505
 [[package]]
1563
 [[package]]
1506
 name = "wasm-bindgen"
1564
 name = "wasm-bindgen"
1507
 version = "0.2.68"
1565
 version = "0.2.68"

+ 1 - 0
Cargo.toml

@@ -25,6 +25,7 @@ mac_address = "1.1"
25
 whoami = "0.9"
25
 whoami = "0.9"
26
 base64 = "0.13"
26
 base64 = "0.13"
27
 cryptoxide = "0.3"
27
 cryptoxide = "0.3"
28
+rand = "0.8"
28
 
29
 
29
 [build-dependencies]
30
 [build-dependencies]
30
 hbb_common = { path = "libs/hbb_common" }
31
 hbb_common = { path = "libs/hbb_common" }

+ 14 - 2
src/lic.rs

@@ -2,6 +2,7 @@ use hbb_common::{bail, log, ResultType};
2
 use serde_derive::{Deserialize, Serialize};
2
 use serde_derive::{Deserialize, Serialize};
3
 use std::io::prelude::*;
3
 use std::io::prelude::*;
4
 use std::path::Path;
4
 use std::path::Path;
5
+use rand::Rng;
5
 
6
 
6
 #[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)]
7
 #[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)]
7
 pub struct Machine {
8
 pub struct Machine {
@@ -25,6 +26,8 @@ pub struct Post {
25
     version: String,
26
     version: String,
26
     #[serde(default)]
27
     #[serde(default)]
27
     next_check_time: u64,
28
     next_check_time: u64,
29
+    #[serde(default)]
30
+    nonce: String,
28
 }
31
 }
29
 
32
 
30
 const LICENSE_FILE: &'static str = ".license.txt";
33
 const LICENSE_FILE: &'static str = ".license.txt";
@@ -90,12 +93,16 @@ fn write_lic(lic: &str) {
90
 
93
 
91
 fn check_email(machine: String, email: String, version: String) -> ResultType<u64> {
94
 fn check_email(machine: String, email: String, version: String) -> ResultType<u64> {
92
     log::info!("Checking email with the license server ...");
95
     log::info!("Checking email with the license server ...");
96
+    let mut rng = rand::thread_rng();
97
+    let nonce: usize = rng.gen();
98
+    let nonce = nonce.to_string();
93
     let resp = minreq::post("http://rustdesk.com/api/check-email")
99
     let resp = minreq::post("http://rustdesk.com/api/check-email")
94
         .with_body(
100
         .with_body(
95
             serde_json::to_string(&Post {
101
             serde_json::to_string(&Post {
96
                 machine: machine.clone(),
102
                 machine: machine.clone(),
97
                 version,
103
                 version,
98
                 email,
104
                 email,
105
+                nonce: nonce.clone(),
99
                 ..Default::default()
106
                 ..Default::default()
100
             })
107
             })
101
             .unwrap(),
108
             .unwrap(),
@@ -106,10 +113,15 @@ fn check_email(machine: String, email: String, version: String) -> ResultType<u6
106
         if !p.status.is_empty() {
113
         if !p.status.is_empty() {
107
             bail!("{}", p.status);
114
             bail!("{}", p.status);
108
         }
115
         }
109
-        if !verify(&p.machine, &machine) {
116
+        if !verify(&p.nonce, &nonce) {
110
             bail!("Verification failure");
117
             bail!("Verification failure");
111
         }
118
         }
112
-        write_lic(&p.machine);
119
+        if !machine.is_empty() {
120
+            if !verify(&p.machine, &machine) {
121
+                bail!("Verification failure");
122
+            }
123
+            write_lic(&p.machine);
124
+        }
113
         log::info!("License OK");
125
         log::info!("License OK");
114
         let mut wait = p.next_check_time;
126
         let mut wait = p.next_check_time;
115
         if wait == 0 {
127
         if wait == 0 {