Skip to content

Fixed redaction and added logout #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 86 additions & 2 deletions auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,37 @@ void KeyAuth::api::forgot(std::string username, std::string email)
load_response_data(json);
}

void KeyAuth::api::logout() {
checkInit();

auto data =
XorStr("type=logout") +
XorStr("&sessionid=") + sessionid +
XorStr("&name=") + name +
XorStr("&ownerid=") + ownerid;
auto response = req(data, url);
auto json = response_decoder.parse(response);
if (json[(XorStr("success"))]) {

//clear all old user data from program
user_data.createdate.clear();
user_data.ip.clear();
user_data.hwid.clear();
user_data.lastlogin.clear();
user_data.username.clear();
user_data.subscriptions.clear();

//clear sessionid
sessionid.clear();

//clear enckey
enckey.clear();

}

load_response_data(json);
}

// credits https://stackoverflow.com/a/3790661
static std::string hexDecode(const std::string& hex)
{
Expand Down Expand Up @@ -1466,8 +1497,61 @@ std::string getPath() {
}
}

void RedactField(nlohmann::json& jsonObject, const std::string& fieldName)
{

if (jsonObject.contains(fieldName)) {
jsonObject[fieldName] = "REDACTED";
}
}

void debugInfo(std::string data, std::string url, std::string response) {

//turn response into json
nlohmann::json responses = nlohmann::json::parse(response);
RedactField(responses, "sessionid");
RedactField(responses, "ownerid");
RedactField(responses, "app");
RedactField(responses, "name");
RedactField(responses, "contents");
RedactField(responses, "key");
RedactField(responses, "username");
RedactField(responses, "password");
RedactField(responses, "secret");
RedactField(responses, "version");
RedactField(responses, "fileid");
RedactField(responses, "webhooks");
std::string redacted_response = responses.dump();

//turn data into json
std::replace(data.begin(), data.end(), '&', ' ');

nlohmann::json datas;

std::istringstream iss(data);
std::vector<std::string> results((std::istream_iterator<std::string>(iss)),
std::istream_iterator<std::string>());

for (auto const& value : results) {
datas[value.substr(0, value.find('='))] = value.substr(value.find('=') + 1);
}

RedactField(datas, "sessionid");
RedactField(datas, "ownerid");
RedactField(datas, "app");
RedactField(datas, "name");
RedactField(datas, "key");
RedactField(datas, "username");
RedactField(datas, "password");
RedactField(datas, "contents");
RedactField(datas, "secret");
RedactField(datas, "version");
RedactField(datas, "fileid");
RedactField(datas, "webhooks");

std::string redacted_data = datas.dump();


//gets the path
std::string path = getPath();

Expand All @@ -1485,7 +1569,7 @@ void debugInfo(std::string data, std::string url, std::string response) {
///////////////////////

//creates variables for the paths needed :smile:
std::string KeyAuthPath = path + "\\KeyAuth";
std::string KeyAuthPath = path + "\\KeyAuth";
std::string logPath = KeyAuthPath + "\\Debug\\" + filenameOnly.substr(0, filenameOnly.size() - 4);

//basically loops until we have all the paths
Expand Down Expand Up @@ -1530,7 +1614,7 @@ void debugInfo(std::string data, std::string url, std::string response) {

std::string currentTimeString = std::to_string(hours) + ":" + formattedMinutes + " " + period;

std::string contents = "\n\n@ " + currentTimeString + "\nData sent : " + data + "\nResponse : " + response + "Sent to: " + url;
std::string contents = "\n\n@ " + currentTimeString + "\nData sent : " + redacted_data + "\nResponse : " + redacted_response + "Sent to: " + url;

logfile << contents;

Expand Down
1 change: 1 addition & 0 deletions auth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace KeyAuth {
std::string fetchonline();
void fetchstats();
void forgot(std::string username, std::string email);
void logout();

class subscriptions_class {
public:
Expand Down