Loading learning content...
Everything we've studied—security services, modes, and protocols—comes together in the IPSec architecture. This architecture defines how policies are specified, how cryptographic parameters are negotiated and stored, and how packets are matched to appropriate security treatments.
The IPSec architecture is fundamentally policy-driven. Rather than applying security uniformly to all traffic, IPSec allows administrators to define granular policies: different security levels for different traffic types, sources, destinations, and applications. This flexibility is both IPSec's greatest strength and its primary complexity factor.
Understanding this architecture is essential for:
By the end of this page, you will understand: (1) the Security Policy Database (SPD) and how it classifies traffic, (2) the Security Association Database (SAD) and its contents, (3) the concept of Security Associations and their parameters, (4) how IKE negotiates and manages Security Associations, and (5) how all components work together to process IP traffic securely.
The IPSec architecture, defined in RFC 4301, consists of several interconnected components that work together to provide security services. At the highest level:
Core Components:
| Component | Purpose | Storage |
|---|---|---|
| Security Policy Database (SPD) | Defines WHAT security to apply to WHICH traffic | Per-interface or global |
| Security Association Database (SAD) | Stores parameters for ACTIVE security associations | Per-endpoint |
| Security Associations (SAs) | The actual security relationships with all cryptographic parameters | Entries in SAD |
| IKE (Internet Key Exchange) | Negotiates and manages SAs automatically | Control plane daemon |
| IPSec Engine | Applies AH/ESP processing to packets | Kernel or hardware |
Conceptual Flow:
Planes of Operation:
Management Plane: Administrator configuration—defining policies, trust anchors (certificates/PSKs), and IKE parameters. This is typically done through configuration files, CLI commands, or management interfaces.
Control Plane: IKE daemon handles automatic key negotiation, SA establishment, and SA lifecycle management (rekey, expiration). IKE uses UDP port 500 (or 4500 for NAT-T) to communicate with peers.
Data Plane: The IPSec engine (kernel module or hardware accelerator) performs the actual packet processing—SPD lookup, SA lookup, encryption/decryption, authentication. This must be extremely fast for line-rate operation.
Separation of Concerns:
This separation is critical for both performance and security:
The Security Policy Database (SPD) is the heart of IPSec's policy-driven architecture. It contains ordered rules that specify what security treatment to apply to what traffic. Every packet processed by an IPSec implementation is evaluated against the SPD.
SPD Entry Components:
Each SPD entry (policy rule) contains:
| Selector | Description | Example Values |
|---|---|---|
| Source IP | Source address or range | 10.0.1.0/24, any, 10.0.1.5 |
| Destination IP | Destination address or range | 10.0.2.0/24, any, 192.168.1.100 |
| Protocol | IP protocol number or name | 6 (TCP), 17 (UDP), any, 1 (ICMP) |
| Source Port | L4 source port or range | 1024-65535, any, specific value |
| Destination Port | L4 destination port or range | 443, 22, 80,443 (list) |
| ICMP Type/Code | For ICMP, specific message types | 8/0 (echo request), any |
| Name/ID | User or machine identity (if available) | Certificate DN, username |
SPD Actions:
| Action | Meaning | Use Case |
|---|---|---|
| PROTECT | Traffic MUST be protected by IPSec. If no SA exists, negotiate one (or drop if negotiation fails). | Inter-site VPN traffic, sensitive data |
| BYPASS | Traffic passes without IPSec processing. | Already-encrypted traffic (HTTPS), local network traffic |
| DISCARD | Traffic is silently dropped. | Block unwanted traffic, prevent unprotected access |
Example SPD Configuration (Conceptual):
# Site-to-site VPN policy
Rule 1: src=10.0.1.0/24, dst=10.0.2.0/24, protocol=any
Action: PROTECT
Mode: tunnel
Endpoints: 203.0.113.1 <-> 198.51.100.1
Protocol: ESP (AES-256-GCM, SHA-256)
PFS: Group 19 (256-bit ECP)
# Allow outbound HTTPS without IPSec (TLS provides security)
Rule 2: src=10.0.1.0/24, dst=any, protocol=TCP, dport=443
Action: BYPASS
# Block SSH from external to internal
Rule 3: src=any, dst=10.0.1.0/24, protocol=TCP, dport=22
Action: DISCARD
# Default: allow all other traffic
Rule 4: src=any, dst=any, protocol=any
Action: BYPASS
SPD entries are evaluated in order—first match wins. Incorrect ordering can create security holes (traffic bypassing IPSec when it should be protected) or connectivity issues (traffic dropped or encrypted when it shouldn't be). Always place more specific rules before general rules, and test policy behavior with packet captures.
Inbound vs. Outbound SPD:
IPSec maintains separate SPD entries (or conceptually separate databases) for inbound and outbound traffic:
Outbound SPD (SPD-O): Evaluated when local system generates or forwards a packet. Determines whether to protect, bypass, or discard outgoing traffic.
Inbound SPD (SPD-I): Evaluated when a packet arrives and after any IPSec processing. Ensures that traffic that SHOULD have been protected actually WAS protected. Prevents downgrade attacks where an attacker removes IPSec protection.
Inbound SPD Verification Example:
Policy states: "Traffic from 10.0.2.0/24 to 10.0.1.0/24 MUST be IPSec-protected."
If an unprotected packet arrives with source 10.0.2.5 and destination 10.0.1.10, the inbound SPD check fails—an attacker might have injected this packet bypassing IPSec. The packet is discarded.
SPD Caching (SPD-S):
RFC 4301 introduces SPD-S (SPD cache), which caches the SPD lookup result along with the corresponding SA. This speeds up subsequent packets in the same flow, avoiding repeated SPD searches.
A Security Association (SA) is a unidirectional agreement between two IPSec peers specifying the security parameters for traffic in one direction. SAs are the runtime manifestation of security policies—they contain all the cryptographic material and parameters needed to protect traffic.
Key Characteristics of Security Associations:
| Parameter | Description | Example Value |
|---|---|---|
| SPI | Security Parameters Index—identifier chosen by receiver | 0xc32a7b91 |
| Sequence Counter | Current packet sequence number (for anti-replay) | 158473 (last sent/received) |
| Anti-Replay Window | Bitmap of received sequence numbers | 64-bit window, highest = 158473 |
| Encryption Algorithm | Algorithm for confidentiality | AES-256-GCM |
| Encryption Key | Symmetric key for encryption | 256-bit key material |
| Integrity Algorithm | Algorithm for authentication (if not AEAD) | HMAC-SHA-256-128 |
| Integrity Key | Key for MAC computation (if not AEAD) | 256-bit key material |
| Mode | Transport or Tunnel | tunnel |
| Tunnel Endpoints | For tunnel mode, gateway addresses | 203.0.113.1 ↔ 198.51.100.1 |
| Lifetime | When SA expires (time and/or bytes) | 28800s or 100GB |
| ESN Flag | Whether Extended Sequence Numbers are used | true (64-bit seq#) |
| Path MTU | Discovered MTU for tunnel (fragmentation) | 1400 bytes |
SA Identification:
An SA is uniquely identified by three values:
SPI (Security Parameters Index): 32-bit identifier chosen by the receiving peer during SA negotiation. When the receiver gets a packet, it uses the SPI to find the corresponding SA.
Destination IP Address: The destination in the outer (on-the-wire) IP header. For tunnel mode, this is the receiving gateway.
Security Protocol: Either ESP (50) or AH (51). An ESP SA and AH SA can have the same SPI without conflict.
Why SPI Alone Isn't Enough:
Multiple peers can (coincidentally) choose the same SPI. Including destination IP disambiguates:
Actually, in practice, since the SPI is chosen by the receiver, and both SAs terminate at your IP, the destination IP is the same. The disambiguation comes from the combination being unique per negotiation—IKE won't assign the same SPI to two different SAs.
Since SAs are unidirectional, two SAs are needed for bidirectional communication: an 'inbound' SA (from peer to you, with your chosen SPI) and an 'outbound' SA (from you to peer, with peer's chosen SPI). IKE negotiates both SAs together as a 'Child SA' pair, but they have different SPIs and are stored as separate entries.
SA Lifecycle:
┌─────────────────────────────────────────────┐
│ │
▼ │
[No SA] ──► IKE Negotiation ──► [Active SA] ──► [Expire] ──► Rekey
│ │
│ ▼
└───────► [Deleted]
Lifecycle Events:
Creation: IKE negotiates SA parameters with peer, exchanges keying material, both sides create matching SAs.
Active Use: Packets are encrypted/decrypted using SA parameters. Sequence counter increments.
Soft Lifetime Expiration: Configurable threshold (e.g., 80% of hard lifetime). Triggers rekey—IKE negotiates replacement SA before old one expires.
Rekey: New SA created with fresh keys. Traffic transitions to new SA. Old SA deleted after grace period.
Hard Lifetime Expiration: SA must not be used after hard limit (time or bytes). If not rekeyed, traffic drops.
Deletion: SA removed from SAD when no longer needed (explicit delete, expiration, or error).
The Security Association Database (SAD) stores all active Security Associations. It's the runtime repository of security relationships, containing the keying material and parameters needed for packet processing.
SAD Operations:
| Operation | When | Description |
|---|---|---|
| Create | IKE SA negotiation completes | Insert new SA with all parameters |
| Lookup | Every protected packet | Find SA by (SPI, dest IP, protocol) |
| Update | Packet processing | Increment sequence counter, update stats |
| Rekey | Soft lifetime reached | Create new SA, mark old for deletion |
| Delete | Lifetime expires or explicit delete | Remove SA, securely erase keys |
SAD Lookup Performance:
For high-speed networks processing millions of packets per second, SAD lookup must be extremely fast. Implementations use:
Typical SAD capacity:
SAD Entry Structure (RFC 4301):
For each SA, the SAD contains:
SAD Entry {
// Identification
SPI: 32-bit identifier
Protocol: ESP or AH
Destination: IP address (outer header destination)
Source: IP address (for validation, optional)
// Cryptographic Parameters
EncryptionAlgorithm: e.g., AES-256-GCM
EncryptionKey: byte array
IntegrityAlgorithm: e.g., HMAC-SHA-256 (if not AEAD)
IntegrityKey: byte array (if not AEAD)
// Mode and Tunnel
Mode: transport or tunnel
TunnelSource: IP (for tunnel mode)
TunnelDestination: IP (for tunnel mode)
// Anti-Replay
SequenceCounter: 32 or 64 bits
SequenceCounterOverflow: bool (error if true and counters exhausted)
AntiReplayWindow: bitmap + highest seen
// Lifetime
LifetimeSeconds: remaining time
LifetimeBytes: remaining bytes
// Traffic Selectors
LocalSelector: what local traffic this SA protects
RemoteSelector: what remote traffic this SA protects
// State
State: active, expiring, larval, dying
}
SAD entries include traffic selectors that were negotiated during IKE SA establishment. These may be narrower than the SPD policy (e.g., policy says 'protect 10.0.0.0/8' but the negotiated SA only covers '10.0.1.0/24'). The inbound policy check verifies received packets fall within the SA's selectors—preventing an attacker from sending traffic outside the protected range through the tunnel.
SAD Security Considerations:
Key Protection: SAD contains highly sensitive cryptographic keys. Implementations must:
Side-Channel Resistance: SAD access patterns could leak information:
Concurrent Access: In multi-core systems, multiple threads may access SAD simultaneously:
IKE (Internet Key Exchange) is the control-plane protocol that manages IPSec Security Associations. IKE handles the complex cryptographic negotiations—authentication, key agreement, algorithm selection—so that the data-plane (ESP/AH) can use simple, fast symmetric cryptography.
IKE Versions:
| Version | Defined In | Status | Notes |
|---|---|---|---|
| IKEv1 | RFC 2409 (1998) | Deprecated | Complex, multiple modes, security issues |
| IKEv2 | RFC 7296 (2014) | Current Standard | Simplified, single exchange sequence |
IKEv2 is the modern standard and should be used for all new deployments. IKEv1 exists only for legacy interoperability.
What IKE Does:
IKE SA vs. Child SA:
IKE operates with two levels of Security Associations:
IKE SA (Parent SA):
Child SA (IPSec SA):
| Exchange | Messages | Purpose |
|---|---|---|
| IKE_SA_INIT | 2 messages | Key exchange (DH), nonces, algorithm negotiation. Not encrypted. |
| IKE_AUTH | 2 messages | Authentication, identity confirmation, first Child SA. Encrypted with IKE SA keys. |
| CREATE_CHILD_SA | 2 messages | Create additional Child SA, or rekey existing SA. Always encrypted. |
| INFORMATIONAL | 2 messages | Delete notification, error notification, dead peer detection. Encrypted. |
Initial Exchange: IKE_SA_INIT + IKE_AUTH
A complete IKE session establishment requires 4 messages (2 round trips):
IKE_SA_INIT (Messages 1-2):
Initiator → Responder:
- SA payload: Proposed algorithms for IKE SA
- KE payload: Diffie-Hellman public value
- Ni payload: Initiator nonce
Responder → Initiator:
- SA payload: Selected algorithms
- KE payload: Responder's DH public value
- Nr payload: Responder nonce
- [CERTREQ]: Optional request for certificates
After this exchange, both parties compute:
The IKE SA is now established and subsequent messages are encrypted.
IKE_AUTH (Messages 3-4):
Initiator → Responder (encrypted):
- IDi: Initiator identity
- [CERT]: Optional certificate chain
- AUTH: Authentication payload (signature or PSK-based MAC)
- SAi2, TSi, TSr: First Child SA proposal + traffic selectors
Responder → Initiator (encrypted):
- IDr: Responder identity
- [CERT]: Optional certificate chain
- AUTH: Response authentication
- SAr2, TSi, TSr: Selected Child SA + traffic selectors
After IKE_AUTH:
During CREATE_CHILD_SA for rekeying or additional SAs, a new Diffie-Hellman exchange can be performed (optional but recommended). This provides PFS—each Child SA has independent keying material. Even if one Child SA's keys are compromised, others remain secure. PFS is enabled by including KEi/KEr payloads in CREATE_CHILD_SA.
IKE supports multiple authentication methods, each with different security properties, deployment requirements, and operational characteristics.
Pre-Shared Keys (PSK):
Both peers are configured with an identical secret string. The AUTH payload contains a MAC computed over the IKE messages using a key derived from the PSK.
Advantages:
Disadvantages:
Best Practice: Use strong, unique PSKs per peer. Minimum 20 characters random. Never share PSK across multiple sites.
| Method | Security | Complexity | Scalability | Use Case |
|---|---|---|---|---|
| Pre-Shared Key (PSK) | Medium (secret sharing) | Low | Poor (O(n²) keys) | Small deployments, testing |
| RSA Certificates | High (PKI) | Medium | Excellent | Enterprise VPN |
| ECDSA Certificates | High (PKI) | Medium | Excellent | Modern deployments, smaller keys |
| EAP | Varies by method | High | Good | Remote access with user auth |
| EAP-TLS | High | High (PKI + radius) | Good | Enterprise remote access |
Digital Certificates (RSA/ECDSA):
Peers authenticate using X.509 certificates and corresponding private keys. The AUTH payload contains a digital signature over the IKE messages.
How It Works:
PKI Requirements:
EAP (Extensible Authentication Protocol):
EAP allows integration with external authentication systems:
EAP is asymmetric in IKEv2: the responder (server) authenticates to initiator (client) using certificates, then initiator authenticates using EAP method.
Weak pre-shared keys are vulnerable to offline dictionary attacks. An attacker capturing IKE_SA_INIT exchanges can attempt to derive the PSK offline. Use random, strong PSKs (at least 20 characters from a cryptographic random source). Never use dictionary words, common phrases, or predictable patterns. Consider certificates for any deployment requiring serious security.
Let's trace a complete IPSec session from initial configuration through active traffic protection:
Scenario: Site-to-site VPN between two corporate locations.
Phase 1: Configuration (Management Plane)
Site A Gateway (203.0.113.1):
SPD:
- src=10.0.1.0/24, dst=10.0.2.0/24 → PROTECT
- ESP tunnel mode to 198.51.100.1
- AES-256-GCM, SHA-384 PRF, Group 19 DH
IKE:
- Peer: 198.51.100.1
- Auth: PSK "very-strong-random-psk-here"
- Lifetime: 86400s (IKE), 28800s (Child)
Site B Gateway (198.51.100.1):
SPD:
- src=10.0.2.0/24, dst=10.0.1.0/24 → PROTECT
- ESP tunnel mode to 203.0.113.1
- AES-256-GCM, SHA-384 PRF, Group 19 DH
IKE:
- Peer: 203.0.113.1
- Auth: PSK "very-strong-random-psk-here"
Phase 2: First Packet Triggers IKE (Control Plane)
Phase 3: IKE Negotiation
Site A → Site B: IKE_SA_INIT
- Propose: ENCR_AES_GCM_256, PRF_HMAC_SHA2_384, DH_ECP256
- DH public value (256-bit ECC point)
- Initiator nonce (32 bytes)
Site B → Site A: IKE_SA_INIT Response
- Accept: ENCR_AES_GCM_256, PRF_HMAC_SHA2_384, DH_ECP256
- DH public value
- Responder nonce
[Both compute shared secret, derive IKE SA keys]
Site A → Site B: IKE_AUTH (encrypted)
- ID: 203.0.113.1
- AUTH: prf(prf(PSK, "Key Pad"), signed octets)
- Child SA proposal: ESP, ENCR_AES_GCM_256
- Traffic Selectors: 10.0.1.0/24 ↔ 10.0.2.0/24
Site B → Site A: IKE_AUTH Response (encrypted)
- ID: 198.51.100.1
- AUTH: verification
- Child SA accept: SPI = 0xaabbccdd (Site A's inbound)
- Traffic Selectors confirmed
Phase 4: SA Installation
Both gateways create matching SAD entries:
Site A SAD Entry (Outbound to Site B):
SPI: 0x11223344 (Site B's choice)
Encryption: AES-256-GCM
Key: [derived from IKE keying material]
Sequence: 0
Mode: tunnel
Tunnel: 203.0.113.1 → 198.51.100.1
Site A SAD Entry (Inbound from Site B):
SPI: 0xaabbccdd (Site A's choice)
Encryption: AES-256-GCM
Key: [derived from IKE keying material]
Anti-replay window: initialized
Mode: tunnel
[Mirror entries created at Site B]
Phase 5: Traffic Protection (Data Plane)
The original packet (10.0.1.5 → 10.0.2.7) is now processed:
At Site B:
You've now seen how all IPSec components work together: SPD defines policy, IKE negotiates parameters when needed, SAD stores active SAs, and ESP processes packets. This architecture enables flexible, policy-driven security while maintaining high performance through separation of control and data planes.
We've completed our exploration of IPSec architecture. Let's consolidate the key insights:
Module Complete:
You have now completed the IPSec Overview module. You understand:
This foundation prepares you for deeper study of IPSec components in subsequent modules, including Authentication Header details, ESP internals, Security Association management, and VPN design patterns.
Congratulations! You've mastered the fundamentals of IPSec—from its historical purpose through security services, modes, protocols, and architecture. You now have the conceptual foundation to configure IPSec solutions, troubleshoot connection issues, and design secure network architectures. Continue to the next module for deeper exploration of specific IPSec components.