Compare commits

...
8 Commits
Author SHA1 Message Date
Morteza Bashsiz 92a290cca7 Merge pull request #169 from MortezaBashsiz/dev
Fix #167
2026-05-29 09:20:47 +02:00
Morteza Bashsiz 108b9729c7 Merge pull request #168 from MortezaBashsiz/mori
Fix #167
2026-05-29 09:17:28 +02:00
Morteza Bashsiz 7baaf6aefb Fix #167 package versioning 2026-05-29 08:40:03 +02:00
Morteza Bashsiz 4793a3f0e3 update workflows action 2026-05-29 01:27:44 +02:00
Morteza Bashsiz c8cd4066d7 Merge pull request #166 from MortezaBashsiz/dev
Fix segmentation fault
Improve performance
Move tls config to general
2026-05-28 18:25:46 +02:00
Morteza Bashsiz 33a4dbd0b8 Merge pull request #165 from MortezaBashsiz/mori
fix segmentation fault issue
2026-05-28 18:21:32 +02:00
Morteza Bashsiz 01d8b36ca0 fix segmentation fault issue 2026-05-28 10:07:23 +02:00
Morteza Bashsiz cd7b985da1 move all tls configs to general 2026-05-28 09:09:09 +02:00
12 changed files with 353 additions and 212 deletions

No files matched your search

