Compare commits

..
64 Commits
Author SHA1 Message Date
Morteza Bashsiz 698da19a8c Merge pull request #204 from MortezaBashsiz/revert-202-dev
Revert "Version 1.1.55"
2026-06-07 07:41:46 +02:00
Morteza Bashsiz 451a169756 Revert "Version 1.1.55" 2026-06-07 07:38:50 +02:00
Morteza Bashsiz 277321306b Version 1.1.55
Version 1.1.55
2026-06-06 14:04:46 +02:00
Morteza Bashsiz d6e0161aa5 Merge pull request #201 from MortezaBashsiz/mori
Version 1.1.55
2026-06-06 14:02:13 +02:00
Morteza Bashsiz 14b0947140 Version 1.1.55 2026-06-06 14:01:16 +02:00
Morteza Bashsiz 134251779c Merge pull request #200 from MortezaBashsiz/mori
change tcpconnection handle accept method
2026-06-06 08:32:05 +02:00
Morteza Bashsiz 92d877be31 change tcpconnection handle accept method 2026-06-06 08:17:14 +02:00
Morteza Bashsiz 7e6ae56753 Version 1.1.54
In this version

Socks5 protocol is now supported. So user can choose socks5|http protocol between client and agent

Refactor of code base is done
2026-06-05 17:45:46 +02:00
Morteza Bashsiz deae50f9d4 Merge pull request #197 from MortezaBashsiz/mori
Add socks5 support
2026-06-05 16:59:20 +02:00
Morteza Bashsiz daa21a57db fix main branch support 2026-06-05 16:38:20 +02:00
Morteza Bashsiz d8f09b9fe2 Add socks5 support 2026-06-05 16:21:05 +02:00
Morteza Bashsiz aeeea2a527 Merge pull request #196 from MortezaBashsiz/mori
Refactor code with better style
2026-06-05 10:33:08 +02:00
Morteza Bashsiz 55004368e4 Refactor code with better style 2026-06-05 10:30:06 +02:00
Morteza Bashsiz d0da1c55d8 Version 1.1.53
Fix handshake bug, close connection after handshake failed
2026-06-05 07:53:48 +02:00
Morteza Bashsiz 3363a7a5d2 Fix handshake bug, close connection after handshake failed
Fix handshake bug, close connection after handshake failed
2026-06-04 23:38:55 +02:00
Morteza Bashsiz 4cdc66bdf1 Fix handshake bug, close connection after handshake failed 2026-06-04 23:36:15 +02:00
Morteza Bashsiz 2540b3a504 Add windows build 2026-06-04 18:33:56 +02:00
Morteza Bashsiz cb87555503 Version 1.1.52
Version 1.1.52
2026-06-04 17:17:48 +02:00
Morteza Bashsiz 20bb0d2b9d Version 1.1.52
Version 1.1.52
2026-06-04 17:14:08 +02:00
Morteza Bashsiz 31b7bb96a8 Version 1.1.52 2026-06-04 17:12:52 +02:00
Morteza Bashsiz 9abc319202 Add workflows for all branches & support android in threading
Add workflows for all branches & support android in threading
2026-06-04 16:51:51 +02:00
Morteza Bashsiz 6c21edfc40 Add workflows for all branches & support android in threading 2026-06-04 16:38:43 +02:00
Morteza Bashsiz 6493d88258 create workflows for all branches 2026-06-04 16:37:01 +02:00
Morteza Bashsiz ed10d097f1 fix missing args 2026-06-03 14:52:26 +02:00
Morteza Bashsiz 14ead78ff8 add release step to android dev 2026-06-02 19:25:05 +02:00
Morteza Bashsiz b1a18e243c change jthread to thread for android 2026-06-02 18:43:46 +02:00
Morteza Bashsiz 24390b6562 fix android binary action 2026-06-02 18:26:57 +02:00
Morteza Bashsiz ec4a68fdb6 Merge pull request #187 from MortezaBashsiz/dev
Fix main verion
2026-06-02 16:37:21 +02:00
Morteza Bashsiz bae6afa35b Merge pull request #186 from MortezaBashsiz/mori
Mori
2026-06-02 16:35:16 +02:00
Morteza Bashsiz 36315032d9 fix main version 2026-06-02 16:33:49 +02:00
Morteza Bashsiz 96758b6322 add android 2026-06-02 16:18:21 +02:00
Morteza Bashsiz 9b5b275275 Merge pull request #185 from MortezaBashsiz/dev
add termux version #182
2026-06-02 16:14:35 +02:00
Morteza Bashsiz 76a9e4acb0 Merge pull request #184 from MortezaBashsiz/mori
add aarch64 termux
2026-06-02 15:57:43 +02:00
Morteza Bashsiz 3b3d2f4d88 add aarch64 to the build 2026-06-02 15:55:23 +02:00
Morteza Bashsiz 9af39a5715 Merge pull request #181 from MortezaBashsiz/dev
Release arm64 and amd64
2026-06-02 09:28:44 +02:00
Morteza Bashsiz 2f043a6f83 Merge pull request #180 from MortezaBashsiz/mori
Build debian package for arm64
2026-06-02 07:26:11 +02:00
Morteza Bashsiz d94075e5c3 fix workflow dev and main 2026-06-02 07:09:44 +02:00
Morteza Bashsiz 9f1a7c8637 fix control 2026-06-02 07:09:44 +02:00
Morteza Bashsiz 2add09ea33 fix control 2026-06-02 07:09:44 +02:00
Morteza Bashsiz 8beee5d127 add arm to workflow 2026-06-02 07:09:44 +02:00
Morteza Bashsiz 84bb675b9c add arm to workflow 2026-06-02 07:09:44 +02:00
Morteza Bashsiz 67c43de80d implement pullTimeout
Add configurable
```
  # pullTimeout: unsigned short
  # Defines the timeout for I/O Operation in milliseconds.
  #   Useful to expire serverside read timer.
  pullTimeout: 50
```
Higher number helps when your network is slower
2026-06-01 15:53:38 +02:00
Morteza Bashsiz ab4580920f implement pullTimeout (#178) 2026-06-01 15:47:15 +02:00
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
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
34 changed files with 2525 additions and 690 deletions

No files matched your search

+157
View File
@@ -0,0 +1,157 @@
name: Build Android Binary - dev
on:
workflow_dispatch:
push:
branches:
- dev
paths:
- 'core/src/**'
- 'core/**'
- 'CMakeLists.txt'
- 'core/CMakeLists.txt'
- '.github/workflows/android-dev.yml'
permissions:
contents: write
env:
PACKAGE_VERSION: 0.2.${{ github.run_number }}
jobs:
build-android:
runs-on: ubuntu-24.04
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Install host dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
cmake \
ninja-build \
git \
curl \
zip \
unzip \
tar \
pkg-config \
autoconf \
autoconf-archive \
automake \
libtool
- name: Setup Android NDK r29
uses: nttld/setup-ndk@v1
with:
ndk-version: r29
add-to-path: true
- name: Show Android NDK information
run: |
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME"
echo "ANDROID_NDK_ROOT=$ANDROID_NDK_ROOT"
ls -lah "$ANDROID_NDK_HOME"
- name: Setup vcpkg
run: |
git clone https://github.com/microsoft/vcpkg.git "$HOME/vcpkg"
"$HOME/vcpkg/bootstrap-vcpkg.sh"
echo "VCPKG_ROOT=$HOME/vcpkg" >> "$GITHUB_ENV"
echo "$HOME/vcpkg" >> "$GITHUB_PATH"
- name: Build Android dependencies
run: |
"$VCPKG_ROOT/vcpkg" install \
boost:arm64-android \
openssl:arm64-android \
yaml-cpp:arm64-android
- name: Configure Android arm64-v8a build
run: |
rm -rf build-android-arm64
cmake -S . -B build-android-arm64 \
-G Ninja \
-DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" \
-DVCPKG_TARGET_TRIPLET=arm64-android \
-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \
-DANDROID_ABI=arm64-v8a \
-DANDROID_PLATFORM=android-23 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-z,max-page-size=16384" \
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,-z,max-page-size=16384"
- name: Build Android arm64-v8a binary
run: |
cmake --build build-android-arm64 -j"$(nproc)"
- name: Collect Android binary and libraries
run: |
mkdir -p out/android/arm64-v8a
if [ ! -f build-android-arm64/core/nipovpn ]; then
echo "Android binary not found:"
find build-android-arm64 -type f || true
exit 1
fi
cp build-android-arm64/core/nipovpn out/android/arm64-v8a/libnipovpn_dev_"${{ env.PACKAGE_VERSION }}".so
chmod 755 out/android/arm64-v8a/libnipovpn_dev_"${{ env.PACKAGE_VERSION }}".so
find "$VCPKG_ROOT/installed/arm64-android" -type f -name "*.so*" -exec cp -v {} out/android/arm64-v8a/ \; || true
ls -lah out/android/arm64-v8a/
- name: Check 16 KB ELF alignment
run: |
READELF="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-readelf"
for file in out/android/arm64-v8a/*.so*; do
echo "Checking $file"
"$READELF" -l "$file" | grep -A3 LOAD || true
if "$READELF" -l "$file" | awk '/LOAD/ && $NF != "0x4000" { bad=1 } END { exit bad }'; then
echo "OK: $file is 16 KB aligned"
else
echo "ERROR: $file is not 16 KB aligned"
exit 1
fi
done
- name: Upload Android artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn-dev-android-arm64-v8a
path: out/android/arm64-v8a/
release-android:
needs:
- build-android
runs-on: ubuntu-24.04
steps:
- name: Download Android artifact
uses: actions/download-artifact@v4
with:
name: nipovpn-dev-android-arm64-v8a
path: ./android-artifact
- name: Show downloaded Android artifact
run: |
ls -lah android-artifact
- name: Create Android GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: dev-android-v${{ env.PACKAGE_VERSION }}
name: dev Android Binary v${{ env.PACKAGE_VERSION }}
prerelease: true
files: |
android-artifact/*
env:
GITHUB_TOKEN: ${{ github.token }}
+157
View File
@@ -0,0 +1,157 @@
name: Build Android Binary - main
on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'core/src/**'
- 'core/**'
- 'CMakeLists.txt'
- 'core/CMakeLists.txt'
- '.github/workflows/android-main.yml'
permissions:
contents: write
env:
PACKAGE_VERSION: 1.1.54
jobs:
build-android:
runs-on: ubuntu-24.04
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Install host dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
cmake \
ninja-build \
git \
curl \
zip \
unzip \
tar \
pkg-config \
autoconf \
autoconf-archive \
automake \
libtool
- name: Setup Android NDK r29
uses: nttld/setup-ndk@v1
with:
ndk-version: r29
add-to-path: true
- name: Show Android NDK information
run: |
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME"
echo "ANDROID_NDK_ROOT=$ANDROID_NDK_ROOT"
ls -lah "$ANDROID_NDK_HOME"
- name: Setup vcpkg
run: |
git clone https://github.com/microsoft/vcpkg.git "$HOME/vcpkg"
"$HOME/vcpkg/bootstrap-vcpkg.sh"
echo "VCPKG_ROOT=$HOME/vcpkg" >> "$GITHUB_ENV"
echo "$HOME/vcpkg" >> "$GITHUB_PATH"
- name: Build Android dependencies
run: |
"$VCPKG_ROOT/vcpkg" install \
boost:arm64-android \
openssl:arm64-android \
yaml-cpp:arm64-android
- name: Configure Android arm64-v8a build
run: |
rm -rf build-android-arm64
cmake -S . -B build-android-arm64 \
-G Ninja \
-DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" \
-DVCPKG_TARGET_TRIPLET=arm64-android \
-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \
-DANDROID_ABI=arm64-v8a \
-DANDROID_PLATFORM=android-23 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-z,max-page-size=16384" \
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,-z,max-page-size=16384"
- name: Build Android arm64-v8a binary
run: |
cmake --build build-android-arm64 -j"$(nproc)"
- name: Collect Android binary and libraries
run: |
mkdir -p out/android/arm64-v8a
if [ ! -f build-android-arm64/core/nipovpn ]; then
echo "Android binary not found:"
find build-android-arm64 -type f || true
exit 1
fi
cp build-android-arm64/core/nipovpn out/android/arm64-v8a/libnipovpn_"${{ env.PACKAGE_VERSION }}".so
chmod 755 out/android/arm64-v8a/libnipovpn_"${{ env.PACKAGE_VERSION }}".so
find "$VCPKG_ROOT/installed/arm64-android" -type f -name "*.so*" -exec cp -v {} out/android/arm64-v8a/ \; || true
ls -lah out/android/arm64-v8a/
- name: Check 16 KB ELF alignment
run: |
READELF="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-readelf"
for file in out/android/arm64-v8a/*.so*; do
echo "Checking $file"
"$READELF" -l "$file" | grep -A3 LOAD || true
if "$READELF" -l "$file" | awk '/LOAD/ && $NF != "0x4000" { bad=1 } END { exit bad }'; then
echo "OK: $file is 16 KB aligned"
else
echo "ERROR: $file is not 16 KB aligned"
exit 1
fi
done
- name: Upload Android artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn-main-android-arm64-v8a
path: out/android/arm64-v8a/
release-android:
needs:
- build-android
runs-on: ubuntu-24.04
steps:
- name: Download Android artifact
uses: actions/download-artifact@v4
with:
name: nipovpn-main-android-arm64-v8a
path: ./android-artifact
- name: Show downloaded Android artifact
run: |
ls -lah android-artifact
- name: Create Android GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: android-v${{ env.PACKAGE_VERSION }}
name: Android Binary v${{ env.PACKAGE_VERSION }}
prerelease: true
files: |
android-artifact/*
env:
GITHUB_TOKEN: ${{ github.token }}
+157
View File
@@ -0,0 +1,157 @@
name: Build Android Binary - MORI
on:
workflow_dispatch:
push:
branches:
- mori
paths:
- 'core/src/**'
- 'core/**'
- 'CMakeLists.txt'
- 'core/CMakeLists.txt'
- '.github/workflows/android-mori.yml'
permissions:
contents: write
env:
PACKAGE_VERSION: 0.1.${{ github.run_number }}
jobs:
build-android:
runs-on: ubuntu-24.04
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Install host dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
cmake \
ninja-build \
git \
curl \
zip \
unzip \
tar \
pkg-config \
autoconf \
autoconf-archive \
automake \
libtool
- name: Setup Android NDK r29
uses: nttld/setup-ndk@v1
with:
ndk-version: r29
add-to-path: true
- name: Show Android NDK information
run: |
echo "ANDROID_NDK_HOME=$ANDROID_NDK_HOME"
echo "ANDROID_NDK_ROOT=$ANDROID_NDK_ROOT"
ls -lah "$ANDROID_NDK_HOME"
- name: Setup vcpkg
run: |
git clone https://github.com/microsoft/vcpkg.git "$HOME/vcpkg"
"$HOME/vcpkg/bootstrap-vcpkg.sh"
echo "VCPKG_ROOT=$HOME/vcpkg" >> "$GITHUB_ENV"
echo "$HOME/vcpkg" >> "$GITHUB_PATH"
- name: Build Android dependencies
run: |
"$VCPKG_ROOT/vcpkg" install \
boost:arm64-android \
openssl:arm64-android \
yaml-cpp:arm64-android
- name: Configure Android arm64-v8a build
run: |
rm -rf build-android-arm64
cmake -S . -B build-android-arm64 \
-G Ninja \
-DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" \
-DVCPKG_TARGET_TRIPLET=arm64-android \
-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake" \
-DANDROID_ABI=arm64-v8a \
-DANDROID_PLATFORM=android-23 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,-z,max-page-size=16384" \
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,-z,max-page-size=16384"
- name: Build Android arm64-v8a binary
run: |
cmake --build build-android-arm64 -j"$(nproc)"
- name: Collect Android binary and libraries
run: |
mkdir -p out/android/arm64-v8a
if [ ! -f build-android-arm64/core/nipovpn ]; then
echo "Android binary not found:"
find build-android-arm64 -type f || true
exit 1
fi
cp build-android-arm64/core/nipovpn out/android/arm64-v8a/libnipovpn_mori_"${{ env.PACKAGE_VERSION }}".so
chmod 755 out/android/arm64-v8a/libnipovpn_mori_"${{ env.PACKAGE_VERSION }}".so
find "$VCPKG_ROOT/installed/arm64-android" -type f -name "*.so*" -exec cp -v {} out/android/arm64-v8a/ \; || true
ls -lah out/android/arm64-v8a/
- name: Check 16 KB ELF alignment
run: |
READELF="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-readelf"
for file in out/android/arm64-v8a/*.so*; do
echo "Checking $file"
"$READELF" -l "$file" | grep -A3 LOAD || true
if "$READELF" -l "$file" | awk '/LOAD/ && $NF != "0x4000" { bad=1 } END { exit bad }'; then
echo "OK: $file is 16 KB aligned"
else
echo "ERROR: $file is not 16 KB aligned"
exit 1
fi
done
- name: Upload Android artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn-mori-android-arm64-v8a
path: out/android/arm64-v8a/
release-android:
needs:
- build-android
runs-on: ubuntu-24.04
steps:
- name: Download Android artifact
uses: actions/download-artifact@v4
with:
name: nipovpn-mori-android-arm64-v8a
path: ./android-artifact
- name: Show downloaded Android artifact
run: |
ls -lah android-artifact
- name: Create Android GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: mori-android-v${{ env.PACKAGE_VERSION }}
name: Mori Android Binary v${{ env.PACKAGE_VERSION }}
prerelease: true
files: |
android-artifact/*
env:
GITHUB_TOKEN: ${{ github.token }}
+264 -40
View File
@@ -1,4 +1,4 @@
name: Build and Release Debian Package
name: Build and Release Package - dev
on:
push:
@@ -6,70 +6,294 @@ on:
- dev
paths:
- 'core/src/**'
- '.github/workflows/**'
- 'core/**'
- 'nipovpn/**'
- '.github/workflows/debian-dev.yml'
permissions:
contents: write
env:
PACKAGE_VERSION: 0.2.${{ github.run_number }}
jobs:
build:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
package_arch: amd64
- arch: arm64
package_arch: arm64
steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up dependencies
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Install host 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: |
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
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
rm -rf build
- name: Upload the Debian nipovpn as an artifact
if [ "${{ matrix.arch }}" = "arm64" ]; then
docker run --rm --platform linux/arm64 \
-v "$PWD:/src" \
-w /src \
ubuntu:24.04 \
bash -c '
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y \
build-essential \
cmake \
libssl-dev \
libboost-all-dev \
libyaml-cpp-dev
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)
'
sudo chown -R $USER:$USER build
else
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)
fi
- name: Build Debian package
run: |
PACKAGE_FILE="nipovpn_dev_${PACKAGE_VERSION}_${{ matrix.arch }}.deb"
rm -rf package-root
cp -a nipovpn package-root
mkdir -p package-root/usr/bin
cp build/core/nipovpn package-root/usr/bin/nipovpn
chmod 755 package-root/usr/bin/nipovpn
sed -i -E "s/^Version[[:space:]]*:.*/Version: ${PACKAGE_VERSION}/" package-root/DEBIAN/control
sed -i -E "s/^Architecture[[:space:]]*:.*/Architecture: ${{ matrix.package_arch }}/" package-root/DEBIAN/control
sed -i -e '$a\' package-root/DEBIAN/control
echo "Final control file:"
cat package-root/DEBIAN/control
grep "^Version: ${PACKAGE_VERSION}$" package-root/DEBIAN/control
grep "^Architecture: ${{ matrix.package_arch }}$" package-root/DEBIAN/control
mkdir -p build
dpkg-deb --build package-root "build/${PACKAGE_FILE}"
ls -lah build/
- name: Show Debian package information
run: |
PACKAGE_FILE="nipovpn_dev_${PACKAGE_VERSION}_${{ matrix.arch }}.deb"
dpkg -I "build/${PACKAGE_FILE}"
dpkg -c "build/${PACKAGE_FILE}"
- name: Upload Debian package artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn
path: build/nipovpn_staging_v1-1-${{ github.run_number }}.deb
name: nipovpn-dev-deb-${{ matrix.arch }}
path: build/nipovpn_dev_${{ env.PACKAGE_VERSION }}_${{ matrix.arch }}.deb
- name: Show nipovpn information
build-termux:
runs-on: ubuntu-24.04
steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
path: nipovpn-src
- name: Install host dependencies
run: |
dpkg -I build/nipovpn_staging_v1-1-${{ github.run_number }}.deb
sudo apt-get update
sudo apt-get install -y \
git \
wget \
unzip \
curl \
python3 \
python3-pip \
build-essential \
cmake \
ninja-build \
pkg-config \
autoconf \
automake \
libtool \
autopoint \
bison \
flex \
gettext \
gperf \
help2man \
lzip \
libarchive-tools \
rsync \
texinfo \
jq
- name: Install Android NDK r29
run: |
mkdir -p "$HOME/lib"
cd "$HOME/lib"
wget -q https://dl.google.com/android/repository/android-ndk-r29-linux.zip
unzip -q android-ndk-r29-linux.zip
EXTRACTED_DIR="$(find "$HOME/lib" -maxdepth 1 -type d -name 'android-ndk-r29*' | head -n 1)"
if [ -z "$EXTRACTED_DIR" ]; then
echo "Android NDK r29 directory not found"
ls -lah "$HOME/lib"
exit 1
fi
ln -sfn "$EXTRACTED_DIR" "$HOME/lib/android-ndk-r29"
echo "NDK=$HOME/lib/android-ndk-r29" >> "$GITHUB_ENV"
echo "ANDROID_NDK_ROOT=$HOME/lib/android-ndk-r29" >> "$GITHUB_ENV"
ls -ld "$HOME/lib/android-ndk-r29"
- name: Clone termux-packages
run: |
git clone --depth=1 https://github.com/termux/termux-packages.git
- name: Create Termux package recipe
run: |
mkdir -p termux-packages/packages/nipovpn
cat > termux-packages/packages/nipovpn/build.sh <<'EOF'
TERMUX_PKG_HOMEPAGE=https://github.com/MortezaBashsiz/nipovpn
TERMUX_PKG_DESCRIPTION="Powerful and secure HTTP/S proxy"
TERMUX_PKG_LICENSE="MIT"
TERMUX_PKG_MAINTAINER="Morteza Bashsiz"
TERMUX_PKG_VERSION=@PACKAGE_VERSION@
TERMUX_PKG_SRCURL=file://@GITHUB_WORKSPACE@/nipovpn-src
TERMUX_PKG_SHA256=SKIP_CHECKSUM
TERMUX_PKG_DEPENDS="openssl, boost, libyaml-cpp"
TERMUX_PKG_BUILD_IN_SRC=false
termux_step_configure() {
cmake -S "$TERMUX_PKG_SRCDIR" \
-B "$TERMUX_PKG_BUILDDIR" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$TERMUX_PREFIX"
}
termux_step_make() {
cmake --build "$TERMUX_PKG_BUILDDIR" -j "$(nproc)"
}
termux_step_make_install() {
install -Dm755 \
"$TERMUX_PKG_BUILDDIR/core/nipovpn" \
"$TERMUX_PREFIX/bin/nipovpn"
if [ -d "$TERMUX_PKG_SRCDIR/nipovpn/etc/nipovpn" ]; then
mkdir -p "$TERMUX_PREFIX/etc/nipovpn"
cp -a "$TERMUX_PKG_SRCDIR/nipovpn/etc/nipovpn/." \
"$TERMUX_PREFIX/etc/nipovpn/"
fi
}
EOF
sed -i "s|@PACKAGE_VERSION@|${PACKAGE_VERSION}|g" termux-packages/packages/nipovpn/build.sh
sed -i "s|@GITHUB_WORKSPACE@|${GITHUB_WORKSPACE}|g" termux-packages/packages/nipovpn/build.sh
cat termux-packages/packages/nipovpn/build.sh
- name: Prepare Termux build data dir
run: |
sudo mkdir -p /data
sudo chown -R $USER:$USER /data
- name: Build Termux aarch64 package
working-directory: termux-packages
run: |
./build-package.sh -I -a aarch64 nipovpn
- name: Collect Termux package
run: |
mkdir -p out
TERMUX_DEB="$(find termux-packages/output -type f -name '*.deb' | head -n 1)"
if [ -z "$TERMUX_DEB" ]; then
echo "No Termux .deb package found"
find termux-packages/output -type f || true
exit 1
fi
cp "$TERMUX_DEB" "out/nipovpn_dev_${PACKAGE_VERSION}_termux_aarch64.deb"
ls -lah out/
- name: Upload Termux package artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn-dev-termux-aarch64
path: out/nipovpn_dev_${{ env.PACKAGE_VERSION }}_termux_aarch64.deb
release:
needs: build
needs:
- build
- build-termux
runs-on: ubuntu-latest
steps:
- name: Download build artifact
- name: Download package artifacts
uses: actions/download-artifact@v4
with:
name: nipovpn
pattern: nipovpn-dev-*
merge-multiple: true
path: ./
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
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: Show downloaded files
run: |
ls -lah
- name: Upload Debian Package to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
- name: Create dev GitHub Release
uses: softprops/action-gh-release@v2
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
tag_name: dev-v${{ env.PACKAGE_VERSION }}
name: dev Version v${{ env.PACKAGE_VERSION }}
prerelease: true
files: |
nipovpn_dev_${{ env.PACKAGE_VERSION }}_amd64.deb
nipovpn_dev_${{ env.PACKAGE_VERSION }}_arm64.deb
nipovpn_dev_${{ env.PACKAGE_VERSION }}_termux_aarch64.deb
env:
GITHUB_TOKEN: ${{ github.token }}
+299
View File
@@ -0,0 +1,299 @@
name: Build and Release Package - Main
on:
push:
branches:
- main
paths:
- 'core/src/**'
- 'core/**'
- 'nipovpn/**'
- '.github/workflows/debian-main.yml'
permissions:
contents: write
env:
PACKAGE_VERSION: 1.1.54
jobs:
build:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
package_arch: amd64
- arch: arm64
package_arch: arm64
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Install host 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
- name: Build binary
run: |
rm -rf build
if [ "${{ matrix.arch }}" = "arm64" ]; then
docker run --rm --platform linux/arm64 \
-v "$PWD:/src" \
-w /src \
ubuntu:24.04 \
bash -c '
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y \
build-essential \
cmake \
libssl-dev \
libboost-all-dev \
libyaml-cpp-dev
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)
'
sudo chown -R $USER:$USER build
else
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)
fi
- name: Build Debian package
run: |
PACKAGE_FILE="nipovpn_${PACKAGE_VERSION}_${{ matrix.arch }}.deb"
rm -rf package-root
cp -a nipovpn package-root
mkdir -p package-root/usr/bin
cp build/core/nipovpn package-root/usr/bin/nipovpn
chmod 755 package-root/usr/bin/nipovpn
sed -i -E "s/^Version[[:space:]]*:.*/Version: ${PACKAGE_VERSION}/" package-root/DEBIAN/control
sed -i -E "s/^Architecture[[:space:]]*:.*/Architecture: ${{ matrix.package_arch }}/" package-root/DEBIAN/control
sed -i -e '$a\' package-root/DEBIAN/control
echo "Final control file:"
cat package-root/DEBIAN/control
grep "^Version: ${PACKAGE_VERSION}$" package-root/DEBIAN/control
grep "^Architecture: ${{ matrix.package_arch }}$" package-root/DEBIAN/control
mkdir -p build
dpkg-deb --build package-root "build/${PACKAGE_FILE}"
ls -lah build/
- name: Show Debian package information
run: |
PACKAGE_FILE="nipovpn_${PACKAGE_VERSION}_${{ matrix.arch }}.deb"
dpkg -I "build/${PACKAGE_FILE}"
dpkg -c "build/${PACKAGE_FILE}"
- name: Upload Debian package artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn-deb-${{ matrix.arch }}
path: build/nipovpn_${{ env.PACKAGE_VERSION }}_${{ matrix.arch }}.deb
build-termux:
runs-on: ubuntu-24.04
steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
path: nipovpn-src
- name: Install host dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
git \
wget \
unzip \
curl \
python3 \
python3-pip \
build-essential \
cmake \
ninja-build \
pkg-config \
autoconf \
automake \
libtool \
autopoint \
bison \
flex \
gettext \
gperf \
help2man \
lzip \
libarchive-tools \
rsync \
texinfo \
jq
- name: Install Android NDK r29
run: |
mkdir -p "$HOME/lib"
cd "$HOME/lib"
wget -q https://dl.google.com/android/repository/android-ndk-r29-linux.zip
unzip -q android-ndk-r29-linux.zip
EXTRACTED_DIR="$(find "$HOME/lib" -maxdepth 1 -type d -name 'android-ndk-r29*' | head -n 1)"
if [ -z "$EXTRACTED_DIR" ]; then
echo "Android NDK r29 directory not found"
ls -lah "$HOME/lib"
exit 1
fi
ln -sfn "$EXTRACTED_DIR" "$HOME/lib/android-ndk-r29"
echo "NDK=$HOME/lib/android-ndk-r29" >> "$GITHUB_ENV"
echo "ANDROID_NDK_ROOT=$HOME/lib/android-ndk-r29" >> "$GITHUB_ENV"
ls -ld "$HOME/lib/android-ndk-r29"
- name: Clone termux-packages
run: |
git clone --depth=1 https://github.com/termux/termux-packages.git
- name: Create Termux package recipe
run: |
mkdir -p termux-packages/packages/nipovpn
cat > termux-packages/packages/nipovpn/build.sh <<'EOF'
TERMUX_PKG_HOMEPAGE=https://github.com/MortezaBashsiz/nipovpn
TERMUX_PKG_DESCRIPTION="Powerful and secure HTTP/S proxy"
TERMUX_PKG_LICENSE="MIT"
TERMUX_PKG_MAINTAINER="Morteza Bashsiz"
TERMUX_PKG_VERSION=@PACKAGE_VERSION@
TERMUX_PKG_SRCURL=file://@GITHUB_WORKSPACE@/nipovpn-src
TERMUX_PKG_SHA256=SKIP_CHECKSUM
TERMUX_PKG_DEPENDS="openssl, boost, libyaml-cpp"
TERMUX_PKG_BUILD_IN_SRC=false
termux_step_configure() {
cmake -S "$TERMUX_PKG_SRCDIR" \
-B "$TERMUX_PKG_BUILDDIR" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$TERMUX_PREFIX"
}
termux_step_make() {
cmake --build "$TERMUX_PKG_BUILDDIR" -j "$(nproc)"
}
termux_step_make_install() {
install -Dm755 \
"$TERMUX_PKG_BUILDDIR/core/nipovpn" \
"$TERMUX_PREFIX/bin/nipovpn"
if [ -d "$TERMUX_PKG_SRCDIR/nipovpn/etc/nipovpn" ]; then
mkdir -p "$TERMUX_PREFIX/etc/nipovpn"
cp -a "$TERMUX_PKG_SRCDIR/nipovpn/etc/nipovpn/." \
"$TERMUX_PREFIX/etc/nipovpn/"
fi
}
EOF
sed -i "s|@PACKAGE_VERSION@|${PACKAGE_VERSION}|g" termux-packages/packages/nipovpn/build.sh
sed -i "s|@GITHUB_WORKSPACE@|${GITHUB_WORKSPACE}|g" termux-packages/packages/nipovpn/build.sh
cat termux-packages/packages/nipovpn/build.sh
- name: Prepare Termux build data dir
run: |
sudo mkdir -p /data
sudo chown -R $USER:$USER /data
- name: Build Termux aarch64 package
working-directory: termux-packages
run: |
./build-package.sh -I -a aarch64 nipovpn
- name: Collect Termux package
run: |
mkdir -p out
TERMUX_DEB="$(find termux-packages/output -type f -name '*.deb' | head -n 1)"
if [ -z "$TERMUX_DEB" ]; then
echo "No Termux .deb package found"
find termux-packages/output -type f || true
exit 1
fi
cp "$TERMUX_DEB" "out/nipovpn_${PACKAGE_VERSION}_termux_aarch64.deb"
ls -lah out/
- name: Upload Termux package artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn-termux-aarch64
path: out/nipovpn_${{ env.PACKAGE_VERSION }}_termux_aarch64.deb
release:
needs:
- build
- build-termux
runs-on: ubuntu-latest
steps:
- name: Download package artifacts
uses: actions/download-artifact@v4
with:
pattern: nipovpn-*
merge-multiple: true
path: ./
- name: Show downloaded files
run: |
ls -lah
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ env.PACKAGE_VERSION }}
name: Version v${{ env.PACKAGE_VERSION }}
prerelease: true
files: |
nipovpn_${{ env.PACKAGE_VERSION }}_amd64.deb
nipovpn_${{ env.PACKAGE_VERSION }}_arm64.deb
nipovpn_${{ env.PACKAGE_VERSION }}_termux_aarch64.deb
env:
GITHUB_TOKEN: ${{ github.token }}
+264 -40
View File
@@ -1,4 +1,4 @@
name: Build and Release Debian Package
name: Build and Release Package - MORI
on:
push:
@@ -6,70 +6,294 @@ on:
- mori
paths:
- 'core/src/**'
- '.github/workflows/**'
- 'core/**'
- 'nipovpn/**'
- '.github/workflows/debian-mori.yml'
permissions:
contents: write
env:
PACKAGE_VERSION: 0.1.${{ github.run_number }}
jobs:
build:
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
package_arch: amd64
- arch: arm64
package_arch: arm64
steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up dependencies
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Install host 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: |
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
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
rm -rf build
- name: Upload the Debian nipovpn as an artifact
if [ "${{ matrix.arch }}" = "arm64" ]; then
docker run --rm --platform linux/arm64 \
-v "$PWD:/src" \
-w /src \
ubuntu:24.04 \
bash -c '
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y \
build-essential \
cmake \
libssl-dev \
libboost-all-dev \
libyaml-cpp-dev
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)
'
sudo chown -R $USER:$USER build
else
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)
fi
- name: Build Debian package
run: |
PACKAGE_FILE="nipovpn_mori_${PACKAGE_VERSION}_${{ matrix.arch }}.deb"
rm -rf package-root
cp -a nipovpn package-root
mkdir -p package-root/usr/bin
cp build/core/nipovpn package-root/usr/bin/nipovpn
chmod 755 package-root/usr/bin/nipovpn
sed -i -E "s/^Version[[:space:]]*:.*/Version: ${PACKAGE_VERSION}/" package-root/DEBIAN/control
sed -i -E "s/^Architecture[[:space:]]*:.*/Architecture: ${{ matrix.package_arch }}/" package-root/DEBIAN/control
sed -i -e '$a\' package-root/DEBIAN/control
echo "Final control file:"
cat package-root/DEBIAN/control
grep "^Version: ${PACKAGE_VERSION}$" package-root/DEBIAN/control
grep "^Architecture: ${{ matrix.package_arch }}$" package-root/DEBIAN/control
mkdir -p build
dpkg-deb --build package-root "build/${PACKAGE_FILE}"
ls -lah build/
- name: Show Debian package information
run: |
PACKAGE_FILE="nipovpn_mori_${PACKAGE_VERSION}_${{ matrix.arch }}.deb"
dpkg -I "build/${PACKAGE_FILE}"
dpkg -c "build/${PACKAGE_FILE}"
- name: Upload Debian package artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn
path: build/nipovpn_mori_v1-1-${{ github.run_number }}.deb
name: nipovpn-mori-deb-${{ matrix.arch }}
path: build/nipovpn_mori_${{ env.PACKAGE_VERSION }}_${{ matrix.arch }}.deb
- name: Show nipovpn information
build-termux:
runs-on: ubuntu-24.04
steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
path: nipovpn-src
- name: Install host dependencies
run: |
dpkg -I build/nipovpn_mori_v1-1-${{ github.run_number }}.deb
sudo apt-get update
sudo apt-get install -y \
git \
wget \
unzip \
curl \
python3 \
python3-pip \
build-essential \
cmake \
ninja-build \
pkg-config \
autoconf \
automake \
libtool \
autopoint \
bison \
flex \
gettext \
gperf \
help2man \
lzip \
libarchive-tools \
rsync \
texinfo \
jq
- name: Install Android NDK r29
run: |
mkdir -p "$HOME/lib"
cd "$HOME/lib"
wget -q https://dl.google.com/android/repository/android-ndk-r29-linux.zip
unzip -q android-ndk-r29-linux.zip
EXTRACTED_DIR="$(find "$HOME/lib" -maxdepth 1 -type d -name 'android-ndk-r29*' | head -n 1)"
if [ -z "$EXTRACTED_DIR" ]; then
echo "Android NDK r29 directory not found"
ls -lah "$HOME/lib"
exit 1
fi
ln -sfn "$EXTRACTED_DIR" "$HOME/lib/android-ndk-r29"
echo "NDK=$HOME/lib/android-ndk-r29" >> "$GITHUB_ENV"
echo "ANDROID_NDK_ROOT=$HOME/lib/android-ndk-r29" >> "$GITHUB_ENV"
ls -ld "$HOME/lib/android-ndk-r29"
- name: Clone termux-packages
run: |
git clone --depth=1 https://github.com/termux/termux-packages.git
- name: Create Termux package recipe
run: |
mkdir -p termux-packages/packages/nipovpn
cat > termux-packages/packages/nipovpn/build.sh <<'EOF'
TERMUX_PKG_HOMEPAGE=https://github.com/MortezaBashsiz/nipovpn
TERMUX_PKG_DESCRIPTION="Powerful and secure HTTP/S proxy"
TERMUX_PKG_LICENSE="MIT"
TERMUX_PKG_MAINTAINER="Morteza Bashsiz"
TERMUX_PKG_VERSION=@PACKAGE_VERSION@
TERMUX_PKG_SRCURL=file://@GITHUB_WORKSPACE@/nipovpn-src
TERMUX_PKG_SHA256=SKIP_CHECKSUM
TERMUX_PKG_DEPENDS="openssl, boost, libyaml-cpp"
TERMUX_PKG_BUILD_IN_SRC=false
termux_step_configure() {
cmake -S "$TERMUX_PKG_SRCDIR" \
-B "$TERMUX_PKG_BUILDDIR" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$TERMUX_PREFIX"
}
termux_step_make() {
cmake --build "$TERMUX_PKG_BUILDDIR" -j "$(nproc)"
}
termux_step_make_install() {
install -Dm755 \
"$TERMUX_PKG_BUILDDIR/core/nipovpn" \
"$TERMUX_PREFIX/bin/nipovpn"
if [ -d "$TERMUX_PKG_SRCDIR/nipovpn/etc/nipovpn" ]; then
mkdir -p "$TERMUX_PREFIX/etc/nipovpn"
cp -a "$TERMUX_PKG_SRCDIR/nipovpn/etc/nipovpn/." \
"$TERMUX_PREFIX/etc/nipovpn/"
fi
}
EOF
sed -i "s|@PACKAGE_VERSION@|${PACKAGE_VERSION}|g" termux-packages/packages/nipovpn/build.sh
sed -i "s|@GITHUB_WORKSPACE@|${GITHUB_WORKSPACE}|g" termux-packages/packages/nipovpn/build.sh
cat termux-packages/packages/nipovpn/build.sh
- name: Prepare Termux build data dir
run: |
sudo mkdir -p /data
sudo chown -R $USER:$USER /data
- name: Build Termux aarch64 package
working-directory: termux-packages
run: |
./build-package.sh -I -a aarch64 nipovpn
- name: Collect Termux package
run: |
mkdir -p out
TERMUX_DEB="$(find termux-packages/output -type f -name '*.deb' | head -n 1)"
if [ -z "$TERMUX_DEB" ]; then
echo "No Termux .deb package found"
find termux-packages/output -type f || true
exit 1
fi
cp "$TERMUX_DEB" "out/nipovpn_mori_${PACKAGE_VERSION}_termux_aarch64.deb"
ls -lah out/
- name: Upload Termux package artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn-mori-termux-aarch64
path: out/nipovpn_mori_${{ env.PACKAGE_VERSION }}_termux_aarch64.deb
release:
needs: build
needs:
- build
- build-termux
runs-on: ubuntu-latest
steps:
- name: Download build artifact
- name: Download package artifacts
uses: actions/download-artifact@v4
with:
name: nipovpn
pattern: nipovpn-mori-*
merge-multiple: true
path: ./
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
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: Show downloaded files
run: |
ls -lah
- name: Upload Debian Package to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
- name: Create Mori GitHub Release
uses: softprops/action-gh-release@v2
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
tag_name: mori-v${{ env.PACKAGE_VERSION }}
name: Mori Version v${{ env.PACKAGE_VERSION }}
prerelease: true
files: |
nipovpn_mori_${{ env.PACKAGE_VERSION }}_amd64.deb
nipovpn_mori_${{ env.PACKAGE_VERSION }}_arm64.deb
nipovpn_mori_${{ env.PACKAGE_VERSION }}_termux_aarch64.deb
env:
GITHUB_TOKEN: ${{ github.token }}
-75
View File
@@ -1,75 +0,0 @@
name: Build and Release Debian Package
on:
push:
branches:
- main
paths:
- 'core/src/**'
jobs:
build:
runs-on: ubuntu-24.04
steps:
- name: Checkout source code
uses: actions/checkout@v3
- 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
- name: Build the package
run: |
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
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
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
release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: nipovpn
path: ./
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
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
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
+98
View File
@@ -0,0 +1,98 @@
name: Build Windows Binary - dev
on:
push:
branches:
- dev
paths:
- 'core/**'
- 'server/**'
- 'agent/**'
- 'CMakeLists.txt'
- '.github/workflows/windows-dev.yml'
permissions:
contents: write
env:
PACKAGE_VERSION: 0.2.${{ github.run_number }}
jobs:
build-windows:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: >-
git
zip
mingw-w64-x86_64-gcc
mingw-w64-x86_64-cmake
mingw-w64-x86_64-ninja
mingw-w64-x86_64-boost
mingw-w64-x86_64-openssl
mingw-w64-x86_64-yaml-cpp
- name: Build nipovpn.exe
run: |
rm -rf build dist
mkdir -p build dist
cmake -S . -B build \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="-DNOMINMAX -DWIN32_LEAN_AND_MEAN -DNOGDI -DOUT=NIPO_OUT"
cmake --build build -j$(nproc)
cp build/core/nipovpn.exe dist/
- name: Copy required DLL files
run: |
cd dist
for dll in $(ldd nipovpn.exe | grep 'mingw64' | awk '{print $3}'); do
cp "$dll" .
done
ls -lah
- name: Add config files
run: |
mkdir -p dist/etc/nipovpn
if [ -d nipovpn/etc/nipovpn ]; then
cp -a nipovpn/etc/nipovpn/. dist/etc/nipovpn/
fi
- name: Create ZIP package
run: |
cd dist
zip -r ../nipovpn_dev_${PACKAGE_VERSION}_windows_x86_64.zip .
- name: Upload Windows artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn-dev-windows-x86_64
path: nipovpn_dev_${{ env.PACKAGE_VERSION }}_windows_x86_64.zip
- name: Create dev Windows Release
uses: softprops/action-gh-release@v2
with:
tag_name: dev-windows-v${{ env.PACKAGE_VERSION }}
name: dev Windows Binary v${{ env.PACKAGE_VERSION }}
prerelease: true
files: nipovpn_dev_${{ env.PACKAGE_VERSION }}_windows_x86_64.zip
env:
GITHUB_TOKEN: ${{ github.token }}
+98
View File
@@ -0,0 +1,98 @@
name: Build Windows Binary - main
on:
push:
branches:
- main
paths:
- 'core/**'
- 'server/**'
- 'agent/**'
- 'CMakeLists.txt'
- '.github/workflows/windows-main.yml'
permissions:
contents: write
env:
PACKAGE_VERSION: 1.1.54
jobs:
build-windows:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: >-
git
zip
mingw-w64-x86_64-gcc
mingw-w64-x86_64-cmake
mingw-w64-x86_64-ninja
mingw-w64-x86_64-boost
mingw-w64-x86_64-openssl
mingw-w64-x86_64-yaml-cpp
- name: Build nipovpn.exe
run: |
rm -rf build dist
mkdir -p build dist
cmake -S . -B build \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="-DNOMINMAX -DWIN32_LEAN_AND_MEAN -DNOGDI -DOUT=NIPO_OUT"
cmake --build build -j$(nproc)
cp build/core/nipovpn.exe dist/
- name: Copy required DLL files
run: |
cd dist
for dll in $(ldd nipovpn.exe | grep 'mingw64' | awk '{print $3}'); do
cp "$dll" .
done
ls -lah
- name: Add config files
run: |
mkdir -p dist/etc/nipovpn
if [ -d nipovpn/etc/nipovpn ]; then
cp -a nipovpn/etc/nipovpn/. dist/etc/nipovpn/
fi
- name: Create ZIP package
run: |
cd dist
zip -r ../nipovpn_${PACKAGE_VERSION}_windows_x86_64.zip .
- name: Upload Windows artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn-windows-x86_64
path: nipovpn_${{ env.PACKAGE_VERSION }}_windows_x86_64.zip
- name: Create Windows Release
uses: softprops/action-gh-release@v2
with:
tag_name: windows-v${{ env.PACKAGE_VERSION }}
name: Windows Binary v${{ env.PACKAGE_VERSION }}
prerelease: true
files: nipovpn_${{ env.PACKAGE_VERSION }}_windows_x86_64.zip
env:
GITHUB_TOKEN: ${{ github.token }}
+98
View File
@@ -0,0 +1,98 @@
name: Build Windows Binary - mori
on:
push:
branches:
- mori
paths:
- 'core/**'
- 'server/**'
- 'agent/**'
- 'CMakeLists.txt'
- '.github/workflows/windows-mori.yml'
permissions:
contents: write
env:
PACKAGE_VERSION: 0.1.${{ github.run_number }}
jobs:
build-windows:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: >-
git
zip
mingw-w64-x86_64-gcc
mingw-w64-x86_64-cmake
mingw-w64-x86_64-ninja
mingw-w64-x86_64-boost
mingw-w64-x86_64-openssl
mingw-w64-x86_64-yaml-cpp
- name: Build nipovpn.exe
run: |
rm -rf build dist
mkdir -p build dist
cmake -S . -B build \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="-DNOMINMAX -DWIN32_LEAN_AND_MEAN -DNOGDI -DOUT=NIPO_OUT"
cmake --build build -j$(nproc)
cp build/core/nipovpn.exe dist/
- name: Copy required DLL files
run: |
cd dist
for dll in $(ldd nipovpn.exe | grep 'mingw64' | awk '{print $3}'); do
cp "$dll" .
done
ls -lah
- name: Add config files
run: |
mkdir -p dist/etc/nipovpn
if [ -d nipovpn/etc/nipovpn ]; then
cp -a nipovpn/etc/nipovpn/. dist/etc/nipovpn/
fi
- name: Create ZIP package
run: |
cd dist
zip -r ../nipovpn_mori_${PACKAGE_VERSION}_windows_x86_64.zip .
- name: Upload Windows artifact
uses: actions/upload-artifact@v4
with:
name: nipovpn-mori-windows-x86_64
path: nipovpn_mori_${{ env.PACKAGE_VERSION }}_windows_x86_64.zip
- name: Create Mori Windows Release
uses: softprops/action-gh-release@v2
with:
tag_name: mori-windows-v${{ env.PACKAGE_VERSION }}
name: Mori Windows Binary v${{ env.PACKAGE_VERSION }}
prerelease: true
files: nipovpn_mori_${{ env.PACKAGE_VERSION }}_windows_x86_64.zip
env:
GITHUB_TOKEN: ${{ github.token }}
+4
View File
@@ -10,6 +10,10 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -ggdb")
# Set the preprocessor flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -MMD -MP")
if(POLICY CMP0167)
cmake_policy(SET CMP0167 NEW)
endif()
# https://cmake.org/cmake/help/latest/module/FindBoost.html
find_package(Boost REQUIRED COMPONENTS regex OPTIONAL_COMPONENTS system)
+3
View File
@@ -36,6 +36,9 @@ To contribute take a look at [contribution page](https://github.com/MortezaBashs
Build from source for [Linux](guides/BuildLinux.md)
## Termux
Build from source for [Linux](guides/InstallTermux.md)
## Run
+4
View File
@@ -38,3 +38,7 @@ target_include_directories(${CORE_TARGET} PUBLIC ${OPENSSL_INCLUDE_DIR})
target_link_libraries(${CORE_TARGET} ${Boost_LIBRARIES})
target_link_libraries(${CORE_TARGET} ${YAML_CPP_LIBRARIES})
target_link_libraries(${CORE_TARGET} ${OPENSSL_LIBRARIES})
if(WIN32)
target_link_libraries(${CORE_TARGET} ws2_32 mswsock)
endif()
+18 -11
View File
@@ -1,21 +1,22 @@
#include "agenthandler.hpp"
#include <sstream>
#include <utility>
AgentHandler::AgentHandler(boost::asio::streambuf &readBuffer,
boost::asio::streambuf &writeBuffer,
const std::shared_ptr<Config> &config,
const std::shared_ptr<Log> &log,
const TCPClient::pointer &client,
const std::string &clientConnStr,
TCPClient::pointer client,
std::string clientConnStr,
boost::uuids::uuid uuid)
: config_(config),
log_(log),
client_(client),
client_(std::move(client)),
readBuffer_(readBuffer),
writeBuffer_(writeBuffer),
request_(HTTP::create(config, log, readBuffer, uuid)),
clientConnStr_(clientConnStr),
clientConnStr_(std::move(clientConnStr)),
uuid_(uuid) {
end_ = false;
connect_ = false;
@@ -40,7 +41,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 +87,21 @@ void AgentHandler::handle() {
request_->httpType() == HTTP::HttpType::connect ? "open" : "request";
std::ostringstream outer;
outer << config_->randomMethod() + " /" + config_->randomEndPoint() + " 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 +110,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;
}
@@ -143,7 +150,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('/');
+9 -11
View File
@@ -18,8 +18,8 @@ public:
boost::asio::streambuf &writeBuffer,
const std::shared_ptr<Config> &config,
const std::shared_ptr<Log> &log,
const TCPClient::pointer &client,
const std::string &clientConnStr,
TCPClient::pointer client,
std::string clientConnStr,
boost::uuids::uuid uuid) {
return pointer(new AgentHandler(readBuffer, writeBuffer, config, log,
client, clientConnStr, uuid));
@@ -29,9 +29,7 @@ public:
void handle();
inline const HTTP::pointer &request() & { return request_; }
inline const HTTP::pointer &&request() && { return std::move(request_); }
inline const HTTP::pointer &request() const { return request_; }
bool end_;
bool connect_;
@@ -41,18 +39,18 @@ private:
boost::asio::streambuf &writeBuffer,
const std::shared_ptr<Config> &config,
const std::shared_ptr<Log> &log,
const TCPClient::pointer &client,
const std::string &clientConnStr,
TCPClient::pointer client,
std::string clientConnStr,
boost::uuids::uuid uuid);
std::string relayHostHeader(const std::shared_ptr<Config> &config);
const std::shared_ptr<Config> &config_;
const std::shared_ptr<Log> &log_;
const TCPClient::pointer &client_;
std::shared_ptr<Config> config_;
std::shared_ptr<Log> log_;
TCPClient::pointer client_;
boost::asio::streambuf &readBuffer_;
boost::asio::streambuf &writeBuffer_;
HTTP::pointer request_;
const std::string &clientConnStr_;
std::string clientConnStr_;
boost::uuids::uuid uuid_;
+54 -28
View File
@@ -1,7 +1,7 @@
#include "config.hpp"
Config::Config(const RunMode &mode, const std::string &filePath)
Config::Config(RunMode mode, const std::string &filePath)
: runMode_(mode),
filePath_(filePath),
configYaml_(YAML::LoadFile(filePath)),
@@ -9,31 +9,31 @@ 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"]["protocol"].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"]["pullTimeout"].as<unsigned short>(),
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_);
@@ -74,7 +74,18 @@ std::string Config::toString() const {
ss << "\nConfig :\n"
<< " General :\n"
<< " token: " << general_.token << "\n"
<< " fakeUrl: " << general_.fakeUrl << "\n"
<< " protocol: " << general_.protocol << "\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) {
@@ -98,7 +109,14 @@ std::string Config::toString() const {
ss << "\n"
<< " timeout: " << general_.timeout << "\n"
<< " pullTimeout: " << general_.pullTimeout << "\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"
@@ -108,11 +126,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"
@@ -121,10 +134,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();
}
@@ -149,7 +159,7 @@ const Config::Agent &Config::agent() const {
return agent_;
}
const unsigned short &Config::threads() const {
unsigned short Config::threads() const {
std::lock_guard<std::mutex> lock(configMutex_);
return threads_;
}
@@ -169,7 +179,7 @@ void Config::listenIp(const std::string &ip) {
listenIp_ = ip;
}
const unsigned short &Config::listenPort() const {
unsigned short Config::listenPort() const {
std::lock_guard<std::mutex> lock(configMutex_);
return listenPort_;
}
@@ -179,7 +189,7 @@ void Config::listenPort(unsigned short port) {
listenPort_ = port;
}
const RunMode &Config::runMode() const {
RunMode Config::runMode() const {
std::lock_guard<std::mutex> lock(configMutex_);
return runMode_;
}
@@ -202,11 +212,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{}()};
@@ -222,7 +248,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{}()};
+18 -18
View File
@@ -20,11 +20,19 @@ class Config : private Uncopyable {
private:
struct General {
std::string token;
std::string fakeUrl;
std::string protocol;
std::vector<std::string> fakeUrls;
std::vector<std::string> methods;
std::vector<std::string> endPoints;
unsigned short timeout;
unsigned short pullTimeout;
bool tunnelEnable;
bool connectionReuse;
bool tlsEnable;
bool tlsVerifyPeer;
std::string tlsCertFile;
std::string tlsKeyFile;
std::string tlsCaFile;
};
struct Log {
@@ -36,12 +44,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 {
@@ -52,15 +54,11 @@ private:
unsigned short serverPort;
std::string httpVersion;
std::string userAgent;
bool tlsEnable;
bool tlsVerifyPeer;
std::string tlsCaFile;
};
const RunMode &runMode_;
RunMode runMode_;
std::string filePath_;
const YAML::Node configYaml_;
YAML::Node configYaml_;
unsigned short threads_;
std::string listenIp_;
@@ -68,12 +66,12 @@ private:
mutable std::mutex configMutex_;
explicit Config(const RunMode &mode, const std::string &filePath);
explicit Config(RunMode mode, const std::string &filePath);
public:
using pointer = std::shared_ptr<Config>;
static pointer create(const RunMode &mode, const std::string &filePath) {
static pointer create(RunMode mode, const std::string &filePath) {
return pointer(new Config(mode, filePath));
}
@@ -91,7 +89,7 @@ public:
const Server &server() const;
const Agent &agent() const;
const unsigned short &threads() const;
unsigned short threads() const;
void threads(unsigned short threads);
@@ -99,11 +97,11 @@ public:
void listenIp(const std::string &ip);
const unsigned short &listenPort() const;
unsigned short listenPort() const;
void listenPort(unsigned short port);
const RunMode &runMode() const;
RunMode runMode() const;
const std::string &filePath() const;
@@ -111,6 +109,8 @@ public:
std::string toString() const;
std::string randomFakeUrl() const;
std::string randomMethod() const;
std::string randomEndPoint() const;
+22 -20
View File
@@ -19,10 +19,13 @@
#include <fstream>
#include <iomanip>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
static constexpr std::size_t BufferSize = 8192;
class Uncopyable {
public:
Uncopyable() = default;
@@ -86,7 +89,7 @@ inline std::string hexArrToStr(const unsigned char *data, std::size_t size) {
}
inline unsigned int hexToInt(const std::string &hexString) {
unsigned short result;
unsigned int result{};
std::stringstream hexStr(hexString);
hexStr >> std::hex >> result;
return result;
@@ -195,40 +198,36 @@ inline BoolStr aes256Encrypt(const std::string &plaintext,
plaintext.size() + EVP_CIPHER_block_size(EVP_aes_256_cbc());
std::vector<unsigned char> ciphertext(ciphertext_len);
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
using EvpCipherCtxPtr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
EvpCipherCtxPtr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
if (!ctx) {
result.message = "Context initialization failed";
return result;
}
if (EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL,
if (EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_cbc(), NULL,
reinterpret_cast<const unsigned char *>(key.c_str()),
iv) != 1) {
EVP_CIPHER_CTX_free(ctx);
result.message = "Encryption initialization failed";
return result;
}
int len;
if (EVP_EncryptUpdate(
ctx, ciphertext.data(), &len,
ctx.get(), ciphertext.data(), &len,
reinterpret_cast<const unsigned char *>(plaintext.c_str()),
plaintext.size()) != 1) {
EVP_CIPHER_CTX_free(ctx);
result.message = "Encryption update failed";
return result;
}
ciphertext_len = len;
if (EVP_EncryptFinal_ex(ctx, ciphertext.data() + len, &len) != 1) {
EVP_CIPHER_CTX_free(ctx);
if (EVP_EncryptFinal_ex(ctx.get(), ciphertext.data() + len, &len) != 1) {
result.message = "Encryption finalization failed";
return result;
}
ciphertext_len += len;
EVP_CIPHER_CTX_free(ctx);
std::string final_result(reinterpret_cast<char *>(iv), sizeof(iv));
final_result.append(reinterpret_cast<char *>(ciphertext.data()),
ciphertext_len);
@@ -252,40 +251,36 @@ inline BoolStr aes256Decrypt(const std::string &ciphertext_with_iv,
int max_plaintext_len = ciphertext.size();
std::vector<unsigned char> plaintext(max_plaintext_len);
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
using EvpCipherCtxPtr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
EvpCipherCtxPtr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
if (!ctx) {
result.message = "Context initialization failed";
return result;
}
if (EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL,
if (EVP_DecryptInit_ex(ctx.get(), EVP_aes_256_cbc(), NULL,
reinterpret_cast<const unsigned char *>(key.c_str()),
iv) != 1) {
EVP_CIPHER_CTX_free(ctx);
result.message = "Decryption initialization failed";
return result;
}
int len;
if (EVP_DecryptUpdate(
ctx, plaintext.data(), &len,
ctx.get(), plaintext.data(), &len,
reinterpret_cast<const unsigned char *>(ciphertext.c_str()),
ciphertext.size()) != 1) {
EVP_CIPHER_CTX_free(ctx);
result.message = "Decryption update failed";
return result;
}
int plaintext_len = len;
if (EVP_DecryptFinal_ex(ctx, plaintext.data() + len, &len) != 1) {
EVP_CIPHER_CTX_free(ctx);
if (EVP_DecryptFinal_ex(ctx.get(), plaintext.data() + len, &len) != 1) {
result.message = "Decryption finalization failed";
return result;
}
plaintext_len += len;
EVP_CIPHER_CTX_free(ctx);
result.ok = true;
result.message =
std::string(reinterpret_cast<char *>(plaintext.data()), plaintext_len);
@@ -325,10 +320,12 @@ inline BoolStr validateConfig(int argc, const char *argv[]) {
try {
configYaml["general"]["token"].as<std::string>();
configYaml["general"]["fakeUrl"].as<std::string>();
configYaml["general"]["protocol"].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"]["pullTimeout"].as<unsigned short>();
configYaml["general"]["tunnelEnable"].as<bool>();
} catch (const std::exception &e) {
result.message = std::string("Error in 'general' block: ") + e.what() + "\n";
@@ -363,6 +360,11 @@ inline BoolStr validateConfig(int argc, const char *argv[]) {
return result;
}
if (configYaml["general"]["protocol"].as<std::string>() != "http" && configYaml["general"]["protocol"].as<std::string>() != "socks5") {
result.message = "First argument must be one of [http|socks5]\n";
return result;
}
result.ok = true;
result.message = "OK";
return result;
+19 -17
View File
@@ -155,28 +155,30 @@ bool HTTP::parseTls() {
return false;
}
const std::string HTTP::genHttpPostReqString(const std::string &body) 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" +
"Content-Type: application/x-www-form-urlencoded\r\n" + "\r\n" + body + "COMP\r\n\r\n";
}
const std::string HTTP::genHttpRestPostReqString() 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";
}
const std::string HTTP::genHttpOkResString(const std::string &body) const {
std::string HTTP::genHttpOkResString(const std::string &body) const {
return std::string("HTTP/1.1 200 OK\r\n") +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"Content-Length: " + std::to_string(body.length()) + "\r\n" +
@@ -194,14 +196,14 @@ void HTTP::setIPPort() {
splitted = splitString(target, ":");
if (!splitted.empty()) {
dstIP_ = splitted[0];
dstIp_ = splitted[0];
if (splitted.size() > 1 && !splitted[1].empty()) {
dstPort_ = std::stoi(splitted[1]);
} else {
dstPort_ = 443;
}
} else {
dstIP_.clear();
dstIp_.clear();
dstPort_ = 443;
}
break;
@@ -232,7 +234,7 @@ void HTTP::setIPPort() {
log_->write("[" + to_string(uuid_) +
"] [HTTP setIPPort] missing Host header",
Log::Level::DEBUG);
dstIP_.clear();
dstIp_.clear();
dstPort_ = 80;
break;
}
@@ -240,7 +242,7 @@ void HTTP::setIPPort() {
splitted = splitString(hostPort, ":");
if (!splitted.empty()) {
dstIP_ = splitted[0];
dstIp_ = splitted[0];
if (splitted.size() > 1 && !splitted[1].empty()) {
dstPort_ = std::stoi(splitted[1]);
} else {
@@ -250,7 +252,7 @@ void HTTP::setIPPort() {
log_->write("[" + to_string(uuid_) +
"] [HTTP setIPPort] wrong request",
Log::Level::DEBUG);
dstIP_.clear();
dstIp_.clear();
dstPort_ = 80;
}
break;
@@ -261,14 +263,14 @@ void HTTP::setIPPort() {
splitted = splitString(target, ":");
if (!splitted.empty()) {
dstIP_ = splitted[0];
dstIp_ = splitted[0];
if (splitted.size() > 1 && !splitted[1].empty()) {
dstPort_ = std::stoi(splitted[1]);
} else {
dstPort_ = 443;
}
} else {
dstIP_.clear();
dstIp_.clear();
dstPort_ = 443;
}
break;
@@ -276,7 +278,7 @@ void HTTP::setIPPort() {
}
}
const std::string HTTP::tlsTypeToString() const {
std::string HTTP::tlsTypeToString() const {
switch (parsedTlsRequest_.type) {
case TlsTypes::TLSHandshake:
return "TLSHandshake";
@@ -289,7 +291,7 @@ const std::string HTTP::tlsTypeToString() const {
}
}
const std::string HTTP::toString() const {
std::string HTTP::toString() const {
switch (httpType()) {
case HTTP::HttpType::https:
return std::string("\n") + "TLS Type : " + tlsTypeToString() + "\n" +
@@ -325,7 +327,7 @@ const std::string HTTP::toString() const {
}
}
const std::string HTTP::restoString() const {
std::string HTTP::restoString() const {
return std::string("\n") +
boost::lexical_cast<std::string>(parsedHttpResponse_.base()) + "\n" +
"Body Size : " +
+12 -12
View File
@@ -43,7 +43,7 @@ public:
~HTTP();
inline const HTTP::HttpType &httpType() const { return httpType_; }
inline HTTP::HttpType httpType() const { return httpType_; }
inline void httpType(const HTTP::HttpType &httpType) { httpType_ = httpType; }
@@ -55,11 +55,11 @@ public:
bool parseTls();
const std::string genHttpPostReqString(const std::string &body) const;
std::string genHttpPostReqString(const std::string &body) const;
const std::string genHttpRestPostReqString() const;
std::string genHttpRestPostReqString() const;
const std::string genHttpOkResString(const std::string &body) const;
std::string genHttpOkResString(const std::string &body) const;
inline const boost::beast::http::request<boost::beast::http::string_body> &
parsedHttpRequest() & {
@@ -73,15 +73,15 @@ public:
inline const TlsRequest &parsedTlsRequest() & { return parsedTlsRequest_; }
const std::string tlsTypeToString() const;
std::string tlsTypeToString() const;
inline const std::string &dstIP() { return dstIP_; }
inline const std::string &dstIp() const { return dstIp_; }
inline const unsigned short &dstPort() { return dstPort_; }
inline unsigned short dstPort() const { return dstPort_; }
const std::string toString() const;
std::string toString() const;
const std::string restoString() const;
std::string restoString() const;
private:
explicit HTTP(const std::shared_ptr<Config> &config,
@@ -91,8 +91,8 @@ private:
void setIPPort();
const std::shared_ptr<Config> &config_;
const std::shared_ptr<Log> &log_;
std::shared_ptr<Config> config_;
std::shared_ptr<Log> log_;
boost::asio::streambuf &buffer_;
boost::beast::http::parser<false, boost::beast::http::string_body> parser_;
@@ -100,7 +100,7 @@ private:
boost::beast::http::response<boost::beast::http::string_body> parsedHttpResponse_;
HttpType httpType_;
std::string dstIP_;
std::string dstIp_;
unsigned short dstPort_;
TlsRequest parsedTlsRequest_;
boost::uuids::uuid uuid_;
+117
View File
@@ -0,0 +1,117 @@
#pragma once
#include <algorithm>
#include <cctype>
#include <sstream>
#include <string>
namespace http_utils {
inline std::string toLowerCopy(std::string value) {
std::transform(value.begin(), value.end(), value.begin(), [](unsigned char c) {
return static_cast<char>(std::tolower(c));
});
return value;
}
inline std::string trimCopy(std::string value) {
while (!value.empty() && (value.front() == ' ' || value.front() == '\t')) {
value.erase(value.begin());
}
while (!value.empty() &&
(value.back() == ' ' ||
value.back() == '\t' ||
value.back() == '\r' ||
value.back() == '\n')) {
value.pop_back();
}
return value;
}
inline std::string extractHeaders(const std::string &message) {
const auto pos = message.find("\r\n\r\n");
if (pos == std::string::npos) {
return {};
}
return message.substr(0, pos + 4);
}
inline std::string extractBody(const std::string &message) {
const auto pos = message.find("\r\n\r\n");
if (pos == std::string::npos) {
return {};
}
return message.substr(pos + 4);
}
inline bool parseContentLength(const std::string &headers, std::size_t &value) {
std::istringstream iss(headers);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
const auto lower = toLowerCopy(line);
if (lower.rfind("content-length:", 0) == 0) {
auto raw = line.substr(std::string("Content-Length:").size());
raw.erase(0, raw.find_first_not_of(" \t"));
try {
value = static_cast<std::size_t>(std::stoull(raw));
return true;
} catch (...) {
return false;
}
}
}
return false;
}
inline bool isChunked(const std::string &headers) {
std::istringstream iss(headers);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
const auto lower = toLowerCopy(line);
if (lower.rfind("transfer-encoding:", 0) == 0 &&
lower.find("chunked") != std::string::npos) {
return true;
}
}
return false;
}
inline std::string getRawHeader(const std::string &headers, const std::string &name) {
std::istringstream iss(headers);
std::string line;
const std::string prefix = toLowerCopy(name) + ":";
while (std::getline(iss, line)) {
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
const std::string lower = toLowerCopy(line);
if (lower.rfind(prefix, 0) == 0) {
return trimCopy(line.substr(name.size() + 1));
}
}
return {};
}
}// namespace http_utils
+2 -4
View File
@@ -10,7 +10,6 @@
#include "config.hpp"
#include "general.hpp"
class Log : private Uncopyable {
public:
enum class Level {
@@ -28,10 +27,9 @@ public:
explicit Log(const std::shared_ptr<Log> &log);
~Log();
const std::shared_ptr<Config> &config() const { return config_; }
std::shared_ptr<Config> config() const { return config_; }
Level level() const { return level_; }
@@ -42,7 +40,7 @@ private:
static std::string levelToString(Level level);
const std::shared_ptr<Config> &config_;
std::shared_ptr<Config> config_;
Level level_;
std::string mode_;
+9 -3
View File
@@ -7,6 +7,12 @@
#include <thread>
#include <vector>
#if defined(__ANDROID__)
using runnerThread = std::thread;
#else
using runnerThread = std::jthread;
#endif
#include "config.hpp"
#include "log.hpp"
#include "tcpserver.hpp"
@@ -25,8 +31,8 @@ private:
void stop();
const std::shared_ptr<Config> &config_;
const std::shared_ptr<Log> &log_;
std::shared_ptr<Config> config_;
std::shared_ptr<Log> log_;
boost::asio::io_context io_context_;
@@ -34,7 +40,7 @@ private:
std::atomic<bool> running_;
std::vector<std::jthread> threadPool_;
std::vector<runnerThread> threadPool_;
boost::asio::strand<boost::asio::io_context::executor_type> strand_;
};
+29 -67
View File
@@ -1,83 +1,45 @@
#include "serverhandler.hpp"
#include <algorithm>
#include <cctype>
#include <sstream>
#include <utility>
#include <vector>
#include "http_utils.hpp"
std::mutex ServerHandler::sessionsMutex_;
std::unordered_map<std::string, TCPClient::pointer> ServerHandler::sessions_;
std::string ServerHandler::HttpUtils::lowerCopy(std::string s) {
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) {
return static_cast<char>(std::tolower(c));
});
return s;
return http_utils::toLowerCopy(std::move(s));
}
std::string ServerHandler::HttpUtils::trimCopy(std::string s) {
while (!s.empty() && (s.front() == ' ' || s.front() == '\t')) {
s.erase(s.begin());
}
while (!s.empty() &&
(s.back() == ' ' ||
s.back() == '\t' ||
s.back() == '\r' ||
s.back() == '\n')) {
s.pop_back();
}
return s;
return http_utils::trimCopy(std::move(s));
}
std::string ServerHandler::HttpUtils::getRawHeader(const std::string &headers,
const std::string &name) {
std::istringstream iss(headers);
std::string line;
const std::string prefix = lowerCopy(name) + ":";
while (std::getline(iss, line)) {
if (!line.empty() && line.back() == '\r') {
line.pop_back();
}
std::string lower = lowerCopy(line);
if (lower.rfind(prefix, 0) == 0) {
return trimCopy(line.substr(name.size() + 1));
}
}
return "";
return http_utils::getRawHeader(headers, name);
}
std::string ServerHandler::HttpUtils::extractHttpBody(const std::string &msg) {
const auto pos = msg.find("\r\n\r\n");
if (pos == std::string::npos) {
return "";
}
return msg.substr(pos + 4);
return http_utils::extractBody(msg);
}
ServerHandler::ServerHandler(boost::asio::streambuf &readBuffer,
boost::asio::streambuf &writeBuffer,
const std::shared_ptr<Config> &config,
const std::shared_ptr<Log> &log,
const TCPClient::pointer &client,
const std::string &clientConnStr,
TCPClient::pointer client,
std::string clientConnStr,
boost::uuids::uuid uuid)
: config_(config),
log_(log),
client_(client),
client_(std::move(client)),
readBuffer_(readBuffer),
writeBuffer_(writeBuffer),
request_(HTTP::create(config, log, readBuffer, uuid)),
clientConnStr_(clientConnStr),
clientConnStr_(std::move(clientConnStr)),
uuid_(uuid) {
end_ = false;
connect_ = false;
@@ -91,7 +53,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 +160,7 @@ void ServerHandler::handle() {
}
if (!targetClient || !targetClient->isOpen()) {
makeEncryptedHttpResponse("", "200 OK", "close");
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
return;
}
@@ -206,7 +168,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 +185,7 @@ void ServerHandler::handle() {
}
if (!targetClient || !targetClient->isOpen()) {
makeEncryptedHttpResponse("", "200 OK", "close");
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
return;
}
@@ -231,7 +193,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 +203,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 +224,7 @@ void ServerHandler::handle() {
sessions_.erase(it);
}
makeEncryptedHttpResponse("", "200 OK", "close");
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
return;
}
@@ -301,12 +263,12 @@ void ServerHandler::handle() {
switch (inner->httpType()) {
case HTTP::HttpType::connect: {
if (config_->general().tunnelEnable) {
if (!client_->doConnect(inner->dstIP(), inner->dstPort())) {
if (!client_->doConnect(inner->dstIp(), inner->dstPort())) {
log_->write(
"[" + to_string(uuid_) +
"] [CONNECT] [ERROR] [Resolving Host] [SRC " +
clientConnStr_ + "] [DST " +
inner->dstIP() + ":" + std::to_string(inner->dstPort()) + "]",
inner->dstIp() + ":" + std::to_string(inner->dstPort()) + "]",
Log::Level::INFO);
makeEncryptedHttpResponse(
@@ -323,7 +285,7 @@ void ServerHandler::handle() {
"[" + to_string(uuid_) +
"] [CONNECT] [TUNNEL] [SRC " +
clientConnStr_ + "] [DST " +
inner->dstIP() + ":" + std::to_string(inner->dstPort()) + "]",
inner->dstIp() + ":" + std::to_string(inner->dstPort()) + "]",
Log::Level::INFO);
makeEncryptedHttpResponse(
@@ -344,12 +306,12 @@ void ServerHandler::handle() {
targetClient->uuid_ = uuid_;
if (!targetClient->doConnect(inner->dstIP(), inner->dstPort())) {
if (!targetClient->doConnect(inner->dstIp(), inner->dstPort())) {
log_->write(
"[" + to_string(uuid_) +
"] [CONNECT] [ERROR] [Resolving Host] [SRC " +
clientConnStr_ + "] [DST " +
inner->dstIP() + ":" + std::to_string(inner->dstPort()) + "]",
inner->dstIp() + ":" + std::to_string(inner->dstPort()) + "]",
Log::Level::INFO);
makeEncryptedHttpResponse(
@@ -366,7 +328,7 @@ void ServerHandler::handle() {
"[" + to_string(uuid_) +
"] [CONNECT] [SRC " +
clientConnStr_ + "] [DST " +
inner->dstIP() + ":" + std::to_string(inner->dstPort()) + "]",
inner->dstIp() + ":" + std::to_string(inner->dstPort()) + "]",
Log::Level::INFO);
if (!pendingTunnelData.empty()) {
@@ -383,7 +345,7 @@ void ServerHandler::handle() {
makeEncryptedHttpResponse(
"HTTP/1.1 200 Connection Established\r\n\r\n",
"200 OK",
"close");
"keep-alive");
connect_ = false;
end_ = false;
@@ -395,7 +357,7 @@ void ServerHandler::handle() {
copyStringToStreambuf(innerRequest, readBuffer_);
if (!client_->socket().is_open()) {
if (!client_->doConnect(inner->dstIP(), inner->dstPort())) {
if (!client_->doConnect(inner->dstIp(), inner->dstPort())) {
client_->socket().close();
makeEncryptedHttpResponse("", "502 Bad Gateway", "close");
return;
@@ -407,14 +369,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;
+9 -10
View File
@@ -19,8 +19,8 @@ public:
boost::asio::streambuf &writeBuffer,
const std::shared_ptr<Config> &config,
const std::shared_ptr<Log> &log,
const TCPClient::pointer &client,
const std::string &clientConnStr,
TCPClient::pointer client,
std::string clientConnStr,
boost::uuids::uuid uuid) {
return pointer(new ServerHandler(readBuffer, writeBuffer, config, log, client, clientConnStr, uuid));
}
@@ -29,8 +29,7 @@ public:
void handle();
inline const HTTP::pointer &request() & { return request_; }
inline const HTTP::pointer &&request() && { return std::move(request_); }
inline const HTTP::pointer &request() const { return request_; }
bool end_;
bool connect_;
@@ -47,8 +46,8 @@ private:
boost::asio::streambuf &writeBuffer,
const std::shared_ptr<Config> &config,
const std::shared_ptr<Log> &log,
const TCPClient::pointer &client,
const std::string &clientConnStr,
TCPClient::pointer client,
std::string clientConnStr,
boost::uuids::uuid uuid);
void makeEncryptedHttpResponse(const std::string &plainBody,
@@ -62,13 +61,13 @@ private:
static std::mutex sessionsMutex_;
static std::unordered_map<std::string, TCPClient::pointer> sessions_;
const std::shared_ptr<Config> &config_;
const std::shared_ptr<Log> &log_;
const TCPClient::pointer &client_;
std::shared_ptr<Config> config_;
std::shared_ptr<Log> log_;
TCPClient::pointer client_;
boost::asio::streambuf &readBuffer_;
boost::asio::streambuf &writeBuffer_;
HTTP::pointer request_;
const std::string &clientConnStr_;
std::string clientConnStr_;
boost::uuids::uuid uuid_;
std::mutex mutex_;
};
+171 -156
View File
@@ -5,8 +5,11 @@
#include <algorithm>
#include <cctype>
#include <sstream>
#include <utility>
#include <vector>
#include "http_utils.hpp"
TCPClient::TCPClient(boost::asio::io_context &io_context,
const std::shared_ptr<Config> &config,
const std::shared_ptr<Log> &log)
@@ -34,7 +37,6 @@ bool TCPClient::isOpen() const {
}
bool TCPClient::enableTlsClient() {
std::lock_guard lock(mutex_);
try {
if (tlsEnabled_) return true;
@@ -48,11 +50,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);
@@ -91,17 +93,27 @@ bool TCPClient::enableTlsClient() {
}
}
bool TCPClient::doConnect(const std::string &dstIP, const unsigned short &dstPort) {
std::lock_guard lock(mutex_);
bool TCPClient::doConnect(const std::string &dstIp, unsigned short dstPort) {
try {
log_->write("[" + to_string(uuid_) + "] [TCPClient doConnect] [DST " + dstIP +
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 +123,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 +150,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,12 +159,11 @@ 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;
std::string sniHost = config_->general().fakeUrl;
std::string sniHost = config_->randomFakeUrl();
if (!sniHost.empty()) {
auto pos = sniHost.find("://");
@@ -217,13 +239,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 +265,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 +273,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 +301,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 +373,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,89 +467,66 @@ 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) {
std::transform(s.begin(), s.end(), s.begin(),
[](unsigned char c) {
return static_cast<char>(std::tolower(c));
});
return s;
return http_utils::toLowerCopy(std::move(s));
}
std::string TCPClient::HttpUtils::extractHeaders(const std::string &msg) {
auto pos = msg.find("\r\n\r\n");
if (pos == std::string::npos) return {};
return msg.substr(0, pos + 4);
return http_utils::extractHeaders(msg);
}
std::string TCPClient::HttpUtils::extractBody(const std::string &msg) {
auto pos = msg.find("\r\n\r\n");
if (pos == std::string::npos) return {};
return msg.substr(pos + 4);
return http_utils::extractBody(msg);
}
bool TCPClient::HttpUtils::parseContentLength(const std::string &headers, std::size_t &value) {
std::istringstream iss(headers);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty() && line.back() == '\r') line.pop_back();
auto lower = toLowerCopy(line);
if (lower.rfind("content-length:", 0) == 0) {
auto raw = line.substr(std::string("Content-Length:").size());
raw.erase(0, raw.find_first_not_of(" \t"));
try {
value = static_cast<std::size_t>(std::stoull(raw));
return true;
} catch (...) {
return false;
}
}
}
return false;
return http_utils::parseContentLength(headers, value);
}
bool TCPClient::HttpUtils::isChunked(const std::string &headers) {
std::istringstream iss(headers);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty() && line.back() == '\r') line.pop_back();
auto lower = toLowerCopy(line);
if (lower.rfind("transfer-encoding:", 0) == 0 &&
lower.find("chunked") != std::string::npos) {
return true;
}
}
return false;
return http_utils::isChunked(headers);
}
bool TCPClient::HttpUtils::readHttpMessage(
@@ -553,10 +568,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 +586,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;
}
+9 -9
View File
@@ -2,8 +2,6 @@
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/uuid/uuid.hpp>
#include <functional>
#include <memory>
@@ -15,9 +13,9 @@
#include "http.hpp"
#include "log.hpp"
class TCPClient : public boost::enable_shared_from_this<TCPClient> {
class TCPClient : public std::enable_shared_from_this<TCPClient> {
public:
using pointer = boost::shared_ptr<TCPClient>;
using pointer = std::shared_ptr<TCPClient>;
using tcp = boost::asio::ip::tcp;
using ssl_stream = boost::asio::ssl::stream<tcp::socket>;
@@ -35,15 +33,13 @@ public:
bool enableTlsClient();
bool doHandshakeClient();
bool doConnect(const std::string &dstIP, const unsigned short &dstPort);
bool doConnect(const std::string &dstIp, unsigned short dstPort);
void writeBuffer(boost::asio::streambuf &buffer);
inline boost::asio::streambuf &writeBuffer() & { return writeBuffer_; }
inline boost::asio::streambuf &&writeBuffer() && { return std::move(writeBuffer_); }
inline boost::asio::streambuf &readBuffer() & { return readBuffer_; }
inline boost::asio::streambuf &&readBuffer() && { return std::move(readBuffer_); }
void doWrite(boost::asio::streambuf &buffer);
void doReadAgent();
@@ -51,6 +47,9 @@ public:
void socketShutdown();
boost::uuids::uuid uuid() const { return uuid_; }
bool ended() const { return end_; }
boost::uuids::uuid uuid_;
bool end_;
@@ -87,8 +86,8 @@ private:
void cancelTimeout();
void onTimeout(const boost::system::error_code &error);
const std::shared_ptr<Config> &config_;
const std::shared_ptr<Log> &log_;
std::shared_ptr<Config> config_;
std::shared_ptr<Log> log_;
boost::asio::io_context &io_context_;
tcp::socket socket_;
@@ -103,4 +102,5 @@ private:
tcp::resolver resolver_;
boost::asio::steady_timer timeout_;
mutable std::mutex mutex_;
bool closed_ = false;
};
+340 -125
View File
@@ -5,8 +5,11 @@
#include <algorithm>
#include <cctype>
#include <sstream>
#include <utility>
#include <vector>
#include "http_utils.hpp"
TCPConnection::TCPConnection(boost::asio::io_context &io_context,
const std::shared_ptr<Config> &config,
const std::shared_ptr<Log> &log,
@@ -36,16 +39,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 +61,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 +75,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;
}
@@ -94,6 +105,7 @@ bool TCPConnection::doHandshakeServer() {
cancelTimeout();
log_->write("[" + to_string(uuid_) + "] [TCPConnection doHandshakeServer] " + error.what(),
Log::Level::ERROR);
socketShutdown();
return false;
}
}
@@ -114,20 +126,30 @@ void TCPConnection::doReadAgent() {
try {
readBuffer_.consume(readBuffer_.size());
writeBuffer_.consume(writeBuffer_.size());
resetTimeout();
boost::asio::async_read(socket_,
readBuffer_,
boost::asio::transfer_at_least(1),
boost::asio::bind_executor(
strand_,
boost::bind(&TCPConnection::handleReadAgent,
shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)));
socket_.async_read_some(
readBuffer_.prepare(8192),
boost::asio::bind_executor(
strand_,
[self = shared_from_this()](
const boost::system::error_code &ec,
std::size_t bytes) {
if (!ec) {
self->readBuffer_.commit(bytes);
}
self->handleReadAgent(ec, bytes);
}));
} catch (std::exception &error) {
log_->write("[" + to_string(uuid_) + "] [TCPConnection doReadAgent] [catch] " + error.what(),
Log::Level::ERROR);
log_->write(
"[" + to_string(uuid_) +
"] [TCPConnection doReadAgent] [catch] " +
error.what(),
Log::Level::ERROR);
socketShutdown();
}
}
@@ -145,7 +167,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);
@@ -168,7 +190,15 @@ void TCPConnection::handleReadAgent(const boost::system::error_code &error, size
boost::system::error_code errorIn;
if (config_->general().protocol == "socks5") {
if (!handleSocks5Handshake()) {
socketShutdown();
return;
}
}
std::string current = streambufToString(readBuffer_);
if (current.find("\r\n\r\n") == std::string::npos) {
boost::asio::read_until(socket_, readBuffer_, "\r\n\r\n", errorIn);
}
@@ -225,6 +255,18 @@ void TCPConnection::handleReadAgent(const boost::system::error_code &error, size
end_ = agentHandler_->end_;
connect_ = agentHandler_->connect_;
if (config_->general().protocol == "socks5" && connect_) {
writeBuffer_.consume(writeBuffer_.size());
const unsigned char ok[10] = {
0x05, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00};
std::ostream os(&writeBuffer_);
os.write(reinterpret_cast<const char *>(ok), sizeof(ok));
}
if (writeBuffer_.size() == 0) {
socketShutdown();
return;
@@ -253,13 +295,17 @@ void TCPConnection::handleReadAgent(const boost::system::error_code &error, size
self->relayClientToServer();
self->relayServerToClient();
} else {
self->client_->socketShutdown();
if (!self->config_->general().connectionReuse) {
self->client_->socketShutdown();
}
self->startTunnelReadFromClient();
self->startTunnelPollServer();
}
return;
}
self->doReadAgent();
}));
} catch (std::exception &error) {
@@ -281,7 +327,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;
@@ -350,10 +396,14 @@ void TCPConnection::handleReadServer(const boost::system::error_code &error, siz
return;
}
self->socketShutdown();
if (self->config_->general().connectionReuse) {
self->doReadServer();
} else {
self->socketShutdown();
}
};
if (config_->server().tlsEnable) {
if (config_->general().tlsEnable) {
boost::asio::async_write(
*tlsSocket_,
writeBuffer_.data(),
@@ -376,7 +426,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);
@@ -387,44 +437,78 @@ std::string TCPConnection::makeRelayHostHeader() const {
return hostHeader;
}
std::string TCPConnection::postTunnelAction(const std::string &action, const std::string &rawBody) {
TCPClient::pointer c = TCPClient::create(io_context_, config_, log_);
c->uuid_ = uuid_;
std::string TCPConnection::postTunnelAction(const std::string &action,
const std::string &rawBody) {
client_->uuid_ = uuid_;
if (config_->agent().tlsEnable && !c->enableTlsClient()) return "";
if (!c->doConnect(config_->agent().serverIp, config_->agent().serverPort)) return "";
if (c->tlsEnabled() && !c->doHandshakeClient()) return "";
auto sendOnce = [&]() -> std::string {
const bool alreadyOpen = client_->isOpen();
BoolStr enc = aes256Encrypt(
hexArrToStr(reinterpret_cast<const unsigned char *>(rawBody.data()), rawBody.size()),
config_->general().token);
if (!alreadyOpen) {
if (config_->general().tlsEnable) {
if (!client_->enableTlsClient()) return "";
}
if (!enc.ok) return "";
if (!client_->doConnect(config_->agent().serverIp,
config_->agent().serverPort)) {
return "";
}
const std::string encodedBody = encode64(enc.message);
if (client_->tlsEnabled()) {
if (!client_->doHandshakeClient()) return "";
}
}
std::ostringstream req;
req << config_->randomMethod() + " /" + config_->randomEndPoint() + " HTTP/1.1\r\n"
<< "Host: " << makeRelayHostHeader() << "\r\n"
<< "User-Agent: Mozilla/5.0\r\n"
<< "Accept: */*\r\n"
<< "Content-Type: application/octet-stream\r\n"
<< "X-Nipo-Session: " << to_string(uuid_) << "\r\n"
<< "X-Nipo-Action: " << action << "\r\n"
<< "Content-Length: " << encodedBody.size() << "\r\n"
<< "Connection: close\r\n"
<< "\r\n"
<< encodedBody;
BoolStr enc = aes256Encrypt(
hexArrToStr(
reinterpret_cast<const unsigned char *>(rawBody.data()),
rawBody.size()),
config_->general().token);
boost::asio::streambuf out;
copyStringToStreambuf(req.str(), out);
if (!enc.ok) return "";
c->doWrite(out);
c->doReadAgent();
const std::string encodedBody = encode64(enc.message);
const std::string response = streambufToString(c->readBuffer());
const bool keepAlive =
config_->general().connectionReuse && action != "close";
c->socketShutdown();
std::ostringstream req;
req << config_->randomMethod() + " /" + config_->randomEndPoint()
<< " HTTP/" << config_->agent().httpVersion << "\r\n"
<< "Host: " << makeRelayHostHeader() << "\r\n"
<< "User-Agent: " << config_->agent().userAgent << "\r\n"
<< "Accept: */*\r\n"
<< "Content-Type: application/text\r\n"
<< "X-Nipo-Session: " << to_string(uuid_) << "\r\n"
<< "X-Nipo-Action: " << action << "\r\n"
<< "Content-Length: " << encodedBody.size() << "\r\n"
<< "Connection: " << (keepAlive ? "keep-alive" : "close") << "\r\n"
<< "\r\n"
<< encodedBody;
boost::asio::streambuf out;
copyStringToStreambuf(req.str(), out);
client_->doWrite(out);
client_->doReadAgent();
const std::string response = streambufToString(client_->readBuffer());
if (!keepAlive) {
client_->socketShutdown();
}
return response;
};
std::string response = sendOnce();
if (response.empty() &&
config_->general().connectionReuse &&
action != "close") {
client_->socketShutdown();
response = sendOnce();
}
const auto pos = response.find("\r\n\r\n");
if (pos == std::string::npos) return "";
@@ -438,6 +522,132 @@ std::string TCPConnection::postTunnelAction(const std::string &action, const std
return dec.message;
}
bool TCPConnection::readExactFromClient(void *data, std::size_t size) {
auto *out = static_cast<char *>(data);
std::size_t copied = 0;
while (copied < size && readBuffer_.size() > 0) {
std::size_t n = std::min(size - copied, readBuffer_.size());
auto buffers = readBuffer_.data();
std::size_t copiedNow = boost::asio::buffer_copy(
boost::asio::buffer(out + copied, n),
buffers);
readBuffer_.consume(copiedNow);
copied += copiedNow;
}
if (copied == size) {
return true;
}
boost::system::error_code ec;
boost::asio::read(
socket_,
boost::asio::buffer(out + copied, size - copied),
ec);
return !ec;
}
bool TCPConnection::handleSocks5Handshake() {
log_->write(
"[" + to_string(uuid_) + "] [TCPConnection handleSocks5Handshake] handshake start",
Log::Level::DEBUG);
unsigned char header[2];
if (!readExactFromClient(header, 2)) {
log_->write(
"[" + to_string(uuid_) + "] [TCPConnection handleSocks5Handshake] [SOCKS5] version=" +
std::to_string(header[0]),
Log::Level::DEBUG);
return false;
}
if (header[0] != 0x05) {
log_->write("[" + to_string(uuid_) + "] [SOCKS5] invalid version", Log::Level::DEBUG);
return false;
}
std::vector<unsigned char> methods(header[1]);
if (!readExactFromClient(methods.data(), methods.size())) return false;
const unsigned char authReply[2] = {0x05, 0x00};
boost::asio::write(socket_, boost::asio::buffer(authReply, 2));
log_->write(
"[" + to_string(uuid_) + "] [TCPConnection handleSocks5Handshake] auth reply sent" +
std::to_string(header[0]),
Log::Level::DEBUG);
unsigned char req[4];
if (!readExactFromClient(req, 4)) return false;
if (req[0] != 0x05 || req[1] != 0x01) {
const unsigned char fail[10] = {0x05, 0x07, 0x00, 0x01, 0, 0, 0, 0, 0, 0};
boost::asio::write(socket_, boost::asio::buffer(fail, 10));
return false;
}
std::string host;
if (req[3] == 0x01) {
unsigned char ip[4];
if (!readExactFromClient(ip, 4)) return false;
host =
std::to_string(ip[0]) + "." +
std::to_string(ip[1]) + "." +
std::to_string(ip[2]) + "." +
std::to_string(ip[3]);
} else if (req[3] == 0x03) {
unsigned char len;
if (!readExactFromClient(&len, 1)) return false;
std::vector<char> domain(len);
if (!readExactFromClient(domain.data(), domain.size())) return false;
host.assign(domain.begin(), domain.end());
} else if (req[3] == 0x04) {
unsigned char ip[16];
if (!readExactFromClient(ip, 16)) return false;
boost::asio::ip::address_v6::bytes_type bytes;
std::copy(ip, ip + 16, bytes.begin());
host = boost::asio::ip::address_v6(bytes).to_string();
} else {
return false;
}
unsigned char portBytes[2];
if (!readExactFromClient(portBytes, 2)) return false;
unsigned short port =
static_cast<unsigned short>((portBytes[0] << 8) | portBytes[1]);
std::string target = host + ":" + std::to_string(port);
std::string connectRequest =
"CONNECT " + target +
" HTTP/1.1\r\n"
"Host: " +
target +
"\r\n"
"\r\n";
copyStringToStreambuf(connectRequest, readBuffer_);
log_->write(
"[" + to_string(uuid_) + "] [SOCKS5] CONNECT " + target,
Log::Level::INFO);
return true;
}
void TCPConnection::startTunnelReadFromClient() {
if (tunnelClosed_ || !socket_.is_open()) return;
@@ -464,7 +674,7 @@ void TCPConnection::startTunnelPollServer() {
pollInProgress_ = true;
pollTimer_.expires_after(std::chrono::milliseconds(10));
pollTimer_.expires_after(std::chrono::milliseconds(config_->general().pullTimeout));
pollTimer_.async_wait(
boost::asio::bind_executor(
strand_,
@@ -508,22 +718,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);
@@ -532,32 +755,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_) {
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("[" + 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;
}
@@ -566,7 +821,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),
@@ -591,7 +846,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));
@@ -773,63 +1028,23 @@ void TCPConnection::relayTargetToAgent() {
}
std::string TCPConnection::HttpUtils::toLowerCopy(std::string s) {
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) {
return static_cast<char>(std::tolower(c));
});
return s;
return http_utils::toLowerCopy(std::move(s));
}
std::string TCPConnection::HttpUtils::extractHeaders(const std::string &msg) {
auto pos = msg.find("\r\n\r\n");
if (pos == std::string::npos) return {};
return msg.substr(0, pos + 4);
return http_utils::extractHeaders(msg);
}
std::string TCPConnection::HttpUtils::extractBody(const std::string &msg) {
auto pos = msg.find("\r\n\r\n");
if (pos == std::string::npos) return {};
return msg.substr(pos + 4);
return http_utils::extractBody(msg);
}
bool TCPConnection::HttpUtils::parseContentLength(const std::string &headers, std::size_t &value) {
std::istringstream iss(headers);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty() && line.back() == '\r') line.pop_back();
auto lower = toLowerCopy(line);
if (lower.rfind("content-length:", 0) == 0) {
auto raw = line.substr(std::string("Content-Length:").size());
raw.erase(0, raw.find_first_not_of(" \t"));
try {
value = static_cast<std::size_t>(std::stoull(raw));
return true;
} catch (...) {
return false;
}
}
}
return false;
return http_utils::parseContentLength(headers, value);
}
bool TCPConnection::HttpUtils::isChunked(const std::string &headers) {
std::istringstream iss(headers);
std::string line;
while (std::getline(iss, line)) {
if (!line.empty() && line.back() == '\r') line.pop_back();
auto lower = toLowerCopy(line);
if (lower.rfind("transfer-encoding:", 0) == 0 &&
lower.find("chunked") != std::string::npos) {
return true;
}
}
return false;
return http_utils::isChunked(headers);
}
bool TCPConnection::HttpUtils::readRemainingHttpBody(
+16 -13
View File
@@ -1,11 +1,10 @@
#pragma once
#include <array>
#include <atomic>
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/bind/bind.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
@@ -19,9 +18,9 @@
#include "general.hpp"
#include "serverhandler.hpp"
class TCPConnection : public boost::enable_shared_from_this<TCPConnection> {
class TCPConnection : public std::enable_shared_from_this<TCPConnection> {
public:
using pointer = boost::shared_ptr<TCPConnection>;
using pointer = std::shared_ptr<TCPConnection>;
using ssl_stream = boost::asio::ssl::stream<boost::asio::ip::tcp::socket>;
static pointer create(boost::asio::io_context &io_context,
@@ -32,7 +31,7 @@ public:
}
boost::asio::ip::tcp::socket &socket();
inline TCPClient::pointer client() { return client_; }
inline TCPClient::pointer client() const { return client_; }
ssl_stream &tlsSocket();
bool initTlsServerContext();
@@ -43,8 +42,8 @@ public:
}
inline const boost::asio::streambuf &readBuffer() & { return readBuffer_; }
inline const boost::asio::streambuf &&readBuffer() && { return std::move(readBuffer_); }
inline boost::uuids::uuid uuid() { return uuid_; }
inline boost::uuids::uuid uuid() const { return uuid_; }
void startAgent();
void startServer();
@@ -70,7 +69,7 @@ public:
std::function<void(const boost::system::error_code &)> done);
inline void asyncReadFromAgentConnection(
std::array<char, 8192> &buffer,
std::array<char, BufferSize> &buffer,
std::function<void(const boost::system::error_code &, std::size_t)> done);
inline void asyncWriteToAgentServerConnection(
@@ -79,7 +78,7 @@ public:
std::function<void(const boost::system::error_code &)> done);
inline void asyncReadFromAgentServerConnection(
std::array<char, 8192> &buffer,
std::array<char, BufferSize> &buffer,
std::function<void(const boost::system::error_code &, std::size_t)> done);
private:
@@ -110,6 +109,9 @@ private:
const std::shared_ptr<Log> &log,
TCPClient::pointer client);
bool handleSocks5Handshake();
bool readExactFromClient(void *data, std::size_t size);
void resetTimeout();
void cancelTimeout();
void onTimeout(const boost::system::error_code &error);
@@ -124,8 +126,8 @@ private:
boost::asio::ssl::context sslContext_;
std::unique_ptr<ssl_stream> tlsSocket_;
const std::shared_ptr<Config> &config_;
const std::shared_ptr<Log> &log_;
std::shared_ptr<Config> config_;
std::shared_ptr<Log> log_;
boost::asio::io_context &io_context_;
TCPClient::pointer client_;
@@ -144,7 +146,8 @@ private:
bool tunnelMode_;
bool tunnelClosed_;
bool pollInProgress_;
std::atomic_bool closed_{false};
std::array<char, 8192> downstreamBuf_;
std::array<char, 8192> upstreamBuf_;
std::array<char, BufferSize> downstreamBuf_;
std::array<char, BufferSize> 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);
+4 -4
View File
@@ -1,13 +1,13 @@
#pragma once
#include <boost/asio.hpp>
#include <boost/shared_ptr.hpp>
#include <memory>
#include "tcpconnection.hpp"
class TCPServer {
public:
using pointer = boost::shared_ptr<TCPServer>;
using pointer = std::shared_ptr<TCPServer>;
static pointer create(boost::asio::io_context &io_context,
const std::shared_ptr<Config> &config,
@@ -25,8 +25,8 @@ private:
void handleAccept(TCPConnection::pointer connection,
const boost::system::error_code &error);
const std::shared_ptr<Config> &config_;
const std::shared_ptr<Log> &log_;
std::shared_ptr<Config> config_;
std::shared_ptr<Log> log_;
boost::asio::io_context &io_context_;
boost::asio::ip::tcp::acceptor acceptor_;
};
+18
View File
@@ -0,0 +1,18 @@
## Install on Termux
### Requirements
libyaml-cpp >= 0.8
boost >= 1.88.0
### Dependencies
Install the dependencies
```bash
pkg install boost libyaml-cpp
```
### Install
Download the nipovpn_VERSION_termux_aarch64 version from releases pages
```bash
pkg install ./nipovpn_VERSION_termux_aarch64.deb
```
+7 -7
View File
@@ -1,7 +1,7 @@
Package : nipovpn
Version : 0.1
Maintainer : Morteza Bashsiz
Architecture : amd64
Description : Powerfull and Secure http/s Proxy
Depends : libyaml-cpp0.8
Homepage : https://github.com/MortezaBashsiz/nipovpn
Package: nipovpn
Version: ${PACKAGE_VERSION}
Maintainer: Morteza Bashsiz
Architecture: ${{ matrix.arch }}
Description: Powerfull and Secure http/s Proxy
Depends: libyaml-cpp0.8
Homepage: https://github.com/MortezaBashsiz/nipovpn
+38 -19
View File
@@ -3,20 +3,28 @@
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: "www.google.com"
# method:
# protocol:
# Defines the protocol between client and agent
# Choose http or socks5
protocol: http
# fakeUrls:
# Defines the list of fake urls between agent and server
fakeUrls:
- nipo.ciron.net
- sudoer.ir
- sudoer.net
- google.com
- cloudflare.com
# methods:
# Defines the list of using methods
# you like to send requests from agent to server
# Program will choose randomly from this list
methods:
- HEAD
- GET
- 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
@@ -29,10 +37,28 @@ general:
# Defines the timeout for I/O Operation in seconds. 0 indicates no timeout.
# Useful to automatically close stalled connections.
timeout: 10
# pullTimeout: unsigned short
# Defines the timeout for I/O Operation in milliseconds.
# Useful to expire serverside read timer.
pullTimeout: 50
# 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: 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: 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
@@ -48,14 +74,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:
@@ -68,11 +90,8 @@ agent:
# serverIp: IPv4 of the nipoServer
serverIp: "127.0.0.10"
# 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"