Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Secure network protocols (TLS, SSH, VPN)

After this lesson: I can pick a protocol that protects the traffic.

60 min lesson4 commandsWireGuard lab: build a VPN tunnel between two sites in your browser

A password sent in plain text leaks

A secure protocol sends data so that it stays private and unchanged, and proves who is at the other end. Old protocols did none of these.

You can swap most of them for a protected partner by changing a setting.

A shop manager logs in to a server from a cafe. If the login travels as plain text, anyone on the cafe wifi can read the password.

By the end of this lesson

Note

I can pick a protocol that protects the traffic.

Key words

WordWhat it means
Encryptionscrambling data so only the right key can read it
Integrityproof that data was not changed on the way
Certificatea signed statement of who owns a server's key
TLSTransport Layer Security: the protection behind HTTPS
SSHSecure Shell: protected remote login
Tunnelprivate traffic wrapped inside other traffic

The cells students fill in are left blank in this preview.

A secure protocol makes three promises

Secrecy: nobody on the way can read the data. That is encryption.

Integrity: nobody can change the data without being noticed.

Identity: you are talking to the right server, not a fake. A certificate or a stored key proves it.

A protocol missing one promise leaves a gap that an attacker uses.

Worked example: plain protocols and their partners

Plain protocolUsed forProtected partner
HTTPWeb pagesHTTPS, which is HTTP inside TLS
TelnetRemote loginSSH
FTPMoving filesSFTP, which runs inside SSH
Plain email linksMail between serversThe same links inside TLS
A plain link between two sitesPrivate traffic over the internetA tunnel such as WireGuard

The cells students fill in are left blank in this preview.

Fingerprint a message

Command
printf 'pay 100 pounds' | sha256sum

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Fingerprint the same message with one change

Command
printf 'pay 900 pounds' | sha256sum

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

A fingerprint shows if a message changed

A hash function turns any message into a short fingerprint. Change one character and the fingerprint changes completely.

The first message gives a fingerprint that starts 26c42532. The second starts e71dd267. They share nothing, although only one digit differs.

This is how integrity works. The sender sends a protected fingerprint, and the receiver checks it. If the two differ, the message was changed.

TLS protects the web and SSH protects logins

With TLS, the server shows a certificate. A trusted authority has signed it to say "this key belongs to this name". The browser checks the signature and the name before it sends anything private.

Then both sides agree a fresh key, and everything after is encrypted.

With SSH, a login is protected the same way. The best practice is to log in with a key pair, not a password, because a stolen password works from anywhere.

An example of settings to review

Code: bash
# An example only: a gateway's settings.
PermitRootLogin no
PasswordAuthentication no
MinTlsVersion 1.2
Ciphers chacha20,aes256
ListenAddress 10.0.0.1
DnsMode protected

Strong settings are as important as the protocol

A protected protocol can still be set up badly. The example above has good choices: no root login, no passwords, a modern TLS floor, no weak ciphers and a named listening address.

Change one line to PermitRootLogin yes or MinTlsVersion 1.0 and the same software becomes weak. A review looks at the settings, not only the name of the protocol.

Plain DNS can be read and forged

The Domain Name System (DNS) turns a name into an address. A plain DNS question is sent as readable text, and the answer is not signed.

So someone on the path can see which sites you ask for. They can also send a false answer that sends you to a fake server.

DNS over TLS and DNS over HTTPS encrypt the question. DNSSEC signs the answer. The safest set-up uses a protected resolver.

A tunnel protects everything between two sites

TLS and SSH protect one kind of traffic. A tunnel protects all the traffic between two points, whatever it is.

A tunnel is the right tool when two sites must share old software that has no protection of its own. It wraps everything in one encrypted layer.

Meet the two sites and their link

Command
wglab status

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Count the public key of a throwaway pair

Command
wg genkey | wg pubkey | wc -c

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

What the two Runs show

The first Run lists four machines. The two gateways each have a second address on wan0, the link that stands for the open internet. Anything that crosses it can be watched.

The second Run makes a private key, turns it into the public key and counts it, without printing either. It prints 45: the public key's 44 characters and the newline.

The private key is gone with the command. Nothing was saved.

A common mistake

Warning

Many people think the padlock on a web page means the site is safe. The padlock means the connection is encrypted to that server. It does not mean the server is honest. A fake site can have a padlock too.

About this lab and its source: WireGuard lab: build a VPN tunnel between two sites in your browser

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.