RFC 5996

Internet Key Exchange Protocol Version 2 (IKEv2)

📅 published September 2010, from ietf

Internet Key Exchange Protocol Version 2 (IKEv2) 💖

Part 1 of 33 🎀 okay bestie, more parts are coming, so don't go anywhere!

Let's start with the title block, because it's already giving main character energy 💅

  • Title: Internet Key Exchange Protocol Version 2 (IKEv2) ✨
  • RFC number: 5996 🦋
  • Authors: C. Kaufman (Microsoft), P. Hoffman (VPN Consortium), Y. Nir (Check Point), and P. Eronen (Independent) 🫶
  • Category: Standards Track 👑
  • Date: September 2010 🌸
  • ISSN: 2070-1721
  • Obsoletes: RFC 4306 and RFC 4718 💀

Abstract ✨

Okay so this doc describes version 2 of the Internet Key Exchange (IKE) protocol 🔥 IKE is a part of IPsec, and its whole job is handling mutual authentication and setting up and keeping alive Security Associations (SAs) 🔐 This document replaces and updates RFC 4306, and it also rolls in all of the clarifications from RFC 4718. Iconic glow-up, honestly 🌈

Status of This Memo 📜

This is an Internet Standards Track document 🎀

This document is a product of the Internet Engineering Task Force (IETF) 🌷 It represents the consensus of the IETF community, and it went through public review before the Internet Engineering Steering Group (IESG) approved it for publication. If you want more info on Internet Standards, check out Section 2 of RFC 5741 📖

Want the current status of this document, any errata, or a way to send feedback? Go to http://www.rfc-editor.org/info/rfc5996 ✨

Copyright (c) 2010 IETF Trust and the persons identified as the document authors. All rights reserved 💜

This document is subject to BCP 78 and to the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info), as they stand on the date this document was published. Please read these carefully, because they spell out your rights and restrictions for this document 🙈 Any Code Components taken from this document must include the Simplified BSD License text, as described in Section 4.e of the Trust Legal Provisions, and they come with no warranty, as the Simplified BSD License describes 🍓

This document may include material from IETF Documents or IETF Contributions that were published or made publicly available before November 10, 2008 🧚 Some of the people who own the copyright in that material may not have given the IETF Trust permission to allow modifications outside the IETF Standards Process. So unless you get an adequate license from the people who control the copyright in those materials, this document may not be modified outside the IETF Standards Process, and derivative works of it may not be created outside that process. The one exceptions are formatting it for publication as an RFC and translating it into languages other than English 🦋

Table of Contents 📚

   1. Introduction ....................................................5
      1.1. Usage Scenarios ............................................6
           1.1.1. Security Gateway to Security Gateway in
                  Tunnel Mode .........................................7
           1.1.2. Endpoint-to-Endpoint Transport Mode .................7
           1.1.3. Endpoint to Security Gateway in Tunnel Mode .........8
           1.1.4. Other Scenarios .....................................9
      1.2. The Initial Exchanges ......................................9
      1.3. The CREATE_CHILD_SA Exchange ..............................13
           1.3.1. Creating New Child SAs with the
                  CREATE_CHILD_SA Exchange ...........................14
           1.3.2. Rekeying IKE SAs with the CREATE_CHILD_SA
                  Exchange ...........................................15
           1.3.3. Rekeying Child SAs with the CREATE_CHILD_SA
                  Exchange ...........................................16
      1.4. The INFORMATIONAL Exchange ................................17
           1.4.1. Deleting an SA with INFORMATIONAL Exchanges ........17
      1.5. Informational Messages outside of an IKE SA ...............18
      1.6. Requirements Terminology ..................................19
      1.7. Significant Differences between RFC 4306 and This
           Document ..................................................20
   2. IKE Protocol Details and Variations ............................22
      2.1. Use of Retransmission Timers ..............................23
      2.2. Use of Sequence Numbers for Message ID ....................24
      2.3. Window Size for Overlapping Requests ......................25
      2.4. State Synchronization and Connection Timeouts .............26
      2.5. Version Numbers and Forward Compatibility .................28
      2.6. IKE SA SPIs and Cookies ...................................30
           2.6.1. Interaction of COOKIE and INVALID_KE_PAYLOAD .......33
      2.7. Cryptographic Algorithm Negotiation .......................34
      2.8. Rekeying ..................................................34
           2.8.1. Simultaneous Child SA Rekeying .....................36
           2.8.2. Simultaneous IKE SA Rekeying .......................39
           2.8.3. Rekeying the IKE SA versus Reauthentication ........40
      2.9. Traffic Selector Negotiation ..............................40
           2.9.1. Traffic Selectors Violating Own Policy .............43
      2.10. Nonces ...................................................44
      2.11. Address and Port Agility .................................44
      2.12. Reuse of Diffie-Hellman Exponentials .....................44
      2.13. Generating Keying Material ...............................45
      2.14. Generating Keying Material for the IKE SA ................46
      2.15. Authentication of the IKE SA .............................47
      2.16. Extensible Authentication Protocol Methods ...............50
      2.17. Generating Keying Material for Child SAs .................52
      2.18. Rekeying IKE SAs Using a CREATE_CHILD_SA Exchange ........53
      2.19. Requesting an Internal Address on a Remote Network .......53
      2.20. Requesting the Peer's Version ............................55
      2.21. Error Handling ...........................................56
           2.21.1. Error Handling in IKE_SA_INIT .....................56
           2.21.2. Error Handling in IKE_AUTH ........................57
           2.21.3. Error Handling after IKE SA is Authenticated ......58
           2.21.4. Error Handling Outside IKE SA .....................58
      2.22. IPComp ...................................................59
      2.23. NAT Traversal ............................................60
           2.23.1. Transport Mode NAT Traversal ......................64
      2.24. Explicit Congestion Notification (ECN) ...................68
      2.25. Exchange Collisions ......................................68
           2.25.1. Collisions while Rekeying or Closing Child SAs ....69
           2.25.2. Collisions while Rekeying or Closing IKE SAs ......69
   3. Header and Payload Formats .....................................69
      3.1. The IKE Header ............................................70
      3.2. Generic Payload Header ....................................73
      3.3. Security Association Payload ..............................75
           3.3.1. Proposal Substructure ..............................78
           3.3.2. Transform Substructure .............................79
           3.3.3. Valid Transform Types by Protocol ..................82
           3.3.4. Mandatory Transform IDs ............................83
           3.3.5. Transform Attributes ...............................84
           3.3.6. Attribute Negotiation ..............................86
      3.4. Key Exchange Payload ......................................87
      3.5. Identification Payloads ...................................87
      3.6. Certificate Payload .......................................90
      3.7. Certificate Request Payload ...............................93
      3.8. Authentication Payload ....................................95
      3.9. Nonce Payload .............................................96
      3.10. Notify Payload ...........................................97
           3.10.1. Notify Message Types ..............................98
      3.11. Delete Payload ..........................................101
      3.12. Vendor ID Payload .......................................102
      3.13. Traffic Selector Payload ................................103
           3.13.1. Traffic Selector .................................105
      3.14. Encrypted Payload .......................................107
      3.15. Configuration Payload ...................................109
           3.15.1. Configuration Attributes .........................110
           3.15.2. Meaning of INTERNAL_IP4_SUBNET and
                   INTERNAL_IP6_SUBNET ..............................113
           3.15.3. Configuration Payloads for IPv6 ..................115
           3.15.4. Address Assignment Failures ......................116
      3.16. Extensible Authentication Protocol (EAP) Payload ........117
   4. Conformance Requirements ......................................118
   5. Security Considerations .......................................120
      5.1. Traffic Selector Authorization ...........................123
   6. IANA Considerations ...........................................124
   7. Acknowledgements ..............................................125
   8. References ....................................................126
      8.1. Normative References .....................................126
      8.2. Informative References ...................................127
   Appendix A. Summary of Changes from IKEv1 ........................132
   Appendix B. Diffie-Hellman Groups ................................133
     B.1. Group 1 - 768-bit MODP ....................................133
     B.2. Group 2 - 1024-bit MODP ...................................133
   Appendix C.  Exchanges and Payloads ..............................134
     C.1. IKE_SA_INIT Exchange  .....................................134
     C.2. IKE_AUTH Exchange without EAP .............................135
     C.3. IKE_AUTH Exchange with EAP  ...............................136
     C.4. CREATE_CHILD_SA Exchange for Creating or Rekeying
          Child SAs .................................................137
     C.5. CREATE_CHILD_SA Exchange for Rekeying the IKE SA ..........137
     C.6. INFORMATIONAL Exchange ....................................137

1. Introduction ✨

okay bestie, so IP Security (IPsec) gives IP datagrams confidentiality, data integrity, access control, and data source authentication 🔐. the way it pulls this off is by keeping shared state between the source and the sink of a datagram 🫶. that state decides the specific services for the datagram, which cryptographic algorithms get used, and the keys that feed those algorithms 💅.

setting up that shared state by hand does not scale well 😭, so we need a protocol that builds it dynamically. enter the Internet Key Exchange (IKE) 👑, which this document describes. IKEv1 was defined in RFCs 2407 [DOI], 2408 [ISAKMP], and 2409 [IKEV1]. IKEv2 replaced all of those RFCs ✨. IKEv2 was defined in [IKEV2] (RFC 4306) and clarified in [Clarif] (RFC 4718). this document replaces and updates RFC 4306 and RFC 4718. ngl IKEv2 was not backward compatible, but this doc only clarifies IKEv2 and makes minimum changes to the IKE protocol 🦋. the significant differences between RFC 4306 and this document are listed in Section 1.7.

IKE does mutual authentication between two parties and sets up an IKE security association (SA) 🎀. that SA holds shared secret information that can be used to efficiently set up SAs for Encapsulating Security Payload (ESP) [ESP] or Authentication Header (AH) [AH], plus a set of cryptographic algorithms those SAs use to protect the traffic they carry. in this doc, "suite" or "cryptographic suite" means a complete set of algorithms used to protect an SA. an initiator proposes one or more suites by listing supported algorithms that can be mixed and matched into suites 🌈. IKE can also negotiate IP Compression (IPComp) [IP-COMP] alongside an ESP or AH SA. the SAs for ESP or AH that get set up through that IKE SA are what we call "Child SAs" 🧚.

All IKE communications are pairs of messages: a request and a response 💖. the pair is called an "exchange", and is sometimes called a "request/response pair". the first exchanges that establish an IKE SA are called IKE_SA_INIT and IKE_AUTH, and later ones are CREATE_CHILD_SA or INFORMATIONAL. usually there's one IKE_SA_INIT and one IKE_AUTH (four messages total) to set up the IKE SA and the first Child SA 🍓. in exceptional cases there can be more than one of each. but in every case, all IKE_SA_INIT exchanges MUST complete before any other exchange type, then all IKE_AUTH exchanges MUST complete, and after that any number of CREATE_CHILD_SA and INFORMATIONAL exchanges can happen in any order. in some scenarios only a single Child SA is needed between the IPsec endpoints, so there are no additional exchanges 🙈. subsequent exchanges MAY be used to set up additional Child SAs between the same authenticated pair of endpoints and to do housekeeping functions.

An IKE message flow always consists of a request followed by a response. it's the requester's responsibility to ensure reliability. if the response doesn't arrive within a timeout interval, the requester needs to retransmit the request (or abandon the connection) 😬.

the first exchange of an IKE session, IKE_SA_INIT, negotiates security parameters for the IKE SA, sends nonces, and sends Diffie-Hellman values 🌸.

