Skip to content

Commit 7147d9d

Browse files
Merge pull request #3 from ELF-Nigel/main
Add server time drift checks to prevent clock tampering
2 parents e434062 + 78d8222 commit 7147d9d

File tree

10 files changed

+3702
-2181
lines changed

10 files changed

+3702
-2181
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
rust-check:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: checkout
12+
uses: actions/checkout@v4
13+
14+
- name: setup rust
15+
uses: dtolnay/rust-toolchain@stable
16+
17+
- name: cargo clippy
18+
run: cargo clippy --all-targets --all-features -- -D warnings
19+
20+
- name: cargo test
21+
run: cargo test --all-features

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@ serde_json = "1.0.86"
1717
machine_uuid = "0.1.0"
1818
hmac-sha256 = { version = "1.1.4", optional = true}
1919
hex = "0.4.3"
20+
ed25519-dalek = { version = "2", features = ["std"], optional = true }
2021
base16 = { version = "0.2.1", features = ["alloc"] }
2122
uuid = {version="1.2.1", features=["v4"] }
2223
serde = { version = "1.0.126", features = ["derive"] }
2324
reqwest = { version = "0.11.12", features = ["blocking"] }
2425
httparse = { version = "1.8.0", optional = true }
26+
httpdate = "1.0"
2527

2628
[features]
27-
default = ["v1_2"]
29+
default = ["v1_3"]
2830
v1_0 = ["dep:aes", "dep:block-modes", "dep:sha256"]
2931
v1_1 = []
3032
v1_2 = ["dep:hmac-sha256"]
33+
v1_3 = ["dep:hmac-sha256", "dep:ed25519-dalek"]
3134
seller = []
32-
all = ["v1_0", "v1_1", "v1_2", "seller", "panic", "web_loader"]
35+
all = ["v1_0", "v1_1", "v1_2", "v1_3", "seller", "panic", "web_loader"]
3336
panic = []
3437
web_loader = ["dep:httparse"]
3538

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# KeyAuth Rust library
22
https://docs.rs/keyauth/latest/keyauth/
33

