Skip to content

Commit

Permalink
Move token to general in config
Browse files Browse the repository at this point in the history
  • Loading branch information
MortezaBashsiz committed Oct 14, 2024
1 parent e75bc11 commit e99f258
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions core/src/agenthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -84,7 +84,7 @@ void AgentHandler::handle() {
decryption =
aes256Decrypt(decode64(boost::lexical_cast<std::string>(
response->parsedHttpResponse().body())),
config_->agent().token);
config_->general().token);
if (boost::lexical_cast<std::string>(response->parsedHttpResponse()[config_->general().chunkHeader]) == "yes") {
end_ = true;
}
Expand Down Expand Up @@ -159,7 +159,7 @@ void AgentHandler::continueRead() {
decryption =
aes256Decrypt(decode64(boost::lexical_cast<std::string>(
response->parsedHttpResponse().body())),
config_->agent().token);
config_->general().token);
if (boost::lexical_cast<std::string>(response->parsedHttpResponse()[config_->general().chunkHeader]) == "yes") {
end_ = true;
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>(),
general_({configYaml_["general"]["token"].as<std::string>(),
configYaml_["general"]["fakeUrl"].as<std::string>(),
configYaml_["general"]["method"].as<std::string>(),
configYaml_["general"]["timeWait"].as<unsigned int>(),
configYaml_["general"]["timeout"].as<unsigned short>(),
Expand All @@ -24,7 +25,6 @@ Config::Config(const RunMode &mode, const std::string &filePath)
configYaml_["agent"]["listenPort"].as<unsigned short>(),
configYaml_["agent"]["serverIp"].as<std::string>(),
configYaml_["agent"]["serverPort"].as<unsigned short>(),
configYaml_["agent"]["token"].as<std::string>(),
configYaml_["agent"]["httpVersion"].as<std::string>(),
configYaml_["agent"]["userAgent"].as<std::string>()}) {
std::lock_guard<std::mutex> lock(configMutex_);
Expand Down Expand Up @@ -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"
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion core/src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion core/src/general.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ inline BoolStr validateConfig(int argc, const char *argv[]) {
}

try {
configYaml["general"]["token"].as<std::string>();
configYaml["general"]["fakeUrl"].as<std::string>();
configYaml["general"]["method"].as<std::string>();
configYaml["general"]["timeWait"].as<unsigned int>();
Expand Down Expand Up @@ -343,7 +344,6 @@ inline BoolStr validateConfig(int argc, const char *argv[]) {
configYaml["agent"]["listenPort"].as<unsigned short>();
configYaml["agent"]["serverIp"].as<std::string>();
configYaml["agent"]["serverPort"].as<unsigned short>();
configYaml["agent"]["token"].as<std::string>();
configYaml["agent"]["httpVersion"].as<std::string>();
configYaml["agent"]["userAgent"].as<std::string>();
} catch (const std::exception &e) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/serverhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void ServerHandler::handle() {
BoolStr decryption{false, std::string("FAILED")};
decryption = aes256Decrypt(decode64(boost::lexical_cast<std::string>(
request_->parsedHttpRequest().body())),
config_->agent().token);
config_->general().token);

if (decryption.ok) {
log_->write(
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
6 changes: 4 additions & 2 deletions nipovpn/etc/nipovpn/config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e99f258

Please sign in to comment.