Sub topic 10
TLS-based VPNs
This chapter assumes you know what a tunnel and a VPN are, how encapsulation adds outer headers, and the difference between TCP and UDP. It also assumes you know what certificates and key exchange do. A TLS-based VPN uses the same handshake that protects HTTPS to set up the keys for a tunnel. OpenVPN is the best-known example.
The working model
TLS (Transport Layer Security) lets two peers authenticate each other and agree on session keys. A TLS-based VPN runs that handshake first. It then uses the resulting keys to protect the tunnelled traffic.
OpenVPN works in two parts:
- Control channel. A TLS session carries authentication and key negotiation. The server presents a certificate. The client usually presents one too, or sends a username and password, or both.
- Data channel. Packets from a virtual interface are encrypted and authenticated with keys derived from the control channel. The keys are renewed periodically.
The virtual interface comes in two forms. A tun device carries IP packets (layer 3). A tap device carries Ethernet frames (layer 2). Most deployments use tun because it is simpler and avoids broadcast traffic.
Transport choices
OpenVPN can run over UDP or TCP. The default is UDP port 1194.
| Transport | Strength | Weakness |
|---|---|---|
| UDP | Low overhead and good performance. Lost packets are left for the inner protocols to handle. | Some networks block it. |
| TCP (often port 443) | Passes through restrictive firewalls and proxies, because it looks like HTTPS. | "TCP over TCP" can stall. The outer and inner connections both retransmit, which can cause delay and collapsing throughput on lossy links. |
Prefer UDP when it works. Use TCP on port 443 as a fallback for networks that only allow web traffic.
Where it differs from IPsec and WireGuard
- Runs in user space. OpenVPN needs no kernel module beyond the tun/tap driver. This makes it portable across operating systems, but it costs some speed compared with in-kernel IPsec or WireGuard.
- Uses TLS and X.509 certificates. Teams that already run a certificate authority (CA) can reuse it. Revoking a lost laptop means revoking its certificate.
- Flexible configuration. The server can push routes and DNS settings to clients, which ties directly into split and full tunnelling.
A minimal client configuration
client
dev tun
proto udp
remote vpn.example.com 1194
remote-cert-tls server
ca ca.crt
cert client.crt
key client.key
verb 3remote-cert-tls server makes the client check that the server's certificate is actually marked for server use. Without it, any certificate your CA issued, for example one for a client, could be used to impersonate the server.
Common errors
- TLS handshake failed. The client's first packet never reached the server, or the replies never came back. Check that the port is open, that the transport matches on both sides, and that the clocks are roughly right, since certificates have validity periods.
- Certificate verification failed. The client does not trust the CA that signed the server certificate, or the certificate has expired.
- Connected, but no traffic to the internal network. The server must route the VPN subnet and the internal subnets, and IP forwarding must be on. Check routes on both ends.
- Large transfers hang while small ones work. This is an MTU problem. Test the path size as in the MTU chapter.
Exercise
A VPN client works from home over UDP but cannot connect from a hotel network that only allows web traffic. What change would you try, and what is the cost?
Show answer
Switch the OpenVPN client and server to TCP on port 443, so the traffic resembles HTTPS and passes the firewall. The cost is TCP-over-TCP behaviour: both the outer and inner connections retransmit, so throughput and latency can suffer on lossy links.