🐳 Sponsored by Narwhal Cloud
Cheap, high-bandwidth NAT VPS (
natvps) for geeks, students & network experiments. Lightweight Podman/LXC & isolated KVM engines, flexible daily billing, no contract, and 620+ global nodes to test latency and connectivity. Purely for learning and tinkering — spin one up, run your experiments, tear it down. → fuckip.me
A pure user-space OpenVPN → SOCKS5 converter, in the spirit of wg2socks.
It connects to an OpenVPN server described by an .ovpn file and exposes a
local SOCKS5 proxy whose traffic exits through the VPN — no TUN device, no
root, no kernel OpenVPN. Everything (the OpenVPN protocol and the TCP/IP
stack) runs in the process.
Verified end-to-end against VPN Gate / SoftEther (public-vpn-251.opengw.net:443,
TCP, AES-128-CBC + SHA1): a curl through the local SOCKS5 port exits from
the Tokyo VPN Gate node (AS36599 SoftEther), with DNS resolved inside the
tunnel (no leak).
SOCKS5 client
│ CONNECT host:port
▼
socks/ SOCKS5 server (CONNECT)
│ DialTCP(host:port)
▼
tunnel/ orchestrator: DNS-through-tunnel, keepalive, packet pumps
│ IP packets
▼
netstack/ gVisor user-space TCP/IP stack (channel endpoint)
│ raw IP packets
▼
datachan/ P_DATA_V1: AES-CBC + HMAC-SHA1 (non-AEAD), packet-id, PKCS#7
│ encrypted OpenVPN packets
▼
reliable/ control-channel reliability (session ids, packet ids, ACKs,
│ in-order reassembly) — exposes net.Conn to crypto/tls
control/ crypto/tls handshake + OpenVPN key-method-2 + PUSH_REQUEST
│
transport/ TCP (2-byte length prefix) or UDP framing
▼
OpenVPN server
The OpenVPN control channel runs TLS (1.3 here) over a home-grown reliability
layer that presents a net.Conn to Go's crypto/tls. Data-channel keys are
derived with OpenVPN's own TLS-1.0 PRF (MD5 ⊕ SHA1) from the key-method-2
exchange — independent of the negotiated TLS version.
| Package | Responsibility |
|---|---|
config |
Parse the .ovpn subset (proto, remote, cipher, auth, inline <ca>/<cert>/<key>) |
transport |
Carry whole OpenVPN packets over TCP (len-prefixed) or UDP |
proto |
Opcodes + control/ack packet (de)serialization |
reliable |
Hard-reset handshake, packet ids, ACKs, retransmit, in-order TLS stream → net.Conn |
control |
TLS handshake (chain-verify against <ca>), key-method-2, PUSH_REQUEST/REPLY |
datachan |
PRF, key derivation, P_DATA_V1 AES-CBC + HMAC encrypt/decrypt |
netstack |
gVisor stack with the pushed tunnel IP; DialTCP/DialUDP through the tunnel |
tunnel |
Pumps (netstack ⇄ data channel), keepalive ping, DNS-through-tunnel resolver |
socks |
SOCKS5 CONNECT server |
We provide an all-in-one installation and service management script install.sh for Linux servers:
- Systemd Integration: automatic startup on boot, background daemon, automatic restart.
- Interactive Node Selection: fetch live high-speed VPN Gate nodes and pick one by number or IP.
- Switch Nodes Anytime: easily switch to another node IP, switch to auto-routing mode, or import local
.ovpnwithout manual file editing. - Proxy Health & Egress Test: built-in connectivity test reporting real egress IP and location.
# One-click install (run as root or with sudo):
sudo ./install.sh
# Or remote installation (recommended on VPS):
curl -4 -fsSL https://raw.githubusercontent.com/narwhal-cloud/ovpn2socks/main/install.sh | sudo bash
# Fast mirror (if raw.githubusercontent.com is blocked):
curl -4 -fsSL https://ghfast.top/https://raw.githubusercontent.com/narwhal-cloud/ovpn2socks/main/install.sh | sudo bashAfter installation, invoke the management menu anytime simply by running:
ovpn2socks-ctlYou can also control the service directly via CLI shortcuts:
ovpn2socks-ctl switch-node <IP> # Switch immediately to target node IP and restart
ovpn2socks-ctl switch-auto # Switch to auto-pick node mode (Auto VPN Gate)
ovpn2socks-ctl switch-config <path> # Switch to local custom .ovpn file
ovpn2socks-ctl status # Check service running status
ovpn2socks-ctl test # Test proxy connection & display egress IP
ovpn2socks-ctl log # Follow live systemd logs
ovpn2socks-ctl restart # Restart servicego build ./cmd/ovpn2socks
# List live VPN Gate nodes (table or tsv format):
./ovpn2socks -list-nodes
./ovpn2socks -list-nodes -list-count 10 -list-format tsv
# Connect to a specific node IP or hostname:
./ovpn2socks -vpngate -node 219.100.37.4 -listen 0.0.0.0:1080
# Auto mode: fetch the live VPN Gate list and try nodes (official 443
# relays first, fastest first) until one connects. Recommended — VPN Gate
# nodes are flaky and rate-limit reconnects with AUTH_FAILED, so a single
# fixed node often rejects you; auto mode just skips to the next.
./ovpn2socks -vpngate -listen 127.0.0.1:1080
# Export a specific node's .ovpn configuration:
./ovpn2socks -export-node 219.100.37.4 -out node.ovpn
# Or run with a specific config file:
./ovpn2socks -config path/to/server.ovpn -listen 127.0.0.1:1080
# then:
curl --socks5-hostname 127.0.0.1:1080 https://api.ipify.orgVPN Gate relays are anonymous (empty credentials), but limit sessions per
source IP. Reconnecting quickly — or leaving lingering sessions from killed
processes — makes a node reject the next connection with AUTH_FAILED. It is
not a password error and not a client bug: the same binary connects fine to a
fresh node. -vpngate handles this by trying many nodes; -tries N bounds
the attempts, and a 12s handshake timeout skips dead/unresponsive nodes fast.
Diagnostic sub-commands (built incrementally, kept as smoke tests):
go run ./cmd/handshake -config x.ovpn # phase 1: control-channel TLS up
go run ./cmd/negotiate -config x.ovpn # phase 2: key-method-2 + PUSH_REPLY
go run ./cmd/datatest -config x.ovpn # phase 3: decrypt server keepalive (key check)- Cipher:
AES-{128,192,256}-CBC+HMAC-{SHA1,SHA256,SHA512}(the VPN Gate default). AES-GCM (AEAD) andtls-auth/tls-cryptwrapping are not yet implemented — the peer-info deliberately advertises only the configured CBC cipher so NCP-capable servers stay on CBC. P_DATA_V1only (nopeer-id/P_DATA_V2); adequate for VPN Gate.- No compression (none pushed by VPN Gate); a pushed
comp-lzo/compresswould need the 1-byte compression header. - No
reneg-secre-key or auto-reconnect yet; replay protection is a simple high-water mark, not a sliding window. - IPv4 egress (IPv6 plumbing exists in netstack but VPN Gate pushes v4 only).