config: add token_valid_for
This commit is contained in:
@@ -81,5 +81,8 @@
|
|||||||
|
|
||||||
// Where to save the logfile. Each run will continue appending to this file. It may grow HUGE! No automatic pruning / compression is done.
|
// Where to save the logfile. Each run will continue appending to this file. It may grow HUGE! No automatic pruning / compression is done.
|
||||||
"traffic_log_file": "./traffic.csv"
|
"traffic_log_file": "./traffic.csv"
|
||||||
}
|
},
|
||||||
|
|
||||||
|
// how long the token (solved challenge) should be valid for before showing a new challenge, in minutes
|
||||||
|
"token_valid_for": 60 // 1 hour
|
||||||
}
|
}
|
||||||
@@ -35,6 +35,7 @@ class CConfig {
|
|||||||
bool trace_logging = false;
|
bool trace_logging = false;
|
||||||
std::vector<SConfigRule> rules = {};
|
std::vector<SConfigRule> rules = {};
|
||||||
int default_challenge_difficulty = 4;
|
int default_challenge_difficulty = 4;
|
||||||
|
int token_valid_for = 60;
|
||||||
bool async_proxy = true;
|
bool async_proxy = true;
|
||||||
std::vector<SProxyRule> proxy_rules;
|
std::vector<SProxyRule> proxy_rules;
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,7 @@
|
|||||||
#include <openssl/evp.h>
|
#include <openssl/evp.h>
|
||||||
#include <magic.h>
|
#include <magic.h>
|
||||||
|
|
||||||
constexpr const uint64_t TOKEN_MAX_AGE_MS = 1000 * 60 * 60; // 1hr
|
constexpr const char* TOKEN_COOKIE_NAME = "checkpoint-token";
|
||||||
constexpr const char* TOKEN_COOKIE_NAME = "checkpoint-token";
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
@@ -216,13 +215,13 @@ void CServerHandler::onRequest(const Pistache::Http::Request& req, Pistache::Htt
|
|||||||
if (TOKEN.valid()) {
|
if (TOKEN.valid()) {
|
||||||
const auto AGE = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() -
|
const auto AGE = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() -
|
||||||
std::chrono::duration_cast<std::chrono::milliseconds>(TOKEN.issued().time_since_epoch()).count();
|
std::chrono::duration_cast<std::chrono::milliseconds>(TOKEN.issued().time_since_epoch()).count();
|
||||||
if (AGE <= TOKEN_MAX_AGE_MS && TOKEN.fingerprint() == NRequestUtils::fingerprintForRequest(req)) {
|
if (AGE <= g_pConfig->m_config.token_valid_for && TOKEN.fingerprint() == NRequestUtils::fingerprintForRequest(req)) {
|
||||||
Debug::log(LOG, " | Action: PASS (token)");
|
Debug::log(LOG, " | Action: PASS (token)");
|
||||||
g_pTrafficLogger->logTraffic(req, "PASS (token)");
|
g_pTrafficLogger->logTraffic(req, "PASS (token)");
|
||||||
proxyPass(req, response);
|
proxyPass(req, response);
|
||||||
return;
|
return;
|
||||||
} else { // token has been used from a different IP or is expired. Nuke it.
|
} else { // token has been used from a different IP or is expired. Nuke it.
|
||||||
if (AGE > TOKEN_MAX_AGE_MS)
|
if (AGE > g_pConfig->m_config.token_valid_for)
|
||||||
Debug::log(LOG, " | Action: CHALLENGE (token expired)");
|
Debug::log(LOG, " | Action: CHALLENGE (token expired)");
|
||||||
else
|
else
|
||||||
Debug::log(LOG, " | Action: CHALLENGE (token fingerprint mismatch)");
|
Debug::log(LOG, " | Action: CHALLENGE (token fingerprint mismatch)");
|
||||||
|
|||||||
Reference in New Issue
Block a user