> For the complete documentation index, see [llms.txt](https://phiph.gitbook.io/foundation-1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://phiph.gitbook.io/foundation-1/network/ipsec.md). Agents can also search and read this documentation through its [MCP server](https://phiph.gitbook.io/foundation-1/~gitbook/mcp).

# IPSeс

## 1 Introduction

**What is it?**

* IPsec is not a single protocol, but a framework for securing IP traffic
* It is primarily designed to protect unicast traffic in point-to-point VPNs
* IPsec establishes a secure control channel first - Phase 1, then negotiates data-protecting channel - Phase 2
* The control channel is used only for key management and crypto parametres negotioation for data channel
* User data is protected separately using Data channel
* All communications inside both tunnels are encrypted and authenticated
* Routing protocols that rely on multicast or broadcast (e.g., OSPF, EIGRP) cannot run directly over classic IPsec tunnels
* To support such protocols, a GRE tunnel is built first, and IPsec is used to encrypt the GRE traffic

**Why it was invented?**

* To add security to IP networking itself
* Original Internet had no built-in security
* IP provides no: Encryption, Authentication, Integrity protection, Anti-replay protection
* Anyone on the path could: Read packets, Modify packets, Spoof IP addresses, Inject traffic
* Security at higher layers was not enough: Every application had to implement its own security
* IPsec enabled: Site-to-site VPNs, Remote-access VPNs, Secure inter-datacenter links

**Who and when invented it?**

* Internet Engineering Task Force (IETF) in 1995
* 1996–1998 - BSD Linux Implementations
* Late 1990s – early 2000s: Cisco, Checkpoint, Juniper

**What is required to establish a secure channel over an untrusted network?**

* Peers must securely exchange cryptographic keys for encryption and packet authentication in a way that prevents any third party from learning those keys - Diffie Hellman algorithm is used for this, also possible: RSA key transposrt, key distribution centre
* Peers must mutually authenticate each other, so that each side can verify the identity of the other - preshared keys, login/passwords, certificates, MFA are used for this
* Peers must negotiate the cryptographic algorithms that will be used to encrypt and decrypt data - symmetric encryption algorithms are used: 3DES, AES...
* Peers must negotiate the algorithms that will be used to provide integrity and authentication for each packet - HMAC algorithms are for authentication of each packet and its integrity
* After the secure session is established, peers exchange data packets that are encrypted and authenticated using the negotiated algorithms and derived keys

**IPSec goals**

* Mutual authentication of peers
* Secure key establishment
* Negotiation of security parameters
* Creation and management of Security Associations
* Data encryption - confidentiality
* Data integrity - data is not modified
* Authentication of packet origin - Verify that packets truly come from the expected peer - Cryptographic authentication per packet
* Anti-replay protection
* Traffic protection policy enforcement - Define which traffic is protected and how
* Secure transport over untrusted networks

**Architecture**

```bash
IPsec Framework
──────────────────────────────────────────────

IKE  → Key Management / Control Plane
│
│── Versions
│   ├── IKEv1
│   │   ├── Based on: ISAKMP + Oakley + SKEME
│   │   │
│   │   ├── Phase 1  → Establish IKE SA
│   │   │   ├── Main Mode
│   │   │   └── Aggressive Mode
│   │   │
│   │   └── Phase 2  → Establish IPsec SAs
│   │       └── Quick Mode
│   │
│   └── IKEv2
│       ├── Unified protocol
│       ├── IKE SA    → Control channel
│       └── CHILD SA → Data channel
│
│── Authentication
│   ├── Pre-Shared Key (PSK)
│   ├── Digital Certificates
│   ├── Xauth (IKEv1)
│   └── EAP (IKEv2)
│
│── │   ├── UDP 500       (IKE)
│   └── UDP 4500      (IKE NAT-T)
│
──────────────────────────────────────────────

ESP  → Data Protection
│
│── Functions
│   ├── Encryption
│   ├── Integrity
│   └── Anti-replay
│
│── Transport
│   ├── IP Protocol 50
│   └── UDP 4500      (ESP NAT-T)
│
│── Modes
│   ├── Tunnel Mode
│   │   └── Encrypts entire IP packet
│   │
│   └── Transport Mode
│       └── Encrypts payload only
│
──────────────────────────────────────────────

AH  → Integrity / Authentication
│
│── Functions
│   └── Integrity + Authentication only
│
│── Transport
│   └── IP Protocol 51
│
│── Modes
│   ├── Tunnel Mode
│   └── Transport Mode
```

**RFC**

* RFC 4301 — Security Architecture for the Internet Protocol (IPsec architecture)
* RFC 2411 — IP Security Document Roadmap
* RFC 4303 — IP Encapsulating Security Payload (ESP)
* RFC 4302 — IP Authentication Header (AH)
* RFC 2409 — Internet Key Exchange (IKEv1)
* RFC 2407 — ISAKMP DOI for IPsec
* RFC 2408 — ISAKMP
* RFC 2412 — Oakley Key Determination Protocol
* RFC 7296 — Internet Key Exchange Protocol Version 2 (IKEv2)
* RFC 3947 — Negotiation of NAT-Traversal in the IKE
* RFC 3948 — UDP Encapsulation of IPsec ESP Packets
* RFC 5998 — Use of EAP Authentication in IKEv2
* RFC 3706 - DPD
* XAUTH (IKEv1, non-RFC standard)
* IKEv1 Mode Config - No RFC
* Vendor RA extensions

**Documentation**

* [Cisco IPSec Negotiation/IKE Protocols](https://www.cisco.com/c/en/us/tech/security-vpn/ipsec-negotiation-ike-protocols/index.html)

**Communications**

* Two nodes can build multiple IPsec tunnels using the same physical interfaces and even the same IP addresses
* IPSec identifies tunnels by `SPI (Security Parameter Index) + destination IP + protocol (ESP/AH)`
* In IKEv1 `Multiple independent IKE tunnels between the same IP pair are usually NOT supported`
* Both nodes use UDP port 500, but Initiator and Responder SPIs are used for multiplexing/demultiplexing
* Some vendors may not support multiple IKEv1 tunnels between the same IPs
* Usually, 1 IKE tunnel and many IPSec tunnels are used
* Real-world cases for 2 completely seaprate IKE and IPSec SAs between 2 nodes:
  * Different authentication methods
  * Different crypto domains
  * Different VRFs
  * Migration scenarios
  * Strong policy separation requirements

**Deployments**

```
IPsec Ecosystem
│
├─ Core IPsec Modes
│  │
│  ├─ ESP Transport Mode
│  │   └─ Host-to-Host encryption
│  │
│  └─ ESP Tunnel Mode
│      └─ Gateway-to-Gateway VPN
│
├─ Basic IPsec VPN Architectures
│  │
│  ├─ Site-to-Site VPN
│  │   ├─ Hub-and-Spoke
│  │   ├─ Full Mesh
│  │   └─ Dual-Hub Redundant
│  │
│  ├─ Remote Access VPN
│  │   ├─ IKEv1 + XAUTH
│  │   ├─ IKEv2 + EAP
│  │   └─ L2TP/IPsec client VPN
│  │
│  └─ Host-to-Host IPsec
│
├─ Tunneling Protocols Combined with IPsec
│  │
│  ├─ L2TP over IPsec
│  │   └─ PPP features (authentication, IP assignment)
│  │
│  ├─ GRE over IPsec
│  │   ├─ routing protocols
│  │   ├─ multicast traffic
│  │   └─ dynamic routing over VPN
│  │
│  ├─ IPIP over IPsec (rare)
│  │
│  └─ VTI (Virtual Tunnel Interface)
│      └─ route-based IPsec VPN
│
├─ Scalable VPN Architectures
│  │
│  ├─ DMVPN
│  │   ├─ GRE
│  │   ├─ NHRP
│  │   └─ IPsec encryption
│  │
│  ├─ FlexVPN
│  │   └─ IKEv2 framework for scalable VPNs
│  │
│  ├─ GETVPN
│  │   └─ group encryption without tunnels
│  │
│  └─ ADVPN
│      └─ auto-discovered spoke-to-spoke tunnels
│
├─ Modern Enterprise Deployments
│  │
│  ├─ Cloud VPN
│  │   ├─ On-prem → Cloud
│  │   ├─ Cloud → Cloud
│  │   └─ Hybrid networks
│  │
│  ├─ SD-WAN overlays
│  │   └─ IPsec tunnels between edges
│  │
│  └─ Datacenter encryption
│      └─ server-to-server IPsec
│
└─ Rare / Historical Uses
   │
   ├─ AH-based VPN
   ├─ Mobile IP with IPsec
   └─ IPsec protecting routing protocols
```

## 2 IPSec Terms

IPSec has several terms, which are used everywhere in protocol descriptions. These terms are:

* SPI
* Transform set
* SA
* Traffic Selectors/Proxy IDs

Below is their meaning and description

### 2.1 SPI

* SPI stands for `Security Parameters Index`
* SPI is a field or fields in a packet header of IKE, ESP, or AH protocols
* Why is it needed? `To demultiplex IKE/ESP/AH traffic.` It is like port numbers in TCP/UDP. Based on SPI node understand which SA to use to process particular traffic flow

`SPI is used in two contexts:`

* IKE SPI
* `IPSec SPI` - generated and exchanged in Phase 2 in IKEv1 or in IKEv2 during CHILD SA creation (IKE\_AUTH or CREATE\_CHILD\_SA)

SPIs are also described using different perspectives: `local and remote, inbound and outbound, initiator and responder`:

* Outbound/Inbound
  * Outbound and inbound logic is relevant only for Phase2/IKE\_AUTH SPIs and used in: AH, ESP
  * `Outbound SPI` - The SPI my router inserts into ESP/AH I send
  * `Inbound SPI` - The SPI my router expects to see in ESP/AH packets I receive
* Initiator/Responder
  * Used in IKE packets
  * `Inititor SPI` - generated by node, which started IKE conversation
  * `Responder SPI` - generated by node, which accepted IKE connection
* Local/Remote
  * These terms are used only in IKE SA description inside the node logic
  * `Local SPI` = the SPI I generated
  * `Remote SPI` = the SPI peer generated

**IKE SPI**

* IKE SPI `generated by each node and transfered in Phase 1 IKEv or IKE_SA_INIT in IKEv2,`
* `Used in all IKE packets`
* Every IKE packet `contains 2 SPIs` 64 bits each:

```
Initiator SPI:  a1b2c3d4e5f60708
Responder SPI:  a1b2c3d4e5f4a1bb
```

* IKE SA is uniquely identified by these `2 SPIs`
* IKE SPI may also be called a `Cookie`
* In IKEv1, the values in the ISAKMP header are formally called cookies, but the RFC explicitly defines them as SPIs for the ISAKMP/IKE SA
* `IKEv2 no longer uses “cookie” as the name for SPI fields; it uses “SPI”, while “cookie” refers to a separate payload`

**IKE SPI flow and terms diagram**

**IPSec SPI**

* IPSec SPI is 32 bits - identifies a specific Security Association (SA) in IPsec (Data Tunnel)
* IPSec SPI is generated by both peers and exchanged during Phase 2 IKEv1 or IKE\_AUTH INKEv2
* Each node generates IPSec SPI and sends it to a peer, it means: use this number when you send ESP/AH packets to me
* This number is injected into the header of every ESP/AH, so the remote peer knows which Security Assosiation (SA) `[cryptographic parametres and keys]` to use for decryption and authentication
* `Only one SPI field in every ESP/AH packet, not two, as in IKE SPI`
* IPSec tunnel SA is uniquely identified by `1 SPI`, but at the same time there are `2 SAs` in routers memory for each IPSec tunnel: `Inbound SA and Outbound SA`
* Inbound SA is identified by inbound SPI - this SPI was received from the peer
* Outbound SA is identified by outbound SPI - this SPI was generated locally
* For every new IPSec tunnel - because of different traffic selectors - new pairs of SPI are generated by both sides

**IPSec SPI Flow**

### 2.2 SA

* SA - Security association - `has 2 meanings`
  * Meaning 1 - it is a set of cryptographic options that are negotiated between devices that are establishing an IPSec relationship
  * Meaning 2 - it is a logical object stored and tracked by the device (router/firewall)
* SAs are used in both meanings in both tunnels: Control and Data
* Control and Data tunnels have different SAs
* Each IPSec connection to 1 peer has minimum 3 SAs in router's memory: 1 SA for control tunnel (bidectional, used for inbound and outbound traffic) and 2 SAs for Data tunnel: one for Inbound traffic and one for Outbound
* Each IPSec connection to a peer may have more than 2 Data tunnel SAs, it depends on the amount of traffic selectors, for each traffic selector another pair of SAs for Data tunnel is created

#### 2.3.1 Control tunnel - IKE SA - ISAKMP SA

**As a set of options**

* SA, used during Phase 1 in IKEv1 and IKE\_INIT in IKEv2, is called IKE SA or ISAKMP SA and it is `Bidirectional`: used for protecting control traffic in both directions
* IKE SA as a set of cryptographic options consist of `SPIs(initiator and responder) and Proposals` - this is what we see in a packet
* `Proposal` consists of `Transforms`
* Transforms maybe be different types: `Encryption, Hash, Authentication Method, DH group, Lifetime`
* `Authentication method is not negotiated as a transform in IKEv2` - it’s implicit in the IKE\_AUTH exchange
* The `set of transforms` inside one proposal defines the full Phase 1/IKE\_INIT policy - `transform set`
* Example on how SA looks like on the wire during phase 1 IKE v1::

**Logical structure**

```
SA payload
 └── Proposal
     ├── Transform 1: ENCR  → AES-CBC
     ├── Transform 2: HASH  → SHA1
     ├── Transform 3: AUTH  → PSK
     └── Transform 4: GROUP → MODP-1024
```

**Packet capture**

```
Internet Security Association and Key Management Protocol (ISAKMP)
    Initiator SPI:  a1b2c3d4e5f60708
    Responder SPI:  0000000000000000
    Next payload:   Security Association (SA)
    Version:        1.0
    Exchange type:  Identity Protection (Main Mode) (5)
    Flags:          0x00  (no encryption)
    Message ID:     00000000
    Length:         216  (example)

Payload: Security Association (SA)
    DOI:    IPsec (1)
    Situation: Identity Only (1)
    Proposal:
        Proposal #1
        Protocol ID: ISAKMP (1)
        SPI Size: 0
        # of Transforms: 4
        Transform #1: Encryption Algorithm
            Type:   ENCR
            ID:     AES-CBC
        Transform #2: Hash Algorithm
            Type:   HASH
            ID:     SHA1
        Transform #3: Authentication Method
            Type:   AUTH
            ID:     Pre-shared Key (PSK)
        Transform #4: Diffie-Hellman Group
            Type:   GROUP_DESC
            ID:     Group 2 (MODP-1024)
```

**As a logical object on router**

```
IKE SA
├── Initiator SPI (chosen by initiator)
├── Responder SPI (chosen by responder)
├── Keys (inbound)
├── Keys (outbound)
├── Crypto parameters
├── Timers
└── State
```

**Phase 1 SA as a logical object on router includes the following:**

* Peer identification
  * Remote peer IP address (or FQDN)
  * Local interface / local IP used
  * Negotiated IKE identity (IP, FQDN, DN, etc.)
* Negotiated cryptographic parameters - Result of the accepted proposal + transforms
  * Encryption algorithm (e.g. AES-CBC)
  * Hash / integrity algorithm (e.g. SHA-1 / SHA-256)
  * Authentication method (PSK, RSA signatures, etc.)
  * Diffie-Hellman group
* SA lifetime (time and/or rekey margin)
* `These parameters are fixed for the lifetime of the IKE SA`
* Keying material (derived, not negotiated) - Derived encryption & integrity keys for IKE messages
* `Keys are never sent, only derived via DH + nonces`
* SPI values
  * Initiator SPI
  * Responder SPI
* `These uniquely identify the IKE SA in both directions`
* State information
  * IKE state (MM\_ACTIVE, QM\_IDLE, ESTABLISHED, etc.)
  * Mode used (Main Mode / Aggressive Mode)
  * Exchange progress markers
* Timers and counters
  * SA creation time
  * Remaining lifetime
  * Rekey timers
  * Message counters / retransmission state
* Authentication data (cached result)
  * Peer authenticated successfully (yes/no)
  * Identity matched PSK or certificate
* Relationship to Phase 2

**Example of SA phase 1 IKEv1 as a logical object**

On router via Cisco command `show crypto isakmp sa detail` - It displays IKEv1 Phase 1 Security Associations currently known to the router

```
IPv4 Crypto ISAKMP SA
dst             src             state          conn-id status
192.0.2.2       192.0.2.1       QM_IDLE        1001    ACTIVE

     IKE SA details:
       Session-id: 1001
       Status: ACTIVE
       IKE version: 1
       Exchange type: Main Mode
       Authentication method: Pre-Shared Key
       Encryption: AES-CBC
       Hashing: SHA1
       DH group: 2
       Lifetime: 86400 seconds
       Remaining lifetime: 83210 seconds
       Local SPI: 0xA1B2C3D4
       Remote SPI: 0xE5F6A7B8
       NAT-T: enabled
       DPD: enabled
       Local ID: IPv4 address 192.0.2.1
       Remote ID: IPv4 address 192.0.2.2
```

**IKEv2 Example**

For IKEv2 command is a little bit different: `show crypto ikev2 sa detail`

```
IKEv2 SAs:

Session-id: 3, Status: UP-ACTIVE
  IKE SA: local 192.0.2.1/500 remote 192.0.2.2/500
  Local ID: ipv4 addr 192.0.2.1
  Remote ID: ipv4 addr 192.0.2.2
  Authentication: Pre-shared key
  Encryption: AES-CBC, keysize 256
  Integrity: SHA256
  PRF: PRF_HMAC_SHA256
  DH Group: 14
  SPI(local): 0x1A2B3C4D5E6F7081
  SPI(remote): 0x9988776655443322
  Lifetime: 86400 seconds
  Remaining Lifetime: 84123 seconds
  NAT-T: detected, enabled
  DPD configured: yes, interval 10, retry 5
  Rekey SA: yes
  Child SAs: 1 active
```

#### 2.3.2 Data tunnel - IPSec SA

**As a set of options during negotiations**

* Each SA payload contains one or more Proposals
* Each Proposal has:
  * Protocol ID (ESP = 50, AH = 51)
  * SPI Size (usually 4 bytes)
  * SPI Value (the actual 32-bit number)
  * Transform set, consisting of several transforms: encryption, auth(Integrity, HMAC), lifetime, DH group - no Authentication method, like in Phase 1

**As a logical object on a router**

* SA, used during Phase 2, is called IPSec SA and it is Unidirectional: used for protecting Data traffic in one direction, so 2 SAs are required for communication
* SA is uniquely identified by a Security Parameter Index (SPI), an IPv4 or IPv6 destination address, and a security protocol (AH or ESP) identifier
* Outbound and inbound SAs are differenti
* Inbound SA for IPSec: how to decrypt and authenticate packets arriving at the device based on SPI inside ESP protocol
* Outbound SA for IPSec: How to encrypt and authenticate packets leaving the device based on SPI inside ESP protocol
* `Both SAs (inbound and outbound) use the same crypto parameters, negotiated during Phase 2/IKEv1 or IKE_INIT/IKEv2`
* `But the keys are different for each direction`
* `Each SA has its own SPI` - Inbound SA has a SPI of remote peer, what it expects to see in an incoming packet - Outbound SPI has an SPI of local router and is used when sending packets to remote router
* Any time direction, keying material, protocol, or traffic selectors differ → a separate SA is required

**IPSec — two SA objects**

```
IPsec SA (outbound)
├── SPI: 0x1001
├── Encryption key
├── Integrity key
└── Traffic selector

IPsec SA (inbound)
├── SPI: 0x2002
├── Encryption key
├── Integrity key
└── Traffic selector
```

#### 2.3.3 Manual and Dynamic SAs

**Manual SA**

* Manual SAs require no negotiation; all values, including the keys, are static and specified in the configuration
* If you configure static/manual IPsec SAs, you do not need (and cannot use) IKE
* All parameters are manually configured on both sides:
  * SPI (Security Parameter Index)
  * Encryption & authentication algorithms
  * Keys
  * Peer IPs
  * Lifetimes (if any)
* There is no key negotiation, rekeying, or authentication exchange
* Used only in test setups or simple, static environments
* Drawback: keys must be changed manually — no automatic refresh → insecure and unscalable

**Dynamic SA**

* Dynamic SAs require additional configuration. With dynamic SAs, you configure IKE first and then the SA. IKE creates dynamic security associations; it negotiates SAs for IPsec and IKE
* The IKE configuration defines the algorithms and keys used to establish the secure IKE connection with the peer security gateway
* This connection is then used to dynamically agree upon keys and other data used by the dynamic IPsec SA. The IKE SA is negotiated first and then used to protect the negotiations that determine the dynamic IPsec SAs

### 2.3 Transform set

* A transform set is a combination of one or more transforms used to build an IPsec Security Association (SA) during Phase 2 (Quick Mode / Child SA) negotiation or IKE Security Assosiation during Phase 1
* Each transform describes one specific aspect of how IPsec protects the traffic
* Transform types:
  * Encryption Algorithm (ENCR) - AES-CBC, AES-GCM, 3DES, ChaCha20-Poly1305
  * Pseudo-Random Function (PRF) - In IKEv1, PRF is not a separate transform — it’s implicit in Phase 1 - PRF-HMAC-SHA1, PRF-HMAC-SHA256
  * Integrity / Authentication Algorithm (INTEG) - HMAC-SHA1, HMAC-SHA256, AES-XCBC
  * Diffie-Hellman Group (D-H Group) - Defines key exchange strength (PFS in Phase 2) - MODP-2048 (Group 14), ECP-256 (Group 19)
* IKE (Phase 1) transform set includes enctyption, integrity, authentication method, Diffie Hellman Group, IKE SA lifetime
* ESP(Phase 2) transform set includes encryption + integrity transforms
* AH (Phase 2) - integrity only

### 2.4 Traffic Selectors

* These are parametres, used during negotiations during Phase 2
* In Palo Alto terms it is called Proxy ID
* Traffic selector consist of local network, remote network, protocol, port - they should match on both sides
* They are configured manually on each node
* It is not used very often now, because mostly route based IPSec is used instead of Policy based
* They are sent separately outside the SA
* Their goal is to specify which traffic should be sent to the IPSec tunnel in Policy based IPSec implementations

**Example of logic**

```
Node A sends 192.168.1.0/255.255.255.0 TCP Any port > 192.168.2.2/255.255.255.255 TCP 443 port
Node B sends 192.168.2.2/255.255.255.255 TCP 443 > 192.168.1.0/255.255.255.0 TCP Any port
This configuration allows traffic from 192.168.1.0/24 to 192.168.2.2 port 443
```

* Some vendors allow “any-to-any” traffic without strict traffic selectors, meaning the SA could match all traffic between the peers’ IPs
* For route based VPN TS are set to 0.0.0.0 - which means "any traffic is allowed"

**Example of traffic selectors in IPSec SA for Cisco Router**

```
Router# show crypto ipsec sa

interface: GigabitEthernet0/0
    Crypto map tag: VPN-MAP, local addr 203.0.113.10

   protected vrf: (none)
   local ident (addr/mask/prot/port): (10.1.0.0/255.255.255.0/0/0)
   remote ident (addr/mask/prot/port): (10.2.0.0/255.255.255.0/0/0)

   #pkts encaps:  12345, #pkts encrypt: 12345, #pkts digest: 12345
   #pkts decaps:  12010, #pkts decrypt: 12010, #pkts verify: 12010

   inbound esp sas:
      spi: 0x32A1B44C(850000964)
        transform: esp-aes esp-sha-hmac ,
        in use settings ={Tunnel, }
        conn id: 1011, flow_id: SW:11, crypto map: VPN-MAP
        sa timing: remaining key lifetime (k/sec): (4294967295/2460)
        replay detection support: Y
        Status: ACTIVE

   outbound esp sas:
      spi: 0xA4BB9923(2769075235)
        transform: esp-aes esp-sha-hmac ,
        in use settings ={Tunnel, }
        conn id: 1012, flow_id: SW:12, crypto map: VPN-MAP
        sa timing: remaining key lifetime (k/sec): (4294967295/2460)
        replay detection support: Y
        Status: ACTIVE
```

### 2.5 Vendor IDs

* In IKEv1, a Vendor ID (VID) is just bytes
* IKEv1 Phase 1 Message 1 Main Mode capture with lots of Vendor IDs, exactly like you’d see from a Cisco RA VPN headend in the 2000s

```
Vendor ID
  Vendor ID: 4a131c81070358455c5728f20e95452f
  Meaning: NAT-Traversal (RFC 3947)

Vendor ID
  Vendor ID: afcad71368a1f1c96b8696fc77570100
  Meaning: Dead Peer Detection (Cisco)

Vendor ID
  Vendor ID: 09002689dfd6b712
  Meaning: XAuth (Cisco Extended Authentication)

Vendor ID
  Vendor ID: 4048b7d56ebce88525e7de7f00d6c2d3
  Meaning: Cisco Unity (Remote Access VPN)

Vendor ID
  Vendor ID: 12f5f28c457168a9702d9fe274cc0100
  Meaning: IKE Fragmentation (Cisco proprietary)

Vendor ID
  Vendor ID: 3f237c7f2c7a3f8a6d8e97c2c4a9f001
  Meaning: Vendor-specific (often ignored)

Vendor ID
  Vendor ID: 1f07f70eaa6514d3b0fa96542a500000
  Meaning: Microsoft Windows IPsec
```

* Why so many VIDs?
* Because IKEv1 had no standard way to say:
  * “I support NAT-T”
  * “I support DPD”
  * “I support username/password”
  * “I support fragmentation”
* What the responder does? If recognized → enable feature - If unknown → silently ignore
* Why Vendor IDs existed (historical reason)
  * IKEv1 (RFC 2409, 1998) had a problem
  * The protocol was underspecified
  * Many features were missing or unclear
  * Vendors implemented incompatible extensions
* So vendors needed a way to say: Hey peer, I support this non-standard thing
* No negotiation, No security, No guarantees
* What Vendor IDs were used for (real use cases)
  * NAT Traversal (before RFC) - Before NAT-T was standardized
  * Dead Peer Detection (DPD)
  * XAuth - Remote-access extensions (username/password auth) - Not in base IKEv1 - Implemented via VID
  * Fragmentation - IKEv1 fragmentation (pre-RFC 7383)
  * Implementation quirks
  * Config Mode
* Some VIDs existed just to say: “I am Cisco”, “I am Check Point”, “I am Windows”
* Peers then adjusted behavior (!)
* Why Vendor IDs are bad (architecturally)
  * Fingerprinting
  * Interoperability hacks
  * Undocumented behavior
  * Works only with vendor
  * They are out-of-band signaling, which protocols should avoid
* IKEv2 removed Vendor IDs completely
* IKEv2 designers said: never again
* IKEv2 replaced VIDs with Notify payload: Standardized, RFC-defined behavior
* Examples:
  * NAT-T → built-in
  * DPD → INFORMATIONAL exchanges
  * Fragmentation → RFC-defined
  * Cookies → standardized DoS protection

### 2.6 IKE identity

* IKE Identity is a `Value` which is sent by both Initiator and Responder to each other during `Authentication` Stage of Phase 1 in IKEv1 and during the IKE\_AUTH exchange in IKEv2
* IKE Identity is `mandatory` for use in both IKE versions, Site-to-Site VPNs and RA VPNs
* It can be in the form of: `distinguished-name, hostname, ip-address, e-mail-address, key-id, FQDN (explicit), RFC822 (email), ASN.1 DN`
* IKE identity is a mandatory input to authentication and IKE SA establishment
* Authentication HASH is based not only on PSK and Nonce, but also on both IKE IDs
* `IKE ID = endpoint(peer, node) name, not the User`
* IKE ID is used to select which PSK to use, which certificate to validate, which EAP policy applies
* If IKE identity is not configured, the device uses the IPv4 or IPv6 address of interface by default

**Why IKE ID is required and how it is used**

* When the responder receives the initiator’s ID, it verifies that the ID matches the configuration
* Using this ID, the responder selects the correct authentication data (PSK or certificate) and applies the appropriate authorization policy
* In both IKEv1 and IKEv2, cryptographic proposals `are not` selected based on the IKE ID - IP address is used to choose SA
* In IKEv2 IP address is not used for PSK selection
* In IKEv1 main mode with PSK IP address is used for selecting PSK, because the responder does not know the peer ID early, ID is sent after PSK
* In IKEv1 aggressive mode with PSK ID is sent early and in cleartext, Responder can choose PSK based on ID
* In IKEv1 all modes with certificates IP is not used, only ID
* IP is not reliable, it may be changed during NAT, so ID is required
* Using ID node also applies authorization policy: where the remote node can connect, both for Site-to-Site and RA VPNs

**IKE Identity in Site-to-Site VPNs**

* IKE identity is configured manually on both Peers for Site-to-Site VPNs if PSK is used, and if Certificate-based → identity derived from cert
* We configure local Identity - what to send to remote Peer, and remote Idenity - what to expect from remote peer
* If Identity mismatch - `Authentication and Phase 1 will fail`
* It must match the peer’s expectations

**IKE Identity in RA VPN with IKEv1**

* IKE Identities in RA VPNs may be flexible, depending on configuration, it may not match
* IKE Identity for VPN Client: group name(Cisco ASA) or IP address or FQDN from certificate
* IKE Identiry for VPN Server: group name, if group name from client request exists, connection is accepted, if not it is rejected
* 1 user or 10,000 users can use the same IKE ID of the VPN client
* Any VPN client IKE ID maybe allowed on VPN server side, if default group is configured
* XAuth is used with username and password for exact user identification after Phase 1 is authenticated via IKE IDs, PSK or certs
* RA VPN Server using IKEv1 will reject connection if either one of these is wrong in client's request in case of strict configuration: `Client IKE ID, Server IKE ID, PSK, Xauth username, Xauth password`

**IKE Identity in RA VPN with IKEv2**

* The role of IKE Identity (IDi / IDr) is similar to IKEv1:
  * it identifies the VPN endpoint, not the user
  * it may be shared by many clients
  * it is used for policy and authentication selection
* Unlike IKEv1:
  * XAUTH is not used
  * User authentication is performed via EAP
  * EAP authenticates the user, not the IKE SA
* The IKE SA must still be authenticated using:
  * PSK, or
  * certificates
* EAP is used in addition to, not instead of, PSK or certificates
* Generic or anonymous client IKE IDs are commonly used

## 3 IPSec databases

3 databases in IPSec: `SPD → SAD → PAD`

### 3.1 SPD — Security Policy Database

* What to do with traffic?
* SPD exampled in Cisco: crypto ACL

**SPD example**

```
src: 10.0.0.0/24
dst: 10.1.0.0/24
proto: any
action: PROTECT (IPsec)
```

**SPD actions**

* PROTECT → use IPsec
* BYPASS → bypass without IPsec
* DISCARD → DROP

**SPD flow**

```
Outbound:
  packet → SPD → (protect?) → yes → SAD lookup

Inbound:
  After decrypt → SPD check
```

### 3.2 SAD — Security Association Database

* SA options: keys, algorithms, SPIs
* `SAD entry ← indexed by SPI`
* IKE → creates entries in SAD
* SAD example in Cisco: `show crypto ipsec sa`

**Example**

```
SPI: 0xA1B2C3D4
destination: 203.0.113.1
protocol: ESP

encryption: AES-256
integrity: SHA-256
key: 0xdeadbeef...

mode: tunnel
lifetime: 3600s
```

**Flow**

```
Inbound:
  SPI → SAD → SA → decrypt
```

### 3.3 PAD — Peer Authorization Database

* Who has rights to establish IPSec sessions with us
* No exactly PAD table in Cisco, but close: `crypto isakmp key MySecretKey address 203.0.113.1`

**Example**

```
peer: vpn.example.com
auth method: certificate
CA: Example-Root-CA

allowed identities:
  CN=vpn.example.com
```

* Used in IKE Phase 1 / IKE\_AUTH
* Checks:
  * Identity
  * Certificates
  * PSK

### 3.4 Full Processing Flow

```
OUTBOUND:

[Packet]
   ↓
[SPD lookup]
   ↓
(PROTECT?)
   ↓ yes
[IKE → create SA if needed]
   ↓
[SAD lookup]
   ↓
[Encrypt → ESP packet]


INBOUND:

[ESP packet]
   ↓
[SPI lookup in SAD]
   ↓
[Decrypt]
   ↓
[SPD check]
   ↓
[Forward]
```

## 4 Key management protocols

### 4.1 IKE v1

**Terms**

* g^xi and g^xr are the Diffie-Hellman (\[DH]) public values of the initiator and responder respectively
* g^xy is the Diffie-Hellman shared secret
* KE is the key exchange payload which contains the public information exchanged in a Diffie-Hellman exchange

**History**

* IKEv1 was designed by the IETF IPsec work group in the mid-1990s and standardized in 1998 as RFC 2409
* First appeared in Research & open-source Unix IPsec stacks, then in Cisco IOS, Checkpoint, Juniper
* IKEv1 was developed, combining ideas from three earlier protocols:
  * ISAKMP – framework for messages and SA management, how packets are formatted (headers, payload types), a generic state machine for SA negotiation, but not how keys are exchanged
  * Oakley – Diffie-Hellman key exchange and math, `key derivation techniques`, DH groups
  * SKEME – identity protection, rekeying, multiple SAs, negotiate algorithms, separation of key exchange from authentication, multiple authentication styles

**IKEv1 goals**

* Authenticate peers
* Negotiate cryptographic parameters
* Establish shared secret keys
* Create and manage IPsec Security Associations (SAs) + IKE SA
* Provide Perfect Forward Secrecy (PFS)
* Detect peer liveness
* Provides identity protection (in main mode)
* Provide NAT-T support
* Provide X-AUTH support

**Communications**

* IKE v1 uses UDP port 500 or UDP port 4500 in case of NAT-T technology
* There is IKE traffic, when everything is established and data flows normally - keepalives via port UDP/500, if NAT-T is enabled then UDP/4500 is used

**Phases and modes**

* IKEv1 uses two phases to authenticate peers `once` and securely negotiate traffic protection many times
* Phase 1 — Build a secure control channel
* Phase 2 - Negotiate parametres for Data traffic encryption via secure Control Channel
* Phase 1 can work in 2 modes: main and aggressive
  * 9 messages in total if main mode is used in Phase 1
  * 6 messages in total if aggressive mode is used in Phase 1

**Initiator and responder**

* In the IPsec/IKE world, the “initiator” is the peer that first sends an IKE packet to start the negotiation
* The responder replies. This role is independent of who sends actual data over data channel later

**Perfect forward secrecy**

* PFS in IKEv1 = `Perform a new DH exchange during Phase 2`. It does not mean “ephemeral DH” in the modern TLS sense

**Supported crypto algorithms**

For Phase 1

```
--------------------------------------------------------------
   IKEv1 PHASE 1 (ISAKMP SA) CRYPTO SET
--------------------------------------------------------------

 [ENCRYPTION (confidentiality)]

   DES        → 56-bit key        (obsolete)
   3DES       → 168-bit key       (3×56, effective ~112)
   AES-CBC    → 128 / 192 / 256-bit ← recommended

--------------------------------------------------------------

 [INTEGRITY + PRF (combined in IKEv1)]

   MD5        → 128-bit output    (obsolete)
   SHA-1      → 160-bit output    (legacy)
   SHA-256    → 256-bit output    ← recommended
   SHA-384    → 384-bit output
   SHA-512    → 512-bit output

   PRF = HMAC(hash)
   Example: SHA-256 → PRF = HMAC-SHA256

--------------------------------------------------------------

 [AUTHENTICATION METHODS]

   PSK        → Pre-Shared Key
   RSA-SIG    → Certificates (public key signatures)
   DSS-SIG    → DSA (legacy / rare)

--------------------------------------------------------------

 [DIFFIE–HELLMAN (KEY EXCHANGE)]

   MODP (Finite Field DH):
     Group 1   → 768-bit     (obsolete)
     Group 2   → 1024-bit    (obsolete)
     Group 5   → 1536-bit    (legacy)
     Group 14  → 2048-bit    ← baseline modern
     Group 15  → 3072-bit
     Group 16  → 4096-bit

   ECDH (Elliptic Curve DH, limited in IKEv1):
     Group 19  → 256-bit (P-256)
     Group 20  → 384-bit (P-384)
     Group 21  → 521-bit (P-521)

   Ephemeral DH (DHE / ECDHE):
     ✔ New private/public values per session
     ✔ Provides Forward Secrecy (PFS)
     ✔ ALWAYS used in IKE Phase 1

--------------------------------------------------------------

 [KEY DERIVATION (implicit in IKEv1)]

   Inputs:
     DH shared secret (g^xy)
     + nonces (Ni, Nr = random values from both peers)
     + cookies (CKY-I, CKY-R = session identifiers)
     + PSK (if used)

   PRF (HMAC) used to derive:
     SKEYID
     SKEYID_d  → keying material
     SKEYID_a  → integrity
     SKEYID_e  → encryption

--------------------------------------------------------------
```

For phase 2

```
--------------------------------------------------------------
   IKEv1 PHASE 2 (QUICK MODE / IPSEC SA) CRYPTO SET
--------------------------------------------------------------

 [ENCRYPTION (ESP only)]

   DES        → 56-bit key        (obsolete)
   3DES       → 168-bit key       (legacy)
   AES-CBC    → 128 / 192 / 256-bit ← recommended

--------------------------------------------------------------

 [INTEGRITY / AUTHENTICATION]

   (for ESP without AEAD and for AH)

   MD5        → 128-bit output    (obsolete)
   SHA-1      → 160-bit output    (legacy)
   SHA-256    → 256-bit output    ← recommended
   SHA-384    → 384-bit output
   SHA-512    → 512-bit output

--------------------------------------------------------------

 [PFS (PERFECT FORWARD SECRECY)]

   Optional in Phase 2

   If enabled:
     → new DH exchange performed
     → new shared secret per CHILD SA

   Uses same DH groups as Phase 1:
     Group 14 → 2048-bit (recommended baseline)
     Group 19 → ECP 256
     etc.

   If NOT enabled:
     → keys derived from Phase 1 only

--------------------------------------------------------------

 [KEY DERIVATION]

   Inputs:
     Phase 1 keying material (SKEYID_d)
     + nonces (Ni, Nr = new random values for Phase 2)
     + SPI values (Security Parameter Index)
     + PFS DH shared secret (if enabled)

   PRF (HMAC) used to derive:
     encryption keys
     integrity keys
     inbound / outbound SA keys

--------------------------------------------------------------
```

#### 4.1.1 Workflow

* IKE Phase 1 — Establish a secure channel (IKE SA) - starts with UDP/500, may switch to UDP/4500
  * `Main mode` - 6 messages
  * `Aggressive mode` - 3 messages
  * SA negotiation - Agree on crypto parametres - transform sets
  * DH key exchange
  * Authentication - encrypted already
  * NAT-T negotiation
  * DPD negotiation
  * IKE SA - one for inbound and outbound - IKE SA is bidirectional
  * Local SPI - The SPI that your router uses when sending ISAKMP messages
  * Remote SPI - The SPI your router expects in incoming ISAKMP messages from the peer
* XAuth
* Config mode
* IKE Phase 2 — Negotiate IPsec SAs (ESP or AH) - `Quick mode` - UDP/500 or UDP4500
  * Negotiate 2 IPsec SAs - inbound and outbound - crypto parametres the same - keys are different
  * Exchange traffic selectors (Proxy-ID) - should be the same
  * `Outbound SPI` - The SPI my router inserts into ESP packets I send
  * `Inbound SPI` - The SPI my router expects to see in ESP packets I receive
  * Transform sets - negotiate crypto parametres
* ESP/AH encapsulation — Actual data traffic encryption/authentication using the negotiated keys - IP/50(ESP) or UDP/4500 or IP/51(AH) - Destination SPI is in header

#### 4.1.2 Phase 1

**Concepts**

* During traffic capture you cannot see Phase 2 negotiation, only Phase 1 as ISAKMP protocol, everything else is encrypted
* Phase 1 SA is called ISAKMP SA or IKE SA
* The Phase 1 keys are long-lived and tied to identity/authentication
* IKE SA and IPSec SAs must be cryptographically independent
* Phase 1 establishes an ISAKMP(Internet Security Association and Key Management Protocol) SA, which is a secure channel through which the IPsec SA negotiation can take place
* Phase 1 workflow: `Crypto negotiations > DH exchange > Authentication > IKE communications between routers`
* The ISAKMP header has its own SPI pair
* These SPIs identify the IKE SA
* IKE SA is bidirectional

**Negotiations - The following crypto parametres are negotiated during Phase 1**

* Hashing - md5 or sha - used inside HMAC for authentication and integrity of every IKE packet
* Authentication - Preshared Keys or certificates
* Group - Diffie Helman group - algorithm which is used to establish shared secret keys
* Encryption
* Lifetime - 24 hours default - don't have to match

To easy remember this we can use first letters of these parametres: `HAGEL`

**IKE Phase 1 can be established via**

* main mode(6 messages)
* aggressive mode(3 messages)

#### 4.1.2.1 Main Mode

* `6 messages`
* IKE Identities and Authentication Hash are protected and sent encrypted only > no one can see it
* `This makes it imposiible to Brute Force Authentication Hash`
* All Phase 1 Main Mode packets must include IKE SPIs(Cookies)
* No ESP/AH SPIs yet — Phase 2 Quick Mode creates those
* `Main mode + PSK will not work with dynamic IPs for S2S tunnels or RA VPN`
* Why? IKE packet with authentication hash arrives in message 5 of Main mode, to verify this hash node needs to know which PSK to use in order to calculate the same hash, to choose PSK node may use ID or IP address, if IP address is dynamic - it is impossible to use it, and ID is encrypted - and in the same same message - then why we cannot just decrypt ID and use it?
* Static IPs on both sides are required
* To choose PSK Main Mode needs correct IP of Initiator
* Main Mode + certs + dynamic IP = totally fine - so with certificates instead of PSK Main Mode works OK

**High level stages**

* Negotiate SA parametres: messages 1 and 2
* Exchange keys with Diffie-Hellman and get Shared Secret
* Based on Shared Secret derive Shared Keys for Encryption, Authentication, Integrity
* Exchange IDs and authentication hash

**Main mode in a Nutshell**

```
│── 1. Generate Initiator and Responder SPIs and Negotiate all required crypto options - messages 1 and 2
│   ├── Encryption
│   ├── Hash - for auth of every packet
│   ├── Authentication: PSK or certs
│   ├── DH Group
│   └── Lifetime 
│ 
│── 2. Exchange keys with Diffie Hellman algorithm - messages 3 and 4
│   ├── DH Group
│   ├── DH public key
│   └── Nonce
│ 
│── 3. Send Encrypted ID and Encrypted Authentication Hash - messages 5 and 6
│   ├── Encrypted ID
│   └── Encrypted Authentication Hash
│   
```

Authentication Hash should match the one calculated locally > IKE tunnel is established\
Derived encryption keys are used to encrypt creation of IPSec tunnel

* `First message` - SA > Proposals > Transforms + Initiator SPI
* Each proposal can contain many transforms
* Each transform is a full combination of all cryptographic parameters - `not like in Phase 2` - `no transform sets`
  * Encryption
  * Hash - for auth of every packet
  * Authentication method: PSK or certs
  * DH Group
  * Lifetime

**Message 1 Example: Initiator → Responder (SA Proposal)**

```
Frame 1: 192.0.2.10 → 198.51.100.20, UDP 500 → 500
Internet Key Exchange v1
  ISAKMP Header
    Initiator SPI: 0xA1B2C3D4E5F60708
    Responder SPI: 0x0000000000000000
    Next Payload: Security Association (1)
    Version: 1.0
    Exchange Type: Main Mode (2)
    Flags: 0x00
    Message ID: 0x00000000
  Payload: Security Association (SA)
    DOI: IPsec (1)
    Situation: Identity Only
    Proposal #1
      Protocol ID: ISAKMP
      SPI Size: 0
      Number of Transforms: 2
      Transform #1
        Transform ID: KEY_IKE
        Encryption: AES-CBC-256
        Hash: SHA-1
        Authentication: Pre-Shared Key
        DH Group: 14
        Lifetime: 28800s
      Transform #2
        Transform ID: KEY_IKE
        Encryption: 3DES
        Hash: SHA-1
        Authentication: Pre-Shared Key
        DH Group: 2
        Lifetime: 28800s
```

* `Second message` - Initiator SPI, Responder SPI, Selected SA with 1 Proposal inside and 1 Transform inside Proposal

**Message 2 Example — Responder → Initiator (SA Selection)**

```
Frame 2: 198.51.100.20 → 192.0.2.10, UDP 500 → 500
Internet Key Exchange v1
  ISAKMP Header
    Initiator SPI: 0xA1B2C3D4E5F60708
    Responder SPI: 0x1122334455667788
    Next Payload: Security Association (1)
    Version: 1.0
    Exchange Type: Main Mode (2)
    Flags: 0x00
    Message ID: 0x00000000
  Payload: Security Association (SA)
    Selected Proposal
      Protocol ID: ISAKMP
      SPI Size: 0
      Transform
        Encryption: AES-CBC-256
        Hash: SHA-1
        Authentication: Pre-Shared Key
        DH Group: 14
        Lifetime: 28800s
```

* `Third message` - DH Group + DH public Key + Nonce + SPIs
* `Nonce - is a a large, random, unpredictable number generated fresh for each exchange`
* Nonce is required to bind the Diffie–Hellman exchange to this specific IKE run and prevent replay, key reuse, and precomputation attacks
* Without nonces: `An attacker could replay an old DH public value` - `Both sides might unknowingly derive the same key again`
* Nonce ensures: Even if DH values repeat, keys will not

**Message 3 Example - Initiator → Responder - Key Exchange + Nonce**

```
Frame 3: 192.0.2.10 → 198.51.100.20, UDP 500 → 500
Internet Key Exchange v1
  ISAKMP Header
    Initiator SPI: 0xA1B2C3D4E5F60708
    Responder SPI: 0x1122334455667788
    Next Payload: Key Exchange (4)
    Version: 1.0
    Exchange Type: Main Mode (2)
    Flags: 0x00
    Message ID: 0x00000000
  Payload: Key Exchange (KE)
    DH Group: 14
    Public Value: g^xi mod p
  Payload: Nonce (Ni)
```

* `Fourth message` - DH Group + DH public Key + Nonce + SPIs

**Message 4 Example — Responder → Initiator - Key Exchange + Nonce**

```
Frame 4: 198.51.100.20 → 192.0.2.10, UDP 500 → 500
Internet Key Exchange v1
  ISAKMP Header
    Initiator SPI: 0xA1B2C3D4E5F60708
    Responder SPI: 0x1122334455667788
    Next Payload: Key Exchange (4)
    Version: 1.0
    Exchange Type: Main Mode (2)
    Flags: 0x00
    Message ID: 0x00000000
  Payload: Key Exchange (KE)
    DH Group: 14
    Public Value: g^xr mod p
  Payload: Nonce (Nr)
```

* `Fifth message` - SPIs + IKE ID encrypted + Authentication Hash Encrypted

**Authentication Hash is calculated based on:**

```
IKEv1 Phase 1 – Authentication HASH Inputs
│
├─ Shared Secret
│  ├─ Pre-Shared Key (PSK)
│  └─ or Private Key (RSA / DSS signatures)
│
├─ Derived Keying Material
│  ├─ SKEYID
│  ├─ SKEYID_d
│  └─ SKEYID_a        ← directly used for authentication
│
├─ Diffie-Hellman Data
│  ├─ g^i             (Initiator DH public value)
│  └─ g^r             (Responder DH public value)
│
├─ ISAKMP Cookies (IKE SPIs)
│  ├─ Initiator Cookie (SPIi)
│  └─ Responder Cookie (SPIr)
│
├─ Nonces
│  ├─ Ni              (Initiator nonce)
│  └─ Nr              (Responder nonce)
│
├─ Phase 1 SA Payload
│  └─ SA              (complete negotiated proposal payload)
│
├─ Identification Payloads
│  ├─ IDii            (Initiator ID – used in HASH_I)
│  └─ IDir            (Responder ID – used in HASH_R)
│
└─ Direction Context
   ├─ HASH_I          (calculated by Initiator)
   │  └─ includes IDii
   └─ HASH_R          (calculated by Responder)
      └─ includes IDir
```

* In IKEv1 Phase 1, there are two different authentication values
* `HASH_I` - computed, sent by Initiator
* `HASH_R` - computed, sent by Responder
* Initiator proves “I am who I claim to be” → HASH\_I
* Responder proves “I am who I claim to be” → HASH\_R
* If the same hash were used, replay or reflection attacks would be possible
* Everything is the same except the ID payload included
* HASH\_I includes IDii (Initiator Identification)
* HASH\_R includes IDir (Responder Identification)
* `The initiator sends its identity and a hash; the responder recomputes the hash using the received identity and verifies it, thereby authenticating the initiator`
* `Hash is a proof of possession` of the shared secret, bound to:
  * The negotiated SA
  * Both nonces
  * Both SPIs
  * The sender’s ID

**Message 5 Example — Initiator → Responder (Encrypted ID + Initiator Authentication HASH)**

```
Frame 5: 192.0.2.10 → 198.51.100.20, UDP 500 → 500
Internet Key Exchange v1
  ISAKMP Header
    Initiator SPI: 0xA1B2C3D4E5F60708
    Responder SPI: 0x1122334455667788
    Next Payload: Identification (5)
    Version: 1.0
    Exchange Type: Main Mode (2)
    Flags: Encryption (0x01)
    Message ID: 0x00000000
  Encrypted Payloads
    Identification (IDii)
      Type: FQDN
      Value: vpn-client.example.com
    HASH_I
```

* `Sixth message` - SPIs + IKE ID encrypted + Responder Authentication Hash Encrypted

**Message 6 Example — Responder → Initiator (Encrypted ID + Authenticated HASH)**

```
Frame 6: 198.51.100.20 → 192.0.2.10, UDP 500 → 500
Internet Key Exchange v1
  ISAKMP Header
    Initiator SPI: 0xA1B2C3D4E5F60708
    Responder SPI: 0x1122334455667788
    Next Payload: Identification (5)
    Version: 1.0
    Exchange Type: Main Mode (2)
    Flags: Encryption (0x01)
    Message ID: 0x00000000
  Encrypted Payloads
    Identification (IDir)
      Type: FQDN
      Value: vpn-gateway.example.com
    HASH_R
```

**In Case of Certificates instead of PSK**

`When using certificates, the initiator replaces PSK-based HASH authentication with a CA-validated public certificate plus a signature created with its private key over the IKE exchange data — while the rest of Phase 1 remains largely the same`

The responder:

* Receives the certificate
* Extracts the public key
* Verifies the signature of connection options - initiator proves that it has a private key
* Verifies The CA’s digital signature on the Public certificate - This public key was issued by a CA I trust for this identity

Digital signatures over connection options:

* DH values
* Nonces
* SA payloads
* IDs

`No pre-shared lookup is required` - so Main Mode witth Certs can be used with Initiator dynamic IP

Responder logic:

```
1. Decrypt message 5
2. Read IDii
3. Read CERT
4. Verify CA trust
5. Verify SIG_I using public key
6. Accept peer
```

#### 4.1.2.2 Aggressive Mode

* `3 messages instead of 6 in Main Mode`
* Aggressive mode was created to reduce load on links and CPU
* `Aggressive Mode was part of IKEv1 from day one, added to enable faster handshakes and remote-access VPNs with dynamic peers, at the cost of identity protection and PSK security`
* It allows connections from `initiator with dynamic IP`
* ID is sent early, responder may `select PSK based on ID, not IP`
* Several Initiators may work behind one IP and NAT
* It is critical for remote-access VPNs
* Most classic IKEv1 Remote Access VPNs used:
  * Aggressive Mode
  * PSK
  * XAuth (username/password after Phase 1)
  * Mode Config
* Aggressive Mode sacrifices identity Security:
  * IDs are sent in cleartext
  * HASH\_I and HASH\_R are exposed
  * Enables offline dictionary attacks against PSK
* It is considered acceptable because of Cryptographic maturity and strong PSKs
* IKEv2 eliminated Aggressive mode and always protects IDs and HASHes

**Main mode, Aggressive Mode, IKEv2, RA VPNs**

```
IKEv1 Main Mode
├─ Dynamic IP allowed by RFC
├─ Works well with certificates
└─ Painful / impractical with PSK

IKEv1 Aggressive Mode
├─ Designed for dynamic peers
├─ Identity arrives early
├─ PSK selection based on ID
└─ Used by almost all PSK-based RA VPNs

IKEv2
├─ No Aggressive Mode
├─ Always identity-protected
└─ Dynamic peers fully supported
```

**Message 1: Initiator > Responder**

* Initiator SPI
* `SA Proposals, DH Group, Key Exchange Data, Nonce, IKE ID - Everything! - Instead of only SA proposal in Main Mode`
* Vendor IDs

```
Internet Key Exchange
  Exchange Type: Aggressive Mode (4)
  Initiator SPI: 0x9f3a7c1e2b4d8a91
  Responder SPI: 0x0000000000000000
  Flags: Initiator
  Message ID: 0x00000000

  Payload: Security Association
    DOI: IPSEC (1)
    Situation: Identity Only
    Proposal: 1
      Proposal Number: 1
      Protocol ID: ISAKMP
      SPI Size: 0
      Number of Transforms: 1
      Transform: 1
        Transform Number: 1
        Transform ID: KEY_IKE
        Encryption Algorithm: AES-CBC (7)
        Hash Algorithm: SHA1 (2)
        Authentication Method: Pre-Shared Key (1)
        Group Description: MODP 1024 (2)
        Life Type: Seconds (1)
        Life Duration: 86400

  Payload: Key Exchange
    Diffie-Hellman Group: MODP 1024 (2)
    Key Exchange Data: 0x7c9a4f8d3a1b...

  Payload: Nonce
    Nonce Data: 0x1f9c33ab4e6d...

  Payload: Identification - Initiator
    ID Type: IPv4 Address (1)
    Protocol ID: Unused (0)
    Port: 0
    Identification Data: 192.0.2.10

  Payload: Vendor ID
    Vendor ID: RFC 3947 - NAT Traversal

  Payload: Vendor ID
    Vendor ID: Cisco-Unity

  Payload: Vendor ID
    Vendor ID: XAUTH
```

First message — The initiator proposes the security association (SA), initiates a DH exchange, and sends a pseudorandom number and its IKE identity. When configuring aggressive mode with multiple proposals for Phase 1 negotiations, use the same DH group in all proposals because the DH group cannot be negotiated. Up to four proposals can be configured. Message one contains everything that was in messages 1,3,5 in Main mode

**Message 2: Responder > Initiator**

It contains the same as messages 2,4,6 in Main mode

* Responder cookie
* Chosen SA proposal - accepts the SA
* Key exchange Diffie-Hellman group + Key Exchange Data
* Nonce
* IKE Identity
* Hash - HASH\_R (Responder Authentication Hash)
  * It is the responder’s proof of identity and possession of the shared secret
  * HASH\_R proves all of the following at once:
    * The responder knows the Pre-Shared Key (PSK)
    * The responder participated in the Diffie–Hellman exchange
    * The responder is the owner of the claimed identity (IDir)
    * The responder did not modify the exchange
  * If any of these are false → hash verification fails → Phase 1 fails
  * HASH\_R = HMAC(Key, Data)
    * Key = Derived from PSK, Nonce-Initiator, Nonce-Responder
    * Data = Responder’s DH public value + Initiator’s DH public value + Responder cookie | Initiator cookie + Initiator’s SA payload + Responder’s identity)
  * It is said that `Responder authenticates itself to the initiator` with HASH\_R, so it `proves` that it is legal
* Vendor IDs

```
Internet Key Exchange
  Exchange Type: Aggressive Mode (4)
  Initiator Cookie: 0x9f3a7c1e2b4d8a91
  Responder Cookie: 0xa8d4c2e9f1234567
  Flags: Responder
  Message ID: 0x00000000

  Payload: Security Association
    DOI: IPSEC (1)
    Situation: Identity Only
    Proposal: 1
      Proposal Number: 1
      Protocol ID: ISAKMP
      SPI Size: 0
      Number of Transforms: 1
      Transform: 1
        Transform Number: 1
        Transform ID: KEY_IKE
        Encryption Algorithm: AES-CBC (7)
        Hash Algorithm: SHA1 (2)
        Authentication Method: Pre-Shared Key (1)
        Group Description: MODP 1024 (2)
        Life Type: Seconds (1)
        Life Duration: 86400

  Payload: Key Exchange
    Diffie-Hellman Group: MODP 1024 (2)
    Key Exchange Data: 0x8a72b91f4c9e...

  Payload: Nonce
    Nonce Data: 0xa91c8f3e52d4...

  Payload: Identification - Responder
    ID Type: IPv4 Address (1)
    Protocol ID: Unused (0)
    Port: 0
    Identification Data: 198.51.100.20

  Payload: Hash
    Hash (HASH_R): 0x4b8f2a7e91c3...

  Payload: Vendor ID
    Vendor ID: RFC 3947 - NAT Traversal

  Payload: Vendor ID
    Vendor ID: Cisco-Unity

  Payload: Vendor ID
    Vendor ID: XAUTHInternet Key Exchange
  Exchange Type: Aggressive Mode (4)
  Initiator Cookie: 0x9f3a7c1e2b4d8a91
  Responder Cookie: 0xa8d4c2e9f1234567
  Flags: Responder
  Message ID: 0x00000000

  Payload: Security Association
    DOI: IPSEC (1)
    Situation: Identity Only
    Proposal: 1
      Proposal Number: 1
      Protocol ID: ISAKMP
      SPI Size: 0
      Number of Transforms: 1
      Transform: 1
        Transform Number: 1
        Transform ID: KEY_IKE
        Encryption Algorithm: AES-CBC (7)
        Hash Algorithm: SHA1 (2)
        Authentication Method: Pre-Shared Key (1)
        Group Description: MODP 1024 (2)
        Life Type: Seconds (1)
        Life Duration: 86400

  Payload: Key Exchange
    Diffie-Hellman Group: MODP 1024 (2)
    Key Exchange Data: 0x8a72b91f4c9e...

  Payload: Nonce
    Nonce Data: 0xa91c8f3e52d4...

  Payload: Identification - Responder
    ID Type: IPv4 Address (1)
    Protocol ID: Unused (0)
    Port: 0
    Identification Data: 198.51.100.20

  Payload: Hash
    Hash (HASH_R): 0x4b8f2a7e91c3...

  Payload: Vendor ID
    Vendor ID: RFC 3947 - NAT Traversal

  Payload: Vendor ID
    Vendor ID: Cisco-Unity

  Payload: Vendor ID
    Vendor ID: XAUTH
```

**Message 3: Initiator to Responder**

* Cookies
* Hash - Initiator authenticates itself to the Responder

```
Internet Key Exchange
  Exchange Type: Aggressive Mode (4)
  Initiator Cookie: 0x9f3a7c1e2b4d8a91
  Responder Cookie: 0xa8d4c2e9f1234567
  Flags: Initiator
  Message ID: 0x00000000

  Payload: Hash
    Hash (HASH_I): 0x91a2cbe4d88f...
```

* Because the participants’ identities are exchanged in the clear (in the first two messages), aggressive mode does not provide identity protection
* Main and aggressive modes applies only to IKEv1 protocol. IKEv2 protocol does not negotiate using main and aggressive modes

**Why aggressive mode enables offline PSK attacks? Why it is dangerous?**

An attacker capturing message 2, for example with ike-scan tool, has:

* SA proposal
* DH public values
* IDs
* HASH\_R

They can brute-force PSK offline until hash matches.\
This is why Aggressive Mode + PSK is discouraged. An attacker only needs:

* A packet capture
* The initiator identity

No interaction with the gateway required.

And what about certs instead of PSK?

**Why XAuth made Aggressive Mode even worse?**

To scale RA VPNs with XAuth, admins typically configured:

* Single global PSK
* Shared by all users
* Rarely rotated
* Often human-memorable

Perfect target for offline cracking

After PSK compromise, attacker can:

* Successfully complete IKE Phase 1
* Trigger XAuth prompts
* Perform:
  * Online password guessing
  * Credential harvesting
  * MFA fatigue (later setups)

#### 4.1.3 Phase 2

* There is only one mode - `quick` in Phase 2, `3 packets`
* It’s called Quick Mode because IKEv1 Phase 2 is deliberately short, lightweight, and fast compared to Phase 1 — both in message count and in cryptographic work: no identity, no DH exchange, only 3 messages
* By default, Phase 2 keys are derived from the session key created in Phase 1. Perfect Forward Secrecy (PFS) forces a new Diffie-Hellman exchange when the tunnel starts and whenever the Phase 2 keylife expires, causing a new key to be generated each time. This exchange ensures that the keys created in Phase 2 are unrelated to the Phase 1 keys or any other keys generated automatically in Phase 2
* PFS does not mean “ephemeral DH” in the modern TLS sense

**Cisco IOS example**

```
crypto map VPN 10 ipsec-isakmp
 set pfs group14
```

* Phase 2 (Quick Mode) packets are sent inside the encrypted IKE SA
* In your packet capture you will still see UDP 500 (or UDP 4500 if NAT-T) packets
* But their payloads are encrypted — they look like random binary blobs
* You can no longer see SA proposals, proxy-IDs, algorithms, etc

**Phase 2 has 3 packets only**

```
Initiator → Responder : SA, Nonce, traffic selectors, SPI, key exchange - optional, protocol - ESP/AH,
Responder → Initiator : SA, Nonce, SPI, key exchange - optional
Initiator → Responder : HASH (ack)
```

* No authentication happens during Phase 2
* `Responder does not send Traffic Selectors, it just agrees or declines Traffic Selectors from initiator`
* Crypto options are sent as many Transforms, which are called a transform set, `not as 1 transform in Phase 1`

**Example of first packet**

```
ISAKMP Header (HDR*)
 ├─ Initiator Cookie: 0xA1B2C3D4E5F60708
 ├─ Responder Cookie: 0x1122334455667788
 ├─ Next Payload: HASH (0x08)
 ├─ Version: 1.0
 ├─ Exchange Type: Quick Mode (32)
 ├─ Flags: Encrypted
 ├─ Message ID: 0x00001234
 └─ Length: 240 bytes

Encrypted Payloads (inside IKE SA):

1. HASH(1)
 └─ Integrity hash computed using Phase 1 keys
    (covers SA, Ni, KE, IDci, IDcr)

2. SA Payload (Security Association)
 ├─ Proposal #1
 │    ├─ Protocol ID: ESP (50)
 │    ├─ SPI Size: 4
 │    ├─ SPI Value (initiator): 0x3F2A1B4C
 │    ├─ Transform #1: Encryption
 │    │     • AES-CBC-256
 │    │     • Key Length: 256 bits
 │    ├─ Transform #2: Integrity
 │    │     • HMAC-SHA1-96
 │    ├─ Transform #3: Lifetime
 │    │     • 3600 seconds
 │    └─ Transform #4 (optional, PFS requested)
 │          • DH Group: 14

3. Ni (Nonce - Initiator)
 └─ Value: 0x8F3D4A9C12BEEF556677889900112233

4. KE (optional - DH for PFS)
 └─ DH Public Value (DH Group 14)
    • Example: 0xB7E3A2F9C4D1...

5. IDci (Identification - Initiator / Local Proxy-ID)
 ├─ Type: IPv4_ADDR_SUBNET
 ├─ Protocol: 0 (any)
 ├─ Port: 0 (any)
 ├─ Address: 10.0.0.0
 └─ Subnet Mask: 255.255.255.0

6. IDcr (Identification - Responder / Remote Proxy-ID)
 ├─ Type: IPv4_ADDR_SUBNET
 ├─ Protocol: 0 (any)
 ├─ Port: 0 (any)
 ├─ Address: 192.168.1.0
 └─ Subnet Mask: 255.255.255.0

7. Optional Payloads
 ├─ NAT-D detection (if NAT present)
 └─ Vendor ID (if implementation-specific)
```

**Negotiated options list - what is negotiated during Phase 2**

* Protocol: ESP or AH
* Mode: Tunnel or Transport
* Encryption transform: AES-CBC-256 - If AEAD (e.g., AES-GCM) was chosen in the encryption transform, separate integrity transform is not needed
* Integrity transform: HMAC-SHA1-96
* Lifetime transform: 3600 seconds and 4608000 kilobytes
* PFS: group 14 (if requested)
* Traffic Selectors(Proxy ID): 10.0.0.0/24 <-> 192.168.0.0/24 (proto any)
* Responder SPI (e.g. 0x3f2a1b4c) and Initiator SPI (e.g. 0x9a7e6c2d) — assigned by peers
* ESN: enabled (if negotiated / supported) - ESN = Extended Sequence Numbers - ESN extends the ESP sequence number from 32 bits to 64 bits

**To confirm Phase 2 happened, look for**

* Three small encrypted IKEv1 packets right after Phase 1
* ESP traffic starting immediately after them
* UDP/500 or 4500

#### 4.1.6 Xauth

* XAuth (Extended Authentication) is an optional extra authentication step used only with IKEv1, mainly to authenticate individual users (not just devices)
* XAuth is an extension to IKEv1 Phase 1, and it happens `after Phase 1 but before Phase 2`
* Standard IKEv1 Phase 1 authenticates devices or gateways (via PSK or certificates)
* XAuth adds a user-level authentication step — typically `username and password`
* XAuth does not substitute Phase 1 Authentication (PSK or Certificates) - it is still required
* Peers complete Phase 1 → a secure channel (IKE SA) is established
* The responder (gateway) requests XAuth credentials from the initiator
* The initiator (client) provides username and password
* The gateway validates them (e.g., against local DB, RADIUS, LDAP, etc.)
* If successful → proceed to Phase 2 (Quick Mode) to negotiate IPsec SAs
* `IKEv2 replaced XAuth with EAP` (Extensible Authentication Protocol) for user-level auth

#### 4.1.7 Mode-Config Phase

* Assign IP, DNS, WINS, Split tunnel
* `Happens after XAuth`
* Not used in IKEv2
* In IKEv2 it is called Configuration Payloads (CP) inside the IKE\_AUTH exchange

#### 4.1.8 Keepalives

* There is no single, clean, mandatory mechanism
* Two kinds of “keepalives” in IKEv1
  * NAT-T keepalives (most common meaning)
  * DPD / liveness checks (often incorrectly called keepalives)
* No automatic keepalives at all in pure IKEv1 without NAT-T and without DPD

#### 4.1.9 DPD

* Dead Peer Detection
* Detect dead peers
* Why DPD was invented?
  * IKE Phase 1 & 2 SAs can last hours (e.g., 8 hours lifetime)
  * VPN gateways may think a peer is alive even if it crashed, rebooted, or lost connectivity
  * Traffic sent to a dead peer gets silently dropped, wasting bandwidth and causing service issues
* DPD detects dead/unresponsive peers before SA lifetime expires
* Allow VPN device to: Delete stale SAs, Reestablish tunnels quickly, Avoid “half-dead” tunnels that appear up in show commands but fail in practice
* Uses ISAKMP INFORMATIONAL exchanges
* Encrypted and authenticated via the Phase 1 key
* Messages:
  * `R-U-THERE`
  * `R-U-THERE-ACK`
* Send DPD every \~30–60s
* Tear down SA after several missed DPDs
* Cisco configuration: `crypto isakmp keepalive 10 3`
* Backward-compatible
* Safe with peers that don’t support it
* If the peer understands DPD → it replies
* If it doesn’t → it silently ignores it
* `DPD checks ONLY the IKE (Phase 1) SA`
* `IKEv1 DPD is not negotiated, uses no Vendor IDs, and when enabled the device simply begins sending encrypted R-U-THERE probes over the existing Phase 1 SA`

**Example Packet Capture (IKEv1 DPD)**

```
Frame 10: IKEv1 Phase 1 SA
ISAKMP: INFORMATIONAL, DPD Request
    Exchange Type: R-U-THERE
    Message ID: 0x00000001
    Payloads: NONE (just a ping)
    
Frame 11: IKEv1 Phase 1 SA
ISAKMP: INFORMATIONAL, DPD Reply
    Exchange Type: R-U-THERE-ACK
    Message ID: 0x00000001
    Payloads: NONE
```

#### 4.1.10 NAT-T

```
+----------------+-----------+-------------+------------+------------------------+---------+-------------+----------+
|  New IP header | UDP header| NAT-T header| ESP header |Original Inner IP Header| IP Data | ESP trailer | ESP auth |
|    20 bytes    |  8 bytes  |   4 bytes   |  8 bytes   |                        |         |   2 bytes   | 12 bytes |
+----------------+-----------+-------------+------------+------------------------+---------+-------------+----------+
```

* ESP breaks when NAT is present
* ESP Tunnel Mode does not include the outer IP header in its Integrity Check Value (ICV)
* ESP Tunnel Mode protects: ESP header, Inner IP header, Payload, `It does NOT include the outer IP header`
* So if NAT changes the outer source/destination IP, `the ICV is not affected`
* `NAT cannot translate ESP because ESP has no ports` - NAT cannot track the flow
* `NAT breaks IPsec because IPsec expects stable src/dst IPs` - Even if ESP ICV survives, the security association itself is bound to a pair of IP addresses
* When NAT-T is enabled, `only SPI` is used for SA lookup
* Without NAT-T `SPI + IPs` are used for SA lookup
* UDP port 4500
* `Total overhead - 54 bytes!`
* Peers detect NAT-Traversal (NAT-T) automatically using a built-in mechanism in IKEv1 phase 1 or IKEv2 IKE\_SA\_INIT
* Each peer sends two special hashes: HASH(Original Source IP, Source Port), HASH(Original Destination IP, Destination Port)
* Each peer receives the other’s NAT-D payloads and compares them to what the packet actually arrived with
* The hashes match → no NAT
* By enabling this option, IPSec traffic can pass through a NAT device
* If the peers detect NAT in the path, they switch to: UDP/4500 for IKE, ESP-in-UDP/4500 for data
* Both peers must explicitly signal support for NAT-Traversal during Phase 1
* In IKEv1 it is optional, negotiated and announced via Vendor IDs
* In IKEv2 it is builtin and automatic

**NAT-T Keepalives**

* Keep NAT mappings alive
* Prevent UDP/4500 state from expiring
* 1-byte UDP packet
* Sent to UDP/4500
* Payload value: `0xFF`
* Not IKE, not ESP
* Stateless
* No response required
* Not authenticated
* Not encrypted
* 20–30 seconds (vendor-dependent)
* Even if no data traffic
* As long as IKE SA exists

The steps are:

* Announce NAT-T support - Via Vendor ID payloads during Phase 1
* Exchange NAT-D hashes
* Detect NAT (if hashes mismatch)
* Switch to UDP/4500

If only ONE peer supports NAT-T

* NAT-T = disabled
* Traffic stays UDP/500 + ESP
* Tunnel will fail if a real NAT is present

### 4.2 IKEv2

* `IKEv2 achieves Main-Mode-level security with Aggressive-Mode-level efficiency`
* `4 messages instead of 6 or 9 in IKEv1`
* IKEv2 is a completely new protocol, not a revised one
* IKEv2 removed ISAKMP entirely and defined its own message format
* Consist of request/response pairs, called exchages: `IKE_SA_INIT, IKE_AUTH`
* In IKEv2 there is no Main Mode or Aggressive Mode
* 2 separate HMAC functions are negotiated in SA for control channel: PRF and Integrity, IKEv1 used a single HMAC for everything

```
Integrity: HMAC-SHA1-96   (fast, smaller packets)
PRF:       HMAC-SHA256    (stronger key derivation)
```

* IKEv2 has:
  * IKE SPI (used in both IKE\_SA\_INIT and IKE\_AUTH) - 2 SPI numbers for Initiator and Responder
  * ESP/AH SPI for CHILD\_SA (used only in ESP/AH traffic) - 2 SPI numbers as well
* IKEv2 does not have phases: 1 and 2
* No Vendor IDs, which are used in IKEv1 for NAT-T, XAUTH.....
* One child Ipsec SA is created by default in IKE\_AUTH message
* If you need additional Child SA - 2 more messages - request and response
* Functionally, Phase 2 in IKEv1 (Quick Mode) and IKEv2 (Child SA) both negotiate ESP/AH SAs, keys, lifetimes, and traffic selectors, optionally with PFS
* IKEv2 merges and simplifies the process, reduces message count, enforces explicit traffic selectors, and has cleaner rekey/Child SA creation flows
* Traffic selectors are Mandatory: you must specify the exact local and remote subnets or hosts that this Child SA will cover
* Workarounds for “any-to-any” for route based VPN: Cover all relevant subnets with broad TS + Use the VTI to route all traffic through a single IPsec SA
* IKEv2 replaced XAuth with EAP (Extensible Authentication Protocol) for user-level auth - carried inside IKE\_AUTH
* EAP does not subsitute PSK or certificates, so you still need username and password
* In IKEv2 Mode-Config phase is called Configuration Payloads (CP) inside the IKE\_AUTH exchange
* Next generation encryption support: AES-GCM, ECDH, etc...
* Assymetric authentication support: one peer uses cert and other one uses password
* Built-in AntiDDoS protection
* NAT-T is embeded
* DPD is built in and mandatory

**Anti-DDoS**

* Has built-in anti-DDoS protections designed to stop an attacker from exhausting CPU or state on a VPN gateway before authentication even happens
* It uses pricipe: Don’t do expensive work, and don’t allocate state, until the peer proves it’s real
* IKEv2 mitigates DDoS attacks by using `stateless cookies, delaying expensive cryptography, and refusing to allocate resources` until the peer proves reachability
* The Problem: An attacker can flood the gateway with fake IKE\_SA\_INIT requests, which triggers: Diffie–Hellman, State allocation, Result: CPU and memory exhaustion
* When a gateway `detects load` or suspicious traffic, it refuses to proceed normally and responds with a COOKIE notification
* How it detects?
  * The primary signal is the number of incomplete IKE\_SAs: IKE\_SA\_INIT received BUT DH / auth not completed yet - Memory-consuming - CPU-expensive
  * CPU Utilization
  * Rate of IKE\_SA\_INIT Requests - Packets per second (PPS) of IKE\_SA\_INIT
  * Retransmission / Failure Ratios
* The cookie is Cryptographically generated, Bound to source IP + SPI, The gateway does not store the cookie, Can verify it statelessly, Spoofed source IPs fail, because they never see the cookie

```
1. Attacker → IKE_SA_INIT
2. Gateway → IKE_SA_INIT + COOKIE
   (no state created)

3. Client → IKE_SA_INIT + COOKIE
4. Gateway → normal processing
```

* Management of "Half-Open" SAs - The server starts a timer for every new request. If the full authentication isn't completed within a short window, the session is cleared to free up memory - Thresholds: Administrators can set limits on the maximum number of half-open sessions allowed at once. Once this threshold is hit, the server can either drop new requests or trigger the Cookie Challenge
* Decryption Failure Detection: If a peer sends multiple packets that fail decryption (often a sign of a junk flood), the server automatically tears down the session
* Certificate Size Limits: To prevent memory exhaustion from massive, fake certificates, administrators can set a maximum allowed size for certificates received during authentication

**In a Nutshell - 4 mandatory messages only - without EAP and Configuration Payload**

```
Initiator > IKE_SA_INIT > Responder
Responder > IKE_SA_INIT reply > Initiator - IKE SA done
Initiator > IKE_AUTH > Responder - Encrypted - possible Configuration Payloads (CP)
Responder > IKE_AUTH reply > Initiator - IPSEC SA done - possible Configuration Payloads (CP)
EAP packets - Optional - carried inside IKE_AUTH
Initiator > CREATE_CHILD_SA > Responder - Optional
Responder > CREATE_CHILD_SA > Initiator - Optional
```

#### 4.2.1 IKEv2 PSK

**Packet 1 - INIT\_SA**

Initiator sends first IKE\_SA\_INIT packet, which includes:

```
Initiator SPI
SA
 |-Proposals
           |-Transforms (Encryption, Integrity, PRF, DH Group) 
DH Public Key
Nonce
Source IP address hash for NAT-T detection - HASH(Initiator SPI | Responder SPI | IP address | UDP port)
Destination IP address hash for NAT-T detection
```

`No Auth method, no lifetime like in IKEv1, but separate PRF transform, NAT-T is embeded, not negotiated, no VIDs, DH exchange is immediate, not after crypto options negotiation`

**Packet itself**

```
Internet Key Exchange Version 2
  Initiator SPI: a1b2c3d4e5f60718
  Responder SPI: 0000000000000000
  Next Payload: Security Association (33)
  Version: 2.0
  Exchange Type: IKE_SA_INIT (34)
  Flags: 0x08 (Initiator)
  Message ID: 0
  Length: 430

Security Association
  Next Payload: Key Exchange (34)
  Length: 120
  Proposal Number: 1
  Protocol ID: IKE (1)
  SPI Size: 0
  Number of Transforms: 4
  Transform: Encryption Algorithm (AES-CBC, 256-bit)
  Transform: Integrity Algorithm (HMAC-SHA2-256-128)
  Transform: Pseudorandom Function (PRF-HMAC-SHA2-256)
  Transform: Diffie-Hellman Group (MODP 2048) - I am willing to use DH group 14 for this IKE SA -    This is negotiation

Key Exchange
  Next Payload: Nonce (40)
  Length: 264
  Diffie-Hellman Group: MODP 2048
  Key Exchange Data:
    9f:73:aa:41:4c:90:1e:77:...

Nonce
  Next Payload: Notify (41)
  Length: 36
  Nonce Data:
    4a:8c:91:ff:10:be:...

Notify
  Next Payload: Notify (41)
  Length: 28
  Notify Message Type: NAT_DETECTION_SOURCE_IP
  Notification Data:
    7e:11:3a:...

Notify
  Next Payload: None (0)
  Length: 28
  Notify Message 
  Type: NAT_DETECTION_DESTINATION_IP
  Notification Data:
    91:5a:8c:...
```

**Packet 2 - INIT\_SA**

Responder sends second IKE\_SA\_INIT packet, which includes:

```
Initiator, Responder SPI
SA
 |-Chosen Proposal 
                 |-Transforms (Encryption, Integrity, PRF, DH Group) 
DH public part
Nonce
NAT-T hashes
```

**Packet Itself**

```
Internet Key Exchange Version 2
  Initiator SPI: a1b2c3d4e5f60718
  Responder SPI: 1122334455667788
  Next Payload: Security Association (33)
  Version: 2.0
  Exchange Type: IKE_SA_INIT (34)
  Flags: 0x20 (Response)
  Message ID: 0
  Length: 434

Security Association
  Next Payload: Key Exchange (34)
  Length: 120
  Proposal Number: 1
  Protocol ID: IKE (1)
  SPI Size: 0
  Number of Transforms: 4
  Transform: Encryption Algorithm (AES-CBC, 256-bit)
  Transform: Integrity Algorithm (HMAC-SHA2-256-128)
  Transform: Pseudorandom Function (PRF-HMAC-SHA2-256)
  Transform: Diffie-Hellman Group (MODP 2048)

Key Exchange
  Next Payload: Nonce (40)
  Length: 264
  Diffie-Hellman Group: MODP 2048
  Key Exchange Data:
    3c:81:de:aa:55:09:...

Nonce
  Next Payload: Notify (41)
  Length: 36
  Nonce Data:
    91:ab:cc:42:...

Notify
  Next Payload: Notify (41)
  Length: 28
  Notify Message Type: NAT_DETECTION_SOURCE_IP
  Notification Data:
    1c:55:99:...

Notify
  Next Payload: None (0)
  Length: 28
  Notify Message Type: NAT_DETECTION_DESTINATION_IP
  Notification Data:
    8e:44:21:...
```

**Packet 3 - INIT\_AUTH**

Initiator sends first IKE\_AUTH Encrypted Packet, which includes:

```
Initiator, Reponder SPI from IKE_INIT
Encrypted
        |-Initiator ID
        |-Auth method
        |-Auth Hash
        |-SA
           |-Proposal
                    |-SPI - for traffic it will RECEIVE
                    |-Transform for Encryption
                    |-Transform for Packet Authentication and Integrity
        |-Traffic Selector for Initiator
        |-Traffic Selector for Responder
```

**Packet itself**

```
Internet Key Exchange Version 2
  Initiator SPI: a1b2c3d4e5f60718
  Responder SPI: 1122334455667788
  Next Payload: Encrypted and Authenticated (46)
  Version: 2.0
  Exchange Type: IKE_AUTH (35)
  Flags: 0x08 (Initiator)
  Message ID: 1
  Length: 348

Encrypted and Authenticated
  Initialization Vector:
    7e:19:aa:03:...
  Encrypted Data:
    Identification - Initiator
      ID Type: ID_USER_FQDN (3)
      Identification Data: user1

    Authentication
      Authentication Method: Shared Key Message Integrity Code
      Authentication Data:
        6f:92:11:88:...

    Security Association (Child SA)
      Proposal Number: 1
      Protocol ID: ESP (3)
      SPI Size: 4
      SPI: 1a2b3c4d
      Transform: AES-CBC-256
      Transform: HMAC-SHA2-256-128

    Traffic Selector - Initiator
      Number of TSs: 1
      TS Type: IPv4 Address Range
      Start Address: 0.0.0.0
      End Address: 255.255.255.255
      Start Port: 0
      End Port: 65535

    Traffic Selector - Responder
      Number of TSs: 1
      TS Type: IPv4 Address Range
      Start Address: 0.0.0.0
      End Address: 255.255.255.255
      Start Port: 0
      End Port: 65535

  Padding Length: 3
  Integrity Checksum: verified
```

**Packet 4**

Responder sends reply to IKE\_AUTH message, which includes:

```
Initiator and Responder SPI from IKE_INIT
Encrypted
        |-Responder ID
        |-Auth Method
        |-Auth Hash
        |-SA
           |-Proposal
                    |-SPI - which it wants to get inbound
                    |-Encryption Transform
                    |-Integrity transform - if not AEAD cipher is used
        |-Traffic selector initiator
        |-Traffic selector responder
```

**Packet itself**

```
Internet Key Exchange Version 2
  Initiator SPI: a1b2c3d4e5f60718
  Responder SPI: 1122334455667788
  Next Payload: Encrypted and Authenticated (46)
  Version: 2.0
  Exchange Type: IKE_AUTH (35)
  Flags: 0x20 (Response)
  Message ID: 1
  Length: 466

Encrypted and Authenticated
  Initialization Vector
  Decrypted Data:

    Identification - Responder
      ID Type: ID_FQDN
      Identification Data: vpn.example.com

    Authentication
      Authentication Method: Shared Key Message Integrity Code
      Authentication Data: AUTH_r

    Security Association (CHILD_SA)
      Proposal 1: ESP
        SPI: 0x1122EEFF        ← Responder inbound ESP SPI
        Encryption Algorithm: AES-GCM-256
        Integrity Algorithm: NONE
        ESN: No

    Traffic Selector - Initiator
      TS Type: IPv4
      Start Address: 10.0.0.10
      End Address: 10.0.0.10

    Traffic Selector - Responder
      TS Type: IPv4
      Start Address: 0.0.0.0
      End Address: 255.255.255.255

  Padding
  Integrity Checksum: verified
```

#### 4.2.2 IKEv2 Certificates

* Certs auth is more secure then PSK
* Certs completely kill offline cracking
* Because the attack surface disappears
* If an attacker captures one IKE exchange, he can do bruteforce attack to AUTH payload (MAC)
* What attacker does not have:
  * Private key
  * Any shared secret
  * Any value that can be guessed
* Private keys are not guessable
* Certs completely eliminate PSK dictionary attacks, capture now - crack later attacks

What does NOT change:

* Number of messages (still 4 in the basic flow)
* IKE\_SA\_INIT packets (frames 1 & 2)
* DH, nonces, NAT detection, SPIs
* CHILD\_SA negotiation
* Traffic selectors
* Encryption of IKE\_AUTH

What DOES change:

* New payloads appear
* AUTH payload content changes: Digital Signature instead of MAC
* Certificate validation happens off-wire

**What actually changes on the wire**

```
PSK:
  ID + AUTH(MAC)

CERT:
  ID + CERT + AUTH(SIGN)
```

`Everything else is identical`

Packet 3 — IKE\_AUTH (Initiator → Responder) - Changes:

* Certificated added as a payload - initiator’s public certificate
* Usually full chain (leaf + intermediates)
* Public key only (never private key)
* CERTREQ is added - optional
* CERTREQ means “please send me a certificate issued by one of these CAs”
* It’s about CA selection, not authentication itself
* CERTREQ payload says: “If you send me a certificate, it must chain up to one of these Certificate Authorities.”
* It contains: `Certificate encoding (X.509), One or more CA Distinguished Names`
* AUTH payload (CHANGED): HMAC of PSK and other fields > Signature: Same data(As for HMAC) is signed - Proves possession of private key

**Packet 3 Example with cert instead of PSK**

```
Internet Key Exchange Version 2
  Initiator SPI: a1b2c3d4e5f60718
  Responder SPI: 1122334455667788
  Next Payload: Encrypted and Authenticated (46)
  Version: 2.0
  Exchange Type: IKE_AUTH (35)
  Flags: 0x08 (Initiator)
  Message ID: 1
  Length: 652

Encrypted and Authenticated
  Initialization Vector:
    7a:3c:91:8f:2d:11:aa:6e:43:90:cd:1f:82:54:9a:01
  Decrypted Data:
    Identification - Initiator
      Next Payload: Certificate (37)
      ID Type: ID_FQDN (2)
      Identification Data: user@vpn.example.com

    Certificate
      Next Payload: Certificate Request (38)
      Certificate Encoding: X.509 Certificate - Signature (4)
      Certificate Data:
        -----BEGIN CERTIFICATE-----
        MIIDqTCCApGgAwIBAgIUVn6n...
        ...base64 omitted...
        -----END CERTIFICATE-----

    Certificate Request
      Next Payload: Authentication (39)
      Certificate Encoding: X.509 Certificate - Signature (4)
      Certification Authority:
        CN=User-CA,O=Example Corp,C=US

    Authentication
      Next Payload: Security Association (33)
      Authentication Method: Digital Signature (14)
      Authentication Data:
        30:45:02:21:00:9c:81:5a:3e:7f:2b:19:ae:
        6f:44:32:aa:91:cd:2e:55:1f:8b:3c:01:
        02:20:6d:9e:43:bb:91:ca:fe:12:7a:cc:
        9f:48:8e:91:0b:11:82:77:41:9e:aa:2d

    Security Association
      Next Payload: Traffic Selector - Initiator (44)
      Proposal Number: 1
      Protocol ID: ESP (3)
      SPI Size: 4
      SPI: 0xAABBCCDD
      Transforms:
        Transform Type: Encryption Algorithm (ENCR)
          Transform ID: AES-GCM-256 (20)
        Transform Type: Extended Sequence Numbers (ESN)
          Transform ID: No ESN (0)

    Traffic Selector - Initiator
      Next Payload: Traffic Selector - Responder (45)
      Number of TSs: 1
      TS Type: IPv4 (7)
      IP Protocol ID: Any (0)
      Start Port: 0
      End Port: 65535
      Start Address: 10.0.0.10
      End Address: 10.0.0.10

    Traffic Selector - Responder
      Next Payload: None (0)
      Number of TSs: 1
      TS Type: IPv4 (7)
      IP Protocol ID: Any (0)
      Start Port: 0
      End Port: 65535
      Start Address: 0.0.0.0
      End Address: 255.255.255.255

  Padding Length: 6
  Padding: 00 00 00 00 00 00
  Integrity Checksum: verified
```

Packet 4 — IKE\_AUTH (Responder → Initiator)

* The same as for PSK, But
* Sends its certificate
* Signs AUTH with its private key - Signature instead of PSK

**What AUTH actually signs (important)**

Exactly the same data for PSK and certs:

* IKE\_SA\_INIT messages (entire payloads)
* ID payload
* SA payload (if present)
* TS payloads (if present)

**What happens off-wire (but matters)**

* Verifies certificate chain
* Checks CA trust
* Checks validity period
* Checks revocation (CRL / OCSP)
* Matches ID to certificate identity

`None of that appears in packets`

#### 4.2.3 EAP

* EAP allows to use additional authentication in addition to PSK or Certs: username/password or additional cert
* Used for RA VPN
* In IKEv1 it called XAUTH
* 8 messages in total, instead of 4
* `When EAP is used, messages 1–2 unchanged, 3–4 modified, and extra messages 5-8 are added`
* EAP happens inside the IKE\_AUTH exchange, after
  * IKE\_SA\_INIT is complete
  * DH keys are established
  * The IKE SA is encrypted
* All EAP messages are encrypted on the wire

**Work flow**

* Messages 1-2: IKE\_SA\_INIT - regular
* Message 3 - empy IKE\_AUTH request with Initiator ID - it means I want EAP
* Messages 4-8 - EAP authentication process
* Messages 9-10 - Regular IKE\_Auth exchange: Authentication, CHILD\_SA creation, Traffic selectors + Configuration Request/Reply (IP, GW, DNS...)
* `EAP packets are between IKE_SA_INIT and IKE_AUTH regular packets, but technically EAP authentication is performed within the IKE_AUTH exchange.`
* Auth and CHILD\_SA happen only after EAP

Terms

* i - Initiator part
* r - Responder part
* SA - Security Assosiation
* KE - Key Exchange (Diffie-Hellman public value) - DH group (must match SA) - DH public number (g^x mod p, EC point, etc.)
* N - Nonce (random number)
* ID - IKE Identity
* TS - Traffic Selector

```
Initiator                                Responder
---------                                ----------

Message 1
IKE_SA_INIT  -------------------------->
  SAi, KEi, Ni
  (crypto negotiation, DH, NAT-D)

Message 2
IKE_SA_INIT  <--------------------------
  SAr, KEr, Nr
  (IKE SA keys derived)

--------------------------------------------------
IKE_AUTH exchange begins (all messages encrypted)
--------------------------------------------------

Message 3
IKE_AUTH     -------------------------->
  IDi
  (no AUTH payload)
  (implicitly indicates EAP will be used)

Message 4
IKE_AUTH     <--------------------------
  IDr
  EAP-Request

Message 5
IKE_AUTH     -------------------------->
  EAP-Response

Message 6
IKE_AUTH     <--------------------------
  EAP-Request

Message 7
IKE_AUTH     -------------------------->
  EAP-Response

Message 8
IKE_AUTH     <--------------------------
  EAP-Success
  (EAP authentication complete)

--------------------------------------------------
Final authentication and CHILD_SA creation
(still part of the same IKE_AUTH exchange)
--------------------------------------------------

Message 9
IKE_AUTH     -------------------------->
  AUTH (Initiator authentication)
  SA (CHILD_SA proposal)
  TSi, TSr
  CFG_REQUEST
    - INTERNAL_IP4_ADDRESS
    - INTERNAL_IP4_DNS
    - INTERNAL_IP4_SUBNET

Message 10
IKE_AUTH     <--------------------------
  AUTH (Responder authentication)
  SA (CHILD_SA accepted)
  TSi, TSr
  CFG_REPLY
    - Assigned virtual IP
    - DNS servers
    - Split tunnel info

IKE SA established
First CHILD_SA established
```

**EAP + PSK Example - Packets 3-10**

**Packet 3 - IKE\_AUTH (Initiator → Responder)**

`No Auth here like in regular packet 3 without EAP, No SA Proposals, No Traffic selectors - this means that Client wants EAP`

```
Initiator and Responder SPI from IKE_INIT
Encrypted
        |-Initiator ID
        |-Configuration Request
```

**Packet itself**

```
Internet Key Exchange Version 2
  Initiator SPI: 0xa1b2c3d4e5f60718
  Responder SPI: 0x1122334455667788
  Next Payload: Encrypted and Authenticated (46)
  Version: 2.0
  Exchange Type: IKE_AUTH (35)
  Flags: 0x08 (Initiator)
  Message ID: 1
  Length: 296

Encrypted and Authenticated Payload
  Decrypted Data:
    Identification - Initiator
      ID Type: ID_FQDN (2)
      Identification Data: user1@example.com

    Configuration Payload
      Configuration Type: CFG_REQUEST (1)
      Attribute:
        INTERNAL_IP4_ADDRESS

  Padding Length: 6
  Integrity Checksum: verified
```

**Packet 4 - IKE\_AUTH (Responder → Initiator) - EAP Request**

```
Initiator and Responder SPI from IKE_INIT
Encrypted
        |-Responder ID
        |-EAP Request
```

**Packet itself**

```
Internet Key Exchange Version 2
  Initiator SPI: 0xa1b2c3d4e5f60718
  Responder SPI: 0x1122334455667788
  Next Payload: Encrypted and Authenticated (46)
  Version: 2.0
  Exchange Type: IKE_AUTH (35)
  Flags: 0x20 (Response)
  Message ID: 1
  Length: 308

Encrypted and Authenticated Payload
  Decrypted Data:
    Identification - Responder
      ID Type: ID_FQDN (2)
      Identification Data: vpn.example.com

    EAP Payload
      Code: Request (1)
      Identifier: 1
      Type: Identity (1)

  Padding Length: 5
  Integrity Checksum: verified
```

**Packet 5 - IKE\_AUTH (Initiator → Responder) - EAP Identity from Client - Username**

```
Initiator and Responder SPI from IKE_INIT
Encrypted
        |-EAP ID
```

**Packet itself**

```
Internet Key Exchange Version 2
  Initiator SPI: 0xa1b2c3d4e5f60718
  Responder SPI: 0x1122334455667788
  Next Payload: Encrypted and Authenticated (46)
  Version: 2.0
  Exchange Type: IKE_AUTH (35)
  Flags: 0x08 (Initiator)
  Message ID: 2
  Length: 284

Encrypted and Authenticated Payload
  Decrypted Data:
    EAP Payload
      Code: Response (2)
      Identifier: 1
      Type: Identity (1)
      Identity: user1@example.com

  Padding Length: 7
  Integrity Checksum: verified
```

**Username is now known**

**Packet 6 - IKE\_AUTH (Responder → Initiator) - EAP authentication challenge**

```
Initiator and Responder SPI from IKE_INIT
Encrypted
        |-EAP Challenge
```

**Packet itself**

```
IKEv2
  Initiator SPI: a1b2c3d4e5f60718
  Responder SPI: 1122334455667788
  Exchange Type: IKE_AUTH
  Flags: Response
  Message ID: 2
  Encrypted

Decrypted Payloads:
  EAP Payload
    Code: Request (1)
    Identifier: 2
    Type: MD5-Challenge (4)
    Value-Size: 16
    Challenge:
      9f:83:21:ab:7c:44:9e:12:3d:aa:09:be:77:01:fe:22
```

**Packet 7 - IKE\_AUTH (Initiator → Responder) - Auth challenge**

```
Initiator and Responder SPI from IKE_INIT
Encrypted
        |-EAP Challenge 
```

**Packet itself**

```
IKEv2
  Initiator SPI: a1b2c3d4e5f60718
  Responder SPI: 1122334455667788
  Exchange Type: IKE_AUTH
  Flags: Initiator
  Message ID: 3
  Encrypted

Decrypted Payloads:
  EAP Payload
    Code: Response (2)
    Identifier: 2
    Type: MD5-Challenge (4)
    Value-Size: 16
    Response:
      5e:44:aa:91:3c:99:f1:77:6d:02:ab:45:11:fe:88:90
```

**Packet 8 - IKE\_AUTH (Responder → Initiator) - EAP Success - EAP authentication complete**

```
Initiator and Responder SPI from IKE_INIT
Encrypted
        |-EAP Success 
```

**Packet itself**

```
IKEv2
  Initiator SPI: a1b2c3d4e5f60718
  Responder SPI: 1122334455667788
  Exchange Type: IKE_AUTH
  Flags: Response
  Message ID: 3
  Encrypted

Decrypted Payloads:
  EAP Payload
    Code: Success (3)
```

**Packet 9 - IKE\_AUTH (Responder → Initiator) - Regular IKE\_AUTH**

```
Initiator and Responder SPI from IKE_INIT
Encrypted
        |-Auth method
        |-Auth Hash
        |-SA
           |-Proposal
             |-SPI
             |-Protocol: ESP
             |-Encryption transform
             |-Integrity transform
        |-Traffic selector - Initiator
        |-Traffic Selector - Responder
```

**Key points**

* FIRST time AUTH appears
* PSK proves IKE identity
* CHILD\_SA proposed

**Packet itself**

```
Internet Key Exchange Version 2
  Initiator SPI:  a1b2c3d4e5f60718
  Responder SPI: 1122334455667788
  Next Payload:  Encrypted and Authenticated (46)
  Version:       2.0
  Exchange Type: IKE_AUTH (35)
  Flags:         0x08 (Initiator)
  Message ID:    3
  Length:        412

Encrypted and Authenticated Payload
  Decrypted Data:
    Authentication
      Authentication Method: Shared Key Message Integrity Code
      Authentication Data:
        8b:19:fa:44:...

    Security Association
      Proposal #1
        Protocol ID: ESP (3)
        SPI: 0x1001a2b3
        Transforms:
          ENCR_AES_CBC (256)
          INTEG_HMAC_SHA2_256
          ESN disabled

    Traffic Selector - Initiator
      TS Type: TS_IPV4_ADDR_RANGE
      Start Address: 0.0.0.0
      End Address: 255.255.255.255

    Traffic Selector - Responder
      TS Type: TS_IPV4_ADDR_RANGE
      Start Address: 10.0.0.0
      End Address: 10.0.0.255

  Padding Length: 4
  Integrity Checksum: verified
```

**Packet 10 - IKE\_AUTH (Responder → Initiator) — FINAL**

```
Initiator and Responder SPI from IKE_INIT
Encrypted
        |-Auth method
        |-Auth Hash
        |-SA
           |-Proposal
             |-SPI
             |-Protocol: ESP
             |-Encryption transform
             |-Integrity transform
        |-Configuration payload: IP, Gateway, DNS...
```

**Packet itself**

```
Internet Key Exchange Version 2
  Initiator SPI:  a1b2c3d4e5f60718
  Responder SPI: 1122334455667788
  Next Payload:  Encrypted and Authenticated (46)
  Version:       2.0
  Exchange Type: IKE_AUTH (35)
  Flags:         0x20 (Response)
  Message ID:    3
  Length:        398

Encrypted and Authenticated Payload
  Decrypted Data:
    Authentication
      Authentication Method: Shared Key Message Integrity Code
      Authentication Data:
        4c:77:19:aa:...

    Security Association
      Proposal #1
        Protocol ID: ESP (3)
        SPI: 0x2009fabc
        Transforms:
          ENCR_AES_CBC (256)
          INTEG_HMAC_SHA2_256
          ESN disabled

    Configuration Payload
      Configuration Type: CFG_REPLY (2)
      Attributes:
        INTERNAL_IP4_ADDRESS: 10.0.0.25
        INTERNAL_IP4_DNS: 10.0.0.10

  Padding Length: 6
  Integrity Checksum: verified 
```

## 5 Authentication scenarios

**SITE-TO-SITE (S2S) VPN — AUTHENTICATION FLOWS**

Goal:

* Authenticate two NETWORK DEVICES
* Long-lived tunnels
* Static peers
* No user authentication

**IKEv1 – Main Mode – PSK**

Purpose:

* Simple device authentication
* Easy to deploy

Problems:

* PSK vulnerable to offline cracking - not only aggressive mode is vulnerable to PSK offline bruteforce - <https://www.kb.cert.org/vuls/id/857035/> - IKEv2 is not vulnerable
* Poor scalability
* Key rotation is painful

Status: Legacy / discouraged today

**IKEv1 – Main Mode – Certificates**

Purpose:

* Strong device authentication
* Identity protection

Pros:

* No offline cracking
* Scales well
* Strong cryptographic identity

Cons:

* PKI overhead

**IKEv2 – PSK**

Purpose:

* Simple S2S authentication

Problems:

* Weak if PSK reused

Status: Acceptable only with strong random PSKs

**IKEv2 – Certificates (BEST PRACTICE)**

Purpose:

* Strong device-to-device authentication

Why best:

* No offline cracking
* Scales well
* Clean rekey & rotation
* Mandatory for high-security environments

`BEST CHOICE FOR S2S VPNs: IKEv2 + Certificates`

**REMOTE-ACCESS (RA) VPN — AUTHENTICATION FLOWS**

Goal:

* Authenticate USERS (and sometimes devices)
* Dynamic IPs
* Per-user authorization
* Virtual IP assignment

**IKEv1 – Aggressive Mode – PSK**

Purpose:

* Fast RA VPN setup

Problems:

* Offline PSK cracking
* Identity exposed
* Very weak security

Status: Do not use today

IKEv1 – Aggressive Mode – PSK + XAUTH

Purpose:

* Device auth (PSK)
* User auth (XAUTH)

Сlassic Cisco RA VPNs

Problems:

* PSK still crackable offline
* XAUTH is vendor-specific
* Legacy design

Status: Legacy / replaced by IKEv2

**IKEv2 – PSK + EAP**

Purpose:

* Device authentication via PSK
* User authentication via EAP

Used when:

* No PKI
* Easy onboarding

IKEv2 – Certificates (device) + EAP (user)

Purpose:

* Device authentication
* User authentication
* Per-user authorization

Why best:

* No offline cracking
* Strong identity binding
* Works with MFA

`BEST CHOICE FOR RA VPNs`

**EAP METHODS — WHAT IS ACTUALLY USED**

Common in IKEv2 RA VPNs:

EAP-MSCHAPv2

* Username/password
* Very common with Active Directory
* Vulnerable if not protected by TLS

EAP-TLS (BEST)

* Client certificate
* Strong mutual authentication
* No passwords
* Enterprise gold standard

EAP-TTLS / PEAP

* TLS tunnel + inner auth
* Username/password inside TLS
* Common in Wi-Fi, less in VPN

EAP-MD5

* Weak
* No mutual auth
* Should not be used

Most popular today:

* EAP-MSCHAPv2 (legacy environments)
* EAP-TLS (modern / secure environments)

ONE-LINE TAKEAWAYS

S2S VPN: → Authenticate DEVICES → Best: IKEv2 + Certificates

RA VPN: → Authenticate USERS (and devices) → Best: IKEv2 + Certificates + EAP-TLS

PSK: → Easy → Weak → Legacy unless carefully managed

## 6 IKE Security

* IKEv1 Aggressive Mode + PSK authentication is vulnerable to PSK offiline bruteforce
* Using ike-scan tool we get PSK hash

```
ike-scan -M -A --id=0000 1.1.1.1

-M - multiline, for comfortable reading
-A - aggressive
--id - IKE identity
- P - show PSK hash

Starting ike-scan 1.9.5 with 1 hosts (http://www.nta-monitor.com/tools/ike-scan/)
1.1.1.1  Main Mode Handshake returned
    HDR=(CKY-R=2d3f8a8c4d1c2e21) 
    SA=(Enc=AES Hash=SHA1 Auth=PSK Group=2:modp1024 LifeType=Seconds LifeDuration=28800)
    VID=4048b7d56ebce88525e7de7f00d6c2d3 (Dead Peer Detection)
    VID=12f5f28c457168a9702d9fe274cc0100 (NAT-T RFC 3947)
    VID=afcad71368a1f1c96b8696fc77570100 (Cisco Unity)

1.1.1.1  Aggressive Mode Handshake returned
    HDR=(CKY-R=89ac45f0f13a9b3e)
    SA=(Enc=AES Hash=SHA1 Auth=PSK Group=2:modp1024 LifeType=Seconds LifeDuration=28800)
    ID(Type=ID_KEY_ID, Value="vpn-group")
    Hash=fa7a0c9a6caa5b8e9e2c7d2c8d5c3d9c

Ending ike-scan: 1 hosts scanned in 0.113 seconds (8.85 hosts/sec). 1 returned handshake; 1 returned notify.
```

Using ike-scan with aggressive mode we get:

* PSK hash
* Crypto parametres
* Server IKE ID

Show full HASH:

```
root@kali:~# ike-scan -M -A --id=0000 11.11.11.11 -P
```

## 7 IPSec protocols

* There are 2 possible IPSec protocols: ESP and AH
* Each of these protocols has 2 possible modes: Tunnel and Transport
* `IPSec protocol and its mode are negotiated during Phase 2 in IKEv1 and IKE_AUTH in IKEv2`

### 7.1 ESP

* Separate IP protocol for Data Plane
* IP protocol number 50
* Provides Confidentiality, authentication, replay protection
* Supports encryption and NAT-T
* `ESP mode: tunnel or transport mode`

#### 7.1.1 Transport Mode

* Typically used for host-to-host communication
* Server A ↔ Server B over the internet - No VPN gateways - No IP tunneling - Just encrypted transport
* Before widespread TLS adoption, this was common in AD environments - Windows 2000 to Windows 2000
* TLS replaced it
* It encrypts only the payload (Layer 4 and up), keeping the original IP header intact
* Adds ESP header after original IP header + ESP trailer + ESP auth

```
+----------------------------+
| Original IP Header       |  ← Unencrypted (source/dest IPs visible)
|   (IPv4 or IPv6)       |
+----------------------------+
| ESP Header               |  ← Not Encrypted + Authenticated
|   (SPI, Sequence #)    |
+----------------------------+
| Upper‑Layer Data         |  ← Encrypted + Authenticated
|   (e.g., TCP, UDP)     |
+----------------------------+
| ESP Trailer              |  ← Encrypted + Authenticated
|   (Padding, Pad Length,  |
|    Next Header)          |
+----------------------------+
| ESP Auth Trailer (ICV)   |  ← Not encrypted; Integrity Check Value (HMAC) - is used to authenticate (verify integrity and authenticity) - computed as an HMAC, e.g., HMAC‑SHA256 - is calculated over ESP Header, Encrypted Payload, ESP Trailer
+----------------------------+
```

#### 7.1.2 Tunnel mode

* Tunnel mode - encrypts the entire original packet - adds a new set of IP headers
* Required parametres for Tunnel mode:
  * Symmetric cipher
  * Hash
  * DH group
  * Lifetime

```
+----------------------------+
| New Outer IP Header      |  ← Unencrypted (gateway IPs)
|   (IPv4 or IPv6)       |
+----------------------------+
| ESP Header               |  ← Not Encrypted + Authenticated
|   (SPI, Sequence #)    |
+----------------------------+
| Original IP Packet       |  ← Encrypted + Authenticated
|   [IP Header +          |
|    Upper‑Layer Data]    |
+----------------------------+
| ESP Trailer              |  ← Encrypted + Authenticated
|   (Padding, Pad Length,  |
|    Next Header)          |
+----------------------------+
| ESP Auth Trailer (ICV)   |  ← Not encrypted; Integrity Check Value (HMAC)
+----------------------------+
```

**Data flow in practice**

* Router receives an ESP packet
* Reads SPI from the ESP header
* Looks up SAD based on SPI to find:
  * Encryption key
  * Integrity key
  * Mode, lifetime, etc.
* Verifies ICV (if authentication is used)
* Decrypts payload only using the key

### 7.2 AH

* Separate protocol above IP with encapsulation for data plane
* Data Integrity, Authentication, Protection from replays
* `It authenticates the packets, not the peers`
* Peers are authenticated via IKE
* Does not support encryption
* AH is incompatible with NAT because it authenticates immutable IP header fields
* Transform set for authentication header defines only HMAC function, for example `ah-sha-hmac`
* Not used anywhere
* AH has two modes just like ESP: Transport mode and Tunnel mode
* Transport mode is used for `Host-to-host security`
* Tunnel mode is used for `Gateway-to-gateway VPN - Secure communication between networks`

**AH – Transport Mode**

* Protects host-to-host traffic without encapsulation
* Transport mode calculates HMAC based on `Immutable IP header fields, AH header, Entire IP payload` and shared secret symmetric key derived during IKE, then puts result to field `Integrity Check Value (ICV)`
* Supported HMAC algorithms: `HMAC-MD5-96, HMAC-SHA1-96, HMAC-SHA2-256-128, HMAC-SHA2-384-192, HMAC-SHA2-512-256`
* Realistic Use Case (Historical): `Secure Router-to-Router Routing Protocols, Secure Server-to-Server Communication`

```
IP Header | AH Header | TCP/UDP | Data
```

```
+---------------------------+
|   IP Header               |
+---------------------------+
|   AH Header               |
|     - Next Header         |
|     - Payload Length      |
|     - SPI                 |
|     - Sequence Number     |
|     - Integrity Check Val |
+---------------------------+
|   TCP / UDP Header        |
+---------------------------+
|   Application Data        |
+---------------------------+
```

**AH – Tunnel Mode**

* Protects `entire original IP packet` with encapsulation
* Tunnel mode calculates HMAC based on `Immutable or predictable fields of the OUTER IP header + AH header (with ICV field set to zero) + Entire INNER IP packet` and shared secret symmetric key derived during IKE, then puts result to field `Integrity Check Value (ICV)`
* IP 51 is used for new IP packet
* Supported HMAC algorithms: `HMAC-MD5-96, HMAC-SHA1-96, HMAC-SHA2-256-128, HMAC-SHA2-384-192, HMAC-SHA2-512-256`
* Realistic Use Case (Historical): \`Government / Military Networks

```
Outer IP | AH Header | Inner IP | TCP/UDP | Data
```

```
+---------------------------+
|   Outer IP Header         |
+---------------------------+
|   AH Header               |
|     - Next Header         |
|     - Payload Length      |
|     - SPI                 |
|     - Sequence Number     |
|     - Integrity Check Val |
+---------------------------+
|   Inner IP Header         |
+---------------------------+
|   TCP / UDP Header        |
+---------------------------+
|   Application Data        |
+---------------------------+

```

**Processing Order (Receiver)**

* Read SPI
* Lookup SA
* Verify sequence number (anti-replay)
* Recalculate hash
* Compare ICV
* If valid → pass packet up
* No decryption step exists.

## 8 L2TP over IPSec

* L2TP - layer-2 tunneling protocol
* Original purpose: tunnel PPP over IP networks for ISPs
* Today: mainly VPNs (L2TP over IPsec)
* Advanced: L2TPv3 for generic Layer 2 tunneling in carrier networks
* Originally, L2TP evolved from L2F (Cisco) and PPTP (Microsoft) to allow ISPs to tunnel PPP sessions from customers to a central server
* Example: A DSL provider could send a customer’s PPP session over the Internet to a BRAS (Broadband Remote Access Server)
* This allows authentication, accounting, and IP assignment at the ISP, even though the customer is on a remote IP network
* Used for client VPNs
* Some carriers use L2TP (or L2TPv3) to tunnel Layer 2 frames across IP/MPLS networks
* `L2TPv3 can encapsulate Ethernet, Frame Relay, ATM, not just PPP`
* L2TP provides encapsulation of PPP to UDP
* L2TP over IPsec was built into the native Windows VPN client for many years
* So you had two layers of authentication:
  * Machine-level (IPsec)
  * User-level (PPP)
* It worked with Active Directory
* It worked with RADIUS
* It required no client install
* User authentication + IP address assignment + policy negotiation
* PPP is a Layer-2 protocol and IPsec protects IP packets (Layer-3) - PPP cannot run directly over IP
* So to carry PPP across an IP network, you must Encapsulate PPP inside an IP-based protocol
* That’s what L2TP does
* L2TP:
  * Puts them inside UDP (port 1701)
  * Which runs over IP
* So now PPP becomes transportable over IP
* Then IPsec encrypts that IP packet
* Without L2TP, PPP has no way to cross an IP network
* We cannot use PPP above UDP directly because:
  * L2TP adds a tunnel ID and session ID
  * L2TP allows multiple PPP sessions over a single UDP/IP tunnel
  * L2TP defines control messages (like starting/ending sessions, managing tunnels). PPP itself has no concept of tunneling over IP
  * Standardization & Interoperability: Using L2TP over UDP/IP became a standard for VPNs, so vendors could interoperate reliably

**Stack looks like:**

```
IPsec
   ↓
IP
   ↓
UDP 1701
   ↓
L2TP
   ↓
PPP
   ↓
User traffic
```

**Before decryption, the packet on the wire would look like:**

```
Ethernet
Outer IP (IPsec peers)
ESP
Encrypted Payload
```

**After Wireshark decrypts ESP, it reveals:**

```
Ethernet
Outer IP
UDP 1701
L2TP
PPP
Inner IP
TCP/UDP
Application
```

**Packet example**

```
Internet Protocol Version 4
    Version: 4
    Header Length: 20 bytes
    Differentiated Services Field: 0x00
    Total Length: 1460
    Identification: 0x1c46
    Flags: 0x4000 (Don't Fragment)
    Fragment Offset: 0
    Time to Live: 63
    Protocol: UDP (17)
    Header Checksum: 0x8b12
    Source Address: 192.0.2.10
    Destination Address: 198.51.100.20

User Datagram Protocol
    Source Port: 1701
    Destination Port: 1701
    Length: 1440
    Checksum: 0x3c7a

Layer 2 Tunneling Protocol
    Flags and Version: 0xc802
        Type: Data Message
        Length present
        Sequence present
        Offset absent
        Version: L2TPv2
    Length: 1432
    Tunnel ID: 0x0003
    Session ID: 0x0001
    Ns: 142
    Nr: 95

Point-to-Point Protocol
    Address: 0xff
    Control: 0x03
    Protocol: 0x0021 (IPv4)

Internet Protocol Version 4
    Version: 4
    Header Length: 20 bytes
    Differentiated Services Field: 0x00
    Total Length: 1400
    Identification: 0x5c11
    Flags: 0x4000
    Fragment Offset: 0
    Time to Live: 64
    Protocol: TCP (6)
    Header Checksum: 0xa811
    Source Address: 10.10.10.5
    Destination Address: 8.8.8.8

Transmission Control Protocol
    Source Port: 51532
    Destination Port: 443
    Sequence Number: 148221
    Acknowledgment Number: 892211
    Header Length: 32 bytes
    Flags: 0x018 (PSH, ACK)
    Window Size: 64240
    Checksum: 0x1f9a
    Urgent Pointer: 0
    Options: (12 bytes)

Transport Layer Security
    TLSv1.3 Record Layer
        Content Type: Application Data
        Version: TLS 1.2
        Length: 1300
```

## 9 GRE over IPSec

* IPsec alone cannot natively send multicast to multiple endpoints without setting up separate Security Associations (SAs) for each receiver
* When you combine GRE + IPsec, the stack is:

```
[IPsec ESP Header]
    └─ [GRE Header]
         └─ [Original Multicast IP Packet]
```

* Now, IPsec sees only unicast GRE packets between the two tunnel endpoints
* GRE handles encapsulating the multicast traffic into unicast tunnels
* For two routers talking OSPF over IPsec, GRE isn’t strictly necessary
* GRE is mostly needed when you want one tunnel to carry multicast traffic to multiple endpoints efficiently
* OSPF can run directly over IPsec, but it’s practical only for simple point-to-point site-to-site tunnels

## 10 IPSec tunnels and MTU

* MTU (Maximum Transmission Unit) is the largest packet size a network interface can transmit
* Standard Ethernet MTU = 1500 bytes.
* IPsec adds headers:
  * ESP header (20–32 bytes)
  * ESP trailer + padding (variable, up to 256 bytes depending on block size)
  * AH header (if used)
* Result: effective MTU for payload is smaller
* If you ignore this:
* Packets larger than the path MTU may be dropped
* TCP may fragment or experience black hole issues if DF (Don’t Fragment) is set
* VPN throughput suffers, intermittent connectivity, strange retransmissions

**IPsec overhead**

```
| Component        | Size (bytes) | Notes                                 |
|------------------|--------------|---------------------------------------|
| ESP header       | 20–32        | Depending on algorithm (AES, SHA, etc.) |
| ESP trailer      | 2–255        | For padding to block boundary         |
| ESP auth (HMAC)  | 12–16        | For integrity check                   |
| IP header (outer)| 20           | IPv4 standard                         |
| UDP (for NAT-T)  | 8            | Only if NAT traversal is used         |
```

* Typical overhead: \~50–60 bytes without NAT-T, \~70–80 bytes with NAT-T
* Implication: If your interface MTU = 1500, the maximum payload that will pass without fragmentation is \~1440 bytes

**Path MTU Discovery (PMTUD)**

* IPsec relies on PMTUD to detect the maximum packet size that can traverse the path
* Problem: PMTUD often fails with firewalls/NAT that block ICMP “fragmentation needed” messages
* Result: large packets are dropped silently → “black hole” problem

**Best Practices for MTU in IPsec**

* Reduce MTU on tunnel interface ≈ 1400–1420
* ip tcp adjust-mss ensures TCP sessions automatically reduce segment size, preventing fragmentation
* If NAT traversal is used, add UDP/4500 encapsulation overhead (\~28 bytes)
* Use ping with DF set to test path MTU: `ping 10.2.2.1 df-bit size 1400`
* Gradually adjust MTU until it succeeds without fragmentation
* Use Wireshark to verify ESP packets and sizes
* Document MTU and MSS in your network design
* Force all TCP sessions going through the VPN to use a smaller MSS, so they never exceed the IPsec MTU - TCP MSS clamping
* Done on firewall or VPN gateway
* Example:

```bash
interface outside
 ip access-group VPN_MSS in
!
ip access-list extended VPN_MSS
 permit tcp any any mss 1360
```

What this does:

* When a TCP SYN packet enters the firewall/VPN, the gateway modifies the MSS field in the TCP header if it’s larger than 1360
* Client sees the smaller MSS, and all future TCP segments are small enough to fit inside the IPsec tunnel without fragmentation
* Works even if clients don’t know the real MTU of the tunnel

## 11 Configuration - Cisco

**Three possible ways to configure IPSec tunnel on Cisco Routers:**

* Pure (Policy-Based) IPsec - crypto-map–based IPsec
  * Traffic is matched by crypto ACLs
  * No tunnel interface
  * IPSec is applied directly to the physical interface via a crypto map
  * Routing is not aware of the tunnel
  * No dynamic routing protocols
* IPsec + VTI (Virtual Tunnel Interface) - route-based IPsec
  * A logical Tunnel interface is created
  * IPSec protects the tunnel traffic
  * Routing happens over the tunnel
  * Tunnel Interface └── IPSec Profile
  * Supports dynamic routing
* IPsec with GRE (GRE over IPsec) - A tunnel inside a tunnel
  * GRE provides encapsulation
  * `Can be done both with crypto maps and IPSec profile`
  * IPSec encrypts the GRE packets
  * GRE handles routing, MULTICAST, multiple subnets
  * Can be policy-based or route-based
  * `Use only when multicast is required`
* A VTI-based (route-based) IPsec endpoint and a policy-based (crypto-map) endpoint are architecturally incompatible
* Policy-based IPsec Expects specific proxy IDs (src/dst subnets)
* VTI-based IPsec Proxy IDs are typically 0.0.0.0/0 ↔ 0.0.0.0/0 (or a host /32)
* IKE Phase 2 (CHILD\_SA) will fail
* But At the protocol level, it is the same protocol

**Why we shouldnt use Crypto maps**

* They cannot natively support MPLS
* Configuration can be complex
* They are commonly misconfigured
* Consume excessive amount of TCAM

### 11.1 IPSec + VTI + IKEv2 example

`Tunnel` (vrf, bandwidth, ip, mss, mtu, load interval, bfd, source, mode, path mtu discovery, destination, **ipsec profile**) > `ipsec profile` (idle, **transform-set**, pfs group, **ike-v2-profile**) > `ike-v2-profile` (identity, authentication, **keyring**, lifetime, dpd), `transform set`(encryption, hash, mode) > `keyring` (address, key)

`ike-v2-policy` (vrf, **proposals**) > `proposal` (encryption, hash, pfs group)

```bash
Tunnel
  └─ IPsec Profile
       ├─ Transform Set   (ESP parameters)
       └─ IKEv2 Profile
            └─ Keyring
IKEv2 Policy
  └─ Proposal             (IKE SA parameters)
```

**Tunnel**

```bash
interface Tunnel12
 description Tunnel
 bandwidth 2000000
 bandwidth qos-reference 1000000
 vrf forwarding IPSEC
 ip address 10.16.6.37 255.255.255.252
 no ip redirects
 ip mtu 1400
 ip tcp adjust-mss 1360
 load-interval 30
 shutdown
 bfd interval 500 min_rx 500 multiplier 3
 tunnel source Port-channel1.440
 tunnel mode ipsec ipv4
 tunnel destination 11.11.11.11
 tunnel path-mtu-discovery
 tunnel vrf corp
 tunnel protection ipsec profile Corp-profile
end
```

**IPSec Profile**

```bash
crypto ipsec profile IPSEC-profile
 set security-association idle-time 3600
 set transform-set IPSEC 
 set pfs group1
 set ikev2-profile CorpIPSEC-Prisma-ikev2-profile
```

**Transform set**

Phase 2 options

```bash
crypto ipsec transform-set IPSEC esp-aes 256 esp-sha256-hmac 
 mode tunnel
```

**IKE v2 Profile**

Phase 1 options

```bash
crypto ikev2 profile IPSEC-profile
 match identity remote any
 authentication remote pre-share
 authentication local pre-share
 keyring local CorpIPSEC-vpn-keyring
 lifetime 28800
 dpd 10 3 periodic
```

**Keyring**

```bash
crypto ikev2 keyring CorpIPSEC-vpn-keyring
 peer Corp_Tunnel12
  address 34.11.11.11
  pre-shared-key CY5R2TugteXEGBv6
```

**IKE-v2 Policy**

```bash
crypto ikev2 policy remote-ikev2-policy 
 match fvrf corpInternet
 match fvrf wan_underlay
 proposal remote-ikev2-proposal
 proposal 3rdParty-ikev2-proposal
 proposal 3rdParty-ikev2-Sha256-proposal
 proposal CorpIPSEC-ikev2-proposal
 proposal oci_ikev2-proposal
```

**IKE Proposal**

Phase 1 options

```bash
crypto ikev2 proposal CorpIPSEC-ikev2-proposal 
 encryption aes-cbc-256 aes-cbc-128
 integrity sha512 sha384 sha256
 group 19 14 5 2
```

### 11.2 IPSec with GRE via Crypto Map

IKEv1 - Can be IKEv2

```bash
GRE Tunnel
  └─ Crypto Map
       ├─ Transform Set        (ESP parameters)
       ├─ Peer                 (remote IP)
       ├─ ACL (Interesting traffic)
       └─ ISAKMP / IKE Policy
            └─ Keyring / PSK
```

### 11.3 IPSec with Crypto Map

IKEv1 - Can be IKEv2

```bash
Interface
  └─ Crypto Map
       ├─ ACL (interesting traffic)
       ├─ Peer
       ├─ Transform Set
       └─ IKE / ISAKMP Policy
            └─ Keyring / PSK
```

### 11.4 IPSec + GRE - IPSec profile

IKEv2 - can be IKEv1

```bash
GRE Tunnel
  └─ Tunnel Protection
       └─ IPsec Profile
            ├─ Transform Set
            └─ IKEv2 Profile
                 └─ Keyring
IKEv2 Policy
  └─ Proposal
```

## 12 Design

* Use IKEv2 Whenever Possible
* Avoid IKEv1 Aggressive Mode
* Use Strong Cryptography
* Enable Perfect Forward Secrecy
* Account for IPsec Overhead (MTU Design)i
* Avoid single-point VPN gateways: Active/Passive firewall clustering, Active/Active VPN gateways, Multiple tunnels with routing failover
* Use Route-Based VPNs
* Use Dynamic Routing Across VPN
* Avoid Large Proxy-ID Lists
* Design for Redundancy
  * Two ISPs if possible
  * Separate physical paths
  * Dynamic routing failover

```bash
Branch
   | \
   |  \
VPN1  VPN2
   |     |
DC1   DC2
```

* Prefer certificates over pre-shared keys in RA
* Integrate Multi-Factor Authentication in RA

**Recommended IKE settings**

* Phase 1
  * IKE version - IKEv2
  * Lifetime - S2S: 8 hours (28800 seconds) or 86400 seconds (24 hours) - IKEv2 handles rekeying much more gracefully - So aggressive lifetimes are safer in IKEv2 than IKEv1 - RA VPN: 8–24 hours - Avoid reauthentication prompts
  * Encryption Algorithms - AES-256-GCM
  * Integrity Algorithms - if not AEAD - SHA2-256
  * PRF Algorithms for IKEv2 - SHA2-256
  * DH group numbers - 14: minimum - 19: perfect
  * DPD time out seconds - 10
  * DPD retry - 5 for S2S - 3 for RA
* Phase 2
  * Life time - 3600 seconds (1 hour)
  * Encryption Algorithms - AES-256-GCM-16
  * Integrity Algorithms - HMAC-SHA2-256 - if not AEAD
  * DH Group numbers - 14: minimum - 19: perfect
  * Lifetime seconds -
  * PFS - Yes
  * S2S and RA are the same
