Compare commits

...
11 Commits
Author SHA1 Message Date
Morteza Bashsiz c0942c4015 Implement Random fakeUrl
* implement random fakeUrl
2026-05-31 23:06:14 +02:00
Morteza Bashsiz 228aff5d63 Dev fix #167 (#174)
* Fix #167 package versioning
2026-05-29 10:46:51 +02:00
Morteza Bashsiz 5647fd2f69 Fix #167 (#171)
* Fix #167 package versioning
2026-05-29 10:00:14 +02:00
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
14 changed files with 425 additions and 243 deletions

No files matched your search

+57 -36
View File
@@ -1,4 +1,4 @@
name: Build and Release Debian Package
name: Build and Release Debian Package - DEV
on:
push:
@@ -6,7 +6,16 @@ on:
- dev
paths:
- 'core/src/**'
- '.github/workflows/**'
- 'core/**'
- 'nipovpn/**'
- '.github/workflows/debian-dev.yml'
permissions:
contents: write
env:
PACKAGE_VERSION: 0.1.${{ github.run_number }}
PACKAGE_FILE: nipovpn_dev_0.1.${{ github.run_number }}_amd64.deb
jobs:
build:
@@ -14,62 +23,74 @@ jobs:
steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
- 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
- name: Build binary
run: |
rm -rf build
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
- name: Build Debian package
run: |
mkdir -p nipovpn/usr/bin
cp build/core/nipovpn nipovpn/usr/bin/nipovpn
chmod 755 nipovpn/usr/bin/nipovpn
sed -i -E "s/^Version[[:space:]]*:.*/Version: ${PACKAGE_VERSION}/" nipovpn/DEBIAN/control
echo "Final control file:"
cat nipovpn/DEBIAN/control
grep "^Version: ${PACKAGE_VERSION}$" nipovpn/DEBIAN/control
dpkg-deb --build nipovpn "build/${PACKAGE_FILE}"
- name: Show package information
run: |
dpkg -I "build/${PACKAGE_FILE}"
dpkg -c "build/${PACKAGE_FILE}"
- 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
name: nipovpn-dev-deb
path: build/${{ env.PACKAGE_FILE }}
release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download build artifact
- name: Download Debian package artifact
uses: actions/download-artifact@v4
with:
name: nipovpn
name: nipovpn-dev-deb
path: ./
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
- name: Create DEV GitHub Release
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
tag_name: dev-v${{ env.PACKAGE_VERSION }}
name: DEV Version v${{ env.PACKAGE_VERSION }}
prerelease: true
- name: Upload Debian Package to Release
uses: actions/upload-release-asset@v1
files: ${{ env.PACKAGE_FILE }}
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: ${{ github.token }}
+57 -36
View File
@@ -1,4 +1,4 @@
name: Build and Release Debian Package
name: Build and Release Debian Package - MORI
on:
push:
@@ -6,7 +6,16 @@ on:
- mori
paths:
- 'core/src/**'
- '.github/workflows/**'
- 'core/**'
- 'nipovpn/**'
- '.github/workflows/debian-mori.yml'
permissions:
contents: write
env:
PACKAGE_VERSION: 0.2.${{ github.run_number }}
PACKAGE_FILE: nipovpn_mori_0.2.${{ github.run_number }}_amd64.deb
jobs:
build:
@@ -14,62 +23,74 @@ jobs:
steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
- 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
- name: Build binary
run: |
rm -rf build
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
- name: Build Debian package
run: |
mkdir -p nipovpn/usr/bin
cp build/core/nipovpn nipovpn/usr/bin/nipovpn
chmod 755 nipovpn/usr/bin/nipovpn
sed -i -E "s/^Version[[:space:]]*:.*/Version: ${PACKAGE_VERSION}/" nipovpn/DEBIAN/control
echo "Final control file:"
cat nipovpn/DEBIAN/control
grep "^Version: ${PACKAGE_VERSION}$" nipovpn/DEBIAN/control
dpkg-deb --build nipovpn "build/${PACKAGE_FILE}"
- name: Show package information
run: |
dpkg -I "build/${PACKAGE_FILE}"
dpkg -c "build/${PACKAGE_FILE}"
- 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
name: nipovpn-mori-deb
path: build/${{ env.PACKAGE_FILE }}
release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download build artifact
- name: Download Debian package artifact
uses: actions/download-artifact@v4
with:
name: nipovpn
name: nipovpn-mori-deb
path: ./
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
- name: Create MORI GitHub Release
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
tag_name: mori-v${{ env.PACKAGE_VERSION }}
name: MORI Version v${{ env.PACKAGE_VERSION }}
prerelease: true
- name: Upload Debian Package to Release
uses: actions/upload-release-asset@v1
files: ${{ env.PACKAGE_FILE }}
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: ${{ github.token }}
+61 -36
View File
@@ -1,4 +1,4 @@
name: Build and Release Debian Package
name: Build and Release Debian Package - MAIN
on:
push:
@@ -6,6 +6,16 @@ on:
- main
paths:
- 'core/src/**'
- 'core/**'
- 'nipovpn/**'
- '.github/workflows/debian.yml'
permissions:
contents: write
env:
PACKAGE_VERSION: 1.1.${{ github.run_number }}
PACKAGE_FILE: nipovpn_1.1.${{ github.run_number }}_amd64.deb
jobs:
build:
@@ -13,63 +23,78 @@ jobs:
steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
- 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
- name: Build binary
run: |
rm -rf build
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
- name: Build Debian package
run: |
mkdir -p nipovpn/usr/bin
cp build/core/nipovpn nipovpn/usr/bin/nipovpn
chmod 755 nipovpn/usr/bin/nipovpn
sed -i -E "s/^Version[[:space:]]*:.*/Version: ${PACKAGE_VERSION}/" nipovpn/DEBIAN/control
echo "Final control file:"
cat nipovpn/DEBIAN/control
grep "^Version: ${PACKAGE_VERSION}$" nipovpn/DEBIAN/control
dpkg-deb --build nipovpn "build/${PACKAGE_FILE}"
- name: Show package information
run: |
dpkg -I "build/${PACKAGE_FILE}"
dpkg -c "build/${PACKAGE_FILE}"
- 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
name: nipovpn-main-deb
path: build/${{ env.PACKAGE_FILE }}
release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download build artifact
- name: Download Debian package artifact
uses: actions/download-artifact@v4
with:
name: nipovpn
name: nipovpn-main-deb
path: ./
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
- name: Check downloaded files
run: |
ls -lah
- name: Create MAIN GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: 'v1.1.${{ github.run_number }}'
release_name: Version v1.1.${{ github.run_number }}
draft: false
tag_name: v${{ env.PACKAGE_VERSION }}
name: Version v${{ env.PACKAGE_VERSION }}
prerelease: false
- name: Upload Debian Package to Release
uses: actions/upload-release-asset@v1
files: ${{ env.PACKAGE_FILE }}
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: ${{ github.token }}
+2 -2
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 + ":" +
@@ -149,7 +149,7 @@ void AgentHandler::handle() {
}
std::string AgentHandler::relayHostHeader(const std::shared_ptr<Config> &config) {
std::string hostHeader = config->general().fakeUrl;
std::string hostHeader = config->randomFakeUrl();
auto pos = hostHeader.find("://");
if (pos != std::string::npos) hostHeader = hostHeader.substr(pos + 3);
pos = hostHeader.find('/');
+44 -24
View File
@@ -9,32 +9,29 @@ Config::Config(const RunMode &mode, const std::string &filePath)
listenIp_("127.0.0.1"),
listenPort_(0),
general_({configYaml_["general"]["token"].as<std::string>(),
configYaml_["general"]["fakeUrl"].as<std::string>(),
configYaml_["general"]["fakeUrls"].as<std::vector<std::string>>(),
configYaml_["general"]["methods"].as<std::vector<std::string>>(),
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_);
@@ -75,7 +72,17 @@ std::string Config::toString() const {
ss << "\nConfig :\n"
<< " General :\n"
<< " token: " << general_.token << "\n"
<< " fakeUrl: " << general_.fakeUrl << "\n"
<< " fakeUrls: ";
for (std::size_t i = 0; i < general_.fakeUrls.size(); ++i) {
ss << general_.fakeUrls[i];
if (i != general_.fakeUrls.size() - 1) {
ss << ", ";
}
}
ss << "\n"
<< " methods: ";
for (std::size_t i = 0; i < general_.methods.size(); ++i) {
@@ -101,6 +108,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 +122,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 +130,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();
}
@@ -204,11 +208,27 @@ std::string Config::modeToString() const {
}
}
std::string Config::randomFakeUrl() const {
std::lock_guard<std::mutex> lock(configMutex_);
if (general_.fakeUrls.empty()) {
return "www.google.com";
}
static thread_local std::mt19937 generator{std::random_device{}()};
std::uniform_int_distribution<std::size_t> distribution(
0,
general_.fakeUrls.size() - 1);
return general_.fakeUrls[distribution(generator)];
}
std::string Config::randomMethod() const {
std::lock_guard<std::mutex> lock(configMutex_);
if (general_.methods.empty()) {
return "GET";// fallback
return "GET";
}
static thread_local std::mt19937 generator{std::random_device{}()};
@@ -224,7 +244,7 @@ std::string Config::randomEndPoint() const {
std::lock_guard<std::mutex> lock(configMutex_);
if (general_.endPoints.empty()) {
return "api";// fallback
return "api";
}
static thread_local std::mt19937 generator{std::random_device{}()};
+8 -11
View File
@@ -20,12 +20,17 @@ class Config : private Uncopyable {
private:
struct General {
std::string token;
std::string fakeUrl;
std::vector<std::string> fakeUrls;
std::vector<std::string> methods;
std::vector<std::string> endPoints;
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_;
@@ -112,6 +107,8 @@ public:
std::string toString() const;
std::string randomFakeUrl() const;
std::string randomMethod() const;
std::string randomEndPoint() const;
+1 -1
View File
@@ -325,7 +325,7 @@ inline BoolStr validateConfig(int argc, const char *argv[]) {
try {
configYaml["general"]["token"].as<std::string>();
configYaml["general"]["fakeUrl"].as<std::string>();
configYaml["general"]["fakeUrls"].as<std::vector<std::string>>();
configYaml["general"]["methods"].as<std::vector<std::string>>();
configYaml["general"]["endPoints"].as<std::vector<std::string>>();
configYaml["general"]["timeout"].as<unsigned short>();
+6 -4
View File
@@ -156,10 +156,11 @@ bool HTTP::parseTls() {
}
const std::string HTTP::genHttpPostReqString(const std::string &body) const {
auto fakeUrl = config_->randomFakeUrl();
return std::string(config_->randomMethod() + " " +
config_->general().fakeUrl + " HTTP/" +
fakeUrl + " HTTP/" +
config_->agent().httpVersion + "\r\n") +
"Host: " + config_->general().fakeUrl + "\r\n" +
"Host: " + fakeUrl + "\r\n" +
"User-Agent: " + config_->agent().userAgent + "\r\n" +
"Accept: */*\r\n" + "Connection: keep-alive\r\n" +
"Content-Length: " + std::to_string(body.length()) + "\r\n" +
@@ -167,10 +168,11 @@ const std::string HTTP::genHttpPostReqString(const std::string &body) const {
}
const std::string HTTP::genHttpRestPostReqString() const {
auto fakeUrl = config_->randomFakeUrl();
return std::string(config_->randomMethod() + " " +
config_->general().fakeUrl + " HTTP/" +
fakeUrl + " HTTP/" +
config_->agent().httpVersion + "\r\n") +
"Host: " + config_->general().fakeUrl + "\r\n" +
"Host: " + fakeUrl + "\r\n" +
"User-Agent: " + config_->agent().userAgent + "\r\n" +
"Accept: */*\r\n" + "Connection: keep-alive\r\n" +
"Rest: yes\r\n" + "COMP\r\n\r\n";
+72 -37
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);
@@ -158,7 +160,7 @@ bool TCPClient::doHandshakeClient() {
try {
if (!tlsEnabled_ || !sslSocket_) return true;
std::string sniHost = config_->general().fakeUrl;
std::string sniHost = config_->randomFakeUrl();
if (!sniHost.empty()) {
auto pos = sniHost.find("://");
@@ -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;
};
+91 -40
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(),
@@ -382,7 +390,7 @@ void TCPConnection::handleReadServer(const boost::system::error_code &error, siz
}
std::string TCPConnection::makeRelayHostHeader() const {
std::string hostHeader = config_->general().fakeUrl;
std::string hostHeader = config_->randomFakeUrl();
auto pos = hostHeader.find("://");
if (pos != std::string::npos) hostHeader = hostHeader.substr(pos + 3);
@@ -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);
+22 -15
View File
@@ -3,10 +3,14 @@
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 between agent and server
fakeUrl: "nipo.ciron.net"
# method:
# fakeUrls:
# Defines the list of fake urls between agent and server
fakeUrls:
- www.google.com
- nipo.ciron.net
- sudoer.net
- sudoer.ir
# 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 +20,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
@@ -36,7 +40,17 @@ general:
# connectionReuse: bool
# 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
connectionReuse: true
# 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 +69,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:
@@ -76,7 +86,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"