IPSec

IPSec

innocentzero

2026-06-16

#networks #protocol | Status: Complete

The underlying protocol of how VPNs work

IPSec

The basic principle is fairly straightforward.

For any machine/router that's sending packets within the network, do nothing and run IP packets as they are.

For anything that's trying to send the packets outside, we turn the IP header into an IPSec header.

IPSec transport mode

Original IP hdr ESP hdr IP payload ESP trailer ESP Auth

The ESP header is the new addition.

IPSec tunnel mode

New IP Header ESP Header Old IP Header IP payload ESP trailer ESP Auth

ESP header is added on top of the old IP header, and a new IP header is added before the ESP header.

ESP header mechanism

ESP encrypts and optionally authenticates

ESP header is the same as the IP header, with the notable exception of its protocol number, which is 50 in this case. The payload itself might be enriched with optional padding (both for obfuscation and alignment), the followed by a pad length and the next-header field, which identifies the type of data contained in the enclosed protocol.

Note that the paddings, pad length, and the next-header field are after the payload. These are then followed by an integrity check.

IPSec security policy

Security Association Database

A security association is a one-way logical connection between a sender and a receiver.

Uniquely identified by 3 params:

The database stores cryptographic parameters associated with each association.

The parameters are negotiated by using IKE.

Security Policy Database

This is effectively an IP based packet filter lookup table alike.

Maps a subset of IP traffic to an association for that traffic.

May create entries in SAD

Internet Key Exchange

The actual exchange goes something like this:

Other forms of exchanges using child nodes and notifs etc are also there.