Compare commits
1
Commits
dev
...
v.11.1.1.13
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7f0291055 |
No files matched your search
@@ -40,7 +40,7 @@ void AgentHandler::handle() {
|
||||
Log::Level::INFO);
|
||||
}
|
||||
|
||||
if (config_->agent().tlsEnable && !client_->tlsEnabled()) {
|
||||
if (config_->general().tlsEnable && !client_->tlsEnabled()) {
|
||||
if (!client_->enableTlsClient()) {
|
||||
log_->write("[" + to_string(uuid_) + "] [TLS] [ERROR] [Init Client Context] [SRC " +
|
||||
clientConnStr_ + "] [DST " + config_->agent().serverIp + ":" +
|
||||
|
||||
+15
-21
@@ -14,27 +14,24 @@ Config::Config(const RunMode &mode, const std::string &filePath)
|
||||
configYaml_["general"]["endPoints"].as<std::vector<std::string>>(),
|
||||
configYaml_["general"]["timeout"].as<unsigned short>(),
|
||||
configYaml_["general"]["tunnelEnable"].as<bool>(false),
|
||||
configYaml_["general"]["connectionReuse"].as<bool>(false)}),
|
||||
configYaml_["general"]["connectionReuse"].as<bool>(false),
|
||||
configYaml_["general"]["tlsEnable"].as<bool>(false),
|
||||
configYaml_["general"]["tlsVerifyPeer"].as<bool>(false),
|
||||
configYaml_["general"]["tlsCertFile"].as<std::string>(""),
|
||||
configYaml_["general"]["tlsKeyFile"].as<std::string>(""),
|
||||
configYaml_["general"]["tlsCaFile"].as<std::string>("")}),
|
||||
log_({configYaml_["log"]["logLevel"].as<std::string>(),
|
||||
configYaml_["log"]["logFile"].as<std::string>()}),
|
||||
server_({configYaml_["server"]["threads"].as<unsigned short>(),
|
||||
configYaml_["server"]["listenIp"].as<std::string>(),
|
||||
configYaml_["server"]["listenPort"].as<unsigned short>(),
|
||||
configYaml_["server"]["tlsEnable"].as<bool>(false),
|
||||
configYaml_["server"]["tlsVerifyPeer"].as<bool>(false),
|
||||
configYaml_["server"]["tlsCertFile"].as<std::string>(""),
|
||||
configYaml_["server"]["tlsKeyFile"].as<std::string>(""),
|
||||
configYaml_["server"]["tlsCaFile"].as<std::string>("")}),
|
||||
configYaml_["server"]["listenPort"].as<unsigned short>()}),
|
||||
agent_({configYaml_["agent"]["threads"].as<unsigned short>(),
|
||||
configYaml_["agent"]["listenIp"].as<std::string>(),
|
||||
configYaml_["agent"]["listenPort"].as<unsigned short>(),
|
||||
configYaml_["agent"]["serverIp"].as<std::string>(),
|
||||
configYaml_["agent"]["serverPort"].as<unsigned short>(),
|
||||
configYaml_["agent"]["httpVersion"].as<std::string>(),
|
||||
configYaml_["agent"]["userAgent"].as<std::string>(),
|
||||
configYaml_["agent"]["tlsEnable"].as<bool>(false),
|
||||
configYaml_["agent"]["tlsVerifyPeer"].as<bool>(false),
|
||||
configYaml_["agent"]["tlsCaFile"].as<std::string>("")}) {
|
||||
configYaml_["agent"]["userAgent"].as<std::string>()}) {
|
||||
|
||||
std::lock_guard<std::mutex> lock(configMutex_);
|
||||
|
||||
@@ -101,6 +98,11 @@ std::string Config::toString() const {
|
||||
<< " timeout: " << general_.timeout << "\n"
|
||||
<< " tunnelEnable: " << std::boolalpha << general_.tunnelEnable << "\n"
|
||||
<< " connectionReuse: " << std::boolalpha << general_.connectionReuse << "\n"
|
||||
<< " tlsEnable: " << std::boolalpha << general_.tlsEnable << "\n"
|
||||
<< " tlsVerifyPeer: " << std::boolalpha << general_.tlsVerifyPeer << "\n"
|
||||
<< " tlsCertFile: " << general_.tlsCertFile << "\n"
|
||||
<< " tlsKeyFile: " << general_.tlsKeyFile << "\n"
|
||||
<< " tlsCaFile: " << general_.tlsCaFile << "\n"
|
||||
|
||||
<< " Log :\n"
|
||||
<< " logLevel: " << log_.level << "\n"
|
||||
@@ -110,11 +112,7 @@ std::string Config::toString() const {
|
||||
<< " threads: " << server_.threads << "\n"
|
||||
<< " listenIp: " << server_.listenIp << "\n"
|
||||
<< " listenPort: " << server_.listenPort << "\n"
|
||||
<< " tlsEnable: " << std::boolalpha << server_.tlsEnable << "\n"
|
||||
<< " tlsVerifyPeer: " << std::boolalpha << server_.tlsVerifyPeer << "\n"
|
||||
<< " tlsCertFile: " << server_.tlsCertFile << "\n"
|
||||
<< " tlsKeyFile: " << server_.tlsKeyFile << "\n"
|
||||
<< " tlsCaFile: " << server_.tlsCaFile << "\n"
|
||||
|
||||
|
||||
<< " Agent :\n"
|
||||
<< " threads: " << agent_.threads << "\n"
|
||||
@@ -122,11 +120,7 @@ std::string Config::toString() const {
|
||||
<< " listenPort: " << agent_.listenPort << "\n"
|
||||
<< " serverIp: " << agent_.serverIp << "\n"
|
||||
<< " serverPort: " << agent_.serverPort << "\n"
|
||||
<< " httpVersion: " << agent_.httpVersion << "\n"
|
||||
<< " userAgent: " << agent_.userAgent << "\n"
|
||||
<< " tlsEnable: " << std::boolalpha << agent_.tlsEnable << "\n"
|
||||
<< " tlsVerifyPeer: " << std::boolalpha << agent_.tlsVerifyPeer << "\n"
|
||||
<< " tlsCaFile: " << agent_.tlsCaFile << "\n";
|
||||
<< " httpVersion: " << agent_.httpVersion << "\n";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
+5
-10
@@ -26,6 +26,11 @@ private:
|
||||
unsigned short timeout;
|
||||
bool tunnelEnable;
|
||||
bool connectionReuse;
|
||||
bool tlsEnable;
|
||||
bool tlsVerifyPeer;
|
||||
std::string tlsCertFile;
|
||||
std::string tlsKeyFile;
|
||||
std::string tlsCaFile;
|
||||
};
|
||||
|
||||
struct Log {
|
||||
@@ -37,12 +42,6 @@ private:
|
||||
unsigned short threads;
|
||||
std::string listenIp;
|
||||
unsigned short listenPort;
|
||||
|
||||
bool tlsEnable;
|
||||
bool tlsVerifyPeer;
|
||||
std::string tlsCertFile;
|
||||
std::string tlsKeyFile;
|
||||
std::string tlsCaFile;
|
||||
};
|
||||
|
||||
struct Agent {
|
||||
@@ -53,10 +52,6 @@ private:
|
||||
unsigned short serverPort;
|
||||
std::string httpVersion;
|
||||
std::string userAgent;
|
||||
|
||||
bool tlsEnable;
|
||||
bool tlsVerifyPeer;
|
||||
std::string tlsCaFile;
|
||||
};
|
||||
|
||||
const RunMode &runMode_;
|
||||
|
||||
@@ -47,11 +47,11 @@ bool TCPClient::enableTlsClient() {
|
||||
|
||||
SSL_CTX_set_min_proto_version(sslContext_.native_handle(), TLS1_2_VERSION);
|
||||
|
||||
if (config_->agent().tlsVerifyPeer) {
|
||||
if (config_->general().tlsVerifyPeer) {
|
||||
sslContext_.set_verify_mode(boost::asio::ssl::verify_peer);
|
||||
|
||||
if (!config_->agent().tlsCaFile.empty()) {
|
||||
sslContext_.load_verify_file(config_->agent().tlsCaFile);
|
||||
if (!config_->general().tlsCaFile.empty()) {
|
||||
sslContext_.load_verify_file(config_->general().tlsCaFile);
|
||||
}
|
||||
} else {
|
||||
sslContext_.set_verify_mode(boost::asio::ssl::verify_none);
|
||||
|
||||
+31
-18
@@ -43,8 +43,8 @@ bool TCPConnection::initTlsServerContext() {
|
||||
|
||||
SSL_CTX_set_min_proto_version(sslContext_.native_handle(), TLS1_2_VERSION);
|
||||
|
||||
sslContext_.use_certificate_chain_file(config_->server().tlsCertFile);
|
||||
sslContext_.use_private_key_file(config_->server().tlsKeyFile,
|
||||
sslContext_.use_certificate_chain_file(config_->general().tlsCertFile);
|
||||
sslContext_.use_private_key_file(config_->general().tlsKeyFile,
|
||||
boost::asio::ssl::context::pem);
|
||||
|
||||
if (!SSL_CTX_check_private_key(sslContext_.native_handle())) {
|
||||
@@ -145,7 +145,7 @@ void TCPConnection::doReadServer() {
|
||||
boost::asio::placeholders::error,
|
||||
boost::asio::placeholders::bytes_transferred));
|
||||
|
||||
if (config_->server().tlsEnable) {
|
||||
if (config_->general().tlsEnable) {
|
||||
boost::asio::async_read_until(*tlsSocket_, readBuffer_, "\r\n\r\n", handler);
|
||||
} else {
|
||||
boost::asio::async_read_until(socket_, readBuffer_, "\r\n\r\n", handler);
|
||||
@@ -283,7 +283,7 @@ void TCPConnection::handleReadServer(const boost::system::error_code &error, siz
|
||||
boost::system::error_code bodyError;
|
||||
std::string remotePeer;
|
||||
|
||||
if (config_->server().tlsEnable) {
|
||||
if (config_->general().tlsEnable) {
|
||||
if (!HttpUtils::readRemainingHttpBody(*tlsSocket_, readBuffer_, bodyError)) {
|
||||
socketShutdown();
|
||||
return;
|
||||
@@ -359,7 +359,7 @@ void TCPConnection::handleReadServer(const boost::system::error_code &error, siz
|
||||
}
|
||||
};
|
||||
|
||||
if (config_->server().tlsEnable) {
|
||||
if (config_->general().tlsEnable) {
|
||||
boost::asio::async_write(
|
||||
*tlsSocket_,
|
||||
writeBuffer_.data(),
|
||||
@@ -401,7 +401,7 @@ std::string TCPConnection::postTunnelAction(const std::string &action,
|
||||
const bool alreadyOpen = client_->isOpen();
|
||||
|
||||
if (!alreadyOpen) {
|
||||
if (config_->agent().tlsEnable) {
|
||||
if (config_->general().tlsEnable) {
|
||||
if (!client_->enableTlsClient()) return "";
|
||||
}
|
||||
|
||||
@@ -547,12 +547,18 @@ void TCPConnection::closeTunnelSession() {
|
||||
}
|
||||
|
||||
void TCPConnection::resetTimeout() {
|
||||
if (!config_->general().timeout) return;
|
||||
if (!config_->general().timeout || closed_) return;
|
||||
|
||||
try {
|
||||
timeout_.cancel();
|
||||
} catch (...) {}
|
||||
|
||||
timeout_.expires_after(std::chrono::seconds(config_->general().timeout));
|
||||
timeout_.async_wait(boost::bind(&TCPConnection::onTimeout,
|
||||
shared_from_this(),
|
||||
boost::asio::placeholders::error));
|
||||
timeout_.async_wait(boost::asio::bind_executor(
|
||||
strand_,
|
||||
[self = shared_from_this()](const boost::system::error_code &error) {
|
||||
self->onTimeout(error);
|
||||
}));
|
||||
}
|
||||
|
||||
void TCPConnection::cancelTimeout() {
|
||||
@@ -560,8 +566,9 @@ void TCPConnection::cancelTimeout() {
|
||||
}
|
||||
|
||||
void TCPConnection::onTimeout(const boost::system::error_code &error) {
|
||||
if (error || error == boost::asio::error::operation_aborted) return;
|
||||
if (connect_) return;
|
||||
if (error == boost::asio::error::operation_aborted) return;
|
||||
if (error) return;
|
||||
if (closed_ || connect_) return;
|
||||
|
||||
log_->write("[" + to_string(uuid_) + "] [TCPConnection onTimeout] [expiration] " +
|
||||
std::to_string(+config_->general().timeout) +
|
||||
@@ -572,6 +579,10 @@ void TCPConnection::onTimeout(const boost::system::error_code &error) {
|
||||
}
|
||||
|
||||
void TCPConnection::socketShutdown() {
|
||||
if (closed_.exchange(true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
boost::system::error_code ignored;
|
||||
|
||||
@@ -579,14 +590,15 @@ void TCPConnection::socketShutdown() {
|
||||
timeout_.cancel();
|
||||
|
||||
if (tlsSocket_) {
|
||||
log_->write("[TCPConnection socketShutdown] [SSL]", Log::Level::DEBUG);
|
||||
tlsSocket_->lowest_layer().cancel();
|
||||
tlsSocket_->shutdown(ignored);
|
||||
tlsSocket_->lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored);
|
||||
tlsSocket_->lowest_layer().shutdown(
|
||||
boost::asio::ip::tcp::socket::shutdown_both, ignored);
|
||||
tlsSocket_->lowest_layer().close(ignored);
|
||||
}
|
||||
|
||||
if (socket_.is_open()) {
|
||||
log_->write("[TCPConnection socketShutdown] [TCP]", Log::Level::DEBUG);
|
||||
socket_.cancel();
|
||||
socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored);
|
||||
socket_.close(ignored);
|
||||
}
|
||||
@@ -595,7 +607,8 @@ void TCPConnection::socketShutdown() {
|
||||
client_->socketShutdown();
|
||||
}
|
||||
} catch (std::exception &error) {
|
||||
log_->write("[" + to_string(uuid_) + "] [TCPConnection socketShutdown] [catch] " + error.what(),
|
||||
log_->write("[" + to_string(uuid_) + "] [TCPConnection socketShutdown] [catch] " +
|
||||
error.what(),
|
||||
Log::Level::DEBUG);
|
||||
}
|
||||
}
|
||||
@@ -608,7 +621,7 @@ void TCPConnection::asyncWriteToAgentConnection(
|
||||
const char *data,
|
||||
std::size_t bytes,
|
||||
std::function<void(const boost::system::error_code &)> done) {
|
||||
if (config_->server().tlsEnable && tlsSocket_) {
|
||||
if (config_->general().tlsEnable && tlsSocket_) {
|
||||
boost::asio::async_write(
|
||||
*tlsSocket_,
|
||||
boost::asio::buffer(data, bytes),
|
||||
@@ -633,7 +646,7 @@ void TCPConnection::asyncWriteToAgentConnection(
|
||||
void TCPConnection::asyncReadFromAgentConnection(
|
||||
std::array<char, 8192> &buffer,
|
||||
std::function<void(const boost::system::error_code &, std::size_t)> done) {
|
||||
if (config_->server().tlsEnable && tlsSocket_) {
|
||||
if (config_->general().tlsEnable && tlsSocket_) {
|
||||
tlsSocket_->async_read_some(
|
||||
boost::asio::buffer(buffer),
|
||||
boost::asio::bind_executor(strand_, done));
|
||||
|
||||
@@ -147,4 +147,6 @@ private:
|
||||
|
||||
std::array<char, 8192> downstreamBuf_;
|
||||
std::array<char, 8192> upstreamBuf_;
|
||||
|
||||
std::atomic_bool closed_{false};
|
||||
};
|
||||
@@ -31,7 +31,7 @@ void TCPServer::handleAccept(TCPConnection::pointer connection,
|
||||
try {
|
||||
if (!error) {
|
||||
if (config_->runMode() == RunMode::server) {
|
||||
if (config_->server().tlsEnable) {
|
||||
if (config_->general().tlsEnable) {
|
||||
if (!connection->initTlsServerContext()) {
|
||||
log_->write("[TCPServer handleAccept] TLS server context init failed",
|
||||
Log::Level::ERROR);
|
||||
|
||||
@@ -5,8 +5,8 @@ general:
|
||||
token: "af445adb-2434-4975-9445-2c1b2231"
|
||||
# fakeUrl: string
|
||||
# Defines the fake url between agent and server
|
||||
fakeUrl: "nipo.ciron.net"
|
||||
# method:
|
||||
fakeUrl: "www.google.com"
|
||||
# methods:
|
||||
# Defines the list of using methods
|
||||
# you like to send requests from agent to server
|
||||
# Program will choose randomly from this list
|
||||
@@ -16,7 +16,7 @@ general:
|
||||
- POST
|
||||
- PUT
|
||||
- DELETE
|
||||
# endPoint:
|
||||
# endPoints:
|
||||
# Defines the list of using endpoints
|
||||
# you like to send requests from agent to server
|
||||
# Program will choose randomly from this list
|
||||
@@ -37,7 +37,16 @@ general:
|
||||
# If false then it will use same connection between agent and server to handle client request
|
||||
# If true then it will create new connection for each request between agent and server
|
||||
connectionReuse: false
|
||||
|
||||
# tlsEnable: bool
|
||||
# It enables or disables tls between agent and server
|
||||
tlsEnable: false
|
||||
# tlsVerifyPeer: bool
|
||||
# Use it to controll if the certificate should be validated or not
|
||||
tlsVerifyPeer: false
|
||||
# Use following configurations to specify the key and cert which will be used between agent and server
|
||||
tlsCertFile: "/etc/nipovpn/server.crt"
|
||||
tlsKeyFile: "/etc/nipovpn/server.key"
|
||||
tlsCaFile: ""
|
||||
|
||||
# This block is to define log directives
|
||||
log:
|
||||
@@ -55,11 +64,6 @@ server:
|
||||
listenIp: "0.0.0.0"
|
||||
# listenPort: the port number which will be used on server
|
||||
listenPort: 80
|
||||
tlsEnable: false
|
||||
tlsVerifyPeer: false
|
||||
tlsCertFile: "/etc/nipovpn/server.crt"
|
||||
tlsKeyFile: "/etc/nipovpn/server.key"
|
||||
tlsCaFile: ""
|
||||
|
||||
# This block is to define agent directives
|
||||
agent:
|
||||
@@ -76,7 +80,4 @@ agent:
|
||||
# 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
|
||||
userAgent : "NipoAgent"
|
||||
tlsEnable: false
|
||||
tlsVerifyPeer: false
|
||||
tlsCaFile: ""
|
||||
userAgent : "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0"
|
||||
Reference in new issue
Block a user