When you connect to a Wi-Fi network that uses WPA or WPA2 security, your device and the router go through a silent but important conversation before you can start browsing.
This conversation is called the 4-way handshake. It is the process that ensures both sides trust each other and that the data you send over the network is protected.
What is the 4-Way Handshake
The 4-way handshake is a security protocol used in Wi-Fi networks that ensures two things:
- Both the client (your device) and the access point (router) have the right encryption key.
- A unique session key is generated for that specific connection, so no one else can eavesdrop or reuse old keys.
It is called the "4-way" handshake because the process consists of four distinct message exchanges between the device and the access point.
Step-by-Step Process
Step 1: The Access Point Sends a Challenge
The access point sends a random number called a nonce to the client. This is used to help generate a temporary encryption key for this session.
Step 2: The Client Responds with Its Own Challenge
The client generates its own nonce and combines it with the one received from the access point. Using these two nonces and the pre-shared key (the Wi-Fi password), it creates a Pairwise Transient Key (PTK). The client sends back its nonce along with a Message Integrity Code (MIC) to prove that it has the correct password.
Step 3: The Access Point Confirms the Key
The access point uses the client’s nonce along with its own to generate the same PTK. If the MIC matches, it means the client has the right key. The access point then sends confirmation along with a message to install the keys for encryption.
Step 4: The Client Confirms and Starts Encrypting Data
The client sends a final acknowledgment. At this point, both sides have agreed on the encryption keys, and data transmission can start securely.
Why the 4-Way Handshake is Important
The 4-way handshake is not just a formality. It provides several security benefits:
- Verification: It ensures that both the client and the access point know the correct password without ever sending the password itself over the air.
- Fresh Keys: Every time you connect, new session keys are generated. This prevents attackers from reusing old keys from previous sessions.
- Protection from Replay Attacks: The nonces used in each handshake are unique, so an attacker cannot simply record a previous handshake and reuse it to gain access.
- Data Integrity: The handshake includes checks that prevent altered or corrupted messages from being accepted.
The Bigger Picture in Encryption and Decryption
The handshake is the step that happens before any actual encrypted data flows. Think of it as the warm-up before the main event. Without it, encryption and decryption would not be reliable because the keys could be wrong or reused.
If the handshake is compromised, the security of the entire session is at risk. That is why attacks like the KRACK attack target vulnerabilities in the 4-way handshake process itself.
Wrapping up
The 4-way handshake may only take a fraction of a second, but it is the foundation of secure Wi-Fi communication. It ensures that encryption and decryption are performed with fresh, verified keys, making your browsing sessions safer from prying eyes.
If you're a software developer who enjoys exploring different technologies and techniques like this one, check out LiveReview.
LiveReview delivers high-quality feedback on your PRs/MRs within minutes.
It saves hours per review by providing fast, automated first-pass insights. This helps both junior and senior engineers move faster.
If you're tired of waiting on peer reviews or unsure about the quality of feedback you'll receive, LiveReview is here to help.