Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5511f8a

Browse files
author
mak6969
authored
Merge pull request #14 from zegevlier/main
Improved a lot of stuff
2 parents e445c43 + 7a77078 commit 5511f8a

File tree

5 files changed

+135
-90
lines changed

5 files changed

+135
-90
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/*

Cargo.lock

Lines changed: 28 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
[package]
2-
name = "keyauth"
3-
version = "0.1.0"
42
authors = ["zegevlier <[email protected]>"]
53
edition = "2018"
4+
name = "keyauth"
5+
version = "0.2.0"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
uuid = { version= "0.8.1", features = ["v4"] }
11-
rust-crypto = "0.2.36"
12-
reqwest = { version = "0.10.9", features = ["blocking"] }
13-
hex = "0.4.2"
1410
aes = "0.6.0"
15-
block-modes = "0.7.0"
1611
base16 = "0.2.1"
17-
machine_uuid = "0.1.0"
12+
block-modes = "0.7.0"
13+
hex = "0.4.2"
14+
machine_uuid = "0.1.0"
15+
obfstr = "0.2.1"
16+
reqwest = {version = "0.10.10", features = ["blocking"]}
17+
rust-crypto = "0.2.36"
18+
serde = {version = "1.0.118", features = ["derive"]}
19+
serde_json = "1.0.61"
20+
uuid = {version = "0.8.1", features = ["v4"]}

src/keyauth.rs

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
use base16::encode_lower;
22
use crypto::{digest::Digest, sha2::Sha256};
33
use hex::decode;
4+
use machine_uuid;
45
use reqwest::blocking::Client;
6+
use serde::Deserialize;
7+
use serde_json;
58
use uuid::Uuid;
6-
use machine_uuid;
79

810
use aes::Aes256;
911
use block_modes::block_padding::Pkcs7;
1012
use block_modes::{BlockMode, Cbc};
1113

12-
const BASE_URL: &str = "https://keyauth.com/api/";
14+
const BASE_URL: &str = "https://keyauth.com/api/v2/";
1315

1416
type Aes256Cbc = Cbc<Aes256, Pkcs7>;
17+
1518
pub struct KeyauthApi {
1619
name: String,
1720
owner_id: String,
1821
secret: String,
22+
key: Option<String>,
23+
init_iv: String,
24+
}
25+
26+
#[derive(Deserialize, Debug)]
27+
pub struct Key {
28+
key: String,
29+
expiry: String,
30+
level: u32,
1931
}
2032

2133
impl KeyauthApi {
@@ -24,68 +36,92 @@ impl KeyauthApi {
2436
name: name,
2537
owner_id: owner_id,
2638
secret: secret,
39+
key: None,
40+
init_iv: String::new(),
2741
}
2842
}
2943

30-
pub fn init(&self) -> Result<(), String> {
44+
pub fn init(&mut self) -> Result<(), String> {
3145
let session_iv = Uuid::new_v4().to_simple().to_string()[..8].to_string();
3246
let mut hasher = Sha256::new();
3347
hasher.input(session_iv.as_bytes());
3448
let init_iv: String = hasher.result_str();
49+
self.init_iv = init_iv;
3550
let data = format!(
3651
"type={}&name={}&ownerid={}&init_iv={}",
3752
encode_lower(b"init"),
3853
encode_lower(self.name.as_bytes()),
3954
encode_lower(self.owner_id.as_bytes()),
40-
&init_iv
55+
&self.init_iv
4156
);
57+
4258

4359
let req = Self::make_req(data);
4460

45-
let response = Encryption::decrypt(req.text().unwrap(), &self.secret, &init_iv);
61+
let response = Encryption::decrypt(req.text().unwrap(), &self.secret, &self.init_iv);
4662

47-
if response == "KeyAuth_Disabled".to_string() {
48-
Err("The program key you tried to use doesn't exist".to_string())
49-
} else if response == "KeyAuth_Initialized".to_string() {
63+
let json_rep: serde_json::Value = serde_json::from_str(&response).unwrap();
64+
if json_rep["success"].as_bool().unwrap() {
5065
Ok(())
5166
} else {
52-
Err("The program key you tried to use doesn't exist".to_string())
67+
Err(json_rep["message"].as_str().unwrap().to_string())
5368
}
5469
}
5570

56-
pub fn login(&self, key: String, hwid: Option<String>) -> Result<(), String> {
71+
pub fn login(&mut self, key: String, hwid: Option<String>) -> Result<Key, String> {
5772
let hwid = match hwid {
5873
Some(hwid) => hwid,
5974
None => Self::get_hwid(),
6075
};
61-
let session_iv = Uuid::new_v4().to_simple().to_string()[..8].to_string();
62-
let mut hasher = Sha256::new();
63-
hasher.input(session_iv.as_bytes());
64-
let init_iv: String = hasher.result_str();
76+
if self.init_iv == String::new() {
77+
return Err("NotInitalized".to_string());
78+
}
6579

6680
let data = format!(
6781
"type={}&key={}&hwid={}&name={}&ownerid={}&init_iv={}",
6882
encode_lower(b"login"),
69-
Encryption::encrypt(key, &self.secret, &init_iv),
70-
Encryption::encrypt(hwid, &self.secret, &init_iv),
83+
Encryption::encrypt(&key, &self.secret, &self.init_iv),
84+
Encryption::encrypt(&hwid, &self.secret, &self.init_iv),
7185
encode_lower(self.name.as_bytes()),
7286
encode_lower(self.owner_id.as_bytes()),
73-
&init_iv
87+
&self.init_iv
7488
);
7589

7690
let req = Self::make_req(data);
7791

78-
let response = Encryption::decrypt(req.text().unwrap(), &self.secret, &init_iv);
79-
if response == "KeyAuth_Valid".to_string() {
92+
let response = Encryption::decrypt(req.text().unwrap(), &self.secret, &self.init_iv);
93+
let json_rep: serde_json::Value = serde_json::from_str(&response).unwrap();
94+
if json_rep["success"].as_bool().unwrap() {
95+
self.key = Some(key);
96+
Ok(serde_json::from_value(json_rep["info"].clone()).unwrap())
97+
} else {
98+
Err(json_rep["message"].as_str().unwrap().to_string())
99+
}
100+
}
101+
102+
pub fn log(&self, msg: String) -> Result<(), String> {
103+
if msg.len() > 128 {
104+
return Err("MaxLogSize128".to_string());
105+
}
106+
match self.key {
107+
Some(_) => {}
108+
None => return Err("NotLoggedIn".to_string()),
109+
};
110+
let key = self.key.clone().unwrap();
111+
let data = format!(
112+
"type={}&key={}&message={}&name={}&ownerid={}&init_iv={}",
113+
encode_lower(b"log"),
114+
Encryption::encrypt(&key, &self.secret, &self.init_iv),
115+
Encryption::encrypt(&msg, &self.secret, &self.init_iv),
116+
encode_lower(self.name.as_bytes()),
117+
encode_lower(self.owner_id.as_bytes()),
118+
&self.init_iv,
119+
);
120+
let resp = Self::make_req(data);
121+
if resp.status().is_success() {
80122
Ok(())
81-
} else if response == "KeyAuth_Invalid".to_string() {
82-
Err("Key not found".to_string())
83-
} else if response == "KeyAuth_InvalidHWID".to_string() {
84-
Err("This computer doesn't match the computer the key is locked to. If you reset your computer, contact the application owner".to_string())
85-
} else if response == "KeyAuth_Expired".to_string() {
86-
Err("This key is expired".to_string())
87123
} else {
88-
Err("Application Failed To Connect. Try again or contact application owner".to_string())
124+
Err(resp.status().as_str().to_string())
89125
}
90126
}
91127

@@ -104,7 +140,7 @@ impl KeyauthApi {
104140
if cfg!(windows) {
105141
machine_uuid::get()
106142
} else {
107-
"None".into()
143+
"None".to_string()
108144
}
109145
}
110146
}
@@ -127,7 +163,7 @@ impl Encryption {
127163
cipher.decrypt_vec(&mut buf).unwrap()
128164
}
129165

130-
fn encrypt(message: String, enc_key: &String, iv: &String) -> String {
166+
fn encrypt(message: &String, enc_key: &String, iv: &String) -> String {
131167
let mut hasher = Sha256::new();
132168
hasher.input(enc_key.as_bytes());
133169
let _key: String = hasher.result_str()[..32].to_owned();

0 commit comments

Comments
 (0)