Pre-shared keys
A shared key is a password for gateways
Lesson 5 of 20 · 11 min · Module 2: Who is on the other end
Encryption is useless if you set it up with the wrong party. Before any child SA exists, each gateway has to prove to the other that it is who it claims to be.
Start this lesson →Free. No installation: you write and run the code in your browser, and it is checked automatically.
By the end, you’ll be able to…
- Explain what the pre-shared key proves
- Recognise AUTHENTICATION_FAILED
- Judge whether a key is strong enough
The idea
The simplest proof is a pre-shared key (PSK): the same secret typed into both gateways. It is never sent; each side proves that it knows it. A PSK is a password, with a password's weaknesses: short or guessable keys can be attacked offline by anyone who records the negotiation.
auth psk 9fK2-xQ7m-Lp41-vT8z-Bn6c
01Authentication happens in IKE_AUTH
After IKE_SA_INIT the two gateways share a secret channel, but neither knows who is at the other end. In IKE_AUTH each proves knowledge of the pre-shared key. If the keys differ by one character, the answer is AUTHENTICATION_FAILED, with no hint about which character.
02Make it long and random
A gateway never types its key by hand, so there is no reason for the key to be memorable. Use at least 20 random characters, a different key for every tunnel, and exchange it over a channel other than the email thread that contains the rest of the configuration.
03Keys on real devices
Devices store the key encrypted and do not show it again, so a mismatch is fixed by typing it once more on both sides. Certificates remove the shared secret altogether and are the better choice when there are many tunnels.
# FortiGate
config vpn ipsec phase1-interface
edit "to-branch"
set authmethod psk
set psksecret Vt4-9mQe-Xb72-hKs6-Pd1w
next
end
# Huawei USG
ike peer branch
pre-shared-key Vt4-9mQe-Xb72-hKs6-Pd1w
# Cisco IOS
crypto ikev2 keyring KEYS
peer BRANCH
address 198.51.100.2
pre-shared-key Vt4-9mQe-Xb72-hKs6-Pd1w
Your turn
Vt4-9mQe-Xb72-hKs6-Pd1w. The branch has already changed its side, so the tunnel is down. Update the key here.What the checks look for
- Authentication succeeds
- The new key is long and not guessable
- The tunnel carries the traffic between the offices
- Nothing else was changed
Take this with you
The pre-shared key proves each gateway to the other. Treat it as a password: long, random, unique per tunnel, and exchanged out of band.
Go a little further
Change one character of the key and run the lab. Notice that the error does not say which side is wrong, or where.