the second exchange, IKE_AUTH, transmits identities, proves knowledge of the secrets corresponding to the two identities, and sets up an SA for the first (and often only) AH or ESP Child SA. (unless there's a failure setting up that AH or ESP Child SA, in which case the IKE SA is still established without the Child SA) 💅.

the types of subsequent exchanges are CREATE_CHILD_SA (which creates a Child SA) and INFORMATIONAL (which deletes an SA, reports error conditions, or does other housekeeping). every request requires a response ✨. an INFORMATIONAL request with no payloads (other than the empty Encrypted payload required by the syntax) is commonly used as a check for liveness 💜. these subsequent exchanges can't be used until the initial exchanges have completed.

in the description that follows, we assume that no errors occur. changes to the flow when errors do happen are described in Section 2.21 ⚠️

1.1. Usage Scenarios

IKE is used to negotiate ESP or AH SAs in a number of different scenarios, each with its own special requirements 🦋.

1.1.1. Security Gateway to Security Gateway in Tunnel Mode

                +-+-+-+-+-+            +-+-+-+-+-+
                |         | IPsec      |         |
   Protected    |Tunnel   | tunnel     |Tunnel   |     Protected
   Subnet   <-->|Endpoint |<---------->|Endpoint |<--> Subnet
                |         |            |         |
                +-+-+-+-+-+            +-+-+-+-+-+

Figure 1: Security Gateway to Security Gateway Tunnel

in this scenario, neither endpoint of the IP connection implements IPsec, but network nodes between them protect traffic for part of the way 🚪. the protection is transparent to the endpoints, and depends on ordinary routing to send packets through the tunnel endpoints for processing. each endpoint would announce the set of addresses "behind" it, and packets would be sent in tunnel mode, where the inner IP header contains the IP addresses of the actual endpoints 🧭.

1.1.2. Endpoint-to-Endpoint Transport Mode

   +-+-+-+-+-+                                          +-+-+-+-+-+
   |         |                 IPsec transport          |         |
   |Protected|                or tunnel mode SA         |Protected|
   |Endpoint |<---------------------------------------->|Endpoint |
   |         |                                          |         |
   +-+-+-+-+-+                                          +-+-+-+-+-+

Figure 2: Endpoint to Endpoint

in this scenario, both endpoints of the IP connection implement IPsec, as required of hosts in [IPSECARCH] 💻. transport mode will commonly be used with no inner IP header. a single pair of addresses will be negotiated for packets protected by this SA. these endpoints MAY implement application-layer access controls based on the IPsec authenticated identities of the participants 🔑. this scenario enables the end-to-end security that has been a guiding principle for the Internet since [ARCHPRINC], [TRANSPARENCY], and a method of limiting the inherent problems with complexity in networks noted by [ARCHGUIDEPHIL]. it's giving principled 🧠. although this scenario may not be fully applicable to the IPv4 Internet, it has been deployed successfully in specific scenarios within intranets using IKEv1. it should be more broadly enabled during the transition to IPv6 and with the adoption of IKEv2 🚀.

it's possible in this scenario that one or both of the protected endpoints will be behind a network address translation (NAT) node. if so, the tunneled packets will have to be UDP encapsulated so that port numbers in the UDP headers can be used to identify individual endpoints "behind" the NAT (see Section 2.23) 🎀.

1.1.3. Endpoint to Security Gateway in Tunnel Mode

   +-+-+-+-+-+                          +-+-+-+-+-+
   |         |         IPsec            |         |     Protected
   |Protected|         tunnel           |Tunnel   |     Subnet
   |Endpoint |<------------------------>|Endpoint |<--- and/or
   |         |                          |         |     Internet
   +-+-+-+-+-+                          +-+-+-+-+-+

Figure 3: Endpoint to Security Gateway Tunnel

in this scenario, a protected endpoint (typically a portable roaming computer) connects back to its corporate network through an IPsec-protected tunnel 💼. it might use this tunnel only to access information on the corporate network, or it might tunnel all of its traffic back through the corporate network to take advantage of the protection a corporate firewall provides against Internet-based attacks 🛡️. either way, the protected endpoint will want an IP address associated with the security gateway, so that packets returned to it go to the security gateway and get tunneled back. this IP address may be static or may be dynamically allocated by the security gateway. for that latter case, IKEv2 includes a mechanism (namely, configuration payloads) for the initiator to request an IP address owned by the security gateway for use for the duration of its SA 🫶.

in this scenario, packets use tunnel mode. on each packet from the protected endpoint, the outer IP header contains the source IP address associated with its current location (i.e., the address that will get traffic routed to the endpoint directly), while the inner IP header contains the source IP address assigned by the security gateway (i.e., the address that will get traffic routed to the security gateway for forwarding to the endpoint). the outer destination address is always that of the security gateway, while the inner destination address is the ultimate destination for the packet 📦.

in this scenario, it's possible the protected endpoint will be behind a NAT. in that case, the IP address seen by the security gateway won't be the same as the IP address sent by the protected endpoint, and packets will have to be UDP encapsulated to be routed properly. interaction with NATs is covered in detail in Section 2.23 🌐.

1.1.4. Other Scenarios

other scenarios are possible, as are nested combinations of the above 🌈. one notable example combines aspects of Sections 1.1.1 and 1.1.3. a subnet may make all external accesses through a remote security gateway using an IPsec tunnel, where the addresses on the subnet are routed to the security gateway by the rest of the Internet 🌸. an example would be someone's home network being virtually on the Internet with static IP addresses, even though connectivity is provided by an ISP that assigns a single dynamically assigned IP address to the user's security gateway (where the static IP addresses and an IPsec relay are provided by a third party located elsewhere) 🏠✨.

1.2. The Initial Exchanges ✨

Okay bestie, so talking over IKE always starts with two exchanges, IKE_SA_INIT and IKE_AUTH (called Phase 1 back in IKEv1 💅). Usually that's four messages total, but sometimes the number grows 📈. Everything in IKE is request/response pairs 🫶. We'll do the basic version first and then the variations. The first pair (IKE_SA_INIT) picks the crypto algorithms, swaps nonces, and does a Diffie-Hellman exchange [DH] 🌸.

The second pair (IKE_AUTH) is where the vibes get serious 😭. It authenticates everything that came before, swaps identities and certificates, and sets up the first Child SA. Most of it is encrypted and integrity protected with keys from IKE_SA_INIT, so eavesdroppers can't see who's talking and every field gets authenticated 🔒. See Section 2.14 for how those encryption keys get made. (Sneaky note: a man-in-the-middle who can't finish IKE_AUTH can still see the initiator's identity 👀.)

Everything after the initial exchange is cryptographically protected with the algorithms and keys from IKE_SA_INIT 🦋. These later messages use the Encrypted payload syntax from Section 3.14, encrypted with keys derived the way Section 2.14 describes. Every later message has an Encrypted payload, even the ones the text calls "empty" 🙈. For CREATE_CHILD_SA, IKE_AUTH, or INFORMATIONAL exchanges, the stuff after the header gets encrypted, and the message including the header gets integrity protected using the algorithms negotiated for the IKE SA 💜.

Every IKE message has a Message ID in its fixed header 🎀. That's how requests and responses get matched up, and how retransmissions get spotted 🔁.

When we describe messages below, the payloads get shown by these names 📋:

Notation    Payload
-----------------------------------------
AUTH        Authentication
CERT        Certificate
CERTREQ     Certificate Request
CP          Configuration
D           Delete
EAP         Extensible Authentication
HDR         IKE header (not a payload)
IDi         Identification - Initiator
IDr         Identification - Responder
KE          Key Exchange
Ni, Nr      Nonce
N           Notify
SA          Security Association
SK          Encrypted and Authenticated
TSi         Traffic Selector - Initiator
TSr         Traffic Selector - Responder
V           Vendor ID

The nitty-gritty of each payload lives in section 3 🧚. Payloads that might show up optionally get wrapped in brackets, like [CERTREQ], which just means a Certificate Request payload can optionally be included 🍓.

Here are the initial exchanges 💖:

   Initiator                         Responder
   -------------------------------------------------------------------
   HDR, SAi1, KEi, Ni  -->

                                <--  HDR, SAr1, KEr, Nr, [CERTREQ]

   HDR, SK {IDi, [CERT,] [CERTREQ,]
       [IDr,] AUTH, SAi2,
       TSi, TSr}  -->

                                <--  HDR, SK {IDr, [CERT,] AUTH,
                                         SAr2, TSi, TSr}

The first message is HDR, SAi1, KEi, Ni. HDR holds the Security Parameter Indexes (SPIs), version numbers, and assorted flags 🏷️. SAi1 lists the crypto algorithms the initiator supports for the IKE SA 🔐. KEi carries the initiator's Diffie-Hellman value, and Ni is the initiator's nonce 🌈.

The responder picks one crypto suite out of what the initiator offered and writes it in SAr1 👑. It finishes the Diffie-Hellman exchange with KEr, and sends its nonce in Nr ✨.

Once that's done, both sides can make SKEYSEED, and every key for this IKE SA gets derived from it 🗝️. Everything after that is encrypted and integrity protected in its entirety, except the message headers 🛡️. The encryption and integrity keys come from SKEYSEED and are called SK_e (encryption) and SK_a (authentication, a.k.a. integrity protection). See Sections 2.13 and 2.14 for the key derivation details 💅. There's a separate SK_e and SK_a for each direction 🦋. On top of the SK_e and SK_a used to protect the IKE SA, there's another value called SK_d, which is used to derive more keying material for Child SAs 🌸. The notation SK { ... } means those payloads are encrypted and integrity protected with that direction's SK_e and SK_a 🔒.

The initiator sends its identity in IDi and proves it knows the secret tied to IDi 🪪. It also integrity protects the first message with the AUTH payload (see Section 2.15) 💜. It can attach its certificate(s) in CERT payload(s) and a list of its trust anchors in CERTREQ payload(s) 📜. If any CERT payloads show up, the first certificate provided MUST contain the public key used to verify the AUTH field 🔑.

The optional IDr payload lets the initiator say which of the responder's identities it wants to talk to 🎯. This comes in handy when the responder's machine hosts several identities on the same IP address 🏠. If the responder doesn't accept the IDr the initiator proposed, it might finish the exchange using some other IDr 🤷‍♀️. If the initiator then doesn't accept that the responder used a different IDr than the one requested, the initiator can close the SA once it notices 🚪.

The Traffic Selectors (TSi and TSr) get their own discussion in Section 2.9 🚦.

The initiator starts negotiating a Child SA with the SAi2 payload 🧚. The rest of the fields (starting at SAi2) get covered in the CREATE_CHILD_SA exchange description 📖.

The responder reveals its identity in IDr and can optionally send one or more certificates (again, the one with the public key used to verify AUTH goes first) 🎀. It authenticates itself and protects the second message's integrity with the AUTH payload 🛡️. It also finishes negotiating a Child SA using the extra fields described in the CREATE_CHILD_SA exchange 🌟.

Both parties in the IKE_AUTH exchange MUST verify that all signatures and Message Authentication Codes (MACs) are computed correctly 🔍. If either side uses a shared secret for authentication, the names in the ID payload MUST correspond to the key used to generate the AUTH payload 🗝️. No sloppy matching allowed, periodt 💅.

Here's a tricky bit 🙃. The initiator sends its Diffie-Hellman value in IKE_SA_INIT, so it has to guess which Diffie-Hellman group the responder will pick from its list of supported groups 🎲. If the guess is wrong, the responder replies with a Notify payload of type INVALID_KE_PAYLOAD that names the group it wants 🙈. In that case, the initiator MUST retry IKE_SA_INIT with the corrected Diffie-Hellman group 🔁. The initiator MUST also propose its full set of acceptable cryptographic suites again 🫶. Why? Because that rejection message isn't authenticated yet, so an active attacker could trick both endpoints into agreeing on a weaker suite instead of a stronger one they both prefer 😤. Not on my watch 🛡️.

If creating the Child SA during IKE_AUTH fails for some reason, the IKE SA still gets created as usual 🎉. Notify types that do NOT stop the IKE SA from being set up include at least these: NO_PROPOSAL_CHOSEN, TS_UNACCEPTABLE, SINGLE_PAIR_REQUIRED, INTERNAL_ADDRESS_FAILURE, and FAILED_CP_REQUIRED 📝.

If the failure is about creating the IKE SA itself (like an AUTHENTICATION_FAILED Notify error), then the IKE SA doesn't get created 🚫. Heads up though: even though IKE_AUTH messages are encrypted and integrity protected, if the peer getting that error hasn't authenticated the other end yet (or fails to for some reason), it has to treat the info with caution ⚠️. More precisely, if the MAC checks out, the sender of the error Notify is known to be the responder from IKE_SA_INIT, but its identity can't be assured 🕵️.

Quick reminder: IKE_AUTH messages don't carry KEi/KEr or Ni/Nr payloads 📌. So the SA payloads in IKE_AUTH can't include Transform Type 4 (Diffie-Hellman group) with any value besides NONE. Implementations SHOULD omit the whole transform substructure instead of sending value NONE 💜.

1.3. The CREATE_CHILD_SA Exchange 🦋

The CREATE_CHILD_SA exchange is for making new Child SAs and rekeying both IKE SAs and Child SAs 🔄. It's one request/response pair, and part of what it does used to be called a Phase 2 exchange in IKEv1 🌸. Either end of the IKE SA MAY start it once the initial exchanges are done ✨.

Rekeying an SA means making a new SA and then deleting the old one 🗑️. This section covers the first half (creating the new SAs). Section 2.8 covers the rest, like moving traffic from old SAs to new ones and deleting the old SAs 🚚. You have to read both sections together to get the full rekeying picture 👯‍♀️.

Either endpoint can start a CREATE_CHILD_SA exchange, so in this section "initiator" just means whoever started this exchange 🫵. An implementation MAY refuse all CREATE_CHILD_SA requests within an IKE SA 🙅‍♀️.

The CREATE_CHILD_SA request MAY optionally include a KE payload for an extra Diffie-Hellman exchange, which gives stronger forward secrecy guarantees for the Child SA 🔐. The keying material for the Child SA is a function of SK_d (from when the IKE SA was set up), the nonces swapped during CREATE_CHILD_SA, and the Diffie-Hellman value (if KE payloads are in the exchange) 🧁.

If a CREATE_CHILD_SA exchange includes a KEi payload, at least one of the SA offers MUST include the Diffie-Hellman group of the KEi 🎀. The Diffie-Hellman group of the KEi MUST be an element of the group the initiator expects the responder to accept (you're allowed to propose extra Diffie-Hellman groups too) 💅. If the responder picks a proposal with a different Diffie-Hellman group (other than NONE), the responder MUST reject the request and name its preferred group in the INVALID_KE_PAYLOAD Notify payload 🚫. That notification carries two octets of data: the accepted Diffie-Hellman group number, in big endian order 🔢. When that rejection happens, the CREATE_CHILD_SA exchange fails, and the initiator will probably retry it with a Diffie-Hellman proposal and a KEi in the group the responder named in INVALID_KE_PAYLOAD 🔁.

The responder sends a NO_ADDITIONAL_SAS notification when it's not accepting any more Child SAs on this IKE SA 🙅‍♀️. The responder is basically saying "no thanks, I'm full" 💀. This notification can also reject an IKE SA rekey 🔄. Some minimal implementations might only accept one Child SA setup during the initial IKE exchange and reject any later attempts to add more 🧚‍♀️.

1.3.1. Creating New Child SAs with the CREATE_CHILD_SA Exchange ✨

okay so a Child SA can be made by sending a CREATE_CHILD_SA request 💅 the request for creating a new Child SA looks like this:

   Initiator                         Responder
   -------------------------------------------------------------------
   HDR, SK {SA, Ni, [KEi],
              TSi, TSr}  -->

the initiator sends SA offer(s) in the SA payload 🎀, a nonce in the Ni payload, optionally a Diffie-Hellman value in the KEi payload, and the proposed Traffic Selectors for the proposed Child SA in the TSi and TSr payloads 🦋

the CREATE_CHILD_SA response for creating a new Child SA is:

                                <--  HDR, SK {SA, Nr, [KEr],
                                         TSi, TSr}

the responder replies (using the same Message ID to respond) with the accepted offer in an SA payload 💖, and a Diffie-Hellman value in the KEr payload if KEi was included in the request and the selected cryptographic suite includes that group.

the Traffic Selectors for traffic to be sent on that SA are specified in the TS payloads in the response 🌸, and they may be a subset of what the initiator of the Child SA proposed. not everything gets approved, bestie 😭

the USE_TRANSPORT_MODE notification MAY be included in a request message that also includes an SA payload requesting a Child SA. it asks for transport mode instead of tunnel mode for the SA being created 🧚 if the request is accepted, the response MUST also include a notification of type USE_TRANSPORT_MODE. if the responder declines, the Child SA will be established in tunnel mode. if that's unacceptable to the initiator, the initiator MUST delete the SA.

ngl, the one exception: except when using this option to negotiate transport mode, all Child SAs will use tunnel mode 🙈

the ESP_TFC_PADDING_NOT_SUPPORTED notification says the sending endpoint will not accept packets that contain Traffic Flow Confidentiality (TFC) padding over the Child SA being negotiated 🍓 if neither endpoint accepts TFC padding, this notification shows up in both the request and the response. if it's only in one of the messages, TFC padding can still be sent in the other direction.

the NON_FIRST_FRAGMENTS_ALSO notification is used for fragmentation control. check [IPSECARCH] for the full tea ☕ both parties need to agree to sending non-first fragments before either party does so. it's only enabled if NON_FIRST_FRAGMENTS_ALSO is included in both the request proposing an SA and the response accepting it. if the responder doesn't want to send or receive non-first fragments, it just leaves NON_FIRST_FRAGMENTS_ALSO out of its response, but it does not reject the whole Child SA creation. main character energy, but make it reasonable 💅

an IPCOMP_SUPPORTED notification, covered in Section 2.22, can also be included in the exchange 🌈

a failed attempt to create a Child SA SHOULD NOT tear down the IKE SA. there's no reason to lose the work done to set up the IKE SA 🫶 see Section 2.21 for a list of error messages that might pop up if creating a Child SA fails.

1.3.2. Rekeying IKE SAs with the CREATE_CHILD_SA Exchange 🔥

the CREATE_CHILD_SA request for rekeying an IKE SA is:

   Initiator                         Responder
   -------------------------------------------------------------------
   HDR, SK {SA, Ni, KEi} -->

the initiator sends SA offer(s) in the SA payload, a nonce in the Ni payload, and a Diffie-Hellman value in the KEi payload 🦋 the KEi payload MUST be included. a new initiator SPI goes in the SPI field of the SA payload. once a peer gets a request to rekey an IKE SA, or sends one, it SHOULD NOT start any new CREATE_CHILD_SA exchanges on the IKE SA that's being rekeyed. no overlapping drama 🙅‍♀️

the CREATE_CHILD_SA response for rekeying an IKE SA is:

                                <--  HDR, SK {SA, Nr, KEr}

the responder replies (using the same Message ID to respond) with the accepted offer in an SA payload, and a Diffie-Hellman value in the KEr payload if the selected cryptographic suite includes that group 💜 a new responder SPI goes in the SPI field of the SA payload.

the new IKE SA has its message counters set to 0, no matter what they were on the earlier IKE SA 🧚 the first IKE requests from both sides on the new IKE SA will have Message ID 0. the old IKE SA keeps its numbering, so any further requests (like deleting the IKE SA) will have consecutive numbering. the new IKE SA also has its window size reset to 1, and the initiator of this rekey exchange becomes the new "original initiator" of the new IKE SA 👑

Section 2.18 also covers IKE SA rekeying in detail 📖

1.3.3. Rekeying Child SAs with the CREATE_CHILD_SA Exchange 🦋

the CREATE_CHILD_SA request for rekeying a Child SA is:

   Initiator                         Responder
   -------------------------------------------------------------------
   HDR, SK {N(REKEY_SA), SA, Ni, [KEi],
       TSi, TSr}   -->

the initiator sends SA offer(s) in the SA payload, a nonce in the Ni payload, optionally a Diffie-Hellman value in the KEi payload, and the proposed Traffic Selectors for the proposed Child SA in the TSi and TSr payloads 💅

the notifications described in Section 1.3.1 may also be sent in a rekeying exchange 🌸 usually these are the same notifications that were used in the original exchange. for example, when rekeying a transport mode SA, the USE_TRANSPORT_MODE notification will be used.

the REKEY_SA notification MUST be included in a CREATE_CHILD_SA exchange if the purpose of the exchange is to replace an existing ESP or AH SA. the SA being rekeyed is identified by the SPI field in the Notify payload. this is the SPI the exchange initiator would expect in inbound ESP or AH packets 🎀 there is no data associated with this Notify message type. the Protocol ID field of the REKEY_SA notification is set to match the protocol of the SA being rekeyed, for example, 3 for ESP and 2 for AH.

the CREATE_CHILD_SA response for rekeying a Child SA is:

                                <--  HDR, SK {SA, Nr, [KEr],
                                         TSi, TSr}

the responder replies (using the same Message ID to respond) with the accepted offer in an SA payload, and a Diffie-Hellman value in the KEr payload if KEi was included in the request and the selected cryptographic suite includes that group ✨

the Traffic Selectors for traffic to be sent on that SA are specified in the TS payloads in the response, and they may be a subset of what the initiator of the Child SA proposed 🫶

1.4. The INFORMATIONAL Exchange 💬

at various points while an IKE SA is running, peers may want to send each other control messages about errors or notifications of certain events 🔥 so IKE defines an INFORMATIONAL exchange for that. INFORMATIONAL exchanges MUST ONLY occur after the initial exchanges, and they are cryptographically protected with the negotiated keys 🔐 some informational messages (not exchanges) can be sent outside the context of an IKE SA, so keep that in mind. Section 2.21 also covers error messages in great detail 🙈

control messages that pertain to an IKE SA MUST be sent under that IKE SA. control messages that pertain to Child SAs MUST be sent under the protection of the IKE SA that generated them (or its successor if the IKE SA was rekeyed) 🧚

messages in an INFORMATIONAL exchange contain zero or more Notification, Delete, and Configuration payloads. the recipient of an INFORMATIONAL exchange request MUST send some response. otherwise, the sender will assume the message got lost in the network and will retransmit it 😭 that response MAY be an empty message. the request message in an INFORMATIONAL exchange MAY also contain no payloads. this is the expected way one endpoint can ask the other to check that it's still alive 💖

the INFORMATIONAL exchange is defined as:

   Initiator                         Responder
   -------------------------------------------------------------------
   HDR, SK {[N,] [D,]
       [CP,] ...}  -->
                                <--  HDR, SK {[N,] [D,]
                                         [CP], ...}

the processing of an INFORMATIONAL exchange is determined by its component payloads 🌈

1.4.1. Deleting an SA with INFORMATIONAL Exchanges 🗑️

ESP and AH SAs always exist in pairs, with one SA in each direction 🦋 when an SA is closed, both members of the pair MUST be closed (that is, deleted). each endpoint MUST close its incoming SAs and allow the other endpoint to close the other SA in each pair. to delete an SA, an INFORMATIONAL exchange with one or more Delete payloads is sent, listing the SPIs (as they'd be expected in the headers of inbound packets) of the SAs to be deleted. the recipient MUST close the designated SAs. one never sends Delete payloads for the two sides of an SA in a single message 🙅‍♀️ if there are many SAs to delete at the same time, one includes Delete payloads for the inbound half of each SA pair in the INFORMATIONAL exchange.

normally, the response in the INFORMATIONAL exchange will contain Delete payloads for the paired SAs going in the other direction. there is one exception 👀 if, by chance, both ends of a set of SAs independently decide to close them, each may send a Delete payload and the two requests may cross in the network. if a node receives a delete request for SAs it has already sent a delete request for, it MUST delete the outgoing SAs while processing the request and the incoming SAs while processing the response. in that case, the responses MUST NOT include Delete payloads for the deleted SAs, since that would result in duplicate deletion and could in theory delete the wrong SA 💀

similar to ESP and AH SAs, IKE SAs are also deleted by sending an Informational exchange. deleting an IKE SA implicitly closes any remaining Child SAs negotiated under it 🫶 the response to a request that deletes the IKE SA is an empty INFORMATIONAL response.

half-closed ESP or AH connections are anomalous 🚩 a node with auditing capability should probably audit their existence if they persist. note that this specification does not specify time periods, so it's up to individual endpoints to decide how long to wait ⏳ a node MAY refuse to accept incoming data on half-closed connections, but it MUST NOT unilaterally close them and reuse the SPIs. if connection state becomes sufficiently messed up, a node MAY close the IKE SA, as described above. it can then rebuild the SAs it needs on a clean base under a new IKE SA 🧼

1.5. Informational Messages outside of an IKE SA ✨

okay so sometimes a node gets a packet it literally cannot process 😭 but it might still wanna let the sender know something's off. there are three situations where this happens 🦋

  • If an ESP or AH packet arrives with an unrecognized SPI. This might be because the receiving node recently crashed and lost its state, or because of some other system malfunction or attack.
  • If an encrypted IKE request packet arrives on port 500 or 4500 with an unrecognized IKE SPI. This might be because the receiving node recently crashed and lost state, or because of some other system malfunction or attack.
  • If an IKE request packet arrives with a higher major version number than the implementation supports.

in the first case, if the receiving node has an active IKE SA to the IP address the packet came from, it MAY send an INVALID_SPI notification about the wayward packet over that IKE SA, inside an INFORMATIONAL exchange. the Notification Data holds the SPI of the invalid packet. the recipient can't tell whether that SPI is for AH or ESP, and that's totally fine because the two are supposed to have different SPIs anyway 💅. if there's no suitable IKE SA, the node MAY send an informational message with no cryptographic protection to the source IP address. if the packet was UDP (UDP-encapsulated ESP or AH), it uses the source UDP port as the destination port. here's the tea: this one should only be used by the recipient as a hint that something might be wrong, because it could easily be forged 🙈. this message isn't part of an INFORMATIONAL exchange, and the receiving node MUST NOT respond to it, because replying could cause a message loop 🔁. the message gets built like this: there are no IKE SPI values that would be meaningful to the recipient, so using zero values or random values are both acceptable. that's the exception to the rule in Section 3.1 that prohibits zero IKE Initiator SPIs. the Initiator flag is set to 1, the Response flag is set to 0, and the version flags are set in the normal fashion. you can read about those flags in Section 3.1 🎀

in the second and third cases, the message is always sent without cryptographic protection (outside of an IKE SA), and includes either an INVALID_IKE_SPI or an INVALID_MAJOR_VERSION notification (with no notification data). it's a response message, so it's sent to the IP address and port it came from, with the same IKE SPIs. the Message ID and Exchange Type get copied from the request. the Response flag is set to 1, and the version flags are set in the normal fashion ✨


1.6. Requirements Terminology 🧚

definitions of the primitive terms in this document (like Security Association or SA) can be found in [IPSECARCH]. it's worth noting that parts of IKEv2 rely on some of the processing rules in [IPSECARCH], as described in various sections of this document 💜

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [MUSTSHOULD].


1.7. Significant Differences between RFC 4306 and This Document 🌸

this document contains clarifications and amplifications to IKEv2 [IKEV2]. a lot of the clarifications are based on [Clarif]. the changes listed in that document were discussed in the IPsec Working Group and, after the Working Group was disbanded, on the IPsec mailing list. that document has detailed explanations of areas that were unclear in IKEv2, so it's super useful for IKEv2 implementers 🤓

the protocol described in this document keeps the same major version number (2) and minor version number (0) as RFC 4306 used. that means the version number is not changed from RFC 4306. the small number of technical changes listed here aren't expected to affect RFC 4306 implementations that were already deployed when this document was published 🫶

this document makes the figures and references a bit more consistent than they were in [IKEV2] 💅

IKEv2 developers have noted that the SHOULD-level requirements in RFC 4306 are often unclear, because they don't say when it's OK to not obey them. they've also noted that there are MUST-level requirements that aren't related to interoperability. this document explains some of these requirements more. All non-capitalized uses of the words SHOULD and MUST now mean their normal English sense, not the interoperability sense of [MUSTSHOULD] 😭

IKEv2 (and IKEv1) developers have noted that there's a great deal of material in the tables of codes in Section 3.10.1 in RFC 4306. this leads to implementers not having all the info they need in the main body of the document. a lot of the material from those tables has been moved into the associated parts of the main body of the document 📚

this document removes discussion of nesting AH and ESP. that was a mistake in RFC 4306, caused by the lag between finishing RFC 4306 and RFC 4301. basically, IKEv2 is based on RFC 4301, which doesn't include "SA bundles" that were part of RFC 2401. while a single packet can go through IPsec processing multiple times, each of these passes uses a separate SA, and the passes are coordinated by the forwarding tables. in IKEv2, each of these SAs has to be created using a separate CREATE_CHILD_SA exchange 🧩

this document removes discussion of the INTERNAL_ADDRESS_EXPIRY configuration attribute because its implementation was very problematic. Implementations that conform to this document MUST ignore proposals that have configuration attribute type 5, the old value for INTERNAL_ADDRESS_EXPIRY. this document also removed INTERNAL_IP6_NBNS as a configuration attribute 🗑️

this document removes the allowance for rejecting messages in which the payloads were not in the "right" order. now implementations MUST NOT reject them. this is because it wasn't clear where the orders for the payloads were described 🙄

the lists of items from RFC 4306 that ended up in the IANA registry were trimmed to only include items that were actually defined in RFC 4306. also, many of those lists now come with a very important instruction for developers: they really should look at the IANA registry at the time of development, because new items have been added since RFC 4306 🌈

this document adds clarification on when notifications are and aren't sent encrypted, depending on the state of the negotiation at the time 🔐

this document discusses more about how to negotiate combined-mode ciphers 🍓

in Section 1.3.2, "The KEi payload SHOULD be included" was changed to be "The KEi payload MUST be included". this also led to changes in Section 2.18 ✨

in Section 2.1, there's new material covering how the initiator's SPI and/or IP is used to tell if this is a "half-open" IKE SA or a new request 🦋

this document clarifies the use of the critical flag in Section 2.5 🎀

in Section 2.8, "Note that, when rekeying, the new Child SA MAY have different Traffic Selectors and algorithms than the old one" was changed to "Note that, when rekeying, the new Child SA SHOULD NOT have different Traffic Selectors and algorithms than the old one" 👑

the new Section 2.8.2 covers simultaneous IKE SA rekeying 🔁

the new Section 2.9.2 covers Traffic Selectors in rekeying 🎯

this document adds the restriction in Section 2.13 that all pseudorandom functions (PRFs) used with IKEv2 MUST take variable-sized keys. this shouldn't affect any implementations, because there were no standardized PRFs that have fixed-size keys 🙌

Section 2.18 requires doing a Diffie-Hellman exchange when rekeying the IKE_SA. in theory, RFC 4306 allowed a policy where the Diffie-Hellman exchange was optional, but that wasn't useful (or appropriate) when rekeying the IKE_SA 💀

Section 2.21 has been greatly expanded to cover the different cases where error responses are needed, and the appropriate responses to them 🛠️

Section 2.23 clarified that, in NAT traversal, both UDP-encapsulated IPsec packets and non-UDP-encapsulated IPsec packets now need to be understood when receiving 🌐

added Section 2.23.1 to describe NAT traversal when transport mode is requested 🚀

added Section 2.25 to explain how to act when there are timing collisions when deleting and/or rekeying SAs. two new error notifications (TEMPORARY_FAILURE and CHILD_SA_NOT_FOUND) were defined too 🫣

in Section 3.6, "Implementations MUST support the HTTP method for hash-and-URL lookup. The behavior of other URL methods is not currently specified, and such methods SHOULD NOT be used in the absence of a document specifying them" was added 🙈

in Section 3.15.3, a pointer to a new document related to configuration of IPv6 addresses was added 🌍

Appendix C was expanded and clarified 📖


2. IKE Protocol Details and Variations 🌈

IKE normally listens and sends on UDP port 500, though IKE messages may also be received on UDP port 4500 with a slightly different format (see Section 2.23). since UDP is a datagram (unreliable) protocol, IKE builds in recovery from transmission errors, including packet loss, packet replay, and packet forgery 🛡️ IKE is designed to function as long as (1) at least one of a series of retransmitted packets reaches its destination before timing out, and (2) the channel isn't so full of forged and replayed packets that it exhausts the network or CPU capacities of either endpoint. even without those minimum performance requirements, IKE is designed to fail cleanly (as though the network were broken) 🫠

although IKEv2 messages are meant to be short, they contain structures with no hard upper bound on size (digital certificates especially 📜), and IKEv2 itself has no mechanism for fragmenting large messages. IP defines a mechanism for fragmentation of oversized UDP messages, but implementations vary in the maximum message size they support. plus, using IP fragmentation opens an implementation up to denial-of-service (DoS) attacks [DOSUDPPROT] ⚠️ and some NAT and/or firewall implementations may block IP fragments too 🧱

All IKEv2 implementations MUST be able to send, receive, and process IKE messages up to 1280 octets long, and they SHOULD be able to send, receive, and process messages up to 3000 octets long. IKEv2 implementations need to be aware of the maximum UDP message size they support, and they MAY shorten messages by leaving out some certificates or cryptographic suite proposals if that keeps messages below the maximum 💖 using the "Hash and URL" formats instead of including certificates in exchanges where possible can avoid most problems. implementations and configuration need to keep in mind, though, that if URL lookups are only possible after the Child SA is established, recursion issues could stop this technique from working 🔄

The UDP payload of all packets containing IKE messages sent on port 4500 MUST begin with the prefix of four zeros; otherwise, the receiver won't know how to handle them 🫶

2.1. Use of Retransmission Timers 💖

okay so every IKE message comes in pairs 🎀: a request and a response. Setting up an IKE SA usually takes two exchanges ✨. Once it's up, either end can send requests whenever it wants, and there can be a whole bunch of requests and responses "in flight" at the same time 🦋. But every message is labeled as a request or a response, and for each exchange, one end is the initiator and the other is the responder 💅.

For every pair of IKE messages, the initiator is in charge of retransmission if things time out 🫶. The responder MUST never retransmit a response unless it gets a retransmission of the request 😭. When that happens, the responder MUST ignore the retransmitted request, except for the part where it causes a retransmission of the response 🙈. The initiator MUST remember each request until the matching response shows up 🧠. The responder MUST remember each response until it sees a request whose sequence number is larger than or equal to the sequence number in the response plus its window size (see Section 2.3) 👑. To save memory, responders are allowed to forget the response after a timeout of several minutes 🍓. If the responder gets a retransmitted request for a response it already forgot, it MUST ignore the request (and not, for example, attempt constructing a new response) 💀.

IKE is a reliable protocol, so the initiator MUST retransmit a request until it either gets a corresponding response or decides the IKE SA has failed 🔥. In that second case, the initiator discards all state associated with the IKE SA and any Child SAs that were negotiated using that IKE SA. A retransmission from the initiator MUST be bitwise identical to the original request. That is, everything starting from the IKE header (the IKE SA initiator's SPI onwards) must be bitwise identical. Items before it (such as the IP and UDP headers) do not have to be identical 🧚.

Retransmissions of the IKE_SA_INIT request need some special handling 🌈. When a responder gets an IKE_SA_INIT request, it has to figure out whether the packet is a retransmission belonging to an existing "half-open" IKE SA (in which case it retransmits the same response), a brand new request (in which case it creates a new IKE SA and sends a fresh response), or something that belongs to an existing IKE SA where the IKE_AUTH request has already been received (in which case it ignores it) 🕵️.

It's not enough to use the initiator's SPI and/or IP address to tell these three cases apart, because two different peers behind a single NAT could choose the same initiator SPI 🙃. So a robust responder will do the IKE SA lookup using the whole packet, its hash, or the Ni payload ✨.

The retransmission policy for one-way messages is kinda different 🦋. Because no acknowledgement is ever sent, there's no reason to gratuitously retransmit one-way messages. Given that all these messages are errors, it makes sense to send them only once per "offending" packet, and only retransmit if further offending packets are received. Still, it also makes sense to limit retransmissions of such error messages 💅.

2.2. Use of Sequence Numbers for Message ID 🔢

Every IKE message contains a Message ID as part of its fixed header 💜. This Message ID is used to match up requests and responses and to identify retransmissions of messages. Retransmission of a message MUST use the same Message ID as the original message.

The Message ID is a 32-bit quantity. It's zero for the IKE_SA_INIT messages (including retries of the message due to responses such as COOKIE and INVALID_KE_PAYLOAD), and it gets incremented for each subsequent exchange. So the first pair of IKE_AUTH messages has an ID of 1, the second (when EAP is used) is 2, and so on. The Message ID is reset to zero in the new IKE SA after the IKE SA is rekeyed.

Each endpoint in the IKE Security Association maintains two "current" Message IDs: the next one to be used for a request it initiates, and the next one it expects to see in a request from the other end. These counters increment as requests are generated and received. Responses always contain the same Message ID as the corresponding request. That means that after the initial exchange, each integer n may appear as the Message ID in four distinct messages: the nth request from the original IKE initiator, the corresponding response, the nth request from the original IKE responder, and the corresponding response. If the two ends make a very different number of requests, the Message IDs in the two directions can be very different. There's no ambiguity in the messages, though, because the Initiator and Response flags in the message header specify which of the four messages a particular one is ✨.

Throughout this document, "initiator" refers to the party who initiated the exchange being described. The "original initiator" always refers to the party who initiated the exchange that resulted in the current IKE SA. In other words, if the "original responder" starts rekeying the IKE SA, that party becomes the "original initiator" of the new IKE SA 🎀.

Note that Message IDs are cryptographically protected and provide protection against message replays. In the unlikely event that Message IDs grow too large to fit in 32 bits, the IKE SA MUST be closed or rekeyed 🚨.

2.3. Window Size for Overlapping Requests 🪟

The SET_WINDOW_SIZE notification asserts that the sending endpoint is capable of keeping state for multiple outstanding exchanges, which lets the recipient send multiple requests before getting a response to the first one 🦋. The data associated with a SET_WINDOW_SIZE notification MUST be 4 octets long and contain the big endian representation of the number of messages the sender promises to keep. The window size is always one until the initial exchanges complete 🌸.

An IKE endpoint MUST wait for a response to each of its messages before sending a subsequent message, unless it has received a SET_WINDOW_SIZE Notify message from its peer informing it that the peer is prepared to maintain state for multiple outstanding messages in order to allow greater throughput ⭐.

After an IKE SA is set up, in order to maximize IKE throughput, an IKE endpoint MAY issue multiple requests before getting a response to any of them, up to the limit set by its peer's SET_WINDOW_SIZE. These requests may pass one another over the network. An IKE endpoint MUST be prepared to accept and process a request while it has a request outstanding, in order to avoid a deadlock in this situation. An IKE endpoint may also accept and process multiple requests while it has a request outstanding 🧩.

An IKE endpoint MUST NOT exceed the peer's stated window size for transmitted IKE requests. In other words, if the responder stated its window size is N, then when the initiator needs to make a request X, it MUST wait until it has received responses to all requests up through request X-N. An IKE endpoint MUST keep a copy of (or be able to regenerate exactly) each request it has sent until it receives the corresponding response. An IKE endpoint MUST keep a copy of (or be able to regenerate exactly) the number of previous responses equal to its declared window size, in case its response was lost and the initiator requests its retransmission by retransmitting the request 🛡️.

An IKE endpoint supporting a window size greater than one ought to be capable of processing incoming requests out of order, to maximize performance in the event of network failures or packet reordering 🌈.

The window size is normally a (possibly configurable) property of a particular implementation, and it is not related to congestion control (unlike the window size in TCP, for example) 🙅. In particular, what the responder should do when it receives a SET_WINDOW_SIZE notification containing a smaller value than is currently in effect is not defined. Thus, there is currently no way to reduce the window size of an existing IKE SA. You can only increase it 📈. When rekeying an IKE SA, the new IKE SA starts with window size 1 until it is explicitly increased by sending a new SET_WINDOW_SIZE notification.

The INVALID_MESSAGE_ID notification is sent when an IKE Message ID outside the supported window is received. This Notify message MUST NOT be sent in a response, and the invalid request MUST NOT be acknowledged. Instead, inform the other side by initiating an INFORMATIONAL exchange with Notification data containing the four-octet invalid Message ID. Sending this notification is OPTIONAL, and notifications of this type MUST be rate limited 🚦.

2.4. State Synchronization and Connection Timeouts ✨

okay bestie, so an IKE endpoint is totally allowed to forget everything it knows about an IKE SA and its whole collection of Child SAs, at any time 🧠💨. This is the expected behavior when an endpoint crashes and restarts. It's really important that when one side fails or reinitializes, the other side notices. Otherwise it keeps wasting network bandwidth sending packets over SAs that got thrown away, and those packets just fall into a black hole 🕳️😭

The INITIAL_CONTACT notification says that this IKE SA is the only IKE SA currently active between the authenticated identities 🫶 It MAY be sent when an IKE SA gets established after a crash, and the recipient MAY use that info to delete any other IKE SAs it has to the same authenticated identity, without waiting for a timeout 💅 But there are rules! This notification MUST NOT be sent by an entity that may be replicated. Think a roaming user whose credentials let them connect to the corporate firewall from two remote systems at once 👀 Also, the INITIAL_CONTACT notification, if sent, MUST be in the first IKE_AUTH request or response, not as a separate exchange afterwards. Receiving parties MAY ignore it in other messages 🙈

Since IKE is built to keep working even under DoS attacks from the network, the rules for deciding the other side is dead are super strict 💀

An endpoint MUST NOT conclude that the other endpoint has failed based on any routing information (like ICMP messages) or IKE messages that arrive without cryptographic protection (like Notify messages complaining about unknown SPIs). Those can be faked, so no cap, don't trust them for this 🚫 An endpoint MUST conclude that the other endpoint has failed only when repeated attempts to contact it have gone unanswered for a timeout period, or when a cryptographically protected INITIAL_CONTACT notification shows up on a different IKE SA to the same authenticated identity 🔥 An endpoint should suspect that the other endpoint has failed based on routing information, and then initiate a request to see whether the other endpoint is alive 🔍

To check whether the other side is alive, IKE specifies an empty INFORMATIONAL message. Like all IKE requests, it requires an acknowledgement 🌸 (Quick note: inside an IKE SA, an "empty" message is just an IKE header followed by an Encrypted payload that contains no payloads. Lowkey iconic, right? 🧚) If a cryptographically protected message (fresh, meaning not retransmitted) has been received from the other side recently, unprotected Notify messages MAY be ignored 💖 Implementations MUST limit the rate at which they take actions based on unprotected messages, so nobody gets flooded 🛑

The number of retries and length of timeouts aren't covered in this specification, because they don't affect interoperability ✨ It's suggested that messages be retransmitted at least a dozen times over a period of at least several minutes before giving up on an SA. Different environments may need different rules though 🌈 To be a good network citizen, retransmission times MUST increase exponentially, so you don't flood the network and make an existing congestion situation even worse 🫧 If there has only been outgoing traffic on all of the SAs associated with an IKE SA, it's essential to confirm liveness of the other endpoint to avoid black holes 🕳️ If no cryptographically protected messages have been received on an IKE SA or any of its Child SAs recently, the system needs to perform a liveness check so it doesn't keep sending messages to a dead peer 💀 (This is sometimes called "dead peer detection" or "DPD," although it's really detecting live peers, not dead ones. The naming is kinda chaotic 🙃)

Receiving a fresh cryptographically protected message on an IKE SA or any of its Child SAs ensures liveness of the IKE SA and all of its Child SAs 🎀 Note that this puts requirements on the failure modes of an IKE endpoint. An implementation needs to stop sending over any SA if some failure stops it from receiving on all of the associated SAs 🛑 And if a system creates Child SAs that can fail independently from one another, without the associated IKE SA being able to send a delete message, then the system MUST negotiate such Child SAs using separate IKE SAs 👑

There's a DoS attack on the initiator of an IKE SA, but it can be avoided if the initiator takes proper care 🛡️ The first two messages of an SA setup aren't cryptographically protected, so an attacker could respond to the initiator's message before the genuine responder does and poison the connection setup attempt 😤 To prevent this, the initiator MAY be willing to accept multiple responses to its first message. It treats each one as potentially legitimate, responds to it, and then discards all the invalid half-open connections once it receives a valid cryptographically protected response to any one of its requests 💅 Once a cryptographically valid response is received, all subsequent responses should be ignored, whether or not they're cryptographically valid 🙅‍♀️

With these rules there's no reason to negotiate and agree upon an SA lifetime, bestie 🥰 If IKE presumes the partner is dead, based on repeated lack of acknowledgement to an IKE message, then the IKE SA and all Child SAs set up through that IKE SA get deleted 🗑️

An IKE endpoint may at any time delete inactive Child SAs to recover the resources used to hold their state 🧹 If an IKE endpoint chooses to delete Child SAs, it MUST send Delete payloads to the other end to notify it of the deletion 📨 It MAY similarly time out the IKE SA. Closing the IKE SA implicitly closes all associated Child SAs 💫 In this case, an IKE endpoint SHOULD send a Delete payload indicating that it has closed the IKE SA, unless the other endpoint is no longer responding 🫶


2.5. Version Numbers and Forward Compatibility 🦋

This document describes version 2.0 of IKE, which means the major version number is 2 and the minor version number is 0 🎀 It replaces [IKEV2], and it's likely that some implementations will want to support version 1.0 and version 2.0, and in the future, other versions too 🌸

The major version number should be incremented only if the packet formats or required actions have changed so dramatically that an older version node couldn't interoperate with a newer one by simply ignoring the fields it doesn't understand and taking the actions in the older specification 💀 The minor version number indicates new capabilities. It MUST be ignored by a node with a smaller minor version number, but it's used for informational purposes by the node with the larger minor version number 🧠 For example, it might indicate the ability to process a newly defined Notify message type. The node with the larger minor version number would simply note that its correspondent can't understand that message, so it wouldn't send it 🙈

If an endpoint receives a message with a higher major version number, it MUST drop the message. It SHOULD send an unauthenticated Notify message of type INVALID_MAJOR_VERSION, containing the highest (closest) version number it supports 📣 If an endpoint supports major version n and major version m, it MUST support all versions between n and m 🌈 If it receives a message with a major version that it supports, it MUST respond with that version number 💖 To keep two nodes from being tricked into talking on a lower major version than the maximum they both support, IKE has a flag that indicates the node is capable of speaking a higher major version number 🚩

So the major version number in the IKE header shows the version of the message, not the highest version the transmitter supports 🫧 If the initiator can speak versions n, n+1, and n+2, and the responder can speak versions n and n+1, then they'll negotiate speaking n+1, and the initiator will set a flag saying it can speak a higher version 👑 If they get mixed up (maybe an active attacker sends error messages) and negotiate down to version n, then both will notice that the other side supports a higher version number, and they MUST break the connection and reconnect using version n+1 😤

IKEv1 doesn't follow these rules, because v1 has no way of noting that you can speak a higher version number 🙃 So an active attacker can trick two v2-capable nodes into speaking v1. When a v2-capable node negotiates down to v1, it should note that fact in its logs 📝

Also, for forward compatibility, all fields marked RESERVED MUST be set to zero by an implementation running version 2.0, and their content MUST be ignored by an implementation running version 2.0 ("Be conservative in what you send and liberal in what you receive" [IP]) 🫶 That way, future versions of the protocol can use those fields in a way that's guaranteed to be ignored by implementations that don't understand them 🧚 Similarly, payload types that aren't defined are reserved for future use. Implementations of a version where they're undefined MUST skip over those payloads and ignore their contents 🌸

IKEv2 adds a "critical" flag to each payload header for extra forward-compatibility flexibility 💅 If the critical flag is set and the payload type is unrecognized, the message MUST be rejected, and the response to the IKE request containing that payload MUST include a Notify payload UNSUPPORTED_CRITICAL_PAYLOAD, which says an unsupported critical payload was included 🚨 In that Notify payload, the notification data contains the one-octet payload type. If the critical flag isn't set and the payload type is unsupported, that payload MUST be ignored 🙈 Payloads sent in IKE response messages MUST NOT have the critical flag set 🙅‍♀️ Note that the critical flag applies only to the payload type, not the contents. If the payload type is recognized but the payload contains something that isn't (like an unknown transform inside an SA payload, or an unknown Notify Message Type inside a Notify payload), the critical flag is ignored 🧠

Although new payload types may be added in the future, and may show up interleaved with the fields defined in this specification, implementations SHOULD send the payloads defined in this specification in the order shown in the figures in Sections 1 and 2 🌈 Implementations MUST NOT reject as invalid a message with those payloads in any other order 🫶 Periodt! 💖

2.6. IKE SA SPIs and Cookies 🦋

okay so the first two eight-octet fields in the header, called the "IKE SPIs", are the connection identifier at the start of every IKE packet 🎀. Each endpoint picks one of the two SPIs, and it MUST pick them so they're unique identifiers of an IKE SA 💖. An SPI value of zero is special: it means the sender doesn't know the remote SPI yet 🙈.

Incoming IKE packets get mapped to an IKE SA using ONLY the packet's SPI, not stuff like the source IP address of the packet 💅.

Unlike ESP and AH, where only the recipient's SPI shows up in the header, IKE sends the sender's SPI in every message too ✨. The SPI chosen by the original initiator of the IKE SA is always sent first, so an endpoint with multiple IKE SAs open that wants to find the right one using the SPI it assigned must look at the Initiator flag in the header. That tells it whether it assigned the first or the second eight octets 🧚.

In the first message of an initial IKE exchange, the initiator won't know the responder's SPI, so it will set that field to zero 🌸. When the IKE_SA_INIT exchange doesn't result in an IKE SA because of INVALID_KE_PAYLOAD, NO_PROPOSAL_CHOSEN, or COOKIE (see Section 2.6), the responder's SPI will also be zero in the response message. However, if the responder sends a non-zero responder SPI, the initiator should not reject the response just for that reason 🫶.

Two expected attacks against IKE are state and CPU exhaustion, where the target gets flooded with session initiation requests from forged IP addresses 😭. These attacks get way less effective if a responder uses minimal CPU and commits no state to an SA until it knows the initiator can receive packets at the address it claims to be sending from 🔥.

When a responder detects a large number of half-open IKE SAs, it SHOULD reply to IKE_SA_INIT requests with a response containing the COOKIE notification 👑. The data for this notification MUST be between 1 and 64 octets in length (inclusive), and how it's generated is described later in this section ⭐. If the IKE_SA_INIT response includes the COOKIE notification, the initiator MUST then retry the IKE_SA_INIT request, and include the COOKIE notification containing the received data as the first payload, with all other payloads unchanged 💜. The initial exchange then looks like this:

Initiator                         Responder
-------------------------------------------------------------------
HDR(A,0), SAi1, KEi, Ni  -->
                            <--  HDR(A,0), N(COOKIE)
HDR(A,0), N(COOKIE), SAi1,
    KEi, Ni  -->
                            <--  HDR(A,B), SAr1, KEr,
                                     Nr, [CERTREQ]
HDR(A,B), SK {IDi, [CERT,]
    [CERTREQ,] [IDr,] AUTH,
    SAi2, TSi, TSr}  -->
                            <--  HDR(A,B), SK {IDr, [CERT,]
                                     AUTH, SAr2, TSi, TSr}

The first two messages don't affect any initiator or responder state, except for carrying the cookie 🍓. Basically, the message sequence numbers in the first four messages are all zero, and the ones in the last two messages are one 🙈. 'A' is the SPI assigned by the initiator, and 'B' is the SPI assigned by the responder 🦋.

An IKE implementation can do its responder cookie generation in a way that doesn't need any saved state to recognise its valid cookie when the second IKE_SA_INIT message shows up 🧠. The exact algorithms and syntax for generating cookies don't affect interoperability, so they aren't specified here 💅. The following is an example of how an endpoint could use cookies for limited DoS protection ✨.

A good way to do this is to set the responder cookie to be:

Cookie = <VersionIDofSecret> | Hash(Ni | IPi | SPIi | <secret>)

where <secret> is a randomly generated secret known only to the responder and periodically changed, and | means concatenation 🔐. <VersionIDofSecret> should be changed whenever <secret> is regenerated 🌈. The cookie can be recomputed when the IKE_SA_INIT arrives the second time and then compared to the cookie in the received message 🔁. If it matches, the responder knows the cookie was generated since the last change to <secret>, and that IPi must be the same as the source address it saw the first time 🎯. Putting SPIi into the calculation makes sure that if multiple IKE SAs are being set up in parallel, they'll all get different cookies (assuming the initiator chooses unique SPIi's) 🌸. Putting Ni in the hash makes sure an attacker who sees only message 2 can't successfully forge a message 3 🛡️. Also, including SPIi in the hash stops an attacker from grabbing one cookie from the other end and then starting many IKE_SA_INIT exchanges, all with different initiator SPIs (and maybe port numbers), so the responder thinks there are a ton of machines behind one NAT box all trying to connect 🙃.

If a new value for <secret> is chosen while connections are still being initialised, an IKE_SA_INIT might come back with something other than the current <VersionIDofSecret> 🫠. In that case the responder MAY reject the message by sending another response with a new cookie, or it MAY keep the old value of <secret> around for a short time and accept cookies computed from either one 💫. The responder should not accept cookies indefinitely after <secret> is changed, since that would defeat part of the DoS protection 🚫. The responder should change the value of <secret> frequently, especially when it's under attack 🚨.

When a party receives an IKE_SA_INIT request containing a cookie whose contents don't match the expected value, that party MUST ignore the cookie and process the message as if no cookie had been included. Usually that means sending a response with a new cookie 🔄. The initiator should limit how many cookie exchanges it tries before giving up, possibly using exponential back-off ⏳. An attacker can forge multiple cookie responses to the initiator's IKE_SA_INIT message, and each forged cookie reply causes two packets to be sent: one from the initiator to the responder (which will reject those cookies), and one response from the responder to the initiator that includes the correct cookie 👀.

A quick note on terminology 📚: the term "cookies" comes from Karn and Simpson [PHOTURIS] in Photuris, an early proposal for key management with IPsec, and it stuck around 🍪. The Internet Security Association and Key Management Protocol (ISAKMP) [ISAKMP] fixed message header includes two eight-octet fields called "cookies", and that syntax is used by both IKEv1 and IKEv2 🤝. In IKEv2, though, they're called the "IKE SPI", and there's a new separate field in a Notify payload that holds the cookie 💜.

there are two common reasons the initiator might have to retry the IKE_SA_INIT exchange: the responder requests a cookie, or it wants a different Diffie-Hellman group than the one included in the KEi payload 🤷‍♀️. If the initiator receives a cookie from the responder, it needs to decide whether to include the cookie only in the next retry of the IKE_SA_INIT request, or in all subsequent retries as well 🧩.

If the initiator includes the cookie only in the next retry, one extra round trip may be needed in some cases 🐢. An extra round trip is also needed if the initiator includes the cookie in all retries but the responder doesn't support that. For instance, if the responder includes the KEi payloads in the cookie calculation, it will reject the request by sending a new cookie 😤.

If both peers support including the cookie in all retries, a slightly shorter exchange can happen ⚡.

Initiator                   Responder
-----------------------------------------------------------
HDR(A,0), SAi1, KEi, Ni -->
                        <-- HDR(A,0), N(COOKIE)
HDR(A,0), N(COOKIE), SAi1, KEi, Ni  -->
                        <-- HDR(A,0), N(INVALID_KE_PAYLOAD)
HDR(A,0), N(COOKIE), SAi1, KEi', Ni -->
                        <-- HDR(A,B), SAr1, KEr, Nr

Implementations SHOULD support this shorter exchange, but they MUST NOT fail if other implementations don't support it 🫶✨.

2.7. Cryptographic Algorithm Negotiation 💅

the payload type known as "SA" indicates a proposal for a set of choices of IPsec protocols (IKE, ESP, or AH) for the SA, along with the cryptographic algorithms for each protocol 🔐.

An SA payload is made up of one or more proposals 🧁. Each proposal includes one protocol. Each protocol contains one or more transforms, and each transform specifies a cryptographic algorithm 🎯. Each transform contains zero or more attributes (attributes are only needed if the Transform ID doesn't completely specify the cryptographic algorithm) 🧠.

This hierarchical structure was designed to encode proposals for cryptographic suites efficiently when the number of supported suites is large, because multiple values are acceptable for multiple transforms 🌈. The responder MUST choose a single suite, which may be any subset of the SA proposal, following the rules below 👑.

Each proposal contains one protocol. If a proposal is accepted, the SA response MUST contain the same protocol. The responder MUST accept a single proposal or reject them all and return an error. That error is given in a notification of type NO_PROPOSAL_CHOSEN 🚫.

Each IPsec protocol proposal contains one or more transforms, and each transform contains a Transform Type 🧩. The accepted cryptographic suite MUST contain exactly one transform of each type included in the proposal 💖. For example: if an ESP proposal includes transforms ENCR_3DES, ENCR_AES w/keysize 128, ENCR_AES w/keysize 256, AUTH_HMAC_MD5, and AUTH_HMAC_SHA, the accepted suite MUST contain one of the ENCR_ transforms and one of the AUTH_ transforms. That means six combinations are acceptable 🧮.

If an initiator proposes both normal ciphers with integrity protection and combined-mode ciphers, then two proposals are needed 🍭. One proposal includes the normal ciphers with the integrity algorithms for them. The other includes all the combined-mode ciphers without integrity algorithms, because combined-mode ciphers aren't allowed to have any integrity algorithm other than "none" 🙅‍♀️💀.

2.8. Rekeying ✨

okay so keys don't last forever 🥺 IKE, ESP, and AH Security Associations use secret keys that should only be used for a limited amount of time and to protect a limited amount of data, so the whole SA has a lifetime too. when an SA's lifetime runs out, it MUST NOT be used anymore 🚫. if there's demand, new SAs MAY be established, and swapping an expiring SA for a fresh one is called "rekeying" 🎀

to keep minimal IPsec implementations possible, being able to rekey SAs without restarting the whole IKE SA is optional 💅 an implementation MAY refuse all CREATE_CHILD_SA requests within an IKE SA. if an SA has expired or is about to, and the rekeying methods here fail, an implementation MUST close the IKE SA and any associated Child SAs, and then it MAY start new ones. implementers may wish to support in-place rekeying, since it's better for performance and is likely to drop fewer packets during the transition 🦋

to rekey a Child SA inside an existing IKE SA, make a new, equivalent SA (see Section 2.17 below), and once the new one is up, delete the old one 🔁 heads up though: when rekeying, the new Child SA SHOULD NOT have different Traffic Selectors and algorithms than the old one 👀

to rekey an IKE SA, set up a new equivalent IKE SA (see Section 2.18 below) with the same peer the old one is shared with, using a CREATE_CHILD_SA inside the existing IKE SA. the new IKE SA inherits all of the original IKE SA's Child SAs, and it's the one used for all the control messages that keep those Child SAs going 🫶 after the new equivalent IKE SA exists, the initiator deletes the old IKE SA, and the Delete payload that deletes itself MUST be the last request sent over the old IKE SA 🌸

SAs should be rekeyed proactively, which means the new SA gets established before the old one expires and becomes unusable ⏰ enough time should pass between the new SA being established and the old one becoming unusable so traffic can be switched over to the new SA.

fun fact: IKEv1 negotiated SA lifetimes, but in IKEv2 each end of the SA enforces its own lifetime policy on it and rekeys it when necessary 💜 if the two ends have different lifetime policies, the end with the shorter lifetime will always end up being the one requesting the rekey. if an SA has been inactive for a long time and an endpoint wouldn't initiate the SA without traffic anyway, the endpoint MAY choose to close the SA instead of rekeying it when its lifetime expires. it can also do that if there's been no traffic since the last time the SA was rekeyed.

IKEv2 deliberately allows parallel SAs with the same Traffic Selectors between common endpoints 🌈 one of the reasons is supporting traffic quality of service (QoS) differences among the SAs (see [DIFFSERVFIELD], [DIFFSERVARCH], and Section 4.1 of [DIFFTUNNEL]). so unlike IKEv1, the combo of endpoints and Traffic Selectors may not uniquely identify an SA between those endpoints, which means the IKEv1 rekeying heuristic of deleting SAs based on duplicate Traffic Selectors SHOULD NOT be used 🙅

there are timing windows, especially when packets get lost, where endpoints might not agree on the state of an SA 😬 the responder to a CREATE_CHILD_SA MUST be prepared to accept messages on an SA before sending its response to the creation request, so there's no ambiguity for the initiator. the initiator MAY begin sending on an SA as soon as it processes the response. the initiator, however, can't receive on a newly created SA until it receives and processes the response to its CREATE_CHILD_SA request. so how does the responder know when it's OK to send on the newly created SA? 🤔

from a technical correctness and interoperability perspective, the responder MAY begin sending on an SA as soon as it sends its response to the CREATE_CHILD_SA request. in some situations though, this could mean packets get dropped unnecessarily, so an implementation MAY defer such sending 🫠

the responder can be assured that the initiator is ready to receive messages on an SA if either (1) it has received a cryptographically valid message on the other half of the SA pair, or (2) the new SA rekeys an existing SA and it receives an IKE request to close the replaced SA. when rekeying an SA, the responder keeps sending traffic on the old SA until one of those events happens. when establishing a new SA, the responder MAY defer sending messages on the new SA until either it receives one or a timeout has occurred. if an initiator receives a message on an SA it hasn't gotten a response for to its CREATE_CHILD_SA request, it reads that as a likely packet loss and retransmits the CREATE_CHILD_SA request. an initiator MAY send a dummy ESP message on a newly created ESP SA if it has no messages queued, to assure the responder that it's ready to receive messages 💌

2.8.1. Simultaneous Child SA Rekeying

if both ends have the same lifetime policies, it's possible that both will start a rekeying at the same time 🙃 which results in redundant SAs. to reduce the chances of that, the timing of rekeying requests SHOULD be jittered (delayed by a random amount of time after the need for rekeying is noticed) 🎲

this form of rekeying can temporarily leave multiple similar SAs between the same pairs of nodes. when there are two SAs eligible to receive packets, a node MUST accept incoming packets through either SA. if redundant SAs get created through a collision like this, the SA created with the lowest of the four nonces used in the two exchanges SHOULD be closed by the endpoint that created it. "Lowest" means an octet-by-octet comparison (instead of, for instance, comparing the nonces as large integers). in other words, start by comparing the first octet; if they're equal, move to the next octet, and so on. if you reach the end of one nonce, that nonce is the lower one. the node that initiated the surviving rekeyed SA should delete the replaced SA after the new one is established ✨

here's how it plays out for implementations 👩‍💻 assume hosts A and B have an existing Child SA pair with SPIs (SPIa1,SPIb1), and both start rekeying it at the same time:

   Host A                            Host B
   -------------------------------------------------------------------
   send req1: N(REKEY_SA,SPIa1),
       SA(..,SPIa2,..),Ni1,..  -->
                                <--  send req2: N(REKEY_SA,SPIb1),
                                         SA(..,SPIb2,..),Ni2
   recv req2 <--

at this point, A knows there's a simultaneous rekeying happening. however, it can't know yet which exchange will have the lowest nonce, so it just notes the situation and responds as usual.

   send resp2: SA(..,SPIa3,..),
        Nr1,..  -->
                                -->  recv req1

now B also knows that simultaneous rekeying is going on. it responds as usual.

                               <--  send resp1: SA(..,SPIb3,..),
                                        Nr2,..
   recv resp1 <--
                               -->  recv resp2

at this point, there are three Child SA pairs between A and B (the old one and two new ones). A and B can now compare the nonces. suppose the lowest nonce was Nr1 in message resp2; in that case, B (the sender of req2) deletes the redundant new SA, and A (the node that initiated the surviving rekeyed SA) deletes the old one 🧹

   send req3: D(SPIa1) -->
                                <--  send req4: D(SPIb2)
                                -->  recv req3
                                <--  send resp3: D(SPIb1)
   recv req4 <--
   send resp4: D(SPIa3) -->

and the rekeying is now finished 🎉

there's also a second possible sequence of events 👀 if some packets are lost in the network and retransmissions happen, the rekeying begins as usual, but A's first packet (req1) gets lost.

   Host A                            Host B
   -------------------------------------------------------------------
   send req1: N(REKEY_SA,SPIa1),
       SA(..,SPIa2,..),
       Ni1,..  -->  (lost)
                                <--  send req2: N(REKEY_SA,SPIb1),
                                         SA(..,SPIb2,..),Ni2
   recv req2 <--
   send resp2: SA(..,SPIa3,..),
       Nr1,.. -->
                                -->  recv resp2
                                <--  send req3: D(SPIb1)
   recv req3 <--
   send resp3: D(SPIa1) -->
                                -->  recv resp3

from B's point of view, the rekeying is now completed, and since it hasn't received A's req1 yet, it doesn't even know there was simultaneous rekeying 🤷‍♀️ however, A will keep retransmitting the message, and eventually it will reach B.

   resend req1 -->
                                -->  recv req1

to B, it looks like A is trying to rekey an SA that no longer exists 😅 so B responds to the request with something non-fatal, such as CHILD_SA_NOT_FOUND.

                                <--  send resp1: N(CHILD_SA_NOT_FOUND)
   recv resp1 <--

when A receives this error, it already knows there was simultaneous rekeying, so it can ignore the error message 💖

2.8.2. Simultaneous IKE SA Rekeying 💥

okay so this is probably the messiest rekey situation ever 😭 when both peers try to rekey the IKE_SA at the exact same time. Section 2.8 still applies here, but the big thing to get right is making sure the Child SAs get inherited by the correct IKE_SA 🎀

When both endpoints notice the simultaneous rekey, it works just like it does for Child SAs 🦋 After the CREATE_CHILD_SA exchanges finish, you've got three IKE SAs between A and B: the old one and two shiny new ones 👀 The new IKE SA with the lowest nonce SHOULD be deleted by the node that created it 🗑️, and the other surviving new IKE SA MUST inherit all the Child SAs 👑

There's also a special case where one peer finishes its rekey before it even notices that the other peer is rekeying too 🙈 If only one peer detects the simultaneous rekey, redundant SAs don't get created. In that situation, when the peer that didn't notice gets a request to rekey the IKE SA it already successfully rekeyed, it SHOULD return TEMPORARY_FAILURE, because that's an IKE SA it's currently trying to close (whether or not it already sent the delete notification for that SA) 💅 And if the peer that did notice gets the delete request for the old IKE SA from the other peer, it knows the other peer never detected the simultaneous rekey, so it can forget its own rekey attempt ✨

Here's the vibe in diagram form 🧚

   Host A                      Host B
   -------------------------------------------------------------------
   send req1:
        SA(..,SPIa1,..),Ni1,.. -->
                             <-- send req2: SA(..,SPIb1,..),Ni2,..
                             --> recv req1
                             <-- send resp1: SA(..,SPIb2,..),Nr2,..
   recv resp1 <--
   send req3: D() -->
                             --> recv req3

At this point, host B sees a request to close the IKE_SA. Honestly there's not much to do beyond replying as usual 🥰 But host B should stop retransmitting req2 💀, because once host A receives resp3, it deletes all the state tied to the old IKE_SA and won't be able to reply to it anymore 😭

                             <-- send resp3: ()

Lowkey tea: the TEMPORARY_FAILURE notification wasn't in RFC 4306, and support for it isn't negotiated 🍵

So older peers that implement RFC 4306 but not this document might get these notifications. When that happens, they'll treat it like any other unknown error notification and stop the exchange. Because the other peer already rekeyed, stopping doesn't cause any ill effects 🫶


2.8.3. Rekeying the IKE SA versus Reauthentication 🔐

okay the drama here is that rekeying and reauthentication are different things in IKEv2 🙅‍♀️ Rekeying the IKE SA creates new keys for the IKE SA and resets the Message ID counters, but it doesn't authenticate the parties again (no AUTH or EAP payloads are involved) 🔑

Rekeying can be super important in some environments, but reauthentication (checking that the parties still have access to the long-term credentials) is often the bigger deal 💖

IKEv2 doesn't have any special support for reauthentication 🥺 Instead, you do it by creating a brand new IKE SA from scratch (using IKE_SA_INIT/IKE_AUTH exchanges, without any REKEY_SA Notify payloads), creating new Child SAs inside that new IKE SA (also without REKEY_SA Notify payloads), and then deleting the old IKE SA, which takes the old Child SAs with it 🧹

That means reauthentication also creates new keys for the IKE SA and Child SAs ✨ So while you can rekey more often than you reauthenticate, a situation where the "authentication lifetime" is shorter than the "key lifetime" doesn't make sense 🤷‍♀️

Either party can start creating a new IKE SA (the initiator or the responder of the original IKE SA) 🦋 But when EAP and/or Configuration payloads are involved, reauthentication in practice has to be started by the same party that started the original IKE SA. IKEv2 doesn't currently let the responder ask for reauthentication in this case 🙃 There are extensions that add that functionality, though, such as [REAUTH] 💅


2.9. Traffic Selector Negotiation 🎯

okay so when an RFC4301-compliant IPsec subsystem gets an IP packet that matches a "protect" selector in its Security Policy Database (SPD), it protects that packet with IPsec 🛡️ If no SA exists yet, IKE is the one that has to create it 🙌 Maintaining a system's SPD is outside the scope of IKE, though some implementations might update their SPD while IKE is running (for an example scenario, see Section 1.1.3) 🌸

Traffic Selector (TS) payloads let endpoints share some of the info from their SPD with their peers 💌 That info has to come to IKE from the SPD (for example, the PF_KEY API [PFKEY] uses the SADB_ACQUIRE message). The TS payloads spell out the selection criteria for packets that will be forwarded over the newly set up SA. This can act as a consistency check in some scenarios, making sure the SPDs match up. In other scenarios, it guides dynamic updates to the SPD 🧚

Two TS payloads show up in each message of the exchange that creates a Child SA pair 👯 Each TS payload holds one or more Traffic Selectors, and each Traffic Selector is made of an address range (IPv4 or IPv6), a port range, and an IP protocol ID 🍓

The first TS payload is called TSi (Traffic Selector-initiator), and the second is called TSr (Traffic Selector-responder) 💜 TSi covers the source address of traffic forwarded from (or the destination address of traffic forwarded to) the initiator of the Child SA pair. TSr covers the destination address of traffic forwarded to (or the source address of traffic forwarded from) the responder of the Child SA pair 🎀

Here's an example: say the original initiator asks for a Child SA pair and wants to tunnel all traffic from the 198.51.100.* subnet on its side to the 192.0.2.* subnet on the responder's side 🌈 The initiator would put a single Traffic Selector in each TS payload. TSi would say (198.51.100.0 - 198.51.100.255), and TSr would say (192.0.2.0 - 192.0.2.255). If the responder is cool with that proposal, it sends back identical TS payloads 🫶

IKEv2 lets the responder pick a subset of the traffic the initiator proposed 🍰 That can happen when the two endpoints' configs are being updated but only one end has the new info. Since the two endpoints might be set up by different people, the mismatch can stick around for a while even with no errors at all 😅 It also allows for intentionally different configs, like when one end is set to tunnel all addresses and relies on the other end to have the up-to-date list 👑

When the responder narrows things down to a subset of what the initiator proposed, it shrinks the Traffic Selectors to some part of the initiator's proposal (as long as the set doesn't end up empty) ✂️ If the initiator proposes a Traffic Selector type the responder doesn't know, the responder ignores that Traffic Selector, so the unknown type never shows up in the narrowed set 🙈

To help the responder pick the right range, the initiator SHOULD include, as the first Traffic Selector in each of TSi and TSr, a very specific Traffic Selector with the addresses from the packet that triggered the request 🎯 In the example, the initiator would put two Traffic Selectors in TSi: the first is (198.51.100.43 - 198.51.100.43) with the source port and IP protocol from the packet, and the second is (198.51.100.0 - 198.51.100.255) with all ports and IP protocols. The initiator would do the same thing with two Traffic Selectors in TSr. But if the initiator creates the Child SA pair not in response to an arriving packet (say, at startup), there might be no specific addresses it prefers over any other. In that case, the first values in TSi and TSr can be ranges instead of specific values 🌸

The responder does the narrowing like this:

  • If the responder's policy doesn't let it accept any part of the proposed Traffic Selectors, it responds with a TS_UNACCEPTABLE Notify message 🙅‍♀️
  • If the responder's policy allows the entire set of traffic covered by TSi and TSr, no narrowing is needed, and the responder can return the same TSi and TSr values 💖
  • If the responder's policy allows it to accept the first selector of TSi and TSr, then the responder MUST narrow the Traffic Selectors to a subset that includes the initiator's first choices. In the example above, the responder might respond with TSi being (198.51.100.43 - 198.51.100.43) with all ports and IP protocols 🎯
  • If the responder's policy doesn't allow it to accept the first selector of TSi and TSr, the responder narrows down to an acceptable subset of TSi and TSr 🥹

Sometimes there are several subsets that are each acceptable, but their union isn't. In that case the responder arbitrarily picks one of them, and it MAY include an ADDITIONAL_TS_POSSIBLE notification in the response 🦋 That notification says the responder narrowed the proposed Traffic Selectors, but other Traffic Selectors would also have been acceptable, just in a separate SA. There's no data associated with this Notify type 🫧 This case only happens when the initiator and responder are configured differently from each other. If they agree on how granular the tunnels should be, the initiator will never ask for a tunnel wider than the responder will accept 💅

The responder's policy could also contain multiple smaller ranges, all inside the initiator's Traffic Selector, where each range has to go over a different SA 🌈 Continuing the example, the responder might be happy to tunnel those addresses to and from the initiator, but require each address pair to have its own separately negotiated Child SA. If the initiator didn't build its request from a packet (say, at startup), there wouldn't be those very specific first Traffic Selectors to help the responder pick the right range. The responder would have no way to figure out which pair of addresses should go in this tunnel, so it would have to guess or reject the request with a SINGLE_PAIR_REQUIRED Notify message 😬

The SINGLE_PAIR_REQUIRED error means a CREATE_CHILD_SA request is unacceptable because its sender will only accept Traffic Selectors that specify a single pair of addresses 🚫 The requestor is expected to respond by asking for an SA covering only the specific traffic it's trying to forward 🙏

Few implementations have policies that require separate SAs for each address pair, so if only some parts of the TSi and TSr proposed by the initiator are acceptable, responders SHOULD narrow the selectors to an acceptable subset instead of using SINGLE_PAIR_REQUIRED 🎀✨

2.9.1. Traffic Selectors Violating Own Policy ✨

okay bestie, this one is SO important 🫶 When an initiator creates a new SA, it needs to avoid proposing Traffic Selectors that violate its own policy 🙅‍♀️ If it doesn't, valid traffic can get dropped 😭 and nobody wants that. If you use decorrelated policies from [IPSECARCH], this kind of policy violation can't happen 💅

let me show you with an example, it's giving clarity 🎀 say host A has a policy where traffic to 198.51.100.66 goes through host B encrypted with AES, and traffic to every other host in 198.51.100.0/24 also goes through B, but has to use 3DES. and say host B accepts any mix of AES and 3DES 🦋

so if host A proposes an SA that uses 3DES and includes a TSr containing (198.51.100.0-198.51.100.255), host B will accept it, totally fine. BUT now host B can use that same SA to send traffic from 198.51.100.66, and A will drop those packets bc A needs AES for that traffic 💀 even if A makes a brand new SA just for 198.51.100.66 that uses AES, B can keep using the first SA for that traffic 🙈 so in this situation, when proposing the SA, host A should have followed its own policy and included a TSr of ((198.51.100.0-198.51.100.65),(198.51.100.67-198.51.100.255)) instead 💖

in general, if (1) the initiator makes a proposal "for traffic X (TSi/TSr), do SA", and (2) for some subset X' of X, the initiator doesn't actually accept traffic X' with SA, and (3) the initiator would be willing to accept traffic X' with some SA' (!=SA), then valid traffic can get dropped unnecessarily, since the responder can apply either SA or SA' to traffic X' 🥺


2.10. Nonces 🎀

the IKE_SA_INIT messages each carry a nonce, and those nonces are used as inputs to cryptographic functions 🔐 the CREATE_CHILD_SA request and the CREATE_CHILD_SA response carry nonces too. these are used to add freshness to the key derivation technique used to get keys for Child SA, and to make sure you get strong pseudorandom bits out of the Diffie-Hellman key ✨ Nonces used in IKEv2 MUST be randomly chosen, MUST be at least 128 bits in size, and MUST be at least half the key size of the negotiated pseudorandom function (PRF). but the initiator picks the nonce before the outcome of the negotiation is known 🙃 so the nonce has to be long enough for all the PRFs being proposed. if the same random number source is used for both keys and nonces, be careful that the nonce use doesn't compromise the keys 🧠

2.11. Address and Port Agility 🦋

IKE runs over UDP ports 500 and 4500, and it implicitly sets up ESP and AH associations for the same IP addresses it runs over 🌸 the IP addresses and ports in the outer header aren't cryptographically protected, though, and IKE is designed to work even through Network Address Translation (NAT) boxes. An implementation MUST accept incoming requests even if the source port is not 500 or 4500, and MUST respond to the address and port the request came from. It MUST specify the address and port at which the request was received as the source address and port in the response. IKE functions identically over IPv4 or IPv6 🌈

2.12. Reuse of Diffie-Hellman Exponentials 👑

IKE generates keying material using an ephemeral Diffie-Hellman exchange to gain "perfect forward secrecy". This means that once a connection is closed and its keys are forgotten, even someone who recorded all the data from the connection and gets access to all the long-term keys of both endpoints can't reconstruct the keys without doing a brute force search of the session key space 🔒

achieving perfect forward secrecy requires that when a connection is closed, each endpoint MUST forget not only the keys used by the connection but also any information that could be used to recompute those keys 💀

because computing Diffie-Hellman exponentials is computationally expensive, an endpoint may find it advantageous to reuse those exponentials for multiple connection setups. there are a few reasonable strategies for this 🧁 an endpoint could choose a new exponential only periodically, though this could result in less-than-perfect forward secrecy if some connection lasts for less than the lifetime of the exponential. or it could keep track of which exponential was used for each connection and delete the information associated with the exponential only when some corresponding connection was closed. this lets the exponential be reused without losing perfect forward secrecy, at the cost of maintaining more state.

whether and when to reuse Diffie-Hellman exponentials are private decisions, in the sense that they won't affect interoperability. An implementation that reuses exponentials MAY choose to remember the exponential used by the other endpoint on past exchanges and, if one is reused, to avoid the second half of the calculation. See [REUSE] for a security analysis of this practice and for additional security considerations when reusing ephemeral Diffie-Hellman keys 🦋

2.13. Generating Keying Material 🌸

in the context of the IKE SA, four cryptographic algorithms are negotiated: an encryption algorithm, an integrity protection algorithm, a Diffie-Hellman group, and a pseudorandom function (PRF). The PRF is used to build the keying material for all the cryptographic algorithms used in both the IKE SA and the Child SAs 💅

we assume that each encryption algorithm and integrity protection algorithm uses a fixed-size key, and that any randomly chosen value of that fixed size can work as a key. For algorithms that accept a variable-length key, a fixed key size MUST be specified as part of the cryptographic transform negotiated (see Section 3.3.5 for the definition of the Key Length transform attribute). For algorithms where not all values are valid keys (like DES or 3DES with key parity), the algorithm by which keys are derived from arbitrary values MUST be specified by the cryptographic transform.

for integrity protection functions based on Hashed Message Authentication Code (HMAC), the fixed key size is the size of the output of the underlying hash function.

it's assumed that PRFs accept keys of any length but have a preferred key size. The preferred key size MUST be used as the length of SK_d, SK_pi, and SK_pr (see Section 2.14). For PRFs based on the HMAC construction, the preferred key size is equal to the length of the output of the underlying hash function. Other types of PRFs MUST specify their preferred key size.

keying material is always derived as the output of the negotiated PRF algorithm. Since the amount of keying material needed may be greater than the size of the output of the PRF, the PRF is used iteratively. The term "prf+" describes a function that outputs a pseudorandom stream based on the inputs to a pseudorandom function called "prf".

in the following, | indicates concatenation. prf+ is defined as:

prf+ (K,S) = T1 | T2 | T3 | T4 | ...

where:
T1 = prf (K, S | 0x01)
T2 = prf (K, T1 | S | 0x02)
T3 = prf (K, T2 | S | 0x03)
T4 = prf (K, T3 | S | 0x04)
...

this continues until all the material needed to compute all required keys has been output from prf+. The keys are taken from the output string without regard to boundaries (e.g., if the required keys are a 256-bit Advanced Encryption Standard (AES) key and a 160-bit HMAC key, and the prf function generates 160 bits, the AES key will come from T1 and the beginning of T2, while the HMAC key will come from the rest of T2 and the beginning of T3). 🧩

the constant concatenated to the end of each prf function is a single octet. The prf+ function is not defined beyond 255 times the size of the prf function output. 🎀

2.14. Generating Keying Material for the IKE SA 🔑

the shared keys are computed as follows. A quantity called SKEYSEED is calculated from the nonces exchanged during the IKE_SA_INIT exchange and the Diffie-Hellman shared secret established during that exchange. SKEYSEED is used to calculate seven other secrets: SK_d, used for deriving new keys for the Child SAs established with this IKE SA; SK_ai and SK_ar, used as keys to the integrity protection algorithm for authenticating the component messages of subsequent exchanges; SK_ei and SK_er, used for encrypting (and of course decrypting) all subsequent exchanges; and SK_pi and SK_pr, which are used when generating an AUTH payload. The lengths of SK_d, SK_pi, and SK_pr MUST be the preferred key length of the PRF agreed upon. 🫶

SKEYSEED and its derivatives are computed as follows:

SKEYSEED = prf(Ni | Nr, g^ir)

{SK_d | SK_ai | SK_ar | SK_ei | SK_er | SK_pi | SK_pr }
                   = prf+ (SKEYSEED, Ni | Nr | SPIi | SPIr )

(indicating that the quantities SK_d, SK_ai, SK_ar, SK_ei, SK_er, SK_pi, and SK_pr are taken in order from the generated bits of the prf+). g^ir is the shared secret from the ephemeral Diffie-Hellman exchange. g^ir is represented as a string of octets in big endian order, padded with zeros if necessary to make it the length of the modulus. Ni and Nr are the nonces, stripped of any headers. For historical backward-compatibility reasons, there are two PRFs that are treated specially in this calculation. If the negotiated PRF is AES-XCBC-PRF-128 [AESXCBCPRF128] or AES-CMAC-PRF-128 [AESCMACPRF128], only the first 64 bits of Ni and the first 64 bits of Nr are used in calculating SKEYSEED, but all the bits are used for input to the prf+ function. 🌈

the two directions of traffic flow use different keys. The keys used to protect messages from the original initiator are SK_ai and SK_ei. The keys used to protect messages in the other direction are SK_ar and SK_er. 💜

2.15. Authentication of the IKE SA ✨

Okay bestie, so when you're NOT doing extensible authentication (more on that in Section 2.16 🫶), the peers prove who they are by each signing a block of data 🔐. Or they can MAC it using a padded shared secret as the key, which we'll get to later in this section 🌸. In these calculations, IDi' and IDr' are the entire ID payloads minus the fixed header. For the responder, the octets to be signed start at the first octet of the first SPI in the header of the second message (the IKE_SA_INIT response) and end at the last octet of the last payload in that message. Then you tack on (just for the signature math) the initiator's nonce Ni (just the value, not the payload wrapping it) and the value prf(SK_pr, IDr') 💅. Neither the nonce Ni nor prf(SK_pr, IDr') actually gets sent, so it's like a secret handshake 🤫. The initiator signs the first message (IKE_SA_INIT request) the same way, starting at the first octet of the first SPI in the header and ending at the last octet of the last payload, with the responder's nonce Nr and prf(SK_pi, IDi') appended 💖. It is critical to the security of the exchange that each side signs the other side's nonce 🚨.

The initiator's signed octets can be described as:

InitiatorSignedOctets = RealMessage1 | NonceRData | MACedIDForI
GenIKEHDR = [ four octets 0 if using port 4500 ] | RealIKEHDR
RealIKEHDR =  SPIi | SPIr |  . . . | Length
RealMessage1 = RealIKEHDR | RestOfMessage1
NonceRPayload = PayloadHeader | NonceRData
InitiatorIDPayload = PayloadHeader | RestOfInitIDPayload
RestOfInitIDPayload = IDType | RESERVED | InitIDData
MACedIDForI = prf(SK_pi, RestOfInitIDPayload)

The responder's signed octets can be described as:

ResponderSignedOctets = RealMessage2 | NonceIData | MACedIDForR
GenIKEHDR = [ four octets 0 if using port 4500 ] | RealIKEHDR
RealIKEHDR =  SPIi | SPIr |  . . . | Length
RealMessage2 = RealIKEHDR | RestOfMessage2
NonceIPayload = PayloadHeader | NonceIData
ResponderIDPayload = PayloadHeader | RestOfRespIDPayload
RestOfRespIDPayload = IDType | RESERVED | RespIDData
MACedIDForR = prf(SK_pr, RestOfRespIDPayload)

Note that all of the payloads are included under the signature, including any payload types not defined in this document. If the first message of the exchange is sent multiple times (such as with a responder cookie and/or a different Diffie-Hellman group), it is the latest version of the message that is signed 🍓.

Optionally, messages 3 and 4 MAY include a certificate, or certificate chain, providing evidence that the key used to compute a digital signature belongs to the name in the ID payload 📜. The signature or MAC will be computed using algorithms dictated by the type of key used by the signer, and specified by the Auth Method field in the Authentication payload. There is no requirement that the initiator and responder sign with the same cryptographic algorithms. The choice of cryptographic algorithms depends on the type of key each has. In particular, the initiator may be using a shared key while the responder may have a public signature key and certificate. It will commonly be the case (but it is not required) that, if a shared secret is used for authentication, the same key is used in both directions 🦋.

Note that it is a common but typically insecure practice to have a shared key derived solely from a user-chosen password without incorporating another source of randomness. This is typically insecure because user-chosen passwords are unlikely to have sufficient unpredictability to resist dictionary attacks, and these attacks are not prevented in this authentication method. (Applications using password-based authentication for bootstrapping and IKE SA should use the authentication method in Section 2.16, which is designed to prevent off-line dictionary attacks.) The pre-shared key needs to contain as much unpredictability as the strongest key being negotiated 💀. In the case of a pre-shared key, the AUTH value is computed as:

For the initiator:

AUTH = prf( prf(Shared Secret, "Key Pad for IKEv2"),
                 <InitiatorSignedOctets>)

For the responder:

AUTH = prf( prf(Shared Secret, "Key Pad for IKEv2"),
                 <ResponderSignedOctets>)

where the string "Key Pad for IKEv2" is 17 ASCII characters without null termination. The shared secret can be variable length. The pad string is added so that if the shared secret is derived from a password, the IKE implementation need not store the password in cleartext, but rather can store the value prf(Shared Secret,"Key Pad for IKEv2"), which could not be used as a password equivalent for protocols other than IKEv2 🎀. As noted above, deriving the shared secret from a password is not secure. This construction is used because it is anticipated that people will do it anyway 🙈. The management interface by which the shared secret is provided MUST accept ASCII strings of at least 64 octets and MUST NOT add a null terminator before using them as shared secrets. It MUST also accept a hex encoding of the shared secret. The management interface MAY accept other encodings if the algorithm for translating the encoding to a binary string is specified 🧚.

There are two types of EAP authentication (described in Section 2.16), and each type uses different values in the AUTH computations shown above. If the EAP method is key-generating, substitute master session key (MSK) for the shared secret in the computation. For non-key-generating methods, substitute SK_pi and SK_pr, respectively, for the shared secret in the two AUTH computations 👑.


2.16. Extensible Authentication Protocol Methods

In addition to authentication using public key signatures and shared secrets, IKE supports authentication using methods defined in RFC 3748 [EAP]. Typically, these methods are asymmetric (designed for a user authenticating to a server), and they may not be mutual. For this reason, these protocols are typically used to authenticate the initiator to the responder and MUST be used in conjunction with a public-key-signature-based authentication of the responder to the initiator 🔑. These methods are often associated with mechanisms referred to as "Legacy Authentication" mechanisms 🌈.

While this document references [EAP] with the intent that new methods can be added in the future without updating this specification, some simpler variations are documented here. [EAP] defines an authentication protocol requiring a variable number of messages. Extensible Authentication is implemented in IKE as additional IKE_AUTH exchanges that MUST be completed in order to initialize the IKE SA ✨.

An initiator indicates a desire to use EAP by leaving out the AUTH payload from the first message in the IKE_AUTH exchange. (Note that the AUTH payload is required for non-EAP authentication, and is thus not marked as optional in the rest of this document.) By including an IDi payload but not an AUTH payload, the initiator has declared an identity but has not proven it 🤨. If the responder is willing to use an EAP method, it will place an Extensible Authentication Protocol (EAP) payload in the response of the IKE_AUTH exchange and defer sending SAr2, TSi, and TSr until initiator authentication is complete in a subsequent IKE_AUTH exchange. In the case of a minimal EAP method, the initial SA establishment will appear as follows:

   Initiator                         Responder
   -------------------------------------------------------------------
   HDR, SAi1, KEi, Ni  -->
                                <--  HDR, SAr1, KEr, Nr, [CERTREQ]
   HDR, SK {IDi, [CERTREQ,]
       [IDr,] SAi2,
       TSi, TSr}  -->
                                <--  HDR, SK {IDr, [CERT,] AUTH,
                                         EAP }
   HDR, SK {EAP}  -->
                                <--  HDR, SK {EAP (success)}
   HDR, SK {AUTH}  -->
                                <--  HDR, SK {AUTH, SAr2, TSi, TSr }

As described in Section 2.2, when EAP is used, each pair of IKE SA initial setup messages will have their message numbers incremented; the first pair of AUTH messages will have an ID of 1, the second will be 2, and so on 🔢.

For EAP methods that create a shared key as a side effect of authentication, that shared key MUST be used by both the initiator and responder to generate AUTH payloads in messages 7 and 8 using the syntax for shared secrets specified in Section 2.15. The shared key from EAP is the field from the EAP specification named MSK. This shared key generated during an IKE exchange MUST NOT be used for any other purpose 🫢.

EAP methods that do not establish a shared key SHOULD NOT be used, as they are subject to a number of man-in-the-middle attacks [EAPMITM] if these EAP methods are used in other protocols that do not use a server-authenticated tunnel 😱. Please see the Security Considerations section for more details. If EAP methods that do not generate a shared key are used, the AUTH payloads in messages 7 and 8 MUST be generated using SK_pi and SK_pr, respectively 🚨.

The initiator of an IKE SA using EAP needs to be capable of extending the initial protocol exchange to at least ten IKE_AUTH exchanges in the event the responder sends notification messages and/or retries the authentication prompt 💅. Once the protocol exchange defined by the chosen EAP authentication method has successfully terminated, the responder MUST send an EAP payload containing the Success message. Similarly, if the authentication method has failed, the responder MUST send an EAP payload containing the Failure message. The responder MAY at any time terminate the IKE exchange by sending an EAP payload containing the Failure message 🙅‍♀️.

Following such an extended exchange, the EAP AUTH payloads MUST be included in the two messages following the one containing the EAP Success message 🎀.

When the initiator authentication uses EAP, it is possible that the contents of the IDi payload is used only for Authentication, Authorization, and Accounting (AAA) routing purposes and selecting which EAP method to use. This value may be different from the identity authenticated by the EAP method. It is important that policy lookups and access control decisions use the actual authenticated identity 👀. Often the EAP server is implemented in a separate AAA server that communicates with the IKEv2 responder. In this case, the authenticated identity, if different from that in the IDi payload, has to be sent from the AAA server to the IKEv2 responder 💜.

2.17. Generating Keying Material for Child SAs ✨

okay so the first Child SA gets born in the IKE_AUTH exchange 👶, and any extra Child SAs are optional and show up later in CREATE_CHILD_SA exchanges 💅. Their keying material is cooked up like this:

KEYMAT = prf+(SK_d, Ni | Nr)

Ni and Nr are the nonces from the IKE_SA_INIT exchange if this request is the first Child SA being made 🌸. If it's a later one, they're the fresh Ni and Nr from that CREATE_CHILD_SA exchange 🦋.

When a CREATE_CHILD_SA exchange also includes an optional Diffie-Hellman exchange 🔥, the recipe changes to:

KEYMAT = prf+(SK_d, g^ir (new) | Ni | Nr )

Here g^ir (new) is the shared secret from the ephemeral Diffie-Hellman exchange in that CREATE_CHILD_SA exchange 💜. It's an octet string in big endian order, padded with zeros in the high-order bits if needed so it matches the length of the modulus ✨.

Now the fun part: one Child SA negotiation can produce more than one Security Association 👑. ESP and AH SAs come as pairs (one per direction), so those two get made together in one go 🎀. A Child SA negotiation might also include future IPsec protocols on top of, or instead of, ESP or AH. ROHC_INTEG is one example, described in [ROHCV2] 🧚. Either way, the keying material for each Child SA MUST be pulled from the expanded KEYMAT using these rules:

  • All keys for SAs carrying data from the initiator to the responder are taken before SAs going from the responder to the initiator. 🍓
  • If multiple IPsec protocols are negotiated, keying material for each Child SA is taken in the order in which the protocol headers will appear in the encapsulated packet. 🌈
  • If an IPsec protocol requires multiple keys, the order in which they are taken from the SA's keying material needs to be described in the protocol's specification. For ESP and AH, [IPSECARCH] defines the order, namely: the encryption key (if any) MUST be taken from the first bits and the integrity key (if any) MUST be taken from the remaining bits. 🔑

Every cryptographic algorithm eats a fixed number of bits of keying material 🍰. That number is either specified as part of the algorithm or negotiated in SA payloads. See Section 2.13 for the description of key lengths, and Section 3.3.5 for the definition of the Key Length transform attribute 💖.

2.18. Rekeying IKE SAs Using a CREATE_CHILD_SA Exchange 🔄

The CREATE_CHILD_SA exchange can be used to rekey an existing IKE SA (see Sections 1.3.2 and 2.8) 🫶. The new initiator and responder SPIs go in the SPI fields of the Proposal structures inside the Security Association (SA) payloads, not in the SPI fields of the IKE header 🪄. The TS payloads are left out when you're rekeying an IKE SA 🙈. SKEYSEED for the new IKE SA is computed using SK_d from the existing IKE SA:

SKEYSEED = prf(SK_d (old), g^ir (new) | Ni | Nr)

g^ir (new) is the shared secret from the ephemeral Diffie-Hellman exchange of this CREATE_CHILD_SA exchange, as an octet string in big endian order, padded with zeros if needed to match the length of the modulus 💫. Ni and Nr are the two nonces, stripped of any headers ✨.

The old and new IKE SA are allowed to have picked different PRFs 🧁. But the rekeying exchange belongs to the old IKE SA, so it's the old IKE SA's PRF that generates SKEYSEED 💅.

Why rekey the IKE SA at all? The main reason is so that if old keying material gets compromised, it tells an attacker nothing about the current keys, and vice versa 🛡️. For that to work, implementations MUST perform a new Diffie-Hellman exchange when rekeying the IKE SA 💥. So an initiator MUST NOT propose the value "NONE" for the Diffie-Hellman transform, and a responder MUST NOT accept such a proposal 🙅‍♀️. That means a successful exchange rekeying the IKE SA always includes the KEi/KEr payloads 💜.

The new IKE SA MUST reset its message counters to 0 🔢.

SK_d, SK_ai, SK_ar, SK_ei, and SK_er are computed from SKEYSEED as specified in Section 2.14, using SPIi, SPIr, Ni, and Nr from the new exchange, and using the new IKE SA's PRF 🌸.

2.19. Requesting an Internal Address on a Remote Network 🏠

Most commonly, this happens in the endpoint-to-security-gateway scenario 🚪. An endpoint might need an IP address inside the network protected by the security gateway, and that address gets assigned dynamically 🎟️. You can ask for this temporary address in any request to create a Child SA (including the implicit request in message 3) by including a CP payload 🫧. Heads up though, it's usual to only assign one IP address during the IKE_AUTH exchange 🙃. That address sticks around at least until the IKE SA gets deleted 🔒.

This function gives address allocation to an IPsec Remote Access Client (IRAC) that's trying to tunnel into a network protected by an IPsec Remote Access Server (IRAS) 🌐. Since the IKE_AUTH exchange creates an IKE SA and a Child SA, the IRAC MUST request the IRAS-controlled address (and optionally other info about the protected network) in the IKE_AUTH exchange 📮. The IRAS may get an address for the IRAC from all sorts of places, like a DHCP/BOOTP (Bootstrap Protocol) server or its own address pool 🏊‍♀️.

   Initiator                         Responder
   -------------------------------------------------------------------
    HDR, SK {IDi, [CERT,]
       [CERTREQ,] [IDr,] AUTH,
       CP(CFG_REQUEST), SAi2,
       TSi, TSr}  -->
                                <--  HDR, SK {IDr, [CERT,] AUTH,
                                         CP(CFG_REPLY), SAr2,
                                         TSi, TSr}

In all cases, the CP payload MUST be inserted before the SA payload 🎀. In variations of the protocol with multiple IKE_AUTH exchanges, the CP payloads MUST be inserted in the messages containing the SA payloads 🧩.

CP(CFG_REQUEST) MUST contain at least an INTERNAL_ADDRESS attribute (either IPv4 or IPv6) 🌟, but it MAY contain any number of additional attributes the initiator wants sent back in the response 💌.

Here's an example, message from initiator to responder:

   CP(CFG_REQUEST)=
     INTERNAL_ADDRESS()
   TSi = (0, 0-65535,0.0.0.0-255.255.255.255)
   TSr = (0, 0-65535,0.0.0.0-255.255.255.255)
NOTE: Traffic Selectors contain (protocol, port range, address range). 📝

And the message from responder to initiator:

   CP(CFG_REPLY)=
     INTERNAL_ADDRESS(192.0.2.202)
     INTERNAL_NETMASK(255.255.255.0)
     INTERNAL_SUBNET(192.0.2.0/255.255.255.0)
   TSi = (0, 0-65535,192.0.2.202-192.0.2.202)
   TSr = (0, 0-65535,192.0.2.0-192.0.2.255)

All returned values are implementation dependent 🤷‍♀️. As you can see in the example above, the IRAS MAY also send other attributes that weren't in CP(CFG_REQUEST), and it MAY ignore the non-mandatory attributes it doesn't support 🫶.

The responder MUST NOT send a CFG_REPLY without having first received a CP(CFG_REQUEST) from the initiator 🚫. The reason is that we don't want the IRAS doing an unnecessary configuration lookup if the IRAC can't process the REPLY anyway 🙈.

Now for the tricky case 😬. If the IRAS's configuration requires that CP be used for a given identity IDi, but the IRAC never sent a CP(CFG_REQUEST), then the IRAS MUST fail the request and terminate the Child SA creation with a FAILED_CP_REQUIRED error 🛑. FAILED_CP_REQUIRED is not fatal to the IKE SA. It just makes the Child SA creation fail 💁‍♀️. The initiator can fix this by later starting a new Configuration payload request 🔁. There's no associated data in the FAILED_CP_REQUIRED error 🫧.

2.20. Requesting the Peer's Version 🔍

An IKE peer that wants to ask about the other peer's IKE software version information MAY use the method below 🕵️‍♀️. This is an example of a configuration request inside an INFORMATIONAL exchange, after the IKE SA and first Child SA have been created 🎀.

An IKE implementation MAY decline to give out version information before authentication, or even after authentication, in case some implementation is known to have a security weakness 🙊. In that case, it MUST either return an empty string or no CP payload if CP is not supported 🫡.

   Initiator                         Responder
   -------------------------------------------------------------------
   HDR, SK{CP(CFG_REQUEST)}  -->
                                <--  HDR, SK{CP(CFG_REPLY)}
   CP(CFG_REQUEST)=
     APPLICATION_VERSION("")
   CP(CFG_REPLY) APPLICATION_VERSION("foobar v1.3beta, (c) Foo Bar
     Inc.")

2.21. Error Handling 🚨

There are a lot of kinds of errors that can happen during IKE processing 😵‍💫. The general rule: if a request comes in badly formatted, or it's unacceptable for policy reasons (like no matching cryptographic algorithms), the response contains a Notify payload saying what went wrong 📣. Whether or not you send that response depends on whether there's an authenticated IKE SA 🔐.

If there's an error parsing or processing a response packet, the general rule is to NOT send back any error message 🙅‍♀️. Responses shouldn't generate new requests, and a new request would be the only way to send an error message back anyway 🔄. Errors like this in response packets should still make the recipient clean up its IKE state, for example by sending a Delete for a bad SA 🧹.

Only authentication failures (AUTHENTICATION_FAILED and EAP failure) and malformed messages (INVALID_SYNTAX) lead to deleting the IKE SA without needing an explicit INFORMATIONAL exchange carrying a Delete payload 💀. Other error conditions MAY require such an exchange if policy says so 📋. If the exchange ends with EAP Failure, an AUTHENTICATION_FAILED notification is NOT sent 🙈.

2.21.1. Error Handling in IKE_SA_INIT 🥺

Errors that happen before a cryptographically protected IKE SA is established need to be handled very carefully 🧐. It's a trade-off: you want to help the peer diagnose a problem by responding to the error, but you also don't want to be part of a DoS attack based on forged messages 🛡️.

In an IKE_SA_INIT exchange, any error notification causes the exchange to fail 🙅‍♀️. Some error notifications, like COOKIE, INVALID_KE_PAYLOAD, or INVALID_MAJOR_VERSION, may lead to a successful exchange later 🌈. Since all error notifications are completely unauthenticated, the recipient should keep trying for some time before giving up ⏳. The recipient should not act right away based on the error notification unless corrective actions are defined in this specification, like for COOKIE, INVALID_KE_PAYLOAD, and INVALID_MAJOR_VERSION 🫶.

2.21.2. Error Handling in IKE_AUTH ✨

okay so any error in an IKE_AUTH exchange that makes authentication fail, for whatever reason (wrong shared secret, invalid ID, a certificate issuer nobody trusts, a cert that's revoked or expired, etc.) SHOULD result in an AUTHENTICATION_FAILED notification 🙅‍♀️. If the error happened on the responder, that notification comes back inside the protected response, and it's usually the only payload in there 💅. The IKE_AUTH messages are encrypted and integrity protected, but the peer getting this notification hasn't authenticated the other end yet, so it has to treat the info with caution 👀 bestie, not everything is trustworthy yet 🫶.

If the error happens on the initiator, the notification MAY be sent back in a separate INFORMATIONAL exchange, usually with no other payloads 📩. This is the exception to the general "don't start new exchanges because of errors in responses" rule 🙈.

⚠️ Heads up: request messages with an unsupported critical payload, or where the whole message is malformed (not just bad payload contents), MUST be rejected in their entirety, and MUST only lead to an UNSUPPORTED_CRITICAL_PAYLOAD or INVALID_SYNTAX Notification sent as a response. The receiver should not verify the payloads related to authentication in this case.

If authentication succeeded in the IKE_AUTH exchange, the IKE SA is established 🎉. Establishing the Child SA or requesting configuration information can still fail though, and that failure does not automatically delete the IKE SA. A responder may include all the authentication payloads (IDr, CERT, and AUTH) while sending error notifications for the piggybacked exchanges (FAILED_CP_REQUIRED, NO_PROPOSAL_CHOSEN, and so on), and the initiator MUST NOT fail the authentication because of this 🙌. The initiator MAY, of course, delete such an IKE SA later for reasons of policy 🧹.

In an IKE_AUTH exchange, or in the INFORMATIONAL exchange right after it (in case an error happened while processing a response to IKE_AUTH), the UNSUPPORTED_CRITICAL_PAYLOAD, INVALID_SYNTAX, and AUTHENTICATION_FAILED notifications are the only ones that cause the IKE SA to be deleted or not created, without a Delete payload 💀. Extension documents can define new error notifications with these semantics, but they MUST NOT use them unless the peer has been shown to understand them, such as by using the Vendor ID payload 🪪.


2.21.3. Error Handling after IKE SA is Authenticated 🛡️

After the IKE SA is authenticated, all requests having errors MUST result in a response notifying about the error 📬.

In normal situations, a valid response from one peer shouldn't cause an error on the other peer, so there's no real reason to send error messages except as a response 🙃. Sending those errors as an INFORMATIONAL exchange could trigger more errors and get stuck in loops, so such errors SHOULD NOT be sent 🔁. If the errors show that the peers don't have the same state, it might be smart to delete the IKE SA, clean up, and start over 🧽.

If a peer parsing a request notices it's badly formatted (after it has passed the message authentication code checks and window checks) and returns an INVALID_SYNTAX notification, that error is fatal in both peers 💥. The IKE SA gets deleted without needing an explicit Delete payload, no drama 💅.


2.21.4. Error Handling Outside IKE SA 🌙

A node needs to limit how fast it sends messages in response to unprotected messages 🐢.

If a node gets a message on UDP port 500 or 4500 outside the context of any IKE SA it knows about (and the message isn't a request to start an IKE SA), it might be the aftermath of a recent crash 👻. If the message is marked as a response, the node can audit the suspicious event but MUST NOT respond 🤐. If the message is marked as a request, the node can audit the event and MAY send a response 📝. If it does respond, the response MUST be sent to the IP address and port it came from, with the same IKE SPIs and the Message ID copied 🎯. The response MUST NOT be cryptographically protected and MUST contain an INVALID_IKE_SPI Notify payload 🧾. That notification says an IKE message came in with an unrecognized destination SPI, which usually means the recipient rebooted and forgot its IKE SA 🔄.

A peer that gets such an unprotected Notify payload MUST NOT respond and MUST NOT change the state of any existing SAs 🚫. The message could be a forgery, or a response that a genuine correspondent was tricked into sending 🕵️‍♀️. A node should treat such a message (and also a network message like ICMP destination unreachable) as a hint that there might be problems with SAs to that IP address, and should start a liveness check for any such IKE SA 👂. An implementation SHOULD limit how often it runs these tests so it doesn't get tricked into joining a DoS attack 🛑.

If an error happens outside the context of an IKE request (e.g., the node is getting ESP messages on a nonexistent SPI), the node SHOULD start an INFORMATIONAL exchange with a Notify payload describing the problem 📣.

A node that gets a suspicious message from an IP address (and port, if NAT traversal is used) it has an IKE SA with SHOULD send an IKE Notify payload in an IKE INFORMATIONAL exchange over that SA 🫶. The recipient MUST NOT change the state of any SAs because of it, but it may want to audit the event to help diagnose malfunctions 🔍.


2.22. IPComp 🗜️

Use of IP Compression [IP-COMP] can be negotiated as part of setting up a Child SA. While IP Compression adds an extra header to each packet and a compression parameter index (CPI), the virtual "compression association" has no life outside the ESP or AH SA that contains it 🧃. Compression associations disappear when the matching ESP or AH SA goes away 👋. They aren't explicitly mentioned in any Delete payload 🙈.

Negotiating IP Compression is separate from negotiating the cryptographic parameters for a Child SA 🔀. A node requesting a Child SA MAY advertise support for one or more compression algorithms through one or more Notify payloads of type IPCOMP_SUPPORTED ✨. That Notify can only be included in a message with an SA payload that negotiates a Child SA, and it shows the sender is willing to use IPComp on this SA 🤝. The response MAY indicate acceptance of a single compression algorithm with a Notify payload of type IPCOMP_SUPPORTED 💌. These payloads MUST NOT occur in messages that don't contain SA payloads 🚷.

The data for this Notify holds a two-octet IPComp CPI, then a one-octet Transform ID, and optionally attributes whose length and format are defined by that Transform ID 🧩. A message proposing an SA may contain multiple IPCOMP_SUPPORTED notifications to show several supported algorithms, while a message accepting an SA may contain at most one 🔢.

The Transform IDs are listed here. The values in the table below are only current as of the publication date of RFC 4306. Other values may have been added since then, or will be added after this document is published. Readers should refer to [IKEV2IANA] for the latest values 📚.

Name              Number   Defined In
-------------------------------------
IPCOMP_OUI        1
IPCOMP_DEFLATE    2        RFC 2394
IPCOMP_LZS        3        RFC 2395
IPCOMP_LZJH       4        RFC 3051

Discussion has happened about allowing multiple compression algorithms to be accepted, and having different ones for the two directions of a Child SA 🤔. Still, implementations of this specification MUST NOT accept an IPComp algorithm that wasn't proposed, MUST NOT accept more than one, and MUST NOT compress using an algorithm other than the one proposed and accepted when the Child SA was set up 🚫🚫🚫.

A side effect of separating IPComp negotiation from the cryptographic parameters is that you can't propose several cryptographic suites and offer IP Compression with some of them but not others 🙃.

In some cases, Robust Header Compression (ROHC) may be a better fit than IP Compression 🌸. [ROHCV2] defines how to use ROHC with IKEv2 and IPsec 💖.

2.23. NAT Traversal 🌸

okay so NAT gateways are lowkey a controversial topic 💀. This part gives you the basics on what they are and how they're likely to mess with IKE traffic 👀. A lot of people think NATs are evil and that we shouldn't design protocols to make them work better, which, valid 😤. IKEv2 still has some unintuitive processing rules so NATs are more likely to cooperate 🫶.

NATs exist mostly because IPv4 addresses are scarce 😭, though there are other reasons too ✨. Nodes "behind" a NAT have IP addresses that aren't globally unique 🙈. Those addresses come from a space that's unique inside the network behind the NAT, but that same space is likely to get reused by nodes behind other NATs. So generally, nodes behind a NAT can talk to other nodes behind the same NAT and to nodes with globally unique addresses, but not to nodes behind other NATs. There are exceptions, bestie 🦋. When those nodes connect out to the real Internet, the NAT gateway "translates" the IP source address into one that will route back to the gateway. Messages coming back from the Internet get their destination addresses "translated" to the internal address that routes the packet to the right endnode 🧚.

NATs are designed to be "transparent" to endnodes 💅. Neither the software on the node behind the NAT nor the node on the Internet needs modifying to communicate through the NAT. Some protocols make that transparency way harder than others. Protocols that put endpoint IP addresses inside their payloads will break unless the NAT gateway understands the protocol and rewrites the internal references too, not just the ones in the headers 💀. That kind of knowledge is inherently unreliable, is a network layer violation, and often causes subtle problems 😭.

Opening an IPsec connection through a NAT comes with its own special drama 🔥. If the connection runs in transport mode, changing the IP addresses on packets makes the checksums fail, and the NAT can't fix them because they're cryptographically protected 🙅. Even in tunnel mode there are routing problems, since transparently translating the addresses of AH and ESP packets needs special logic in the NAT, and that logic is heuristic and unreliable 🫠. So IKEv2 uses UDP encapsulation of IKE and ESP packets 🎀. It's a bit less efficient, but way easier for NATs to process. Firewalls might also be set up to pass UDP-encapsulated IPsec traffic but not plain, unencapsulated ESP/AH, or the other way around 🧱.

It's super common for NATs to translate TCP and UDP port numbers as well as addresses, and to use the port numbers of inbound packets to decide which internal node gets a given packet 🍓. That's why, even though IKE packets MUST be sent to and from UDP port 500 or 4500, they MUST be accepted coming from any port, and responses MUST be sent to the port they came from ✨. Ports can get modified as packets pass through NATs, after all. Similarly, the IP addresses of the IKE endpoints are generally left out of the IKE payloads, because those payloads are cryptographically protected and NATs couldn't transparently modify them 🔐.

Port 4500 is reserved for UDP-encapsulated ESP and IKE 🌈. An IPsec endpoint that discovers a NAT between it and its correspondent (more on that below) MUST send all subsequent traffic from port 4500, which NATs shouldn't treat specially the way they might with port 500 👑.

An initiator can use port 4500 for both IKE and ESP, whether or not there's a NAT, even right at the beginning of IKE 💜. When either side is using port 4500, sending ESP with UDP encapsulation is not required, but understanding received UDP-encapsulated ESP packets is required 🫶. UDP encapsulation MUST NOT be done on port 500 🚫. If Network Address Translation Traversal (NAT-T) is supported (that is, if NAT_DETECTION_*_IP payloads were exchanged during IKE_SA_INIT), all devices MUST be able to receive and process both UDP-encapsulated ESP and non-UDP-encapsulated ESP packets at any time 🦋. Either side can decide whether or not to use UDP encapsulation for ESP, regardless of what the other side chose. However, if a NAT is detected, both devices MUST use UDP encapsulation for ESP 🔥.

The specific requirements for supporting NAT traversal [NATREQ] are listed below. Support for NAT traversal is optional. In this section only, requirements listed as MUST apply only to implementations supporting NAT traversal 📝.

  • Both the IKE initiator and responder MUST include in their IKE_SA_INIT packets Notify payloads of type NAT_DETECTION_SOURCE_IP and NAT_DETECTION_DESTINATION_IP. Those payloads can be used to detect if there's NAT between the hosts, and which end is behind the NAT. They go in the IKE_SA_INIT packets just after the Ni and Nr payloads (before the optional CERTREQ payload) 🧩.
  • The data for the NAT_DETECTION_SOURCE_IP notification is a SHA-1 digest of the SPIs (in the order they appear in the header), IP address, and port from which this packet was sent. There MAY be multiple NAT_DETECTION_SOURCE_IP payloads in a message if the sender doesn't know which of several network attachments will be used to send the packet 🌐.
  • The data for the NAT_DETECTION_DESTINATION_IP notification is a SHA-1 digest of the SPIs (in the order they appear in the header), IP address, and port to which this packet was sent 📬.
  • The recipient of either the NAT_DETECTION_SOURCE_IP or NAT_DETECTION_DESTINATION_IP notification MAY compare the supplied value to a SHA-1 hash of the SPIs, source or recipient IP address (respectively), address, and port. If they don't match, it SHOULD enable NAT traversal. If the NAT_DETECTION_SOURCE_IP hash mismatches all of the NAT_DETECTION_SOURCE_IP payloads received, the recipient MAY reject the connection attempt if NAT traversal isn't supported. If the NAT_DETECTION_DESTINATION_IP hash mismatches, that means the system receiving the NAT_DETECTION_DESTINATION_IP payload is behind a NAT, and that system SHOULD start sending keepalive packets as defined in [UDPENCAPS]. Alternately, it MAY reject the connection attempt if NAT traversal isn't supported 🕵️.
  • If none of the NAT_DETECTION_SOURCE_IP payload(s) received matches the expected value of the source IP and port found in the IP header of the packet containing the payload, it means the system sending those payloads is behind a NAT. (Someone along the route changed the source address of the original packet to match the NAT box's address 🫣.) In this case, the system receiving the payloads should allow dynamic updates of the other system's IP address, as described later.
  • The IKE initiator MUST check the NAT_DETECTION_SOURCE_IP or NAT_DETECTION_DESTINATION_IP payloads if present, and if they don't match the addresses in the outer packet, it MUST tunnel all future IKE and ESP packets associated with this IKE SA over UDP port 4500 🚇.
  • To tunnel IKE packets over UDP port 4500, the IKE header has four octets of zero prepended, and the result immediately follows the UDP header. To tunnel ESP packets over UDP port 4500, the ESP header immediately follows the UDP header. Since the first four octets of the ESP header contain the SPI, and the SPI cannot validly be zero, it's always possible to tell ESP and IKE messages apart 🧠.
  • Implementations MUST process received UDP-encapsulated ESP packets even when no NAT was detected 💪.
  • The original source and destination IP addresses needed for the transport mode TCP and UDP packet checksum fixup (see [UDPENCAPS]) come from the Traffic Selectors associated with the exchange. For transport mode NAT traversal, the Traffic Selectors MUST contain exactly one IP address, which is then used as the original IP address. This is covered in greater detail in Section 2.23.1 📚.
  • Sometimes a NAT box decides to remove mappings that are still alive (for example, the keepalive interval is too long, or the NAT box gets rebooted) 😬. A host can tell this is happening if it receives a packet whose integrity protection validates, but that has a different port, address, or both from the one associated with the SA in the validated packet. When such a validated packet shows up, a host that doesn't support other recovery methods, like IKEv2 Mobility and Multihoming (MOBIKE) [MOBIKE], and that isn't behind a NAT, SHOULD send all packets (including retransmission packets) to the IP address and port in the validated packet. It SHOULD also store that as the new address and port combination for the SA (that is, it SHOULD dynamically update the address) 🔄. A host behind a NAT SHOULD NOT do this type of dynamic address update if a validated packet has different port and/or address values, because it opens a possible DoS attack (like letting an attacker break the connection with a single packet) 🚨. Also, dynamic address updates should only be done in response to a new packet, otherwise an attacker can revert the addresses using old replayed packets 🙅‍♀️. Because of this, dynamic updates can only be done safely if replay protection is enabled 🔐. When IKEv2 is used with MOBIKE, dynamically updating the addresses described above interferes with MOBIKE's way of recovering from the same situation. See Section 3.8 of [MOBIKE] for more information 🦋.

2.23.1. Transport Mode NAT Traversal ✨

okay bestie, transport mode plus NAT traversal is a LOT, so grab a snack 🍓. Transport mode with NAT Traversal needs special handling of the Traffic Selectors used in IKEv2, and the full picture looks like this 🦋:

+------+        +------+            +------+         +------+
|Client| IP1    | NAT  | IPN1  IPN2 | NAT  |     IP2 |Server|
|node  |<------>|  A   |<---------->|  B   |<------->|      |
+------+        +------+            +------+         +------+

Every other scenario is just a simplified version of this messy one, so we're going full drama 🎀.

In this scenario there are two address-translating NATs, NAT A and NAT B 🙈. NAT A is a dynamic NAT that maps the client's source address IP1 to IPN1. NAT B is a static NAT set up so that connections coming to the IPN2 address get mapped to the gateway's address IP2. That means the IPN2 destination gets mapped to IP2, which lets the client reach the server by connecting to IPN2 ✨. NAT B doesn't have to be static, but the client needs to know how to connect to the server, and it can only do that if it somehow knows NAT B's outer address, which is IPN2. If NAT B is static, that address can just be put in the client's configuration. Another option is finding it with some other protocol (like DNS), but that's outside the scope of IKEv2, so not our problem here 💅.

In this scenario, both the client and server are configured to use transport mode for the traffic originating from the client node and destined to the server 🫶.

When the client starts creating the IKEv2 SA and Child SA for sending traffic to the server, it may have a triggering packet with source IP address IP1 and destination IP address IPN2. Its Peer Authorization Database (PAD) and SPD need to have a configuration matching those addresses (or wildcard entries covering them) 💖.

Because this is transport mode, it uses exactly the same addresses as the Traffic Selectors and the outer IP address of the IKE packets. For transport mode, it MUST use exactly one IP address in the TSi and TSr payloads. It can have multiple Traffic Selectors if it has, for example, multiple port ranges it wants to negotiate. But all TSi entries must use the IP1-IP1 range as the IP addresses, and all TSr entries must have the IPN2-IPN2 range as IP addresses. The first Traffic Selector of TSi and TSr SHOULD have very specific Traffic Selectors, including protocol and port numbers, such as the ones from the packet that triggered the request 🎯.

NAT A then replaces the source address of the IKE packet from IP1 to IPN1, and NAT B replaces the destination address of the IKE packet from IPN2 to IP2. So when the packet arrives at the server it still has exactly the same Traffic Selectors the client sent, but the IP address of the IKE packet has been replaced by IPN1 and IP2 🦋.

When the server receives this packet, it normally looks in the Peer Authorization Database (PAD) described in RFC 4301 [IPSECARCH] based on the ID, and then searches the SPD based on the Traffic Selectors. Because IP1 doesn't really mean anything to the server (it's the address the client has behind the NAT), it's useless to do a lookup based on that if transport mode is used 🙃. On the other hand, the server can't know whether transport mode is allowed by its policy until it finds the matching SPD entry.

In this case, the server should first check that the initiator requested transport mode, and then do address substitution on the Traffic Selectors. It needs to store the old Traffic Selector IP addresses first, so they can be used later for the incremental checksum fixup. The IP address in the TSi can be stored as the original source address, and the IP address in the TSr can be stored as the original destination address. After that, if the other end was detected as being behind a NAT, the server replaces the IP address in the TSi payloads with the IP address from the source address of the IKE packet it received (so it replaces IP1 in TSi with IPN1). If the server's own end was detected to be behind a NAT, it replaces the IP address in the TSr payloads with the IP address from the destination address of the IKE packet it received (so it replaces IPN2 in TSr with IP2) 🔥.

After this substitution, the Traffic Selectors and the IKE UDP source and destination addresses look the same, and the server does an SPD lookup based on those new Traffic Selectors. If an entry is found and it allows transport mode, that entry gets used. If an entry is found but it does NOT allow transport mode, the server MAY undo the address substitution and redo the SPD lookup using the original Traffic Selectors. If that second lookup succeeds, the server creates an SA in tunnel mode using the real Traffic Selectors sent by the other end 🌈.

This address substitution in transport mode is needed because the SPD gets looked up using the addresses the local host will actually see. It also makes sure the Security Association Database (SAD) entries for the tunnel exit checks and return packets get added using the addresses as seen by the local operating system stack 🧚.

The most common case is that the server's SPD contains wildcard entries matching any addresses, but this also allows making different SPD entries, for example, for different known NATs' outer addresses 💜.

After the SPD lookup, the server does Traffic Selector narrowing based on the SPD entry it found. It uses the already-substituted Traffic Selectors again, so it sends back Traffic Selectors with IPN1 and IP2 as their IP addresses. It can still narrow down the protocol number or port ranges used by the Traffic Selectors. The SAD entry created for the Child SA has the addresses as seen by the server, namely IPN1 and IP2 👑.

When the client receives the server's response for the Child SA, it does similar processing. If the transport mode SA was created, the client can store the original returned Traffic Selectors as the original source and destination addresses. Then it replaces the IP addresses in the Traffic Selectors with the ones from the IP header of the IKE packet: IPN1 becomes IP1, and IP2 becomes IPN2. After that, it uses those Traffic Selectors when verifying the SA against the Traffic Selectors it sent, and when installing the SAD entry 🎀.

Here's a summary of the rules for NAT traversal in transport mode 💅:

For the client proposing transport mode:

  • The TSi entries MUST have exactly one IP address, and that MUST match the source address of the IKE SA.
  • The TSr entries MUST have exactly one IP address, and that MUST match the destination address of the IKE SA.
  • The first TSi and TSr Traffic Selectors SHOULD have very specific Traffic Selectors, including protocol and port numbers, such as the ones from the packet that triggered the request.
  • There MAY be multiple TSi and TSr entries.
  • If transport mode for the SA was selected (that is, if the server included USE_TRANSPORT_MODE notification in its response):
    • Store the original Traffic Selectors as the received source and destination address.
    • If the server is behind a NAT, substitute the IP address in the TSr entries with the remote address of the IKE SA.
    • If the client is behind a NAT, substitute the IP address in the TSi entries with the local address of the IKE SA.
    • Do address substitution before using those Traffic Selectors for anything other than storing their original content. This includes verification that Traffic Selectors were narrowed correctly by the other end, creation of the SAD entry, and so on.

For the responder, when transport mode is proposed by the client:

  • Store the original Traffic Selector IP addresses as the received source and destination address, in case undoing the address substitution is needed, to use as the "real source and destination address" specified by [UDPENCAPS], and for TCP/UDP checksum fixup.
  • If the client is behind a NAT, substitute the IP address in the TSi entries with the remote address of the IKE SA.
  • If the server is behind a NAT, substitute the IP address in the TSr entries with the local address of the IKE SA.
  • Do PAD and SPD lookup using the ID and substituted Traffic Selectors.
  • If no SPD entry was found, or if the SPD entry found does not allow transport mode, undo the Traffic Selector substitutions. Do PAD and SPD lookup again using the ID and original Traffic Selectors, but also search for a tunnel mode SPD entry (that is, fall back to tunnel mode).
  • However, if a transport mode SPD entry was found, do normal traffic selection narrowing based on the substituted Traffic Selectors and SPD entry. Use the resulting Traffic Selectors when creating SAD entries, and when sending Traffic Selectors back to the client.

2.24. Explicit Congestion Notification (ECN) 🦋

When IPsec tunnels behave as originally specified in [IPSECARCH-OLD], ECN usage is NOT appropriate for the outer IP headers, because tunnel decapsulation processing discards ECN congestion indications to the detriment of the network 😭. ECN support for IKEv1-based IPsec tunnels requires multiple operating modes and negotiation (see [ECN]). IKEv2 simplifies this whole mess by requiring that ECN be usable in the outer IP headers of all tunnel mode Child SAs created by IKEv2. Specifically, tunnel encapsulators and decapsulators for all tunnel mode SAs created by IKEv2 MUST support the ECN full-functionality option for tunnels specified in [ECN], and MUST implement the tunnel encapsulation and decapsulation processing specified in [IPSECARCH] to prevent discarding of ECN congestion indications 👑.

2.25. Exchange Collisions 💥

Because IKEv2 exchanges can be initiated by either peer, it's possible that two exchanges affecting the same SA partly overlap 🙈. This can lead to a situation where the SA state information is temporarily out of sync, and a peer can receive a request it can't process in a normal fashion.

Obviously, using a window size greater than 1 leads to more complex situations, especially if requests are processed out of order. This section focuses on problems that can come up even with a window size of 1, and recommends solutions 🧠.

A TEMPORARY_FAILURE notification SHOULD be sent when a peer receives a request that cannot be completed due to a temporary condition, such as a rekeying operation. When a peer receives a TEMPORARY_FAILURE notification, it MUST NOT immediately retry the operation. It MUST wait so that the sender can complete whatever operation caused the temporary condition. The recipient MAY retry the request one or more times over a period of several minutes. If a peer keeps receiving TEMPORARY_FAILURE on the same IKE SA after several minutes, it SHOULD conclude that the state information is out of sync and close the IKE SA 🫠.

A CHILD_SA_NOT_FOUND notification SHOULD be sent when a peer receives a request to rekey a Child SA that doesn't exist. The SA the initiator tried to rekey is indicated by the SPI field in the Notify payload, which is copied from the SPI field in the REKEY_SA notification. A peer that receives a CHILD_SA_NOT_FOUND notification SHOULD silently delete the Child SA (if it still exists) and send a request to create a new Child SA from scratch (if the Child SA doesn't exist yet) 💀.

2.25.1. Collisions while Rekeying or Closing Child SAs 💥

Okay so, if a peer gets a request to rekey a Child SA that it's currently trying to close, it SHOULD reply with TEMPORARY_FAILURE 🙅‍♀️. If it gets a request to rekey a Child SA that it's already rekeying, it SHOULD reply as usual, and SHOULD prepare to close redundant SAs later based on the nonces (see Section 2.8.1) 🔁. And if the Child SA doesn't even exist, it SHOULD reply with CHILD_SA_NOT_FOUND 🫥.

Now for close requests 🗑️. If a peer gets a request to close a Child SA it's currently trying to close, it SHOULD reply without a Delete payload (see Section 1.4.1). If it gets a request to close a Child SA it's currently rekeying, it SHOULD reply as usual, with a Delete payload, no cap 💅. And if the Child SA doesn't exist, it SHOULD reply without a Delete payload.

Last one, and it's a big deal ✨. If a peer gets a request to rekey the IKE SA, and it's currently creating, rekeying, or closing a Child SA of that IKE SA, it SHOULD reply with TEMPORARY_FAILURE. Literally the whole IKE SA is busy, so it's a no-go 🙃.

2.25.2. Collisions while Rekeying or Closing IKE SAs 🫠

If a peer gets a request to rekey an IKE SA that it's currently rekeying, it SHOULD reply as usual, and SHOULD prepare to close redundant SAs and move inherited Child SAs later based on the nonces (see Section 2.8.2) 🧚. But if it's currently trying to close that IKE SA, it SHOULD reply with TEMPORARY_FAILURE. Not me being dramatic, it's just the rule 💀.

For close requests on an IKE SA: if the peer is currently rekeying it, it SHOULD reply as usual, and forget about its own rekeying request 🫶. If the peer is currently trying to close it too, it SHOULD reply as usual, and forget about its own close request. Iykyk, it's a whole mutual-letting-go moment 🌸.

And if a peer gets a request to create or rekey a Child SA while it's rekeying the IKE SA, it SHOULD reply with TEMPORARY_FAILURE. But if it gets a request to delete a Child SA while it's rekeying the IKE SA, it SHOULD reply as usual, with a Delete payload 🎀.


3. Header and Payload Formats 📦

In the tables in this section, some cryptographic primitives and configuration attributes are marked as "UNSPECIFIED" 🚫. These are items with no known specifications, so interoperability is currently impossible. A future specification may describe their use, but until one exists, implementations SHOULD NOT attempt to use items marked as "UNSPECIFIED" in implementations that are meant to be interoperable 🙏.

3.1. The IKE Header 🎀

IKE messages use UDP ports 500 and/or 4500, with one IKE message per UDP datagram 🦋. Basically everything from the start of the packet through the UDP header is mostly ignored, except that the IP addresses and UDP ports get reversed and used for return packets. When sent on UDP port 500, IKE messages begin right after the UDP header. When sent on UDP port 4500, IKE messages get four octets of zero prepended to them. Those four zero octets are not part of the IKE message, and they're not counted in any of the length fields or checksums IKE defines 🫧.

Each IKE message starts with the IKE header, which this document calls HDR 📝. After the header come one or more IKE payloads, and each one is identified by a "Next Payload" field in the payload before it. So you follow the "Next Payload" field in the IKE header to find the first payload, then keep following the "Next Payload" field in each payload until you hit a "Next Payload" of zero, which means nothing else follows 🧭. If you find a payload of type "Encrypted", you decrypt it and parse its contents as more payloads. Now the rules: an Encrypted payload MUST be the last payload in a packet, and an Encrypted payload MUST NOT contain another Encrypted payload 🔒. No nesting, bestie.

The responder's SPI in the header identifies an instance of an IKE Security Association. So one IKE instance can multiplex separate sessions with multiple peers, including multiple sessions with the same peer 🌈.

All multi-octet fields representing integers are laid out in big endian order (also known as "most significant byte first", or "network byte order") 🔢.

The format of the IKE header is shown in Figure 4 👇.

                    1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       IKE SA Initiator's SPI                  |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       IKE SA Responder's SPI                  |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Next Payload | MjVer | MnVer | Exchange Type |     Flags     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                          Message ID                           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                            Length                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                 Figure 4:  IKE Header Format
  • Initiator's SPI (8 octets) 🌱: a value chosen by the initiator to identify a unique IKE Security Association. This value MUST NOT be zero.
  • Responder's SPI (8 octets) 🌷: a value chosen by the responder to identify a unique IKE Security Association. This value MUST be zero in the first message of an IKE initial exchange (including repeats of that message including a cookie).
  • Next Payload (1 octet) 🧩: indicates the type of payload that immediately follows the header. The format and value of each payload are defined below.
  • Major Version (4 bits) 👑: indicates the major version of the IKE protocol in use. Implementations based on this version of IKE MUST set the major version to 2. Implementations based on previous versions of IKE and ISAKMP MUST set the major version to 1. Implementations based on this version of IKE MUST reject or ignore messages containing a version number greater than 2 with an INVALID_MAJOR_VERSION notification message as described in Section 2.5 🚫.
  • Minor Version (4 bits) 🍓: indicates the minor version of the IKE protocol in use. Implementations based on this version of IKE MUST set the minor version to 0. They MUST ignore the minor version number of received messages 🫶.
  • Exchange Type (1 octet) 🔀: indicates the type of exchange being used. This constrains the payloads sent in each message in an exchange. The values in the following table are only current as of the publication date of RFC 4306. Other values may have been added since then or may be added after the publication of this document. Readers should refer to [IKEV2IANA] for the latest values 📚.
Exchange Type             Value
----------------------------------
IKE_SA_INIT               34
IKE_AUTH                  35
CREATE_CHILD_SA           36
INFORMATIONAL             37
  • Flags (1 octet) 🏳️‍🌈: indicates specific options that are set for the message. An option is present when its bit in the flags field is set. The bits look like this:
  +-+-+-+-+-+-+-+-+
  |X|X|R|V|I|X|X|X|
  +-+-+-+-+-+-+-+-+

In the description below, a bit being 'set' means its value is '1', while 'cleared' means its value is '0' 🔍. 'X' bits MUST be cleared when sending and MUST be ignored on receipt. No exceptions, the X bits are basically ghosted 👻.

  • R (Response) 💬: this bit indicates that this message is a response to a message containing the same Message ID. This bit MUST be cleared in all request messages and MUST be set in all responses. An IKE endpoint MUST NOT generate a response to a message that is marked as being a response (with one exception; see Section 2.21.2) 🙅.
  • V (Version) ⬆️: this bit indicates that the transmitter is capable of speaking a higher major version number of the protocol than the one indicated in the major version number field. Implementations of IKEv2 MUST clear this bit when sending and MUST ignore it in incoming messages 🫧.
  • I (Initiator) 🙋‍♀️: this bit MUST be set in messages sent by the original initiator of the IKE SA and MUST be cleared in messages sent by the original responder. The recipient uses it to determine which eight octets of the SPI were generated by the recipient. This bit changes to reflect who initiated the last rekey of the IKE SA 🔄.
  • Message ID (4 octets, unsigned integer) 🆔: message identifier used to control retransmission of lost packets and matching of requests and responses. It is essential to the security of the protocol because it is used to prevent message replay attacks. See Sections 2.1 and 2.2 🛡️.
  • Length (4 octets, unsigned integer) 📏: length of the total message (header + payloads) in octets.

3.2. Generic Payload Header ✨

okay so every IKE payload from Section 3.3 through Section 3.16 starts with the same little header, the generic payload header 🎀 It's shown in Figure 5, and every payload's figure includes it too, so the per-field descriptions get skipped there to keep things short. Think of it as the ID badge every payload wears at the door 🫶

                    1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload  |C|  RESERVED   |         Payload Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Figure 5: Generic Payload Header

Here's what each field is doing 💅

  • Next Payload (1 octet) is the payload type of whatever comes next in the message. If the current payload is the last one, this field is 0. This is the "chaining" trick: you tack a new payload onto the end of the message and point the previous payload's Next Payload field at its type. The one exception is the Encrypted payload, which has to be the last payload in a message (lowercase, no cap, just a rule of the game 🙈). It holds its own stack of payloads inside. So its Next Payload field gets set to the type of the first payload inside it, not 0. And then the last payload inside has its Next Payload field set to zero. Lowkey genius 🧚 The payload type values are listed in the table below. Heads up: those numbers were only current when RFC 4306 came out. Newer values may have shown up since then or will show up after this document, so go check [IKEV2IANA] for the latest 📚
Next Payload Type                Notation  Value
--------------------------------------------------
No Next Payload                             0
Security Association             SA         33
Key Exchange                     KE         34
Identification - Initiator       IDi        35
Identification - Responder       IDr        36
Certificate                      CERT       37
Certificate Request              CERTREQ    38
Authentication                   AUTH       39
Nonce                            Ni, Nr     40
Notify                           N          41
Delete                           D          42
Vendor ID                        V          43
Traffic Selector - Initiator     TSi        44
Traffic Selector - Responder     TSr        45
Encrypted and Authenticated      SK         46
Configuration                    CP         47
Extensible Authentication        EAP        48

(Payload type values 1-32 should not be assigned in the future so that there is no overlap with the code assignments for IKEv1. Respect the boundary, bestie 🌸)

  • Critical (1 bit) is the one that gets a little dramatic 🔥 It MUST be set to zero if the sender wants the recipient to skip this payload when it doesn't understand the payload type in the previous payload's Next Payload field. It MUST be set to one if the sender wants the recipient to reject the entire message when it doesn't understand the type. If the recipient does understand the type, the bit MUST be ignored. For payload types defined in this document, it MUST be set to zero. Also, the critical bit is about the current payload, not the "next" one whose type code is in the first octet, so don't mix those up 🙈 The reason payloads from this document don't use the critical bit is that every implementation MUST understand every payload type defined here, so they all have to ignore the bit's value anyway 💜 Skipped payloads are still expected to have valid Next Payload and Payload Length fields. For more on this bit, see Section 2.5 🦋
  • RESERVED (7 bits) MUST be sent as zero, and MUST be ignored on receipt 🍓
  • Payload Length (2 octets, unsigned integer) is the length in octets of the current payload, including the generic payload header. So the header counts itself, which is very main character energy ✨
Heads up: lots of payloads have fields marked "RESERVED", and some payloads in IKEv2 (and back in IKEv1 too) aren't aligned to 4-octet boundaries. Don't assume everything lines up neatly 😭

3.3. Security Association Payload ✨

Okay bestie, the Security Association payload (we call it SA in this doc 💅) is how two peers negotiate the attributes of a Security Association. Building one takes great peace of mind 🧘🌸 An SA payload MAY contain multiple proposals. If there's more than one, they MUST be ordered from most preferred to least preferred. Each proposal carries a single IPsec protocol (IKE, ESP, or AH 🔐), each protocol MAY contain multiple transforms, and each transform MAY contain multiple attributes. When you parse an SA, an implementation MUST check that the total Payload Length is consistent with the payload's internal lengths and counts 🙈 Proposals, Transforms, and Attributes all have their own variable-length encodings, and they're nested so the SA's Payload Length covers everything inside it: the SA, Proposal, Transform, and Attribute info. A Proposal's length includes every Transform and Attribute in it, and a Transform's length includes every Attribute in it.

The syntax is based on ISAKMP, but the semantics are different, no cap 🦋 The whole nested hierarchy exists so you can encode lots of algorithm combos in one SA. Sometimes you're offering a choice between algorithms, and other times you need a combination. For example, an initiator might wanna offer ESP with either (3DES and HMAC_MD5) or (AES and HMAC_SHA1).

One of the reasons the SA payload semantics changed from ISAKMP and IKEv1 was to make the encodings more compact in common cases 💖

The Proposal structure has a Proposal Num and an IPsec protocol ID inside it. Each structure MUST have a proposal number one (1) greater than the previous structure. The first Proposal in the initiator's SA payload MUST have a Proposal Num of one (1). One reason to use multiple proposals is to offer both standard crypto ciphers and combined-mode ciphers ✨ Combined-mode ciphers bundle integrity and encryption into a single encryption algorithm, so they MUST either offer no integrity algorithm or a single integrity algorithm of "none", with no integrity algorithm being the RECOMMENDED method 🎀 If an initiator wants to propose both combined-mode ciphers and normal ciphers, it must include two proposals: one with all the combined-mode ciphers, and one with all the normal ciphers plus their integrity algorithms. For example, one such proposal would have two proposal structures. Proposal 1 is ESP with AES-128, AES-192, and AES-256 bits in Cipher Block Chaining (CBC) mode, with either HMAC-SHA1-96 or XCBC-96 as the integrity algorithm. Proposal 2 is AES-128 or AES-256 in GCM mode with an 8-octet Integrity Check Value (ICV). Both proposals allow but do not require the use of ESNs (Extended Sequence Numbers) 🌈 Here's how it looks:

SA Payload
   |
   +--- Proposal #1 ( Proto ID = ESP(3), SPI size = 4,
   |     |            7 transforms,      SPI = 0x052357bb )
   |     |
   |     +-- Transform ENCR ( Name = ENCR_AES_CBC )
   |     |     +-- Attribute ( Key Length = 128 )
   |     |
   |     +-- Transform ENCR ( Name = ENCR_AES_CBC )
   |     |     +-- Attribute ( Key Length = 192 )
   |     |
   |     +-- Transform ENCR ( Name = ENCR_AES_CBC )
   |     |     +-- Attribute ( Key Length = 256 )
   |     |
   |     +-- Transform INTEG ( Name = AUTH_HMAC_SHA1_96 )
   |     +-- Transform INTEG ( Name = AUTH_AES_XCBC_96 )
   |     +-- Transform ESN ( Name = ESNs )
   |     +-- Transform ESN ( Name = No ESNs )
   |
   +--- Proposal #2 ( Proto ID = ESP(3), SPI size = 4,
         |            4 transforms,      SPI = 0x35a1d6f2 )
         |
         +-- Transform ENCR ( Name = AES-GCM with a 8 octet ICV )
         |     +-- Attribute ( Key Length = 128 )
         |
         +-- Transform ENCR ( Name = AES-GCM with a 8 octet ICV )
         |     +-- Attribute ( Key Length = 256 )
         |
         +-- Transform ESN ( Name = ESNs )
         +-- Transform ESN ( Name = No ESNs )

Each Proposal/Protocol structure is followed by one or more transform structures. How many different transforms you get is generally decided by the Protocol. AH generally has two transforms: Extended Sequence Numbers (ESNs) and an integrity check algorithm. ESP generally has three: ESN, an encryption algorithm, and an integrity check algorithm. IKE generally has four: a Diffie-Hellman group, an integrity check algorithm, a PRF algorithm, and an encryption algorithm. For each Protocol, the set of permissible transforms gets Transform ID numbers, which show up in the header of each transform 🧚

If there are multiple transforms with the same Transform Type, the proposal is an OR of those transforms. If there are multiple transforms with different Transform Types, the proposal is an AND of the different groups. For example, to propose ESP with (3DES or AES-CBC) and (HMAC_MD5 or HMAC_SHA), the ESP proposal would contain two Transform Type 1 candidates (one for 3DES and one for AEC-CBC) and two Transform Type 3 candidates (one for HMAC_MD5 and one for HMAC_SHA). That effectively proposes four combinations of algorithms. If the initiator only wanted a subset of those, like (3DES and HMAC_MD5) or (IDEA and HMAC_SHA), there's no way to encode that as multiple transforms within a single Proposal. Instead, the initiator would have to construct two different Proposals, each with two transforms 😭

A given transform MAY have one or more Attributes. Attributes are necessary when the transform can be used in more than one way, like when an encryption algorithm has a variable key size. The transform specifies the algorithm and the attribute specifies the key size. Most transforms don't have attributes. A transform MUST NOT have multiple attributes of the same type. To propose alternate values for an attribute (like multiple key sizes for the AES encryption algorithm), an implementation MUST include multiple transforms with the same Transform Type, each with a single Attribute 💜

Heads up: the semantics of Transforms and Attributes are quite different from IKEv1. In IKEv1, a single Transform carried multiple algorithms for a protocol, with one carried in the Transform and the others carried in the Attributes. Don't mix them up, bestie 💀
                     1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload  |C|  RESERVED   |         Payload Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                          <Proposals>                          ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

         Figure 6:  Security Association Payload
  • Proposals (variable) - One or more proposal substructures.

The payload type for the Security Association payload is thirty-three (33) 🍓


3.3.1. Proposal Substructure

                     1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 (last) or 2 |   RESERVED    |         Proposal Length       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Proposal Num  |  Protocol ID  |    SPI Size   |Num  Transforms|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~                        SPI (variable)                         ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                        <Transforms>                           ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

         Figure 7:  Proposal Substructure
  • 0 (last) or 2 (more) (1 octet) - Specifies whether this is the last Proposal Substructure in the SA. This syntax is inherited from ISAKMP, but it's kinda unnecessary because the last Proposal could be identified from the length of the SA. The value (2) corresponds to a payload type of Proposal in IKEv1, and the first four octets of the Proposal structure are designed to look somewhat like the header of a payload 🌸
  • RESERVED (1 octet) - MUST be sent as zero; MUST be ignored on receipt.
  • Proposal Length (2 octets, unsigned integer) - Length of this proposal, including all transforms and attributes that follow.
  • Proposal Num (1 octet) - When a proposal is made, the first proposal in an SA payload MUST be 1, and subsequent proposals MUST be one more than the previous proposal (indicating an OR of the two proposals). When a proposal is accepted, the proposal number in the SA payload MUST match the number on the proposal sent that was accepted 🎯
  • Protocol ID (1 octet) - Specifies the IPsec protocol identifier for the current negotiation. The values in the following table are only current as of the publication date of RFC 4306. Other values may have been added since then or will be added after the publication of this document. Readers should refer to [IKEV2IANA] for the latest values.
Protocol                Protocol ID
-----------------------------------
IKE                     1
AH                      2
ESP                     3
  • SPI Size (1 octet) - For an initial IKE SA negotiation, this field MUST be zero; the SPI is obtained from the outer header. During subsequent negotiations, it is equal to the size, in octets, of the SPI of the corresponding protocol (8 for IKE, 4 for ESP and AH) 🦋
  • Num Transforms (1 octet) - Specifies the number of transforms in this proposal.
  • SPI (variable) - The sending entity's SPI. Even if the SPI Size is not a multiple of 4 octets, there is no padding applied to the payload. When the SPI Size field is zero, this field is not present in the Security Association payload.
  • Transforms (variable) - One or more transform substructures.

3.3.2. Transform Substructure ✨

                        1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   | 0 (last) or 3 |   RESERVED    |        Transform Length       |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |Transform Type |   RESERVED    |          Transform ID         |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   ~                      Transform Attributes                     ~
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Figure 8: Transform Substructure

Okay so this is the layout of a Transform Substructure, and it's giving neat little building block 🧚 Here's what each field does:

  • 0 (last) or 3 (more) (1 octet): tells you whether this is the last Transform Substructure in the Proposal 💅. It's inherited from ISAKMP, but honestly it's kinda unnecessary, because the last transform could be figured out from the length of the proposal anyway. The value 3 matches a payload type of Transform in IKEv1, and the first four octets of the Transform structure were designed to look a bit like a payload header 🎀.
  • RESERVED: MUST be sent as zero, and MUST be ignored on receipt 🫶.
  • Transform Length: the length, in octets, of the whole Transform Substructure, Header and Attributes included 🌸.
  • Transform Type (1 octet): the kind of transform being specified here 🔥. Different protocols support different Transform Types, and for some protocols certain transforms are optional. If a transform is optional and the initiator wants to propose leaving it out, no transform of that type gets included in the proposal at all. But if the initiator wants the responder to be able to pick whether it's used, it includes a transform substructure with Transform ID = 0 as one of the options ✨.
  • Transform ID (2 octets): the specific instance of the Transform Type being proposed 💖.

The Transform Type values are listed below. Heads up, these values are only current as of the publication date of RFC 4306. More values may have been added since then, or will be added later, so readers should check [IKEV2IANA] for the latest values 🦋.

Description                     Trans.  Used In
                                Type
------------------------------------------------------------------
Encryption Algorithm (ENCR)     1       IKE and ESP
Pseudorandom Function (PRF)     2       IKE
Integrity Algorithm (INTEG)     3       IKE*, AH, optional in ESP
Diffie-Hellman group (D-H)      4       IKE, optional in AH & ESP
Extended Sequence Numbers (ESN) 5       AH and ESP

(*) Negotiating an integrity algorithm is mandatory for the Encrypted payload format specified in this document. For example, [AEAD] specifies additional formats based on authenticated encryption, where a separate integrity algorithm doesn't get negotiated at all 🙈.

For Transform Type 1 (Encryption Algorithm), the Transform IDs are listed below. Same deal here: these values are only current as of the publication date of RFC 4306, and [IKEV2IANA] has the latest ones 💜.

Name                 Number      Defined In
---------------------------------------------------
ENCR_DES_IV64        1           (UNSPECIFIED)
ENCR_DES             2           (RFC2405), [DES]
ENCR_3DES            3           (RFC2451)
ENCR_RC5             4           (RFC2451)
ENCR_IDEA            5           (RFC2451), [IDEA]
ENCR_CAST            6           (RFC2451)
ENCR_BLOWFISH        7           (RFC2451)
ENCR_3IDEA           8           (UNSPECIFIED)
ENCR_DES_IV32        9           (UNSPECIFIED)
ENCR_NULL            11          (RFC2410)
ENCR_AES_CBC         12          (RFC3602)
ENCR_AES_CTR         13          (RFC3686)

For Transform Type 2 (Pseudorandom Function), here are the Transform IDs. Again, only current as of RFC 4306, so peek at [IKEV2IANA] for updates 🌈.

Name                        Number    Defined In
------------------------------------------------------
PRF_HMAC_MD5                1         (RFC2104), [MD5]
PRF_HMAC_SHA1               2         (RFC2104), [SHA]
PRF_HMAC_TIGER              3         (UNSPECIFIED)

For Transform Type 3 (Integrity Algorithm), here are the defined Transform IDs. Same caveat as always: check [IKEV2IANA] for the latest 🍓.

Name                 Number   Defined In
----------------------------------------
NONE                 0
AUTH_HMAC_MD5_96     1        (RFC2403)
AUTH_HMAC_SHA1_96    2        (RFC2404)
AUTH_DES_MAC         3        (UNSPECIFIED)
AUTH_KPDK_MD5        4        (UNSPECIFIED)
AUTH_AES_XCBC_96     5        (RFC3566)

For Transform Type 4 (Diffie-Hellman group), here are the defined Transform IDs, valid as of RFC 4306 and then you go to [IKEV2IANA] for the newest ones 🫧.

Name               Number     Defined In
----------------------------------------
NONE               0
768-bit MODP       1          Appendix B
1024-bit MODP      2          Appendix B
1536-bit MODP      5          [ADDGROUP]
2048-bit MODP      14         [ADDGROUP]
3072-bit MODP      15         [ADDGROUP]
4096-bit MODP      16         [ADDGROUP]
6144-bit MODP      17         [ADDGROUP]
8192-bit MODP      18         [ADDGROUP]

Okay, the plot twist 🤭: ESP and AH don't directly include a Diffie-Hellman exchange, but a Diffie-Hellman group MAY be negotiated for the Child SA. That lets the peers use Diffie-Hellman in the CREATE_CHILD_SA exchange, which gives perfect forward secrecy for the generated Child SA keys 🔐✨.

For Transform Type 5 (Extended Sequence Numbers), here are the defined Transform IDs. You already know the drill, valid as of RFC 4306, and [IKEV2IANA] for the latest 👑.

Name                               Number
--------------------------------------------
No Extended Sequence Numbers       0
Extended Sequence Numbers          1

Note that an initiator who supports ESNs will usually include two ESN transforms, with values "0" and "1", in its proposals 🦋. A proposal containing a single ESN transform with value "1" means that normal (non-extended) sequence numbers are not acceptable. Bestie, that's a whole vibe check 💀.

Numerous additional Transform Types have been defined since RFC 4306 was published, so please check the IANA IKEv2 registry for details 🌸.

3.3.3. Valid Transform Types by Protocol 💖

The number and type of transforms that come with an SA payload depend on the protocol in the SA itself. An SA payload proposing the establishment of an SA has the following mandatory and optional Transform Types 🧚. A compliant implementation MUST understand all mandatory and optional types for each protocol it supports, though it doesn't need to accept proposals with unacceptable suites. A proposal MAY leave out the optional types if the only value it will accept for them is NONE 🙌.

Protocol    Mandatory Types          Optional Types
---------------------------------------------------
IKE         ENCR, PRF, INTEG*, D-H
ESP         ENCR, ESN                INTEG, D-H
AH          INTEG, ESN               D-H

(*) Negotiating an integrity algorithm is mandatory for the Encrypted payload format specified in this document. For example, [AEAD] specifies additional formats based on authenticated encryption, where a separate integrity algorithm isn't negotiated 🫶.

3.3.4. Mandatory Transform IDs 🔥

Okay so the list of suites that MUST and SHOULD be supported for interoperability got removed from this document 💅. The reason is that those suites change way faster than this document evolves. At the time of publication, [RFC4307] specifies these suites, but it might get updated later, and other RFCs might specify different sets of suites 🌈.

An important lesson learned from IKEv1 is that no system should implement only the mandatory algorithms and expect them to be the best choice for every customer 😭.

IANA will likely add more transforms in the future, and some users will want private suites, especially for IKE, where implementations should be able to support different parameters, up to certain size limits 🍓. To make that work, all implementations of IKEv2 SHOULD include a management facility that lets a user or system administrator specify Diffie-Hellman parameters (the generator, modulus, and exponent lengths and values) for new Diffie-Hellman groups ✨. Implementations SHOULD also provide a management interface where those parameters and their associated Transform IDs can be entered by a user or system administrator, so that such groups can be negotiated 🦋.

All implementations of IKEv2 MUST include a management facility that lets a user or system administrator specify which suites are acceptable for use with IKE 👑. When a payload with a set of Transform IDs comes in, the implementation MUST compare the transmitted Transform IDs against the ones configured locally through those management controls, to check that the proposed suite is acceptable under local policy. The implementation MUST reject SA proposals that aren't authorized by these IKE suite controls 🚫. Note that cryptographic suites that MUST be implemented don't need to be configured as acceptable to local policy 🎀.

3.3.5. Transform Attributes 💅

okay bestie, so each transform in a Security Association payload can bring along little attributes that tweak or finish off its spec 🎀 Which attributes are valid totally depends on the transform. Right now there's only ONE attribute type: the Key Length attribute, which certain encryption transforms with variable-length keys use (more on that below) ✨

The attributes are type/value pairs, and they're defined below. They can have a fixed two-octet value or a variable-length one. For the variable-length kind, it's encoded as type/length/value 🦋

                     1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|A|       Attribute Type        |    AF=0  Attribute Length     |
|F|                             |    AF=1  Attribute Value      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                   AF=0  Attribute Value                       |
|                   AF=1  Not Transmitted                       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Figure 9: Data Attributes

  • Attribute Format (AF) (1 bit) 🌸 This tells you whether the data attribute uses the Type/Length/Value (TLV) format or the shortened Type/Value (TV) format. If the AF bit is zero (0), the attribute uses TLV format. If the AF bit is one (1), the TV format is used, with a two-byte value.
  • Attribute Type (15 bits) 🧚 A unique identifier for each type of attribute (see below).
  • Attribute Value (variable length) 💜 The value of the attribute that goes with the attribute type. If the AF bit is a zero (0), this field's length is set by the Attribute Length field. If the AF bit is a one (1), the Attribute Value is 2 octets long.

The only currently defined attribute type (Key Length) is fixed length. The variable-length encoding spec is only in here for future extensions 🔮 Attributes described as fixed length MUST NOT be encoded using the variable-length encoding unless that length exceeds two bytes. Variable-length attributes MUST NOT be encoded as fixed-length, even if their value could fit into two octets. Note: This is a change from IKEv1, where increased flexibility may have simplified the composer of messages but certainly complicated the parser 😭

The values in the following table are only current as of the publication date of RFC 4306. Other values may have been added since then, or will be added after this document is published. Readers should check [IKEV2IANA] for the latest values 📚

Attribute Type         Value         Attribute Format
------------------------------------------------------------
Key Length (in bits)   14            TV

Values 0-13 and 15-17 were used in a similar context in IKEv1, and should not be assigned except to matching values.

The Key Length attribute specifies the key length in bits (MUST use network byte order) for certain transforms, like so:

  • The Key Length attribute MUST NOT be used with transforms that use a fixed-length key. For example, this includes ENCR_DES, ENCR_IDEA, and all the Type 2 (Pseudorandom function) and Type 3 (Integrity Algorithm) transforms specified in this document. It is recommended that future Type 2 or 3 transforms do not use this attribute.
  • Some transforms specify that the Key Length attribute MUST be always included (omitting the attribute is not allowed, and proposals not containing it MUST be rejected). For example, this includes ENCR_AES_CBC and ENCR_AES_CTR.
  • Some transforms allow variable-length keys, but also specify a default key length if the attribute is not included. For example, these transforms include ENCR_RC5 and ENCR_BLOWFISH.

Implementation note: To boost interoperability and support upgrading endpoints independently, implementers of this protocol SHOULD accept values that they deem to supply greater security. For instance, if a peer is configured to accept a variable-length cipher with a key length of X bits and is offered that cipher with a larger key length, the implementation SHOULD accept the offer if it supports use of the longer key 💖

Support for this capability lets a responder express a concept of "at least" a certain level of security, like "a key length of _at least_ X bits for cipher Y" 🫶 However, since the attribute is always returned unchanged (see the next section), an initiator willing to accept multiple key lengths has to include multiple transforms with the same Transform Type, each with a different Key Length attribute 🍓

3.3.6. Attribute Negotiation 🦋

During Security Association negotiation, initiators present offers to responders. Responders MUST select a single complete set of parameters from the offers (or reject all offers if none are acceptable). If there are multiple proposals, the responder MUST choose a single proposal. If the selected proposal has multiple transforms with the same type, the responder MUST choose a single one. Any attributes of a selected transform MUST be returned unmodified. The initiator of an exchange MUST check that the accepted offer is consistent with one of its proposals, and if it's not, the initiator MUST terminate the exchange 🔥

If the responder receives a proposal that contains a Transform Type it does not understand, or a proposal that is missing a mandatory Transform Type, it MUST consider this proposal unacceptable. However, other proposals in the same SA payload are processed as usual. Similarly, if the responder receives a transform that it does not understand, or one that contains a Transform Attribute it does not understand, it MUST consider this transform unacceptable. Other transforms with the same Transform Type are processed as usual. This lets new Transform Types and Transform Attributes be defined in the future ✨

Negotiating Diffie-Hellman groups is lowkey tricky 🙈 SA offers include proposed attributes and a Diffie-Hellman public number (KE) in the same message. If in the initial exchange the initiator offers to use one of several Diffie-Hellman groups, it SHOULD pick the one the responder is most likely to accept, and include a KE corresponding to that group. If the responder selects a proposal using a different Diffie-Hellman group (other than NONE), the responder will indicate the correct group in the response, and the initiator SHOULD pick an element of that group for its KE value when retrying the first message. It SHOULD, however, continue to propose its full supported set of groups in order to prevent a man-in-the-middle downgrade attack 👑 If one of the proposals offered is for the Diffie-Hellman group of NONE, and the responder selects that Diffie-Hellman group, then it MUST ignore the initiator's KE payload and omit the KE payload from the response.

3.4. Key Exchange Payload 🌈

The Key Exchange payload, denoted KE in this document, is used to exchange Diffie-Hellman public numbers as part of a Diffie-Hellman key exchange. It's made of the IKE generic payload header, followed by the Diffie-Hellman public value itself 💅

                     1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload  |C|  RESERVED   |         Payload Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Diffie-Hellman Group Num    |           RESERVED            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                       Key Exchange Data                       ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Figure 10: Key Exchange Payload Format

A Key Exchange payload is built by copying one's Diffie-Hellman public value into the "Key Exchange Data" portion of the payload. For modular exponentiation group (MODP) groups, the length of the Diffie-Hellman public value MUST be equal to the length of the prime modulus over which the exponentiation was performed, with zero bits prepended to the value if necessary 🧁

The Diffie-Hellman Group Num identifies the Diffie-Hellman group in which the Key Exchange Data was computed (see Section 3.3.2). This Diffie-Hellman Group Num MUST match a Diffie-Hellman group specified in a proposal in the SA payload sent in the same message, and SHOULD match the Diffie-Hellman group in the first group of the first proposal, if one exists. If none of the proposals in that SA payload specifies a Diffie-Hellman group, the KE payload MUST NOT be present. If the selected proposal uses a different Diffie-Hellman group (other than NONE), the message MUST be rejected with a Notify payload of type INVALID_KE_PAYLOAD. See also Sections 1.2 and 2.7 🎀

The payload type for the Key Exchange payload is thirty-four (34) 🦋

3.5. Identification Payloads 🆔

okay so the Identification payloads (IDi and IDr in this doc) are how peers say "hey, this is me" to each other 💅 You can use that identity to look up policy, but it doesn't have to match anything in the CERT payload. Both fields can be used to make access control decisions. 🔐 When you use ID_IPV4_ADDR or ID_IPV6_ADDR in IDi/IDr, IKEv2 does not require that address to match the source address in the IP header of the IKEv2 packets, or anything in the TSi/TSr payloads. The IDi/IDr contents are used purely to fetch the policy and authentication data for the other party, nothing more 🦋

NOTE: In IKEv1, two ID payloads went in each direction to carry Traffic Selector (TS) info for the data passing over the SA. In IKEv2, that info lives in TS payloads instead (see Section 3.13) ✨

The Peer Authorization Database (PAD) from RFC 4301 [IPSECARCH] explains how the ID payload works in IKEv2. It also gives a formal model for tying an identity to a policy, plus services for the nitty-gritty of enforcing that policy 🧚 Basically the PAD is the link between the SPD and IKE Security Association management. See Section 4.4.3 of RFC 4301 for more details 💜

The Identification payload is the IKE generic payload header followed by these identification fields:

                    1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload  |C|  RESERVED   |         Payload Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   ID Type     |                 RESERVED                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                   Identification Data                         ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Figure 11: Identification Payload Format 🎀

  • ID Type (1 octet) - Specifies the type of Identification being used.
  • RESERVED - MUST be sent as zero; MUST be ignored on receipt.
  • Identification Data (variable length) - Value, as indicated by the Identification Type. The length of the Identification Data is computed from the size in the ID payload header.

The payload types for the Identification payload are thirty-five (35) for IDi and thirty-six (36) for IDr 🌸

The table below lists the assigned semantics for the Identification Type field. The values in it are only current as of the publication date of RFC 4306. Other values may have been added since then or will be added after this document is published. Readers should refer to [IKEV2IANA] for the latest values 🍓

ID Type                           Value
-------------------------------------------------------------------
ID_IPV4_ADDR                        1
   A single four (4) octet IPv4 address.

ID_FQDN                             2
   A fully-qualified domain name string.  An example of an ID_FQDN
   is "example.com".  The string MUST NOT contain any terminators
   (e.g., NULL, CR, etc.). All characters in the ID_FQDN are ASCII;
   for an "internationalized domain name", the syntax is as defined
   in [IDNA], for example "xn--tmonesimerkki-bfbb.example.net".

ID_RFC822_ADDR                      3
   A fully-qualified RFC 822 email address string.  An example of a
   ID_RFC822_ADDR is "jsmith@example.com".  The string MUST NOT
   contain any terminators.  Because of [EAI], implementations would
   be wise to treat this field as UTF-8 encoded text, not as
   pure ASCII.

ID_IPV6_ADDR                        5
   A single sixteen (16) octet IPv6 address.

ID_DER_ASN1_DN                      9
   The binary Distinguished Encoding Rules (DER) encoding of an
   ASN.1 X.500 Distinguished Name [PKIX].

ID_DER_ASN1_GN                      10
   The binary DER encoding of an ASN.1 X.509 GeneralName [PKIX].

ID_KEY_ID                           11
   An opaque octet stream that may be used to pass vendor-
   specific information necessary to do certain proprietary
   types of identification.

Two implementations will only interoperate if each can generate a type of ID the other accepts 🤝 For maximum interop, implementations MUST be configurable to send at least one of ID_IPV4_ADDR, ID_FQDN, ID_RFC822_ADDR, or ID_KEY_ID, and MUST be configurable to accept all four of those types. Implementations SHOULD be capable of generating and accepting all of these types. IPv6-capable implementations MUST additionally be configurable to accept ID_IPV6_ADDR. IPv6-only implementations MAY be configurable to send only ID_IPV6_ADDR instead of ID_IPV4_ADDR for IP addresses 🌈

EAP [EAP] doesn't mandate any particular identifier type, but EAP is often used with Network Access Identifiers (NAIs) defined in [NAI] 🧸 NAIs look a bit like email addresses (e.g., "joe@example.com"), but the syntax isn't exactly the same as an email address in [MAILFORMAT]. For NAIs that include the realm component, the ID_RFC822_ADDR identification type SHOULD be used. Responder implementations should not try to verify that the contents strictly conform to the exact syntax in [MAILFORMAT]. Instead they should accept any reasonable-looking NAI. For NAIs that do not include the realm component, the ID_KEY_ID identification type SHOULD be used 💖


3.6. Certificate Payload 📜

The Certificate payload (called CERT in this document) is how IKE carries certificates or other authentication-related info 🫶 Certificate payloads SHOULD be included in an exchange if the sender has certificates available. The Hash and URL formats of the Certificate payloads should be used in case the peer has indicated it can fetch this info from elsewhere using an HTTP_CERT_LOOKUP_SUPPORTED Notify payload. Also, the name "Certificate payload" is kinda misleading, ngl 🙈 Not every auth mechanism uses certificates, and data other than certificates can be passed in this payload too.

The Certificate payload is defined like this:

                    1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload  |C|  RESERVED   |         Payload Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Cert Encoding |                                               |
+-+-+-+-+-+-+-+-+                                               |
~                       Certificate Data                        ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Figure 12: Certificate Payload Format ✨

  • Certificate Encoding (1 octet) - This field indicates the type of certificate or certificate-related information contained in the Certificate Data field. The values in the table below are only current as of the publication date of RFC 4306. Other values may have been added since then or will be added after this document is published. Readers should refer to [IKEV2IANA] for the latest values.
Certificate Encoding                 Value
----------------------------------------------------
PKCS #7 wrapped X.509 certificate    1   UNSPECIFIED
PGP Certificate                      2   UNSPECIFIED
DNS Signed Key                       3   UNSPECIFIED
X.509 Certificate - Signature        4
Kerberos Token                       6   UNSPECIFIED
Certificate Revocation List (CRL)    7
Authority Revocation List (ARL)      8   UNSPECIFIED
SPKI Certificate                     9   UNSPECIFIED
X.509 Certificate - Attribute        10  UNSPECIFIED
Raw RSA Key                          11
Hash and URL of X.509 certificate    12
Hash and URL of X.509 bundle         13
  • Certificate Data (variable length) - Actual encoding of certificate data. The type of certificate is indicated by the Certificate Encoding field.

The payload type for the Certificate payload is thirty-seven (37) 🌷

Syntax for some of the certificate type codes above isn't defined in this document. The types whose syntax IS defined here are:

  • "X.509 Certificate - Signature" contains a DER-encoded X.509 certificate whose public key is used to validate the sender's AUTH payload. With this encoding, if a chain of certificates needs to be sent, multiple CERT payloads are used, and only the first one holds the public key used to validate the sender's AUTH payload.
  • "Certificate Revocation List" contains a DER-encoded X.509 certificate revocation list.
  • "Raw RSA Key" contains a PKCS #1 encoded RSA key, that is, a DER-encoded RSAPublicKey structure (see [RSA] and [PKCS1]).
  • Hash and URL encodings keep IKE messages short by replacing long data structures with a 20-octet SHA-1 hash (see [SHA]) of the replaced value, followed by a variable-length URL that resolves to the DER-encoded data structure itself. This is more efficient when the endpoints have certificate data cached, and it makes IKE less subject to DoS attacks that get easier to mount when IKE messages are big enough to need IP fragmentation [DOSUDPPROT] 🛡️

The "Hash and URL of a bundle" type uses the following ASN.1 definition for the X.509 bundle:

CertBundle
  { iso(1) identified-organization(3) dod(6) internet(1)
    security(5) mechanisms(5) pkix(7) id-mod(0)
    id-mod-cert-bundle(34) }

DEFINITIONS EXPLICIT TAGS ::=
BEGIN

IMPORTS
  Certificate, CertificateList
  FROM PKIX1Explicit88
     { iso(1) identified-organization(3) dod(6)
       internet(1) security(5) mechanisms(5) pkix(7)
       id-mod(0) id-pkix1-explicit(18) } ;

CertificateOrCRL ::= CHOICE {
  cert [0] Certificate,
  crl  [1] CertificateList }

CertificateBundle ::= SEQUENCE OF CertificateOrCRL

END

Implementations MUST be capable of being configured to send and accept up to four X.509 certificates for authentication, and MUST also be capable of being configured to send and accept the Hash and URL format (with HTTP URLs) 🎯 Implementations SHOULD be capable of being configured to send and accept Raw RSA keys. If multiple certificates are sent, the first certificate MUST contain the public key used to sign the AUTH payload. The other certificates may be sent in any order.

Implementations MUST support the HTTP [HTTP] method for hash-and-URL lookup. The behavior of other URL methods [URLS] is not currently specified, so such methods SHOULD NOT be used unless a document specifying them exists 🌸

3.7. Certificate Request Payload 📜

Okay bestie, the Certificate Request payload (we call it CERTREQ in this doc 🎀) is how you ask for preferred certificates over IKE. It can show up in the IKE_INIT_SA response and/or the IKE_AUTH request. Certificate Request payloads MAY be included in an exchange when the sender needs to get the certificate of the receiver. 💌

Here's the layout, no cap it's giving very organized 🧚

                        1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   | Next Payload  |C|  RESERVED   |         Payload Length        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   | Cert Encoding |                                               |
   +-+-+-+-+-+-+-+-+                                               |
   ~                    Certification Authority                    ~
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

         Figure 13:  Certificate Request Payload Format

The fields you need to know about:

  • Certificate Encoding (1 octet) - Contains an encoding of the type or format of certificate requested. Values are listed in Section 3.6.
  • Certification Authority (variable length) - Contains an encoding of an acceptable certification authority for the type of certificate requested.

Its payload type is thirty-eight (38) 🌸

The Certificate Encoding field uses the same values as the ones in Section 3.6. The Certification Authority field is basically an indicator of trusted authorities for that certificate type 👑 Its value is a concatenated list of SHA-1 hashes of the public keys of trusted Certification Authorities (CAs). Each one is the SHA-1 hash of the Subject Public Key Info element (see section 4.1.2.7 of [PKIX]) taken from each Trust Anchor certificate. The 20-octet hashes get concatenated and included with no other formatting, so it's just raw hashes stacked up 🧁

The contents of the "Certification Authority" field are only defined for X.509 certificates, which are types 4, 12, and 13. Other values SHOULD NOT be used until Standards-Track specifications that specify their use are published. Lowkey a very strict little rule 🙈

Ngl the name "Certificate Request" is a bit misleading 💅 Values other than certificates are defined in a "Certificate" payload, and requests for those values can actually show up in a Certificate Request payload. The syntax of the Certificate Request payload in those cases is not defined in this document.

So how do you process one? You look at the "Cert Encoding" field first to see whether you even have certificates of that type. If you do, you check the "Certification Authority" field to see if you have any certificates that can be validated up to one of the specified certification authorities. That can be a chain of certificates, so it might take a few hops 🦋

If an end-entity certificate matches what the CERTREQ asks for, a certificate or certificate chain SHOULD be sent back to the certificate requestor, but only if the recipient of the CERTREQ:

  • is configured to use certificate authentication,
  • is allowed to send a CERT payload,
  • has matching CA trust policy governing the current negotiation, and
  • has at least one time-wise and usage-appropriate end-entity certificate chaining to a CA provided in the CERTREQ.
Certificate revocation checking must be considered during the chaining process used to select a certificate. Also, even if two peers are configured to use two different CAs, cross-certification relationships should be supported by appropriate selection logic. Don't skip this part, it matters 🫶

The vibe here is "don't be a rigid rule-follower." The point isn't to block communication by strictly sticking to what the CERTREQ says, if the sender could pick an alternate certificate that the recipient can still validate and trust through cross-certification, CRLs, or other out-of-band configured means. So honestly, processing a CERTREQ should be seen as a suggestion for a certificate to select, not a mandated one 🌈 If no certificates exist, the CERTREQ is simply ignored. That's not an error condition of the protocol, so chill. There may also be cases where a preferred CA is sent in the CERTREQ but an alternate would be acceptable (maybe after prompting a human operator) 🍓

The HTTP_CERT_LOOKUP_SUPPORTED notification MAY be included in any message that can include a CERTREQ payload. It indicates that the sender is able to look up certificates based on an HTTP-based URL, and so it presumably would prefer to receive certificate specifications in that format 🔥


3.8. Authentication Payload 🔐

The Authentication payload, denoted AUTH in this document, carries data used for authentication purposes. The syntax of the Authentication data changes depending on the Auth Method, as you'll see below ✨

Layout time:

                        1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   | Next Payload  |C|  RESERVED   |         Payload Length        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   | Auth Method   |                RESERVED                       |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   ~                      Authentication Data                      ~
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

              Figure 14:  Authentication Payload Format
  • Auth Method (1 octet) - Specifies the method of authentication used. The types of signatures are listed here. The values in the following table are only current as of the publication date of RFC 4306. Other values may have been added since then or will be added after the publication of this document. Readers should refer to [IKEV2IANA] for the latest values.

Here's the table, copied exactly 📋

   Mechanism                              Value
   -----------------------------------------------------------------
   RSA Digital Signature                  1
   Shared Key Message Integrity Code      2
   DSS Digital Signature                  3

For the RSA Digital Signature (value 1), the signature is computed as specified in Section 2.15 using an RSA private key with the RSASSA-PKCS1-v1_5 signature scheme specified in [PKCS1]. Implementers should note that IKEv1 used a different method for RSA signatures 👀 To promote interoperability, implementations that support this type SHOULD support signatures that use SHA-1 as the hash function, and SHOULD use SHA-1 as the default hash function when generating signatures. Implementations can use the certificates received from a given peer as a hint for selecting a mutually understood hash function for the AUTH payload signature.

Note, however, that the hash algorithm used in the AUTH payload signature doesn't have to be the same as any hash algorithm(s) used in the certificate(s) 💖

For the Shared Key Message Integrity Code (value 2), it's computed as specified in Section 2.15 using the shared key associated with the identity in the ID payload and the negotiated PRF 🗝️

For the DSS Digital Signature (value 3), it's computed as specified in Section 2.15 using a DSS private key (see [DSS]) over a SHA-1 hash 🦄

  • Authentication Data (variable length) - see Section 2.15.

The payload type for the Authentication payload is thirty-nine (39) 🎀


3.9. Nonce Payload 🎲

The Nonce payload, denoted as Ni and Nr in this document for the initiator's and responder's nonce respectively, contains random data used to guarantee liveness during an exchange and protect against replay attacks. Basically it's the "are you really here, right now?" data 🌸

                        1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   | Next Payload  |C|  RESERVED   |         Payload Length        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   ~                            Nonce Data                         ~
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                Figure 15:  Nonce Payload Format
  • Nonce Data (variable length) - Contains the random data generated by the transmitting entity.

The payload type for the Nonce payload is forty (40) 💜

The size of the Nonce Data MUST be between 16 and 256 octets, inclusive. Nonce values MUST NOT be reused. Non-negotiable, bestie 🚫


3.10. Notify Payload 🔔

The Notify payload, denoted N in this document, is used to transmit informational data, such as error conditions and state transitions, to an IKE peer. A Notify payload may appear in a response message (usually to say why a request got rejected), in an INFORMATIONAL Exchange (to report an error that's not in an IKE request), or in any other message to indicate sender capabilities or to modify the meaning of the request. It's the messenger of the protocol 💬

                        1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   | Next Payload  |C|  RESERVED   |         Payload Length        |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |  Protocol ID  |   SPI Size    |      Notify Message Type      |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   ~                Security Parameter Index (SPI)                 ~
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   ~                       Notification Data                       ~
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

            Figure 16:  Notify Payload Format
  • Protocol ID (1 octet) - If this notification concerns an existing SA whose SPI is given in the SPI field, this field indicates the type of that SA. For notifications concerning Child SAs, this field MUST contain either (2) to indicate AH or (3) to indicate ESP. Of the notifications defined in this document, the SPI is included only with INVALID_SELECTORS and REKEY_SA. If the SPI field is empty, this field MUST be sent as zero and MUST be ignored on receipt.
  • SPI Size (1 octet) - Length in octets of the SPI as defined by the IPsec protocol ID, or zero if no SPI is applicable. For a notification concerning the IKE SA, the SPI Size MUST be zero and the field must be empty.
  • Notify Message Type (2 octets) - Specifies the type of notification message.
  • SPI (variable length) - Security Parameter Index.
  • Notification Data (variable length) - Status or error data transmitted in addition to the Notify Message Type. Values for this field are type specific (see below).

The payload type for the Notify payload is forty-one (41) 🦋

3.10.1. Notify Message Types ✨

Okay so Notify info can be an error message explaining why an SA couldn't get established 😭. It can also be status data that a process managing an SA database wants to share with its peer process 🫶.

The table below lists the Notification messages and their corresponding values 🎀. The number of different error statuses got seriously trimmed down from IKEv1, both to keep things simple and to avoid giving configuration info to probers 🙈.

Types in the range 0 - 16383 are for reporting errors 💀. An implementation receiving a Notify payload with one of these types that it does not recognize in a response MUST assume that the corresponding request has failed entirely. Unrecognized error types in a request and status types in a request or response MUST be ignored, and they should be logged 📝.

Notify payloads with status types MAY be added to any message and MUST be ignored if not recognized. They're meant to show capabilities, and as part of SA negotiation they're used to negotiate non-cryptographic parameters ✨.

More info on error handling is in Section 2.21 🧚.

The values below are only current as of the publication date of RFC 4306, plus two error types added in this document 📅. Other values may have been added since then or will be added after this document is published. Readers should refer to [IKEV2IANA] for the latest values 💜.

NOTIFY messages: error types              Value
-------------------------------------------------------------------
UNSUPPORTED_CRITICAL_PAYLOAD              1
    See Section 2.5.

INVALID_IKE_SPI                           4
    See Section 2.21.

INVALID_MAJOR_VERSION                     5
    See Section 2.5.

INVALID_SYNTAX                            7
    Indicates the IKE message that was received was invalid because
    some type, length, or value was out of range or because the
    request was rejected for policy reasons.  To avoid a DoS
    attack using forged messages, this status may only be
    returned for and in an encrypted packet if the Message ID and
    cryptographic checksum were valid.  To avoid leaking information
    to someone probing a node, this status MUST be sent in response
    to any error not covered by one of the other status types.
    To aid debugging, more detailed error information should be
    written to a console or log.

INVALID_MESSAGE_ID                        9
    See Section 2.3.

INVALID_SPI                              11
    See Section 1.5.

NO_PROPOSAL_CHOSEN                       14
    None of the proposed crypto suites was acceptable.  This can be
    sent in any case where the offered proposals (including but not
    limited to SA payload values, USE_TRANSPORT_MODE notify,
    IPCOMP_SUPPORTED notify) are not acceptable for the responder.
    This can also be used as "generic" Child SA error when Child SA
    cannot be created for some other reason.  See also Section 2.7.

INVALID_KE_PAYLOAD                       17
    See Sections 1.2 and 1.3.

AUTHENTICATION_FAILED                    24
    Sent in the response to an IKE_AUTH message when, for some reason,
    the authentication failed.  There is no associated data.  See also
    Section 2.21.2.

SINGLE_PAIR_REQUIRED                     34
    See Section 2.9.

NO_ADDITIONAL_SAS                        35
    See Section 1.3.

INTERNAL_ADDRESS_FAILURE                 36
    See Section 3.15.4.

FAILED_CP_REQUIRED                       37
    See Section 2.19.

TS_UNACCEPTABLE                          38
    See Section 2.9.

INVALID_SELECTORS                        39
    MAY be sent in an IKE INFORMATIONAL exchange when a node receives
    an ESP or AH packet whose selectors do not match those of the SA
    on which it was delivered (and that caused the packet to be
    dropped).  The Notification Data contains the start of the
    offending packet (as in ICMP messages) and the SPI field of the
    notification is set to match the SPI of the Child SA.

TEMPORARY_FAILURE                        43
    See section 2.25.

CHILD_SA_NOT_FOUND                       44
    See section 2.25.



NOTIFY messages: status types            Value
-------------------------------------------------------------------
INITIAL_CONTACT                          16384
    See Section 2.4.

SET_WINDOW_SIZE                          16385
    See Section 2.3.

ADDITIONAL_TS_POSSIBLE                   16386
    See Section 2.9.

IPCOMP_SUPPORTED                         16387
    See Section 2.22.

NAT_DETECTION_SOURCE_IP                  16388
    See Section 2.23.

NAT_DETECTION_DESTINATION_IP             16389
    See Section 2.23.

COOKIE                                   16390
    See Section 2.6.

USE_TRANSPORT_MODE                       16391
    See Section 1.3.1.

HTTP_CERT_LOOKUP_SUPPORTED               16392
    See Section 3.6.

REKEY_SA                                 16393
    See Section 1.3.3.

ESP_TFC_PADDING_NOT_SUPPORTED            16394
    See Section 1.3.1.

NON_FIRST_FRAGMENTS_ALSO                 16395
    See Section 1.3.1.

3.11. Delete Payload 🗑️

The Delete payload, denoted D in this document, carries a protocol-specific Security Association identifier that the sender has already removed from its Security Association database, so that SPI is no longer valid 💅. Figure 17 shows what the Delete payload looks like 👀.

You can send several SPIs in one Delete payload, but every SPI in it MUST be for the same protocol 🔥. Mixing protocol identifiers MUST NOT be performed in the Delete payload. You're allowed to include multiple Delete payloads in a single INFORMATIONAL exchange, though, as long as each one lists SPIs for a different protocol 🎀.

Deleting the IKE SA is signaled by a protocol ID of 1 (IKE) with no SPIs at all 🌸. Deleting a Child SA, like ESP or AH, uses the IPsec protocol ID for that protocol (2 for AH, 3 for ESP), and the SPI is the one the sending endpoint would expect to see in inbound ESP or AH packets 🦋.

                    1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload  |C|  RESERVED   |         Payload Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Protocol ID   |   SPI Size    |          Num of SPIs          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~               Security Parameter Index(es) (SPI)              ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

           Figure 17:  Delete Payload Format

Here's the field breakdown 🧁:

  • Protocol ID (1 octet) - Must be 1 for an IKE SA, 2 for AH, or 3 for ESP.
  • SPI Size (1 octet) - Length in octets of the SPI as defined by the protocol ID. It MUST be zero for IKE (SPI is in message header) or four for AH and ESP.
  • Num of SPIs (2 octets, unsigned integer) - The number of SPIs contained in the Delete payload. The size of each SPI is defined by the SPI Size field.
  • Security Parameter Index(es) (variable length) - Identifies the specific Security Association(s) to delete. The length of this field is determined by the SPI Size and Num of SPIs fields.

The payload type for the Delete payload is forty-two (42) 🔢.


3.12. Vendor ID Payload 🌈

The Vendor ID payload, denoted V in this document, holds a vendor-defined constant 💖. Vendors use it to spot and recognize remote instances of their own implementations 👀. This is the trick that lets a vendor try out new features while staying backward compatible ✨.

A Vendor ID payload MAY announce that the sender can accept certain extensions to the protocol, or it MAY simply identify the implementation to help with debugging 🐛. A Vendor ID payload MUST NOT change the interpretation of any information defined in this specification (i.e., the critical bit MUST be set to 0) 🚫. You can send multiple Vendor ID payloads MAY be sent, too, so go wild 🌸. An implementation is not required to send any Vendor ID payload at all, no pressure 🫶.

A Vendor ID payload can ride along in any message 🧚. If you recognize a Vendor ID, you can use the private use numbers described throughout this document, like private payloads, private exchanges, private notifications, and so on 🔥. Unfamiliar Vendor IDs MUST be ignored 🙈.

Writers who want to extend this protocol MUST define a Vendor ID payload to announce that they can implement the extension in the document 📜. The expectation is that documents which gain acceptance and get standardized will be given "magic numbers" out of the Future Use range by IANA, and then the requirement to use a Vendor ID goes away 🎀.

The Vendor ID payload fields look like this 👇:

                    1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload  |C|  RESERVED   |         Payload Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                        Vendor ID (VID)                        ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

          Figure 18:  Vendor ID Payload Format
  • Vendor ID (variable length) - It is the responsibility of the person choosing the Vendor ID to assure its uniqueness in spite of the absence of any central registry for IDs. Good practice is to include a company name, a person name, or some such information. If you want to show off, you might include the latitude and longitude and time where you were when you chose the ID and some random input. A message digest of a long unique string is preferable to the long unique string itself 💅.

The payload type for the Vendor ID payload is forty-three (43) 🔢.

3.13. Traffic Selector Payload 🎀

okay so the Traffic Selector payload (we're calling it TS from here on 💅) is how peers say "hey, these are the packet flows I want IPsec security services to handle." 🦋 It's just the IKE generic payload header, followed by the individual Traffic Selectors lined up one after another ✨

                    1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload  |C|  RESERVED   |         Payload Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Number of TSs |                 RESERVED                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                       <Traffic Selectors>                     ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        Figure 19:  Traffic Selectors Payload Format

Here's the breakdown of the header fields 🌸

  • Number of TSs (1 octet) - how many Traffic Selectors are being provided. 🍓
  • RESERVED - this field MUST be sent as zero and MUST be ignored on receipt. 🙈 (no touching the reserved bits, bestie!)
  • Traffic Selectors (variable length) - one or more individual Traffic Selectors. 💜

The length of the Traffic Selector payload covers the TS header and all the Traffic Selectors inside it 🧚

The payload type for the Traffic Selector payload is forty-four (44) when it's describing addresses at the initiator's end of the SA, and forty-five (45) when it's describing addresses at the responder's end. 👑

Here's a fun one: there is zero requirement that TSi and TSr have the same number of individual Traffic Selectors 🌈 So they get interpreted like this: a packet matches a given TSi/TSr pair if it matches at least one of the individual selectors in TSi AND at least one of the individual selectors in TSr. It's giving mix-and-match energy 💅

For example, these Traffic Selectors:

TSi = ((17, 100, 198.51.100.66-198.51.100.66),
       (17, 200, 198.51.100.66-198.51.100.66))
TSr = ((17, 300, 0.0.0.0-255.255.255.255),
       (17, 400, 0.0.0.0-255.255.255.255))

would match UDP packets coming from 198.51.100.66 going to literally anywhere 🦋 with any of the four source/destination port combos: (100,300), (100,400), (200,300), and (200, 400). Ate and left no crumbs 💖

So some policies might need several Child SA pairs. 🫶 Like, a policy that only matches the (100,300) and (200,400) combos, but NOT the other two, can't be negotiated as a single Child SA pair. Not me needing a whole second pair just to get my policy right 😭

3.13.1. Traffic Selector 🦋

                    1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   TS Type     |IP Protocol ID*|       Selector Length         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Start Port*         |           End Port*           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                         Starting Address*                     ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                         Ending Address*                       ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
           Figure 20: Traffic Selector

Heads up 👀 every field except TS Type and Selector Length depends on which TS Type you're using. The fields shown here are for TS Types 7 and 8, which are the only two values defined right now ✨

Here's the rundown on each field 🌸

  • TS Type (one octet) - specifies the type of Traffic Selector. 💅
  • IP protocol ID (1 octet) - a value specifying an associated IP protocol ID (like UDP, TCP, and ICMP). A value of zero means the protocol ID doesn't matter for this Traffic Selector. The SA can carry all protocols 🌈
  • Selector Length - the length of this Traffic Selector substructure, header included. 🧚
  • Start Port (2 octets, unsigned integer) - the smallest port number this Traffic Selector allows. For protocols where port is undefined (including protocol 0), or if all ports are allowed, this field MUST be zero. ICMP and ICMPv6 Type and Code values, plus Mobile IP version 6 (MIPv6) mobility header (MH) Type values, get stored here as described in Section 4.4.1.1 of [IPSECARCH]. ICMP Type and Code get treated as one single 16-bit integer, with Type in the most significant eight bits and Code in the least significant eight bits. MIPv6 MH Type values get treated as one single 16-bit integer too, with Type in the most significant eight bits and the least significant eight bits set to zero. 🎀
  • End Port (2 octets, unsigned integer) - the largest port number this Traffic Selector allows. For protocols where port is undefined (including protocol 0), or if all ports are allowed, this field MUST be 65535. ICMP, ICMPv6, and MIPv6 MH Type values are represented here the same way as the start port, as specified in Section 4.4.1.1 of [IPSECARCH]: ICMP Type and Code form one 16-bit integer (Type up top, Code at the bottom), and MIPv6 MH Type values form one 16-bit integer with the least significant eight bits set to zero. 🦋
  • Starting Address - the smallest address included in this Traffic Selector (the length depends on TS Type). 🌸
  • Ending Address - the largest address included in this Traffic Selector (again, the length depends on TS Type). 💖

Systems complying with [IPSECARCH] that want to indicate "ANY" ports MUST set the start port to 0 and the end port to 65535. Quick note though: according to [IPSECARCH], "ANY" includes "OPAQUE" 🙈 Systems working with [IPSECARCH] that want to indicate "OPAQUE" ports, but NOT "ANY" ports, MUST set the start port to 65535 and the end port to 0. 🔥

⚠️ Watch the start and end port values here, because "ANY" and "OPAQUE" are kind of sneaky with their numbers. Mixing them up is the fastest way to end up with the wrong policy 💀

Traffic Selector types 7 and 8 can also point at ICMP or ICMPv6 type and code fields, plus MH Type fields for the IPv6 mobility header [MIPV6]. Just know that neither ICMP nor MIPv6 packets have separate source and destination fields 🥺 The method for specifying Traffic Selectors for ICMP and MIPv6 is shown by example in Section 4.4.1.3 of [IPSECARCH] ✨

Here's the table of values for the Traffic Selector Type field and the matching Address Selector Data. Heads up that these values were only current as of the publication date of RFC 4306 🕰️ Other values may have been added since then, or may get added after this document was published. For the latest and greatest, check [IKEV2IANA] 💜

TS Type                            Value
-------------------------------------------------------------------
TS_IPV4_ADDR_RANGE                  7

Type 7, TS_IPV4_ADDR_RANGE, is a range of IPv4 addresses, represented by two four-octet values. 🌈 The first value is the beginning IPv4 address (inclusive), and the second value is the ending IPv4 address (inclusive). Every address falling between those two gets counted as part of the list ✨

TS_IPV6_ADDR_RANGE                  8

Type 8, TS_IPV6_ADDR_RANGE, is the IPv6 version, a range of IPv6 addresses represented by two sixteen-octet values. 🧚 The first value is the beginning IPv6 address (inclusive), and the second is the ending IPv6 address (inclusive). Same deal: everything in between is part of the list 🫶

3.14. Encrypted Payload 🔐✨

Okay bestie, the Encrypted payload (written SK{...} in this doc) is literally a payload that carries other payloads inside it, all wrapped up in encryption 🎀 It's giving secret box energy. If it shows up in a message, it MUST be the last payload in there 💅 Usually it's the only payload in the message, lol. It's also called the "Encrypted and Authenticated" payload, iykyk 🦋

The encryption and integrity algorithms get negotiated during IKE SA setup, and the keys get computed the way Sections 2.14 and 2.18 explain 🧚

This doc spells out how Encrypted payloads get processed using a block cipher in CBC mode, plus an integrity check algorithm that makes a fixed-length checksum over a message of any size 🍓 The design is modeled after the ESP algorithms in RFCs 2104 [HMAC], 4303 [ESP], and 2451 [ESPCBC]. This document fully covers the crypto processing of IKE data, but those docs are where you go for the design rationale 💜 Future docs might cover Encrypted payloads for other transform types, like counter mode encryption and authenticated encryption algorithms. Peers MUST NOT negotiate transforms for which no such specification exists, so no sneaking in unspecced stuff 🙅

When an authenticated encryption algorithm protects the IKE SA, building the Encrypted payload works differently than what's described here. Check [AEAD] for the full tea on authenticated encryption and how it's used in ESP 🌈

The payload type for an Encrypted payload is forty-six (46). It starts with the IKE generic payload header, then these fields:

                    1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload  |C|  RESERVED   |         Payload Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                     Initialization Vector                     |
|         (length is block size for encryption algorithm)       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~                    Encrypted IKE Payloads                     ~
+               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |             Padding (0-255 octets)            |
+-+-+-+-+-+-+-+-+                               +-+-+-+-+-+-+-+-+
|                                               |  Pad Length   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~                    Integrity Checksum Data                    ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

          Figure 21:  Encrypted Payload Format
  • Next Payload: the payload type of the first embedded payload. Heads up, this is an exception to the standard header format 👀 Normally the Next Payload field would be zero, since Encrypted is the last payload in the message. But the content is embedded payloads and there was no natural spot to put the type of the first one, so that type goes here instead ✨
  • Payload Length: includes the lengths of the header, initialization vector (IV), Encrypted IKE payloads, Padding, Pad Length, and Integrity Checksum Data 📏
  • Initialization Vector: for CBC mode ciphers, the IV length equals the block length of the underlying encryption algorithm. Senders MUST select a new unpredictable IV for every message; recipients MUST accept any value. Go check [MODES] for IV generation advice, it's a must-read 📖 Specifically, reusing the final ciphertext block of the previous message is not considered unpredictable, so don't do that 🙅 For modes other than CBC, the IV format and processing is specified in the document that defines the encryption algorithm and mode.
  • IKE payloads: as specified earlier in this section. This field is encrypted with the negotiated cipher 🔒
  • Padding: MAY contain any value chosen by the sender, and MUST have a length that makes the combination of the payloads, the Padding, and the Pad Length a multiple of the encryption block size. This field is encrypted with the negotiated cipher 🧁
  • Pad Length: the length of the Padding field. The sender SHOULD set the Pad Length to the minimum value that makes the combination of the payloads, the Padding, and the Pad Length a multiple of the block size, but the recipient MUST accept any length that results in proper alignment. This field is encrypted with the negotiated cipher 🫶
  • Integrity Checksum Data: the cryptographic checksum of the entire message, starting with the Fixed IKE header through the Pad Length. The checksum MUST be computed over the encrypted message. Its length is determined by the integrity algorithm negotiated 🔥

3.15. Configuration Payload 🎀

The Configuration payload (denoted CP in this document) is how IKE peers swap configuration info 🌸 It's for an IRAC to ask an IRAS for an internal IP address, plus any other stuff you'd normally get from Dynamic Host Configuration Protocol (DHCP) if the IRAC was plugged straight into a LAN. Main character energy for networking 💖

The Configuration payload is defined as follows:

                    1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload  |C| RESERVED    |         Payload Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   CFG Type    |                    RESERVED                   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                   Configuration Attributes                    ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

          Figure 22:  Configuration Payload Format

The payload type for the Configuration payload is forty-seven (47) 🧚

  • CFG Type (1 octet): the type of exchange represented by the Configuration Attributes. The values in the table below are only current as of the publication date of RFC 4306. Other values may have been added since then or will be added after this document is published, so check [IKEV2IANA] for the latest values 🦋
CFG Type           Value
--------------------------
CFG_REQUEST        1
CFG_REPLY          2
CFG_SET            3
CFG_ACK            4
  • RESERVED (3 octets): MUST be sent as zero; MUST be ignored on receipt 🙈
  • Configuration Attributes (variable length): these are type length value (TLV) structures specific to the Configuration payload, and they're defined below. There may be zero or more Configuration Attributes in this payload 💜

3.15.1. Configuration Attributes

okay so this is the attribute layout, bestie 🎀 every attribute gets the same little header before its value:

                        1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |R|         Attribute Type      |            Length             |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                                                               |
   ~                             Value                             ~
   |                                                               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Figure 23: Configuration Attribute Format 🦋

  • Reserved (1 bit) 🫶 This bit MUST be set to zero and MUST be ignored on receipt.
  • Attribute Type (15 bits) 🌸 A unique identifier for each of the Configuration Attribute Types.
  • Length (2 octets, unsigned integer) 💅 The length in octets of the value.
  • Value (0 or more octets) ✨ The variable-length value of this Configuration Attribute. The attribute types are listed below.

The values in the table below were only current as of the publication date of RFC 4306, except INTERNAL_ADDRESS_EXPIRY and INTERNAL_IP6_NBNS, which this document removed 🥀. Other values may have been added since then, or will be added after this document is published. For the latest values, go check [IKEV2IANA] 🔥

      Attribute Type           Value  Multi-Valued  Length
      ------------------------------------------------------------
      INTERNAL_IP4_ADDRESS     1      YES*          0 or 4 octets
      INTERNAL_IP4_NETMASK     2      NO            0 or 4 octets
      INTERNAL_IP4_DNS         3      YES           0 or 4 octets
      INTERNAL_IP4_NBNS        4      YES           0 or 4 octets
      INTERNAL_IP4_DHCP        6      YES           0 or 4 octets
      APPLICATION_VERSION      7      NO            0 or more
      INTERNAL_IP6_ADDRESS     8      YES*          0 or 17 octets
      INTERNAL_IP6_DNS         10     YES           0 or 16 octets
      INTERNAL_IP6_DHCP        12     YES           0 or 16 octets
      INTERNAL_IP4_SUBNET      13     YES           0 or 8 octets
      SUPPORTED_ATTRIBUTES     14     NO            Multiple of 2
      INTERNAL_IP6_SUBNET      15     YES           17 octets

      * These attributes may be multi-valued on return only if
        multiple values were requested.
  • INTERNAL_IP4_ADDRESS, INTERNAL_IP6_ADDRESS 🌷 This is an address on the internal network, sometimes called a red node address or private address, and it MAY be a private address on the Internet. In a request, the address given is a requested address (or a zero-length address if you don't ask for anything specific). If you do ask for a specific one, it likely means you had a previous connection with that address and you'd like to reuse it. With IPv6, a requestor MAY supply the low-order address octets it wants to use. Multiple internal addresses MAY be requested by asking for multiple internal address attributes. The responder MAY only send up to the number of addresses requested. The INTERNAL_IP6_ADDRESS is made of two fields: a 16-octet IPv6 address, and a one-octet prefix-length as defined in [ADDRIPV6]. The requested address stays valid for as long as this IKE SA (or its rekeyed successors) that requested it stays valid. There's more on this in Section 3.15.3 🧚
  • INTERNAL_IP4_NETMASK 🍓 This is the internal network's netmask. Only one netmask is allowed in requests and responses (for example, 255.255.255.0), and it MUST be used only with an INTERNAL_IP4_ADDRESS attribute. In a CFG_REPLY, INTERNAL_IP4_NETMASK means roughly the same thing as an INTERNAL_IP4_SUBNET containing the same information ("send traffic to these addresses through me"), but it also implies a link boundary. For example, the client could use its own address and the netmask to work out the link's broadcast address. An empty INTERNAL_IP4_NETMASK attribute can be included in a CFG_REQUEST to ask for this information (although the gateway can send the information even when it wasn't requested). Non-empty values for this attribute in a CFG_REQUEST don't make sense, so they MUST NOT be included. 🙈
  • INTERNAL_IP4_DNS, INTERNAL_IP6_DNS 🌈 These specify an address of a DNS server within the network. Multiple DNS servers MAY be requested. The responder MAY respond with zero or more DNS server attributes. 💜
  • INTERNAL_IP4_NBNS 🦋 This specifies an address of a NetBIOS Name Server (WINS) within the network. Multiple NBNS servers MAY be requested. The responder MAY respond with zero or more NBNS server attributes. 🍓
  • INTERNAL_IP4_DHCP, INTERNAL_IP6_DHCP 🧚 This tells the host to send any internal DHCP requests to the address contained in the attribute. Multiple DHCP servers MAY be requested. The responder MAY respond with zero or more DHCP server attributes. 🌸
  • APPLICATION_VERSION 👑 This is the version or application information of the IPsec host. It's a string of printable ASCII characters that is NOT null terminated. 💅
  • INTERNAL_IP4_SUBNET 🌐 These are the protected sub-networks that this edge device protects. The attribute has two fields: the first is an IP address and the second is a netmask. Multiple sub-networks MAY be requested. The responder MAY respond with zero or more sub-network attributes. This is covered in more detail in Section 3.15.2 ✨
  • SUPPORTED_ATTRIBUTES 🔍 When this is used inside a Request, the attribute MUST be zero-length, and it asks the responder to send back every attribute it supports. The response contains an attribute holding a set of attribute identifiers, each in 2 octets. Dividing the length by 2 (in octets) gives the number of supported attributes in the response. 🫶
  • INTERNAL_IP6_SUBNET 💖 These are the protected sub-networks that this edge device protects. The attribute has two fields: the first is a 16-octet IPv6 address, and the second is a one-octet prefix-length as defined in [ADDRIPV6]. Multiple sub-networks MAY be requested. The responder MAY respond with zero or more sub-network attributes. This is covered in more detail in Section 3.15.2 🎀

Quick note, no recommendations are made in this document about how an implementation actually works out what to put in a response. In other words, we don't recommend any specific way for an IRAS to decide which DNS server to hand back to a requesting IRAC. Figuring that out is up to you 💅

The CFG_REQUEST and CFG_REPLY pair lets an IKE endpoint ask its peer for information. If an attribute in a CFG_REQUEST Configuration payload is not zero-length, it's treated as a suggestion for that attribute. The CFG_REPLY Configuration payload MAY return that value, or a new one. It MAY also add new attributes and leave out some of the requested ones. Unrecognized or unsupported attributes MUST be ignored in both requests and responses. 🌈

The CFG_SET and CFG_ACK pair lets an IKE endpoint push configuration data to its peer. Here, the CFG_SET Configuration payload contains the attributes the initiator wants its peer to change. If the responder accepted any of the configuration data, it MUST return a Configuration payload, and that payload MUST contain the attributes the responder accepted, with zero-length data. Any attributes it did not accept MUST NOT be in the CFG_ACK Configuration payload. If no attributes were accepted, the responder MUST return either an empty CFG_ACK payload or a response message without a CFG_ACK payload. Right now there are no defined uses for the CFG_SET/CFG_ACK exchange, though it might get used alongside extensions based on Vendor IDs. An implementation of this specification MAY ignore CFG_SET payloads. 😭

3.15.2. Meaning of INTERNAL_IP4_SUBNET and INTERNAL_IP6_SUBNET

ngl this part is a whole vibe 🌸 INTERNAL_IP4/6_SUBNET attributes can point out extra subnets, the kind that need one or more separate SAs, that you can reach through the gateway announcing the attributes. They can also show the gateway's policy about what traffic should go through it. The client can choose whether other traffic (covered by TSr but not in INTERNAL_IP4/6_SUBNET) goes through the gateway or straight to the destination. So traffic to the addresses listed in the INTERNAL_IP4/6_SUBNET attributes should be sent through the gateway that announced them. If there are no existing Child SAs whose Traffic Selectors cover the address in question, new SAs need to be created. 🦋

Here's an example. Say there are two subnets, 198.51.100.0/26 and 192.0.2.0/24, and the client's request contains the following:

CP(CFG_REQUEST) =
  INTERNAL_IP4_ADDRESS()
TSi = (0, 0-65535, 0.0.0.0-255.255.255.255)
TSr = (0, 0-65535, 0.0.0.0-255.255.255.255)

Then a valid response could be the following, where TSr and INTERNAL_IP4_SUBNET contain the same information:

CP(CFG_REPLY) =
  INTERNAL_IP4_ADDRESS(198.51.100.234)
  INTERNAL_IP4_SUBNET(198.51.100.0/255.255.255.192)
  INTERNAL_IP4_SUBNET(192.0.2.0/255.255.255.0)
TSi = (0, 0-65535, 198.51.100.234-198.51.100.234)
TSr = ((0, 0-65535, 198.51.100.0-198.51.100.63),
       (0, 0-65535, 192.0.2.0-192.0.2.255))

In cases like this, the INTERNAL_IP4_SUBNET doesn't really carry any useful information 🙄

A different response could have been this one:

CP(CFG_REPLY) =
  INTERNAL_IP4_ADDRESS(198.51.100.234)
  INTERNAL_IP4_SUBNET(198.51.100.0/255.255.255.192)
  INTERNAL_IP4_SUBNET(192.0.2.0/255.255.255.0)
TSi = (0, 0-65535, 198.51.100.234-198.51.100.234)
TSr = (0, 0-65535, 0.0.0.0-255.255.255.255)

That response would mean the client can send all its traffic through the gateway, but the gateway doesn't mind if the client sends traffic not covered by INTERNAL_IP4_SUBNET straight to the destination (without going through the gateway). 🌷

A different situation comes up if the gateway has a policy that requires traffic for the two subnets to be carried in separate SAs. Then a response like this tells the client that if it wants access to the second subnet, it needs to create a separate SA:

CP(CFG_REPLY) =
  INTERNAL_IP4_ADDRESS(198.51.100.234)
  INTERNAL_IP4_SUBNET(198.51.100.0/255.255.255.192)
  INTERNAL_IP4_SUBNET(192.0.2.0/255.255.255.0)
TSi = (0, 0-65535, 198.51.100.234-198.51.100.234)
TSr = (0, 0-65535, 198.51.100.0-198.51.100.63)

INTERNAL_IP4_SUBNET can also be useful if the client's TSr only covered part of the address space. For example, if the client requests the following:

CP(CFG_REQUEST) =
  INTERNAL_IP4_ADDRESS()
TSi = (0, 0-65535, 0.0.0.0-255.255.255.255)
TSr = (0, 0-65535, 192.0.2.155-192.0.2.155)

then the gateway's response might be:

CP(CFG_REPLY) =
  INTERNAL_IP4_ADDRESS(198.51.100.234)
  INTERNAL_IP4_SUBNET(198.51.100.0/255.255.255.192)
  INTERNAL_IP4_SUBNET(192.0.2.0/255.255.255.0)
TSi = (0, 0-65535, 198.51.100.234-198.51.100.234)
TSr = (0, 0-65535, 192.0.2.155-192.0.2.155)

Because the meaning of INTERNAL_IP4_SUBNET/INTERNAL_IP6_SUBNET in CFG_REQUESTs is unclear, they cannot be used reliably in CFG_REQUESTs. 🥺

3.15.3. Configuration Payloads for IPv6 🎀

okay so the IPv6 Configuration payloads are based on the IPv4 ones, but they don't fully follow the "normal IPv6 way of doing things" 🧚 bestie, there's no stateless autoconfiguration, no router advertisement messages, and no neighbor discovery! 💅 There's also an extra doc that talks about IPv6 configuration in IKEv2, [IPV6CONFIG]. It's still experimental for now, but people are hoping that once there's more implementation experience, it'll get the same standards treatment as this one ✨

A client can get an IPv6 address through the INTERNAL_IP6_ADDRESS Configuration payload 🦋 Here's a super minimal exchange:

CP(CFG_REQUEST) =
  INTERNAL_IP6_ADDRESS()
  INTERNAL_IP6_DNS()
TSi = (0, 0-65535, :: - FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF)
TSr = (0, 0-65535, :: - FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF)
CP(CFG_REPLY) =
  INTERNAL_IP6_ADDRESS(2001:DB8:0:1:2:3:4:5/64)
  INTERNAL_IP6_DNS(2001:DB8:99:88:77:66:55:44)
TSi = (0, 0-65535, 2001:DB8:0:1:2:3:4:5 - 2001:DB8:0:1:2:3:4:5)
TSr = (0, 0-65535, :: - FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF)

The client MAY send a non-empty INTERNAL_IP6_ADDRESS attribute in the CFG_REQUEST if it wants a specific address or interface identifier 🌸 The gateway checks first whether that address is acceptable, and if it is, it hands that one back. If it isn't acceptable, the gateway tries that interface identifier with some other prefix, and if even that doesn't work, it picks a totally different interface identifier 😭

The INTERNAL_IP6_ADDRESS attribute also has a prefix length field. When it shows up in a CFG_REPLY, it's the IPv6 version of the INTERNAL_IP4_NETMASK attribute from IPv4 land 🍓

Okay, real talk: this way of getting IPv6 addresses is pretty simple, but it has some limitations 🙈 IPsec tunnels set up with IKEv2 aren't fully featured "interfaces" in the IPv6 addressing architecture sense [ADDRIPV6]. They don't necessarily have link-local addresses, and that can make it messy for protocols that expect them, like [MLDV2]. Not me having to deal with that 💀


3.15.4. Address Assignment Failures 💔

If the responder hits an error while trying to assign an IP address to the initiator during processing of a Configuration payload, it responds with an INTERNAL_ADDRESS_FAILURE notification. The IKE SA still gets created even if the initial Child SA can't be created because of this failure. If this error happens inside an IKE_AUTH exchange, no Child SA will be created. There are also some more complicated error cases, though 😩

If the responder doesn't support Configuration payloads at all, it can just ignore all of them. An implementation like that never sends INTERNAL_ADDRESS_FAILURE notifications. If the initiator needs an IP address assigned, it will treat a response without CFG_REPLY as an error 🙃

The initiator may ask for a particular type of address (IPv4 or IPv6) that the responder doesn't support, even though the responder does support Configuration payloads. In that case, the responder just ignores the address type it doesn't support and processes the rest of the request as usual 🫶

If the initiator asks for multiple addresses of a type the responder supports, and some (but not all) of those requests fail, the responder replies with only the successful addresses. INTERNAL_ADDRESS_FAILURE only gets sent if no addresses can be assigned at all 🌈

If the initiator doesn't get the IP address(es) its policy requires, it MAY keep the IKE SA up and retry the Configuration payload as a separate INFORMATIONAL exchange after a suitable timeout. Or it MAY tear down the IKE SA by sending a Delete payload inside a separate INFORMATIONAL exchange, and then retry the IKE SA from the beginning after some timeout ⭐ That timeout shouldn't be too short (especially if the IKE SA is started from the beginning), because these error situations may not get fixed quickly. The timeout should likely be several minutes. For example, an address shortage on the responder will probably only get fixed when more entries are returned to the address pool because other clients disconnected, or when the responder is reconfigured with a larger address pool 🦋


3.16. Extensible Authentication Protocol (EAP) Payload ✨

The Extensible Authentication Protocol payload, which this document calls EAP, lets IKE SAs be authenticated using the protocol defined in RFC 3748 [EAP] and its later extensions 👑 When you use EAP, you have to pick an appropriate EAP method. Lots of these methods have been defined, each specifying how the protocol gets used with different authentication mechanisms. EAP method types are listed in [EAP-IANA]. Here's a quick summary of the EAP format so we're all on the same page 💜

                    1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload  |C|  RESERVED   |         Payload Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
~                       EAP Message                             ~
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

               Figure 24:  EAP Payload Format

The payload type for an EAP payload is forty-eight (48) 🔥

                    1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     Code      | Identifier    |           Length              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     Type      | Type_Data...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

               Figure 25:  EAP Message Format

Here's what each field in the EAP message does 🌸

  • Code (1 octet) tells you whether this message is a Request (1), Response (2), Success (3), or Failure (4).
  • Identifier (1 octet) is used in PPP to tell replayed messages apart from repeated ones. Since EAP runs over a reliable protocol in IKE, it serves no function here. In a response message, this octet MUST be set to match the identifier in the corresponding request.
  • Length (2 octets, unsigned integer) is the length of the EAP message, and it MUST be four less than the Payload Length of the encapsulating payload.
  • Type (1 octet) is only present if the Code field is Request (1) or Response (2). For other codes, the EAP message length MUST be four octets, and the Type and Type_Data fields MUST NOT be present. In a Request (1) message, Type indicates the data being requested. In a Response (2) message, Type MUST either be Nak or match the type of the data requested. Note that since IKE passes an indication of initiator identity in the first message in the IKE_AUTH exchange, the responder SHOULD NOT send EAP Identity requests (type 1). The initiator MAY, however, respond to such requests if it receives them.
  • Type_Data (Variable Length) varies with the Type of Request and the associated Response. For documentation of the EAP methods, see [EAP].

Note that since IKE passes an indication of initiator identity in the first message in the IKE_AUTH exchange, the responder should not send EAP Identity requests. The initiator may, however, respond to such requests if it receives them 🫶

4. Conformance Requirements ✨

okay so bestie, interop is literally the whole point 🫶 IKEv2 has a few "MUST support" requirements on top of the ones listed everywhere else, so everyone's implementations can actually talk to each other. 💅 Real talk though, IKEv2 is a security protocol, so its big job is letting only authorized parties finish setting up SAs 🔐. That means a particular implementation can be configured with restrictions on algorithms and trusted authorities, and those restrictions can stop it from interoperating with everyone. Not a bug, just security being security 🙈

IKEv2 is designed so you can build a minimal implementation that still interoperates with every compliant implementation ✨ These features are totally skippable in a minimal build:

  • Ability to negotiate SAs through a NAT and tunnel the resulting ESP SA over UDP.
  • Ability to request (and respond to a request for) a temporary IP address on the remote end of a tunnel.
  • Ability to support EAP-based authentication.
  • Ability to support window sizes greater than one.
  • Ability to establish multiple ESP or AH SAs within a single IKE SA.
  • Ability to rekey SAs.

Now the non-negotiables 💖 To assure interoperability, all implementations MUST be capable of parsing all payload types (even if it's just to skip over them), and they MUST ignore payload types they don't support unless the critical bit is set in the payload header. If the critical bit is set in an unsupported payload header, all implementations MUST reject the messages containing those payloads. No exceptions, periodt 💅

Every implementation MUST be capable of doing four-message IKE_SA_INIT and IKE_AUTH exchanges that establish two SAs, one for IKE and one for ESP or AH 🦋 Implementations MAY be initiate-only or respond-only if that's appropriate for their platform. Every implementation MUST also be capable of responding to an INFORMATIONAL exchange 🎀 A minimal implementation MAY respond to any request in the INFORMATIONAL exchange with an empty response. (Quick reminder, within the context of an IKE SA, an "empty" message is an IKE header followed by an Encrypted payload with no payloads inside it 🧚)

A minimal implementation MAY support the CREATE_CHILD_SA exchange only as far as recognizing requests and rejecting them with a Notify payload of type NO_ADDITIONAL_SAS 🌸 It also doesn't need to be able to initiate CREATE_CHILD_SA or INFORMATIONAL exchanges. When an SA expires (based on locally configured values of either lifetime or octets passed), an implementation MAY either try to renew it with a CREATE_CHILD_SA exchange, or it MAY delete (close) the old SA and create a new one ✨ If the responder rejects the CREATE_CHILD_SA request with a NO_ADDITIONAL_SAS notification, the implementation MUST be capable of instead deleting the old SA and creating a new one. That's the fallback, and it's mandatory 👑

Requesting or responding to temporary IP addresses is not required for implementations 🦋 But if an implementation does support issuing such requests and its policy requires using temporary IP addresses, it MUST include a CP payload in the first message in the IKE_AUTH exchange, containing at least a field of type INTERNAL_IP4_ADDRESS or INTERNAL_IP6_ADDRESS. All other fields are optional. If an implementation supports responding to such requests, it MUST parse the CP payload of type CFG_REQUEST in the first message in the IKE_AUTH exchange and recognize a field of type INTERNAL_IP4_ADDRESS or INTERNAL_IP6_ADDRESS 🌈 If it supports leasing an address of the appropriate type, it MUST return a CP payload of type CFG_REPLY containing an address of the requested type. The responder may include any other related attributes, which is giving very generous vibes 💜

Now, if you want to be called a conforming implementation 👑 it MUST be possible to configure it to accept the following:

  • Public Key Infrastructure using X.509 (PKIX) Certificates containing and signed by RSA keys of size 1024 or 2048 bits, where the ID passed is any of ID_KEY_ID, ID_FQDN, ID_RFC822_ADDR, or ID_DER_ASN1_DN. 🔑
  • Shared key authentication where the ID passed is any of ID_KEY_ID, ID_FQDN, or ID_RFC822_ADDR. 🗝️
  • Authentication where the responder is authenticated using PKIX Certificates and the initiator is authenticated using shared key authentication. 🫶

5. Security Considerations ✨

okay bestie, this section is where we get SERIOUS 🫶 The protocol is literally built to keep config info away from unauthenticated peeps, but ngl some disclosure is unavoidable. One peer or the other has to identify itself first and prove who it is first. To avoid probing, the initiator is required to identify itself first, and usually is required to authenticate itself first. The initiator can still learn that the responder supports IKE and what cryptographic protocols it supports. The responder (or someone impersonating the responder) can probe the initiator not only for its identity, but using CERTREQ payloads may be able to figure out which certificates the initiator is willing to use 👀

Use of EAP authentication changes the probing game a bit 🦋 When EAP authentication is used, the responder proves its identity before the initiator does, so an initiator that knew the name of a valid initiator could probe the responder for both its name and certificates.

Repeated rekeying using CREATE_CHILD_SA without additional Diffie-Hellman exchanges leaves all SAs vulnerable to cryptanalysis of a single key. Implementers should take note of this fact and set a limit on CREATE_CHILD_SA exchanges between exponentiations. This document does not prescribe such a limit 💅

The strength of a key derived from a Diffie-Hellman exchange using any of the groups defined here depends on the inherent strength of the group, the size of the exponent used, and the entropy provided by the random number generator used. Because of these inputs, it is difficult to determine the strength of a key for any of the defined groups 🌈 Diffie-Hellman group number two, when used with a strong random number generator and an exponent no less than 200 bits, is common for use with 3DES. Group five provides greater security than group two. Group one is for historic purposes only and does not provide sufficient strength, except for use with DES, which is also for historic use only. Implementations should make note of these estimates when establishing policy and negotiating security parameters 🧚

Note that these limitations are on the Diffie-Hellman groups themselves. There is nothing in IKE that prohibits using stronger groups, nor is there anything that will dilute the strength obtained from stronger groups (limited by the strength of the other algorithms negotiated, including the PRF). In fact, the extensible framework of IKE encourages the definition of more groups; use of elliptic curve groups may greatly increase strength using much smaller numbers 🔥

It is assumed that all Diffie-Hellman exponents are erased from memory after use 🫧

The IKE_SA_INIT and IKE_AUTH exchanges happen before the initiator has been authenticated, which means an implementation of this protocol needs to be completely robust when deployed on any insecure network 😭 Implementation vulnerabilities, particularly DoS attacks, can be exploited by unauthenticated peers. This issue is especially worrisome because of the unlimited number of messages in EAP-based authentication.

The strength of all keys is limited by the size of the output of the negotiated PRF. For this reason, a PRF whose output is less than 128 bits (e.g., 3DES-CBC) MUST NOT be used with this protocol 🚫

The security of this protocol is critically dependent on the randomness of the randomly chosen parameters 🎲 These should be generated by a strong random or properly seeded pseudorandom source (see [RANDOMNESS]). Implementers should take care to ensure that the use of random numbers for both keys and nonces is engineered in a way that does not undermine the security of the keys.

For information on the rationale behind many of the cryptographic design choices in this protocol, see [SIGMA] and [SKEME]. Though the security of negotiated Child SAs does not depend on the strength of the encryption and integrity protection negotiated in the IKE SA, implementations MUST NOT negotiate NONE as the IKE integrity protection algorithm or ENCR_NULL as the IKE encryption algorithm 🛑

When using pre-shared keys, a critical consideration is how to assure the randomness of these secrets. The strongest practice is to ensure that any pre-shared key contains as much randomness as the strongest key being negotiated. Deriving a shared secret from a password, name, or other low-entropy source is not secure. These sources are subject to dictionary and social-engineering attacks, among others 🙅‍♀️

The NAT_DETECTION_*_IP notifications contain a hash of the addresses and ports in an attempt to hide internal IP addresses behind a NAT. Since the IPv4 address space is only 32 bits, and it is usually very sparse, it would be possible for an attacker to find out the internal address used behind the NAT box by trying all possible IP addresses and checking for the matching hash. The port numbers are normally fixed to 500, and the SPIs can be extracted from the packet. This reduces the number of hash calculations to 2^32. With an educated guess about the use of private address space, the number of hash calculations is much smaller. Designers should therefore not assume that use of IKE will not leak internal address information 🙈

When using an EAP authentication method that does not generate a shared key for protecting a subsequent AUTH payload, certain man-in-the-middle and server-impersonation attacks are possible [EAPMITM]. These vulnerabilities occur when EAP is also used in protocols that are not protected with a secure tunnel. Since EAP is a general-purpose authentication protocol, which is often used to provide single-signon facilities, a deployed IPsec solution that relies on an EAP authentication method that does not generate a shared key (also known as a non-key-generating EAP method) can become compromised due to the deployment of an entirely unrelated application that also happens to use the same non-key-generating EAP method, but in an unprotected fashion. Note that this vulnerability is not limited to just EAP, but can occur in other scenarios where an authentication infrastructure is reused. For example, if the EAP mechanism used by IKEv2 utilizes a token authenticator, a man-in-the-middle attacker could impersonate the web server, intercept the token authentication exchange, and use it to initiate an IKEv2 connection 😱 For this reason, use of non-key-generating EAP methods SHOULD be avoided where possible. Where they are used, it is extremely important that all usages of these EAP methods SHOULD utilize a protected tunnel, where the initiator validates the responder's certificate before initiating the EAP authentication. Implementers should describe the vulnerabilities of using non-key-generating EAP methods in the documentation of their implementations so that the administrators deploying IPsec solutions are aware of these dangers 💜

An implementation using EAP MUST also use a public-key-based authentication of the server to the client before the EAP authentication begins, even if the EAP method offers mutual authentication. This avoids having additional IKEv2 protocol variations and protects the EAP data from active attackers 🛡️

If the messages of IKEv2 are long enough that IP-level fragmentation is necessary, it is possible that attackers could prevent the exchange from completing by exhausting the reassembly buffers. The chances of this can be minimized by using the Hash and URL encodings instead of sending certificates (see Section 3.6). Additional mitigations are discussed in [DOSUDPPROT]. 🧯

Admission control is critical to the security of the protocol 🚪 For example, trust anchors used for identifying IKE peers should probably be different than those used for other forms of trust, such as those used to identify public web servers. Moreover, although IKE provides a great deal of leeway in defining the security policy for a trusted peer's identity, credentials, and the correlation between them, having such security policy defined explicitly is essential to a secure implementation ⭐

5.1. Traffic Selector Authorization

IKEv2 relies on information in the Peer Authorization Database (PAD) when determining what kind of Child SAs a peer is allowed to create. This process is described in Section 4.4.3 of [IPSECARCH]. When a peer requests the creation of a Child SA with some Traffic Selectors, the PAD must contain "Child SA Authorization Data" linking the identity authenticated by IKEv2 and the addresses permitted for Traffic Selectors 🗝️

For example, the PAD might be configured so that the authenticated identity "sgw23.example.com" is allowed to create Child SAs for 192.0.2.0/24, meaning this security gateway is a valid "representative" for these addresses. Host-to-host IPsec requires similar entries, linking, for example, "fooserver4.example.com" with 198.51.100.66/32, meaning this identity is a valid "owner" or "representative" of the address in question 🎀

As noted in [IPSECARCH], "It is necessary to impose these constraints on creation of child SAs to prevent an authenticated peer from spoofing IDs associated with other, legitimate peers". In the example given above, a correct configuration of the PAD prevents sgw23 from creating Child SAs with address 198.51.100.66, and prevents fooserver4 from creating Child SAs with addresses from 192.0.2.0/24 🙅‍♀️

It is important to note that simply sending IKEv2 packets using some particular address does not imply permission to create Child SAs with that address in the Traffic Selectors. For example, even if sgw23 were able to spoof its IP address as 198.51.100.66, it could not create Child SAs matching fooserver4's traffic 🧠

The IKEv2 specification does not specify how exactly IP address assignment using Configuration payloads interacts with the PAD. Our interpretation is that when a security gateway assigns an address using Configuration payloads, it also creates a temporary PAD entry linking the authenticated peer identity and the newly allocated inner address. ✨

It has been recognized that configuring the PAD correctly may be difficult in some environments. For instance, if IPsec is used between a pair of hosts whose addresses are allocated dynamically using DHCP, it is extremely difficult to ensure that the PAD specifies the correct "owner" for each IP address. This would require a mechanism to securely convey address assignments from the DHCP server, and link them to identities authenticated using IKEv2 🥺

Due to this limitation, some vendors have been known to configure their PADs to allow an authenticated peer to create Child SAs with Traffic Selectors containing the same address that was used for the IKEv2 packets. In environments where IP spoofing is possible (i.e., almost everywhere), this essentially allows any peer to create Child SAs with any Traffic Selectors. This is not an appropriate or secure configuration in most circumstances 💀 See [H2HIPSEC] for an extensive discussion about this issue, and the limitations of host-to-host IPsec in general.

6. IANA Considerations 🎀

okay so IANA already has a lot on file. [IKEV2] defined a ton of field types and values, and IANA registered all of them in [IKEV2IANA] 🗂️ so we're not listing them again bestie, no need to repeat the whole catalogue 💅

two things got cut from the IKEv2 Configuration Payload Attribute Types table: INTERNAL_IP6_NBNS and INTERNAL_ADDRESS_EXPIRY 🫠 gone, like they were never there 👋

then there are two brand new entries for the IKEv2 parameters "NOTIFY MESSAGES - ERROR TYPES" registry. These ones were NOT defined in [IKEV2], so this document is introducing them 🆕✨

43   TEMPORARY_FAILURE
44   CHILD_SA_NOT_FOUND

the Payload Types table got a glow-up too 🦋 IANA changed entry 46 from this:

46        Encrypted                        E          [IKEV2]

to this:

46        Encrypted and Authenticated      SK    [This document]

so it's now the SK payload, and this document is the place to look for it 🔥

last thing: IANA has pointed every reference to RFC 4306 over to this document instead 🌈 so anywhere you see the old number, the new one is what counts 💜


7. Acknowledgements 🫶

so many people from the IPsecME Working Group helped out 🌸 they threw in ideas, wrote text, and reviewed the clarifications other folks suggested. absolute legends 😭

the acknowledgements from the IKEv2 document go like this 💖

This document is a collaborative effort of the entire IPsec WG. If there were no limit to the number of authors that could appear on an RFC, the following, in alphabetical order, would have been listed: Bill Aiello, Stephane Beaulieu, Steve Bellovin, Sara Bitan, Matt Blaze, Ran Canetti, Darren Dukes, Dan Harkins, Paul Hoffman, John Ioannidis, Charlie Kaufman, Steve Kent, Angelos Keromytis, Tero Kivinen, Hugo Krawczyk, Andrew Krywaniuk, Radia Perlman, Omer Reingold, and Michael Richardson. Many other people contributed to the design. It is an evolution of IKEv1, ISAKMP, and the IPsec DOI, each of which has its own list of authors. Hugh Daniel suggested the feature of having the initiator, in message 3, specify a name for the responder, and gave the feature the cute name "You Tarzan, Me Jane". David Faucher and Valery Smyslov helped refine the design of the Traffic Selector negotiation.

the "You Tarzan, Me Jane" name is iconic 🍓 someone had to come up with it and honestly they earned it 👑


8. References 📚

8.1. Normative References

these are the sources this document leans on, and they're listed with every detail intact 🧚

[ADDGROUP] Kivinen, T. and M. Kojo, "More Modular Exponential (MODP)
           Diffie-Hellman groups for Internet Key Exchange (IKE)",
           RFC 3526, May 2003.

[ADDRIPV6] Hinden, R. and S. Deering, "IP Version 6 Addressing
           Architecture", RFC 4291, February 2006.

[AEAD]     Black, D. and D. McGrew, "Using Authenticated Encryption
           Algorithms with the Encrypted Payload of the Internet Key
           Exchange version 2 (IKEv2) Protocol", RFC 5282,
           August 2008.

[AESCMACPRF128]
           Song, J., Poovendran, R., Lee, J., and T. Iwata, "The
           Advanced Encryption Standard-Cipher-based Message
           Authentication Code-Pseudo-Random Function-128 (AES-CMAC-
           PRF-128) Algorithm for the Internet Key Exchange Protocol
           (IKE)", RFC 4615, August 2006.

[AESXCBCPRF128]
           Hoffman, P., "The AES-XCBC-PRF-128 Algorithm for the
           Internet Key Exchange Protocol (IKE)", RFC 4434,
           February 2006.

[EAP]      Aboba, B., Blunk, L., Vollbrecht, J., Carlson, J., and H.
           Levkowetz, "Extensible Authentication Protocol (EAP)",
           RFC 3748, June 2004.

[ECN]      Ramakrishnan, K., Floyd, S., and D. Black, "The Addition
           of Explicit Congestion Notification (ECN) to IP",
           RFC 3168, September 2001.

[ESPCBC]   Pereira, R. and R. Adams, "The ESP CBC-Mode Cipher
           Algorithms", RFC 2451, November 1998.

[HTTP]     Fielding, R., Gettys, J., Mogul, J., Frystyk, H.,
           Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext
           Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999.

[IKEV2IANA]
           "Internet Key Exchange Version 2 (IKEv2) Parameters",
           <http://www.iana.org>.

[IPSECARCH]
           Kent, S. and K. Seo, "Security Architecture for the
           Internet Protocol", RFC 4301, December 2005.

[MUSTSHOULD]
           Bradner, S., "Key words for use in RFCs to Indicate
           Requirement Levels", BCP 14, RFC 2119, March 1997.

[PKCS1]    Jonsson, J. and B. Kaliski, "Public-Key Cryptography
           Standards (PKCS) #1: RSA Cryptography Specifications
           Version 2.1", RFC 3447, February 2003.

[PKIX]     Cooper, D., Santesson, S., Farrell, S., Boeyen, S.,
           Housley, R., and W. Polk, "Internet X.509 Public Key
           Infrastructure Certificate and Certificate Revocation List
           (CRL) Profile", RFC 5280, May 2008.

[RFC4307]  Schiller, J., "Cryptographic Algorithms for Use in the
           Internet Key Exchange Version 2 (IKEv2)", RFC 4307,
           December 2005.

[UDPENCAPS]
           Huttunen, A., Swander, B., Volpe, V., DiBurro, L., and M.
           Stenberg, "UDP Encapsulation of IPsec ESP Packets",
           RFC 3948, January 2005.

[URLS]     Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform
           Resource Identifier (URI): Generic Syntax", STD 66,
           RFC 3986, January 2005.

8.2. Informative References 📚✨

okay so these are the "go read this if you want the backstory" refs 🤓 they're not required to implement IKEv2, but they're lowkey the receipts for everything. bestie, these are the ones I'd bookmark 🔖

[AH] Kent, S., "IP Authentication Header", RFC 4302, December 2005.

[ARCHGUIDEPHIL] Bush, R. and D. Meyer, "Some Internet Architectural Guidelines and Philosophy", RFC 3439, December 2002.

[ARCHPRINC] Carpenter, B., "Architectural Principles of the Internet", RFC 1958, June 1996.

[Clarif] Eronen, P. and P. Hoffman, "IKEv2 Clarifications and Implementation Guidelines", RFC 4718, October 2006.

[DES] American National Standards Institute, "American National Standard for Information Systems-Data Link Encryption", ANSI X3.106, 1983.

[DH] Diffie, W. and M. Hellman, "New Directions in Cryptography", IEEE Transactions on Information Theory, V.IT-22 n. 6, June 1977.

[DIFFSERVARCH] Blake, S., Black, D., Carlson, M., Davies, E., Wang, Z., and W. Weiss, "An Architecture for Differentiated Services", RFC 2475, December 1998.

[DIFFSERVFIELD] Nichols, K., Blake, S., Baker, F., and D. Black, "Definition of the Differentiated Services Field (DS Field) in the IPv4 and IPv6 Headers", RFC 2474, December 1998.

[DIFFTUNNEL] Black, D., "Differentiated Services and Tunnels", RFC 2983, October 2000.

[DOI] Piper, D., "The Internet IP Security Domain of Interpretation for ISAKMP", RFC 2407, November 1998.

[DOSUDPPROT] C. Kaufman, R. Perlman, and B. Sommerfeld, "DoS protection for UDP-based protocols", ACM Conference on Computer and Communications Security, October 2003.

[DSS] National Institute of Standards and Technology, U.S. Department of Commerce, "Digital Signature Standard", Draft FIPS 186-3, June 2008.

[EAI] Abel, Y., "Internationalized Email Headers", RFC 5335, September 2008.

[EAP-IANA] "Extensible Authentication Protocol (EAP) Registry: Method Types", <http://www.iana.org>.

[EAPMITM] N. Asokan, V. Nierni, and K. Nyberg, "Man-in-the-Middle in Tunneled Authentication Protocols", November 2002, <http://eprint.iacr.org/2002/163>.

[ESP] Kent, S., "IP Encapsulating Security Payload (ESP)", RFC 4303, December 2005.

[EXCHANGEANALYSIS] R. Perlman and C. Kaufman, "Analysis of the IPsec key exchange Standard", WET-ICE Security Conference, MIT, 2001, <http://sec.femto.org/wetice-2001/papers/radia-paper.pdf>.

[H2HIPSEC] Aura, T., Roe, M., and A. Mohammed, "Experiences with Host-to-Host IPsec", 13th International Workshop on Security Protocols, Cambridge, UK, April 2005.

[HMAC] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed-Hashing for Message Authentication", RFC 2104, February 1997.

[IDEA] X. Lai, "On the Design and Security of Block Ciphers", ETH Series in Information Processing, v. 1, Konstanz: Hartung-Gorre Verlag, 1992.

[IDNA] Klensin, J., "Internationalized Domain Names for Applications (IDNA): Definitions and Document Framework", RFC 5890, August 2010.

[IKEV1] Harkins, D. and D. Carrel, "The Internet Key Exchange (IKE)", RFC 2409, November 1998.

[IKEV2] Kaufman, C., "Internet Key Exchange (IKEv2) Protocol", RFC 4306, December 2005.

[IP] Postel, J., "Internet Protocol", STD 5, RFC 791, September 1981.

[IP-COMP] Shacham, A., Monsour, B., Pereira, R., and M. Thomas, "IP Payload Compression Protocol (IPComp)", RFC 3173, September 2001.

[IPSECARCH-OLD] Kent, S. and R. Atkinson, "Security Architecture for the Internet Protocol", RFC 2401, November 1998.

[IPV6CONFIG] Eronen, P., Laganier, J., and C. Madson, "IPv6 Configuration in Internet Key Exchange Protocol Version 2 (IKEv2)", RFC 5739, February 2010.

[ISAKMP] Maughan, D., Schneider, M., and M. Schertler, "Internet Security Association and Key Management Protocol (ISAKMP)", RFC 2408, November 1998.

[MAILFORMAT] Resnick, P., Ed., "Internet Message Format", RFC 5322, October 2008.

[MD5] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, April 1992.

[MIPV6] Johnson, D., Perkins, C., and J. Arkko, "Mobility Support in IPv6", RFC 3775, June 2004.

[MLDV2] Vida, R. and L. Costa, "Multicast Listener Discovery Version 2 (MLDv2) for IPv6", RFC 3810, June 2004.

[MOBIKE] Eronen, P., "IKEv2 Mobility and Multihoming Protocol (MOBIKE)", RFC 4555, June 2006.

[MODES] National Institute of Standards and Technology, U.S. Department of Commerce, "Recommendation for Block Cipher Modes of Operation", SP 800-38A, 2001.

[NAI] Aboba, B., Beadles, M., Arkko, J., and P. Eronen, "The Network Access Identifier", RFC 4282, December 2005.

[NATREQ] Aboba, B. and W. Dixon, "IPsec-Network Address Translation (NAT) Compatibility Requirements", RFC 3715, March 2004.

[OAKLEY] Orman, H., "The OAKLEY Key Determination Protocol", RFC 2412, November 1998.

[PFKEY] McDonald, D., Metz, C., and B. Phan, "PF_KEY Key Management API, Version 2", RFC 2367, July 1998.

[PHOTURIS] Karn, P. and W. Simpson, "Photuris: Session-Key Management Protocol", RFC 2522, March 1999.

[RANDOMNESS] Eastlake, D., Schiller, J., and S. Crocker, "Randomness Requirements for Security", BCP 106, RFC 4086, June 2005.

[REAUTH] Nir, Y., "Repeated Authentication in Internet Key Exchange (IKEv2) Protocol", RFC 4478, April 2006.

[REUSE] Menezes, A. and B. Ustaoglu, "On Reusing Ephemeral Keys In Diffie-Hellman Key Agreement Protocols", December 2008, <http://www.cacr.math.uwaterloo.ca/techreports/2008/cacr2008-24.pdf>.

[ROHCV2] Ertekin, E., Christou, C., Jasani, R., Kivinen, T., and C. Bormann, "IKEv2 Extensions to Support Robust Header Compression over IPsec", RFC 5857, May 2010.

[RSA] R. Rivest, A. Shamir, and L. Adleman, "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems", February 1978.

[SHA] National Institute of Standards and Technology, U.S. Department of Commerce, "Secure Hash Standard", FIPS 180-3, October 2008.

[SIGMA] H. Krawczyk, "SIGMA: the SIGn-and-MAc' Approach to Authenticated Diffie-Hellman and its Use in the IKE Protocols", Advances in Cryptography - CRYPTO 2003 Proceedings LNCS 2729, 2003, <http://www.informatik.uni-trier.de/~ley/db/conf/crypto/crypto2003.html>`.

[SKEME] H. Krawczyk, "SKEME: A Versatile Secure Key Exchange Mechanism for Internet", IEEE Proceedings of the 1996 Symposium on Network and Distributed Systems Security , 1996.

[TRANSPARENCY] Carpenter, B., "Internet Transparency", RFC 2775, February 2000.


Appendix A. Summary of Changes from IKEv1 🔄💅

the glow-up glow-up 🌈 this is where IKEv2 explains how it's different from IKEv1 and honestly the receipts are immaculate. the goals were:

  1. To define the entire IKE protocol in a single document, replacing RFCs 2407, 2408, and 2409 and incorporating subsequent changes to support NAT Traversal, Extensible Authentication, and Remote Address acquisition;
  2. To simplify IKE by replacing the eight different initial exchanges with a single four-message exchange (with changes in authentication mechanisms affecting only a single AUTH payload rather than restructuring the entire exchange) see [EXCHANGEANALYSIS];
  3. To remove the Domain of Interpretation (DOI), Situation (SIT), and Labeled Domain Identifier fields, and the Commit and Authentication only bits;
  4. To decrease IKE's latency in the common case by making the initial exchange be 2 round trips (4 messages), and allowing the ability to piggyback setup of a Child SA on that exchange;
  5. To replace the cryptographic syntax for protecting the IKE messages themselves with one based closely on ESP to simplify implementation and security analysis;
  6. To reduce the number of possible error states by making the protocol reliable (all messages are acknowledged) and sequenced. This allows shortening CREATE_CHILD_SA exchanges from 3 messages to 2;
  7. To increase robustness by allowing the responder to not do significant processing until it receives a message proving that the initiator can receive messages at its claimed IP address;
  8. To fix cryptographic weaknesses such as the problem with symmetries in hashes used for authentication (documented by Tero Kivinen);
  9. To specify Traffic Selectors in their own payloads type rather than overloading ID payloads, and making more flexible the Traffic Selectors that may be specified;
  10. To specify required behavior under certain error conditions or when data that is not understood is received in order to make it easier to make future revisions in a way that does not break backward compatibility;
  11. To simplify and clarify how shared state is maintained in the presence of network failures and DoS attacks; and
  12. To maintain existing syntax and magic numbers to the extent possible to make it likely that implementations of IKEv1 can be enhanced to support IKEv2 with minimum effort.

Appendix B. Diffie-Hellman Groups 🔢🫶

okay this is the math bit and i'm not gonna lie, these primes are giving main character energy ✨ there are two Diffie-Hellman groups defined here for use in IKE. they were generated by Richard Schroeppel at the University of Arizona, and the properties of these primes are described in [OAKLEY].

the strength supplied by group 1 may not be sufficient for typical uses and is here for historic reasons. 💀

additional Diffie-Hellman groups have been defined in [ADDGROUP].

B.1. Group 1 - 768-bit MODP 🌸

this group is assigned ID 1 (one).

The prime is: 2^768 - 2 ^704 - 1 + 2^64 * { [2^638 pi] + 149686 } Its hexadecimal value is:

FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1
29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD
EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245
E485B576 625E7EC6 F44C42E9 A63A3620 FFFFFFFF FFFFFFFF

The generator is 2.

B.2. Group 2 - 1024-bit MODP 🦋

this group is assigned ID 2 (two).

The prime is 2^1024 - 2^960 - 1 + 2^64 * { [2^894 pi] + 129093 }. Its hexadecimal value is:

FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1
29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD
EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245
E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED
EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE65381
FFFFFFFF FFFFFFFF

The generator is 2.


Appendix C. Exchanges and Payloads 🧚

okay last bit for now 🥹 this appendix is a quick summary of the IKEv2 exchanges and which payloads can show up in which message. it's purely informative, so if it ever disagrees with the body of the document, the other text is considered correct. 🫶

vendor ID (V) payloads may be included in any place in any message. this sequence here shows what are the most logical places for them. 💜

C.1. IKE_SA_INIT Exchange ✨

Okay bestie, the IKE_SA_INIT exchange is where the whole party starts 🎀 Here's the diagram, no cap 💅

   request             --> [N(COOKIE)],
                           SA, KE, Ni,
                           [N(NAT_DETECTION_SOURCE_IP)+,
                            N(NAT_DETECTION_DESTINATION_IP)],
                           [V+][N+]

   normal response     <-- SA, KE, Nr,
   (no cookie)             [N(NAT_DETECTION_SOURCE_IP),
                            N(NAT_DETECTION_DESTINATION_IP)],
                           [[N(HTTP_CERT_LOOKUP_SUPPORTED)], CERTREQ+],
                           [V+][N+]

   cookie response     <-- N(COOKIE),
                           [V+][N+]

   different Diffie-   <-- N(INVALID_KE_PAYLOAD),
   Hellman group           [V+][N+]
   wanted

C.2. IKE_AUTH Exchange without EAP 🦋

This one's the IKE_AUTH exchange when EAP isn't in the picture 🌸

   request             --> IDi, [CERT+],
                           [N(INITIAL_CONTACT)],
                           [[N(HTTP_CERT_LOOKUP_SUPPORTED)], CERTREQ+],
                           [IDr],
                           AUTH,
                           [CP(CFG_REQUEST)],
                           [N(IPCOMP_SUPPORTED)+],
                           [N(USE_TRANSPORT_MODE)],
                           [N(ESP_TFC_PADDING_NOT_SUPPORTED)],
                           [N(NON_FIRST_FRAGMENTS_ALSO)],
                           SA, TSi, TSr,
                           [V+][N+]

   response            <-- IDr, [CERT+],
                           AUTH,
                           [CP(CFG_REPLY)],
                           [N(IPCOMP_SUPPORTED)],
                           [N(USE_TRANSPORT_MODE)],
                           [N(ESP_TFC_PADDING_NOT_SUPPORTED)],
                           [N(NON_FIRST_FRAGMENTS_ALSO)],
                           SA, TSi, TSr,
                           [N(ADDITIONAL_TS_POSSIBLE)],
                           [V+][N+]

   error in Child SA  <--  IDr, [CERT+],
   creation                AUTH,
                           N(error),
                           [V+][N+]

C.3. IKE_AUTH Exchange with EAP 🌈

Same vibe, but now EAP joins the group chat 🫶 It goes back and forth as many times as needed, periodt 💜

   first request       --> IDi,
                           [N(INITIAL_CONTACT)],
                           [[N(HTTP_CERT_LOOKUP_SUPPORTED)], CERTREQ+],
                           [IDr],
                           [CP(CFG_REQUEST)],
                           [N(IPCOMP_SUPPORTED)+],
                           [N(USE_TRANSPORT_MODE)],
                           [N(ESP_TFC_PADDING_NOT_SUPPORTED)],
                           [N(NON_FIRST_FRAGMENTS_ALSO)],
                           SA, TSi, TSr,
                           [V+][N+]

   first response      <-- IDr, [CERT+], AUTH,
                           EAP,
                           [V+][N+]

                     / --> EAP
   repeat 1..N times |
                     \ <-- EAP

   last request        --> AUTH

   last response       <-- AUTH,
                           [CP(CFG_REPLY)],
                           [N(IPCOMP_SUPPORTED)],
                           [N(USE_TRANSPORT_MODE)],
                           [N(ESP_TFC_PADDING_NOT_SUPPORTED)],
                           [N(NON_FIRST_FRAGMENTS_ALSO)],
                           SA, TSi, TSr,
                           [N(ADDITIONAL_TS_POSSIBLE)],
                           [V+][N+]

C.4. CREATE_CHILD_SA Exchange for Creating or Rekeying Child SAs ⭐

This is the one for making new Child SAs or rekeying existing ones 🍓

   request             --> [N(REKEY_SA)],
                           [CP(CFG_REQUEST)],
                           [N(IPCOMP_SUPPORTED)+],
                           [N(USE_TRANSPORT_MODE)],
                           [N(ESP_TFC_PADDING_NOT_SUPPORTED)],
                           [N(NON_FIRST_FRAGMENTS_ALSO)],
                           SA, Ni, [KEi], TSi, TSr
                           [V+][N+]

   normal              <-- [CP(CFG_REPLY)],
   response                [N(IPCOMP_SUPPORTED)],
                           [N(USE_TRANSPORT_MODE)],
                           [N(ESP_TFC_PADDING_NOT_SUPPORTED)],
                           [N(NON_FIRST_FRAGMENTS_ALSO)],
                           SA, Nr, [KEr], TSi, TSr,
                           [N(ADDITIONAL_TS_POSSIBLE)]
                           [V+][N+]

   error case          <-- N(error)

   different Diffie-   <-- N(INVALID_KE_PAYLOAD),
   Hellman group           [V+][N+]
   wanted

C.5. CREATE_CHILD_SA Exchange for Rekeying the IKE SA 🧚

And this one's the special exchange for rekeying the IKE SA itself 👑

   request             --> SA, Ni, KEi
                           [V+][N+]

   response            <-- SA, Nr, KEr
                           [V+][N+]

C.6. INFORMATIONAL Exchange 💀

Last but not least, the INFORMATIONAL exchange, which is basically the catch-up chat of the whole protocol 🙈

   request             --> [N+],
                           [D+],
                           [CP(CFG_REQUEST)]

   response            <-- [N+],
                           [D+],
                           [CP(CFG_REPLY)]

Authors' Addresses 💖

Here are the people who made this whole thing happen, with their contact info 🎀

   Charlie Kaufman
   Microsoft
   1 Microsoft Way
   Redmond, WA  98052
   US

   Phone: 1-425-707-3335
   EMail: charliek@microsoft.com


   Paul Hoffman
   VPN Consortium
   127 Segre Place
   Santa Cruz, CA  95060
   US

   Phone: 1-831-426-9827
   EMail: paul.hoffman@vpnc.org


   Yoav Nir
   Check Point Software Technologies Ltd.
   5 Hasolelim St.
   Tel Aviv 67897
   Israel

   EMail: ynir@checkpoint.com


   Pasi Eronen
   Independent

   EMail: pe@iki.fi
📦 where this page comes from