Compare commits

...
27 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
Morteza Bashsiz 80c631f66b Merge pull request #164 from MortezaBashsiz/dev
Merge from dev version v1-1-41
2026-05-26 20:58:56 +02:00
Morteza Bashsiz 8a1fcde280 Merge pull request #163 from MortezaBashsiz/mori
Mori
2026-05-26 16:52:07 +02:00
Morteza Bashsiz 51feb98dc3 fix segmentation fault for server and test connectionReuse 2026-05-26 16:37:48 +02:00
Morteza Bashsiz 560b5d93cc dummy commit 2026-05-26 14:03:01 +02:00
Morteza Bashsiz 97ee705eec dummy commit 2026-05-26 14:00:31 +02:00
Morteza Bashsiz 8d1ecfc2dc dummy commit 2026-05-26 13:55:11 +02:00
Morteza Bashsiz b402144e9e Update config 2026-05-26 13:27:39 +02:00
Morteza Bashsiz e7c8cb51cc See if behind cf fixed or not 2026-05-26 13:07:15 +02:00
Morteza Bashsiz 51fd1d47cc test if it works behind cf 2026-05-26 12:02:39 +02:00
Morteza Bashsiz 251b0202e8 Try to implement connectionReuse 2026-05-26 09:59:48 +02:00
Morteza Bashsiz 10e4481376 Merge pull request #153 from MortezaBashsiz/dev
Random endpoint and method
2026-05-06 13:19:59 +02:00
Morteza Bashsiz 47b56af86e Merge pull request #152 from MortezaBashsiz/mori
Random endpoint and method
2026-05-06 12:34:08 +02:00
Morteza Bashsiz 1c8d2d610b add random endPoint 2026-05-06 10:47:17 +02:00
Morteza Bashsiz 86f2b750a8 add random method 2026-05-06 10:18:48 +02:00
Morteza Bashsiz 0e4c1bf00d Implement tunnel mode
Implement tunnel mode beside http mode, So you can configure if you like to have the connection between agent and data in tunnel or pure HTTP request/response
2026-05-04 12:39:52 +02:00
Morteza Bashsiz 1452c1bd82 Merge pull request #150 from MortezaBashsiz/mori
Implement tunnel mode beside http mode, So you can configure if you like to have the connection between agent and data in tunnel or pure HTTP request/response
2026-05-04 11:59:56 +02:00
Morteza Bashsiz 09d5e25509 rename function from browser to client 2026-05-04 11:33:22 +02:00
Morteza Bashsiz f70ef566d7 Merge pull request #149 from MortezaBashsiz/dev
Update readme
Update actions
2026-05-01 21:00:09 +02:00
Morteza Bashsiz 064fe1614a Merge pull request #148 from MortezaBashsiz/mori
Change readme
2026-05-01 20:58:07 +02:00
15 changed files with 1342 additions and 1045 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 }}
+12 -6
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 + ":" +
@@ -86,15 +86,21 @@ void AgentHandler::handle() {
request_->httpType() == HTTP::HttpType::connect ? "open" : "request";
std::ostringstream outer;
outer << config_->general().method + " / HTTP/1.1\r\n"
const bool directTunnelOpen =
config_->general().tunnelEnable &&
request_->httpType() == HTTP::HttpType::connect;
outer << config_->randomMethod() + " /" + config_->randomEndPoint() + " HTTP/" << config_->agent().httpVersion << "\r\n"
<< "Host: " << relayHostHeader(config_) << "\r\n"
<< "User-Agent: Mozilla/5.0\r\n"
<< "User-Agent: " << config_->agent().userAgent << "\r\n"
<< "Accept: */*\r\n"
<< "Content-Type: application/octet-stream\r\n"
<< "Content-Type: application/text\r\n"
<< "X-Nipo-Session: " << to_string(uuid_) << "\r\n"
<< "X-Nipo-Action: " << action << "\r\n"
<< "Content-Length: " << innerRequest.size() << "\r\n"
<< "Connection: close\r\n"
<< "Connection: "
<< ((config_->general().connectionReuse || directTunnelOpen) ? "keep-alive" : "close")
<< "\r\n"
<< "\r\n"
<< innerRequest;
@@ -103,7 +109,7 @@ void AgentHandler::handle() {
client_->doWrite(readBuffer_);
client_->doReadAgent();
if (client_->readBuffer().size() == 0) {
if (client_->readBuffer().size() == 0 && !config_->general().connectionReuse) {
client_->socketShutdown();
return;
}
+79 -25
View File
@@ -10,29 +10,28 @@ Config::Config(const RunMode &mode, const std::string &filePath)
listenPort_(0),
general_({configYaml_["general"]["token"].as<std::string>(),
configYaml_["general"]["fakeUrl"].as<std::string>(),
configYaml_["general"]["method"].as<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"]["tunnelEnable"].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_);
@@ -67,38 +66,61 @@ Config::~Config() = default;
std::string Config::toString() const {
std::lock_guard<std::mutex> lock(configMutex_);
std::stringstream ss;
ss << "\nConfig :\n"
<< " General :\n"
<< " token: " << general_.token << "\n"
<< " fakeUrl: " << general_.fakeUrl << "\n"
<< " method: " << general_.method << "\n"
<< " methods: ";
for (std::size_t i = 0; i < general_.methods.size(); ++i) {
ss << general_.methods[i];
if (i != general_.methods.size() - 1) {
ss << ", ";
}
}
ss << "\n"
<< " endPoints: ";
for (std::size_t i = 0; i < general_.endPoints.size(); ++i) {
ss << general_.endPoints[i];
if (i != general_.endPoints.size() - 1) {
ss << ", ";
}
}
ss << "\n"
<< " timeout: " << general_.timeout << "\n"
<< " tunnelEnable: " << general_.tunnelEnable << "\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"
<< " logFile: " << log_.file << "\n"
<< " server :\n"
<< " Server :\n"
<< " threads: " << server_.threads << "\n"
<< " listenIp: " << server_.listenIp << "\n"
<< " listenPort: " << server_.listenPort << "\n"
<< " tlsEnable: " << server_.tlsEnable << "\n"
<< " tlsVerifyPeer: " << server_.tlsVerifyPeer << "\n"
<< " tlsCertFile: " << server_.tlsCertFile << "\n"
<< " tlsKeyFile: " << server_.tlsKeyFile << "\n"
<< " tlsCaFile: " << server_.tlsCaFile << "\n"
<< " agent :\n"
<< " Agent :\n"
<< " threads: " << agent_.threads << "\n"
<< " listenIp: " << agent_.listenIp << "\n"
<< " listenPort: " << agent_.listenPort << "\n"
<< " serverIp: " << agent_.serverIp << "\n"
<< " serverPort: " << agent_.serverPort << "\n"
<< " httpVersion: " << agent_.httpVersion << "\n"
<< " userAgent: " << agent_.userAgent << "\n"
<< " tlsEnable: " << agent_.tlsEnable << "\n"
<< " tlsVerifyPeer: " << agent_.tlsVerifyPeer << "\n"
<< " tlsCaFile: " << agent_.tlsCaFile << "\n";
<< " userAgent: " << agent_.userAgent << "\n";
return ss.str();
}
@@ -174,4 +196,36 @@ std::string Config::modeToString() const {
default:
return "UNKNOWN MODE";
}
}
std::string Config::randomMethod() const {
std::lock_guard<std::mutex> lock(configMutex_);
if (general_.methods.empty()) {
return "GET";// fallback
}
static thread_local std::mt19937 generator{std::random_device{}()};
std::uniform_int_distribution<std::size_t> distribution(
0,
general_.methods.size() - 1);
return general_.methods[distribution(generator)];
}
std::string Config::randomEndPoint() const {
std::lock_guard<std::mutex> lock(configMutex_);
if (general_.endPoints.empty()) {
return "api";// fallback
}
static thread_local std::mt19937 generator{std::random_device{}()};
std::uniform_int_distribution<std::size_t> distribution(
0,
general_.endPoints.size() - 1);
return general_.endPoints[distribution(generator)];
}
+14 -11
View File
@@ -4,8 +4,10 @@
#include <memory>
#include <mutex>
#include <random>
#include <sstream>
#include <string>
#include <vector>
#include "general.hpp"
@@ -19,9 +21,16 @@ private:
struct General {
std::string token;
std::string fakeUrl;
std::string method;
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 {
@@ -33,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 {
@@ -49,10 +52,6 @@ private:
unsigned short serverPort;
std::string httpVersion;
std::string userAgent;
bool tlsEnable;
bool tlsVerifyPeer;
std::string tlsCaFile;
};
const RunMode &runMode_;
@@ -107,4 +106,8 @@ public:
std::string modeToString() const;
std::string toString() const;
std::string randomMethod() const;
std::string randomEndPoint() const;
};
+2 -1
View File
@@ -326,7 +326,8 @@ 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"]["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>();
} catch (const std::exception &e) {
+2 -2
View File
@@ -156,7 +156,7 @@ bool HTTP::parseTls() {
}
const std::string HTTP::genHttpPostReqString(const std::string &body) const {
return std::string(config_->general().method + " " +
return std::string(config_->randomMethod() + " " +
config_->general().fakeUrl + " HTTP/" +
config_->agent().httpVersion + "\r\n") +
"Host: " + config_->general().fakeUrl + "\r\n" +
@@ -167,7 +167,7 @@ const std::string HTTP::genHttpPostReqString(const std::string &body) const {
}
const std::string HTTP::genHttpRestPostReqString() const {
return std::string(config_->general().method + " " +
return std::string(config_->randomMethod() + " " +
config_->general().fakeUrl + " HTTP/" +
config_->agent().httpVersion + "\r\n") +
"Host: " + config_->general().fakeUrl + "\r\n" +
+11 -11
View File
@@ -91,7 +91,7 @@ void ServerHandler::makePlainHttpResponse(const std::string &body,
std::ostringstream outer;
outer << "HTTP/1.1 " << status << "\r\n"
<< "Content-Type: application/octet-stream\r\n"
<< "Content-Type: application/text\r\n"
<< "Content-Length: " << body.size() << "\r\n"
<< "Connection: " << connection << "\r\n"
<< "\r\n"
@@ -198,7 +198,7 @@ void ServerHandler::handle() {
}
if (!targetClient || !targetClient->isOpen()) {
makeEncryptedHttpResponse("", "200 OK", "close");
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
return;
}
@@ -206,7 +206,7 @@ void ServerHandler::handle() {
copyStringToStreambuf(hexToASCII(decryption.message), tunnelBuf);
targetClient->doWrite(tunnelBuf);
makeEncryptedHttpResponse("", "200 OK", "close");
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
return;
}
@@ -223,7 +223,7 @@ void ServerHandler::handle() {
}
if (!targetClient || !targetClient->isOpen()) {
makeEncryptedHttpResponse("", "200 OK", "close");
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
return;
}
@@ -231,7 +231,7 @@ void ServerHandler::handle() {
std::size_t available = targetClient->socket().available(ec);
if (ec || available == 0) {
makeEncryptedHttpResponse("", "200 OK", "close");
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
return;
}
@@ -241,14 +241,14 @@ void ServerHandler::handle() {
ec);
if (ec || n == 0) {
makeEncryptedHttpResponse("", "200 OK", "close");
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
return;
}
makeEncryptedHttpResponse(
std::string(data.data(), n),
"200 OK",
"close");
(config_->general().connectionReuse ? "keep-alive" : "close"));
return;
}
@@ -262,7 +262,7 @@ void ServerHandler::handle() {
sessions_.erase(it);
}
makeEncryptedHttpResponse("", "200 OK", "close");
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
return;
}
@@ -383,7 +383,7 @@ void ServerHandler::handle() {
makeEncryptedHttpResponse(
"HTTP/1.1 200 Connection Established\r\n\r\n",
"200 OK",
"close");
"keep-alive");
connect_ = false;
end_ = false;
@@ -407,14 +407,14 @@ void ServerHandler::handle() {
if (client_->readBuffer().size() == 0) {
client_->socket().close();
makeEncryptedHttpResponse("", "200 OK", "close");
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
return;
}
makeEncryptedHttpResponse(
streambufToString(client_->readBuffer()),
"200 OK",
"close");
(config_->general().connectionReuse ? "keep-alive" : "close"));
connect_ = false;
end_ = false;
+160 -105
View File
@@ -34,7 +34,6 @@ bool TCPClient::isOpen() const {
}
bool TCPClient::enableTlsClient() {
std::lock_guard lock(mutex_);
try {
if (tlsEnabled_) return true;
@@ -48,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);
@@ -92,16 +91,26 @@ bool TCPClient::enableTlsClient() {
}
bool TCPClient::doConnect(const std::string &dstIP, const unsigned short &dstPort) {
std::lock_guard lock(mutex_);
try {
if (tlsEnabled_ && sslSocket_ && sslSocket_->lowest_layer().is_open()) {
return true;
}
if (!tlsEnabled_ && socket_.is_open()) {
return true;
}
log_->write("[" + to_string(uuid_) + "] [TCPClient doConnect] [DST " + dstIP +
":" + std::to_string(dstPort) + "]",
Log::Level::DEBUG);
boost::system::error_code error_code;
auto endpoint =
resolver_.resolve(dstIP.c_str(), std::to_string(dstPort).c_str(), error_code);
auto endpoint = resolver_.resolve(
dstIP.c_str(),
std::to_string(dstPort).c_str(),
error_code);
if (error_code) {
log_->write("[" + to_string(uuid_) +
@@ -111,9 +120,19 @@ bool TCPClient::doConnect(const std::string &dstIP, const unsigned short &dstPor
return false;
}
if (tlsEnabled_ && sslSocket_) {
if (tlsEnabled_) {
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);
}
@@ -128,7 +147,8 @@ bool TCPClient::doConnect(const std::string &dstIP, const unsigned short &dstPor
return true;
} catch (std::exception &error) {
log_->write("[" + to_string(uuid_) + "] [TCPClient doConnect] " +
log_->write("[" + to_string(uuid_) +
"] [TCPClient doConnect] " +
error.what(),
Log::Level::ERROR);
return false;
@@ -136,7 +156,6 @@ bool TCPClient::doConnect(const std::string &dstIP, const unsigned short &dstPor
}
bool TCPClient::doHandshakeClient() {
std::lock_guard lock(mutex_);
try {
if (!tlsEnabled_ || !sslSocket_) return true;
@@ -217,13 +236,11 @@ bool TCPClient::doHandshakeClient() {
}
void TCPClient::writeBuffer(boost::asio::streambuf &buffer) {
std::lock_guard lock(mutex_);
moveStreambuf(buffer, writeBuffer_);
}
void TCPClient::doWrite(boost::asio::streambuf &buffer) {
std::lock_guard lock(mutex_);
try {
moveStreambuf(buffer, writeBuffer_);
@@ -245,7 +262,7 @@ void TCPClient::doWrite(boost::asio::streambuf &buffer) {
resetTimeout();
if (tlsEnabled_ && sslSocket_) {
log_->write("[" + to_string(uuid_) + "] [TCPClient doWrite] [DST " +
log_->write("[" + to_string(uuid_) + "] [TCPClient doWrite] [SSL] [DST " +
sslSocket_->lowest_layer().remote_endpoint().address().to_string() +
":" +
std::to_string(sslSocket_->lowest_layer().remote_endpoint().port()) +
@@ -253,7 +270,7 @@ void TCPClient::doWrite(boost::asio::streambuf &buffer) {
Log::Level::DEBUG);
boost::asio::write(*sslSocket_, writeBuffer_, error);
} else {
log_->write("[" + to_string(uuid_) + "] [TCPClient doWrite] [DST " +
log_->write("[" + to_string(uuid_) + "] [TCPClient doWrite] [TCP] [DST " +
socket_.remote_endpoint().address().to_string() + ":" +
std::to_string(socket_.remote_endpoint().port()) +
"] [Bytes " + std::to_string(writeBuffer_.size()) + "] ",
@@ -281,51 +298,70 @@ void TCPClient::doWrite(boost::asio::streambuf &buffer) {
void TCPClient::doReadAgent() {
boost::system::error_code error;
std::lock_guard lock(mutex_);
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();
}
@@ -334,7 +370,6 @@ void TCPClient::doReadAgent() {
void TCPClient::doReadServer() {
boost::system::error_code error;
end_ = false;
std::lock_guard lock(mutex_);
readBuffer_.consume(readBuffer_.size());
try {
@@ -429,26 +464,46 @@ void TCPClient::onTimeout(const boost::system::error_code &error) {
}
void TCPClient::socketShutdown() {
try {
boost::system::error_code ignored;
boost::system::error_code ec;
if (sslSocket_) {
sslSocket_->shutdown(ignored);
sslSocket_->lowest_layer().shutdown(
boost::asio::ip::tcp::socket::shutdown_both, ignored);
sslSocket_->lowest_layer().close(ignored);
}
std::lock_guard<std::mutex> lock(mutex_);
if (socket_.is_open()) {
socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored);
socket_.close(ignored);
}
if (closed_) return;
closed_ = true;
} catch (std::exception &error) {
log_->write("[" + to_string(uuid_) +
"] [TCPClient socketShutdown] [catch] " + error.what(),
cancelTimeout();
if (sslSocket_) {
log_->write("[" + to_string(uuid_) + "] [TCPClient socketShutdown] [SSL]",
Log::Level::DEBUG);
auto &lowest = sslSocket_->lowest_layer();
lowest.cancel(ec);
ec.clear();
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("[" + 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) {
@@ -553,10 +608,13 @@ bool TCPClient::HttpUtils::readHttpMessage(
bool TCPClient::HttpUtils::readHttpMessageImpl(
boost::asio::streambuf &out,
boost::system::error_code &ec,
const std::function<std::size_t(boost::asio::mutable_buffer,
boost::system::error_code &)> &readSome,
const std::function<bool(boost::asio::streambuf &,
boost::system::error_code &)> &readHeaders) {
const std::function<std::size_t(
boost::asio::mutable_buffer,
boost::system::error_code &)> &readSome,
const std::function<bool(
boost::asio::streambuf &,
boost::system::error_code &)> &readHeaders) {
out.consume(out.size());
if (!readHeaders(out, ec)) {
@@ -568,64 +626,61 @@ bool TCPClient::HttpUtils::readHttpMessageImpl(
std::string body = extractBody(current);
std::size_t contentLength = 0;
if (parseContentLength(headers, contentLength)) {
if (body.size() < contentLength) {
std::vector<char> tmp(contentLength - body.size());
std::size_t total = 0;
while (total < tmp.size()) {
std::size_t n = readSome(
boost::asio::buffer(tmp.data() + total, tmp.size() - total),
ec);
if (ec) return false;
total += n;
while (body.size() < contentLength) {
char tmp[8192];
std::size_t remaining =
contentLength - body.size();
std::size_t toRead =
std::min<std::size_t>(
sizeof(tmp),
remaining);
std::size_t n =
readSome(
boost::asio::buffer(
tmp,
toRead),
ec);
if (ec) {
return false;
}
std::ostream os(&out);
os.write(tmp.data(), static_cast<std::streamsize>(tmp.size()));
if (n == 0) {
ec = boost::asio::error::eof;
return false;
}
boost::asio::buffer_copy(
out.prepare(n),
boost::asio::buffer(tmp, n));
out.commit(n);
body.append(tmp, n);
}
return true;
}
if (isChunked(headers)) {
for (;;) {
current = streambufToString(out);
auto bodyPos = current.find("\r\n\r\n");
if (bodyPos == std::string::npos) return false;
std::string bodyPart = current.substr(bodyPos + 4);
auto lastChunkPos = bodyPart.find("\r\n0\r\n\r\n");
if (lastChunkPos != std::string::npos || bodyPart == "0\r\n\r\n") {
return true;
while (
body.find("\r\n0\r\n\r\n") ==
std::string::npos &&
body.find("\r\n0\r\n") ==
std::string::npos) {
char tmp[8192];
std::size_t n =
readSome(
boost::asio::buffer(tmp),
ec);
if (ec) {
return false;
}
std::array<char, 4096> tmp{};
std::size_t n = readSome(boost::asio::buffer(tmp), ec);
if (ec) return false;
std::ostream os(&out);
os.write(tmp.data(), static_cast<std::streamsize>(n));
if (n == 0) {
ec = boost::asio::error::eof;
return false;
}
boost::asio::buffer_copy(
out.prepare(n),
boost::asio::buffer(tmp, n));
out.commit(n);
body.append(tmp, n);
}
return true;
}
for (;;) {
std::array<char, 4096> tmp{};
std::size_t n = readSome(boost::asio::buffer(tmp), ec);
if (ec == boost::asio::error::eof) {
ec.clear();
return true;
}
if (ec) return false;
std::ostream os(&out);
os.write(tmp.data(), static_cast<std::streamsize>(n));
}
}
return true;
}
+1
View File
@@ -103,4 +103,5 @@ private:
tcp::resolver resolver_;
boost::asio::steady_timer timeout_;
mutable std::mutex mutex_;
bool closed_ = false;
};
+858 -765
View File
File diff suppressed because it is too large. Load diff
+9 -7
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>
@@ -58,27 +59,27 @@ public:
void enableDirectTunnelMode();
void relayBrowserToServer();
void relayServerToBrowser();
void relayClientToServer();
void relayServerToClient();
void relayAgentToTarget();
void relayTargetToAgent();
void asyncWriteToAgentConnection(
inline void asyncWriteToAgentConnection(
const char *data,
std::size_t bytes,
std::function<void(const boost::system::error_code &)> done);
void asyncReadFromAgentConnection(
inline void asyncReadFromAgentConnection(
std::array<char, 8192> &buffer,
std::function<void(const boost::system::error_code &, std::size_t)> done);
void asyncWriteToAgentServerConnection(
inline void asyncWriteToAgentServerConnection(
const char *data,
std::size_t bytes,
std::function<void(const boost::system::error_code &)> done);
void asyncReadFromAgentServerConnection(
inline void asyncReadFromAgentServerConnection(
std::array<char, 8192> &buffer,
std::function<void(const boost::system::error_code &, std::size_t)> done);
@@ -114,7 +115,7 @@ private:
void cancelTimeout();
void onTimeout(const boost::system::error_code &error);
void startTunnelReadFromBrowser();
void startTunnelReadFromClient();
void startTunnelPollServer();
std::string postTunnelAction(const std::string &action, const std::string &rawBody);
std::string makeRelayHostHeader() const;
@@ -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);
+41 -19
View File
@@ -5,19 +5,48 @@ general:
token: "af445adb-2434-4975-9445-2c1b2231"
# fakeUrl: string
# Defines the fake url between agent and server
fakeUrl: "nipo.ciron.net"
# method: "HEAD|GET|POST|PUT|DELETE"
# Defines with which method
fakeUrl: "www.google.com"
# methods:
# Defines the list of using methods
# you like to send requests from agent to server
method: "GET"
# Program will choose randomly from this list
methods:
- HEAD
- GET
- POST
- PUT
- DELETE
# endPoints:
# Defines the list of using endpoints
# you like to send requests from agent to server
# Program will choose randomly from this list
endPoints:
- api
- login
- user
- update
# timeout: unsigned short
# Defines the timeout for I/O Operation in seconds. 0 indicates no timeout.
# Useful to automatically close stalled connections.
timeout: 10
# tunnelEnable: bool
# Degines the connection mode between agent and server. If enabled then the traffic
# Defines the connection mode between agent and server. If enabled then the traffic
# will be TCP/TLS tunnel like.
tunnelEnable: true
tunnelEnable: false
# 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
# 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
@@ -33,14 +62,10 @@ server:
# threads: number of threads in server
threads: 8
# listenIp: which must be IPv4 which is used on server
listenIp: "127.0.0.10"
listenIp: "0.0.0.0"
# listenPort: the port number which will be used on server
listenPort: 8081
tlsEnable: false
tlsVerifyPeer: false
tlsCertFile: "/etc/nipovpn/server.crt"
tlsKeyFile: "/etc/nipovpn/server.key"
tlsCaFile: ""
listenPort: 80
# This block is to define agent directives
agent:
@@ -51,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: 8081
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"