SoftEtherUnofficial/SoftEtherClient
A modern, cross-platform VPN client implementation in Zig, compatible with SoftEther VPN protocol.
A modern, cross-platform VPN client implementation in pure Zig, progressively replacing the SoftEther VPN C codebase.
IMPORTANT: Never use plaintext passwords on the command line! See SECURITY.md for secure credential management best practices.
Recommended: Use pre-hashed passwords or environment variables:
# Generate hash (do this once)
./vpnclient --gen-hash username password
# Use hash instead of plaintext password
./vpnclient -u username --password-hash "your_hash_here"
# Or use environment variables
export SOFTETHER_PASSWORD_HASH="your_hash_here"
./vpnclient
SoftEtherZig is a complete rewrite of SoftEther VPN in pure Zig. While currently wrapping the battle-tested C core, we're systematically replacing all C code with safe, idiomatic Zig implementations.
Why Zig?
Zig Components (Pure Zig - Phase 1-3 Complete):
include/ffi.h
) for iOS, Android, and other platformsVPN Capabilities (SoftEther SSL-VPN Protocol):
# Clone the repository
git clone https://github.com/yourusername/SoftEtherZig.git
cd SoftEtherZig
# Build the client
zig build
# Generate password hash (recommended for security)
./zig-out/bin/vpnclient --gen-hash username password
# Copy the generated hash
# Connect to a VPN server (using hash)
sudo ./zig-out/bin/vpnclient -s vpn.example.com -H VPN -u username --password-hash "your_hash_here"
# Or use environment variables (most secure)
export SOFTETHER_SERVER="vpn.example.com"
export SOFTETHER_HUB="VPN"
export SOFTETHER_USER="username"
export SOFTETHER_PASSWORD_HASH="your_hash_here"
sudo -E ./zig-out/bin/vpnclient
β οΈ Security Warning: The examples in the rest of this README may show
-P password
for simplicity, but you should always use--password-hash
in production. See SECURITY.md for details.
# macOS
brew install openssl@3
# Ubuntu/Debian
sudo apt update
sudo apt install libssl-dev
# Fedora/RHEL
sudo dnf install openssl-devel
# Windows
# Download OpenSSL from https://slproweb.com/products/Win32OpenSSL.html
# Development build
zig build
# Optimized release build
zig build -Doptimize=ReleaseFast
# Install system-wide (optional)
sudo cp zig-out/bin/vpnclient /usr/local/bin/
# Basic connection
sudo vpnclient -s vpn.example.com -H VPN -u username -P password
# Custom port
sudo vpnclient -s vpn.example.com -p 8443 -H VPN -u username -P password
# Daemon mode (background)
sudo vpnclient -s vpn.example.com -H VPN -u username -P password -d
# Show help
vpnclient --help
Option | Description | Default |
---|---|---|
-s, --server <HOST> |
VPN server hostname | required |
-p, --port <PORT> |
VPN server port | 443 |
-H, --hub <HUB> |
Virtual hub name | required |
-u, --user <USERNAME> |
Username | required |
-P, --password <PASS> |
Password (use --password-hash instead!) |
required |
--password-hash <HASH> |
Pre-hashed password (recommended) | |
-a, --account <NAME> |
Account name | username |
--no-encrypt |
Disable encryption | false |
--no-compress |
Disable compression | false |
-d, --daemon |
Run as daemon | false |
Option | Description | Default |
---|---|---|
--use-zig-adapter |
Use Zig packet adapter (default, 10x faster) | true |
--use-c-adapter |
Use legacy C adapter (fallback) | false |
--profile |
Enable performance profiling | false |
Option | Description | Default |
---|---|---|
--reconnect |
Enable auto-reconnection | true |
--no-reconnect |
Disable auto-reconnection | false |
--max-retries <N> |
Max reconnection attempts (0=infinite) | 0 |
--min-backoff <SEC> |
Min backoff delay (seconds) | 5 |
--max-backoff <SEC> |
Max backoff delay (seconds) | 300 |
Option | Description | Default |
---|---|---|
--log-level <LEVEL> |
Log verbosity: silent, error, warn, info, debug, trace | info |
-h, --help |
Show help | |
-v, --version |
Show version |
const softether = @import("softether");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const config = softether.ConnectionConfig{
.server_name = "vpn.example.com",
.server_port = 443,
.hub_name = "VPN",
.account_name = "myaccount",
.auth = .{ .password = .{
.username = "user",
.password = "pass",
} },
.use_encrypt = true,
.use_compress = true,
};
var client = try softether.VpnClient.init(allocator, config);
defer client.deinit();
try client.connect();
// Your application logic here
while (client.isConnected()) {
std.time.sleep(1 * std.time.ns_per_s);
}
}
FFI Layer | Status | Platforms | Implementation | Recommended |
---|---|---|---|---|
ffi.h | β Active | All platforms | Pure Zig | β YES |
softether_ffi.h | β Removed | iOS only | C | β No |
Note: Legacy FFI was archived October 2025. See Migration Guide for historical context.
Phase | Component | Status | Progress | Target |
---|---|---|---|---|
1 | Foundation | π‘ In Progress | 15% | Q2 2026 |
1.1 | Platform Adapters (TUN/TAP) | β³ Starting | 0% | Q1 2026 |
1.2 | Mayaqua Library (utilities) | β³ Planned | 0% | Q2 2026 |
2 | Core Infrastructure | βΈοΈ Not Started | 0% | Q4 2026 |
2.1 | Network Stack (TCP/UDP/HTTP) | βΈοΈ Not Started | 0% | Q3 2026 |
2.2 | Cryptography Layer | βΈοΈ Not Started | 0% | Q4 2026 |
3 | Session Management | βΈοΈ Not Started | 0% | Q2 2027 |
4 | Protocols (SSTP/L2TP/OpenVPN) | βΈοΈ Not Started | 0% | Q4 2027 |
5 | Applications (Client/Server) | βΈοΈ Not Started | 0% | Q2 2028 |
Overall: 2% complete (~1,200 of ~70,000 lines ported to Zig)
Goal: Port macOS packet adapter to pure Zig
Create src/platform/macos.zig
Integrate ZigTapTun for utun management
Port DHCP packet handling
Achieve performance parity with C version
See Porting Progress Tracker for detailed task list.
βββββββββββββββββββββββββββββββββββββββ
β Zig Application Layer (PURE ZIG) β
β cli.zig, client.zig, config.zig β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββββββββββ
β FFI Layer (PURE ZIG) β
β ffi/ffi.zig - Cross-platform API β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
βββββββ΄ββββββ
β C Bridge β β Being eliminated
βββββββ¬ββββββ
β
ββββββββββββββββΌβββββββββββββββββββββββ
β SoftEther Core (C β Zig in progress)
β Cedar + Mayaqua libraries β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββββββββββ
β Platform Layer (C β Zig Phase 1) β
β TUN/TAP adapters β
βββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββ
β Zig Application β
β (Client, Server, Bridge) β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββββββββββ
β Protocol Layer (Zig) β
β SSTP, L2TP, OpenVPN β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββββββββββ
β Session Management (Zig) β
β Connection pooling, Keep-alive β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββββββββββ
β Network Stack (Zig) β
β TCP/UDP, HTTP, TLS via std.crypto β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββββββββββ
β Platform Adapters (Zig) β
β Pure Zig TUN/TAP via ZigTapTun β
βββββββββββββββββββββββββββββββββββββββ
SoftEtherZig/
βββ SoftEtherVPN_Stable/ # SoftEther C source (submodule)
β βββ src/ # Original SoftEther VPN codebase
βββ src/ # Zig implementation
β βββ main.zig # Library entry point
β βββ cli.zig # Command-line interface
β βββ client.zig # VPN client logic
β βββ config.zig # Configuration types
β βββ types.zig # Common data structures
β βββ errors.zig # Error definitions
β βββ ffi/
β β βββ ffi.zig # β
FFI (cross-platform C API)
β βββ c.zig # C imports and bindings
β βββ bridge/ # C bridge layer
β βββ softether_bridge.c # Main SoftEther interface
β βββ unix_bridge.c # POSIX system abstraction
β βββ packet_adapter_*.c # Platform-specific TUN/TAP
β βββ tick64_*.c # High-resolution timing
βββ legacy/ # Archived deprecated code
β βββ ffi/ # Legacy FFI (archived Oct 2025)
β βββ ios_ffi.c.archived # Old iOS FFI implementation
β βββ softether_ffi.h.archived # Old FFI header
β βββ ffi.zig.archived # Old Zig FFI stubs
βββ build.zig # Build configuration
βββ build.zig.zon # Zig package dependencies
βββ zig-out/ # Build artifacts
βββ bin/
βββ vpnclient # Compiled executable
cli.zig
): Command-line argument parsing and user interactionclient.zig
): High-level VPN connection managementbridge/
): C code that interfaces with SoftEther VPNffi.zig
): Safe Zig bindings to C functionsβββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Application ββββββ Zig Client ββββββ C Bridge β
β (CLI/Library) β β Logic β β Layer β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β β
βββββββββββββββββββββββββΌββββββββββββββββββββββββ
β
ββββββββββββββββββββββ
β SoftEther VPN β
β Core (C) β
ββββββββββββββββββββββ
β
ββββββββββββββββββββββ
β SSL/TLS 1.3 β
β (OpenSSL) β
ββββββββββββββββββββββ
β
ββββββββββββββββββββββ
β TUN/TAP Device β
β (Platform) β
ββββββββββββββββββββββ
Platform | Architecture | TUN Device | Status |
---|---|---|---|
macOS | x86_64, ARM64 | utun | β Tested |
Linux | x86_64, ARM64 | TUN/TAP | π§ Planned |
Windows | x86_64 | TAP-Windows6 | π§ Planned |
Platform | Architecture | Implementation | Status |
---|---|---|---|
Android | ARM64, ARMv7, x86_64 | JNI + VpnService | β Complete |
iOS | ARM64, x86_64 | PacketTunnelProvider | β Complete |
Mobile implementations are production-ready! See:
android/README.md
- Android integration guideios/README.md
- iOS integration guideZig enables seamless cross-compilation:
# Build for Linux from macOS
zig build -Dtarget=x86_64-linux-gnu
# Build for Windows from macOS
zig build -Dtarget=x86_64-windows-gnu
# Build for ARM64 Linux
zig build -Dtarget=aarch64-linux-gnu
# Debug build (with symbols)
zig build
# Release build (optimized)
zig build -Doptimize=ReleaseFast
# Safe release build
zig build -Doptimize=ReleaseSafe
# Build with custom target
zig build -Dtarget=aarch64-linux-gnu
# Build with specific CPU features
zig build -Dcpu=baseline
# Clean build artifacts
rm -rf zig-cache zig-out
The build system automatically:
SoftEtherZig supports three configuration methods with priority order:
Create ~/.config/softether-zig/config.json
:
{
"server": "vpn.example.com",
"port": 443,
"hub": "VPN",
"username": "myuser",
"password_hash": "base64-hashed-password"
}
Then simply run:
vpnclient # Uses config file
See docs/CONFIGURATION.md for complete configuration guide.
Example configurations:
config.example.json
- Full configuration with all optionsconfig.minimal.json
- Minimal working configurationConnection settings:
SOFTETHER_SERVER
: VPN server hostnameSOFTETHER_PORT
: VPN server portSOFTETHER_HUB
: Virtual hub nameSOFTETHER_USER
: UsernameSOFTETHER_PASSWORD
: Password (plaintext, not recommended)SOFTETHER_PASSWORD_HASH
: Pre-hashed password (recommended)SSL/TLS settings:
SSL_CERT_FILE
: Path to custom CA certificate bundleSSL_CERT_DIR
: Directory containing CA certificatesPermission Denied
# Solution: Run with sudo for TUN device access
sudo vpnclient -s server -H hub -u user -P pass
Connection Timeout
Authentication Failed
TUN Device Busy
/dev/net/tun
permissions# Build with debug symbols
zig build -Doptimize=Debug
# Run with verbose logging
sudo ./zig-out/bin/vpnclient -s server -H hub -u user -P pass 2>&1 | tee debug.log
src/
: Zig source codesrc/bridge/
: C bridge code interfacing with SoftEtherSoftEtherVPN_Stable/
: Upstream SoftEther VPN sourceCLI Features:
src/cli.zig
for new command-line optionsClient Features:
src/client.zig
for connection logicBridge Features:
src/bridge/softether_bridge.c
for new SoftEther integration# Run tests
zig build test
# Build and test specific target
zig build -Dtarget=x86_64-linux-gnu test
Contributions are welcome! Please:
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
The SoftEther VPN components are licensed under Apache License 2.0 by the SoftEther VPN Project.
SoftEtherZig - Bringing modern programming practices to enterprise VPN connectivity.