Skip to content

Commit d316569

Browse files
committed
Add fetchStats and fix invalid session by adding delay
1 parent 665ba57 commit d316569

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

auth.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ void KeyAuth::api::init()
127127

128128
if (json[(XorStr("success"))])
129129
{
130+
if (json[(XorStr("newSession"))]) {
131+
Sleep(100);
132+
}
130133
sessionid = json[(XorStr("sessionid"))];
131134
initalized = true;
132135
load_app_data(json[(XorStr("appinfo"))]);
@@ -1078,6 +1081,42 @@ std::string KeyAuth::api::fetchonline()
10781081
return onlineusers;
10791082
}
10801083

1084+
void KeyAuth::api::fetchstats()
1085+
{
1086+
checkInit();
1087+
1088+
auto data =
1089+
XorStr("type=fetchStats") +
1090+
XorStr("&sessionid=") + sessionid +
1091+
XorStr("&name=") + name +
1092+
XorStr("&ownerid=") + ownerid;
1093+
1094+
auto response = req(data, url);
1095+
1096+
auto json = response_decoder.parse(response);
1097+
std::string message = json[(XorStr("message"))];
1098+
1099+
std::stringstream ss_result;
1100+
1101+
std::vector<uint8_t> out(SHA256_HASH_SIZE);
1102+
1103+
hmac_sha256(enckey.data(), enckey.size(), response.data(), response.size(),
1104+
out.data(), out.size());
1105+
1106+
for (uint8_t x : out) {
1107+
ss_result << std::hex << std::setfill('0') << std::setw(2) << (int)x;
1108+
}
1109+
1110+
if (!constantTimeStringCompare(ss_result.str().c_str(), signature.c_str(), sizeof(signature).c_str())) { // check response authenticity, if not authentic program crashes
1111+
error("Signature checksum failed. Request was tampered with or session ended most likely. & echo: & echo Message: " + message);
1112+
}
1113+
1114+
load_response_data(json);
1115+
1116+
if (json[(XorStr("success"))])
1117+
load_app_data(json[(XorStr("appinfo"))]);
1118+
}
1119+
10811120
void KeyAuth::api::forgot(std::string username, std::string email)
10821121
{
10831122
checkInit();

auth.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ namespace KeyAuth {
3939
bool chatsend(std::string message, std::string channel);
4040
void changeusername(std::string newusername);
4141
std::string fetchonline();
42+
void fetchstats();
4243
void forgot(std::string username, std::string email);
4344

4445
class subscriptions_class {

library.vcxproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@
157157
<OptimizeReferences>true</OptimizeReferences>
158158
<GenerateDebugInformation>true</GenerateDebugInformation>
159159
</Link>
160+
<Lib>
161+
<TargetMachine>MachineX64</TargetMachine>
162+
</Lib>
160163
</ItemDefinitionGroup>
161164
<ItemGroup>
162165
<ClCompile Include="auth.cpp" />
@@ -229,4 +232,4 @@
229232
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
230233
<ImportGroup Label="ExtensionTargets">
231234
</ImportGroup>
232-
</Project>
235+
</Project>

0 commit comments

Comments
 (0)