SSH, WebSocket and TLS Tunneling Explained: How These Connections Work
What SSH tunnels are, why apps wrap them in WebSocket and TLS, what labels like SSH-WS-TLS mean, and the trade-offs of each layer.
في هذه الصفحة
- SSH tunneling
- Strengths and limits of SSH tunnels
- WebSocket: a tunnel that starts like a web request
- What about "payloads"?
- TLS: the encryption layer
- Putting the layers together
- Performance and security considerations
- SSH and WebSocket in Socket Tunnel X
- FAQ
- Is SSH tunneling the same as a VPN?
- Does WebSocket encrypt my traffic?
- Why use WebSocket at all?
- Does TLS hide which website I'm visiting?
- Sources
هذا المقال غير متوفر بالعربية بعد، لذا يظهر بلغته الأصلية، وهي الإنجليزية.
Labels like SSH, SSH-WS-TLS and VLESS-WS-TLS describe a stack of layers, and each layer has one job. SSH or VLESS carries your traffic, WebSocket gives it a web-style connection, and TLS encrypts the whole thing. Once you know what each layer does, these labels are easy to read, and you can tell what each one gains and costs.
SSH tunneling
SSH (Secure Shell) is best known for logging in to servers remotely, but it was designed from the start to carry other traffic too. The protocol is defined in a set of IETF standards, RFC 4251 to RFC 4254, and has three parts:
- The transport layer (RFC 4253) sets up encryption and checks the server's identity with its host key.
- User authentication (RFC 4252) checks who you are, with a password or a key.
- The connection protocol (RFC 4254) runs many "channels" inside one encrypted connection, including forwarded TCP connections.
That third part is what makes tunneling possible. With port forwarding, the SSH client accepts a connection on your side and the server opens the matching connection on its side. OpenSSH's dynamic forwarding (ssh -D) goes further and turns the client into a SOCKS proxy, so any program can send connections to any destination through the tunnel.
SSH tunnel apps on Android work along the same lines. They open an SSH connection to the server, capture the phone's traffic through Android's VPN interface, and send each connection through the SSH session.
Strengths and limits of SSH tunnels
- Mature and well reviewed. SSH has been in wide use for decades, and its cryptography is well understood.
- Encrypted by default. Modern SSH uses ciphers such as ChaCha20-Poly1305 and AES-GCM.
- Built for TCP. Port forwarding carries TCP connections. Apps that relay UDP over SSH, for DNS or voice calls, need an extra helper, and results vary.
- One connection for everything. All your connections share the SSH session's single TCP connection, so one lost packet holds up every channel until it's resent.
- Easy to recognise. An SSH connection opens by announcing its version in plain text, so networks that restrict SSH can spot it.
WebSocket: a tunnel that starts like a web request
WebSocket (RFC 6455) was created so web pages could keep a two-way connection open to a server. It starts with an ordinary HTTP request that asks to "upgrade" the connection:
GET /path HTTP/1.1
Host: example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13
The server answers 101 Switching Protocols, and from then on either side can send data, in frames, over the same connection. ws:// is WebSocket without encryption; wss:// is WebSocket over TLS.
Tunnel apps use WebSocket as a transport: SSH, VLESS or another protocol travels inside the WebSocket frames. That brings two practical advantages:
- It passes through web infrastructure. Reverse proxies and CDNs that support WebSocket can forward the connection to the real server, so the server doesn't have to be exposed directly.
- It starts like any web app. The opening request is an HTTP request like millions of others.
The costs are a little overhead for the handshake and the framing, and the fact that WebSocket on its own (ws://) adds no encryption.
What about "payloads"?
Some SSH tunnel apps let you edit a payload: the HTTP request the app sends before the tunnel itself starts. Over WebSocket, the payload is essentially an upgrade request like the one above. Through an HTTP proxy, it's usually a CONNECT request asking the proxy to open a connection to the SSH server. A payload has to match what the server or proxy expects, so it normally comes from whoever runs the server rather than being written by hand.
TLS: the encryption layer
TLS (Transport Layer Security) is what puts the "S" in HTTPS. Its current version, TLS 1.3, is specified in RFC 8446. In a tunnel, TLS does three things:
- It encrypts everything inside it, including the WebSocket handshake and the tunnel protocol.
- It authenticates the server with a certificate, so the client knows it reached the right server and not an impostor.
- It provides forward secrecy: TLS 1.3 negotiates fresh keys for each connection, so a key stolen later can't decrypt traffic recorded today.
One detail matters for privacy. During the handshake, the client usually sends the server's name (the SNI, Server Name Indication) unencrypted, so the network can see which name you connect to, though not what you exchange. Encrypted Client Hello (ECH) is designed to hide it, but it isn't available everywhere yet.
Putting the layers together
| Label | Tunnel protocol | Transport | Encryption | Notes |
|---|---|---|---|---|
| SSH | SSH | TCP | SSH's own | Simple and mature; easy for networks to recognise |
| SSH-WS | SSH | WebSocket | SSH's own | Can pass through web proxies and CDNs |
| SSH-WS-TLS | SSH | WebSocket inside TLS | TLS, plus SSH's own | Begins like an HTTPS connection |
| SSH-TLS (SSL) | SSH | TLS | TLS, plus SSH's own | TLS wraps SSH directly, without WebSocket |
| VLESS-WS-TLS | VLESS | WebSocket inside TLS | TLS | VLESS relies on TLS for encryption |
In SSH-WS-TLS your data is encrypted twice, once by TLS and once by SSH. That does no harm to security, but it costs a little extra processing.
Performance and security considerations
- Speed depends mostly on the server and the route. The layers add some overhead, but distance, server load and network quality matter more.
- Every layer has a cost. WebSocket adds framing and TLS adds a handshake. On a good connection you won't notice; on a weak one you might.
- Trust the server. Every option here encrypts the link between your phone and the server, but the server itself sees where your traffic goes.
- Respect the network's rules. Tunnels are a legitimate privacy tool, but using one to get around the terms of a network, whether an employer's, a school's or a mobile operator's, can break those terms.
SSH and WebSocket in Socket Tunnel X
Socket Tunnel X, the Android VPN developed by SBRK Dev Team, labels its servers by stack. SSH servers use a plain SSH tunnel. SSH-WS-TLS servers carry SSH over WebSocket inside TLS. VLESS-WS-TLS servers use VLESS on the same WebSocket-and-TLS transport. If one type doesn't connect well on your network, try another, as the setup and troubleshooting guide explains.
FAQ
Is SSH tunneling the same as a VPN?
Not exactly. A VPN protocol such as WireGuard or OpenVPN carries IP packets; an SSH tunnel carries individual connections. Android apps make SSH tunnels behave like a VPN by capturing traffic through the system's VPN interface.
Does WebSocket encrypt my traffic?
No. Plain WebSocket (ws://) is unencrypted. Encryption comes from TLS (wss://) or from the tunnel protocol inside it, such as SSH.
Why use WebSocket at all?
Because it lets the tunnel travel like web traffic, through the reverse proxies and CDNs that support WebSocket.
Does TLS hide which website I'm visiting?
TLS hides the content, but the server name is usually visible unless Encrypted Client Hello is used. Inside a tunnel, the network sees the tunnel server's name, not the sites you visit through it.