+51 -31
View File
@@ -3,10 +3,11 @@ name: Build and Release Debian Package
on:
push:
branches:
- dev
- main
paths:
- 'core/src/**'
- '.github/workflows/**'
- '.github/workflows/debian-dev.yml'
- 'nipovpn/**'
jobs:
build:
@@ -14,39 +15,70 @@ jobs:
steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set package version
run: echo "PACKAGE_VERSION=0.1.${{ github.run_number }}" >> "$GITHUB_ENV"
- name: Set up dependencies
run: |
sudo apt-get update
sudo apt-get install -y dpkg-dev build-essential lintian fakeroot devscripts cmake libssl-dev libboost-all-dev libyaml-cpp-dev
sudo apt-get install -y \
dpkg-dev \
build-essential \
lintian \
fakeroot \
devscripts \
cmake \
libssl-dev \
libboost-all-dev \
libyaml-cpp-dev
- name: Build the package
run: |
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)
cd ..
mkdir -p nipovpn/usr/bin/
cp build/core/nipovpn nipovpn/usr/bin/nipovpn
dpkg-deb --build nipovpn/ build/nipovpn_staging_v1-1-${{ github.run_number }}.deb
- name: Upload the Debian nipovpn as an artifact
rm -rf package
mkdir -p package/DEBIAN
mkdir -p package/usr/bin
cp build/core/nipovpn package/usr/bin/nipovpn
chmod 755 package/usr/bin/nipovpn
cat > package/DEBIAN/control <<EOF
Package: nipovpn
Version: ${PACKAGE_VERSION}
Maintainer: Morteza Bashsiz
Architecture: amd64
Description: Powerful and Secure HTTP/S Proxy
Depends: libyaml-cpp0.8
Homepage: https://github.com/MortezaBashsiz/nipovpn
EOF
dpkg-deb --build package "build/nipovpn_dev_${PACKAGE_VERSION}_amd64.deb"
- name: Show package information
run: |
dpkg -I "build/nipovpn_dev_${PACKAGE_VERSION}_amd64.deb"
- name: Upload Debian package as artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn
path: build/nipovpn_staging_v1-1-${{ github.run_number }}.deb
- name: Show nipovpn information
run: |
dpkg -I build/nipovpn_staging_v1-1-${{ github.run_number }}.deb
path: build/nipovpn_dev_${{ env.PACKAGE_VERSION }}_amd64.deb
release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Set package version
run: echo "PACKAGE_VERSION=0.1.${{ github.run_number }}" >> "$GITHUB_ENV"
- name: Download build artifact
uses: actions/download-artifact@v4
with:
@@ -54,22 +86,10 @@ jobs:
path: ./
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
uses: softprops/action-gh-release@v2
with:
tag_name: 'v.0.1.1.${{ github.run_number }}'
release_name: Staging v.0.1.1.${{ github.run_number }}
draft: false
prerelease: true
- name: Upload Debian Package to Release
uses: actions/upload-release-asset@v1
tag_name: v${{ env.PACKAGE_VERSION }}
name: Version v${{ env.PACKAGE_VERSION }}
files: nipovpn_dev_${{ env.PACKAGE_VERSION }}_amd64.deb
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./nipovpn_staging_v1-1-${{ github.run_number }}.deb
asset_name: nipovpn_staging_v1-1-${{ github.run_number }}.deb
asset_content_type: application/octet-stream
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
+51 -31
View File
@@ -3,10 +3,11 @@ name: Build and Release Debian Package
on:
push:
branches:
- mori
- main
paths:
- 'core/src/**'
- '.github/workflows/**'
- '.github/workflows/debian-mori.yml'
- 'nipovpn/**'
jobs:
build:
@@ -14,39 +15,70 @@ jobs:
steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set package version
run: echo "PACKAGE_VERSION=0.0.1.${{ github.run_number }}" >> "$GITHUB_ENV"
- name: Set up dependencies
run: |
sudo apt-get update
sudo apt-get install -y dpkg-dev build-essential lintian fakeroot devscripts cmake libssl-dev libboost-all-dev libyaml-cpp-dev
sudo apt-get install -y \
dpkg-dev \
build-essential \
lintian \
fakeroot \
devscripts \
cmake \
libssl-dev \
libboost-all-dev \
libyaml-cpp-dev
- name: Build the package
run: |
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)
cd ..
mkdir -p nipovpn/usr/bin/
cp build/core/nipovpn nipovpn/usr/bin/nipovpn
dpkg-deb --build nipovpn/ build/nipovpn_mori_v1-1-${{ github.run_number }}.deb
- name: Upload the Debian nipovpn as an artifact
rm -rf package
mkdir -p package/DEBIAN
mkdir -p package/usr/bin
cp build/core/nipovpn package/usr/bin/nipovpn
chmod 755 package/usr/bin/nipovpn
cat > package/DEBIAN/control <<EOF
Package: nipovpn
Version: ${PACKAGE_VERSION}
Maintainer: Morteza Bashsiz
Architecture: amd64
Description: Powerful and Secure HTTP/S Proxy
Depends: libyaml-cpp0.8
Homepage: https://github.com/MortezaBashsiz/nipovpn
EOF
dpkg-deb --build package "build/nipovpn_mori_${PACKAGE_VERSION}_amd64.deb"
- name: Show package information
run: |
dpkg -I "build/nipovpn_mori_${PACKAGE_VERSION}_amd64.deb"
- name: Upload Debian package as artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn
path: build/nipovpn_mori_v1-1-${{ github.run_number }}.deb
- name: Show nipovpn information
run: |
dpkg -I build/nipovpn_mori_v1-1-${{ github.run_number }}.deb
path: build/nipovpn_mori_${{ env.PACKAGE_VERSION }}_amd64.deb
release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Set package version
run: echo "PACKAGE_VERSION=0.0.1.${{ github.run_number }}" >> "$GITHUB_ENV"
- name: Download build artifact
uses: actions/download-artifact@v4
with:
@@ -54,22 +86,10 @@ jobs:
path: ./
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
uses: softprops/action-gh-release@v2
with:
tag_name: 'v.11.1.1.${{ github.run_number }}'
release_name: Mori v.11.1.1.${{ github.run_number }}
draft: false
prerelease: true
- name: Upload Debian Package to Release
uses: actions/upload-release-asset@v1
tag_name: v${{ env.PACKAGE_VERSION }}
name: Version v${{ env.PACKAGE_VERSION }}
files: nipovpn_mori_${{ env.PACKAGE_VERSION }}_amd64.deb
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./nipovpn_mori_v1-1-${{ github.run_number }}.deb
asset_name: nipovpn_mori_v1-1-${{ github.run_number }}.deb
asset_content_type: application/octet-stream
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
+50 -30
View File
@@ -6,6 +6,8 @@ on:
- main
paths:
- 'core/src/**'
- '.github/workflows/debian.yml'
- 'nipovpn/**'
jobs:
build:
@@ -13,39 +15,70 @@ jobs:
steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set package version
run: echo "PACKAGE_VERSION=1.1.${{ github.run_number }}" >> "$GITHUB_ENV"
- name: Set up dependencies
run: |
sudo apt-get update
sudo apt-get install -y dpkg-dev build-essential lintian fakeroot devscripts cmake libssl-dev libboost-all-dev libyaml-cpp-dev
sudo apt-get install -y \
dpkg-dev \
build-essential \
lintian \
fakeroot \
devscripts \
cmake \
libssl-dev \
libboost-all-dev \
libyaml-cpp-dev
- name: Build the package
run: |
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)
cd ..
mkdir -p nipovpn/usr/bin/
cp build/core/nipovpn nipovpn/usr/bin/nipovpn
dpkg-deb --build nipovpn/ build/nipovpn_v1-1-${{ github.run_number }}.deb
- name: Upload the Debian nipovpn as an artifact
rm -rf package
mkdir -p package/DEBIAN
mkdir -p package/usr/bin
cp build/core/nipovpn package/usr/bin/nipovpn
chmod 755 package/usr/bin/nipovpn
cat > package/DEBIAN/control <<EOF
Package: nipovpn
Version: ${PACKAGE_VERSION}
Maintainer: Morteza Bashsiz
Architecture: amd64
Description: Powerful and Secure HTTP/S Proxy
Depends: libyaml-cpp0.8
Homepage: https://github.com/MortezaBashsiz/nipovpn
EOF
dpkg-deb --build package "build/nipovpn_${PACKAGE_VERSION}_amd64.deb"
- name: Show package information
run: |
dpkg -I "build/nipovpn_${PACKAGE_VERSION}_amd64.deb"
- name: Upload Debian package as artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn
path: build/nipovpn_v1-1-${{ github.run_number }}.deb
- name: Show nipovpn information
run: |
dpkg -I build/nipovpn_v1-1-${{ github.run_number }}.deb
path: build/nipovpn_${{ env.PACKAGE_VERSION }}_amd64.deb
release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Set package version
run: echo "PACKAGE_VERSION=1.1.${{ github.run_number }}" >> "$GITHUB_ENV"
- name: Download build artifact
uses: actions/download-artifact@v4
with:
@@ -53,23 +86,10 @@ jobs:
path: ./
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
uses: softprops/action-gh-release@v2
with:
tag_name: 'v1.1.${{ github.run_number }}'
release_name: Version v1.1.${{ github.run_number }}
draft: false
prerelease: false
- name: Upload Debian Package to Release
uses: actions/upload-release-asset@v1
tag_name: v${{ env.PACKAGE_VERSION }}
name: Version v${{ env.PACKAGE_VERSION }}
files: nipovpn_${{ env.PACKAGE_VERSION }}_amd64.deb
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./nipovpn_v1-1-${{ github.run_number }}.deb
asset_name: nipovpn_v1-1-${{ github.run_number }}.deb
asset_content_type: application/octet-stream
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
+1 -1
View File
@@ -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 + ":" +
+14 -20
View File
@@ -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,6 @@ 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"
@@ -123,10 +120,7 @@ std::string Config::toString() const {
<< " 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";
<< " userAgent: " << agent_.userAgent << "\n";
return ss.str();
}
+5 -10
View File
@@ -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_;
+71 -36
View File
@@ -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);
@@ -121,14 +121,16 @@ bool TCPClient::doConnect(const std::string &dstIP, const unsigned short &dstPor
}
if (tlsEnabled_) {
if (!sslSocket_) {
if (!sslSocket_ || closed_ || !sslSocket_->lowest_layer().is_open()) {
sslSocket_ = std::make_unique<ssl_stream>(io_context_, sslContext_);
closed_ = false;
}
boost::asio::connect(sslSocket_->lowest_layer(), endpoint, error_code);
} else {
if (!socket_.is_open()) {
socket_ = tcp::socket(io_context_);
closed_ = false;
}
boost::asio::connect(socket_, endpoint, error_code);
@@ -296,50 +298,70 @@ void TCPClient::doWrite(boost::asio::streambuf &buffer) {
void TCPClient::doReadAgent() {
boost::system::error_code error;
readBuffer_.consume(readBuffer_.size());
try {
if (!isOpen()) {
log_->write("[" + to_string(uuid_) +
"] [TCPClient doReadAgent] Socket is not OPEN",
Log::Level::DEBUG);
return;
{
std::lock_guard<std::mutex> lock(mutex_);
readBuffer_.consume(readBuffer_.size());
if (!isOpen()) {
log_->write("[" + to_string(uuid_) +
"] [TCPClient doReadAgent] Socket is not OPEN",
Log::Level::DEBUG);
return;
}
}
resetTimeout();
bool ok = false;
if (tlsEnabled_ && sslSocket_) {
if (tlsEnabled_) {
if (!sslSocket_) {
cancelTimeout();
log_->write("[" + to_string(uuid_) +
"] [TCPClient doReadAgent] SSL socket is null",
Log::Level::DEBUG);
socketShutdown();
return;
}
ok = HttpUtils::readHttpMessage(*sslSocket_, readBuffer_, error);
} else {
ok = HttpUtils::readHttpMessage(socket_, readBuffer_, error);
}
cancelTimeout();
if (!ok) {
if (error == boost::asio::error::eof) {
if (error == boost::asio::error::operation_aborted) {
log_->write("[" + to_string(uuid_) +
"] [TCPClient doReadAgent] [aborted]",
Log::Level::DEBUG);
} else if (error == boost::asio::error::eof) {
log_->write("[" + to_string(uuid_) +
"] [TCPClient doReadAgent] [EOF] Connection closed by peer.",
Log::Level::TRACE);
} else {
log_->write("[" + to_string(uuid_) +
"] [TCPClient doReadAgent] [error] " + error.message(),
"] [TCPClient doReadAgent] [error] " +
error.message(),
Log::Level::ERROR);
}
socketShutdown();
return;
}
if (readBuffer_.size() > 0) {
copyStreambuf(readBuffer_, buffer_);
} else {
socketShutdown();
return;
}
} catch (std::exception &error) {
log_->write("[" + to_string(uuid_) +
"] [TCPClient doReadAgent] [catch read] " + error.what(),
"] [TCPClient doReadAgent] empty read buffer",
Log::Level::DEBUG);
socketShutdown();
} catch (const std::exception &ex) {
cancelTimeout();
log_->write("[" + to_string(uuid_) +
"] [TCPClient doReadAgent] [catch read] " +
ex.what(),
Log::Level::DEBUG);
socketShutdown();
}
@@ -442,33 +464,46 @@ void TCPClient::onTimeout(const boost::system::error_code &error) {
}
void TCPClient::socketShutdown() {
boost::system::error_code ec;
std::lock_guard<std::mutex> lock(mutex_);
boost::system::error_code ignored;
if (closed_) return;
closed_ = true;
cancelTimeout();
if (sslSocket_) {
log_->write("[TCPClient socketShutdown] [SSL]", Log::Level::DEBUG);
log_->write("[" + to_string(uuid_) + "] [TCPClient socketShutdown] [SSL]",
Log::Level::DEBUG);
auto &lowest = sslSocket_->lowest_layer();
if (lowest.is_open()) {
lowest.cancel(ignored);
sslSocket_->shutdown(ignored);
lowest.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored);
lowest.close(ignored);
}
lowest.cancel(ec);
ec.clear();
sslSocket_.reset();
tlsEnabled_ = false;
if (lowest.is_open()) {
lowest.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
ec.clear();
lowest.close(ec);
}
}
if (socket_.is_open()) {
log_->write("[TCPClient socketShutdown] [TCP]", Log::Level::DEBUG);
socket_.cancel(ignored);
socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored);
socket_.close(ignored);
log_->write("[" + to_string(uuid_) + "] [TCPClient socketShutdown] [TCP]",
Log::Level::DEBUG);
socket_.cancel(ec);
ec.clear();
socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
ec.clear();
socket_.close(ec);
}
tlsEnabled_ = false;
}
std::string TCPClient::HttpUtils::toLowerCopy(std::string s) {
+1
View File
@@ -103,4 +103,5 @@ private:
tcp::resolver resolver_;
boost::asio::steady_timer timeout_;
mutable std::mutex mutex_;
bool closed_ = false;
};
+90 -39
View File
@@ -36,16 +36,18 @@ bool TCPConnection::initTlsServerContext() {
try {
sslContext_ = boost::asio::ssl::context(boost::asio::ssl::context::tls_server);
sslContext_.set_options(boost::asio::ssl::context::default_workarounds |
boost::asio::ssl::context::no_sslv2 |
boost::asio::ssl::context::no_sslv3 |
boost::asio::ssl::context::single_dh_use);
sslContext_.set_options(
boost::asio::ssl::context::default_workarounds |
boost::asio::ssl::context::no_sslv2 |
boost::asio::ssl::context::no_sslv3 |
boost::asio::ssl::context::single_dh_use);
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,
boost::asio::ssl::context::pem);
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())) {
log_->write("[" + to_string(uuid_) +
@@ -56,12 +58,13 @@ bool TCPConnection::initTlsServerContext() {
sslContext_.set_verify_mode(boost::asio::ssl::verify_none);
if (SSL_CTX_set_cipher_list(sslContext_.native_handle(),
"ECDHE-RSA-AES256-GCM-SHA384:"
"ECDHE-RSA-AES128-GCM-SHA256:"
"ECDHE-RSA-CHACHA20-POLY1305:"
"AES256-GCM-SHA384:"
"AES128-GCM-SHA256") != 1) {
if (SSL_CTX_set_cipher_list(
sslContext_.native_handle(),
"ECDHE-RSA-AES256-GCM-SHA384:"
"ECDHE-RSA-AES128-GCM-SHA256:"
"ECDHE-RSA-CHACHA20-POLY1305:"
"AES256-GCM-SHA384:"
"AES128-GCM-SHA256") != 1) {
log_->write("[" + to_string(uuid_) +
"] [TCPConnection initTlsServerContext] failed to set cipher list",
Log::Level::ERROR);
@@ -69,16 +72,21 @@ bool TCPConnection::initTlsServerContext() {
}
#if defined(TLS1_3_VERSION)
SSL_CTX_set_ciphersuites(sslContext_.native_handle(),
"TLS_AES_256_GCM_SHA384:"
"TLS_AES_128_GCM_SHA256:"
"TLS_CHACHA20_POLY1305_SHA256");
SSL_CTX_set_ciphersuites(
sslContext_.native_handle(),
"TLS_AES_256_GCM_SHA384:"
"TLS_AES_128_GCM_SHA256:"
"TLS_CHACHA20_POLY1305_SHA256");
#endif
tlsSocket_ = std::make_unique<ssl_stream>(io_context_, sslContext_);
closed_ = false;
return true;
} catch (std::exception &error) {
log_->write("[" + to_string(uuid_) + "] [TCPConnection initTlsServerContext] " + error.what(),
log_->write("[" + to_string(uuid_) +
"] [TCPConnection initTlsServerContext] " +
error.what(),
Log::Level::ERROR);
return false;
}
@@ -145,7 +153,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 +291,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 +367,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 +409,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 "";
}
@@ -548,22 +556,35 @@ void TCPConnection::closeTunnelSession() {
void TCPConnection::resetTimeout() {
if (!config_->general().timeout) return;
if (closed_) return;
timeout_.cancel();
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() {
if (config_->general().timeout) timeout_.cancel();
if (!config_->general().timeout) return;
boost::system::error_code ignored;
timeout_.cancel();
}
void TCPConnection::onTimeout(const boost::system::error_code &error) {
if (error || error == boost::asio::error::operation_aborted) return;
if (error == boost::asio::error::operation_aborted) return;
if (error) return;
if (connect_) return;
if (closed_) return;
log_->write("[" + to_string(uuid_) + "] [TCPConnection onTimeout] [expiration] " +
log_->write("[" + to_string(uuid_) +
"] [TCPConnection onTimeout] [expiration] " +
std::to_string(+config_->general().timeout) +
" seconds has passed, and the timeout has expired",
Log::Level::TRACE);
@@ -572,34 +593,64 @@ void TCPConnection::onTimeout(const boost::system::error_code &error) {
}
void TCPConnection::socketShutdown() {
try {
boost::system::error_code ignored;
if (closed_.exchange(true)) {
return;
}
boost::system::error_code ignored;
try {
pollTimer_.cancel();
ignored.clear();
timeout_.cancel();
ignored.clear();
if (tlsSocket_) {
log_->write("[TCPConnection socketShutdown] [SSL]", Log::Level::DEBUG);
tlsSocket_->shutdown(ignored);
tlsSocket_->lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored);
tlsSocket_->lowest_layer().close(ignored);
log_->write("[" + to_string(uuid_) +
"] [TCPConnection socketShutdown] [SSL]",
Log::Level::DEBUG);
auto &lowest = tlsSocket_->lowest_layer();
lowest.cancel(ignored);
ignored.clear();
if (lowest.is_open()) {
lowest.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored);
ignored.clear();
lowest.close(ignored);
ignored.clear();
}
}
if (socket_.is_open()) {
log_->write("[TCPConnection socketShutdown] [TCP]", Log::Level::DEBUG);
log_->write("[" + to_string(uuid_) +
"] [TCPConnection socketShutdown] [TCP]",
Log::Level::DEBUG);
socket_.cancel(ignored);
ignored.clear();
socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored);
ignored.clear();
socket_.close(ignored);
ignored.clear();
}
if (client_) {
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);
}
}
void TCPConnection::enableDirectTunnelMode() {
tunnelMode_ = true;
}
@@ -608,7 +659,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 +684,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));
+2
View File
@@ -1,6 +1,7 @@
#pragma once
#include <array>
#include <atomic>
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/bind/bind.hpp>
@@ -144,6 +145,7 @@ private:
bool tunnelMode_;
bool tunnelClosed_;
bool pollInProgress_;
std::atomic_bool closed_{false};
std::array<char, 8192> downstreamBuf_;
std::array<char, 8192> upstreamBuf_;
+1 -1
View File
@@ -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);
+16 -13
View File
@@ -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,6 +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
@@ -55,11 +65,7 @@ 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:
@@ -70,13 +76,10 @@ agent:
# listenPort: the port number which will be used on agent
listenPort: 8080
# serverIp: IPv4 of the nipoServer
serverIp: "127.0.0.10"
serverIp: "127.0.0.1"
# serverPort: port number of the nipoServer
serverPort: 80
# 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"