Skip to content

Commit e805b2f

Browse files
committed
Bug fixes, improve session check security
1 parent d086004 commit e805b2f

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

auth.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ bool KeyAuth::api::checkblack() {
11631163
}
11641164
}
11651165

1166-
void KeyAuth::api::check() {
1166+
void KeyAuth::api::check(bool check_paid) {
11671167
checkInit();
11681168

11691169
auto data =
@@ -1172,7 +1172,12 @@ void KeyAuth::api::check() {
11721172
XorStr("&name=") + name +
11731173
XorStr("&ownerid=") + ownerid;
11741174

1175-
auto response = req(data, url);
1175+
std::string endpoint = url;
1176+
if (check_paid) {
1177+
endpoint += "?check_paid=1";
1178+
}
1179+
1180+
auto response = req(data, endpoint);
11761181

11771182
std::hash<int> hasher;
11781183
int expectedHash = hasher(42);
@@ -1197,7 +1202,9 @@ void KeyAuth::api::check() {
11971202
LI_FN(exit)(9);
11981203
}
11991204
}
1200-
LI_FN(exit)(7);
1205+
else {
1206+
LI_FN(exit)(7);
1207+
}
12011208
}
12021209

12031210
std::string KeyAuth::api::var(std::string varid) {
@@ -1509,15 +1516,15 @@ int VerifyPayload(std::string signature, std::string timestamp, std::string body
15091516
{
15101517
// std::cerr << "Invalid public key format" << std::endl;
15111518
LI_FN(exit)(6);
1512-
}
1519+
};
15131520

15141521
if (crypto_sign_ed25519_verify_detached(sig, reinterpret_cast<const unsigned char*>(message.c_str()), message.length(), pk) != 0)
15151522
{
15161523
// std::cerr << "Signature verification failed" << std::endl;
15171524
LI_FN(exit)(7);
15181525
}
15191526

1520-
// std::cout << "Payload verfied" << std::endl;
1527+
// std::cout << "\n Payload verfied" << std::endl;
15211528

15221529
int value = 42 ^ 0xA5A5;
15231530
return value & 0xFFFF;

auth.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace KeyAuth {
2121

2222
void ban(std::string reason = "");
2323
void init();
24-
void check();
24+
void check(bool check_paid = false);
2525
void log(std::string msg);
2626
void license(std::string key);
2727
std::string var(std::string varid);
@@ -76,8 +76,9 @@ namespace KeyAuth {
7676
public:
7777
// response data
7878
std::vector<channel_struct> channeldata;
79-
bool success{false};
79+
bool success{};
8080
std::string message;
81+
bool isPaid{};
8182
};
8283

8384
userdata user_data;
@@ -120,6 +121,10 @@ namespace KeyAuth {
120121
void load_response_data(nlohmann::json data) {
121122
api::response.success = data[XorStr("success")];
122123
api::response.message = data["message"];
124+
125+
if (data.contains(XorStr("role").c_str()) && data[XorStr("role")] != XorStr("tester").c_str() && data[XorStr("role")] != XorStr("not_checked").c_str()) {
126+
api::response.isPaid = true;
127+
}
123128
}
124129

125130
void load_channel_data(nlohmann::json data) {

library.sln

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31624.102
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33815.320
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "library", "library.vcxproj", "{03A87D79-B6BB-4199-BD0C-97158912F6AB}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10-
Debug|x64 = Debug|x64
11-
Debug|x86 = Debug|x86
1210
Release|x64 = Release|x64
1311
Release|x86 = Release|x86
1412
EndGlobalSection
1513
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16-
{03A87D79-B6BB-4199-BD0C-97158912F6AB}.Debug|x64.ActiveCfg = Debug|x64
17-
{03A87D79-B6BB-4199-BD0C-97158912F6AB}.Debug|x64.Build.0 = Debug|x64
18-
{03A87D79-B6BB-4199-BD0C-97158912F6AB}.Debug|x86.ActiveCfg = Debug|Win32
19-
{03A87D79-B6BB-4199-BD0C-97158912F6AB}.Debug|x86.Build.0 = Debug|Win32
2014
{03A87D79-B6BB-4199-BD0C-97158912F6AB}.Release|x64.ActiveCfg = Release|x64
2115
{03A87D79-B6BB-4199-BD0C-97158912F6AB}.Release|x64.Build.0 = Release|x64
2216
{03A87D79-B6BB-4199-BD0C-97158912F6AB}.Release|x86.ActiveCfg = Release|Win32

0 commit comments

Comments
 (0)