Compare commits
50
Commits
v1.1.57
...
dev-v0.1.74
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3de78c2f6b | ||
|
|
abc8ae9a6b | ||
|
|
0a45ccc315 | ||
|
|
bd283fbf22 | ||
|
|
29eab9f955 | ||
|
|
1d95451402 | ||
|
|
230ea19b34 | ||
|
|
7f42ceff35 | ||
|
|
65fd8f1fca | ||
|
|
4dd09b0d0e | ||
|
|
88782afbfd | ||
|
|
6bcc946f58 | ||
|
|
6770764f2b | ||
|
|
9199a0ded9 | ||
|
|
92de8a0bce | ||
|
|
679ab77dc2 | ||
|
|
04768f37de | ||
|
|
e52743c051 | ||
|
|
ce61bfd8ad | ||
|
|
78188d8ac3 | ||
|
|
1af9ede5ff | ||
|
|
5f3594b6d2 | ||
|
|
95e05cf59c | ||
|
|
a8205a716b | ||
|
|
c76b23f93c | ||
|
|
555cad3654 | ||
|
|
df310303da | ||
|
|
5056b7b907 | ||
|
|
5616828192 | ||
|
|
5a0c414f63 | ||
|
|
5ddfcf1a0d | ||
|
|
703595501c | ||
|
|
3b195208ff | ||
|
|
a63d7ca141 | ||
|
|
882c68179f | ||
|
|
5e8b76769d | ||
|
|
c1afc7dab2 | ||
|
|
ef04fb3fb2 | ||
|
|
ec5eaf824b | ||
|
|
de4606d884 | ||
|
|
4860804ef1 | ||
|
|
d9c3a45074 | ||
|
|
33adcf9541 | ||
|
|
02920acb49 | ||
|
|
b250ec47a9 | ||
|
|
8e677a826d | ||
|
|
2e2ef18529 | ||
|
|
fdf03a7ec7 | ||
|
|
13aa2cd816 | ||
|
|
042998095e |
No files matched your search
@@ -0,0 +1,7 @@
|
||||
.git
|
||||
.github
|
||||
build
|
||||
cmake-build-*
|
||||
*.deb
|
||||
*.tar.gz
|
||||
*.log
|
||||
@@ -16,7 +16,7 @@ permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
PACKAGE_VERSION: 1.1.57
|
||||
PACKAGE_VERSION: 1.1.60
|
||||
|
||||
jobs:
|
||||
build-android:
|
||||
|
||||
@@ -100,9 +100,32 @@ jobs:
|
||||
|
||||
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
|
||||
|
||||
mkdir -p package-root/DEBIAN
|
||||
cat > package-root/DEBIAN/conffiles <<'EOF'
|
||||
/etc/nipovpn/config.yaml
|
||||
EOF
|
||||
|
||||
rm -f package-root/var/log/nipovpn/nipovpn.log
|
||||
mkdir -p package-root/var/log/nipovpn
|
||||
|
||||
cat > package-root/DEBIAN/postinst <<'EOF'
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
mkdir -p /var/log/nipovpn
|
||||
|
||||
if [ ! -f /var/log/nipovpn/nipovpn.log ]; then
|
||||
touch /var/log/nipovpn/nipovpn.log
|
||||
chmod 0644 /var/log/nipovpn/nipovpn.log
|
||||
fi
|
||||
|
||||
exit 0
|
||||
EOF
|
||||
|
||||
chmod 755 package-root/DEBIAN/postinst
|
||||
|
||||
echo "Final control file:"
|
||||
cat package-root/DEBIAN/control
|
||||
|
||||
@@ -164,32 +187,46 @@ jobs:
|
||||
texinfo \
|
||||
jq
|
||||
|
||||
- name: Install Android NDK r29
|
||||
- name: Clone termux-packages
|
||||
run: |
|
||||
git clone --depth=1 https://github.com/termux/termux-packages.git
|
||||
|
||||
- name: Install Android NDK required by termux-packages
|
||||
run: |
|
||||
NDK_NUM="$(sed -n 's/^: "${TERMUX_NDK_VERSION_NUM:="\([0-9]*\)"}"/\1/p' termux-packages/scripts/properties.sh)"
|
||||
NDK_REV="$(sed -n 's/^: "${TERMUX_NDK_REVISION:="\([a-z]*\)"}"/\1/p' termux-packages/scripts/properties.sh)"
|
||||
|
||||
if [ -z "$NDK_NUM" ]; then
|
||||
echo "Could not read the NDK version from termux-packages/scripts/properties.sh"
|
||||
grep -n NDK termux-packages/scripts/properties.sh || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NDK_VERSION="r${NDK_NUM}${NDK_REV}"
|
||||
echo "termux-packages requires Android NDK $NDK_VERSION"
|
||||
|
||||
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
|
||||
wget -q "https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-linux.zip"
|
||||
unzip -q "android-ndk-${NDK_VERSION}-linux.zip"
|
||||
|
||||
EXTRACTED_DIR="$(find "$HOME/lib" -maxdepth 1 -type d -name 'android-ndk-r29*' | head -n 1)"
|
||||
EXTRACTED_DIR="$(find "$HOME/lib" -maxdepth 1 -type d -name "android-ndk-${NDK_VERSION}*" | head -n 1)"
|
||||
|
||||
if [ -z "$EXTRACTED_DIR" ]; then
|
||||
echo "Android NDK r29 directory not found"
|
||||
echo "Android NDK $NDK_VERSION directory not found"
|
||||
ls -lah "$HOME/lib"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ln -sfn "$EXTRACTED_DIR" "$HOME/lib/android-ndk-r29"
|
||||
if [ "$EXTRACTED_DIR" != "$HOME/lib/android-ndk-${NDK_VERSION}" ]; then
|
||||
ln -sfn "$EXTRACTED_DIR" "$HOME/lib/android-ndk-${NDK_VERSION}"
|
||||
fi
|
||||
|
||||
echo "NDK=$HOME/lib/android-ndk-r29" >> "$GITHUB_ENV"
|
||||
echo "ANDROID_NDK_ROOT=$HOME/lib/android-ndk-r29" >> "$GITHUB_ENV"
|
||||
echo "NDK=$HOME/lib/android-ndk-${NDK_VERSION}" >> "$GITHUB_ENV"
|
||||
echo "ANDROID_NDK_ROOT=$HOME/lib/android-ndk-${NDK_VERSION}" >> "$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
|
||||
ls -ld "$HOME/lib/android-ndk-${NDK_VERSION}"
|
||||
|
||||
- name: Create Termux package recipe
|
||||
run: |
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: Build and Release Package - Main
|
||||
name: Build and Release Package - main
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -14,7 +14,7 @@ permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
PACKAGE_VERSION: 1.1.57
|
||||
PACKAGE_VERSION: 1.1.60
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -100,9 +100,32 @@ jobs:
|
||||
|
||||
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
|
||||
|
||||
mkdir -p package-root/DEBIAN
|
||||
cat > package-root/DEBIAN/conffiles <<'EOF'
|
||||
/etc/nipovpn/config.yaml
|
||||
EOF
|
||||
|
||||
rm -f package-root/var/log/nipovpn/nipovpn.log
|
||||
mkdir -p package-root/var/log/nipovpn
|
||||
|
||||
cat > package-root/DEBIAN/postinst <<'EOF'
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
mkdir -p /var/log/nipovpn
|
||||
|
||||
if [ ! -f /var/log/nipovpn/nipovpn.log ]; then
|
||||
touch /var/log/nipovpn/nipovpn.log
|
||||
chmod 0644 /var/log/nipovpn/nipovpn.log
|
||||
fi
|
||||
|
||||
exit 0
|
||||
EOF
|
||||
|
||||
chmod 755 package-root/DEBIAN/postinst
|
||||
|
||||
echo "Final control file:"
|
||||
cat package-root/DEBIAN/control
|
||||
|
||||
@@ -164,32 +187,46 @@ jobs:
|
||||
texinfo \
|
||||
jq
|
||||
|
||||
- name: Install Android NDK r29
|
||||
- name: Clone termux-packages
|
||||
run: |
|
||||
git clone --depth=1 https://github.com/termux/termux-packages.git
|
||||
|
||||
- name: Install Android NDK required by termux-packages
|
||||
run: |
|
||||
NDK_NUM="$(sed -n 's/^: "${TERMUX_NDK_VERSION_NUM:="\([0-9]*\)"}"/\1/p' termux-packages/scripts/properties.sh)"
|
||||
NDK_REV="$(sed -n 's/^: "${TERMUX_NDK_REVISION:="\([a-z]*\)"}"/\1/p' termux-packages/scripts/properties.sh)"
|
||||
|
||||
if [ -z "$NDK_NUM" ]; then
|
||||
echo "Could not read the NDK version from termux-packages/scripts/properties.sh"
|
||||
grep -n NDK termux-packages/scripts/properties.sh || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NDK_VERSION="r${NDK_NUM}${NDK_REV}"
|
||||
echo "termux-packages requires Android NDK $NDK_VERSION"
|
||||
|
||||
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
|
||||
wget -q "https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-linux.zip"
|
||||
unzip -q "android-ndk-${NDK_VERSION}-linux.zip"
|
||||
|
||||
EXTRACTED_DIR="$(find "$HOME/lib" -maxdepth 1 -type d -name 'android-ndk-r29*' | head -n 1)"
|
||||
EXTRACTED_DIR="$(find "$HOME/lib" -maxdepth 1 -type d -name "android-ndk-${NDK_VERSION}*" | head -n 1)"
|
||||
|
||||
if [ -z "$EXTRACTED_DIR" ]; then
|
||||
echo "Android NDK r29 directory not found"
|
||||
echo "Android NDK $NDK_VERSION directory not found"
|
||||
ls -lah "$HOME/lib"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ln -sfn "$EXTRACTED_DIR" "$HOME/lib/android-ndk-r29"
|
||||
if [ "$EXTRACTED_DIR" != "$HOME/lib/android-ndk-${NDK_VERSION}" ]; then
|
||||
ln -sfn "$EXTRACTED_DIR" "$HOME/lib/android-ndk-${NDK_VERSION}"
|
||||
fi
|
||||
|
||||
echo "NDK=$HOME/lib/android-ndk-r29" >> "$GITHUB_ENV"
|
||||
echo "ANDROID_NDK_ROOT=$HOME/lib/android-ndk-r29" >> "$GITHUB_ENV"
|
||||
echo "NDK=$HOME/lib/android-ndk-${NDK_VERSION}" >> "$GITHUB_ENV"
|
||||
echo "ANDROID_NDK_ROOT=$HOME/lib/android-ndk-${NDK_VERSION}" >> "$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
|
||||
ls -ld "$HOME/lib/android-ndk-${NDK_VERSION}"
|
||||
|
||||
- name: Create Termux package recipe
|
||||
run: |
|
||||
@@ -285,7 +322,7 @@ jobs:
|
||||
run: |
|
||||
ls -lah
|
||||
|
||||
- name: Create GitHub Release
|
||||
- name: Create main GitHub Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: v${{ env.PACKAGE_VERSION }}
|
||||
@@ -296,4 +333,4 @@ jobs:
|
||||
nipovpn_${{ env.PACKAGE_VERSION }}_arm64.deb
|
||||
nipovpn_${{ env.PACKAGE_VERSION }}_termux_aarch64.deb
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
@@ -15,7 +15,7 @@ permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
PACKAGE_VERSION: 1.1.56
|
||||
PACKAGE_VERSION: 1.1.60
|
||||
|
||||
jobs:
|
||||
build-windows:
|
||||
|
||||
@@ -37,3 +37,10 @@ build
|
||||
.idea
|
||||
/cmake-build-debug/
|
||||
test
|
||||
|
||||
|
||||
.git
|
||||
.github
|
||||
*.deb
|
||||
*.tar.gz
|
||||
*.log
|
||||
@@ -1,74 +1,342 @@
|
||||
# NipoVPN
|
||||
|
||||
## Overview
|
||||
NipoVPN is a proxy that hides your traffic inside ordinary-looking HTTP requests.
|
||||
It runs in two roles: an **agent** on your side and a **server** outside the
|
||||
censored or monitored network. The agent wraps each request in a decoy HTTP
|
||||
request (random method, endpoint and `Host`), optionally encrypts it with
|
||||
AES-256-GCM and sends it over TLS. The server unwraps it, talks to the real
|
||||
destination and sends the response back the same way.
|
||||
|
||||
NipoVPN is a powerful proxy tool designed to conceal your HTTP requests within fake HTTP requests. This program, written in C++, leverages the Boost library to handle networking functionalities efficiently.
|
||||
It is written in C++20 on top of Boost.Asio, OpenSSL and yaml-cpp.
|
||||
|
||||
- [Features](#features)
|
||||
- [How it works](#how-it-works)
|
||||
- [Installation](#installation)
|
||||
- [Quick start](#quick-start)
|
||||
- [Configuration reference](#configuration-reference)
|
||||
- [Security notes](#security-notes)
|
||||
- [Logging](#logging)
|
||||
- [Troubleshooting](#troubleshooting)
|
||||
- [Contribution](#contribution)
|
||||
- [License](#license)
|
||||
|
||||
## Features
|
||||
|
||||
- HTTP Request Obfuscation: Hide your legitimate HTTP requests inside decoy requests to avoid detection.
|
||||
- Boost Library Integration: Utilizes Boost for robust and reliable networking operations.
|
||||
- High Performance: Optimized for speed and efficiency, ensuring minimal impact on request latency.
|
||||
### Client side (agent)
|
||||
|
||||
- **HTTP proxy and SOCKS5 proxy** for local applications (`general.protocol`).
|
||||
- HTTP: plain HTTP requests and `CONNECT` tunnels (HTTPS).
|
||||
- SOCKS5: `CONNECT` command, no authentication, with IPv4, IPv6 and domain
|
||||
name targets.
|
||||
- **Multiple agents per server.** Each agent session is identified by a UUID, so
|
||||
many agents (and many clients behind each agent) can share one server.
|
||||
- **Multi-threaded.** The number of worker threads is configurable for the agent
|
||||
and the server separately.
|
||||
|
||||
## Usecases
|
||||
### Traffic obfuscation
|
||||
|
||||
### Bypass filtering
|
||||
This could help you to bypass the filtering in your country.
|
||||
- **Decoy HTTP requests.** Every request between the agent and server is a
|
||||
normal HTTP request whose method, path and `Host` header are picked at random
|
||||
from lists you configure (`methods`, `endPoints`, `fakeUrls`).
|
||||
- **Configurable `User-Agent` and HTTP version** for the decoy requests.
|
||||
- **Randomized TLS SNI.** With TLS enabled, the SNI sent to the server is also
|
||||
picked at random from `fakeUrls`.
|
||||
- **Hidden control data.** The session ID and action travel inside the
|
||||
(encrypted) body, not in custom headers, so the outer request carries no
|
||||
NipoVPN-specific headers.
|
||||
|
||||
### Encryption
|
||||
|
||||
- **AES-256-GCM payload encryption** (on by default). The key is the SHA-256 of
|
||||
`general.token`; each message gets a random 12-byte nonce and a 16-byte
|
||||
authentication tag, so tampered or wrongly keyed payloads are rejected.
|
||||
- **TLS between agent and server** (`tlsEnable`): TLS 1.2 minimum, TLS 1.3
|
||||
preferred, with AEAD-only cipher suites (AES-GCM, ChaCha20-Poly1305).
|
||||
- **Optional certificate verification** on the agent (`tlsVerifyPeer`) against
|
||||
a custom CA (`tlsCaFile`).
|
||||
|
||||
AES and TLS are independent: you can use either, both, or (not recommended)
|
||||
neither.
|
||||
|
||||
### Connection handling
|
||||
|
||||
- **Two tunnel modes** for `CONNECT`/SOCKS5 traffic:
|
||||
- **Polling mode** (default, `tunnelEnable: false`): every chunk of tunneled
|
||||
data is sent as its own decoy HTTP request (`send`), and the agent polls the
|
||||
server for incoming data (`recv`). Traffic looks like many short HTTP
|
||||
requests. Polling backs off from `pullTimeout` up to 50 ms while idle and
|
||||
snaps back as soon as data arrives.
|
||||
- **Direct tunnel mode** (`tunnelEnable: true`): after the first decoy
|
||||
request, the agent–server connection becomes a raw byte pipe to the
|
||||
destination. Faster, but only the opening request is disguised and
|
||||
encrypted. Use it together with `tlsEnable`.
|
||||
- **Connection reuse** (`connectionReuse`): keep one keep-alive connection
|
||||
between agent and server instead of opening a new one per request.
|
||||
- **Timeouts**: an I/O timeout that closes stalled connections (`timeout`) and
|
||||
a configurable buffer size per read (`bufferSize`).
|
||||
|
||||
### Operations
|
||||
|
||||
- **Config validation at startup** with clear error messages.
|
||||
- **Warning when the public sample token is still in use.**
|
||||
- **Log levels** `INFO`, `TRACE` (per-request source/destination) and `DEBUG`;
|
||||
logs go to a file and to stdout.
|
||||
- **Packaging**: `.deb` packages (amd64, arm64) with systemd units, a Docker
|
||||
image and compose file, a Nix flake with a NixOS module, a Termux package,
|
||||
Windows (x86_64) builds and an [Android app](https://github.com/MortezaBashsiz/nipovpn-android).
|
||||
|
||||
## How it works
|
||||
|
||||
### Use cases
|
||||
|
||||
**Bypass filtering.** Run the server outside the filtered network and the agent
|
||||
inside it. Filtering equipment sees only HTTP(S) requests to harmless-looking
|
||||
hosts.
|
||||
|
||||

|
||||
|
||||
### Hide your requests in the Internet
|
||||
If you want to hide your HTTP requests in the Internet, this proxy could help you.
|
||||
**Hide your requests on the Internet.** Even without censorship, NipoVPN hides
|
||||
which sites you visit from anyone watching your connection.
|
||||
|
||||

|
||||
|
||||
## Flow
|
||||
Here you can see the logical flow of a single request from first step to get the response
|
||||
### Request flow
|
||||
|
||||
```
|
||||
Browser/app ──HTTP or SOCKS5──▶ Agent ──decoy HTTP(S)──▶ Server ──real request──▶ Destination
|
||||
◀────────────────── ◀──────────────── ◀────────────────
|
||||
```
|
||||
|
||||
1. A local application sends a request to the agent (HTTP proxy or SOCKS5).
|
||||
SOCKS5 requests are converted to an HTTP `CONNECT` internally.
|
||||
2. The agent builds an envelope `action + session ID + request bytes`, encrypts
|
||||
it with AES-256-GCM (if `aesEnable`) and Base64-encodes it.
|
||||
3. The envelope is sent as the body of a decoy request such as
|
||||
`PUT /login` with `Host: cloudflare.com`, over TLS if `tlsEnable`.
|
||||
4. The server decodes and decrypts the body and performs the action:
|
||||
- `request` — forward a plain HTTP request and return the response.
|
||||
- `open` — open a TCP connection to the `CONNECT` target.
|
||||
- `send` / `recv` — write to / read from that connection (polling mode).
|
||||
- `close` — close the connection.
|
||||
5. The server's reply is encrypted and returned as the body of an HTTP
|
||||
`200 OK` response; the agent decrypts it and hands it to the application.
|
||||
|
||||

|
||||
|
||||
## Installation
|
||||
|
||||
| Platform | How |
|
||||
|---|---|
|
||||
| Debian / Ubuntu (amd64, arm64) | `.deb` from the [releases page](https://github.com/MortezaBashsiz/nipovpn/releases), tested on Ubuntu 24.04 |
|
||||
| Build from source on Linux | [Linux build guide](guides/BuildLinux.md) |
|
||||
| Docker | [Docker guide](guides/Docker.md) |
|
||||
| Nix / NixOS | [Nix guide](guides/Nix.md) |
|
||||
| Termux | [Termux guide](guides/InstallTermux.md) |
|
||||
| Windows (x86_64) | zip from the [releases page](https://github.com/MortezaBashsiz/nipovpn/releases) (`windows-v*` tags) |
|
||||
| Android | [nipovpn-android](https://github.com/MortezaBashsiz/nipovpn-android) |
|
||||
|
||||
### Debian package
|
||||
|
||||
```bash
|
||||
sudo apt install ./nipovpn.deb
|
||||
```
|
||||
|
||||
The package installs:
|
||||
|
||||
- `/usr/bin/nipovpn`
|
||||
- `/etc/nipovpn/config.yaml` (kept on upgrade)
|
||||
- `nipovpn-server.service` and `nipovpn-agent.service`
|
||||
|
||||
```bash
|
||||
sudo systemctl enable --now nipovpn-server.service # on the server
|
||||
sudo systemctl enable --now nipovpn-agent.service # on the agent machine
|
||||
```
|
||||
|
||||
### From source
|
||||
|
||||
Requirements: a C++20 compiler, CMake ≥ 3.22, Boost ≥ 1.88, yaml-cpp ≥ 0.8 and
|
||||
OpenSSL. See the [Linux build guide](guides/BuildLinux.md) for details.
|
||||
|
||||
```bash
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -B build
|
||||
cmake --build build -j$(nproc)
|
||||
```
|
||||
|
||||
## Quick start
|
||||
|
||||
The same binary and the same config file format are used on both sides; the
|
||||
first argument selects the role:
|
||||
|
||||
```bash
|
||||
nipovpn <server|agent> <config_file_path>
|
||||
```
|
||||
|
||||
### 1. Prepare the log file
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /var/log/nipovpn/
|
||||
sudo touch /var/log/nipovpn/nipovpn.log
|
||||
```
|
||||
|
||||
### 2. Pick a shared token
|
||||
|
||||
`general.token` must be at least 32 bytes and identical on the agent and the
|
||||
server. Do not use the sample token from the shipped config.
|
||||
|
||||
```bash
|
||||
openssl rand -hex 16 # prints 32 hex characters
|
||||
```
|
||||
|
||||
### 3. TLS certificate (if `tlsEnable: true`)
|
||||
|
||||
The server needs a certificate and key. A self-signed pair is enough when
|
||||
`tlsVerifyPeer` is `false`:
|
||||
|
||||
```bash
|
||||
sudo openssl req -x509 -newkey rsa:2048 -nodes -days 3650 \
|
||||
-subj "/CN=example.com" \
|
||||
-keyout /etc/nipovpn/server.key -out /etc/nipovpn/server.crt
|
||||
```
|
||||
|
||||
### 4. Run the server
|
||||
|
||||
On the server, set `server.listenIp`/`server.listenPort`, then:
|
||||
|
||||
```bash
|
||||
sudo nipovpn server /etc/nipovpn/config.yaml
|
||||
```
|
||||
|
||||
### 5. Run the agent
|
||||
|
||||
On your machine, set `agent.serverIp`/`agent.serverPort` to the server's
|
||||
address and make sure `token`, `aesEnable`, `tlsEnable` and `tunnelEnable` match
|
||||
the server. Then:
|
||||
|
||||
```bash
|
||||
sudo nipovpn agent /etc/nipovpn/config.yaml
|
||||
```
|
||||
|
||||
### 6. Point your applications at the agent
|
||||
|
||||
```bash
|
||||
# protocol: socks5
|
||||
curl --socks5-hostname 127.0.0.1:8080 https://example.com
|
||||
|
||||
# protocol: http
|
||||
curl -x http://127.0.0.1:8080 https://example.com
|
||||
```
|
||||
|
||||
Or configure the agent's address as the SOCKS5/HTTP proxy in your browser or
|
||||
operating system.
|
||||
|
||||
## Configuration reference
|
||||
|
||||
The sample config lives at [nipovpn/etc/nipovpn/config.yaml](nipovpn/etc/nipovpn/config.yaml).
|
||||
Settings marked **must match** have to be the same on agent and server.
|
||||
|
||||
### `general`
|
||||
|
||||
| Key | Type | Default | Description |
|
||||
|---|---|---|---|
|
||||
| `token` | string | — | Shared secret, ≥ 32 bytes when `aesEnable` is on. The AES key is derived from it. **Must match.** |
|
||||
| `aesEnable` | bool | `true` | AES-256-GCM payload encryption. **Must match.** |
|
||||
| `protocol` | `http` \| `socks5` | — | Protocol the agent accepts from local applications. |
|
||||
| `bufferSize` | 1–65536 | `65536` | Maximum bytes read per operation. |
|
||||
| `fakeUrls` | list | — | Hosts used at random for the decoy `Host` header and TLS SNI. |
|
||||
| `methods` | list | — | HTTP methods used at random for decoy requests. |
|
||||
| `endPoints` | list | — | URL paths used at random for decoy requests (`/api`, `/login`, ...). |
|
||||
| `timeout` | seconds | `10` | I/O timeout for stalled connections. `0` disables it. |
|
||||
| `pullTimeout` | milliseconds | `1` | Base polling interval in polling mode. |
|
||||
| `tunnelEnable` | bool | `false` | `true` = direct tunnel mode, `false` = polling mode. **Must match.** |
|
||||
| `connectionReuse` | bool | `false` | Reuse one keep-alive connection between agent and server. |
|
||||
| `tlsEnable` | bool | `false` | TLS between agent and server. **Must match.** |
|
||||
| `tlsVerifyPeer` | bool | `false` | Agent verifies the server certificate. |
|
||||
| `tlsCertFile` | path | — | Server certificate (PEM, chain allowed). |
|
||||
| `tlsKeyFile` | path | — | Server private key (PEM). |
|
||||
| `tlsCaFile` | path | — | CA file the agent uses when `tlsVerifyPeer` is on. |
|
||||
|
||||
### `log`
|
||||
|
||||
| Key | Default | Description |
|
||||
|---|---|---|
|
||||
| `logLevel` | `INFO` | `INFO`, `TRACE` or `DEBUG`. Errors are always logged. |
|
||||
| `logFile` | — | Log file path. The directory and file must exist. |
|
||||
|
||||
### `server`
|
||||
|
||||
| Key | Default | Description |
|
||||
|---|---|---|
|
||||
| `threads` | `2` | Worker threads. |
|
||||
| `listenIp` | `127.0.0.1` | IPv4 address to listen on. |
|
||||
| `listenPort` | `8080` | Port to listen on (443 is a good choice to blend in). |
|
||||
|
||||
### `agent`
|
||||
|
||||
| Key | Default | Description |
|
||||
|---|---|---|
|
||||
| `threads` | `2` | Worker threads. |
|
||||
| `listenIp` | `127.0.0.1` | IPv4 address for local applications to connect to. |
|
||||
| `listenPort` | `8080` | Port for local applications. |
|
||||
| `serverIp` | `127.0.0.1` | IPv4 address of the NipoVPN server. |
|
||||
| `serverPort` | `8080` | Port of the NipoVPN server. |
|
||||
| `httpVersion` | `1.1` | HTTP version in decoy requests. |
|
||||
| `userAgent` | `NipoAgent` | `User-Agent` header in decoy requests. |
|
||||
|
||||
## Security notes
|
||||
|
||||
- **Change the token.** The sample token is public; the program logs a warning
|
||||
if it is still in use.
|
||||
- **Turn on at least one of `aesEnable` and `tlsEnable`.** Without either,
|
||||
traffic is only obfuscated, not encrypted.
|
||||
- **Direct tunnel mode** sends tunneled bytes without the decoy framing or AES,
|
||||
so pair it with `tlsEnable: true`.
|
||||
- **`tlsVerifyPeer: false`** protects against passive observers but not against
|
||||
an active man-in-the-middle. Enable it with a proper `tlsCaFile` if that
|
||||
matters to you. AES-GCM with a strong token still authenticates the payload.
|
||||
- **Listening on `0.0.0.0` on the agent** exposes your proxy to the local
|
||||
network. Use `127.0.0.1` unless you mean to share it.
|
||||
|
||||
> **Protocol change:** this version uses AES-256-GCM and carries the session and
|
||||
> action inside the encrypted body instead of `X-Nipo-*` headers. It is not
|
||||
> compatible with older agents, servers or the Android app; upgrade all of them
|
||||
> together.
|
||||
|
||||
## Logging
|
||||
|
||||
Log lines look like:
|
||||
|
||||
```
|
||||
2026-01-01_12:00:00 [AGENT] [INFO] [<session-uuid>] [CONNECT] [SRC 127.0.0.1:51234] [ORIGIN example.com:443]
|
||||
```
|
||||
|
||||
- `INFO`: startup, effective configuration (token hidden), connections opened.
|
||||
- `TRACE`: adds the destination of every forwarded request.
|
||||
- `DEBUG`: adds handshake, encryption and byte-level details. Use only for
|
||||
troubleshooting.
|
||||
|
||||
```bash
|
||||
tail -f /var/log/nipovpn/nipovpn.log
|
||||
journalctl -u nipovpn-server.service -f
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
| Symptom | Likely cause |
|
||||
|---|---|
|
||||
| `Configuration validation failed: ...` | A required key is missing or invalid; the message names the block. |
|
||||
| `token must be at least 32 bytes when aesEnable is true` | Use a longer token (`openssl rand -hex 16`). |
|
||||
| `Error opening log file` | Create the log directory and file (see Quick start). |
|
||||
| Server logs `Decryption Failed` / `Invalid Envelope` | `token`, `aesEnable` or NipoVPN versions differ between agent and server. |
|
||||
| Agent logs `[TLS] [ERROR]` | `tlsEnable` differs between the two sides, or the certificate/key path is wrong. |
|
||||
| `[CONNECT] [ERROR] [To Server]` | Agent cannot reach `serverIp:serverPort` (firewall, wrong address, server not running). |
|
||||
|
||||
## Contribution
|
||||
To contribute take a look at [contribution page](https://github.com/MortezaBashsiz/nipovpn/blob/main/CONTRIBUTING.md).
|
||||
|
||||
## Build
|
||||
See the [contribution guide](CONTRIBUTING.md). In short: branch from `dev`,
|
||||
format with `scripts/format.sh`, build and test, and open a pull request against
|
||||
`dev`.
|
||||
|
||||
Build from source for [Linux](guides/BuildLinux.md)
|
||||
## License
|
||||
|
||||
## Termux
|
||||
NipoVPN is released under the [GNU General Public License v3.0](LICENSE).
|
||||
|
||||
Build from source for [Linux](guides/InstallTermux.md)
|
||||
|
||||
|
||||
## Run
|
||||
|
||||
#### Create directories
|
||||
Create the log directory and log file
|
||||
```bash
|
||||
[~/nipovpn]>$ sudo mkdir /var/log/nipovpn/
|
||||
[~/nipovpn]>$ sudo touch /var/log/nipovpn/nipovpn.log
|
||||
```
|
||||
|
||||
Run it
|
||||
```bash
|
||||
sudo build/core/nipovpn server nipovpn/etc/nipovpn/config.yaml
|
||||
```
|
||||
|
||||
### Package
|
||||
|
||||
#### Install
|
||||
Currently it is only available for debian-based Linuxes and fully tested on ubuntu 24.04
|
||||
You can simply download and install the package. To download it please visit the [releases page](https://github.com/MortezaBashsiz/nipovpn/tags) and get the latest release.
|
||||
```bash
|
||||
[~]>$ sudo apt install ./nipovpn.deb
|
||||
```
|
||||
|
||||
#### Run
|
||||
There are systemd services to manage the nipovpn process.
|
||||
`nipovpn-server.service` to manage as server.
|
||||
`nipovpn-agent.service` to manage as agent.
|
||||
```bash
|
||||
[~]>$ sudo systemctl start nipovpn-server.service
|
||||
[~]>$ cat /var/log/nipovpn/nipovpn.log
|
||||
```
|
||||
+16
-12
@@ -62,8 +62,7 @@ void AgentHandler::handle() {
|
||||
return;
|
||||
} else {
|
||||
log_->write("[" + to_string(uuid_) + "] [CONNECT] [SRC " +
|
||||
clientConnStr_ + "] [DST " + config_->agent().serverIp + ":" +
|
||||
std::to_string(config_->agent().serverPort) + "]",
|
||||
clientConnStr_ + "] [ORIGIN " + std::string(request_->parsedHttpRequest().target()) + "]",
|
||||
Log::Level::INFO);
|
||||
}
|
||||
|
||||
@@ -77,8 +76,15 @@ void AgentHandler::handle() {
|
||||
}
|
||||
}
|
||||
|
||||
const std::string action =
|
||||
request_->httpType() == HTTP::HttpType::connect ? "open" : "request";
|
||||
|
||||
BoolStr encryption{false, std::string("FAILED")};
|
||||
encryption = aes256Encrypt(hexStreambufToStr(readBuffer_), config_->general().token);
|
||||
const std::string payload =
|
||||
makeEnvelope(action, to_string(uuid_), hexStreambufToStr(readBuffer_));
|
||||
encryption = config_->general().aesEnable
|
||||
? aes256Encrypt(payload, config_->general().token)
|
||||
: BoolStr{true, payload};
|
||||
if (!encryption.ok) {
|
||||
log_->write("[" + to_string(uuid_) + "] [AgentHandler handle] [Encryption Failed] : [ " +
|
||||
encryption.message + "] ",
|
||||
@@ -88,8 +94,6 @@ void AgentHandler::handle() {
|
||||
}
|
||||
|
||||
const std::string innerRequest = encode64(encryption.message);
|
||||
const std::string action =
|
||||
request_->httpType() == HTTP::HttpType::connect ? "open" : "request";
|
||||
|
||||
std::ostringstream outer;
|
||||
const bool directTunnelOpen =
|
||||
@@ -100,9 +104,7 @@ void AgentHandler::handle() {
|
||||
<< "Host: " << relayHostHeader(config_) << "\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-Type: text/plain; charset=utf-8\r\n"
|
||||
<< "Content-Length: " << innerRequest.size() << "\r\n"
|
||||
<< "Connection: "
|
||||
<< ((config_->general().connectionReuse || directTunnelOpen) ? "keep-alive" : "close")
|
||||
@@ -130,14 +132,16 @@ void AgentHandler::handle() {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string encryptedBody = outerResponse.substr(bodyPos + 4);
|
||||
if (encryptedBody.empty()) {
|
||||
const std::string responseBody = outerResponse.substr(bodyPos + 4);
|
||||
if (responseBody.empty()) {
|
||||
client_->socketShutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
BoolStr decryption{false, std::string("FAILED")};
|
||||
decryption = aes256Decrypt(encryptedBody, config_->general().token);
|
||||
decryption = config_->general().aesEnable
|
||||
? aes256Decrypt(responseBody, config_->general().token)
|
||||
: BoolStr{true, responseBody};
|
||||
if (!decryption.ok) {
|
||||
log_->write("[" + to_string(uuid_) + "] [AgentHandler handle] [Decryption Failed] : [ " +
|
||||
decryption.message + "] ",
|
||||
@@ -147,7 +151,7 @@ void AgentHandler::handle() {
|
||||
}
|
||||
|
||||
copyStringToStreambuf(decryption.message, writeBuffer_);
|
||||
log_->write("[" + to_string(uuid_) + "] [AgentHandler handle] [Decryption Done]",
|
||||
log_->write("[" + to_string(uuid_) + "] [AgentHandler handle] [Payload Decoded]",
|
||||
Log::Level::DEBUG);
|
||||
|
||||
connect_ = request_->httpType() == HTTP::HttpType::connect;
|
||||
|
||||
+18
-14
@@ -10,30 +10,32 @@ Config::Config(RunMode mode, const std::string &filePath)
|
||||
listenPort_(0),
|
||||
general_({configYaml_["general"]["token"].as<std::string>(),
|
||||
configYaml_["general"]["protocol"].as<std::string>(""),
|
||||
configYaml_["general"]["bufferSize"].as<unsigned int>(65536),
|
||||
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"]["timeout"].as<unsigned short>(10),
|
||||
configYaml_["general"]["pullTimeout"].as<unsigned short>(1),
|
||||
configYaml_["general"]["tunnelEnable"].as<bool>(false),
|
||||
configYaml_["general"]["connectionReuse"].as<bool>(false),
|
||||
configYaml_["general"]["aesEnable"].as<bool>(true),
|
||||
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>(),
|
||||
log_({configYaml_["log"]["logLevel"].as<std::string>("INFO"),
|
||||
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>()}),
|
||||
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>()}) {
|
||||
server_({configYaml_["server"]["threads"].as<unsigned short>(2),
|
||||
configYaml_["server"]["listenIp"].as<std::string>("127.0.0.1"),
|
||||
configYaml_["server"]["listenPort"].as<unsigned short>(8080)}),
|
||||
agent_({configYaml_["agent"]["threads"].as<unsigned short>(2),
|
||||
configYaml_["agent"]["listenIp"].as<std::string>("127.0.0.1"),
|
||||
configYaml_["agent"]["listenPort"].as<unsigned short>(8080),
|
||||
configYaml_["agent"]["serverIp"].as<std::string>("127.0.0.1"),
|
||||
configYaml_["agent"]["serverPort"].as<unsigned short>(8080),
|
||||
configYaml_["agent"]["httpVersion"].as<std::string>("1.1"),
|
||||
configYaml_["agent"]["userAgent"].as<std::string>("NipoAgent")}) {
|
||||
|
||||
std::lock_guard<std::mutex> lock(configMutex_);
|
||||
|
||||
@@ -73,8 +75,9 @@ std::string Config::toString() const {
|
||||
|
||||
ss << "\nConfig :\n"
|
||||
<< " General :\n"
|
||||
<< " token: " << general_.token << "\n"
|
||||
<< " token: " << (general_.token.empty() ? "" : "<hidden>") << "\n"
|
||||
<< " protocol: " << general_.protocol << "\n"
|
||||
<< " bufferSize: " << general_.bufferSize << "\n"
|
||||
<< " fakeUrls: ";
|
||||
|
||||
for (std::size_t i = 0; i < general_.fakeUrls.size(); ++i) {
|
||||
@@ -112,6 +115,7 @@ std::string Config::toString() const {
|
||||
<< " pullTimeout: " << general_.pullTimeout << "\n"
|
||||
<< " tunnelEnable: " << std::boolalpha << general_.tunnelEnable << "\n"
|
||||
<< " connectionReuse: " << std::boolalpha << general_.connectionReuse << "\n"
|
||||
<< " aesEnable: " << std::boolalpha << general_.aesEnable << "\n"
|
||||
<< " tlsEnable: " << std::boolalpha << general_.tlsEnable << "\n"
|
||||
<< " tlsVerifyPeer: " << std::boolalpha << general_.tlsVerifyPeer << "\n"
|
||||
<< " tlsCertFile: " << general_.tlsCertFile << "\n"
|
||||
|
||||
@@ -21,6 +21,7 @@ private:
|
||||
struct General {
|
||||
std::string token;
|
||||
std::string protocol;
|
||||
unsigned int bufferSize;
|
||||
std::vector<std::string> fakeUrls;
|
||||
std::vector<std::string> methods;
|
||||
std::vector<std::string> endPoints;
|
||||
@@ -28,6 +29,7 @@ private:
|
||||
unsigned short pullTimeout;
|
||||
bool tunnelEnable;
|
||||
bool connectionReuse;
|
||||
bool aesEnable;
|
||||
bool tlsEnable;
|
||||
bool tlsVerifyPeer;
|
||||
std::string tlsCertFile;
|
||||
|
||||
+103
-36
@@ -24,7 +24,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
static constexpr std::size_t BufferSize = 8192;
|
||||
static constexpr std::size_t BufferSize = 65536;
|
||||
static constexpr std::size_t MinTokenLength = 32;
|
||||
static constexpr const char *SampleToken = "af445adb-2434-4975-9445-2c1b2231";
|
||||
|
||||
class Uncopyable {
|
||||
public:
|
||||
@@ -184,19 +186,29 @@ inline std::string encode64(const std::string &inputStr) {
|
||||
return encoded;
|
||||
}
|
||||
|
||||
static constexpr std::size_t AesGcmNonceLength = 12;
|
||||
static constexpr std::size_t AesGcmTagLength = 16;
|
||||
|
||||
inline std::string deriveAesKey(const std::string &token) {
|
||||
unsigned char digest[EVP_MAX_MD_SIZE];
|
||||
unsigned int digestLen = 0;
|
||||
EVP_Digest(token.data(), token.size(), digest, &digestLen, EVP_sha256(), NULL);
|
||||
return std::string(reinterpret_cast<char *>(digest), digestLen);
|
||||
}
|
||||
|
||||
inline BoolStr aes256Encrypt(const std::string &plaintext,
|
||||
const std::string &key) {
|
||||
const std::string &token) {
|
||||
BoolStr result{false, "Encryption failed"};
|
||||
|
||||
unsigned char iv[EVP_MAX_IV_LENGTH];
|
||||
if (!RAND_bytes(iv, sizeof(iv))) {
|
||||
result.message = "IV generation failed";
|
||||
const std::string key = deriveAesKey(token);
|
||||
|
||||
unsigned char nonce[AesGcmNonceLength];
|
||||
if (!RAND_bytes(nonce, sizeof(nonce))) {
|
||||
result.message = "Nonce generation failed";
|
||||
return result;
|
||||
}
|
||||
|
||||
int ciphertext_len =
|
||||
plaintext.size() + EVP_CIPHER_block_size(EVP_aes_256_cbc());
|
||||
std::vector<unsigned char> ciphertext(ciphertext_len);
|
||||
std::vector<unsigned char> ciphertext(plaintext.size());
|
||||
|
||||
using EvpCipherCtxPtr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
|
||||
EvpCipherCtxPtr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
|
||||
@@ -205,22 +217,24 @@ inline BoolStr aes256Encrypt(const std::string &plaintext,
|
||||
return result;
|
||||
}
|
||||
|
||||
if (EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_cbc(), NULL,
|
||||
reinterpret_cast<const unsigned char *>(key.c_str()),
|
||||
iv) != 1) {
|
||||
if (EVP_EncryptInit_ex(ctx.get(), EVP_aes_256_gcm(), NULL, NULL, NULL) != 1 ||
|
||||
EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_SET_IVLEN, AesGcmNonceLength, NULL) != 1 ||
|
||||
EVP_EncryptInit_ex(ctx.get(), NULL, NULL,
|
||||
reinterpret_cast<const unsigned char *>(key.data()),
|
||||
nonce) != 1) {
|
||||
result.message = "Encryption initialization failed";
|
||||
return result;
|
||||
}
|
||||
|
||||
int len;
|
||||
int len = 0;
|
||||
if (EVP_EncryptUpdate(
|
||||
ctx.get(), ciphertext.data(), &len,
|
||||
reinterpret_cast<const unsigned char *>(plaintext.c_str()),
|
||||
reinterpret_cast<const unsigned char *>(plaintext.data()),
|
||||
plaintext.size()) != 1) {
|
||||
result.message = "Encryption update failed";
|
||||
return result;
|
||||
}
|
||||
ciphertext_len = len;
|
||||
int ciphertext_len = len;
|
||||
|
||||
if (EVP_EncryptFinal_ex(ctx.get(), ciphertext.data() + len, &len) != 1) {
|
||||
result.message = "Encryption finalization failed";
|
||||
@@ -228,28 +242,38 @@ inline BoolStr aes256Encrypt(const std::string &plaintext,
|
||||
}
|
||||
ciphertext_len += len;
|
||||
|
||||
std::string final_result(reinterpret_cast<char *>(iv), sizeof(iv));
|
||||
final_result.append(reinterpret_cast<char *>(ciphertext.data()),
|
||||
ciphertext_len);
|
||||
unsigned char tag[AesGcmTagLength];
|
||||
if (EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_GET_TAG, AesGcmTagLength, tag) != 1) {
|
||||
result.message = "Tag generation failed";
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string final_result(reinterpret_cast<char *>(nonce), sizeof(nonce));
|
||||
final_result.append(reinterpret_cast<char *>(ciphertext.data()), ciphertext_len);
|
||||
final_result.append(reinterpret_cast<char *>(tag), sizeof(tag));
|
||||
|
||||
result.ok = true;
|
||||
result.message = final_result;
|
||||
return result;
|
||||
}
|
||||
|
||||
inline BoolStr aes256Decrypt(const std::string &ciphertext_with_iv,
|
||||
const std::string &key) {
|
||||
inline BoolStr aes256Decrypt(const std::string &sealed,
|
||||
const std::string &token) {
|
||||
BoolStr result{false, "Decryption failed"};
|
||||
|
||||
unsigned char iv[EVP_MAX_IV_LENGTH];
|
||||
std::memcpy(iv, ciphertext_with_iv.c_str(),
|
||||
EVP_CIPHER_iv_length(EVP_aes_256_cbc()));
|
||||
if (sealed.size() < AesGcmNonceLength + AesGcmTagLength) {
|
||||
result.message = "Ciphertext too short";
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string ciphertext =
|
||||
ciphertext_with_iv.substr(EVP_CIPHER_iv_length(EVP_aes_256_cbc()));
|
||||
const std::string key = deriveAesKey(token);
|
||||
|
||||
int max_plaintext_len = ciphertext.size();
|
||||
std::vector<unsigned char> plaintext(max_plaintext_len);
|
||||
const auto *nonce = reinterpret_cast<const unsigned char *>(sealed.data());
|
||||
const auto *ciphertext = nonce + AesGcmNonceLength;
|
||||
const std::size_t ciphertextLen = sealed.size() - AesGcmNonceLength - AesGcmTagLength;
|
||||
std::string tag = sealed.substr(sealed.size() - AesGcmTagLength);
|
||||
|
||||
std::vector<unsigned char> plaintext(ciphertextLen);
|
||||
|
||||
using EvpCipherCtxPtr = std::unique_ptr<EVP_CIPHER_CTX, decltype(&EVP_CIPHER_CTX_free)>;
|
||||
EvpCipherCtxPtr ctx(EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_free);
|
||||
@@ -258,25 +282,31 @@ inline BoolStr aes256Decrypt(const std::string &ciphertext_with_iv,
|
||||
return result;
|
||||
}
|
||||
|
||||
if (EVP_DecryptInit_ex(ctx.get(), EVP_aes_256_cbc(), NULL,
|
||||
reinterpret_cast<const unsigned char *>(key.c_str()),
|
||||
iv) != 1) {
|
||||
if (EVP_DecryptInit_ex(ctx.get(), EVP_aes_256_gcm(), NULL, NULL, NULL) != 1 ||
|
||||
EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_SET_IVLEN, AesGcmNonceLength, NULL) != 1 ||
|
||||
EVP_DecryptInit_ex(ctx.get(), NULL, NULL,
|
||||
reinterpret_cast<const unsigned char *>(key.data()),
|
||||
nonce) != 1) {
|
||||
result.message = "Decryption initialization failed";
|
||||
return result;
|
||||
}
|
||||
|
||||
int len;
|
||||
if (EVP_DecryptUpdate(
|
||||
ctx.get(), plaintext.data(), &len,
|
||||
reinterpret_cast<const unsigned char *>(ciphertext.c_str()),
|
||||
ciphertext.size()) != 1) {
|
||||
int len = 0;
|
||||
if (EVP_DecryptUpdate(ctx.get(), plaintext.data(), &len, ciphertext,
|
||||
ciphertextLen) != 1) {
|
||||
result.message = "Decryption update failed";
|
||||
return result;
|
||||
}
|
||||
int plaintext_len = len;
|
||||
|
||||
if (EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_SET_TAG, AesGcmTagLength,
|
||||
tag.data()) != 1) {
|
||||
result.message = "Setting tag failed";
|
||||
return result;
|
||||
}
|
||||
|
||||
if (EVP_DecryptFinal_ex(ctx.get(), plaintext.data() + len, &len) != 1) {
|
||||
result.message = "Decryption finalization failed";
|
||||
result.message = "Authentication failed (wrong token or tampered payload)";
|
||||
return result;
|
||||
}
|
||||
plaintext_len += len;
|
||||
@@ -288,6 +318,31 @@ inline BoolStr aes256Decrypt(const std::string &ciphertext_with_iv,
|
||||
return result;
|
||||
}
|
||||
|
||||
inline std::string makeEnvelope(const std::string &action,
|
||||
const std::string &session,
|
||||
const std::string &data) {
|
||||
return action + "\n" + session + "\n" + data;
|
||||
}
|
||||
|
||||
struct Envelope {
|
||||
std::string action;
|
||||
std::string session;
|
||||
std::string data;
|
||||
};
|
||||
|
||||
inline bool parseEnvelope(const std::string &raw, Envelope &out) {
|
||||
const auto actionEnd = raw.find('\n');
|
||||
if (actionEnd == std::string::npos) return false;
|
||||
|
||||
const auto sessionEnd = raw.find('\n', actionEnd + 1);
|
||||
if (sessionEnd == std::string::npos) return false;
|
||||
|
||||
out.action = raw.substr(0, actionEnd);
|
||||
out.session = raw.substr(actionEnd + 1, sessionEnd - actionEnd - 1);
|
||||
out.data = raw.substr(sessionEnd + 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline BoolStr validateConfig(int argc, const char *argv[]) {
|
||||
BoolStr result{false, "Validation failed"};
|
||||
|
||||
@@ -321,6 +376,7 @@ inline BoolStr validateConfig(int argc, const char *argv[]) {
|
||||
try {
|
||||
configYaml["general"]["token"].as<std::string>();
|
||||
configYaml["general"]["protocol"].as<std::string>();
|
||||
configYaml["general"]["bufferSize"].as<unsigned int>();
|
||||
configYaml["general"]["fakeUrls"].as<std::vector<std::string>>();
|
||||
configYaml["general"]["methods"].as<std::vector<std::string>>();
|
||||
configYaml["general"]["endPoints"].as<std::vector<std::string>>();
|
||||
@@ -361,7 +417,18 @@ inline BoolStr validateConfig(int argc, const char *argv[]) {
|
||||
}
|
||||
|
||||
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";
|
||||
result.message = "protocol must be one of [http|socks5]\n";
|
||||
return result;
|
||||
}
|
||||
|
||||
if (configYaml["general"]["bufferSize"].as<unsigned int>() < 1 || configYaml["general"]["bufferSize"].as<unsigned int>() > 65536) {
|
||||
result.message = "bufferSize must be between 1 and 65536\n";
|
||||
return result;
|
||||
}
|
||||
|
||||
if (configYaml["general"]["aesEnable"].as<bool>(true) &&
|
||||
configYaml["general"]["token"].as<std::string>().size() < MinTokenLength) {
|
||||
result.message = "token must be at least 32 bytes when aesEnable is true\n";
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -12,6 +12,9 @@ int main(int argc, char const *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string mode(argv[1]);
|
||||
RunMode runMode_ = (mode == "agent") ? RunMode::agent : RunMode::server;
|
||||
|
||||
BoolStr configValidation = validateConfig(argc, argv);
|
||||
if (!configValidation.ok) {
|
||||
std::cerr << "Configuration validation failed: " << configValidation.message
|
||||
@@ -19,9 +22,6 @@ int main(int argc, char const *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string mode(argv[1]);
|
||||
RunMode runMode_ = (mode == "agent") ? RunMode::agent : RunMode::server;
|
||||
|
||||
Config::pointer config_ = Config::create(runMode_, std::string(argv[2]));
|
||||
|
||||
Log::pointer log_ = Log::create(config_);
|
||||
|
||||
@@ -25,6 +25,13 @@ void Runner::run() {
|
||||
log_->write("Config initialized in " + config_->modeToString() + " mode", Log::Level::INFO);
|
||||
log_->write(config_->toString(), Log::Level::INFO);
|
||||
|
||||
if (config_->general().aesEnable && config_->general().token == SampleToken) {
|
||||
log_->write(
|
||||
"[WARNING] general.token is the public sample token; "
|
||||
"set a unique random token on both agent and server",
|
||||
Log::Level::ERROR);
|
||||
}
|
||||
|
||||
auto tcpServer = TCPServer::create(io_context_, config_, log_);
|
||||
|
||||
for (auto i = 0; i < config_->threads(); ++i) {
|
||||
|
||||
+46
-39
@@ -53,7 +53,7 @@ void ServerHandler::makePlainHttpResponse(const std::string &body,
|
||||
std::ostringstream outer;
|
||||
|
||||
outer << "HTTP/1.1 " << status << "\r\n"
|
||||
<< "Content-Type: application/text\r\n"
|
||||
<< "Content-Type: application/octet-stream\r\n"
|
||||
<< "Content-Length: " << body.size() << "\r\n"
|
||||
<< "Connection: " << connection << "\r\n"
|
||||
<< "\r\n"
|
||||
@@ -65,10 +65,12 @@ void ServerHandler::makePlainHttpResponse(const std::string &body,
|
||||
connect_ = false;
|
||||
}
|
||||
|
||||
void ServerHandler::makeEncryptedHttpResponse(const std::string &plainBody,
|
||||
const std::string &status,
|
||||
const std::string &connection) {
|
||||
BoolStr encryption = aes256Encrypt(plainBody, config_->general().token);
|
||||
void ServerHandler::makePayloadHttpResponse(const std::string &plainBody,
|
||||
const std::string &status,
|
||||
const std::string &connection) {
|
||||
BoolStr encryption = config_->general().aesEnable
|
||||
? aes256Encrypt(plainBody, config_->general().token)
|
||||
: BoolStr{true, plainBody};
|
||||
|
||||
if (!encryption.ok) {
|
||||
log_->write("[" + to_string(uuid_) + "] [ServerHandler] [Encryption Failed] " + encryption.message,
|
||||
@@ -98,17 +100,6 @@ void ServerHandler::handle() {
|
||||
const auto &outerReq = request_->parsedHttpRequest();
|
||||
|
||||
const std::string outerRaw = streambufToString(readBuffer_);
|
||||
const auto outerHeaderEnd = outerRaw.find("\r\n\r\n");
|
||||
const std::string outerHeaders =
|
||||
outerHeaderEnd == std::string::npos
|
||||
? ""
|
||||
: outerRaw.substr(0, outerHeaderEnd + 2);
|
||||
|
||||
const std::string session =
|
||||
HttpUtils::getRawHeader(outerHeaders, "X-Nipo-Session");
|
||||
|
||||
const std::string action =
|
||||
HttpUtils::getRawHeader(outerHeaders, "X-Nipo-Action");
|
||||
|
||||
std::string requestBody = std::string(outerReq.body());
|
||||
|
||||
@@ -119,9 +110,10 @@ void ServerHandler::handle() {
|
||||
BoolStr decryption{false, std::string("FAILED")};
|
||||
|
||||
try {
|
||||
decryption = aes256Decrypt(
|
||||
decode64(requestBody),
|
||||
config_->general().token);
|
||||
const std::string payload = decode64(requestBody);
|
||||
decryption = config_->general().aesEnable
|
||||
? aes256Decrypt(payload, config_->general().token)
|
||||
: BoolStr{true, payload};
|
||||
} catch (const std::exception &e) {
|
||||
log_->write(
|
||||
"[" + to_string(uuid_) +
|
||||
@@ -143,8 +135,23 @@ void ServerHandler::handle() {
|
||||
return;
|
||||
}
|
||||
|
||||
Envelope envelope;
|
||||
if (!parseEnvelope(decryption.message, envelope)) {
|
||||
log_->write(
|
||||
"[" + to_string(uuid_) +
|
||||
"] [ServerHandler handle] [Invalid Envelope] (agent and server versions or aesEnable may differ)",
|
||||
Log::Level::DEBUG);
|
||||
|
||||
makePlainHttpResponse("", "400 Bad Request", "close");
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string &action = envelope.action;
|
||||
const std::string &session = envelope.session;
|
||||
decryption.message = std::move(envelope.data);
|
||||
|
||||
log_->write(
|
||||
"[" + to_string(uuid_) + "] [ServerHandler handle] [Decryption Done]",
|
||||
"[" + to_string(uuid_) + "] [ServerHandler handle] [Payload Decoded]",
|
||||
Log::Level::DEBUG);
|
||||
|
||||
if (action == "send") {
|
||||
@@ -160,7 +167,7 @@ void ServerHandler::handle() {
|
||||
}
|
||||
|
||||
if (!targetClient || !targetClient->isOpen()) {
|
||||
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
makePayloadHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -168,7 +175,7 @@ void ServerHandler::handle() {
|
||||
copyStringToStreambuf(hexToASCII(decryption.message), tunnelBuf);
|
||||
targetClient->doWrite(tunnelBuf);
|
||||
|
||||
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
makePayloadHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -185,7 +192,7 @@ void ServerHandler::handle() {
|
||||
}
|
||||
|
||||
if (!targetClient || !targetClient->isOpen()) {
|
||||
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
makePayloadHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -193,21 +200,21 @@ void ServerHandler::handle() {
|
||||
std::size_t available = targetClient->socket().available(ec);
|
||||
|
||||
if (ec || available == 0) {
|
||||
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
makePayloadHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<char> data(std::min<std::size_t>(available, 65536));
|
||||
std::vector<char> data(std::min<std::size_t>(available, config_->general().bufferSize));
|
||||
std::size_t n = targetClient->socket().read_some(
|
||||
boost::asio::buffer(data),
|
||||
ec);
|
||||
|
||||
if (ec || n == 0) {
|
||||
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
makePayloadHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
return;
|
||||
}
|
||||
|
||||
makeEncryptedHttpResponse(
|
||||
makePayloadHttpResponse(
|
||||
std::string(data.data(), n),
|
||||
"200 OK",
|
||||
(config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
@@ -224,7 +231,7 @@ void ServerHandler::handle() {
|
||||
sessions_.erase(it);
|
||||
}
|
||||
|
||||
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
makePayloadHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -238,7 +245,7 @@ void ServerHandler::handle() {
|
||||
"] [ServerHandler handle] [INNER REQUEST MISSING HEADER END]",
|
||||
Log::Level::DEBUG);
|
||||
|
||||
makeEncryptedHttpResponse("", "400 Bad Request", "close");
|
||||
makePayloadHttpResponse("", "400 Bad Request", "close");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -256,7 +263,7 @@ void ServerHandler::handle() {
|
||||
streambufToString(readBuffer_),
|
||||
Log::Level::DEBUG);
|
||||
|
||||
makeEncryptedHttpResponse("", "400 Bad Request", "close");
|
||||
makePayloadHttpResponse("", "400 Bad Request", "close");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -271,7 +278,7 @@ void ServerHandler::handle() {
|
||||
inner->dstIp() + ":" + std::to_string(inner->dstPort()) + "]",
|
||||
Log::Level::INFO);
|
||||
|
||||
makeEncryptedHttpResponse(
|
||||
makePayloadHttpResponse(
|
||||
"HTTP/1.1 502 Bad Gateway\r\n\r\n",
|
||||
"502 Bad Gateway",
|
||||
"close");
|
||||
@@ -283,12 +290,12 @@ void ServerHandler::handle() {
|
||||
|
||||
log_->write(
|
||||
"[" + to_string(uuid_) +
|
||||
"] [CONNECT] [TUNNEL] [SRC " +
|
||||
"] [CONNECT] [SRC " +
|
||||
clientConnStr_ + "] [DST " +
|
||||
inner->dstIp() + ":" + std::to_string(inner->dstPort()) + "]",
|
||||
Log::Level::INFO);
|
||||
|
||||
makeEncryptedHttpResponse(
|
||||
makePayloadHttpResponse(
|
||||
"HTTP/1.1 200 Connection Established\r\n\r\n",
|
||||
"200 OK",
|
||||
"keep-alive");
|
||||
@@ -314,7 +321,7 @@ void ServerHandler::handle() {
|
||||
inner->dstIp() + ":" + std::to_string(inner->dstPort()) + "]",
|
||||
Log::Level::INFO);
|
||||
|
||||
makeEncryptedHttpResponse(
|
||||
makePayloadHttpResponse(
|
||||
"HTTP/1.1 502 Bad Gateway\r\n\r\n",
|
||||
"502 Bad Gateway",
|
||||
"close");
|
||||
@@ -327,7 +334,7 @@ void ServerHandler::handle() {
|
||||
log_->write(
|
||||
"[" + to_string(uuid_) +
|
||||
"] [CONNECT] [SRC " +
|
||||
clientConnStr_ + "] [DST " +
|
||||
clientConnStr_ + "] [ORIGIN " +
|
||||
inner->dstIp() + ":" + std::to_string(inner->dstPort()) + "]",
|
||||
Log::Level::INFO);
|
||||
|
||||
@@ -342,7 +349,7 @@ void ServerHandler::handle() {
|
||||
sessions_[session.empty() ? to_string(uuid_) : session] = targetClient;
|
||||
}
|
||||
|
||||
makeEncryptedHttpResponse(
|
||||
makePayloadHttpResponse(
|
||||
"HTTP/1.1 200 Connection Established\r\n\r\n",
|
||||
"200 OK",
|
||||
"keep-alive");
|
||||
@@ -359,7 +366,7 @@ void ServerHandler::handle() {
|
||||
if (!client_->socket().is_open()) {
|
||||
if (!client_->doConnect(inner->dstIp(), inner->dstPort())) {
|
||||
client_->socket().close();
|
||||
makeEncryptedHttpResponse("", "502 Bad Gateway", "close");
|
||||
makePayloadHttpResponse("", "502 Bad Gateway", "close");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -369,11 +376,11 @@ void ServerHandler::handle() {
|
||||
|
||||
if (client_->readBuffer().size() == 0) {
|
||||
client_->socket().close();
|
||||
makeEncryptedHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
makePayloadHttpResponse("", "200 OK", (config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
return;
|
||||
}
|
||||
|
||||
makeEncryptedHttpResponse(
|
||||
makePayloadHttpResponse(
|
||||
streambufToString(client_->readBuffer()),
|
||||
"200 OK",
|
||||
(config_->general().connectionReuse ? "keep-alive" : "close"));
|
||||
|
||||
@@ -50,9 +50,9 @@ private:
|
||||
std::string clientConnStr,
|
||||
boost::uuids::uuid uuid);
|
||||
|
||||
void makeEncryptedHttpResponse(const std::string &plainBody,
|
||||
const std::string &status = "200 OK",
|
||||
const std::string &connection = "close");
|
||||
void makePayloadHttpResponse(const std::string &plainBody,
|
||||
const std::string &status = "200 OK",
|
||||
const std::string &connection = "close");
|
||||
|
||||
void makePlainHttpResponse(const std::string &body,
|
||||
const std::string &status = "200 OK",
|
||||
|
||||
+83
-8
@@ -12,6 +12,85 @@
|
||||
|
||||
#include "http_utils.hpp"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename Socket>
|
||||
void connectWithTimeout(Socket &socket,
|
||||
const boost::asio::ip::tcp::resolver::results_type &endpoints,
|
||||
unsigned short timeoutSeconds,
|
||||
boost::system::error_code &ec) {
|
||||
ec = boost::asio::error::host_not_found;
|
||||
|
||||
for (const auto &entry: endpoints) {
|
||||
boost::system::error_code ignored;
|
||||
socket.close(ignored);
|
||||
|
||||
socket.open(entry.endpoint().protocol(), ec);
|
||||
if (ec) continue;
|
||||
|
||||
if (timeoutSeconds == 0) {
|
||||
socket.connect(entry.endpoint(), ec);
|
||||
if (!ec) return;
|
||||
continue;
|
||||
}
|
||||
|
||||
socket.native_non_blocking(true, ec);
|
||||
if (ec) continue;
|
||||
|
||||
const auto endpoint = entry.endpoint();
|
||||
const bool started =
|
||||
::connect(socket.native_handle(), endpoint.data(),
|
||||
static_cast<int>(endpoint.size())) == 0;
|
||||
#ifdef _WIN32
|
||||
const int connectErr = started ? 0 : WSAGetLastError();
|
||||
const bool pending = connectErr == WSAEWOULDBLOCK;
|
||||
#else
|
||||
const int connectErr = started ? 0 : errno;
|
||||
const bool pending = connectErr == EINPROGRESS;
|
||||
#endif
|
||||
ec = boost::system::error_code(connectErr, boost::system::system_category());
|
||||
|
||||
if (pending) {
|
||||
#ifdef _WIN32
|
||||
WSAPOLLFD pfd{socket.native_handle(), POLLWRNORM, 0};
|
||||
const int ready = WSAPoll(&pfd, 1, timeoutSeconds * 1000);
|
||||
#else
|
||||
pollfd pfd{socket.native_handle(), POLLOUT, 0};
|
||||
const int ready = ::poll(&pfd, 1, timeoutSeconds * 1000);
|
||||
#endif
|
||||
if (ready == 0) {
|
||||
ec = boost::asio::error::timed_out;
|
||||
} else if (ready < 0) {
|
||||
#ifdef _WIN32
|
||||
ec = boost::system::error_code(WSAGetLastError(), boost::system::system_category());
|
||||
#else
|
||||
ec = boost::system::error_code(errno, boost::system::system_category());
|
||||
#endif
|
||||
} else {
|
||||
boost::asio::detail::socket_option::integer<SOL_SOCKET, SO_ERROR> soError;
|
||||
socket.get_option(soError, ec);
|
||||
if (!ec && soError.value() != 0) {
|
||||
ec = boost::system::error_code(soError.value(), boost::system::system_category());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ec) {
|
||||
socket.native_non_blocking(false, ec);
|
||||
if (!ec) return;
|
||||
}
|
||||
}
|
||||
|
||||
boost::system::error_code ignored;
|
||||
socket.close(ignored);
|
||||
}
|
||||
|
||||
}// namespace
|
||||
|
||||
TCPClient::TCPClient(boost::asio::io_context &io_context,
|
||||
const std::shared_ptr<Config> &config,
|
||||
const std::shared_ptr<Log> &log)
|
||||
@@ -131,18 +210,14 @@ bool TCPClient::doConnect(const std::string &dstIp, unsigned short dstPort) {
|
||||
sslSocket_ = std::make_unique<ssl_stream>(io_context_, sslContext_);
|
||||
closed_ = false;
|
||||
|
||||
boost::asio::connect(
|
||||
sslSocket_->lowest_layer(),
|
||||
endpoints,
|
||||
error_code);
|
||||
connectWithTimeout(sslSocket_->lowest_layer(), endpoints,
|
||||
config_->general().timeout, error_code);
|
||||
} else {
|
||||
socket_ = tcp::socket(io_context_);
|
||||
closed_ = false;
|
||||
|
||||
boost::asio::connect(
|
||||
socket_,
|
||||
endpoints,
|
||||
error_code);
|
||||
connectWithTimeout(socket_, endpoints,
|
||||
config_->general().timeout, error_code);
|
||||
}
|
||||
|
||||
cancelTimeout();
|
||||
|
||||
+41
-16
@@ -29,6 +29,11 @@ TCPConnection::TCPConnection(boost::asio::io_context &io_context,
|
||||
connect_ = false;
|
||||
tunnelClosed_ = false;
|
||||
pollInProgress_ = false;
|
||||
pollDelayMs_ = 0;
|
||||
}
|
||||
|
||||
namespace {
|
||||
constexpr unsigned int MaxPollDelayMs = 50;
|
||||
}
|
||||
|
||||
boost::asio::ip::tcp::socket &TCPConnection::socket() { return socket_; }
|
||||
@@ -130,7 +135,7 @@ void TCPConnection::doReadAgent() {
|
||||
resetTimeout();
|
||||
|
||||
socket_.async_read_some(
|
||||
readBuffer_.prepare(8192),
|
||||
readBuffer_.prepare(BufferSize),
|
||||
boost::asio::bind_executor(
|
||||
strand_,
|
||||
[self = shared_from_this()](
|
||||
@@ -299,6 +304,7 @@ void TCPConnection::handleReadAgent(const boost::system::error_code &error, size
|
||||
self->client_->socketShutdown();
|
||||
}
|
||||
|
||||
self->pollDelayMs_ = self->config_->general().pullTimeout;
|
||||
self->startTunnelReadFromClient();
|
||||
self->startTunnelPollServer();
|
||||
}
|
||||
@@ -461,11 +467,13 @@ std::string TCPConnection::postTunnelAction(const std::string &action,
|
||||
}
|
||||
}
|
||||
|
||||
BoolStr enc = aes256Encrypt(
|
||||
hexArrToStr(
|
||||
reinterpret_cast<const unsigned char *>(rawBody.data()),
|
||||
rawBody.size()),
|
||||
config_->general().token);
|
||||
const std::string payload = makeEnvelope(
|
||||
action, to_string(uuid_),
|
||||
hexArrToStr(reinterpret_cast<const unsigned char *>(rawBody.data()),
|
||||
rawBody.size()));
|
||||
BoolStr enc = config_->general().aesEnable
|
||||
? aes256Encrypt(payload, config_->general().token)
|
||||
: BoolStr{true, payload};
|
||||
|
||||
if (!enc.ok) return "";
|
||||
|
||||
@@ -480,9 +488,7 @@ std::string TCPConnection::postTunnelAction(const std::string &action,
|
||||
<< "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-Type: text/plain; charset=utf-8\r\n"
|
||||
<< "Content-Length: " << encodedBody.size() << "\r\n"
|
||||
<< "Connection: " << (keepAlive ? "keep-alive" : "close") << "\r\n"
|
||||
<< "\r\n"
|
||||
@@ -536,10 +542,12 @@ std::string TCPConnection::postTunnelAction(const std::string &action,
|
||||
const auto pos = response.find("\r\n\r\n");
|
||||
if (pos == std::string::npos) return "";
|
||||
|
||||
const std::string encryptedBody = response.substr(pos + 4);
|
||||
if (encryptedBody.empty()) return "";
|
||||
const std::string responseBody = response.substr(pos + 4);
|
||||
if (responseBody.empty()) return "";
|
||||
|
||||
BoolStr dec = aes256Decrypt(encryptedBody, config_->general().token);
|
||||
BoolStr dec = config_->general().aesEnable
|
||||
? aes256Decrypt(responseBody, config_->general().token)
|
||||
: BoolStr{true, responseBody};
|
||||
if (!dec.ok) return "";
|
||||
|
||||
return dec.message;
|
||||
@@ -690,6 +698,10 @@ void TCPConnection::startTunnelReadFromClient() {
|
||||
std::string raw(self->downstreamBuf_.data(), bytes);
|
||||
|
||||
self->postTunnelAction("send", raw);
|
||||
|
||||
self->pollDelayMs_ = self->config_->general().pullTimeout;
|
||||
if (self->pollInProgress_) self->pollTimer_.cancel();
|
||||
|
||||
self->startTunnelReadFromClient();
|
||||
}));
|
||||
}
|
||||
@@ -699,17 +711,30 @@ void TCPConnection::startTunnelPollServer() {
|
||||
|
||||
pollInProgress_ = true;
|
||||
|
||||
pollTimer_.expires_after(std::chrono::milliseconds(config_->general().pullTimeout));
|
||||
pollTimer_.expires_after(std::chrono::milliseconds(pollDelayMs_));
|
||||
pollTimer_.async_wait(
|
||||
boost::asio::bind_executor(
|
||||
strand_,
|
||||
[self = shared_from_this()](const boost::system::error_code &ec) {
|
||||
self->pollInProgress_ = false;
|
||||
|
||||
if (ec || self->tunnelClosed_ || !self->socket_.is_open()) return;
|
||||
if (self->tunnelClosed_ || !self->socket_.is_open()) return;
|
||||
|
||||
if (ec == boost::asio::error::operation_aborted) {
|
||||
self->startTunnelPollServer();
|
||||
return;
|
||||
}
|
||||
|
||||
if (ec) return;
|
||||
|
||||
std::string data = self->postTunnelAction("recv", "");
|
||||
|
||||
const unsigned int baseDelay = self->config_->general().pullTimeout;
|
||||
self->pollDelayMs_ =
|
||||
data.empty()
|
||||
? std::min(std::max(self->pollDelayMs_ * 2, 1u), std::max(MaxPollDelayMs, baseDelay))
|
||||
: baseDelay;
|
||||
|
||||
if (!data.empty()) {
|
||||
boost::asio::async_write(
|
||||
self->socket_,
|
||||
@@ -869,7 +894,7 @@ void TCPConnection::asyncWriteToAgentConnection(
|
||||
}
|
||||
|
||||
void TCPConnection::asyncReadFromAgentConnection(
|
||||
std::array<char, 8192> &buffer,
|
||||
std::array<char, BufferSize> &buffer,
|
||||
std::function<void(const boost::system::error_code &, std::size_t)> done) {
|
||||
if (config_->general().tlsEnable && tlsSocket_) {
|
||||
tlsSocket_->async_read_some(
|
||||
@@ -910,7 +935,7 @@ void TCPConnection::asyncWriteToAgentServerConnection(
|
||||
}
|
||||
|
||||
void TCPConnection::asyncReadFromAgentServerConnection(
|
||||
std::array<char, 8192> &buffer,
|
||||
std::array<char, BufferSize> &buffer,
|
||||
std::function<void(const boost::system::error_code &, std::size_t)> done) {
|
||||
if (client_->tlsEnabled()) {
|
||||
client_->sslSocket().async_read_some(
|
||||
|
||||
@@ -148,6 +148,7 @@ private:
|
||||
bool tunnelMode_;
|
||||
bool tunnelClosed_;
|
||||
bool pollInProgress_;
|
||||
unsigned int pollDelayMs_;
|
||||
std::atomic_bool closed_{false};
|
||||
|
||||
std::array<char, BufferSize> downstreamBuf_;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
FROM ubuntu:24.04 AS builder
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
build-essential \
|
||||
cmake \
|
||||
git \
|
||||
libboost-all-dev \
|
||||
libssl-dev \
|
||||
libyaml-cpp-dev \
|
||||
ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
|
||||
&& cmake --build build --target nipovpn -j$(nproc)
|
||||
|
||||
|
||||
FROM ubuntu:24.04
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libboost-regex1.83.0 \
|
||||
libssl3t64 \
|
||||
libyaml-cpp0.8 \
|
||||
ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN mkdir -p /etc/nipovpn /var/log/nipovpn
|
||||
|
||||
COPY --from=builder /src/build/core/nipovpn /usr/local/bin/nipovpn
|
||||
COPY nipovpn/etc/nipovpn/config.yaml /etc/nipovpn/config.yaml
|
||||
|
||||
ENTRYPOINT ["nipovpn"]
|
||||
CMD ["server", "/etc/nipovpn/config.yaml"]
|
||||
@@ -0,0 +1,26 @@
|
||||
services:
|
||||
nipovpn:
|
||||
container_name: nipovpn
|
||||
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: docker/Dockerfile
|
||||
|
||||
image: nipovpn:latest
|
||||
|
||||
restart: unless-stopped
|
||||
|
||||
ports:
|
||||
- "443:443"
|
||||
- "8080:8080"
|
||||
|
||||
volumes:
|
||||
- ../nipovpn/etc/nipovpn/config.yaml:/etc/nipovpn/config.yaml:ro
|
||||
- nipovpn_logs:/var/log/nipovpn
|
||||
|
||||
command:
|
||||
- ${NIPOVPN_MODE:-server}
|
||||
- /etc/nipovpn/config.yaml
|
||||
|
||||
volumes:
|
||||
nipovpn_logs:
|
||||
@@ -1,3 +0,0 @@
|
||||
theme: jekyll-theme-minimal
|
||||
title: NipoVPN's homepage
|
||||
description: Safe and powerful http proxy
|
||||
@@ -1,74 +0,0 @@
|
||||
body {
|
||||
font-family: 'Karla', sans-serif;
|
||||
background-image: url("../images/bg.jpg");
|
||||
background-size: cover;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
color: #ffffff;
|
||||
padding-bottom: 75px; }
|
||||
@media (min-width: 768px) {
|
||||
body {
|
||||
padding-bottom: 110px; } }
|
||||
|
||||
.navbar-brand {
|
||||
margin-right: 0; }
|
||||
.navbar-brand img {
|
||||
height: 21px; }
|
||||
|
||||
.navbar-dark {
|
||||
padding-top: 35px;
|
||||
padding-bottom: 35px; }
|
||||
.navbar-dark .navbar-text {
|
||||
color: #ffffff;
|
||||
opacity: 1;
|
||||
padding: 0 20px;
|
||||
border-right: 1px solid #ffffff;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
text-align: center; }
|
||||
.navbar-dark .navbar-text:last-child {
|
||||
border-right: 0; }
|
||||
@media (max-width: 767px) {
|
||||
.navbar-dark {
|
||||
padding-bottom: 0; } }
|
||||
|
||||
.page-title {
|
||||
font-size: 80px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 6px; }
|
||||
@media (max-width: 767px) {
|
||||
.page-title {
|
||||
font-size: 35px;
|
||||
margin-bottom: 14px; } }
|
||||
|
||||
.page-description {
|
||||
max-width: 465px;
|
||||
font-size: 18px;
|
||||
margin-bottom: 59px; }
|
||||
@media (max-width: 767px) {
|
||||
.page-description {
|
||||
font-size: 14px; } }
|
||||
|
||||
p {
|
||||
font-size: 14px;
|
||||
margin-bottom: 21px; }
|
||||
|
||||
.footer-social-links .social-link {
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
line-height: 40px;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
background-color: #ffffff;
|
||||
color: #000000;
|
||||
margin-right: 16px;
|
||||
transition: all 0.3s ease-in-out; }
|
||||
.footer-social-links .social-link:last-child {
|
||||
margin-right: 0; }
|
||||
.footer-social-links .social-link:hover {
|
||||
text-decoration: none;
|
||||
background-color: #000000;
|
||||
color: #ffffff; }
|
||||
|
||||
/*# sourceMappingURL=bd-coming-soon.css.map */
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"sources":["bd-coming-soon.scss"],"names":[],"mappings":"AAAA;EACI,gCAAgC;EAChC,yCAAyC;EACzC,sBAAsB;EACtB,4BAA4B;EAC5B,2BAA2B;EAC3B,cAAc;EACd,oBAAoB,EAAA;EAEpB;IATJ;MAUQ,qBAAqB,EAAA,EAE5B;;AACD;EACI,eAAe,EAAA;EADnB;IAIQ,YAAY,EAAA;;AAGpB;EACI,iBAAiB;EACjB,oBAAoB,EAAA;EAFxB;IAIQ,cAAc;IACd,UAAU;IACV,eAAe;IACf,+BAA+B;IAC/B,eAAe;IACf,iBAAiB;IACjB,kBAAkB,EAAA;IAV1B;MAaY,eAAe,EAAA;EAIvB;IAjBJ;MAkBQ,iBAAiB,EAAA,EAExB;;AACD;EACI,eAAe;EACf,iBAAiB;EACjB,kBAAkB,EAAA;EAElB;IALJ;MAMQ,eAAe;MACf,mBAAmB,EAAA,EAE1B;;AACD;EACI,gBAAgB;EAChB,eAAe;EACf,mBAAmB,EAAA;EAEnB;IALJ;MAMQ,eAAe,EAAA,EAEtB;;AAED;EACI,eAAe;EACf,mBAAmB,EAAA;;AAGvB;EAEQ,qBAAqB;EACrB,kBAAkB;EAClB,iBAAiB;EACjB,WAAW;EACX,YAAY;EACZ,kBAAkB;EAClB,yBAAyB;EACzB,cAAc;EACd,kBAAkB;EAClB,gCAAgC,EAAA;EAXxC;IAcY,eAAe,EAAA;EAd3B;IAkBY,qBAAqB;IACrB,yBAAyB;IACzB,cAAc,EAAA","file":"bd-coming-soon.css","sourcesContent":["body {\n font-family: 'Karla', sans-serif;\n background-image: url(\"../images/bg.jpg\");\n background-size: cover;\n background-repeat: no-repeat;\n background-position: center;\n color: #ffffff;\n padding-bottom: 75px;\n\n @media (min-width: 768px) {\n padding-bottom: 110px;\n }\n}\n.navbar-brand {\n margin-right: 0;\n\n img {\n height: 21px;\n }\n}\n.navbar-dark {\n padding-top: 35px;\n padding-bottom: 35px;\n .navbar-text {\n color: #ffffff;\n opacity: 1;\n padding: 0 20px;\n border-right: 1px solid #ffffff;\n font-size: 18px;\n font-weight: bold;\n text-align: center;\n\n &:last-child {\n border-right: 0;\n }\n }\n\n @media (max-width: 767px) {\n padding-bottom: 0;\n }\n}\n.page-title {\n font-size: 80px;\n font-weight: bold;\n margin-bottom: 6px;\n\n @media (max-width: 767px) {\n font-size: 35px;\n margin-bottom: 14px; \n }\n}\n.page-description {\n max-width: 465px;\n font-size: 18px;\n margin-bottom: 59px;\n\n @media (max-width: 767px) {\n font-size: 14px; \n }\n}\n\np {\n font-size: 14px;\n margin-bottom: 21px;\n}\n\n.footer-social-links {\n .social-link {\n display: inline-block;\n text-align: center;\n line-height: 40px;\n width: 40px;\n height: 40px;\n border-radius: 50%;\n background-color: #ffffff;\n color: #000000;\n margin-right: 16px;\n transition: all 0.3s ease-in-out;\n\n &:last-child {\n margin-right: 0;\n }\n\n &:hover {\n text-decoration: none;\n background-color: #000000;\n color: #ffffff;\n }\n }\n}"]}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 215 KiB |
@@ -1,3 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="59" height="25" viewBox="0 0 59 25" fill="#FFFFFF">
|
||||
<path d="M4.125,15.3 L10.05,15.3 L10.05,18 L0.6,18 L0.6,0.35 L4.125,0.35 L4.125,15.3 Z M18.55,3.975 C19.9000067,3.975 21.1124946,4.2583305 22.1875,4.825 C23.2625054,5.3916695 24.1083302,6.21249462 24.725,7.2875 C25.3416697,8.36250537 25.65,9.62499275 25.65,11.075 C25.65,12.5250073 25.3416697,13.783328 24.725,14.85 C24.1083302,15.916672 23.2625054,16.7374971 22.1875,17.3125 C21.1124946,17.8875029 19.9000067,18.175 18.55,18.175 C17.1999933,18.175 15.9875054,17.8875029 14.9125,17.3125 C13.8374946,16.7374971 12.9916697,15.916672 12.375,14.85 C11.7583302,13.783328 11.45,12.5250073 11.45,11.075 C11.45,9.62499275 11.7583302,8.36250537 12.375,7.2875 C12.9916697,6.21249462 13.8374946,5.3916695 14.9125,4.825 C15.9875054,4.2583305 17.1999933,3.975 18.55,3.975 Z M18.55,7.025 C17.5666618,7.025 16.7333368,7.37082987 16.05,8.0625 C15.3666633,8.75417013 15.025,9.75832675 15.025,11.075 C15.025,12.3916733 15.3666633,13.3958299 16.05,14.0875 C16.7333368,14.7791701 17.5666618,15.125 18.55,15.125 C19.5333382,15.125 20.3666633,14.7791701 21.05,14.0875 C21.7333367,13.3958299 22.075,12.3916733 22.075,11.075 C22.075,9.75832675 21.7333367,8.75417013 21.05,8.0625 C20.3666633,7.37082987 19.5333382,7.025 18.55,7.025 Z M33.575,3.975 C34.7416725,3.975 35.7416625,4.24999725 36.575,4.8 C37.4083375,5.35000275 37.9999982,6.091662 38.35,7.025 L38.35,4.15 L41.85,4.15 L41.85,18.05 C41.85,19.3333398 41.5958359,20.4874949 41.0875,21.5125 C40.5791641,22.5375051 39.8208384,23.3416638 38.8125,23.925 C37.8041616,24.5083363 36.5833405,24.8 35.15,24.8 C33.14999,24.8 31.5333395,24.3250048 30.3,23.375 C29.0666605,22.4249953 28.316668,21.1333415 28.05,19.5 L31.525,19.5 C31.725001,20.2000035 32.1124971,20.7458314 32.6875,21.1375 C33.2625029,21.5291686 33.9999955,21.725 34.9,21.725 C35.9333385,21.725 36.7666635,21.4208364 37.4,20.8125 C38.0333365,20.2041636 38.35,19.2833395 38.35,18.05 L38.35,15.1 C37.9999982,16.033338 37.4083375,16.7791639 36.575,17.3375 C35.7416625,17.8958361 34.7416725,18.175 33.575,18.175 C32.4083275,18.175 31.358338,17.8916695 30.425,17.325 C29.491662,16.7583305 28.7625026,15.9375054 28.2375,14.8625 C27.7124974,13.7874946 27.45,12.5250073 27.45,11.075 C27.45,9.62499275 27.7124974,8.36250537 28.2375,7.2875 C28.7625026,6.21249462 29.491662,5.3916695 30.425,4.825 C31.358338,4.2583305 32.4083275,3.975 33.575,3.975 Z M34.675,7.05 C33.5749945,7.05 32.69167,7.40832975 32.025,8.125 C31.35833,8.84167025 31.025,9.82499375 31.025,11.075 C31.025,12.3250063 31.35833,13.3041631 32.025,14.0125 C32.69167,14.7208369 33.5749945,15.075 34.675,15.075 C35.741672,15.075 36.6208299,14.7125036 37.3125,13.9875 C38.0041701,13.2624964 38.35,12.2916728 38.35,11.075 C38.35,9.8416605 38.0041701,8.86250363 37.3125,8.1375 C36.6208299,7.41249637 35.741672,7.05 34.675,7.05 Z M51.45,3.975 C52.8000068,3.975 54.0124946,4.2583305 55.0875,4.825 C56.1625054,5.3916695 57.0083302,6.21249462 57.625,7.2875 C58.2416697,8.36250537 58.55,9.62499275 58.55,11.075 C58.55,12.5250073 58.2416697,13.783328 57.625,14.85 C57.0083302,15.916672 56.1625054,16.7374971 55.0875,17.3125 C54.0124946,17.8875029 52.8000068,18.175 51.45,18.175 C50.0999933,18.175 48.8875054,17.8875029 47.8125,17.3125 C46.7374946,16.7374971 45.8916698,15.916672 45.275,14.85 C44.6583303,13.783328 44.35,12.5250073 44.35,11.075 C44.35,9.62499275 44.6583303,8.36250537 45.275,7.2875 C45.8916698,6.21249462 46.7374946,5.3916695 47.8125,4.825 C48.8875054,4.2583305 50.0999933,3.975 51.45,3.975 Z M51.45,7.025 C50.4666618,7.025 49.6333367,7.37082987 48.95,8.0625 C48.2666633,8.75417013 47.925,9.75832675 47.925,11.075 C47.925,12.3916733 48.2666633,13.3958299 48.95,14.0875 C49.6333367,14.7791701 50.4666618,15.125 51.45,15.125 C52.4333383,15.125 53.2666633,14.7791701 53.95,14.0875 C54.6333367,13.3958299 54.975,12.3916733 54.975,11.075 C54.975,9.75832675 54.6333367,8.75417013 53.95,8.0625 C53.2666633,7.37082987 52.4333383,7.025 51.45,7.025 Z"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 3.9 KiB |
@@ -1,90 +0,0 @@
|
||||
body {
|
||||
font-family: 'Karla', sans-serif;
|
||||
background-image: url("../images/bg.jpg");
|
||||
background-size: cover;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center;
|
||||
color: #ffffff;
|
||||
padding-bottom: 75px;
|
||||
|
||||
@media (min-width: 768px) {
|
||||
padding-bottom: 110px;
|
||||
}
|
||||
}
|
||||
.navbar-brand {
|
||||
margin-right: 0;
|
||||
|
||||
img {
|
||||
height: 21px;
|
||||
}
|
||||
}
|
||||
.navbar-dark {
|
||||
padding-top: 35px;
|
||||
padding-bottom: 35px;
|
||||
.navbar-text {
|
||||
color: #ffffff;
|
||||
opacity: 1;
|
||||
padding: 0 20px;
|
||||
border-right: 1px solid #ffffff;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
|
||||
&:last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
padding-bottom: 0;
|
||||
}
|
||||
}
|
||||
.page-title {
|
||||
font-size: 80px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 6px;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
font-size: 35px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
}
|
||||
.page-description {
|
||||
max-width: 465px;
|
||||
font-size: 18px;
|
||||
margin-bottom: 59px;
|
||||
|
||||
@media (max-width: 767px) {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 14px;
|
||||
margin-bottom: 21px;
|
||||
}
|
||||
|
||||
.footer-social-links {
|
||||
.social-link {
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
line-height: 40px;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
background-color: #ffffff;
|
||||
color: #000000;
|
||||
margin-right: 16px;
|
||||
transition: all 0.3s ease-in-out;
|
||||
|
||||
&:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
text-decoration: none;
|
||||
background-color: #000000;
|
||||
color: #ffffff;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
//Import
|
||||
|
||||
const gulp = require('gulp');
|
||||
const sass = require('gulp-sass');
|
||||
const sourceMaps = require('gulp-sourcemaps');
|
||||
const autoprefixer = require('gulp-autoprefixer');
|
||||
const browserSync = require('browser-sync');
|
||||
|
||||
//SCSS
|
||||
|
||||
function style() {
|
||||
return gulp.src('./assets/scss/*.scss')
|
||||
.pipe(sourceMaps.init())
|
||||
.pipe(sass().on('error', sass.logError))
|
||||
.pipe(autoprefixer())
|
||||
.pipe(sourceMaps.write('./'))
|
||||
.pipe(gulp.dest('./assets/css'))
|
||||
.pipe(browserSync.stream());
|
||||
}
|
||||
|
||||
//Serve and watch
|
||||
|
||||
function watch() {
|
||||
browserSync.init({
|
||||
server: {
|
||||
baseDir: './',
|
||||
},
|
||||
startPath: './index.html',
|
||||
ghostMode: false,
|
||||
notify: false
|
||||
});
|
||||
gulp.watch('./assets/scss/*.scss', style);
|
||||
gulp.watch('./*.html').on('change', browserSync.reload);
|
||||
gulp.watch('./assets/js/*.js').on('change', browserSync.reload);
|
||||
|
||||
}
|
||||
|
||||
exports.style = style;
|
||||
exports.watch = watch;
|
||||
@@ -1,45 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>NipoVPN documentation</title>
|
||||
<link href="https://fonts.googleapis.com/css?family=Karla:400,700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdn.materialdesignicons.com/4.8.95/css/materialdesignicons.min.css">
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="assets/css/bd-coming-soon.css">
|
||||
</head>
|
||||
|
||||
<body class="min-vh-100 d-flex flex-column">
|
||||
|
||||
<header>
|
||||
<div class="container">
|
||||
<nav class="navbar navbar-dark bg-transparenet">
|
||||
<a class="navbar-brand" href="#">
|
||||
<img src="assets/images/logo.svg" alt="logo">
|
||||
</a>
|
||||
<span class="navbar-text ml-auto d-none d-sm-inline-block">Email</span>
|
||||
<span class="navbar-text d-none d-sm-inline-block">morteza.bashsiz@gmail.com</span>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
<main class="my-auto">
|
||||
<div class="container">
|
||||
<h1 class="page-title">We're coming soon</h1>
|
||||
<p class="page-description">We are working hard to make it possible
|
||||
</p>
|
||||
<p>Stay connected</p>
|
||||
<!-- <nav class="footer-social-links">
|
||||
<a href="#!" class="social-link"><i class="mdi mdi-facebook-box"></i></a>
|
||||
<a href="#!" class="social-link"><i class="mdi mdi-twitter"></i></a>
|
||||
<a href="#!" class="social-link"><i class="mdi mdi-google"></i></a>
|
||||
<a href="#!" class="social-link"><i class="mdi mdi-slack"></i></a>
|
||||
<a href="#!" class="social-link"><i class="mdi mdi-skype"></i></a>
|
||||
</nav> -->
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Generated
-4995
File diff suppressed because it is too large.
Load diff
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"name": "bd-wizard-free-1",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"browser-sync": "^3.0.2",
|
||||
"gulp": "^5.0.0",
|
||||
"gulp-autoprefixer": "^7.0.1",
|
||||
"gulp-sass": "^5.1.0",
|
||||
"gulp-sourcemaps": "^2.6.5",
|
||||
"node-sass": "^9.0.0"
|
||||
}
|
||||
}
|
||||
Generated
+61
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1780243769,
|
||||
"narHash": "sha256-x5UQuRsH3MqI0U9afaXSNqzTPSeZlRLvFAav2Ux1pNw=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "331800de5053fcebacf6813adb5db9c9dca22a0c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
{
|
||||
description = "NipoVPN - Powerful HTTP proxy";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
}:
|
||||
flake-utils.lib.eachSystem ["x86_64-linux" "aarch64-linux"] (system: let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
nipovpn = pkgs.stdenv.mkDerivation {
|
||||
pname = "nipovpn";
|
||||
version = "1.1.57";
|
||||
src = self;
|
||||
|
||||
nativeBuildInputs = with pkgs; [cmake];
|
||||
buildInputs = with pkgs; [boost yaml-cpp openssl];
|
||||
|
||||
cmakeFlags = ["-DCMAKE_BUILD_TYPE=Release"];
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
mkdir -p $out/bin $out/etc/nipovpn
|
||||
cp core/nipovpn $out/bin/nipovpn
|
||||
cp -r $src/nipovpn/etc/nipovpn/. $out/etc/nipovpn/
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
meta = with pkgs.lib; {
|
||||
description = "Powerful HTTP proxy with traffic obfuscation";
|
||||
homepage = "https://github.com/MortezaBashsiz/nipovpn";
|
||||
license = licenses.gpl3Plus;
|
||||
platforms = platforms.linux;
|
||||
mainProgram = "nipovpn";
|
||||
};
|
||||
};
|
||||
in {
|
||||
packages.default = nipovpn;
|
||||
packages.nipovpn = nipovpn;
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
cmake
|
||||
ninja
|
||||
boost
|
||||
yaml-cpp
|
||||
openssl
|
||||
clang-tools
|
||||
gdb
|
||||
valgrind
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
echo "NipoVPN dev environment ready"
|
||||
echo ""
|
||||
echo "You can build using either Make or Ninja:"
|
||||
echo " Standard (Make):"
|
||||
echo " cmake -B build -DCMAKE_BUILD_TYPE=Debug"
|
||||
echo " cmake --build build -j\$(nproc)"
|
||||
echo ""
|
||||
echo " Fast (Ninja):"
|
||||
echo " cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug"
|
||||
echo " cmake --build build -j\$(nproc)"
|
||||
'';
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,348 @@
|
||||
# NipoVPN Docker
|
||||
|
||||
This directory contains Docker files for building and running **NipoVPN** in either `server` or `agent` mode.
|
||||
|
||||
## Directory Structure
|
||||
|
||||
```text
|
||||
nipovpn/
|
||||
├── docker/
|
||||
│ ├── Dockerfile
|
||||
│ ├── docker-compose.yml
|
||||
│ └── README.md
|
||||
├── nipovpn/
|
||||
│ └── etc/nipovpn/config.yaml
|
||||
├── core/
|
||||
├── CMakeLists.txt
|
||||
└── .dockerignore
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
Install Docker and Docker Compose:
|
||||
|
||||
```bash
|
||||
docker --version
|
||||
docker compose version
|
||||
```
|
||||
|
||||
For older systems:
|
||||
|
||||
```bash
|
||||
docker-compose --version
|
||||
```
|
||||
|
||||
## Important: `.dockerignore`
|
||||
|
||||
Create `.dockerignore` in the repository root:
|
||||
|
||||
```text
|
||||
.git
|
||||
.github
|
||||
build
|
||||
cmake-build-*
|
||||
*.deb
|
||||
*.tar.gz
|
||||
*.log
|
||||
```
|
||||
|
||||
This prevents local build files from being copied into the Docker image.
|
||||
|
||||
## Docker Compose File
|
||||
|
||||
The compose file is located at:
|
||||
|
||||
```bash
|
||||
docker/docker-compose.yml
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
nipovpn:
|
||||
container_name: nipovpn
|
||||
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: docker/Dockerfile
|
||||
|
||||
image: nipovpn:latest
|
||||
|
||||
restart: unless-stopped
|
||||
|
||||
ports:
|
||||
- "443:443"
|
||||
- "8080:8080"
|
||||
|
||||
volumes:
|
||||
- ../nipovpn/etc/nipovpn/config.yaml:/etc/nipovpn/config.yaml:ro
|
||||
- nipovpn_logs:/var/log/nipovpn
|
||||
|
||||
command:
|
||||
- ${NIPOVPN_MODE:-server}
|
||||
- /etc/nipovpn/config.yaml
|
||||
|
||||
volumes:
|
||||
nipovpn_logs:
|
||||
```
|
||||
|
||||
## Build Image
|
||||
|
||||
From the `docker` directory:
|
||||
|
||||
```bash
|
||||
cd docker
|
||||
docker compose build
|
||||
```
|
||||
|
||||
Or with old Docker Compose:
|
||||
|
||||
```bash
|
||||
cd docker
|
||||
docker-compose build
|
||||
```
|
||||
|
||||
To rebuild without cache:
|
||||
|
||||
```bash
|
||||
docker compose build --no-cache
|
||||
```
|
||||
|
||||
## Run in Server Mode
|
||||
|
||||
Using environment variable:
|
||||
|
||||
```bash
|
||||
cd docker
|
||||
NIPOVPN_MODE=server docker compose up -d
|
||||
```
|
||||
|
||||
Or create `docker/.env`:
|
||||
|
||||
```env
|
||||
NIPOVPN_MODE=server
|
||||
```
|
||||
|
||||
Then run:
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
The container will run:
|
||||
|
||||
```bash
|
||||
nipovpn server /etc/nipovpn/config.yaml
|
||||
```
|
||||
|
||||
## Run in Agent Mode
|
||||
|
||||
Using environment variable:
|
||||
|
||||
```bash
|
||||
cd docker
|
||||
NIPOVPN_MODE=agent docker compose up -d
|
||||
```
|
||||
|
||||
Or create `docker/.env`:
|
||||
|
||||
```env
|
||||
NIPOVPN_MODE=agent
|
||||
```
|
||||
|
||||
Then run:
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
The container will run:
|
||||
|
||||
```bash
|
||||
nipovpn agent /etc/nipovpn/config.yaml
|
||||
```
|
||||
|
||||
## Specify Config File
|
||||
|
||||
By default, this file is mounted into the container:
|
||||
|
||||
```bash
|
||||
../nipovpn/etc/nipovpn/config.yaml
|
||||
```
|
||||
|
||||
Inside the container it becomes:
|
||||
|
||||
```bash
|
||||
/etc/nipovpn/config.yaml
|
||||
```
|
||||
|
||||
To use another config file, change this line in `docker-compose.yml`:
|
||||
|
||||
```yaml
|
||||
volumes:
|
||||
- ../nipovpn/etc/nipovpn/config.yaml:/etc/nipovpn/config.yaml:ro
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
volumes:
|
||||
- ./server-config.yaml:/etc/nipovpn/config.yaml:ro
|
||||
```
|
||||
|
||||
Then run:
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
## View Logs
|
||||
|
||||
Show live container logs:
|
||||
|
||||
```bash
|
||||
docker compose logs -f
|
||||
```
|
||||
|
||||
Show logs only for NipoVPN service:
|
||||
|
||||
```bash
|
||||
docker compose logs -f nipovpn
|
||||
```
|
||||
|
||||
Read the log file inside the container volume:
|
||||
|
||||
```bash
|
||||
docker exec -it nipovpn cat /var/log/nipovpn/nipovpn.log
|
||||
```
|
||||
|
||||
Follow the log file:
|
||||
|
||||
```bash
|
||||
docker exec -it nipovpn tail -f /var/log/nipovpn/nipovpn.log
|
||||
```
|
||||
|
||||
## Stop Container
|
||||
|
||||
```bash
|
||||
docker compose down
|
||||
```
|
||||
|
||||
## Restart Container
|
||||
|
||||
```bash
|
||||
docker compose restart
|
||||
```
|
||||
|
||||
## Rebuild and Restart
|
||||
|
||||
```bash
|
||||
docker compose down
|
||||
docker compose build --no-cache
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
## Check Container Status
|
||||
|
||||
```bash
|
||||
docker ps
|
||||
```
|
||||
|
||||
Or:
|
||||
|
||||
```bash
|
||||
docker compose ps
|
||||
```
|
||||
|
||||
## Execute Shell Inside Container
|
||||
|
||||
```bash
|
||||
docker exec -it nipovpn bash
|
||||
```
|
||||
|
||||
## Run Manually Without Compose
|
||||
|
||||
Build image from repository root:
|
||||
|
||||
```bash
|
||||
docker build -f docker/Dockerfile -t nipovpn:latest .
|
||||
```
|
||||
|
||||
Run server mode:
|
||||
|
||||
```bash
|
||||
docker run --rm \
|
||||
--name nipovpn \
|
||||
-p 443:443 \
|
||||
-p 8080:8080 \
|
||||
-v ./nipovpn/etc/nipovpn/config.yaml:/etc/nipovpn/config.yaml:ro \
|
||||
nipovpn:latest server /etc/nipovpn/config.yaml
|
||||
```
|
||||
|
||||
Run agent mode:
|
||||
|
||||
```bash
|
||||
docker run --rm \
|
||||
--name nipovpn \
|
||||
-p 8080:8080 \
|
||||
-v ./nipovpn/etc/nipovpn/config.yaml:/etc/nipovpn/config.yaml:ro \
|
||||
nipovpn:latest agent /etc/nipovpn/config.yaml
|
||||
```
|
||||
|
||||
## Common Problems
|
||||
|
||||
### CMakeCache path error
|
||||
|
||||
If you see an error like:
|
||||
|
||||
```text
|
||||
CMakeCache.txt directory is different
|
||||
```
|
||||
|
||||
your local `build/` directory was copied into Docker.
|
||||
|
||||
Fix:
|
||||
|
||||
```bash
|
||||
rm -rf build
|
||||
docker compose build --no-cache
|
||||
```
|
||||
|
||||
Also make sure `.dockerignore` exists in the repository root.
|
||||
|
||||
### Port already in use
|
||||
|
||||
If port `443` or `8080` is already used, change the port mapping:
|
||||
|
||||
```yaml
|
||||
ports:
|
||||
- "8443:443"
|
||||
- "8081:8080"
|
||||
```
|
||||
|
||||
### Config changes are not applied
|
||||
|
||||
Restart the container:
|
||||
|
||||
```bash
|
||||
docker compose restart
|
||||
```
|
||||
|
||||
## Recommended Commands
|
||||
|
||||
Server:
|
||||
|
||||
```bash
|
||||
cd docker
|
||||
NIPOVPN_MODE=server docker compose up -d --build
|
||||
docker compose logs -f
|
||||
```
|
||||
|
||||
Agent:
|
||||
|
||||
```bash
|
||||
cd docker
|
||||
NIPOVPN_MODE=agent docker compose up -d --build
|
||||
docker compose logs -f
|
||||
```
|
||||
@@ -0,0 +1,84 @@
|
||||
## Nix Guide
|
||||
|
||||
**Note:** Nix Flakes are an experimental feature and must be enabled before using any of the commands in this guide.
|
||||
|
||||
### Enable Flakes
|
||||
|
||||
* **NixOS:** Follow the instructions in the NixOS & Flakes Book:
|
||||
|
||||
[Enabling NixOS with Flakes](https://nixos-and-flakes.thiscute.world/nixos-with-flakes/nixos-with-flakes-enabled?utm_source=chatgpt.com#enable-nix-flakes)
|
||||
|
||||
* **Non-NixOS systems:** Add the following to `~/.config/nix/nix.conf` (or `/etc/nix/nix.conf`):
|
||||
|
||||
```bash
|
||||
experimental-features = nix-command flakes
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
### Install into your Nix profile
|
||||
|
||||
```bash
|
||||
nix profile install github:MortezaBashsiz/nipovpn
|
||||
```
|
||||
|
||||
### NixOS (system-wide installation)
|
||||
|
||||
Add the flake as an input in your system `flake.nix`:
|
||||
|
||||
```nix
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
nipovpn.url = "github:MortezaBashsiz/nipovpn";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, nipovpn, ... }: {
|
||||
nixosConfigurations.yourhostname = nixpkgs.lib.nixosSystem {
|
||||
system = "x86_64-linux"; # or "aarch64-linux"
|
||||
|
||||
modules = [
|
||||
./configuration.nix
|
||||
{
|
||||
environment.systemPackages = [
|
||||
nipovpn.packages.${pkgs.system}.default
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
### Manual Build (without Nix)
|
||||
|
||||
For traditional builds on Linux, please refer to [`BuildLinux.md`](./BuildLinux.md).
|
||||
|
||||
### Build with Nix
|
||||
|
||||
From the repository root:
|
||||
|
||||
```bash
|
||||
nix build
|
||||
```
|
||||
|
||||
Or directly from GitHub without cloning:
|
||||
|
||||
```bash
|
||||
nix build github:MortezaBashsiz/nipovpn
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
Enter the development shell with all dependencies pre-configured:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/MortezaBashsiz/nipovpn.git
|
||||
cd nipovpn
|
||||
|
||||
nix develop
|
||||
```
|
||||
|
||||
If the command completes successfully, the development environment is ready to use.
|
||||
@@ -0,0 +1 @@
|
||||
/etc/nipovpn/config.yaml
|
||||
@@ -1,7 +1,7 @@
|
||||
Package: nipovpn
|
||||
Version: ${PACKAGE_VERSION}
|
||||
Version: 0.0.0
|
||||
Maintainer: Morteza Bashsiz
|
||||
Architecture: ${{ matrix.arch }}
|
||||
Description: Powerfull and Secure http/s Proxy
|
||||
Architecture: amd64
|
||||
Depends: libyaml-cpp0.8
|
||||
Homepage: https://github.com/MortezaBashsiz/nipovpn
|
||||
Description: Powerful and secure proxy
|
||||
@@ -1,12 +1,21 @@
|
||||
---
|
||||
# This block contains general and global configuration which is in both modes
|
||||
general:
|
||||
# token: 32 bytes of string. this will be used on agent and server side to encryption
|
||||
# token: at least 32 bytes of string. The AES-256-GCM key is derived from it. Must match on agent and server.
|
||||
# This sample value is public: replace it, e.g. with the output of `openssl rand -hex 16`
|
||||
token: "af445adb-2434-4975-9445-2c1b2231"
|
||||
# aesEnable: bool (default: true)
|
||||
# Enables AES-256-GCM payload encryption (confidentiality and integrity). Must match on the agent and server.
|
||||
# Independent of tlsEnable; request encoding remains enabled.
|
||||
aesEnable: true
|
||||
# protocol:
|
||||
# Defines the protocol between client and agent
|
||||
# Choose http or socks5
|
||||
protocol: http
|
||||
protocol: socks5
|
||||
# bufferSize: unsigned short
|
||||
# Defines the maximum buffer size for each request in Bytes. Default is 65536
|
||||
# Do not use less than 1 and more than 65536
|
||||
bufferSize: 65536
|
||||
# fakeUrls:
|
||||
# Defines the list of fake urls between agent and server
|
||||
fakeUrls:
|
||||
@@ -40,18 +49,18 @@ general:
|
||||
# pullTimeout: unsigned short
|
||||
# Defines the timeout for I/O Operation in milliseconds.
|
||||
# Useful to expire serverside read timer.
|
||||
pullTimeout: 50
|
||||
pullTimeout: 1
|
||||
# tunnelEnable: bool
|
||||
# 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
|
||||
# If true then it will use same connection between agent and server to handle client request
|
||||
# If false 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
|
||||
tlsEnable: true
|
||||
# tlsVerifyPeer: bool
|
||||
# Use it to controll if the certificate should be validated or not
|
||||
tlsVerifyPeer: false
|
||||
@@ -64,7 +73,7 @@ general:
|
||||
# This block is to define log directives
|
||||
log:
|
||||
# logLevel: "INFO|TRACE|DEBUG"
|
||||
logLevel: "DEBUG"
|
||||
logLevel: "INFO"
|
||||
# logFile: "/var/log/nipo/nipo.log"
|
||||
# Path of log file
|
||||
logFile: "/var/log/nipovpn/nipovpn.log"
|
||||
@@ -72,11 +81,11 @@ log:
|
||||
# This block is to define server directives
|
||||
server:
|
||||
# threads: number of threads in server
|
||||
threads: 8
|
||||
threads: 2
|
||||
# listenIp: which must be IPv4 which is used on server
|
||||
listenIp: "0.0.0.0"
|
||||
# listenPort: the port number which will be used on server
|
||||
listenPort: 80
|
||||
listenPort: 443
|
||||
|
||||
|
||||
# This block is to define agent directives
|
||||
@@ -90,7 +99,7 @@ agent:
|
||||
# serverIp: IPv4 of the nipoServer
|
||||
serverIp: "127.0.0.10"
|
||||
# serverPort: port number of the nipoServer
|
||||
serverPort: 80
|
||||
serverPort: 443
|
||||
# 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
|
||||
|
||||
@@ -8,6 +8,7 @@ ExecReload=/bin/kill -HUP $MAINPID
|
||||
KillMode=process
|
||||
Restart=on-failure
|
||||
Type=simple
|
||||
LimitNOFILE=1048576
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
@@ -8,6 +8,7 @@ ExecReload=/bin/kill -HUP $MAINPID
|
||||
KillMode=process
|
||||
Restart=on-failure
|
||||
Type=simple
|
||||
LimitNOFILE=1048576
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
Whitespace-only changes.
Executable
+95
@@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import json
|
||||
import sys
|
||||
|
||||
try:
|
||||
import yaml
|
||||
except ImportError:
|
||||
sys.exit("PyYAML is required: pip install pyyaml (or install python-yaml)")
|
||||
|
||||
DEFAULT_CONFIG = "/etc/nipovpn/config.yaml"
|
||||
|
||||
|
||||
def to_str(value):
|
||||
return "" if value is None else str(value)
|
||||
|
||||
|
||||
def to_lines(value):
|
||||
if isinstance(value, (list, tuple)):
|
||||
return "\n".join(str(v) for v in value)
|
||||
return to_str(value)
|
||||
|
||||
|
||||
def build_payload(cfg, name=None, server_ip=None):
|
||||
general = cfg.get("general", {}) or {}
|
||||
log = cfg.get("log", {}) or {}
|
||||
agent = cfg.get("agent", {}) or {}
|
||||
|
||||
server_ip = server_ip or to_str(agent.get("serverIp"))
|
||||
config = {
|
||||
"token": to_str(general.get("token")),
|
||||
"protocol": to_str(general.get("protocol")),
|
||||
"fakeUrls": to_lines(general.get("fakeUrls")),
|
||||
"methods": to_lines(general.get("methods")),
|
||||
"endPoints": to_lines(general.get("endPoints")),
|
||||
"timeout": to_str(general.get("timeout")),
|
||||
"pullTimeout": to_str(general.get("pullTimeout")),
|
||||
"tunnelEnable": bool(general.get("tunnelEnable", False)),
|
||||
"connectionReuse": bool(general.get("connectionReuse", False)),
|
||||
"tlsEnable": bool(general.get("tlsEnable", False)),
|
||||
"tlsVerifyPeer": bool(general.get("tlsVerifyPeer", False)),
|
||||
"tlsCertFile": to_str(general.get("tlsCertFile")),
|
||||
"tlsKeyFile": to_str(general.get("tlsKeyFile")),
|
||||
"tlsCaFile": to_str(general.get("tlsCaFile")),
|
||||
"logLevel": to_str(log.get("logLevel")),
|
||||
"listenIp": to_str(agent.get("listenIp")),
|
||||
"listenPort": to_str(agent.get("listenPort")),
|
||||
"serverIp": server_ip,
|
||||
"serverPort": to_str(agent.get("serverPort")),
|
||||
"httpVersion": to_str(agent.get("httpVersion")),
|
||||
"userAgent": to_str(agent.get("userAgent")),
|
||||
}
|
||||
return {"name": name or server_ip, "config": config}
|
||||
|
||||
|
||||
def encode(payload):
|
||||
text = json.dumps(payload, separators=(",", ":"), ensure_ascii=False)
|
||||
text = text.replace("/", "\\/")
|
||||
return "nipovpn://" + base64.b64encode(text.encode("utf-8")).decode("ascii")
|
||||
|
||||
|
||||
def decode(url):
|
||||
data = url.strip()
|
||||
if data.startswith("nipovpn://"):
|
||||
data = data[len("nipovpn://"):]
|
||||
data += "=" * (-len(data) % 4)
|
||||
return json.loads(base64.b64decode(data).decode("utf-8"))
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Convert nipovpn config.yaml to a nipovpn:// URL")
|
||||
parser.add_argument("config", nargs="?", default=DEFAULT_CONFIG,
|
||||
help=f"path to config.yaml (default: {DEFAULT_CONFIG})")
|
||||
parser.add_argument("--name", help="profile name (default: serverIp)")
|
||||
parser.add_argument("--server-ip", help="override agent.serverIp (e.g. the public IP of the server)")
|
||||
parser.add_argument("--decode", metavar="URL", help="decode a nipovpn:// URL and print its JSON")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.decode:
|
||||
print(json.dumps(decode(args.decode), indent=2, ensure_ascii=False))
|
||||
return
|
||||
|
||||
try:
|
||||
with open(args.config, "r", encoding="utf-8") as f:
|
||||
cfg = yaml.safe_load(f) or {}
|
||||
except OSError as e:
|
||||
sys.exit(f"Cannot read {args.config}: {e}")
|
||||
|
||||
print(encode(build_payload(cfg, args.name, args.server_ip)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user