4-
Credits: [@davidon-top](https://github.com/davidon-top)
4+
Credits: Nigel (Discord: chefendpoint, Telegram: ELF_Nigel)
55

66
## **Bugs**
77

@@ -18,7 +18,7 @@ service, where the service provides users with access to any substantial set of
1818
the features or functionality of the software.
1919

2020
* You may not move, change, disable, or circumvent the license key functionality
21-
in the software, and you may not remove or obscure any functionality in the
21+
to the software, and you may not remove or obscure any functionality in the
2222
software that is protected by the license key.
2323

2424
* You may not alter, remove, or obscure any licensing, copyright, or other notices
@@ -31,4 +31,5 @@ Thank you for your compliance, we work hard on the development of KeyAuth and do
3131

3232
KeyAuth is a powerful cloud-based authentication system designed to protect your software from piracy and unauthorized access. With KeyAuth, you can implement secure licensing, user management, and subscription systems in minutes. Client SDKs available for [C#](https://github.com/KeyAuth/KeyAuth-CSHARP-Example), [C++](https://github.com/KeyAuth/KeyAuth-CPP-Example), [Python](https://github.com/KeyAuth/KeyAuth-Python-Example), [Java](https://github.com/KeyAuth-Archive/KeyAuth-JAVA-api), [JavaScript](https://github.com/mazkdevf/KeyAuth-JS-Example), [VB.NET](https://github.com/KeyAuth/KeyAuth-VB-Example), [PHP](https://github.com/KeyAuth/KeyAuth-PHP-Example), [Rust](https://github.com/KeyAuth/KeyAuth-Rust-Example), [Go](https://github.com/mazkdevf/KeyAuth-Go-Example), [Lua](https://github.com/mazkdevf/KeyAuth-Lua-Examples), [Ruby](https://github.com/mazkdevf/KeyAuth-Ruby-Example), and [Perl](https://github.com/mazkdevf/KeyAuth-Perl-Example). KeyAuth has several unique features such as memory streaming, webhook function where you can send requests to API without leaking the API, discord webhook notifications, ban the user securely through the application at your discretion. Feel free to join https://t.me/keyauth if you have questions or suggestions.
3333

34-
Looking for a Discord bot made by the KeyAuth & RestoreCord founder that you can use to backup your Discord members, server settings, and messages? Go to https://vaultcord.com
34+
## API Version (Default)
35+
This library now defaults to API **1.3**. If you need older versions, disable default features and enable `v1_2`, `v1_1`, or `v1_0` explicitly.

src/lib.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,32 @@ unofficial [keyauth](https://keyauth.cc) library that implements all versions of
33
to make an api version available use the feature flag for that version.
44
example
55
```toml
6-
keyauth = { version = "*" } # this will enable 1.2 api version (default)
6+
keyauth = { version = "*" } # this will enable 1.3 api version (default)
77
```
8-
by default the 1.2 api is enabled because it is most commonly used. so if you dont want the 1.2 api you have to disable it.
8+
by default the 1.3 api is enabled because it is most commonly used. so if you dont want the 1.3 api you have to disable it.
99
```toml
10-
keyauth = { version = "*", features = ["v1_1", "seller"], default-features = false } # this will enable 1.1 and seller api
10+
keyauth = { version = "*", features = ["v1_2", "v1_1", "seller"], default-features = false } # this will enable 1.2, 1.1 and seller api
1111
```
12-
the ``default-features = false`` disabled the default v1_2 api.
12+
the ``default-features = false`` disabled the default v1_3 api.
1313
1414
basic usage:
15-
```rust
16-
let mut auth = keyauth::v1_2::KeyauthApi::new("application name", "ownerid", "application secret", "application version", "api url"); // if you dont have a custom domain for api use "https://keyauth.win/api/1.2/"
15+
```no_run
16+
use keyauth::v1_3::KeyauthApi;
17+
18+
let mut auth = KeyauthApi::new(
19+
"application name",
20+
"ownerid",
21+
"application secret",
22+
"application version",
23+
"https://keyauth.win/api/1.3/",
24+
); // if you dont have a custom domain for api use "https://keyauth.win/api/1.3/"
1725
auth.init(None).unwrap(); // None -> no hash set, Some("hash") -> if you have has checking enabled
18-
auth.login("username".to_string(), "password".to_string(), Some("hwid".to_string())).unwrap(); // if you want to automaticly generate hwid use None insted of Some(...)
26+
auth.login(
27+
"username".to_string(),
28+
"password".to_string(),
29+
Some("hwid".to_string()),
30+
)
31+
.unwrap(); // if you want to automaticly generate hwid use None insted of Some(...)
1932
```
2033
2134
also if you want to use an obfuscator for rust i recommend using [obfstr](https://crates.io/crates/obfstr) and [llvm obfuscator](https://github.com/eshard/obfuscator-llvm/wiki/Rust-obfuscation-guide)
@@ -29,6 +42,8 @@ pub mod v1_0;
2942
pub mod v1_1;
3043
#[cfg(feature = "v1_2")]
3144
pub mod v1_2;
45+
#[cfg(feature = "v1_3")]
46+
pub mod v1_3;
3247
#[cfg(feature = "seller")]
3348
pub mod seller;
3449

src/seller.rs

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
use std::collections::HashMap;
2-
use reqwest::blocking::{Client};
3-
use serde_json::Value;
4-
5-
pub(crate) fn request(req_data: HashMap<&str, &str>, url: String) -> reqwest::blocking::Response {
6-
let client = Client::new();
7-
client.get(url)
8-
.query(&req_data)
9-
.header("User-Agent", "KeyAuth")
10-
.send().unwrap()
11-
}
1+
use reqwest::blocking::Client;
2+
use serde_json::Value;
3+
use std::collections::HashMap;
4+
5+
pub(crate) fn request(req_data: HashMap<&str, &str>, url: String) -> reqwest::blocking::Response {
6+
let client = Client::new();
7+
client
8+
.get(url)
9+
.query(&req_data)
10+
.header("User-Agent", "KeyAuth")
11+
.send()
12+
.unwrap()
13+
}
1214

1315
/// https://docs.keyauth.cc/seller/licenses
1416
pub mod licenses {
@@ -20,24 +22,18 @@ pub mod licenses {
2022
pub fn create(sellerkey: &str, url: String, expiry: u64, mask: Option<String>, level: Option<i32>, amount: Option<u8>, owner: Option<String>) -> Result<Vec<String>, String> {
2123
let mut req_data = HashMap::new();
2224
req_data.insert("type", "add");
23-
req_data.insert("sellerkey", &sellerkey);
25+
req_data.insert("sellerkey", sellerkey);
2426
let expiry = expiry.to_string();
2527
req_data.insert("expiry", expiry.as_str());
2628
let mask = match mask {
2729
Some(m) => m,
2830
None => "XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX".to_string(),
2931
};
3032
req_data.insert("mask", mask.as_str());
31-
let level = match level {
32-
Some(l) => l,
33-
None => 1,
34-
};
33+
let level = level.unwrap_or(1);
3534
let level = level.to_string();
3635
req_data.insert("level", level.as_str());
37-
let amount = match amount {
38-
Some(a) => a,
39-
None => 1,
40-
};
36+
let amount = amount.unwrap_or(1);
4137
let amount = amount.to_string();
4238
req_data.insert("amount", amount.as_str());
4339
let owner = match owner {
@@ -104,10 +100,7 @@ pub mod licenses {
104100
req_data.insert("sellerkey", sellerkey);
105101
req_data.insert("key", license);
106102
req_data.insert("type", "del");
107-
let user_too = match user_too {
108-
Some(u) => u,
109-
None => false,
110-
};
103+
let user_too = user_too.unwrap_or_default();
111104
let user_too = if user_too { 1 } else { 0 };
112105
let user_too = user_too.to_string();
113106
req_data.insert("user_too", user_too.as_str());
@@ -220,10 +213,7 @@ pub mod licenses {
220213
req_data.insert("type", "ban");
221214
req_data.insert("key", license);
222215
req_data.insert("reason", reason);
223-
let user_too = match user_too {
224-
Some(u) => u,
225-
None => false,
226-
};
216+
let user_too = user_too.unwrap_or_default();
227217
let user_too = if user_too { 1 } else { 0 };
228218
let user_too = user_too.to_string();
229219
req_data.insert("user_too", user_too.as_str());
@@ -485,10 +475,7 @@ pub mod user {
485475
req_data.insert("user", name);
486476
req_data.insert("sub", sub);
487477
req_data.insert("expiry", days);
488-
let active_only = match active_only {
489-
Some(a) => a,
490-
None => false,
491-
};
478+
let active_only = active_only.unwrap_or_default();
492479
let active_only = if active_only { "1" } else { "0" };
493480
req_data.insert("active_only", active_only);
494481

@@ -1208,12 +1195,12 @@ pub mod blacklists {
12081195
let mut req_data = HashMap::new();
12091196
req_data.insert("sellerkey", sellerkey);
12101197
req_data.insert("type", "black");
1211-
if ip.is_some() {
1212-
req_data.insert("ip", ip.unwrap());
1213-
}
1214-
if hwid.is_some() {
1215-
req_data.insert("hwid", hwid.unwrap());
1216-
}
1198+
if let Some(ip) = ip {
1199+
req_data.insert("ip", ip);
1200+
}
1201+
if let Some(hwid) = hwid {
1202+
req_data.insert("hwid", hwid);
1203+
}
12171204

12181205
let res = super::request(req_data, url);
12191206
let resp = res.text().unwrap();
@@ -1553,4 +1540,4 @@ pub mod web_loader {
15531540
}
15541541
Err(json["message"].to_string())
15551542
}
1556-
}
1543+
}

src/test.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#[test]
2+
#[ignore]
23
fn bench2() {
34
let mut keyauth = crate::v1_2::KeyauthApi::new("library-development", "EdmsTKiuld", "9f752b6a414455175efd942abfd2183667413d57b1d59d6742d8437c71802b49", "1.0", "https://keyauth.win/api/1.2/");
4-
keyauth.init(None);
5-
keyauth.login("demoseller".to_string(), "R9yzxdRyybgY75".to_string(), None);
5+
let _ = keyauth.init(None);
6+
let _ = keyauth.login("demoseller".to_string(), "R9yzxdRyybgY75".to_string(), None);
67
}
78

89
#[test]
910
#[cfg(feature = "v1_0")]
11+
#[ignore]
1012
fn bench1() {
1113
let mut keyauth = crate::v1_0::KeyauthApi::new("library-development", "EdmsTKiuld", "9f752b6a414455175efd942abfd2183667413d57b1d59d6742d8437c71802b49", "1.0", "https://keyauth.win/api/1.0/");
12-
keyauth.init(None);
13-
keyauth.login("demoseller".to_string(), "R9yzxdRyybgY75".to_string(), None);
14+
let _ = keyauth.init(None);
15+
let _ = keyauth.login("demoseller".to_string(), "R9yzxdRyybgY75".to_string(), None);
1416
}

0 commit comments

Comments
 (0)