From e99f2583b97dac7d2697b755a333e107ca48edc5 Mon Sep 17 00:00:00 2001 From: Morteza Bashsiz Date: Mon, 14 Oct 2024 20:38:08 +0200 Subject: [PATCH] Move token to general in config --- core/src/agenthandler.cpp | 6 +++--- core/src/config.cpp | 6 +++--- core/src/config.hpp | 2 +- core/src/general.hpp | 2 +- core/src/serverhandler.cpp | 6 +++--- nipovpn/etc/nipovpn/config.yaml | 6 ++++-- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/core/src/agenthandler.cpp b/core/src/agenthandler.cpp index 8c6572f..e2637a0 100644 --- a/core/src/agenthandler.cpp +++ b/core/src/agenthandler.cpp @@ -27,7 +27,7 @@ void AgentHandler::handle() { BoolStr encryption{false, std::string("FAILED")}; encryption = - aes256Encrypt(hexStreambufToStr(readBuffer_), config_->agent().token); + aes256Encrypt(hexStreambufToStr(readBuffer_), config_->general().token); if (encryption.ok) { log_->write("[" + to_string(uuid_) + "] [AgentHandler handle] [Encryption Done]", Log::Level::DEBUG); @@ -84,7 +84,7 @@ void AgentHandler::handle() { decryption = aes256Decrypt(decode64(boost::lexical_cast( response->parsedHttpResponse().body())), - config_->agent().token); + config_->general().token); if (boost::lexical_cast(response->parsedHttpResponse()[config_->general().chunkHeader]) == "yes") { end_ = true; } @@ -159,7 +159,7 @@ void AgentHandler::continueRead() { decryption = aes256Decrypt(decode64(boost::lexical_cast( response->parsedHttpResponse().body())), - config_->agent().token); + config_->general().token); if (boost::lexical_cast(response->parsedHttpResponse()[config_->general().chunkHeader]) == "yes") { end_ = true; } diff --git a/core/src/config.cpp b/core/src/config.cpp index 769bf17..68df305 100644 --- a/core/src/config.cpp +++ b/core/src/config.cpp @@ -7,7 +7,8 @@ Config::Config(const RunMode &mode, const std::string &filePath) threads_(0), listenIp_("127.0.0.1"), listenPort_(0), - general_({configYaml_["general"]["fakeUrl"].as(), + general_({configYaml_["general"]["token"].as(), + configYaml_["general"]["fakeUrl"].as(), configYaml_["general"]["method"].as(), configYaml_["general"]["timeWait"].as(), configYaml_["general"]["timeout"].as(), @@ -24,7 +25,6 @@ Config::Config(const RunMode &mode, const std::string &filePath) configYaml_["agent"]["listenPort"].as(), configYaml_["agent"]["serverIp"].as(), configYaml_["agent"]["serverPort"].as(), - configYaml_["agent"]["token"].as(), configYaml_["agent"]["httpVersion"].as(), configYaml_["agent"]["userAgent"].as()}) { std::lock_guard lock(configMutex_); @@ -59,6 +59,7 @@ std::string Config::toString() const { std::stringstream ss; ss << "\nConfig :\n" << " General :\n" + << " token: " << general_.token << "\n" << " fakeUrl: " << general_.fakeUrl << "\n" << " method: " << general_.method << "\n" << " timeWait: " << general_.timeWait << "\n" @@ -79,7 +80,6 @@ std::string Config::toString() const { << " listenPort: " << agent_.listenPort << "\n" << " serverIp: " << agent_.serverIp << "\n" << " serverPort: " << agent_.serverPort << "\n" - << " token: " << agent_.token << "\n" << " httpVersion: " << agent_.httpVersion << "\n" << " userAgent: " << agent_.userAgent << "\n"; return ss.str(); diff --git a/core/src/config.hpp b/core/src/config.hpp index cf6ba97..85b8b73 100644 --- a/core/src/config.hpp +++ b/core/src/config.hpp @@ -14,6 +14,7 @@ enum class RunMode { server, class Config : private Uncopyable { private: struct General { + std::string token; std::string fakeUrl; std::string method; unsigned int timeWait; @@ -40,7 +41,6 @@ class Config : private Uncopyable { unsigned short listenPort; std::string serverIp; unsigned short serverPort; - std::string token; std::string httpVersion; std::string userAgent; }; diff --git a/core/src/general.hpp b/core/src/general.hpp index ab6b820..355387b 100644 --- a/core/src/general.hpp +++ b/core/src/general.hpp @@ -310,6 +310,7 @@ inline BoolStr validateConfig(int argc, const char *argv[]) { } try { + configYaml["general"]["token"].as(); configYaml["general"]["fakeUrl"].as(); configYaml["general"]["method"].as(); configYaml["general"]["timeWait"].as(); @@ -343,7 +344,6 @@ inline BoolStr validateConfig(int argc, const char *argv[]) { configYaml["agent"]["listenPort"].as(); configYaml["agent"]["serverIp"].as(); configYaml["agent"]["serverPort"].as(); - configYaml["agent"]["token"].as(); configYaml["agent"]["httpVersion"].as(); configYaml["agent"]["userAgent"].as(); } catch (const std::exception &e) { diff --git a/core/src/serverhandler.cpp b/core/src/serverhandler.cpp index c31474c..082809b 100644 --- a/core/src/serverhandler.cpp +++ b/core/src/serverhandler.cpp @@ -30,7 +30,7 @@ void ServerHandler::handle() { BoolStr decryption{false, std::string("FAILED")}; decryption = aes256Decrypt(decode64(boost::lexical_cast( request_->parsedHttpRequest().body())), - config_->agent().token); + config_->general().token); if (decryption.ok) { log_->write( @@ -97,7 +97,7 @@ void ServerHandler::handle() { BoolStr encryption{false, std::string("FAILED")}; encryption = aes256Encrypt(streambufToString(client_->readBuffer()), - config_->agent().token); + config_->general().token); if (encryption.ok) { if (end_) { request_->chunkHeader_ = "yes"; @@ -169,7 +169,7 @@ void ServerHandler::continueRead() { BoolStr encryption{false, std::string("FAILED")}; encryption = aes256Encrypt(streambufToString(client_->readBuffer()), - config_->agent().token); + config_->general().token); if (encryption.ok) { if (end_) { request_->chunkHeader_ = "yes"; diff --git a/nipovpn/etc/nipovpn/config.yaml b/nipovpn/etc/nipovpn/config.yaml index 38c5c0e..20c9f61 100644 --- a/nipovpn/etc/nipovpn/config.yaml +++ b/nipovpn/etc/nipovpn/config.yaml @@ -1,6 +1,10 @@ --- # This block contains general and global configuration which is in both modes general: + # token: 32 bytes of string. this will be used on agent and server side to encryption + token: "af445adb-2434-4975-9445-2c1b2231" + # fakeUrl: string + # Defines the fake url and endpoint between agent and server fakeUrl: "http://www.adas.com/api01" # method: "HEAD|GET|POST|PUT|DELETE" # Defines with which method @@ -54,8 +58,6 @@ agent: serverIp: "127.0.0.1" # serverPort: port number of the nipoServer serverPort: 443 - # token: 32 bytes of string. this will be used on agent and server side to encryption - token: "af445adb-2434-4975-9445-2c1b2231" # httpVersion: This version will be used between agent and server httpVersion: "1.1" # userAgent: This is the http user agent which will be used between agent and server