RFC 4306

Internet Key Exchange (IKEv2) Protocol

๐Ÿ“… published December 2005, from ietf

RFC 4306: Internet Key Exchange (IKEv2) Protocol ๐ŸŽ€

Okay bestie, here's the title block tea โ˜•:

  • Network Working Group ๐ŸŒธ
  • Request for Comments: 4306
  • Authors: C. Kaufman, Ed., from Microsoft ๐Ÿ’ป (the "Ed." means editor, so C. Kaufman was the editor ๐Ÿซถ)
  • Obsoletes: 2407, 2408, 2409 ๐Ÿ’€ (these three older docs are getting replaced, bye bye)
  • Date: December 2005 ๐Ÿ“…
  • Category: Standards Track ๐Ÿ‘‘

Status of This Memo ๐Ÿ“

So this doc is an Internet standards track protocol for the Internet community ๐ŸŒ, and it's literally asking for discussion and suggestions for improvements ๐Ÿ’ญ. If you want the standardization state and status of this protocol, check the current edition of the "Internet Official Protocol Standards" (STD 1) ๐Ÿ“š. Distribution of this memo is unlimited โœจ.

Copyright (C) The Internet Society (2005).

Abstract ๐Ÿงš

This doc describes version 2 of the Internet Key Exchange (IKE) protocol ๐Ÿ’–. IKE is a component of IPsec, and it's used for performing mutual authentication and for establishing and maintaining security associations (SAs) ๐Ÿ”.

This version of the IKE spec is giving "combine everything into one" energy ๐Ÿซถ. It merges stuff that used to be in separate documents: Internet Security Association and Key Management Protocol (ISAKMP, RFC 2408), IKE (RFC 2409), the Internet Domain of Interpretation (DOI, RFC 2407), Network Address Translation (NAT) Traversal, Legacy authentication, and remote address acquisition ๐ŸŒˆ.

Version 2 of IKE does not interoperate with version 1 ๐Ÿ™ˆ. BUT it has enough of the header format in common that both versions can unambiguously run over the same UDP port. Iconic compatibility moment ๐Ÿ’….

Table of Contents ๐Ÿ“š

   1. Introduction ....................................................3
      1.1. Usage Scenarios ............................................5
      1.2. The Initial Exchanges ......................................7
      1.3. The CREATE_CHILD_SA Exchange ...............................9
      1.4. The INFORMATIONAL Exchange ................................11
      1.5. Informational Messages outside of an IKE_SA ...............12
   2. IKE Protocol Details and Variations ............................12
      2.1. Use of Retransmission Timers ..............................13
      2.2. Use of Sequence Numbers for Message ID ....................14
      2.3. Window Size for Overlapping Requests ......................14
      2.4. State Synchronization and Connection Timeouts .............15
      2.5. Version Numbers and Forward Compatibility .................17
      2.6. Cookies ...................................................18
      2.7. Cryptographic Algorithm Negotiation .......................21
      2.8. Rekeying ..................................................22
      2.9. Traffic Selector Negotiation ..............................24
      2.10. Nonces ...................................................26
      2.11. Address and Port Agility .................................26
      2.12. Reuse of Diffie-Hellman Exponentials .....................27
      2.13. Generating Keying Material ...............................27
      2.14. Generating Keying Material for the IKE_SA ................28
      2.15. Authentication of the IKE_SA .............................29
      2.16. Extensible Authentication Protocol Methods ...............31
      2.17. Generating Keying Material for CHILD_SAs .................33
      2.18. Rekeying IKE_SAs Using a CREATE_CHILD_SA exchange ........34
      2.19. Requesting an Internal Address on a Remote Network .......34
      2.20. Requesting the Peer's Version ............................35
      2.21. Error Handling ...........................................36
      2.22. IPComp ...................................................37
      2.23. NAT Traversal ............................................38
      2.24. Explicit Congestion Notification (ECN) ...................40
   3. Header and Payload Formats .....................................41
      3.1. The IKE Header ............................................41
      3.2. Generic Payload Header ....................................44
      3.3. Security Association Payload ..............................46
      3.4. Key Exchange Payload ......................................56
      3.5. Identification Payloads ...................................56
      3.6. Certificate Payload .......................................59
      3.7. Certificate Request Payload ...............................61
      3.8. Authentication Payload ....................................63
      3.9. Nonce Payload .............................................64
      3.10. Notify Payload ...........................................64
      3.11. Delete Payload ...........................................72
      3.12. Vendor ID Payload ........................................73
      3.13. Traffic Selector Payload .................................74
      3.14. Encrypted Payload ........................................77
      3.15. Configuration Payload ....................................79
      3.16. Extensible Authentication Protocol (EAP) Payload .........84
   4. Conformance Requirements .......................................85
   5. Security Considerations ........................................88
   6. IANA Considerations ............................................90
   7. Acknowledgements ...............................................91
   8. References .....................................................91
      8.1. Normative References ......................................91
      8.2. Informative References ....................................92
   Appendix A: Summary of Changes from IKEv1 .........................96
   Appendix B: Diffie-Hellman Groups .................................97
      B.1. Group 1 - 768 Bit MODP ....................................97
      B.2. Group 2 - 1024 Bit MODP ...................................97

1. Introduction โœจ

Okay so IP Security (IPsec) gives IP datagrams confidentiality, data integrity, access control, and data source authentication ๐Ÿ”๐Ÿ’–. It pulls this off by keeping shared state between the source and the sink of an IP datagram ๐Ÿค. That state decides, among other things, which specific services get applied to the datagram, which cryptographic algorithms provide those services, and which keys go into those algorithms ๐Ÿ—๏ธ.

Setting up this shared state by hand does not scale well ๐Ÿ˜ฉ. So we need a protocol that sets it up dynamically, and this memo describes exactly that: the Internet Key Exchange (IKE) ๐ŸŽ€. This is version 2 of IKE. Version 1 was defined in RFCs 2407, 2408, and 2409 [Pip98, MSST98, HC98], and this single document is meant to replace all three of them ๐Ÿ’….

Definitions of the primitive terms in this document (like Security Association or SA) can be found in [RFC4301] ๐Ÿ“–.

So the keywords "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT" and "MAY" that show up in this doc are to be interpreted as described in [Bra97] ๐Ÿค“.

The term "Expert Review" is to be interpreted as defined in [RFC2434] ๐Ÿง.

IKE performs mutual authentication between two parties ๐Ÿซถ. It establishes an IKE security association (SA) that holds shared secret information, which can be used to efficiently set up SAs for Encapsulating Security Payload (ESP) [RFC4303] and/or Authentication Header (AH) [RFC4302]. It also sets up a set of cryptographic algorithms that the SAs use to protect the traffic they carry ๐Ÿ”ฅ. In this doc, "suite" or "cryptographic suite" means one complete set of algorithms used to protect an SA ๐Ÿงฉ. An initiator proposes one or more suites by listing supported algorithms, and those algorithms can be mixed and matched into suites ๐Ÿ“. IKE can also negotiate use of IP Compression (IPComp) [IPCOMP] alongside an ESP and/or AH SA โœจ. We call the IKE SA an "IKE_SA", and the SAs for ESP and/or AH that get set up through that IKE_SA we call "CHILD_SAs" ๐Ÿฆ‹.

All IKE communications come in pairs of messages: a request and a response ๐Ÿ’Œ. That pair is called an "exchange" ๐Ÿ’ฌ. The first messages that establish an IKE_SA are the IKE_SA_INIT and IKE_AUTH exchanges, and the later IKE exchanges are CREATE_CHILD_SA or INFORMATIONAL exchanges ๐ŸŒธ. In the common case you get one IKE_SA_INIT exchange and one IKE_AUTH exchange, which is four messages total, to set up the IKE_SA and the first CHILD_SA ๐ŸŽ‰. In exceptional cases there may be more than one of each of these exchanges ๐Ÿ‘€. Either way, 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 ๐Ÿ”. Sometimes only a single CHILD_SA is needed between the IPsec endpoints, so there are no extra exchanges at all ๐Ÿง˜. Subsequent exchanges MAY be used to set up additional CHILD_SAs between the same authenticated pair of endpoints and to do housekeeping ๐Ÿงน.

IKE message flow is always a request followed by a response ๐Ÿ“จ. The requester is the one responsible for reliability ๐Ÿ›ก๏ธ. If the response doesn't arrive within a timeout interval, the requester needs to retransmit the request (or abandon the connection) โฐ.

The first request/response of an IKE session (IKE_SA_INIT) negotiates security parameters for the IKE_SA, sends nonces, and sends Diffie-Hellman values ๐ŸŽ€.

The second request/response (IKE_AUTH) transmits identities, proves knowledge of the secrets that go with those two identities, and sets up an SA for the first (and often only) AH and/or ESP 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 that the syntax requires) is commonly used as a liveness check ๐Ÿ’“. And these subsequent exchanges cannot be used until the initial exchanges have completed ๐Ÿšซ.

In the description that follows, we assume no errors occur ๐Ÿ™ˆ. If errors do happen, the modifications to the flow are described in section 2.21.

1.1. Usage Scenarios ๐ŸŒ

IKE is expected to be used to negotiate ESP and/or AH SAs in a bunch of different scenarios ๐Ÿ’ซ, and each one comes with its own special requirements ๐Ÿฆ„.

1.1.1. Security Gateway to Security Gateway Tunnel ๐Ÿš‡

                    +-+-+-+-+-+            +-+-+-+-+-+
                    !         ! 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 the traffic for part of the way ๐Ÿ›ค๏ธ. The protection is totally transparent to the endpoints, and it depends on ordinary routing to send packets through the tunnel endpoints for processing ๐Ÿช„. Each endpoint announces the set of addresses "behind" it ๐Ÿ“ฃ, and packets get sent in tunnel mode, where the inner IP header contains the IP addresses of the actual endpoints ๐Ÿ’–.

1.1.2. Endpoint-to-Endpoint Transport โœจ

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

                  Figure 2:  Endpoint to Endpoint

Okay so in this setup, BOTH endpoints of the IP connection run IPsec ๐Ÿ’…, because that's what [RFC4301] says hosts have to do. ๐Ÿซถ Transport mode usually doesn't come with an inner IP header. If there is one, the inner addresses match the outer ones, no cap. A single pair of addresses gets negotiated for the packets protected by this SA. These endpoints MAY implement application layer access controls based on the IPsec authenticated identities of the participants. ๐Ÿ” This is giving end-to-end security, which has basically been the guiding principle of the Internet since [RFC1958] and [RFC2775], and it's a way of dodging the complexity problems in networks that [RFC3439] talks about. Is this scenario fully applicable to the IPv4 Internet? Not really, ngl ๐Ÿฅฒ But it has been deployed successfully in specific intranet scenarios using IKEv1. It should be more broadly enabled during the transition to IPv6 and with the adoption of IKEv2. ๐Ÿฆ‹

Here's the tea: it's possible that one or both of the protected endpoints sit behind a network address translation (NAT) node. When that happens, the tunneled packets have to be UDP encapsulated, so the port numbers in the UDP headers can be used to pick out individual endpoints "behind" the NAT (see section 2.23). Main character energy for the port numbers ๐ŸŽ€

1.1.3. Endpoint to Security Gateway Tunnel ๐ŸŒธ

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

            Figure 3:  Endpoint to Security Gateway Tunnel

In this one, a protected endpoint (usually a portable roaming computer, relatable ๐Ÿ’ป) connects back to its corporate network through an IPsec-protected tunnel. It might only use the tunnel to reach stuff on the corporate network, or it might send ALL of its traffic back through the corporate network so the corporate firewall can guard it against Internet-based attacks. ๐Ÿ›ก๏ธ Either way, the protected endpoint wants an IP address tied to the security gateway, so that packets sent back to it end up at the gateway and get tunneled over. This IP address might be static, or the security gateway might hand it out dynamically. ๐Ÿงš For the dynamic case, IKEv2 has a mechanism that lets the initiator ask for an IP address owned by the security gateway, to 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 holds the source IP address for its current location (the address that traffic gets routed to directly), while the inner IP header holds the source IP address the security gateway assigned (the address that traffic gets routed to the gateway for forwarding to the endpoint). The outer destination is always the security gateway, while the inner destination is the packet's ultimate destination. It's a whole matryoshka situation ๐Ÿช†

Also, the protected endpoint could be behind a NAT. In that case, the IP address the security gateway sees won't match the one the protected endpoint sent, and the packets have to be UDP encapsulated to get routed properly. ๐Ÿ™ˆ

1.1.4. Other Scenarios ๐Ÿ“

Other scenarios are possible, and nested combos of the above are too. One notable example mixes parts of 1.1.1 and 1.1.3. A subnet may route all of its external access through a remote security gateway using an IPsec tunnel, while the rest of the Internet routes the subnet's addresses to that gateway. ๐ŸŒˆ Picture someone's home network being "on the Internet" with static IP addresses, even though their ISP only gives their security gateway a single dynamically assigned IP address. The static addresses and the IPsec relay come from a third party located somewhere else. It's giving layers ๐Ÿ’œ


1.2. The Initial Exchanges ๐Ÿซถ

Communication using IKE always starts with the IKE_SA_INIT and IKE_AUTH exchanges (known in IKEv1 as Phase 1). โœจ These initial exchanges normally consist of four messages, though in some scenarios that number can grow. ๐Ÿ“ˆ Every IKE communication is made of request/response pairs. We'll go over the base exchange first, then the variations. The first pair of messages (IKE_SA_INIT) negotiates cryptographic algorithms, exchanges nonces, and does a Diffie-Hellman exchange [DH]. ๐Ÿ”‘

The second pair of messages (IKE_AUTH) authenticates the previous messages, exchanges identities and certificates, and sets up the first CHILD_SA. ๐Ÿ’… Parts of these messages are encrypted and integrity protected with keys established through the IKE_SA_INIT exchange. So the identities are hidden from eavesdroppers, and every field in every message gets authenticated. Bestie, that's a whole vibe ๐Ÿ•ต๏ธโ€โ™€๏ธ

In the descriptions below, the payloads in each message are named using the notation listed here:

  Notation    Payload

  AUTH      Authentication
  CERT      Certificate
  CERTREQ   Certificate Request
  CP        Configuration
  D         Delete
  E         Encrypted
  EAP       Extensible Authentication
  HDR       IKE Header
  IDi       Identification - Initiator
  IDr       Identification - Responder
  KE        Key Exchange
  Ni, Nr    Nonce
  N         Notify
  SA        Security Association
  TSi       Traffic Selector - Initiator
  TSr       Traffic Selector - Responder
  V         Vendor ID

The nitty-gritty of what goes inside each payload is in section 3. ๐Ÿ“š Payloads that might show up optionally are written in brackets, like [CERTREQ], which just means a certificate request payload can be included, but doesn't have to be. ๐ŸŽ€

The initial exchanges go like this:

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

HDR holds the Security Parameter Indexes (SPIs), version numbers, and flags of various sorts. ๐Ÿงฉ The SAi1 payload lists the cryptographic algorithms the initiator supports for the IKE_SA. The KE payload carries the initiator's Diffie-Hellman value, and Ni is the initiator's nonce. ๐ŸŒธ

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

The responder picks a cryptographic suite out of the initiator's offers and puts that choice in the SAr1 payload. ๐Ÿ’– It finishes the Diffie-Hellman exchange with the KEr payload and sends its nonce in the Nr payload. Cute teamwork ๐Ÿค

At this point, each party can generate SKEYSEED, which is where all the keys for that IKE_SA come from. โœจ Everything except the headers of the messages that follow is encrypted and integrity protected. The keys used for encryption and integrity protection are derived from SKEYSEED and are called SK_e (encryption) and SK_a (authentication, a.k.a. integrity protection). A separate SK_e and SK_a gets computed for each direction. ๐Ÿ”„ On top of SK_e and SK_a, which come from the DH value and protect the IKE_SA, there's another quantity called SK_d. SK_d is used to derive further keying material for CHILD_SAs. ๐Ÿง The notation SK { ... } means those payloads are encrypted and integrity protected using that direction's SK_e and SK_a. ๐Ÿ”

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

The initiator states its identity with the IDi payload, proves it knows the secret corresponding to IDi, and integrity protects the contents of the first message using the AUTH payload (see section 2.15). ๐Ÿซถ It might also send its certificate(s) in CERT payload(s), and a list of its trust anchors in CERTREQ payload(s). If any CERT payloads are included, 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 is super useful when the machine running the responder hosts multiple identities at the same IP address. ๐ŸŒ The initiator starts negotiating a CHILD_SA using the SAi2 payload. The final fields (starting with SAi2) are described in the CREATE_CHILD_SA exchange. ๐Ÿ‘‘

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

The responder asserts its identity with the IDr payload, and it can optionally send one or more certificates (again with the certificate holding the public key used to verify AUTH listed first). ๐Ÿ’œ It authenticates its identity and protects the integrity of the second message with the AUTH payload, then finishes negotiating a CHILD_SA using the extra fields described in the CREATE_CHILD_SA exchange. โญ

Last but not least, the recipients of messages 3 and 4 MUST verify that all signatures and MACs are computed correctly, and that the names in the ID payloads match the keys used to generate the AUTH payload. ๐Ÿ” This part is non-negotiable, so no skipping it, periodt ๐Ÿ’…๐Ÿ”ฅ

1.3. The CREATE_CHILD_SA Exchange โœจ

okay bestie, this one is a single request/response pair ๐Ÿ’… and back in IKEv1 we called it a phase 2 exchange ๐ŸŽ€. It can be started by either end of the IKE_SA, but only MAY be started once the initial exchanges are done, so it's giving "anyone can make the first move" energy ๐Ÿฆ‹. Wait, that's not right, the text says it MAY be initiated by either end after the initial exchanges are completed, so let me say it like that: once the initial exchanges are finished, either end is allowed to start it ๐Ÿซถ.

Everything after the initial exchange is locked down with the crypto algorithms and keys agreed in the first two messages of IKE ๐Ÿ”. These follow-up messages use the Encrypted Payload syntax from section 3.14, and yes, even the ones the text calls "empty" still carry an Encrypted Payload ๐Ÿ™ˆ no cap.

Either endpoint can kick this off, so in this section "initiator" just means whoever is starting the exchange ๐Ÿ’œ.

A CHILD_SA gets made by sending a CREATE_CHILD_SA request ๐ŸŒธ. That request MAY optionally include a KE payload for an extra Diffie-Hellman exchange, which gives stronger forward secrecy for the CHILD_SA ๐Ÿ”ฅ. The CHILD_SA's keying material comes from SK_d (set up when the IKE_SA was established), the nonces swapped during this exchange, and the Diffie-Hellman value if KE payloads showed up here ๐Ÿงš.

For the CHILD_SA made as part of the initial exchange, a second KE payload and nonce MUST NOT be sent ๐Ÿšซ. The nonces from the initial exchange are already used for the CHILD_SA keys, so we don't need them again ๐Ÿ’–.

The CREATE_CHILD_SA request looks like this:

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

The initiator sends SA offers in the SA payload, a nonce in the Ni payload, optionally a Diffie-Hellman value in the KEi payload, and the proposed traffic selectors in the TSi and TSr payloads ๐ŸŽ€. If this exchange is rekeying an existing SA other than the IKE_SA, the leading N payload of type REKEY_SA MUST identify the SA being rekeyed ๐Ÿ”. If it isn't rekeying an existing SA, the N payload MUST be omitted ๐Ÿ™…โ€โ™€๏ธ. If the SA offers include different Diffie-Hellman groups, KEi MUST be an element of the group the initiator expects the responder to accept. If it guesses wrong, the exchange fails and has to retry with a different KEi ๐Ÿ˜ญ.

The message after the header is encrypted, and the message including the header is integrity protected using the cryptographic algorithms negotiated for the IKE_SA ๐Ÿ”’.

The CREATE_CHILD_SA response looks like this:

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

The responder replies using the same Message ID, sending the accepted offer in an SA payload, plus a Diffie-Hellman value in the KEr payload if KEi was in the request and the chosen cryptographic suite includes that group โœจ. If the responder picks a suite with a different group, it MUST reject the request ๐Ÿ’€. The initiator SHOULD repeat the request, now with a KEi payload from the group the responder selected ๐Ÿ”„.

The traffic selectors for traffic on that SA are in the TS payloads, and they might be a subset of what the initiator of the CHILD_SA proposed ๐ŸŒˆ. Traffic selectors get omitted if this request is only changing the key of the IKE_SA ๐Ÿ™ˆ.


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 certain events ๐Ÿ“ฃ. That's what the INFORMATIONAL exchange is for ๐ŸŽ€. INFORMATIONAL exchanges MUST ONLY happen after the initial exchanges, and they're always cryptographically protected with the negotiated keys ๐Ÿ”.

Control messages about an IKE_SA MUST be sent under that IKE_SA ๐Ÿ’œ. Control messages about CHILD_SAs MUST be sent under the protection of the IKE_SA that generated them, or its successor if that IKE_SA got replaced during rekeying ๐Ÿฆ‹.

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, or else the Sender will assume the message got lost and retransmit it ๐Ÿ˜ค. That response MAY be a message with no payloads. The request in an INFORMATIONAL exchange MAY also have no payloads at all ๐Ÿซถ. This is the expected way for one endpoint to check that the other one is still alive ๐Ÿ’–.

ESP and AH SAs always come in pairs, one SA per direction ๐Ÿ‘ฏ. When an SA is closed, both members of the pair MUST be closed ๐Ÿšช. When SAs are nested, like when data (and IP headers, if in tunnel mode) gets wrapped first with IPComp, then ESP, then AH between the same two endpoints, all of those SAs MUST be deleted together ๐Ÿ’…. Each endpoint MUST close its incoming SAs and let the other endpoint close the other SA in each pair ๐Ÿ”’.

To delete an SA, you send an INFORMATIONAL exchange with one or more delete payloads listing the SPIs (as they'd show up in the headers of inbound packets) of the SAs to be removed ๐Ÿ—‘๏ธ. The recipient MUST close the designated SAs. Normally the reply will carry delete payloads for the paired SAs going the other way ๐Ÿ”. There's one exception, though ๐Ÿ‘€. If both ends independently decide to close the same set of SAs, each might send a delete payload and the two requests cross in the network ๐Ÿ’€. If a node gets 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 be a duplicate deletion and could, in theory, delete the wrong SA ๐Ÿ˜ฑ.

A node SHOULD treat half-closed connections as anomalous and audit them if they stick around ๐Ÿ•ต๏ธโ€โ™€๏ธ. This spec doesn't give any time periods, so it's up to each endpoint to decide how long to wait โณ. A node MAY refuse to accept incoming data on half-closed connections, but MUST NOT unilaterally close them and reuse the SPIs ๐Ÿ™…โ€โ™€๏ธ. If the connection state gets sufficiently messed up, a node MAY close the IKE_SA, which implicitly closes every SA negotiated under it ๐Ÿงน. It can then rebuild the SAs it needs on a clean base under a new IKE_SA ๐ŸŒธ.

The INFORMATIONAL exchange is defined like this:

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

How an INFORMATIONAL exchange gets processed depends entirely on its component payloads โœจ.


1.5. Informational Messages outside of an IKE_SA ๐ŸŒ™

If an encrypted IKE packet shows up on port 500 or 4500 with an unrecognized SPI, it could be because the receiving node recently crashed and lost its state ๐Ÿ’ฅ. It could also be some other system malfunction, or an attack ๐Ÿ‘€. If the receiving node has an active IKE_SA to the IP address the packet came from, it MAY send a notification about the wayward packet over that IKE_SA in an INFORMATIONAL exchange ๐Ÿ“ฌ. If it doesn't have such an IKE_SA, it MAY send an Informational message without cryptographic protection to the source IP address ๐Ÿ“จ. That kind of message isn't part of an informational exchange, and the receiving node MUST NOT respond to it. Responding could cause a message loop ๐Ÿ”๐Ÿ’€.


2. IKE Protocol Details and Variations ๐Ÿ’œ

IKE normally listens and sends on UDP port 500 ๐ŸŽง, though IKE messages may also show up on UDP port 4500 in a slightly different format (see section 2.23) ๐ŸŒˆ. UDP is a datagram protocol, so it's unreliable, which means IKE builds in recovery from transmission errors, including packet loss, packet replay, and packet forgery ๐Ÿ›Ÿ. IKE is designed to work 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 capacity of either endpoint ๐Ÿ’ช. Even without those minimum performance requirements, IKE is designed to fail cleanly, as though the network were broken ๐Ÿซก.

IKEv2 messages are meant to be short, but they can contain structures with no hard upper bound on size (X.509 certificates, especially) ๐Ÿ“œ. IKEv2 itself has no mechanism for fragmenting large messages ๐Ÿ˜ฌ. IP does define a way to fragment oversize UDP messages, but implementations vary in the maximum message size they support ๐Ÿคทโ€โ™€๏ธ. Using IP fragmentation also opens an implementation up to denial of service attacks [KPS03] ๐Ÿ’€. And some NAT and/or firewall implementations may block IP fragments entirely ๐Ÿงฑ.

All IKEv2 implementations MUST be able to send, receive, and process IKE messages up to 1280 bytes long, and they SHOULD be able to send, receive, and process messages up to 3000 bytes long ๐Ÿ“. IKEv2 implementations SHOULD be aware of the maximum UDP message size they support, and MAY shorten messages by leaving out some certificates or cryptographic suite proposals if that keeps messages under the maximum โœ‚๏ธ. Using the "Hash and URL" formats instead of including certificates in exchanges, where possible, can avoid most of these problems ๐ŸŽ€. Implementations and configuration should keep in mind, though, that if URL lookups only work after the IPsec SA is established, recursion issues could stop this technique from working ๐Ÿ”„๐Ÿ˜ตโ€๐Ÿ’ซ.

2.1. Use of Retransmission Timers โฐ

All messages in IKE come in pairs: a request and a response ๐Ÿ‘ฏ. Setting up an IKE_SA normally takes two request/response pairs ๐Ÿค. Once the IKE_SA is up, either end can send requests at any time, and there can be lots of requests and responses "in flight" at once ๐Ÿš€. But every message is labeled as either a request or a response, and for each request/response pair, one end is the initiator and the other is the responder ๐ŸŽญ.

For every pair of IKE messages, the initiator is responsible for retransmission if a timeout happens โฑ๏ธ. The responder MUST never retransmit a response unless it receives a retransmission of the request ๐Ÿ™…โ€โ™€๏ธ. When that happens, the responder MUST ignore the retransmitted request, except to the extent that it triggers a retransmission of the response ๐Ÿ”. The initiator MUST remember each request until it gets the corresponding response ๐Ÿง . The responder MUST remember each response until it receives a request whose sequence number is larger than the sequence number in that response plus its window size (see section 2.3) ๐ŸชŸ.

IKE is a reliable protocol in the sense that the initiator MUST retransmit a request until either it receives a corresponding reply or it decides the IKE security association has failed, at which point it discards all state tied to the IKE_SA and any CHILD_SAs negotiated using that IKE_SA ๐Ÿ’€โœจ okay that's the end of this part bestie, the rest is coming up next! ๐ŸŒˆ

2.2. Use of Sequence Numbers for Message ID โœจ

okay so every IKE message carries a Message ID in its fixed header ๐Ÿ’… This is how requests and responses find each other, and how retransmissions get recognized ๐Ÿ”

The Message ID is a 32-bit number, and it's zero for the first IKE request in each direction ๐ŸŽ€ The IKE_SA initial setup messages are always numbered 0 and 1 ๐ŸŒธ Each endpoint in the IKE Security Association keeps track of two "current" Message IDs: the next one it'll use for a request it starts, and the next one it expects to see in a request from the other end ๐Ÿงš These counters go up as requests get made and received. Responses always copy the Message ID of the request they answer ๐Ÿซถ

So after the initial exchange, each integer n can show up as the Message ID in four different messages: the nth request from the original IKE initiator, its response, the nth request from the original IKE responder, and its response ๐Ÿ˜ญ If the two ends make very different numbers of requests, the Message IDs in each direction can be way apart, and that's fine ๐Ÿ’– There's still no confusion, because the (I)nitiator and (R)esponse bits in the message header tell you exactly which of the four messages you're looking at ๐Ÿฆ‹

Note that Message IDs are cryptographically protected and help protect against message replays ๐Ÿ” In the unlikely event that Message IDs get too big to fit in 32 bits, the IKE_SA MUST be closed ๐Ÿ’€ Rekeying an IKE_SA resets the sequence numbers ๐ŸŒˆ


2.3. Window Size for Overlapping Requests ๐ŸชŸ

To squeeze out maximum IKE throughput, an IKE endpoint MAY send multiple requests before getting a response to any of them, as long as the other endpoint has said it can handle that ๐Ÿš€ For simplicity, an IKE implementation MAY choose to process requests strictly in order, and/or wait for a response to one request before sending another ๐Ÿ™ˆ There are certain rules that have to be followed so implementations using different strategies can still talk to each other ๐Ÿ’œ

After an IKE_SA is set up, either end can start one or more requests ๐Ÿ’ซ These requests may pass each other on the wire โœจ An IKE endpoint MUST be ready to accept and process a request while it has a request outstanding, otherwise it can get stuck in a deadlock ๐Ÿ˜ฑ An IKE endpoint SHOULD be ready to accept and process multiple requests while it has a request outstanding ๐Ÿ’…

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. That message says the peer is ready to keep state for multiple outstanding messages so you can get more throughput ๐Ÿ“

An IKE endpoint MUST NOT go over the peer's stated window size for transmitted IKE requests ๐Ÿšซ Put differently: if the responder said its window size is N, then when the initiator wants to make 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 each request it has sent (or be able to regenerate it exactly) until the matching response comes back ๐Ÿ“ฆ It also MUST keep a copy of (or be able to regenerate exactly) the number of previous responses equal to its declared window size ๐Ÿง  That's in case a response got lost and the initiator asks for it again by retransmitting the request ๐Ÿ”

An IKE endpoint that supports a window size greater than one SHOULD be able to process incoming requests out of order ๐ŸŒ€ That helps performance when the network fails or packets get reordered ๐Ÿงš


2.4. State Synchronization and Connection Timeouts โณ

An IKE endpoint is allowed to forget all of its state for an IKE_SA, plus the collection of matching CHILD_SAs, at any time ๐Ÿซ  This is the expected behavior when an endpoint crashes and restarts ๐Ÿ’ฅ It's super important that when an endpoint fails or reinitializes its state, the other endpoint notices and doesn't keep wasting bandwidth sending packets over SAs that no longer exist and falling into a black hole ๐Ÿ•ณ๏ธ

IKE is designed to keep working even under Denial of Service (DoS) attacks from the network ๐Ÿ›ก๏ธ So an endpoint MUST NOT decide the other endpoint has failed based on routing information (for example, ICMP messages) or on IKE messages that arrive without cryptographic protection (for example, Notify messages complaining about unknown SPIs) ๐Ÿ™…โ€โ™€๏ธ An endpoint MUST only conclude the other endpoint has failed when repeated attempts to reach it have gone unanswered for a timeout period, OR when a cryptographically protected INITIAL_CONTACT notification arrives on a different IKE_SA for the same authenticated identity ๐Ÿ” An endpoint SHOULD suspect the other endpoint has failed based on routing information, and start a request to see whether the other endpoint is still alive ๐Ÿ‘€

To check if the other side is alive, IKE specifies an empty INFORMATIONAL message that (like all IKE requests) requires an acknowledgement ๐Ÿซง Note that within the context of an IKE_SA, an "empty" message is an IKE header followed by an Encrypted payload that contains no payloads ๐Ÿงธ If a cryptographically protected message has been received from the other side recently, unprotected notifications MAY be ignored ๐Ÿ™ƒ Implementations MUST limit the rate at which they take actions based on unprotected messages ๐Ÿšฆ

The number of retries and the lengths 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, but different environments may need different rules ๐ŸŒ To be a good network citizen, retransmission times MUST increase exponentially, so you don't flood the network and make an existing congestion situation worse ๐Ÿ“ˆ If there has only been outgoing traffic on all of the SAs associated with an IKE_SA, it's essential to confirm the other endpoint is alive so you 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 do a liveness check so it doesn't keep sending messages to a dead peer ๐Ÿ’€ Receiving a fresh cryptographically protected message on an IKE_SA or any of its CHILD_SAs confirms liveness for the IKE_SA and all of its CHILD_SAs ๐Ÿ’–

This puts requirements on the failure modes of an IKE endpoint. An implementation MUST NOT keep sending on any SA if some failure stops it from receiving on all of the associated SAs ๐Ÿ›‘ If CHILD_SAs can fail independently of one another without the associated IKE_SA being able to send a delete message, then they MUST be negotiated by separate IKE_SAs ๐Ÿงฉ

โš ๏ธ There's a Denial of Service attack on the initiator of an IKE_SA, but it can be avoided if the initiator is careful. The first two messages of an SA setup are not cryptographically protected, so an attacker could answer the initiator before the real responder does and poison the connection setup attempt ๐Ÿ˜ค

To prevent this, the initiator MAY be willing to accept multiple responses to its first message, treat each one as potentially legitimate, respond to it, and then throw away all the invalid half-open connections when it gets 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 are cryptographically valid ๐Ÿ™…โ€โ™€๏ธ

Note that with these rules, there's no reason to negotiate and agree on an SA lifetime ๐Ÿ™Œ 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 are deleted ๐Ÿ—‘๏ธ

An IKE endpoint may delete inactive CHILD_SAs at any time to free up 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 tell it about 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 saying that it has closed the IKE_SA ๐Ÿ‘‹

2.5. Version Numbers and Forward Compatibility โœจ

okay so this doc describes version 2.0 of IKE, which means major version 2 and minor version 0 ๐ŸŽ€ and it's giving clean versioning. ngl some implementations are gonna want to support both 1.0 and 2.0, and maybe other versions later on ๐Ÿฆ‹

the major number should only go up if the packet formats or required actions changed SO much that an older node couldn't work with a newer one even if it just ignored the fields it didn't recognize and did what the older spec says ๐Ÿ’… the minor number is for new capabilities. a node with a smaller minor number MUST ignore it, but the node with the larger minor number uses it just for info ๐Ÿงš like, it could show it can handle some newly defined notification message. then the bigger-minor node just notes that its bestie can't understand that message and therefore won't send it. iconic restraint, honestly ๐Ÿ‘‘

if an endpoint gets a message with a higher major version number, it MUST drop the message and SHOULD send an unauthenticated notification message with the highest version number it supports ๐Ÿซถ if an endpoint supports major version n and major version m, it MUST support every version in between. and if it gets a message with a major version it supports, it MUST respond with that version number. so nobody gets tricked into talking on a lower major version than the max they both support, IKE has a flag that says "hey, I can speak a higher major version" ๐ŸŒˆ

so the major version number in the IKE header tells you the version of that message, NOT the highest version the sender can speak ๐Ÿ˜ญ say the initiator can speak n, n+1, and n+2, and the responder can speak n and n+1. they'll negotiate n+1, and the initiator sets the flag saying it can go higher. if they mistakenly (maybe because an active attacker is sending error messages ๐Ÿ‘€) end up on version n, both sides will notice the other one can support a higher version, and they MUST break the connection and reconnect using version n+1. not it being messy ๐Ÿ’€

IKEv1 doesn't follow any of these rules, bc v1 has no way to say "I can speak a higher version" ๐Ÿ™ˆ so an active attacker can trick two v2-capable nodes into speaking v1. when a v2-capable node drops down to v1, it SHOULD note that in its logs.

also, for forward compatibility, every field marked RESERVED MUST be set to zero by a version 2.0 implementation, and its content MUST be ignored by a version 2.0 implementation. this is the "be conservative in what you send and liberal in what you receive" energy ๐Ÿ“ so future versions can use those fields in a way that's guaranteed to get ignored by implementations that don't know about them. similarly, payload types that aren't defined are reserved for later, so version 2.0 implementations MUST skip over those payloads and ignore their contents โœจ

IKEv2 adds a "critical" flag to each payload header for extra forward-compat flexibility ๐Ÿ’œ if the critical flag is set and the payload type isn't recognized, the message MUST be rejected, and the response to the IKE request containing that payload MUST include a Notify payload UNSUPPORTED_CRITICAL_PAYLOAD, saying an unsupported critical payload showed up. if the critical flag is NOT set and the payload type is unsupported, that payload MUST be ignored. ๐Ÿ”ฅ

and even though new payload types might get added later and show up interleaved with the fields defined here, implementations MUST send the payloads defined in this specification in the order shown in the figures in section 2, and implementations SHOULD reject as invalid any message with those payloads in a different order ๐ŸŽ€


2.6. Cookies ๐Ÿช

the term "cookies" comes from Karn and Simpson [RFC2522] in Photuris, an early proposal for key management with IPsec, and it has stuck around ever since ๐Ÿฆ‹ the ISAKMP [MSST98] fixed message header has two eight-octet fields called "cookies," and IKEv1 and IKEv2 both use that syntax. in IKEv2 though, they're called the IKE SPI, and there's a new separate field in a Notify payload that holds the cookie ๐Ÿ’… the first two eight-octet fields in the header work as a connection identifier at the start of IKE packets. each endpoint picks one of the two SPIs and SHOULD pick them so they're unique identifiers of an IKE_SA. and an SPI value of zero is special: it means the sender doesn't know the remote SPI yet ๐Ÿงš

here's the vibe check: with ESP and AH, only the recipient's SPI shows up in the header, but in IKE the sender's SPI gets sent in every message too ๐Ÿ‘€ the SPI chosen by the original initiator of the IKE_SA is always sent first. so if an endpoint has multiple IKE_SAs open and wants to find the right one using the SPI it assigned, it has to look at the I(nitiator) Flag bit in the header to figure out 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 sets that field to zero ๐Ÿซถ

now, the expected attack against IKE is state and CPU exhaustion ๐Ÿ˜ญ the target gets flooded with session initiation requests from forged IP addresses. this attack gets less effective if the responder uses minimal CPU and doesn't commit any state to an SA until it knows the initiator can receive packets at the address it's claiming to send from. so a responder SHOULD, when it detects a large number of half-open IKE_SAs, reject initial IKE messages unless they contain a Notify payload of type COOKIE. it SHOULD instead send an unprotected IKE message as the response, including a COOKIE Notify payload with the cookie data to send back ๐ŸŒธ initiators who get those responses MUST retry the IKE_SA_INIT with a Notify payload of type COOKIE that holds the responder-supplied cookie data as the first payload, with all other payloads unchanged. the whole initial exchange goes 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 passing along the cookie ๐Ÿ“ 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 the initiator assigned, and 'B' is the SPI the responder assigned ๐Ÿ’œ

an IKE implementation SHOULD generate its responder cookies so it doesn't need any saved state to recognize a valid cookie when the second IKE_SA_INIT message shows up ๐Ÿงš the exact algorithms and syntax used to make cookies don't affect interoperability, so they aren't specified here. but here's 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:
   Cookie = <VersionIDofSecret> | Hash(Ni | IPi | SPIi | <secret>)

where <secret> is a randomly generated secret that only the responder knows and that gets changed periodically, 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 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 ๐Ÿ’… including SPIi in the calculation means that if multiple IKE_SAs are being set up in parallel, they'll all get different cookies (as long as the initiator picks unique SPIi's) โœจ and including Ni in the hash means an attacker who only sees message 2 can't successfully forge a message 3. no sneaky forging here ๐Ÿ™…โ€โ™€๏ธ

if a new value for <secret> gets picked while connections are still being initialized, 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> changes, since that would undo part of the denial of service protection. and the responder SHOULD change the value of <secret> frequently, especially if it's under attack ๐Ÿšจ

2.7. Cryptographic Algorithm Negotiation โœจ

okay so the payload type called "SA" ๐Ÿ’– is basically how you pitch a menu of IPsec protocol choices (IKE, ESP, and/or AH) for an SA, plus the crypto algorithms that go with each protocol ๐ŸŽ€

An SA payload holds one or more proposals. Each proposal holds one or more protocols (usually just one ๐Ÿ™ˆ). Each protocol holds one or more transforms, and each transform names a cryptographic algorithm. A transform can carry zero or more attributes, but attributes only show up when the transform identifier doesn't fully describe the algorithm on its own ๐Ÿ’…

this nested setup is genius, honestly ๐Ÿ˜ญ It's built to encode a ton of cryptographic suite options super efficiently, especially when lots of values are acceptable for lots of transforms. The responder MUST choose a single suite, and that suite MAY be any subset of the SA proposal, as long as it follows these rules:

  • Each proposal contains one or more protocols. If a proposal is accepted, the SA response MUST contain the same protocols, in the same order, as the proposal. The responder MUST accept a single proposal or reject them all and return an error. (Example: if a single proposal contains ESP and AH and that proposal is accepted, both ESP and AH MUST be accepted. If ESP and AH are included in separate proposals, the responder MUST accept only one of them.)
  • Each IPsec protocol proposal contains one or more transforms. Each transform has 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 gives you six acceptable combinations ๐Ÿงš

now here's the spicy part ๐ŸŒถ๏ธ The initiator sends its Diffie-Hellman value in the IKE_SA_INIT, which means it has to guess which Diffie-Hellman group the responder will pick from its list of supported groups ๐Ÿ™ˆ If the initiator guesses wrong, the responder replies with a Notify payload of type INVALID_KE_PAYLOAD that says which group it selected. In that case the initiator MUST retry the IKE_SA_INIT using 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, and an active attacker could otherwise trick both endpoints into negotiating a weaker suite instead of the stronger one they both actually prefer ๐Ÿ’€ not on my watch ๐Ÿ›ก๏ธ


2.8. Rekeying ๐Ÿ”„

IKE, ESP, and AH security associations use secret keys that SHOULD be used only for a limited amount of time and to protect a limited amount of data. That's what limits the lifetime of the whole security association. When an SA's lifetime expires, the SA MUST NOT be used anymore. If there's demand, new SAs MAY be established. Re-establishing SAs to replace the expired ones is called "rekeying" ๐Ÿฆ‹

Rekeying SAs without restarting the whole IKE_SA is optional, so minimal IPsec implementations can skip it. An implementation MAY refuse all CREATE_CHILD_SA requests within an IKE_SA. If an SA has expired or is about to, and rekeying through the mechanisms described here fails, an implementation MUST close the IKE_SA and any associated CHILD_SAs, and then MAY start new ones. Implementations SHOULD support in-place rekeying of SAs, since it performs better and is likely to reduce the number of packets lost during the transition โœจ

To rekey a CHILD_SA inside an existing IKE_SA, create a new, equivalent SA (see section 2.17 below), and once the new one is established, delete the old one. To rekey an IKE_SA, establish a new equivalent IKE_SA (see section 2.18 below) with the peer that shares the old IKE_SA, using a CREATE_CHILD_SA inside the existing IKE_SA. The new IKE_SA inherits all of the original IKE_SA's CHILD_SAs ๐Ÿซถ Use the new IKE_SA for all the control messages needed to maintain the CHILD_SAs the old IKE_SA created, and then delete the old IKE_SA. The Delete payload that deletes the IKE_SA itself MUST be the last request sent over that IKE_SA ๐Ÿ’…

SAs SHOULD be rekeyed proactively, i.e., the new SA should be established before the old one expires and becomes unusable. There should be enough time between establishing the new SA and the old one becoming unusable so traffic can switch over to the new SA ๐ŸŒธ

Here's the difference from IKEv1: in IKEv1, SA lifetimes were negotiated. In IKEv2, each end of the SA enforces its own lifetime policy and rekeys the SA when needed ๐Ÿ‘‘ If the two ends have different lifetime policies, the end with the shorter lifetime ends up always being the one to request the rekeying. If an SA bundle has been inactive for a long time, and an endpoint wouldn't have initiated the SA without traffic, the endpoint MAY close the SA instead of rekeying it when its lifetime expires. It SHOULD do that if there has been no traffic since the last time the SA was rekeyed ๐Ÿ™ˆ

If both ends have the same lifetime policies, they could both start a rekey at the same moment, which results in redundant SAs. To make that less likely, the timing of rekeying requests SHOULD be jittered, meaning delayed by a random amount of time after the need for rekeying is noticed ๐ŸŽฒ

This style of rekeying can temporarily leave multiple similar SAs between the same pair of nodes. When two SAs are eligible to receive packets, a node MUST accept incoming packets through either one. If redundant SAs get created because of such a collision, the SA created with the lowest of the four nonces used in the two exchanges SHOULD be closed by the endpoint that created it ๐Ÿง

Note that IKEv2 deliberately allows parallel SAs with the same traffic selectors between the same endpoints. One reason is to support traffic quality of service (QoS) differences among the SAs (see [RFC2474], [RFC2475], and section 4.1 of [RFC2983]). So, unlike IKEv1, the combination of endpoints and traffic selectors may not uniquely identify an SA between those endpoints. That means the IKEv1 rekeying trick of deleting SAs based on duplicate traffic selectors SHOULD NOT be used ๐Ÿšซ

The node that initiated the surviving rekeyed SA SHOULD delete the replaced SA once the new one is established โœจ

Timing windows can exist, especially when packets get lost, where endpoints don't agree on an SA's state ๐Ÿ˜ญ The responder to a CREATE_CHILD_SA MUST be ready to accept messages on an SA before it sends 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 has received and processed the response to its CREATE_CHILD_SA request. So how does the responder know when it's okay to send on the newly created SA? ๐Ÿค”

From a technical correctness and interoperability standpoint, 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, that could cause packets to be dropped for no reason, so an implementation MAY want to hold off on that sending ๐Ÿซง

The responder can be sure the initiator is ready to receive messages on an SA if either (1) it has received a cryptographically valid message on the new SA, or (2) the new SA rekeys an existing SA and the responder receives an IKE request to close the replaced SA ๐Ÿ’œ When rekeying an SA, the responder SHOULD keep sending messages 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 it either receives one or a timeout occurs. If an initiator receives a message on an SA for which it hasn't received a response to its CREATE_CHILD_SA request, it SHOULD read that as a likely packet loss and retransmit the CREATE_CHILD_SA request. An initiator MAY send a dummy message on a newly created SA if it has no messages queued, to let the responder know it's ready to receive messages ๐ŸŒˆ

2.9. Traffic Selector Negotiation โœจ

okay so when an IP packet shows up at an RFC4301-compliant IPsec subsystem and matches a "protect" selector in its Security Policy Database (SPD), the subsystem MUST protect that packet with IPsec ๐Ÿ”. If no SA exists yet, creating one is IKE's job ๐Ÿ’…. Maintaining an SPD is outside the scope of IKE (see [PFKEY] for an example protocol) ๐Ÿ™ˆ, though some implementations might update their SPD in connection with the running of IKE (for an example scenario, see section 1.1.3) ๐Ÿงš.

Traffic Selector (TS) payloads let the endpoints spill some of what's in their SPD to their peers ๐Ÿซถ. They specify the selection criteria for packets that will be forwarded over the newly set up SA. In some scenarios this acts as a consistency check to make sure both SPDs actually agree, and in others it guides the dynamic update of the SPD. literally so useful ๐Ÿ˜ญ

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 up of an address range (IPv4 or IPv6), a port range, and an IP protocol ID ๐ŸŒธ. For the scenario in section 1.1.3, an initiator may ask the responder to assign it an IP address and then tell it what that address is ๐Ÿฆ‹.

IKEv2 lets the responder pick a subset of the traffic the initiator proposed ๐Ÿ‘‘. This can happen when both endpoints' configurations are being updated but only one end has the new info yet. Since the two endpoints may be configured by different people, the mismatch can hang around for a long time even with no errors at all ๐Ÿ’€. It's also fine for the configs to be intentionally different, like when one end is set up to tunnel all addresses and depends on the other end to have the up-to-date list ๐Ÿ“.

The first TS payload is called TSi (Traffic Selector-initiator), and the second is TSr (Traffic Selector-responder) ๐Ÿ’œ. TSi describes the source address of traffic forwarded from the initiator of the CHILD_SA pair (or the destination address of traffic forwarded to it). TSr describes the destination address of traffic forwarded to the responder (or the source address of traffic forwarded from it) โœจ.

Here's a good example, bestie ๐ŸŽ€. Say the original initiator wants a CHILD_SA pair and wants to tunnel all traffic from subnet 192.0.1.* on its side to subnet 192.0.2.* on the responder's side. The initiator would put a single traffic selector in each TS payload. TSi would specify the address range 192.0.1.0 - 192.0.1.255, and TSr would specify the address range 192.0.2.0 - 192.0.2.255. If the responder finds that proposal acceptable, it sends back identical TS payloads ๐Ÿ™Œ. (Note: The IP address range 192.0.2.* has been reserved for use in examples in RFCs and similar documents. This document needed two such ranges, and so also used 192.0.1.*. This should not be confused with any actual address.) ๐Ÿ™ˆ

The responder is allowed to narrow the choices by picking a subset of the traffic, like by eliminating or narrowing the range of one or more of the traffic selectors, as long as the set does not become the NULL set ๐Ÿ’….

It's possible for the responder's policy to contain several smaller ranges, all inside the initiator's traffic selector, where the responder wants each of those ranges sent over a different SA ๐Ÿงฉ. Continuing the example, the responder might be willing to tunnel those addresses to and from the initiator, but might require that each address pair get its own separately negotiated CHILD_SA. If the initiator generated its request in response to an incoming packet from 192.0.1.43 to 192.0.2.123, there would be no way for the responder to tell which pair of addresses should be in this tunnel. It would have to guess, or reject the request with a status of SINGLE_PAIR_REQUIRED ๐Ÿ˜ญ.

To help the responder pick the right range in this situation, if the initiator requested the SA because of a data packet, the initiator SHOULD include as the first traffic selector in each of TSi and TSr a very specific traffic selector containing the addresses from the packet that triggered the request ๐ŸŽฏ. In the example, the initiator would put two traffic selectors in TSi: the first with the address range 192.0.1.43 - 192.0.1.43 plus the source port and IP protocol from the packet, and the second with 192.0.1.0 - 192.0.1.255 and all ports and IP protocols. The initiator would similarly include two traffic selectors in TSr ๐Ÿงš.

If the responder's policy doesn't let it accept the entire set of traffic selectors in the initiator's request, but does let it 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 this example, the responder might respond with TSi being 192.0.1.43 - 192.0.1.43 with all ports and IP protocols.

If the initiator creates the CHILD_SA pair not in response to an arriving packet, but say, right at startup, there may be no specific addresses it prefers for the initial tunnel over any others ๐ŸŒˆ. In that case, the first values in TSi and TSr MAY be ranges rather than specific values, and the responder chooses a subset of the initiator's TSi and TSr that it finds acceptable. If more than one subset is acceptable but their union is not, the responder MUST accept some subset and MAY include a Notify payload of type ADDITIONAL_TS_POSSIBLE to indicate that the initiator might want to try again ๐Ÿ”. This only happens when the initiator and responder are configured differently from each other. If they agree on the granularity of tunnels, the initiator will never request a tunnel wider than the responder will accept. Such misconfigurations SHOULD be recorded in error logs ๐Ÿ“.


2.10. Nonces ๐ŸŒ™

The IKE_SA_INIT messages each contain a nonce, and these nonces are used as inputs to cryptographic functions ๐Ÿ”. The CREATE_CHILD_SA request and the CREATE_CHILD_SA response also contain nonces. They're used to add freshness to the key derivation technique that gets keys for CHILD_SA, and to make sure strong pseudo-random bits come 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 prf. ("prf" refers to "pseudo-random function", one of the cryptographic algorithms negotiated in the IKE exchange.) ๐Ÿง If the same random number source gets used for both keys and nonces, care must be taken so 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 are not themselves cryptographically protected, though. IKE is designed to work even through Network Address Translation (NAT) boxes, which is honestly iconic ๐Ÿ‘‘. 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 was received 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 so it can get the property of "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 got access to both endpoints' long-term keys still can't rebuild the keys that protected the conversation. The only option left is a brute force search of the session key space ๐Ÿ’€.

Getting perfect forward secrecy requires that when a connection closes, each endpoint MUST forget not only the keys the connection used but also any info that could be used to recompute those keys. In particular, it MUST forget the secrets used in the Diffie-Hellman calculation, plus any state that might persist in a pseudo-random number generator and could be used to recompute the Diffie-Hellman secrets ๐Ÿซ .

Computing Diffie-Hellman exponentials is computationally expensive, so an endpoint may find it helpful to reuse those exponentials across multiple connection setups ๐Ÿง . There are several reasonable strategies. 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 only delete the info tied to the exponential once the corresponding connections are closed. This lets the exponential get reused without losing perfect forward secrecy, at the cost of keeping more state ๐Ÿ“.

Whether and when to reuse Diffie-Hellman exponentials is a private decision, in the sense that it won't affect interoperability ๐ŸŽ€. An implementation that reuses exponentials MAY choose to remember the exponential used by the other endpoint in past exchanges, and if one is reused, avoid the second half of the calculation โœจ.

2.13. Generating Keying Material โœจ

Okay bestie, so for the IKE_SA we negotiate four cryptographic algorithms ๐Ÿ’…: an encryption algorithm, an integrity protection algorithm, a Diffie-Hellman group, and a pseudo-random function (prf). The prf is the star of the show ๐ŸŒŸ because it builds the keying material for every algorithm in both the IKE_SA and the CHILD_SAs.

We assume each encryption algorithm and integrity protection algorithm uses a fixed-size key, and that any randomly chosen value of that size can work as a proper key ๐Ÿ”‘. For algorithms that accept a variable length key, a fixed key size MUST be specified as part of the cryptographic transform negotiated. For algorithms where not every value is a valid key (like DES or 3DES with key parity), the algorithm that turns arbitrary values into keys 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. When the prf takes a variable length key and variable length data and gives back a fixed-length output (for example, with HMAC), the formulas in this document apply. When the key for the prf has fixed length, the data given as a key is truncated or padded with zeros as necessary, unless exceptional processing is explained after the formula. ๐Ÿฆ‹

Keying material always comes out of the negotiated prf algorithm ๐ŸŒธ. Since you might need more keying material than one prf output can give, we use the prf over and over. We call this prf+, a function that spits out a pseudo-random stream based on the inputs to a prf (where | means concatenation):

   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)

   continuing as needed to compute all required keys.

The keys get taken from the output string without caring about boundaries ๐Ÿ“. For example, if you need a 256-bit Advanced Encryption Standard (AES) key and a 160-bit HMAC key, and the prf makes 160 bits, the AES key comes from T1 plus the start of T2, while the HMAC key comes from the rest of T2 plus the start of T3. The constant tacked onto the end of each string feeding the prf is a single octet. prf+ in this document is not defined beyond 255 times the size of the prf output. โœจ

2.14. Generating Keying Material for the IKE_SA ๐Ÿ”

Here's where it gets really spicy ๐ŸŒถ๏ธ. A quantity called SKEYSEED is calculated from the nonces exchanged during the IKE_SA_INIT exchange plus the Diffie-Hellman shared secret from that exchange. SKEYSEED then gives birth to seven other secrets ๐Ÿ‘‘:

  • SK_d is used for deriving new keys for the CHILD_SAs set up with this IKE_SA.
  • SK_ai and SK_ar are used as keys for the integrity protection algorithm, authenticating the component messages of later exchanges.
  • SK_ei and SK_er are used for encrypting (and, of course, decrypting) all later exchanges.
  • SK_pi and SK_pr are used when generating an AUTH payload.

Here's how SKEYSEED and its whole family get made ๐Ÿงš:

       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 )

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+. The g^ir is the shared secret from the ephemeral Diffie-Hellman exchange, and it's written 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, with any headers stripped off. If the negotiated prf takes a fixed-length key and the lengths of Ni and Nr don't add up to that length, then half the bits must come from Ni and half from Nr, taking the first bits of each. ๐ŸŒˆ

Now the two directions of traffic use different keys ๐Ÿซถ. The keys protecting messages from the original initiator are SK_ai and SK_ei. The keys protecting messages going the other way are SK_ar and SK_er. Each algorithm takes a fixed number of bits of keying material, which is specified as part of the algorithm. For integrity algorithms based on a keyed hash, the key size is always equal to the length of the output of the underlying hash function. ๐Ÿ’œ

2.15. Authentication of the IKE_SA ๐Ÿ›ก๏ธ

When you're not using extensible authentication (see section 2.16), the peers get authenticated by each one signing a block of data (or doing a MAC with a shared secret as the key) ๐ŸŽ€. For the responder, the octets to be signed start with the first octet of the first SPI in the header of the second message and end with the last octet of the last payload in that message. Tacked onto this (just for computing the signature) are the initiator's nonce Ni (just the value, not the payload holding it) and the value prf(SK_pr,IDr'), where IDr' is the responder's ID payload minus the fixed header. Note that neither the nonce Ni nor the value prf(SK_pr,IDr') gets transmitted. ๐Ÿ™ˆ

The initiator does the same thing with the first message ๐Ÿ’–: it signs starting from the first octet of the first SPI in the header and ending with the last octet of the last payload. Tacked on for the signature are the responder's nonce Nr and the value prf(SK_pi,IDi'). In that calculation, IDi' and IDr' are the entire ID payloads minus the fixed header. It is critical to the security of the exchange that each side signs the other side's nonce. ๐Ÿ˜ญ

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 gets sent twice (the second time with a responder cookie and/or a different Diffie-Hellman group), it's the second version of the message that gets signed. ๐Ÿ”ฅ

Optionally, messages 3 and 4 MAY include a certificate, or a certificate chain, giving evidence that the key used to compute a digital signature belongs to the name in the ID payload ๐Ÿ“œ. The signature or MAC gets computed using algorithms dictated by the type of key the signer uses, 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 algorithms depends on the type of key each one has. In particular, the initiator might be using a shared key while the responder has 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 bringing in another source of randomness. ๐Ÿ˜ฌ This is typically insecure because user-chosen passwords are unlikely to have enough 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 SHOULD contain as much unpredictability as the strongest key being negotiated. ๐ŸŒŸ When it's a pre-shared key, the AUTH value is computed as:

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

The string "Key Pad for IKEv2" is 17 ASCII characters without a null termination. The shared secret can be variable length. The pad string exists so that, if the shared secret is derived from a password, the IKE implementation doesn't need to store the password in cleartext. It can store the value prf(Shared Secret,"Key Pad for IKEv2") instead, 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 people are expected to do it anyway. ๐Ÿฅฒ

The management interface that provides the Shared Secret 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 into a binary string is specified. If the negotiated prf takes a fixed-size key, the shared secret MUST be of that fixed size. ๐Ÿ„

2.16. Extensible Authentication Protocol Methods โœจ

okay so IKE isn't limited to public key signatures and shared secrets ๐Ÿ’… it can also do authentication with methods from RFC 3748 [EAP]. EAP methods are usually asymmetric (built for a user logging into a server) and they may not be mutual ๐Ÿ™ˆ so these protocols are typically used to authenticate the initiator to the responder, and they MUST be used together with a public key signature based authentication of the responder to the initiator. People often call these "Legacy Authentication" mechanisms ๐Ÿ“

this memo references [EAP] on purpose so new methods can be added later without updating this spec ๐Ÿฆ‹ a few simpler variations are written up here and in section 3.16. [EAP] describes an authentication protocol that can take a variable number of messages, so in IKE, extensible authentication happens as extra IKE_AUTH exchanges, and those MUST be completed in order to initialize the IKE_SA. bestie this is the kind of multi-step vibe where you can't skip the steps ๐Ÿ˜ญ

an initiator says "I want extensible auth" by leaving the AUTH payload out of message 3. so if it includes an IDi payload but no AUTH payload, it has claimed an identity but hasn't proven it yet ๐Ÿ‘€ if the responder is down to use an extensible method, it puts an Extensible Authentication Protocol (EAP) payload in message 4 and waits to send SAr2, TSi, and TSr until the initiator is authenticated in a later IKE_AUTH exchange โœจ for a minimal extensible authentication, the initial SA setup looks like this:

   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 }

for EAP methods that make a shared key as a side effect of authentication, that shared key MUST be used by both the initiator and the responder to generate the AUTH payloads in messages 7 and 8, using the shared secret syntax from section 2.15 ๐Ÿ”ฅ the shared key from EAP is the field from the EAP spec named MSK. and the shared key made during an IKE exchange MUST NOT be used for any other purpose ๐Ÿ™…โ€โ™€๏ธ

EAP methods that don't set up a shared key SHOULD NOT be used ๐Ÿ’€ they're open to a bunch of man-in-the-middle attacks [EAPMITM] when they're used in other protocols that don't run over a server-authenticated tunnel. check the Security Considerations section for the full tea โ˜• and if you do use EAP methods that don't generate a shared key anyway, 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 SHOULD be able to stretch the setup out to at least ten IKE_AUTH exchanges, in case the responder sends notifications and/or asks for the auth prompt again ๐ŸŒˆ once the EAP method's protocol run finishes successfully, the responder MUST send an EAP payload with the Success message. same deal if auth fails, the responder MUST send an EAP payload with the Failure message ๐Ÿ’” and the responder MAY end the IKE exchange at any time by sending an EAP payload with the Failure message ๐Ÿซถ

after a longer exchange like that, the EAP AUTH payloads MUST be included in the two messages that come after the one holding the EAP Success message ๐ŸŽ€


2.17. Generating Keying Material for CHILD_SAs ๐Ÿงš

a single CHILD_SA is created by the IKE_AUTH exchange, and more CHILD_SAs can optionally be made in CREATE_CHILD_SA exchanges โœจ here's how their keying material gets generated:

   KEYMAT = prf+(SK_d, Ni | Nr)

where Ni and Nr are the nonces from the IKE_SA_INIT exchange if this request is the first CHILD_SA created, or the fresh Ni and Nr from the CREATE_CHILD_SA exchange if it's a later one ๐Ÿ’œ

for CREATE_CHILD_SA exchanges that include an optional Diffie-Hellman exchange, the keying material is defined as:

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

where g^ir (new) is the shared secret from the ephemeral Diffie-Hellman exchange of this CREATE_CHILD_SA exchange (written as an octet string in big endian order, padded with zeros in the high-order bits if needed to make it the length of the modulus) ๐Ÿ”ฅ

one single CHILD_SA negotiation can end up with multiple security associations ๐Ÿคฏ ESP and AH SAs come in pairs (one per direction), so four SAs could be created in one CHILD_SA negotiation if ESP and AH are both being negotiated ๐Ÿ‘‘

keying material MUST be taken from the expanded KEYMAT in this order:

  • All keys for SAs carrying data from the initiator to the responder are taken before SAs going in the reverse direction.
  • If multiple IPsec protocols are negotiated, keying material is taken in the order in which the protocol headers will appear in the encapsulated packet.
  • If a single protocol has both encryption and authentication keys, the encryption key is taken from the first octets of KEYMAT and the authentication key is taken from the next octets.

each cryptographic algorithm takes a fixed number of bits of keying material, and that number is specified as part of the algorithm ๐ŸŒธ


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 section 2.8) ๐Ÿฆ‹ new initiator and responder SPIs go in the SPI fields. the TS payloads are left out when you're rekeying an IKE_SA. SKEYSEED for the new IKE_SA gets computed using SK_d from the existing IKE_SA, like so:

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

where g^ir (new) is the shared secret from the ephemeral Diffie-Hellman exchange of this CREATE_CHILD_SA exchange (written as an octet string in big endian order, padded with zeros if needed to make it the length of the modulus), and Ni and Nr are the two nonces with any headers stripped off ๐Ÿซง

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 โœจ


2.19. Requesting an Internal Address on a Remote Network ๐Ÿ 

most commonly, in the endpoint-to-security-gateway scenario, an endpoint needs an IP address inside the network the security gateway protects, and that address needs to be dynamically assigned ๐Ÿ™Œ 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.

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 can get an address for the IRAC from all kinds of places, like a DHCP/BOOTP 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 every case, the CP payload MUST be inserted before the SA payload ๐ŸŽ€ in versions of the protocol with multiple IKE_AUTH exchanges, the CP payloads MUST be inserted in the messages that contain the SA payloads.

CP(CFG_REQUEST) MUST contain at least an INTERNAL_ADDRESS attribute (either IPv4 or IPv6), but MAY contain any number of extra attributes the initiator wants sent back in the response ๐Ÿ’…

here's an example, the message from initiator to responder:

   CP(CFG_REQUEST)=
     INTERNAL_ADDRESS(0.0.0.0)
     INTERNAL_NETMASK(0.0.0.0)
     INTERNAL_DNS(0.0.0.0)
   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 the 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 first receiving 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. if the IRAS's configuration requires CP for a given identity IDi, but the IRAC never sent a CP(CFG_REQUEST), the IRAS MUST fail the request and terminate the IKE exchange with a 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 info 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 hand out version info before authentication, or even after authentication, to prevent trolling 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 isn't 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 โœจ

okay so there are SO many ways IKE processing can go sideways ๐Ÿ˜ญ if a request shows up badly formatted, or it's just not allowed by policy (like there's no cryptographic algorithm that matches, bestie ๐Ÿ’€), the response MUST contain a Notify payload that says what went wrong. and if something breaks outside of any IKE request, like a node getting ESP messages on an SPI that doesn't exist, the node SHOULD start an INFORMATIONAL exchange with a Notify payload that describes the problem ๐Ÿซถ

errors that happen before a cryptographically protected IKE_SA exists need to be handled very carefully ๐Ÿ” there's a real trade-off here. you want to be helpful and actually diagnose the problem, but you also don't want to become a dupe in a denial of service attack that's built on forged messages ๐Ÿ™ˆ

if a node gets a message on UDP port 500 or 4500 that's outside any IKE_SA it knows about (and it isn't a request to start one), it might be the leftovers of the node recently crashing ๐Ÿ’… if the message is marked as a response, the node MAY audit the suspicious event but MUST NOT respond. if the message is marked as a request, the node MAY audit the suspicious event and MAY send a response. if a response does get sent, it MUST go to the IP address and port it came from, with the same IKE SPIs and the Message ID copied over. that response MUST NOT be cryptographically protected and MUST contain a Notify payload indicating INVALID_IKE_SPI โœจ

a node that receives that unprotected Notify payload MUST NOT respond and MUST NOT change the state of any existing SAs ๐Ÿฆ‹ the message might be a forgery, or it might be a response the real correspondent got tricked into sending. a node SHOULD treat that message (and also a network message like ICMP destination unreachable) as a hint that there might be trouble with SAs to that IP address, and it SHOULD initiate a liveness test for any such IKE_SA. an implementation SHOULD limit how often it runs these tests so it doesn't get tricked into joining a denial of service attack ๐Ÿ˜ค

a node that gets a suspicious message from an IP address it has an IKE_SA with MAY send an IKE Notify payload in an IKE INFORMATIONAL exchange over that SA. the recipient MUST NOT change the state of any SA's as a result, but SHOULD audit the event to help diagnose malfunctions ๐Ÿ” and a node MUST limit the rate at which it sends messages in response to unprotected messages. no spam, periodt ๐Ÿšซ


2.22. IPComp ๐ŸŒธ

IP compression [IPCOMP] can be negotiated as part of setting up a CHILD_SA. IP compression adds an extra header to each packet and a compression parameter index (CPI), but 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, and they aren't explicitly mentioned in any DELETE payload ๐Ÿงš

negotiating IP compression is separate from negotiating the cryptographic parameters for a CHILD_SA, so it's its own vibe ๐Ÿ’œ 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. the response MAY indicate acceptance of a single compression algorithm with a Notify payload of type IPCOMP_SUPPORTED. these payloads MUST NOT show up in messages that don't contain SA payloads ๐Ÿ™…โ€โ™€๏ธ

there's been discussion about accepting multiple compression algorithms, and about having different compression algorithms for the two directions of a CHILD_SA, but 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 any algorithm other than one that was proposed and accepted during CHILD_SA setup. strict, but iconic ๐Ÿ‘‘

one side effect of splitting IPComp negotiation away from the cryptographic parameters is that you can't propose several cryptographic suites and ask for IP compression with some of them but not others. that's just how it goes, bestie ๐Ÿคทโ€โ™€๏ธ


2.23. NAT Traversal ๐Ÿฆ‹

Network Address Translation (NAT) gateways are a controversial topic ๐Ÿ™ƒ this section briefly explains what they are and how they're likely to treat IKE traffic. a lot of people think NATs are evil and that we shouldn't design protocols to make them work better. even so, IKEv2 does specify some unintuitive processing rules so that NATs are more likely to work, because real life is messy ๐Ÿซ 

NATs mostly exist because IPv4 addresses are scarce, though there are other reasons too. IP nodes "behind" a NAT have addresses that aren't globally unique. they're assigned from a space that's unique inside the network behind the NAT, but that's likely to get reused by nodes behind other NATs. 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 to machines on the real Internet, the NAT gateway "translates" the IP source address into one that will route back to the gateway. messages coming from the Internet to the gateway 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 to change to communicate through the NAT. getting that transparency is harder with some protocols than others. protocols that put the endpoints' IP addresses inside the packet payload will break unless the NAT gateway understands the protocol and also fixes the internal references, not just 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 brings its own special problems ๐Ÿ’€ if the connection runs in transport mode, changing the IP addresses on packets will make the checksums fail, and the NAT can't fix them because they're cryptographically protected. even in tunnel mode there are routing problems, because transparently translating the addresses of AH and ESP packets needs special logic in the NAT, and that logic is heuristic and unreliable by nature. so IKEv2 can negotiate UDP encapsulation of IKE and ESP packets. this encoding is a bit less efficient, but it's easier for NATs to process ๐ŸŽ€ also, firewalls may be configured to pass IPsec traffic over UDP but not ESP/AH, or the other way around.

NATs commonly translate TCP and UDP port numbers as well as addresses, and they use the port numbers of inbound packets to decide which internal node should get a given packet. because of that, even though IKE packets MUST be sent from and to UDP port 500, they MUST be accepted coming from any port, and responses MUST be sent to the port they came from. the ports may get modified as packets pass through NATs. similarly, the IP addresses of the IKE endpoints usually aren't included in IKE payloads, since the payloads are cryptographically protected and NATs couldn't transparently modify them ๐Ÿ”’

port 4500 is reserved for UDP-encapsulated ESP and IKE ๐ŸŒˆ when working through a NAT, it's generally better to send IKE packets over port 4500, because some older NATs handle IKE traffic on port 500 in clever ways. they try to transparently set up IPsec connections between endpoints that don't do NAT traversal themselves. those NATs can get in the way of the straightforward NAT traversal this document is going for, so an IPsec endpoint that finds a NAT between itself and its correspondent MUST send all subsequent traffic to and from port 4500, which NATs should not treat specially (the way they might with port 500) ๐Ÿ™…โ€โ™€๏ธ

the specific requirements for supporting NAT traversal [RFC3715] are listed below. support for NAT traversal is optional. in this section only, requirements listed as MUST apply only to implementations that support NAT traversal โœจ

  • IKE MUST listen on port 4500 as well as port 500. IKE MUST respond to the IP address and port that packets arrived from.
  • Both 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 whether there's a NAT between the hosts, and which end is behind the NAT. they go just after the Ni and Nr payloads (before the optional CERTREQ payload).
  • if none of the NAT_DETECTION_SOURCE_IP payload(s) received matches the hash of the source IP and port found in the IP header of the packet containing the payload, it means the other end is behind a NAT (someone along the route changed the source address of the original packet to match the address of the NAT box). in this case, this end should allow dynamic update of the other end's IP address, as described later ๐Ÿงญ
  • if the NAT_DETECTION_DESTINATION_IP payload received doesn't match the hash of the destination IP and port found in the IP header of the packet containing the payload, it means this end is behind a NAT. in this case, this end SHOULD start sending keepalive packets as explained in [Hutt05] ๐Ÿ’“
  • the IKE initiator MUST check these payloads if they're 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 bytes 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 ๐Ÿงฉ
  • the original source and destination IP addresses needed for the transport mode TCP and UDP packet checksum fixup (see [Hutt05]) come from the Traffic Selectors associated with the exchange. in the case of NAT traversal, the Traffic Selectors MUST contain exactly one IP address, which is then used as the original IP address ๐ŸŽฏ
  • sometimes a NAT box decides to remove mappings that are still alive (for example, the keepalive interval is too long, or the NAT box got rebooted). to recover in these cases, hosts that are not behind a NAT SHOULD send all packets (including retransmissions) to the IP address and port from the last valid authenticated packet from the other end (in other words, dynamically update the address). a host behind a NAT SHOULD NOT do this, because it opens a DoS attack possibility ๐Ÿšจ any authenticated IKE packet or any authenticated UDP-encapsulated ESP packet can be used to detect that the IP address or the port has changed.

note that similar, but probably not identical, actions will likely be needed to make IKE work with Mobile IP, but that processing isn't addressed by this document ๐Ÿš—

2.24. Explicit Congestion Notification (ECN) ๐ŸŒˆ

okay bestie, ECN and IPsec tunnels were kinda beefing ๐Ÿ’€. When IPsec tunnels worked the way [RFC2401] originally described, ECN wasn't appropriate on the outer IP headers, because tunnel decapsulation processing threw away ECN congestion indications, and that's bad news for the network ๐Ÿ˜ญ. Getting ECN to work with IPsec tunnels under IKEv1 needed multiple operating modes and some negotiation (see [RFC3168]), which is a lot ๐Ÿ™„. IKEv2 said "nah, we're simplifying" โœจ. Now ECN has to be usable in the outer IP headers of every tunnel-mode IPsec SA that IKEv2 creates. Tunnel encapsulators and decapsulators for all tunnel-mode SAs created by IKEv2 MUST support the ECN full-functionality option for tunnels specified in [RFC3168] and MUST implement the tunnel encapsulation and decapsulation processing specified in [RFC4301] to prevent discarding of ECN congestion indications. main character energy ๐Ÿ’…๐Ÿซถ


3. Header and Payload Formats โœจ

3.1. The IKE Header ๐Ÿฆ‹

okay so IKE messages live on UDP ports 500 and/or 4500, with exactly one IKE message per UDP datagram ๐ŸŽ€. Almost everything from the start of the packet through the UDP header gets ignored, except the IP addresses and UDP ports get swapped and reused for return packets ๐Ÿ”. On port 500, the IKE message starts right after the UDP header. On port 4500, it gets four octets of zero stuck on the front ๐Ÿงš. Those four zeros aren't part of the IKE message and don't count in any of the length fields or checksums IKE defines, so don't count them ๐Ÿ™ˆ.

Every IKE message starts with the IKE header, which this memo calls HDR ๐Ÿ’œ. After that come one or more IKE payloads, and each one is identified by a "Next Payload" field in the payload before it. You process payloads in the order they show up, using the "Next Payload" field in the IKE header first and then the "Next Payload" field in each payload, until a "Next Payload" of zero says there's nothing else. If you find an "Encrypted" payload, you decrypt it and parse its contents as more payloads ๐Ÿ”. An Encrypted payload MUST be the last payload in a packet and an Encrypted payload MUST NOT contain another Encrypted payload. no nesting drama allowed ๐Ÿ™…โ€โ™€๏ธ

The Recipient SPI in the header tells you which IKE security association an instance belongs to. So a single IKE instance can juggle lots of different sessions with different peers at once. multitasking queen ๐Ÿ‘‘

All multi-octet integer fields are laid out in big endian order, which is also called 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 picked by the initiator to identify a unique IKE security association ๐Ÿ†”. This value MUST NOT be zero.
  • Responder's SPI (8 octets): a value picked 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 that include a cookie) and MUST NOT be zero in any other message.
  • Next Payload (1 octet): tells you what kind of payload comes right after the header ๐Ÿงฉ. The format and value of each payload are defined below.
  • Major Version (4 bits): the major version of the IKE protocol being used ๐Ÿ”ข. 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. boundaries, bestie ๐Ÿšง
  • Minor Version (4 bits): the minor version of the IKE protocol being used โœŒ๏ธ. 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): the type of exchange in use ๐Ÿ”„. This decides which payloads get sent in each message and the order the messages show up in an exchange.
                       Exchange Type            Value

                       RESERVED                 0-33
                       IKE_SA_INIT              34
                       IKE_AUTH                 35
                       CREATE_CHILD_SA          36
                       INFORMATIONAL            37
                       RESERVED TO IANA         38-239
                       Reserved for private use 240-255
  • Flags (1 octet): specific options set for the message ๐Ÿšฉ. Each option is present when its bit in the flags field is set. The bits are defined LSB first, so bit 0 is the least significant bit of the Flags octet. Below, a bit being "set" means its value is '1', and "cleared" means its value is '0'.
    • X(reserved) (bits 0-2): These bits MUST be cleared when sending and MUST be ignored on receipt. ๐Ÿซฅ
    • I(nitiator) (bit 3 of Flags): 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 figure out which eight octets of the SPI were generated by the recipient. ๐Ÿชž
    • V(ersion) (bit 4 of Flags): This bit says the transmitter can speak a higher major version number of the protocol than the one in the major version number field ๐Ÿ“ˆ. IKEv2 implementations must clear this bit when sending and MUST ignore it in incoming messages.
    • R(esponse) (bit 5 of Flags): This bit says this message is a response to a message with 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 already marked as a response. no responding to responses, periodt ๐Ÿ›‘
    • X(reserved) (bits 6-7 of Flags): These bits MUST be cleared when sending and MUST be ignored on receipt. ๐Ÿซฅ
  • Message ID (4 octets): the message identifier used to control retransmission of lost packets and to match requests with responses ๐Ÿ”—. It's essential to the protocol's security, because it's what prevents message replay attacks ๐Ÿ›ก๏ธ. See sections 2.1 and 2.2.
  • Length (4 octets): the length of the total message (header + payloads) in octets ๐Ÿ“.

3.2. Generic Payload Header ๐Ÿ’–

bestie, every IKE payload from 3.3 through 3.16 starts with the same little header ๐ŸŽ€ It's shown in Figure 5 below. Each payload's figure will include this header too, but I'm skipping the field descriptions for each payload to keep things short ๐Ÿ™ˆ

                        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 means:

  • Next Payload (1 octet) - Identifier for the payload type of the next payload in the message. If the current payload is the last in the message, then this field will be 0. This is the "chaining" trick ๐Ÿ”— You add a new payload by tacking it onto the end of the message and setting the "Next Payload" field of the payload before it to that new payload's type. The exception is the Encrypted payload, which must always be the last payload of a message. It holds data structures in the format of additional payloads. In an Encrypted payload's header, the Next Payload field is set to the payload type of the first contained payload (instead of 0) ๐Ÿ˜ญ

Payload Type Values

    Next Payload Type               Notation  Value

    No Next Payload                              0

    RESERVED                                   1-32
    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                        E          46
    Configuration                    CP         47
    Extensible Authentication        EAP        48
    RESERVED TO IANA                          49-127
    PRIVATE USE                              128-255

Payload type values 1-32 should not be used so that there is no overlap with the code assignments for IKEv1. Payload type values 49-127 are reserved to IANA for future assignment in IKEv2 (see section 6). Payload type values 128-255 are for private use among mutually consenting parties. ๐ŸŒˆ

  • Critical (1 bit) - MUST be set to zero if the sender wants the recipient to skip this payload if it does not understand the payload type code in the Next Payload field of the previous payload. MUST be set to one if the sender wants the recipient to reject this entire message if it does not understand the payload type. MUST be ignored by the recipient if the recipient understands the payload type code. MUST be set to zero for payload types defined in this document. Note that the critical bit applies to the current payload rather than the "next" payload whose type code appears in the first octet. The reasoning behind not setting the critical bit for payloads defined in this document is that all implementations MUST understand all payload types defined in this document and therefore must ignore the Critical bit's value. Skipped payloads are expected to have valid Next Payload and Payload Length fields. ๐Ÿ‘‘
The Critical bit is a big deal, so read this part twice ๐Ÿ’€ Every implementation has to understand every payload type defined here, which is exactly why the bit is set to zero for them.
  • RESERVED (7 bits) - MUST be sent as zero; MUST be ignored on receipt. ๐Ÿ“
  • Payload Length (2 octets) - Length in octets of the current payload, including the generic payload header. โœจ

3.3. Security Association Payload ๐Ÿฆ‹

The Security Association Payload, denoted SA in this memo, is used to negotiate attributes of a security association. Assembly of Security Association Payloads requires great peace of mind ๐Ÿ™ˆ An SA payload MAY contain multiple proposals. If there is more than one, they MUST be ordered from most preferred to least preferred. Each proposal may contain multiple IPsec protocols (where a protocol is IKE, ESP, or AH), each protocol MAY contain multiple transforms, and each transform MAY contain multiple attributes. When parsing 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 each have their own variable length encodings. They are nested such that the Payload Length of an SA includes the combined contents of the SA, Proposal, Transform, and Attribute information. The length of a Proposal includes the lengths of all Transforms and Attributes it contains. The length of a Transform includes the lengths of all Attributes it contains. ๐Ÿ’…

The syntax of Security Associations, Proposals, Transforms, and Attributes is based on ISAKMP, but the semantics are somewhat different. The reason for the complexity and the hierarchy is to allow for multiple possible combinations of algorithms to be encoded in a single SA. Sometimes there is a choice of multiple algorithms, whereas other times there is a combination of algorithms. For example, an initiator might want to propose using (AH w/MD5 and ESP w/3DES) OR (ESP w/MD5 and 3DES). ๐Ÿ”ฅ

One of the reasons the semantics of the SA payload has changed from ISAKMP and IKEv1 is to make the encodings more compact in common cases. ๐ŸŒธ

The Proposal structure contains within it a Proposal # and an IPsec protocol ID. Each structure MUST have the same Proposal # as the previous one or be one (1) greater. The first Proposal MUST have a Proposal # of one (1). If two successive structures have the same Proposal number, it means that the proposal consists of the first structure AND the second. So a proposal of AH AND ESP would have two proposal structures, one for AH and one for ESP, and both would have Proposal #1. A proposal of AH OR ESP would have two proposal structures, one for AH with Proposal #1 and one for ESP with Proposal #2. ๐Ÿง 

Each Proposal/Protocol structure is followed by one or more transform structures. The number of different transforms is generally determined by the Protocol. AH generally has a single transform: an integrity check algorithm. ESP generally has two: an encryption algorithm and an integrity check algorithm. IKE generally has four transforms: a Diffie-Hellman group, an integrity check algorithm, a prf algorithm, and an encryption algorithm. If an algorithm that combines encryption and integrity protection is proposed, it MUST be proposed as an encryption algorithm and an integrity protection algorithm MUST NOT be proposed. For each Protocol, the set of permissible transforms is assigned transform ID numbers, which appear 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 IDEA) and (HMAC_MD5 or HMAC_SHA), the ESP proposal would contain two Transform Type 1 candidates (one for 3DES and one for IDEA) and two Transform Type 2 candidates (one for HMAC_MD5 and one for HMAC_SHA). This effectively proposes four combinations of algorithms. If the initiator wanted to propose only a subset of those, for example (3DES and HMAC_MD5) or (IDEA and HMAC_SHA), there is 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, as when an encryption algorithm has a variable key size. The transform would specify the algorithm and the attribute would specify the key size. Most transforms do not have attributes. A transform MUST NOT have multiple attributes of the same type. To propose alternate values for an attribute (for example, multiple key sizes for the AES encryption algorithm), and implementation MUST include multiple Transforms with the same Transform Type each with a single Attribute. ๐Ÿฆ‹

Note that the semantics of Transforms and Attributes are quite different from those in 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. ๐ŸŒˆ

                        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 โœจ

okay so the Proposal Substructure is basically the lil container that holds your whole crew of transforms ๐Ÿ’… it's giving organized, and the first four octets are built to look like a payload header on purpose ๐ŸŽ€

                       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 #    !  Protocol ID  !    SPI Size   !# of 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 is 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 4 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) - Length of this proposal, including all transforms and attributes that follow.
  • Proposal # (1 octet) - When a proposal is made, the first proposal in an SA payload MUST be #1, and subsequent proposals MUST either be the same as the previous proposal (indicating an AND of the two proposals) or one more than the previous proposal (indicating an OR of the two proposals). When a proposal is accepted, all of the proposal numbers in the SA payload MUST be the same and 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 defined values are:
Protocol               Protocol ID
RESERVED                0
IKE                     1
AH                      2
ESP                     3
RESERVED TO IANA        4-200
PRIVATE USE             201-255
  • 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). ๐Ÿ’–
  • # of 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 ๐Ÿฆ‹

the Transform Substructure is the actual "here's what I want to use" part, and it's literally giving main character energy ๐Ÿ‘‘ same deal as before, the first four octets are shaped like a payload header ngl

                       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
  • 0 (last) or 3 (more) (1 octet) - Specifies whether this is the last Transform Substructure in the Proposal. This syntax is inherited from ISAKMP, but is unnecessary because the last Proposal could be identified from the length of the SA. The value (3) corresponds to a Payload Type of Transform in IKEv1, and the first 4 octets of the Transform structure are designed to look somewhat like the header of a Payload.
  • RESERVED - MUST be sent as zero; MUST be ignored on receipt.
  • Transform Length - The length (in octets) of the Transform Substructure including Header and Attributes.
  • Transform Type (1 octet) - The type of transform being specified in this transform. Different protocols support different transform types. For some protocols, some of the transforms may be optional. If a transform is optional and the initiator wishes to propose that the transform be omitted, no transform of the given type is included in the proposal. If the initiator wishes to make use of the transform optional to the responder, 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.

Transform Type Values:

                                 Transform    Used In
                                    Type
      RESERVED                        0
      Encryption Algorithm (ENCR)     1  (IKE and ESP)
      Pseudo-random 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)
      RESERVED TO IANA                6-240
      PRIVATE USE                     241-255

For Transform Type 1 (Encryption Algorithm), defined Transform IDs are:

      Name                     Number           Defined In
      RESERVED                    0
      ENCR_DES_IV64               1              (RFC1827)
      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              (RFC2451)
      ENCR_DES_IV32               9
      RESERVED                   10
      ENCR_NULL                  11              (RFC2410)
      ENCR_AES_CBC               12              (RFC3602)
      ENCR_AES_CTR               13              (RFC3664)

      values 14-1023 are reserved to IANA.  Values 1024-65535 are
      for private use among mutually consenting parties.

For Transform Type 2 (Pseudo-random Function), defined Transform IDs are:

      Name                     Number               Defined In
      RESERVED                    0
      PRF_HMAC_MD5                1                 (RFC2104), [MD5]
      PRF_HMAC_SHA1               2                 (RFC2104), [SHA]
      PRF_HMAC_TIGER              3                 (RFC2104)
      PRF_AES128_XCBC             4                 (RFC3664)

      values 5-1023 are reserved to IANA.  Values 1024-65535 are for
      private use among mutually consenting parties.

For Transform Type 3 (Integrity Algorithm), defined Transform IDs are:

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

      values 6-1023 are reserved to IANA.  Values 1024-65535 are for
      private use among mutually consenting parties.

For Transform Type 4 (Diffie-Hellman Group), defined Transform IDs are:

      Name                                Number
      NONE                               0
      Defined in Appendix B              1 - 2
      RESERVED                           3 - 4
      Defined in [ADDGROUP]              5
      RESERVED TO IANA                   6 - 13
      Defined in [ADDGROUP]              14 - 18
      RESERVED TO IANA                   19 - 1023
      PRIVATE USE                        1024-65535

For Transform Type 5 (Extended Sequence Numbers), defined Transform IDs are:

      Name                                Number
      No Extended Sequence Numbers       0
      Extended Sequence Numbers          1
      RESERVED                           2 - 65535

3.3.3. Valid Transform Types by Protocol ๐ŸŽ€

the number and type of transforms in an SA payload depend on which protocol the SA is for. 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 need not accept proposals with unacceptable suites). A proposal MAY omit the optional types if the only value for them it will accept is NONE. ๐Ÿงš

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

3.3.4. Mandatory Transform IDs โœจ

okay so the list of suites that MUST and SHOULD be supported for interop got yeeted from this doc ๐Ÿ—‘๏ธ bc those are gonna change way faster than this doc ever gets updated. no cap ๐Ÿ”„

the big lesson from IKEv1 is that no system should ONLY implement the mandatory algos and expect them to be the best choice for everyone ๐Ÿ™…โ€โ™€๏ธ like, when this was written, a bunch of IKEv1 folks were moving to AES in CBC mode for VPNs ๐Ÿ” and lots of IKEv2 systems will have AES, extra DH groups, and extra hash algos. some IPsec customers already NEED those on top of the ones listed above ๐Ÿ’…

IANA will probably add more transforms later, and some users will want private suites ๐Ÿ‘€ especially for IKE, where impls should handle different params (up to certain size limits) ๐Ÿงš so all implementations of IKEv2 SHOULD include a management facility that lets a user or sysadmin specify the DH params (generator, modulus, and exponent lengths and values) for new DH groups ๐Ÿฆ‹. implementations SHOULD also have a management interface where those params and the matching transform IDs can be entered, so new groups can actually get negotiated ๐ŸŒธ

now the non-negotiable part ๐Ÿšจ all implementations of IKEv2 MUST include a management facility that lets a user or sysadmin specify which suites are acceptable for IKE ๐Ÿซถ. when a payload with a set of transform IDs shows up, the implementation MUST compare them against the ones configured locally, to check the proposed suite is OK under local policy ๐Ÿ”. and the implementation MUST reject SA proposals that aren't authorized by these IKE suite controls. ๐Ÿšซ also, cryptographic suites that MUST be implemented don't need to be configured as acceptable to local policy. ngl that one's kinda wild ๐Ÿ™ˆ

3.3.5. Transform Attributes ๐ŸŽ€

each transform in a Security Association payload can come with attributes that modify or complete it ๐Ÿ’–. these are type/value pairs, defined below. like, if an encryption algo has a variable-length key, the key length can be specified as an attribute ๐Ÿ”‘. attributes can have a fixed two-octet value OR a variable-length value, and the variable-length ones get 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 Type (2 octets): the unique ID for each attribute type (see below). The most significant bit is the Attribute Format bit (AF) ๐ŸŽฏ. it says whether the attribute is in Type/Length/Value (TLV) form or the shortened Type/Value (TV) form. AF = 0 means TLV, AF = 1 means TV.
  • Attribute Length (2 octets): the length in octets of the Attribute Value. when AF is 1, the Attribute Value is only 2 octets and this field isn't even there ๐Ÿ“
  • Attribute Value (variable length): the value tied to the Attribute Type. if AF is 0, its length comes from the Attribute Length field. if AF is 1, it's 2 octets, period ๐Ÿ’…

ok so only ONE attribute type (Key Length) is defined, and it's fixed length ๐Ÿ™ƒ. the variable-length encoding is only there for future stuff ๐Ÿ”ฎ. the only algos in this doc that take attributes are the AES-based encryption, integrity, and pseudo-random functions, and they just need one attribute saying the key width ๐Ÿ”

     Attribute Type                 Value        Attribute Format
  --------------------------------------------------------------
  RESERVED                           0-13 Key Length (in bits)
  14                 TV RESERVED                           15-17
  RESERVED TO IANA                   18-16383 PRIVATE USE
  16384-32767

values 0-13 and 15-17 were used in a similar way in IKEv1, so they should not be assigned except to matching values ๐Ÿง. values 18-16383 are reserved to IANA ๐Ÿ›๏ธ. values 16384-32767 are for private use between mutually consenting parties ๐Ÿค

  • Key Length

when an Encryption Algorithm has a variable-length key, this attribute gives the key length in bits (it MUST use network byte order) ๐ŸŒ. this attribute MUST NOT be used when the Encryption Algorithm uses a fixed-length key ๐Ÿšซ

the rules for basic attributes are strict, bestie ๐Ÿ˜ค attributes described as basic MUST NOT be encoded using the variable-length encoding ๐Ÿ™…โ€โ™€๏ธ. and variable-length attributes MUST NOT be encoded as basic, even if their value fits into two octets ๐Ÿ’€. NOTE: this is a change from IKEv1, where extra flexibility made composing messages easier but definitely made parsing messier ๐Ÿฅด

3.3.6. Attribute Negotiation ๐Ÿ’œ

during SA negotiation, initiators make offers and responders pick from them ๐Ÿ’ฌ. responders MUST select a single complete set of parameters from the offers (or reject all of them if none are acceptable) ๐Ÿ™…. if there are multiple proposals, the responder MUST choose a single proposal number and return all the Proposal substructures with that number ๐Ÿ”ข. if there are multiple Transforms with the same type, the responder MUST choose just one ๐ŸŽฏ. any attributes of a selected transform MUST be returned unmodified ๐ŸงŠ. and the initiator MUST check that the accepted offer matches one of its proposals, and if it doesn't, that response MUST be rejected ๐Ÿšซ

DH groups are kinda tricky tho ๐Ÿ˜ญ SA offers include proposed attributes AND a Diffie-Hellman public number (KE) in the same message. if the initiator offers several DH groups in the first exchange, it SHOULD pick the one the responder is most likely to accept and include a KE for that group ๐ŸŽฒ. if the guess is wrong, the responder will say which group it wants in the response, and the initiator SHOULD pick an element of that group for its KE when it retries the first message ๐Ÿ”. it SHOULD, however, keep proposing its full set of supported groups, to prevent a man-in-the-middle downgrade attack ๐Ÿ›ก๏ธ (this part is so important, don't skip it fr)

Implementation Note: certain negotiable attributes can have ranges or multiple acceptable values, like the key length of a variable key length symmetric cipher ๐Ÿ”‘. to keep things interoperable and let endpoints upgrade independently, implementers SHOULD accept values that they deem to supply greater security. like, if a peer is configured to accept a variable-length cipher with a key length of X bits and gets offered that cipher with a bigger key length, the implementation SHOULD accept the offer if it supports the longer key ๐Ÿ’ช

this is how you get an "at least" level of security ๐Ÿง, i.e. "a key length of _at least_ X bits for cipher Y" โœจ

3.4. Key Exchange Payload ๐Ÿฆ‹

the Key Exchange Payload, called KE in this memo, is how Diffie-Hellman public numbers get swapped as part of a DH key exchange ๐Ÿ’Œ. it's 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        !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !          DH Group #           !           RESERVED            !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !                                                               !
   ~                       Key Exchange Data                       ~
   !                                                               !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

             Figure 10:  Key Exchange Payload Format

to build a key exchange payload, you copy your Diffie-Hellman public value into the "Key Exchange Data" part ๐Ÿ“‹. the length of that value MUST equal the length of the prime modulus the exponentiation was done over, so you prepend zero bits to it if you need to ๐Ÿซง

the DH Group # tells you which DH group the Key Exchange Data was computed in (see section 3.3.2) ๐Ÿ”. if the selected proposal uses a different DH group, the message MUST be rejected with a Notify payload of type INVALID_KE_PAYLOAD ๐Ÿ™…โ€โ™€๏ธ

the payload type for the Key Exchange payload is thirty four (34) ๐Ÿ”ขโœจ

3.5. Identification Payloads ๐Ÿชช

Okay bestie, the Identification Payloads (IDi and IDr in this memo) let peers claim an identity to each other ๐Ÿ’– That identity can be used for policy lookup, but it doesn't have to match anything in the CERT payload. Either field can be used by an implementation to make access control decisions ๐Ÿ”

NOTE: In IKEv1, two ID payloads were sent in each direction to carry Traffic Selector (TS) information for data passing over the SA. In IKEv2, that info lives in TS payloads instead (see section 3.13) โœจ

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): tells you what kind of identification is being used ๐Ÿท๏ธ
  • RESERVED: MUST be sent as zero; MUST be ignored on receipt ๐Ÿšซ
  • Identification Data (variable length): the 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 ๐Ÿ”ข

Here's the table of assigned values for the Identification Type field, with a description of the Identification Data that follows each one ๐Ÿ‘‘

   ID Type                           Value
   -------                           -----
   RESERVED                            0

   ID_IPV4_ADDR                        1

         A single four (4) octet IPv4 address.

   ID_FQDN                             2

         A fully-qualified domain name string.  An example of a
         ID_FQDN is, "example.com".  The string MUST not contain any
         terminators (e.g., NULL, CR, etc.).

   ID_RFC822_ADDR                      3

         A fully-qualified RFC822 email address string, An example of
         a ID_RFC822_ADDR is, "jsmith@example.com".  The string MUST
         not contain any terminators.

   Reserved to IANA                    4

   ID_IPV6_ADDR                        5

         A single sixteen (16) octet IPv6 address.

   Reserved to IANA                    6 - 8

   ID_DER_ASN1_DN                      9

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

   ID_DER_ASN1_GN                      10

         The binary DER encoding of an ASN.1 X.500 GeneralName
         [X.509].

   ID_KEY_ID                           11

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

   Reserved to IANA                    12-200

   Reserved for private use            201-255

Two implementations only interoperate if each one can generate an ID type the other accepts ๐Ÿค So for maximum interoperability, 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 of these 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 ๐ŸŒˆ

3.6. Certificate Payload ๐Ÿ“œ

The Certificate Payload (CERT in this memo) is how IKE carries certificates or other authentication-related info ๐ŸŽ€ Certificate payloads SHOULD be included in an exchange if the sender has certificates available, unless the peer has said it can fetch that info from elsewhere using an HTTP_CERT_LOOKUP_SUPPORTED Notify payload ๐Ÿฆ‹ Fair warning: the name "Certificate Payload" is kinda misleading, because not every authentication mechanism uses certificates, and stuff other than certificates can ride in this payload too ๐Ÿ™ˆ

Here's how the Certificate Payload is defined:

                        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 tells you what kind of certificate or certificate-related info is in the Certificate Data field ๐Ÿ—‚๏ธ
   Certificate Encoding               Value
   --------------------               -----
   RESERVED                             0
   PKCS #7 wrapped X.509 certificate    1
   PGP Certificate                      2
   DNS Signed Key                       3
   X.509 Certificate - Signature        4
   Kerberos Token                       6
   Certificate Revocation List (CRL)    7
   Authority Revocation List (ARL)      8
   SPKI Certificate                     9
   X.509 Certificate - Attribute       10
   Raw RSA Key                         11
   Hash and URL of X.509 certificate   12
   Hash and URL of X.509 bundle        13
   RESERVED to IANA                  14 - 200
   PRIVATE USE                      201 - 255
  • Certificate Data (variable length): the actual encoding of the certificate data. The type of certificate is indicated by the Certificate Encoding field ๐Ÿ“ฆ

The payload type for the Certificate Payload is thirty seven (37) ๐Ÿ”ข

The 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 (4): contains a DER encoded X.509 certificate whose public key is used to validate the sender's AUTH payload ๐Ÿ”‘
  • Certificate Revocation List (7): contains a DER encoded X.509 certificate revocation list ๐Ÿ“ƒ
  • Raw RSA Key (11): contains a PKCS #1 encoded RSA key (see [RSA] and [PKCS1]) ๐Ÿ—๏ธ
  • Hash and URL encodings (12-13): these keep IKE messages short by swapping long data structures for 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 denial of service attacks that get easier to pull off when IKE messages are big enough to need IP fragmentation [KPS03] ๐Ÿ›ก๏ธ

Use the following ASN.1 definition for an 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

Now the requirements, and these matter so listen up ๐Ÿšจ Implementations MUST be capable of being configured to send and accept up to four X.509 certificates in support of authentication, and also MUST be capable of being configured to send and accept the first two Hash and URL formats (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 ๐Ÿ’œ

3.7. Certificate Request Payload ๐ŸŽ€

Okay bestie, so the Certificate Request Payload (we call it CERTREQ in this memo ๐Ÿ“œ) is how you politely ask for the certificates you'd prefer over IKE ๐Ÿซถ. It can show up in the IKE_INIT_SA response and/or the IKE_AUTH request. You MAY include Certificate Request payloads in an exchange when you need to get the receiver's certificate โœจ. If you trust multiple CAs and the cert encoding can't do a list, you SHOULD send multiple Certificate Request payloads ๐Ÿ’….

                        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

  • 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.

The payload type for the Certificate Request Payload is thirty eight (38) ๐Ÿ”ฅ.

The Certificate Encoding field has the same values as those defined in section 3.6. The Certification Authority field contains an indicator of trusted authorities for this certificate type. The Certification Authority value is a concatenated list of SHA-1 hashes of the public keys of trusted Certification Authorities (CAs). Each is encoded as the SHA-1 hash of the Subject Public Key Info element (see section 4.1.2.7 of [RFC3280]) from each Trust Anchor certificate. The twenty-octet hashes are concatenated and included with no other formatting ๐Ÿงš.

Note that the term "Certificate Request" is somewhat misleading ๐Ÿ™ˆ, because values other than certificates are defined in a "Certificate" payload, and requests for those values can be present in a Certificate Request Payload. The syntax of the Certificate Request payload in such cases is not defined in this document.

The Certificate Request Payload is processed by inspecting the "Cert Encoding" field to determine whether the processor has any certificates of this type. If so, the "Certification Authority" field is inspected to determine if the processor has any certificates that can be validated up to one of the specified certification authorities. This can be a chain of certificates.

If an end-entity certificate exists that satisfies the criteria specified in the CERTREQ, a certificate or certificate chain SHOULD be sent back to the certificate requestor 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. Note that even if two peers are configured to use two different CAs, cross-certification relationships should be supported by appropriate selection logic ๐Ÿฆ‹.

The intent is not to prevent communication through the strict adherence of selection of a certificate based on CERTREQ. An alternate certificate could be selected by the sender that would still enable the recipient to successfully validate and trust it through trust conveyed by cross-certification, CRLs, or other out-of-band configured means. Thus, the processing of a CERTREQ should be seen as a suggestion for a certificate to select, not a mandated one. If no certificates exist, then the CERTREQ is ignored. This is not an error condition of the protocol. There may be cases where there is a preferred CA sent in the CERTREQ, but an alternate might be acceptable (perhaps after prompting a human operator) ๐Ÿ’œ.

3.8. Authentication Payload ๐Ÿ”

The Authentication Payload (we call it AUTH in this memo ๐Ÿ’–) contains data used for authentication purposes. The syntax of the Authentication data varies according to the Auth Method as specified below.

The Authentication 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        !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ! Auth Method   !                RESERVED                       !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !                                                               !
   ~                      Authentication Data                      ~
   !                                                               !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Figure 14: Authentication Payload Format

  • Auth Method (1 octet) - Specifies the method of authentication used. Values defined are:
    • RSA Digital Signature (1) - Computed as specified in section 2.15 using an RSA private key over a PKCS#1 padded hash (see [RSA] and [PKCS1]).
    • Shared Key Message Integrity Code (2) - Computed as specified in section 2.15 using the shared key associated with the identity in the ID payload and the negotiated prf function.
    • DSS Digital Signature (3) - Computed as specified in section 2.15 using a DSS private key (see [DSS]) over a SHA-1 hash.

The values 0 and 4-200 are reserved to IANA. The values 201-255 are available for private use ๐ŸŽ€.

  • 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 (we call it Ni and Nr in this memo for the initiator's and responder's nonce respectively ๐Ÿฆ‹) contains random data used to guarantee liveness during an exchange and protect against replay attacks. Main character energy, honestly ๐Ÿ‘‘.

The Nonce 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        !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !                                                               !
   ~                            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 a Nonce MUST be between 16 and 256 octets inclusive. Nonce values MUST NOT be reused ๐Ÿ”ฅ. No cap, this one is important.

3.10. Notify Payload ๐Ÿ’Œ

The Notify Payload (we call it 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 specifying why a request was rejected), in an INFORMATIONAL Exchange (to report an error not in an IKE request), or in any other message to indicate sender capabilities or to modify the meaning of the request โœจ.

The Notify 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        !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !  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, this field indicates the type of that SA. For IKE_SA notifications, this field MUST be one (1). For notifications concerning IPsec SAs this field MUST contain either (2) to indicate AH or (3) to indicate ESP. For notifications that do not relate to an existing SA, this field MUST be sent as zero and MUST be ignored on receipt. All other values for this field are reserved to IANA for future assignment.
  • 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.
  • Notify Message Type (2 octets) - Specifies the type of notification message.
  • SPI (variable length) - Security Parameter Index.
  • Notification Data (variable length) - Informational 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 ๐Ÿงšโ€โ™€๏ธ

Notification information can be error messages specifying why an SA could not be established. It can also be status data that a process managing an SA database wishes to communicate with a peer process. The table below lists the Notification messages and their corresponding values. The number of different error statuses was greatly reduced from IKEv1 both for simplification and to avoid giving configuration information to probers ๐Ÿ™ˆ.

Types in the range 0 - 16383 are intended 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 except that they SHOULD be logged ๐Ÿซถ.

Notify payloads with status types MAY be added to any message and MUST be ignored if not recognized. They are intended to indicate capabilities, and as part of SA negotiation are used to negotiate non-cryptographic parameters โœจ.

     NOTIFY MESSAGES - ERROR TYPES           Value
     -----------------------------           -----
     RESERVED                                  0

     UNSUPPORTED_CRITICAL_PAYLOAD              1

Okay bestie, the UNSUPPORTED_CRITICAL_PAYLOAD vibe continues ๐Ÿ’… This one gets sent if the payload has the "critical" bit set and the payload type is not recognized. The Notification Data holds the one-octet payload type. ๐Ÿซถ

INVALID_IKE_SPI 4 ๐Ÿงš

Okay so this one shows up when an IKE message comes in with an unrecognized destination SPI ๐Ÿ‘€ It usually means the recipient rebooted and totally forgot the IKE_SA ever existed. ๐Ÿ˜ญ

INVALID_MAJOR_VERSION 5 ๐ŸŽ€

This is for when the recipient can't handle the IKE version in the header. The closest version number the recipient can support goes in the reply header, so it's giving helpful. ๐ŸŒธ

INVALID_SYNTAX 7 ๐Ÿ’€

This one is serious, babes. It means the IKE message was invalid because a type, length, or value was out of range, or because the request got rejected for policy reasons. ๐Ÿ™ˆ To stop a denial of service attack using forged messages, this status can only come back in an encrypted packet if the message ID and cryptographic checksum were valid. โœจ Also, to avoid leaking info to someone probing a node, this status MUST be sent for any error that isn't covered by one of the other status types. To help with debugging, more detailed error info SHOULD be written to a console or log. ๐Ÿ”ฅ

INVALID_MESSAGE_ID 9 ๐Ÿฆ‹

This gets sent when an IKE message ID outside the supported window shows up. Here's the tea: this Notify MUST NOT be sent in a response, and the invalid request MUST NOT be acknowledged. โ˜• Instead, you tell the other side by starting an INFORMATIONAL exchange with Notification data holding the four octet invalid message ID. Sending this one is optional, but notifications of this type MUST be rate limited. ๐Ÿšฆ

INVALID_SPI 11 ๐Ÿ“

This one MAY be sent in an IKE INFORMATIONAL exchange when a node gets an ESP or AH packet with an invalid SPI. The Notification Data holds the SPI of the invalid packet. Usually this means a node rebooted and forgot an SA ๐Ÿ”„ If this Informational Message gets sent outside the context of an IKE_SA, the recipient should only treat it as a "hint" that something might be wrong, because it could easily be forged. ๐Ÿ•ต๏ธโ€โ™€๏ธ

NO_PROPOSAL_CHOSEN 14 ๐Ÿšซ

None of the proposed crypto suites was acceptable. Rip. ๐Ÿ’”

INVALID_KE_PAYLOAD 17 ๐Ÿ”‘

The D-H Group # field in the KE payload is not the group # the responder picked for this exchange. This notification carries two octets of data: the accepted D-H Group # in big endian order. ๐Ÿงฎ

AUTHENTICATION_FAILED 24 ๐Ÿšช

Sent in the response to an IKE_AUTH message when, for some reason, the authentication failed. There's no associated data here. ๐Ÿฅ€

SINGLE_PAIR_REQUIRED 34 ๐Ÿ‘ฏ

This error means a CREATE_CHILD_SA request is unacceptable because its sender will only accept traffic selectors specifying a single pair of addresses. The requestor is expected to respond by asking for an SA for only the specific traffic it's trying to forward. ๐ŸŽฏ

NO_ADDITIONAL_SAS 35 ๐Ÿ™…โ€โ™€๏ธ

This error means a CREATE_CHILD_SA request is unacceptable because the responder won't accept any more CHILD_SAs on this IKE_SA. Some minimal implementations may only accept a single CHILD_SA setup during an initial IKE exchange and reject any later attempts to add more. Main character energy, but in a limited way. ๐Ÿ’…

INTERNAL_ADDRESS_FAILURE 36 ๐Ÿ 

This indicates an error assigning an internal address (INTERNAL_IP4_ADDRESS or INTERNAL_IP6_ADDRESS) while a responder processes a Configuration Payload. If this error comes up inside an IKE_AUTH exchange, no CHILD_SA will be created. ๐Ÿ˜ตโ€๐Ÿ’ซ

FAILED_CP_REQUIRED 37 ๐Ÿ“‹

Sent by the responder when CP(CFG_REQUEST) was expected but not received. That makes it a conflict with locally configured policy. There's no associated data. ๐Ÿ™ƒ

TS_UNACCEPTABLE 38 ๐Ÿšท

This means none of the addresses, protocols, or ports in the supplied traffic selectors is acceptable. Not it. ๐Ÿ’…

INVALID_SELECTORS 39 ๐Ÿ•ธ๏ธ

This one MAY be sent in an IKE INFORMATIONAL exchange when a node gets an ESP or AH packet whose selectors don't match those of the SA it was delivered on (and that caused the packet to get dropped). The Notification Data holds the start of the offending packet, like in ICMP messages, and the SPI field of the notification is set to match the SPI of the IPsec SA. ๐Ÿงฉ

Here's the number range breakdown ๐Ÿ”ข

RESERVED TO IANA - Error types         40 - 8191

Private Use - Errors                8192 - 16383
NOTIFY MESSAGES - STATUS TYPES           Value
------------------------------           -----

Now we're in the STATUS TYPES era, and it's giving good vibes ๐ŸŒˆ

INITIAL_CONTACT 16384 ๐Ÿค

This notification asserts that this IKE_SA is the only IKE_SA currently active between the authenticated identities. It MAY be sent when an IKE_SA is established after a crash, and the recipient MAY use this info to delete any other IKE_SAs it has with the same authenticated identity without waiting for a timeout. โฐ However, this notification MUST NOT be sent by an entity that may be replicated. Think a roaming user's credentials where the user can connect to the corporate firewall from two remote systems at the same time. ๐Ÿ’ป๐Ÿ’ป

SET_WINDOW_SIZE 16385 ๐ŸชŸ

This notification asserts that the sending endpoint can keep state for multiple outstanding exchanges. That lets the recipient send multiple requests before getting a response to the first one. The data attached 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. ๐Ÿฃ

ADDITIONAL_TS_POSSIBLE 16386 โœจ

This notification asserts that the sending endpoint narrowed the proposed traffic selectors, but other traffic selectors would also have been acceptable, just in a separate SA (see section 2.9). There's no data with this Notify type. It may be sent only as an additional payload in a message that includes accepted TSs. ๐ŸŽ

IPCOMP_SUPPORTED 16387 ๐Ÿ—œ๏ธ

This notification may be included only in a message containing an SA payload that negotiates a CHILD_SA. It shows the sender is willing to use IPComp on this SA. The data has a two-octet IPComp CPI, then a one-octet transform ID, optionally followed by attributes whose length and format are defined by that transform ID. A message proposing an SA may contain multiple IPCOMP_SUPPORTED notifications to show multiple supported algorithms. A message accepting an SA may contain at most one. ๐Ÿงƒ

The transform IDs that are currently defined are:

     NAME         NUMBER  DEFINED IN
     -----------  ------  -----------
     RESERVED       0
     IPCOMP_OUI     1
     IPCOMP_DEFLATE 2     RFC 2394
     IPCOMP_LZS     3     RFC 2395
     IPCOMP_LZJH    4     RFC 3051

     values 5-240 are reserved to IANA.  Values 241-255 are
     for private use among mutually consenting parties.

NAT_DETECTION_SOURCE_IP 16388 ๐ŸŒ

The recipient uses this notification to figure out whether the source is behind a NAT box. The data is a SHA-1 digest of the SPIs (in the order they appear in the header), the IP address, and the port the packet was sent on. There MAY be multiple Notify payloads of this type in a message if the sender doesn't know which of several network attachments will be used to send the packet. ๐Ÿ“ก The recipient MAY compare the supplied value to a SHA-1 hash of the SPIs, source IP address, and port. If they don't match, it SHOULD enable NAT traversal (see section 2.23). Alternately, it MAY reject the connection attempt if NAT traversal isn't supported. ๐Ÿšง

NAT_DETECTION_DESTINATION_IP 16389 ๐Ÿชž

The recipient uses this one to check whether it is behind a NAT box. The data is a SHA-1 digest of the SPIs (in the order they appear in the header), the IP address, and the port the packet was sent to. The recipient MAY compare the supplied value to a hash of the SPIs, destination IP address, and port. If they don't match, it SHOULD invoke NAT traversal (see section 2.23). If they don't match, that means this end is behind a NAT, and this end SHOULD start sending keepalive packets as defined in [Hutt05]. Alternately, it MAY reject the connection attempt if NAT traversal isn't supported. ๐Ÿซ 

COOKIE 16390 ๐Ÿช

This notification MAY be included in an IKE_SA_INIT response. It means the request should be retried with a copy of this notification as the first payload. If a COOKIE notification was included in the initial response, this notification MUST be included in the IKE_SA_INIT request retry. The data MUST be between 1 and 64 octets in length, inclusive. ๐Ÿชโœจ

USE_TRANSPORT_MODE 16391 ๐Ÿšš

This notification MAY be included in a request message that also includes an SA payload requesting a CHILD_SA. It asks that the CHILD_SA use transport mode instead of tunnel mode for the SA 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. ๐Ÿ™…โ€โ™€๏ธ Note: Except when using this option to negotiate transport mode, all CHILD_SAs will use tunnel mode.

Note: The ECN decapsulation modifications specified in [RFC4301] MUST be performed for every tunnel mode SA created by IKEv2. ๐ŸŒช๏ธ

HTTP_CERT_LOOKUP_SUPPORTED 16392 ๐ŸŒท

This notification MAY be included in any message that can include a CERTREQ payload ๐ŸŒธ It basically says "hey, I can look up certificates using an HTTP-based URL," so the other side presumably would prefer to get certificate specs in that format ๐Ÿ’…

REKEY_SA 16393

okay bestie, this one is a must-have ๐Ÿ” It MUST be included in a CREATE_CHILD_SA exchange if the whole point is to replace an existing ESP or AH SA. The SPI field tells you which SA is being rekeyed. There is no data, so it's giving minimalist ๐Ÿค

ESP_TFC_PADDING_NOT_SUPPORTED 16394

this one is a big ol' boundary ๐Ÿ™…โ€โ™€๏ธ It says the sending endpoint will NOT accept packets that contain Flow Confidentiality (TFC) padding. Not me rejecting padding ๐Ÿ’€

NON_FIRST_FRAGMENTS_ALSO 16395

used for fragmentation control ๐Ÿงฉ Go check [RFC4301] for the full tea โœจ

RESERVED TO IANA - STATUS TYPES 16396 - 40959

Private Use - STATUS TYPES 40960 - 65535


3.11. Delete Payload

The Delete Payload, denoted D in this memo, is how you tell the other side "bye, this security association is gone" ๐Ÿ‘‹ It contains a protocol-specific security association identifier that the sender has removed from its security association database, so that identifier is no longer valid. Figure 17 shows the format. You can send multiple SPIs in one Delete payload, but each SPI MUST be for the same protocol. Mixing protocol identifiers MUST NOT be performed in a Delete payload ๐Ÿšซ It IS permitted, though, to include multiple Delete payloads in a single INFORMATIONAL exchange, where each Delete payload lists SPIs for a different protocol. Main character energy with the organization ๐ŸŽ€

Deletion of the IKE_SA is indicated by a protocol ID of 1 (IKE) with no SPIs. Deletion of a CHILD_SA, like ESP or AH, will contain the IPsec protocol ID of that protocol (2 for AH, 3 for ESP), and the SPI is the one the sending endpoint would expect in inbound ESP or AH packets ๐Ÿฆ‹

The Delete 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        !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ! Protocol ID   !   SPI Size    !           # of SPIs           !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !                                                               !
   ~               Security Parameter Index(es) (SPI)              ~
   !                                                               !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

               Figure 17:  Delete Payload Format
  • 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.
  • # of SPIs (2 octets) - 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 # 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 memo, is the vendor's little signature ๐Ÿ–Š๏ธ It contains a vendor-defined constant that vendors use to identify and recognize remote instances of their own implementations. This lets a vendor experiment with new features while staying backward compatible. Iconic behavior, honestly ๐ŸŒˆ

A Vendor ID payload MAY announce that the sender is capable of accepting certain extensions to the protocol, or it MAY simply identify the implementation as an aid in 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). Multiple Vendor ID payloads MAY be sent. An implementation is NOT REQUIRED to send any Vendor ID payload at all, so no pressure ๐Ÿซถ

A Vendor ID payload may be sent as part of any message. Getting a familiar Vendor ID lets an implementation use the Private USE numbers described throughout this memo (private payloads, private exchanges, private notifications, and so on) โœจ Unfamiliar Vendor IDs MUST be ignored ๐Ÿ™ˆ

Writers of Internet-Drafts who want to extend this protocol MUST define a Vendor ID payload to announce the ability to implement the extension in the Internet-Draft. It's expected that Internet-Drafts that 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 will go away ๐ŸŽ‰

The Vendor ID Payload fields are 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        !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !                                                               !
   ~                        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. 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

The Traffic Selector Payload, denoted TS in this memo, is how peers say which packet flows should get IPsec security services ๐ŸŒŠ The Traffic Selector Payload consists of the IKE generic payload header followed by individual traffic selectors, 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        !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   ! Number of TSs !                 RESERVED                      !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   !                                                               !
   ~                       <Traffic Selectors>                     ~
   !                                                               !
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

            Figure 19:  Traffic Selectors Payload Format
  • Number of TSs (1 octet) - Number of traffic selectors being provided.
  • RESERVED - This field MUST be sent as zero and MUST be ignored on receipt.
  • Traffic Selectors (variable length) - One or more individual traffic selectors.

The length of the Traffic Selector payload includes the TS header and all the traffic selectors ๐Ÿ“

The payload type for the Traffic Selector payload is forty four (44) for addresses at the initiator's end of the SA and forty five (45) for addresses at the responder's end ๐Ÿงš

3.13.1. Traffic Selector โœจ

Okay bestie, here's the Traffic Selector layout ๐ŸŽ€ Read it left to right, top to bottom, and you're golden.

                           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 the TS Type. The diagram shows TS Types 7 and 8, which are the only two values defined so far.

  • TS Type (one octet) - Specifies the type of traffic selector. ๐Ÿฆ‹
  • IP protocol ID (1 octet) - Value specifying an associated IP protocol ID (e.g., UDP/TCP/ICMP). A value of zero means that the protocol ID is not relevant to this traffic selector -- the SA can carry all protocols. ๐Ÿ’…
  • Selector Length - Specifies the length of this Traffic Selector Substructure including the header.
  • Start Port (2 octets) - Value specifying the smallest port number allowed by this Traffic Selector. For protocols for which port is undefined, or if all ports are allowed, this field MUST be zero. For the ICMP protocol, the two one-octet fields Type and Code are treated as a single 16-bit integer (with Type in the most significant eight bits and Code in the least significant eight bits) port number for the purposes of filtering based on this field. ๐ŸŒธ
  • End Port (2 octets) - Value specifying the largest port number allowed by this Traffic Selector. For protocols for which port is undefined, or if all ports are allowed, this field MUST be 65535. For the ICMP protocol, the two one-octet fields Type and Code are treated as a single 16-bit integer (with Type in the most significant eight bits and Code in the least significant eight bits) port number for the purposes of filtering based on this field. ๐ŸŒˆ
  • Starting Address - The smallest address included in this Traffic Selector (length determined by TS type).
  • Ending Address - The largest address included in this Traffic Selector (length determined by TS type).

Systems that are complying with [RFC4301] that wish to indicate "ANY" ports MUST set the start port to 0 and the end port to 65535. Note that according to [RFC4301], "ANY" includes "OPAQUE". ๐Ÿ™ˆ Systems working with [RFC4301] that wish to indicate "OPAQUE" ports, but not "ANY" ports, MUST set the start port to 65535 and the end port to 0.

Here's the table of assigned values for the Traffic Selector Type field and the matching Address Selector Data ๐Ÿงš

   TS Type                           Value
   -------                           -----
   RESERVED                           0-6

   TS_IPV4_ADDR_RANGE                  7

         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).  All addresses falling between the two
         specified addresses are considered to be within the list.

   TS_IPV6_ADDR_RANGE                  8

         A range of IPv6 addresses, represented by two sixteen-octet
         values.  The first value is the beginning IPv6 address
         (inclusive) and the second value is the ending IPv6 address
         (inclusive).  All addresses falling between the two
         specified addresses are considered to be within the list.

   RESERVED TO IANA                    9-240
   PRIVATE USE                         241-255

So TS_IPV4_ADDR_RANGE (type 7) is a range of IPv4 addresses, given as two four-octet values. The first is the beginning address (inclusive) and the second is the ending address (inclusive). Anything between those two is in the list. ๐Ÿ’–

TS_IPV6_ADDR_RANGE (type 8) works the same way, except each value is sixteen octets, so it's IPv6 instead. ๐Ÿ‘‘


3.14. Encrypted Payload ๐Ÿ”

Okay, so the Encrypted Payload (written SK{...} or just E in this memo) is basically a container that carries other payloads inside it, but all scrambled up ๐Ÿซถ If it shows up in a message, it MUST be the last payload in that message. Most of the time it's the only payload in there, which is super iconic.

The encryption and integrity protection algorithms get negotiated during IKE_SA setup, and the keys are computed the way sections 2.14 and 2.18 describe. ๐ŸŒธ

The encryption and integrity algorithms are modeled after the ESP algorithms in RFCs 2104 [KBC96], 4303 [RFC4303], and 2451 [ESPCBC]. This document fully specifies how IKE data gets cryptographically processed, but if you want the design reasoning, go read those other documents too ๐Ÿ“š We need a block cipher with a fixed block size, plus an integrity check algorithm that makes a fixed-length checksum over a message of any size. โœจ

The payload type for an Encrypted Payload is forty six (46). It starts with the usual 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. This is a bit of a plot twist ๐Ÿ™ƒ It's an exception to the standard header format. The Encrypted payload is the last payload in the message, so the Next Payload field would normally be zero. But since the content is embedded payloads and there was no natural spot for the type of the first one, that type goes here instead.
  • Payload Length - Includes the lengths of the header, IV, Encrypted IKE Payloads, Padding, Pad Length, and Integrity Checksum Data. ๐Ÿ“
  • Initialization Vector - A randomly chosen value whose length equals the block length of the underlying encryption algorithm. Recipients MUST accept any value. Senders SHOULD either pick this value pseudo-randomly and independently for each message, or use the final ciphertext block of the previous message sent. Senders MUST NOT use the same value for each message, use a sequence of values with low hamming distance (e.g., a sequence number), or use ciphertext from a received message. ๐ŸŽฒ
  • IKE Payloads - These are 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. 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 and running through the Pad Length. The checksum MUST be computed over the encrypted message. Its length is determined by the integrity algorithm negotiated. This is the part that keeps everything tamper-proof, so it's a whole vibe ๐ŸŒˆ

3.15. Configuration Payload ๐ŸŽ€

okay so the Configuration payload, which we're calling CP in this doc ๐Ÿ’–, is how IKE peers swap configuration info ๐Ÿซถ. The main use case is an IRAC asking an IRAS for an internal IP address, plus other stuff you'd normally grab from Dynamic Host Configuration Protocol (DHCP) if the IRAC were plugged straight into a LAN ๐ŸŒธ. It's giving DHCP energy but inside IKE ๐Ÿ’….

Here are the rules, bestie ๐Ÿ‘‘. CFG_REQUEST and CFG_SET payloads may optionally be added to any IKE request ๐Ÿฆ‹. The IKE response MUST include either a matching CFG_REPLY or CFG_ACK, or a Notify payload with an error type explaining why the request couldn't be honored ๐Ÿ˜ญ. The one exception is that a minimal implementation MAY ignore all CFG_REQUEST and CFG_SET payloads ๐Ÿ™ˆ, so a response without a matching CFG_REPLY or CFG_ACK MUST be accepted as an indication that the request was not supported ๐Ÿ’€.

CFG_REQUEST/CFG_REPLY lets an IKE endpoint ask its peer for info ๐Ÿงš. If an attribute in the CFG_REQUEST Configuration Payload isn't 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 skip some of the requested ones ๐ŸŒˆ. Requestors MUST ignore returned attributes they don't recognize ๐Ÿ’œ.

Some attributes MAY be multi-valued, so multiple values of the same type get sent and/or returned ๐Ÿ“. Usually, all values of an attribute come back when it's requested. For some attributes (in this version, only internal addresses), asking multiple times means you want multiple values assigned ๐ŸŒธ. For those, the number of values returned SHOULD NOT exceed the number requested ๐Ÿซถ.

If the data type in a CFG_REQUEST isn't recognized or supported, the responder MUST NOT return an error type ๐Ÿ™…. Instead, it MUST either send a CFG_REPLY that MAY be empty, or send a reply with no CFG_REPLY payload at all ๐Ÿฆ‹. Error returns are saved for when the request is recognized but can't be performed as asked, or when it's badly formatted ๐Ÿ˜ญ.

CFG_SET/CFG_ACK lets an IKE endpoint push config data to its peer ๐Ÿ’…. The CFG_SET Configuration Payload carries the attributes the initiator wants its peer to change โœจ. The responder MUST return a Configuration Payload if it accepted any of the config data, and it MUST contain those accepted attributes with zero-length data ๐Ÿ’–. Attributes it didn't accept MUST NOT be in the CFG_ACK Configuration Payload ๐Ÿ™…. If nothing was accepted, the responder MUST return either an empty CFG_ACK payload or a response message without a CFG_ACK payload ๐Ÿ’€. There are currently no defined uses for CFG_SET/CFG_ACK, though they may be used with extensions based on Vendor IDs ๐Ÿ”ฎ. A minimal implementation of this specification MAY ignore CFG_SET payloads ๐Ÿ™ˆ.

Extensions via the CP payload SHOULD NOT be used for general purpose management ๐Ÿ˜ค. Its main intent is to be a bootstrap mechanism, moving info within IPsec from IRAS to IRAC ๐Ÿš€. While it MAY be useful to use such a method to exchange information between some Security Gateways (SGW) or small networks ๐Ÿ , existing management protocols such as DHCP [DHCP], RADIUS [RADIUS], SNMP, or LDAP [LDAP] should be preferred for enterprise management and for later information exchanges ๐Ÿ’ผ.

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 ๐Ÿง.
CFG Type       Value
===========    =====
RESERVED         0
CFG_REQUEST      1
CFG_REPLY        2
CFG_SET          3
CFG_ACK          4

Values 5-127 are reserved to IANA. Values 128-255 are for private use among mutually consenting parties ๐Ÿ”’.

  • RESERVED (3 octets) - MUST be sent as zero; MUST be ignored on receipt ๐Ÿซง.
  • Configuration Attributes (variable length) - These are type length values specific to the Configuration Payload and are defined below. There may be zero or more Configuration Attributes in this payload ๐ŸŒท.

3.15.1. Configuration Attributes โœจ

okay bestie, let's talk attributes ๐Ÿ’– every one is a little tagged box with a Reserved bit, an Attribute Type, a Length, and then a 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): the length in octets of Value ๐Ÿ“
  • Value (0 or more octets): the variable-length value of this Configuration Attribute ๐ŸŒธ

The following attribute types have been defined ๐Ÿ‘‘

                                   Multi-
     Attribute Type          Value Valued Length
     ======================= ===== ====== ==================
      RESERVED                 0
      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_ADDRESS_EXPIRY  5    NO    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
      RESERVED                 9
      INTERNAL_IP6_DNS        10    YES   0 or 16 octets
      INTERNAL_IP6_NBNS       11    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. ๐Ÿ™ˆ

Types 16-16383 are reserved to IANA. Values 16384-32767 are for private use among mutually consenting parties ๐Ÿงš

  • INTERNAL_IP4_ADDRESS, INTERNAL_IP6_ADDRESS: 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 message, the address specified is a requested address (or zero if no specific address is requested). If a specific address is requested, it likely means a previous connection existed with this address and the requestor would like to reuse it. With IPv6, a requestor MAY supply the low-order address bytes it wants to use. Multiple internal addresses MAY be requested by requesting multiple internal address attributes. The responder MAY only send up to the number of addresses requested. The INTERNAL_IP6_ADDRESS is made up of two fields: the first is a sixteen-octet IPv6 address and the second is a one-octet prefix-length as defined in [ADDRIPV6].

The requested address is valid until the expiry time defined with the INTERNAL_ADDRESS_EXPIRY attribute, or until there are no IKE_SAs between the peers โฐ

  • INTERNAL_IP4_NETMASK: the internal network's netmask. Only one netmask is allowed in the request and reply messages (e.g., 255.255.255.0), and it MUST be used only with an INTERNAL_IP4_ADDRESS attribute ๐ŸŽญ
  • INTERNAL_IP4_DNS, INTERNAL_IP6_DNS: specifies 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, INTERNAL_IP6_NBNS: 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_ADDRESS_EXPIRY: specifies the number of seconds that the host can use the internal IP address. The host MUST renew the IP address before this expiry time. Only one of these attributes MAY be present in the reply โŒ›
  • INTERNAL_IP4_DHCP, INTERNAL_IP6_DHCP: instructs the host to send any internal DHCP requests to the address contained within the attribute. Multiple DHCP servers MAY be requested. The responder MAY respond with zero or more DHCP server attributes ๐Ÿ“ฎ
  • APPLICATION_VERSION: the version or application information of the IPsec host. This is a string of printable ASCII characters that is not null terminated ๐Ÿท๏ธ
  • INTERNAL_IP4_SUBNET: the protected sub-networks that this edge-device protects. This attribute is made up of 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 ๐Ÿฐ
  • SUPPORTED_ATTRIBUTES: when used within a Request, this attribute MUST be zero-length and specifies a query asking the responder to reply with all of the attributes that it supports. The response contains an attribute that holds a set of attribute identifiers, each in 2 octets. The length divided by 2 (octets) would state the number of supported attributes contained in the response ๐Ÿ”
  • INTERNAL_IP6_SUBNET: the protected sub-networks that this edge-device protects. This attribute is made up of two fields: the first is a sixteen-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 ๐Ÿ’œ

Note that no recommendations are made in this document as to how an implementation actually figures out what information to send in a reply. That is, we do not recommend any specific method of an IRAS determining which DNS server should be returned to a requesting IRAC ๐Ÿคทโ€โ™€๏ธ


3.16. Extensible Authentication Protocol (EAP) Payload โœจ

okay so the Extensible Authentication Protocol Payload, called EAP in this memo, lets IKE_SAs get authenticated using the protocol defined in RFC 3748 [EAP] and its later extensions ๐Ÿ” The full set of acceptable values for the payload is defined elsewhere, but a short summary of RFC 3748 is included here so this document can stand on its own for the common cases ๐Ÿ’…

                        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

  • Code (1 octet): indicates whether this message is a Request (1), Response (2), Success (3), or Failure (4) ๐Ÿšฆ
  • Identifier (1 octet): PPP uses this 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. In other messages, this field MAY be set to any value ๐Ÿชช
  • Length (2 octets): the length of the EAP message, which MUST be four less than the Payload Length of the encapsulating payload ๐Ÿ“
  • Type (1 octet): present only 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. The following types are defined in RFC 3748:
1  Identity
2  Notification
3  Nak (Response Only)
4  MD5-Challenge
5  One-Time Password (OTP)
6  Generic Token Card
  • Type_Data (Variable Length): varies with the Type of Request and the associated Response. For the documentation of the EAP methods, see [EAP] ๐Ÿ“š

Note that since IKE passes an indication of initiator identity in message 3 of the protocol, the responder SHOULD NOT send EAP Identity requests. The initiator SHOULD, however, respond to such requests if it receives them ๐Ÿซถ

4. Conformance Requirements โœจ

okay bestie, this section is where we figure out what "counts" as a real IKEv2 implementation ๐Ÿ’… so everyone can actually talk to each other. There are "MUST support" requirements on top of the ones listed elsewhere, and yes, that's giving strict ๐Ÿซถ

Also, IKEv2 is a security protocol ๐Ÿ” its whole main job is letting only the authorized people finish setting up SAs. So a particular implementation can be configured with restrictions on algorithms and trusted authorities, and that can stop it from interoperating with literally everyone. Iconic for security, slightly chaotic for compatibility, but that's the tradeoff ๐Ÿ™ˆ

IKEv2 is built so you can make a tiny implementation that still talks to every compliant one ๐Ÿฆ‹ There's a bunch of optional features that a implementation can just ignore if it doesn't support them. Those are:

  • 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 various types of legacy authentication. ๐Ÿ•ฐ๏ธ
  • Ability to support window sizes greater than one. ๐ŸชŸ
  • Ability to establish multiple ESP and/or AH SAs within a single IKE_SA. ๐Ÿงš
  • Ability to rekey SAs. ๐Ÿ”

Now the non-negotiable part ๐Ÿ˜ค 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 vibes-based skipping, periodt ๐Ÿ’€

Every implementation MUST be capable of doing four-message IKE_SA_INIT and IKE_AUTH exchanges that establish two SAs (one for IKE, one for ESP and/or AH) โœจ That's the baseline main-character moment. Implementations MAY be initiate-only or respond-only if that fits their platform ๐Ÿ“ Every implementation MUST be capable of responding to an INFORMATIONAL exchange ๐Ÿ“จ but a minimal implementation MAY respond to any INFORMATIONAL message with an empty INFORMATIONAL reply. (Quick reminder: inside an IKE_SA, an "empty" message is just an IKE header followed by an Encrypted payload with no payloads inside it ๐Ÿซง)

A minimal implementation MAY support the CREATE_CHILD_SA exchange only enough to recognize requests and reject them with a Notify payload of type NO_ADDITIONAL_SAS ๐Ÿ™…โ€โ™€๏ธ A minimal implementation also doesn't need to be able to initiate CREATE_CHILD_SA or INFORMATIONAL exchanges. Lowkey relaxing ๐Ÿง˜โ€โ™€๏ธ

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 โณ And if the responder rejects the CREATE_CHILD_SA request with a NO_ADDITIONAL_SAS notification, the implementation MUST be capable of instead closing the old SA and creating a new one. That one's a hard rule, bestie ๐Ÿšจ

Requesting temporary IP addresses is NOT required. Implementations are not required to support requesting them or responding to such requests ๐Ÿซถ

If an implementation does support issuing those requests, it MUST include a CP payload in message 3 containing at least a field of type INTERNAL_IP4_ADDRESS or INTERNAL_IP6_ADDRESS. Everything else in there is optional ๐ŸŽ€ If an implementation supports responding to such requests, it MUST parse the CP payload of type CFG_REQUEST in message 3 and recognize a field of type INTERNAL_IP4_ADDRESS or INTERNAL_IP6_ADDRESS. And 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 SHOULD include all the other related attributes if it has them, because giving people everything they could want is very on-brand ๐ŸŒธ

A minimal IPv4 responder is kinda chill ๐Ÿ˜Œ It ignores the contents of the CP payload except to figure out that it includes an INTERNAL_IP4_ADDRESS attribute, and then it responds with the address and other related attributes whether or not the initiator actually asked for them.

A minimal IPv4 initiator generates a CP payload with only an INTERNAL_IP4_ADDRESS attribute, then parses the response and ignores any attributes it doesn't know how to use ๐Ÿงš The only attribute it MUST be able to process is INTERNAL_ADDRESS_EXPIRY, and it has to use that to bound the lifetime of the SA, unless it successfully renews the lease before it expires โฐ Minimal initiators need not be able to request lease renewals, and minimal responders need not respond to them. Soft life, honestly ๐Ÿซ 


For an implementation to be called conforming to this specification, it MUST be possible to configure it to accept the following ๐Ÿ“œ

  • 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 passes 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 part is serious, so grab a snack and get comfy ๐Ÿ“. The protocol is designed to keep configuration info away from unauthenticated peers, but some leakage is unavoidable ๐Ÿ˜ญ. One peer has to identify itself first and prove who it is first. To avoid probing, the initiator is required to identify itself first, and usually has to authenticate itself first. The initiator can still learn that the responder supports IKE and which cryptographic protocols it speaks ๐Ÿ‘€. The responder (or someone pretending to be the responder) can probe the initiator for its identity, and by using CERTREQ payloads it may be able to figure out which certificates the initiator is willing to use ๐Ÿ•ต๏ธโ€โ™€๏ธ.

Using EAP authentication shifts the probing a bit ๐Ÿฆ‹. When EAP is in play, the responder proves its identity before the initiator does, so an initiator who already knows the name of a valid initiator could poke at the responder for both its name and its certificates.

Repeated rekeying with CREATE_CHILD_SA and no extra Diffie-Hellman exchanges leaves every SA exposed to cryptanalysis of a single key, or to an overrun of either endpoint ๐Ÿ’€. Implementers should take note of this and set a limit on CREATE_CHILD_SA exchanges between exponentiations. This memo does not prescribe what that limit should be ๐Ÿซถ.

The strength of a key from a Diffie-Hellman exchange, using any of the groups defined here, depends on three things: the inherent strength of the group, the size of the exponent, and the entropy from the random number generator ๐ŸŽฒ. Because of all those inputs, it's hard to pin down exactly how strong a key is for any of the defined groups. Diffie-Hellman group number two, with a strong random number generator and an exponent of at least 200 bits, is common for use with 3DES. Group five is stronger than group two โœจ. Group one is for historic purposes only and isn't strong enough, except for use with DES, which is also historic-only ๐Ÿ•ฐ๏ธ. Implementations should keep these estimates in mind when setting policy and negotiating security parameters.

Now, these limits are about the Diffie-Hellman groups themselves. Nothing in IKE stops you from using stronger groups, and nothing dilutes the strength you get from them (it's capped by the strength of the other negotiated algorithms, including the prf function) ๐Ÿ’ช. The extensible framework of IKE actually encourages defining more groups. Elliptical curve groups, for example, may greatly increase strength while using much smaller numbers ๐ŸŒˆ.

It's assumed that every Diffie-Hellman exponent gets erased from memory after use ๐Ÿงน. In particular, these exponents MUST NOT be derived from long-lived secrets, like the seed to a pseudo-random generator that isn't erased after use ๐Ÿšซ.

All keys are limited by the size of the output of the negotiated prf function, so that's the ceiling ๐Ÿงฑ. For this reason, a prf function whose output is less than 128 bits (e.g., 3DES-CBC) MUST NOT be used with this protocol. Not even a little bit ๐Ÿ™…โ€โ™€๏ธ.

The security of this protocol depends heavily on how random the randomly chosen parameters are ๐ŸŽฐ. They should be generated by a strong random source or a properly seeded pseudo-random source (see [RFC4086]). Implementers should be careful that random numbers, for both keys and nonces, are used in a way that doesn't undermine the security of the keys.

If you want the reasoning behind many of the crypto design choices, check out [SIGMA] and [SKEME] ๐Ÿ“š. Even though the security of negotiated CHILD_SAs doesn't depend on how strong the encryption and integrity protection are in the IKE_SA, implementations MUST NOT negotiate NONE as the IKE integrity protection algorithm or ENCR_NULL as the IKE encryption algorithm. Those are a hard no ๐Ÿ™…โ€โ™€๏ธ๐Ÿ’….

When you're using pre-shared keys, a big question is how to make sure those secrets are truly random ๐Ÿ”‘. The strongest practice is for any pre-shared key to contain as much randomness as the strongest key being negotiated. Deriving a shared secret from a password, a name, or some other low-entropy source is not secure ๐Ÿ˜ฌ. Those sources are open to dictionary attacks and social engineering, among others.

The NAT_DETECTION_*_IP notifications contain a hash of the addresses and ports, which is meant to hide internal IP addresses behind a NAT ๐Ÿ™ˆ. But IPv4 is only 32 bits, and the space is usually very sparse, so an attacker could try every possible IP address and look for a matching hash to find the internal address behind the NAT box. The port numbers are normally fixed at 500, and the SPIs can be pulled straight out of the packet. That shrinks the search to 2^32 hash calculations. With an educated guess about private address space, the number of calculations gets way smaller ๐Ÿ˜ฑ. So designers should not assume that using IKE won't leak internal address information.

When an EAP method doesn't generate a shared key to protect a later AUTH payload, certain man-in-the-middle and server impersonation attacks are possible [EAPMITM] ๐Ÿ‘ป. These problems show up when EAP is also used in protocols that aren't protected by a secure tunnel. EAP is a general-purpose authentication protocol, often used to provide single-signon facilities, so an IPsec setup that relies on a non-key-generating EAP method (one that doesn't produce a shared key) can get compromised just because some totally unrelated app happens to use that same method in an unprotected way ๐Ÿšจ. This isn't limited to EAP, either. It can happen anywhere an authentication infrastructure gets reused. For example, if the EAP mechanism used by IKEv2 uses a token authenticator, a man-in-the-middle attacker could impersonate the web server, intercept the token authentication exchange, and use it to start an IKEv2 connection ๐Ÿซฃ.

For that reason, non-key-generating EAP methods SHOULD be avoided where possible. Where they're used, it's extremely important that all usages of these EAP methods SHOULD utilize a protected tunnel, where the initiator validates the responder's certificate before starting the EAP exchange ๐Ÿ”’. Implementers SHOULD describe the vulnerabilities of non-key-generating EAP methods in their implementation documentation, so the admins deploying IPsec solutions know exactly what dangers they're signing up for ๐Ÿ“.

An implementation using EAP MUST ALSO use public-key-based authentication of the server to the client before the EAP exchange begins, even if the EAP method offers mutual authentication ๐Ÿ”. This avoids extra IKEv2 protocol variations and protects the EAP data from active attackers.

If IKEv2 messages get long enough that IP-level fragmentation is needed, attackers could block the exchange from finishing by exhausting the reassembly buffers ๐Ÿงฉ. You can reduce that chance by using the Hash and URL encodings instead of sending certificates (see section 3.6). More mitigations are discussed in [KPS03] ๐Ÿ’œ.


6. IANA Considerations ๐Ÿ“‹

This document defines a bunch of new field types and values, and future assignments for them will be managed by the IANA ๐ŸŒธ.

The IANA has created the following registries:

   IKEv2 Exchange Types (section 3.1)
   IKEv2 Payload Types (section 3.2)
   IKEv2 Transform Types (section 3.3.2)
       IKEv2 Transform Attribute Types (section 3.3.2)
       IKEv2 Encryption Transform IDs (section 3.3.2)
       IKEv2 Pseudo-random Function Transform IDs (section 3.3.2)
       IKEv2 Integrity Algorithm Transform IDs (section 3.3.2)
       IKEv2 Diffie-Hellman Transform IDs (section 3.3.2)
   IKEv2 Identification Payload ID Types (section 3.5)
   IKEv2 Certificate Encodings (section 3.6)
   IKEv2 Authentication Method (section 3.8)
   IKEv2 Notify Message Types (section 3.10.1)
       IKEv2 Notification IPCOMP Transform IDs (section 3.10.1)
   IKEv2 Security Protocol Identifiers (section 3.3.1)
   IKEv2 Traffic Selector Types (section 3.13.1)
   IKEv2 Configuration Payload CFG Types (section 3.15)
   IKEv2 Configuration Payload Attribute Types (section 3.15.1)

Note: when you create a new Transform Type, a new registry for it has to be created too ๐Ÿง.

Changes and additions to any of those registries are handled by expert review ๐Ÿง‘โ€๐Ÿ”ฌ.


7. Acknowledgements ๐Ÿซถ

This document is a collaborative effort of the entire IPsec WG ๐ŸŒˆ. If there were no limit on how many authors could appear on an RFC, the following people would have been listed, in alphabetical order: 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's an evolution of IKEv1, ISAKMP, and the IPsec DOI, and each of those has its own list of authors โœจ.

Hugh Daniel suggested the feature where the initiator, in message 3, specifies a name for the responder, and he gave it the iconic name "You Tarzan, Me Jane" ๐Ÿฆง๐Ÿ’…. David Faucher and Valery Smyzlov helped refine the design of the traffic selector negotiation ๐Ÿงš.


8. References ๐Ÿ“š

8.1. Normative References

  • [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, "Internet Protocol Version 6 (IPv6) Addressing Architecture", RFC 3513, April 2003.
  • [Bra97] Bradner, S., "Key Words for use in RFCs to indicate Requirement Levels", BCP 14, RFC 2119, March 1997.
  • [EAP] Aboba, B., Blunk, L., Vollbrecht, J., Carlson, J., and H. Levkowetz, "Extensible Authentication Protocol (EAP)", RFC 3748, June 2004.
  • [ESPCBC] Pereira, R. and R. Adams, "The ESP CBC-Mode Cipher Algorithms", RFC 2451, November 1998.
  • [Hutt05] Huttunen, A., Swander, B., Volpe, V., DiBurro, L., and M. Stenberg, "UDP Encapsulation of IPsec ESP Packets", RFC 3948, January 2005.
  • [RFC2434] Narten, T. and H. Alvestrand, "Guidelines for Writing an IANA Considerations Section in RFCs", BCP 26, RFC 2434, October 1998.
  • [RFC3168] Ramakrishnan, K., Floyd, S., and D. Black, "The Addition of Explicit Congestion Notification (ECN) to IP", RFC 3168, September 2001.
  • [RFC3280] Housley, R., Polk, W., Ford, W., and D. Solo, "Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile", RFC 3280, April 2002.
  • [RFC4301] Kent, S. and K. Seo, "Security Architecture for the Internet Protocol", RFC 4301, December 2005.

8.2. Informative References ๐Ÿ“š

okay bestie, this is the extra reading list for anyone who wants to go deeper ๐Ÿค“ these aren't required to implement IKEv2, but they're the receipts behind the design ๐Ÿ’…

  • [DES] ANSI X3.106, "American National Standard for Information Systems-Data Link Encryption", American National Standards Institute, 1983.
  • [DH] Diffie, W., and Hellman M., "New Directions in Cryptography", IEEE Transactions on Information Theory, V. IT-22, n. 6, June 1977.
  • [DHCP] Droms, R., "Dynamic Host Configuration Protocol", RFC 2131, March 1997.
  • [DSS] NIST, "Digital Signature Standard", FIPS 186, National Institute of Standards and Technology, U.S. Department of Commerce, May, 1994.
  • [EAPMITM] Asokan, N., Nierni, V., and Nyberg, K., "Man-in-the-Middle in Tunneled Authentication Protocols", http://eprint.iacr.org/2002/163, November 2002.
  • [HC98] Harkins, D. and D. Carrel, "The Internet Key Exchange (IKE)", RFC 2409, November 1998.
  • [IDEA] Lai, X., "On the Design and Security of Block Ciphers," ETH Series in Information Processing, v. 1, Konstanz: Hartung-Gorre Verlag, 1992.
  • [IPCOMP] Shacham, A., Monsour, B., Pereira, R., and M. Thomas, "IP Payload Compression Protocol (IPComp)", RFC 3173, September 2001.
  • [KPS03] Kaufman, C., Perlman, R., and Sommerfeld, B., "DoS protection for UDP-based protocols", ACM Conference on Computer and Communications Security, October 2003.
  • [KBC96] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed-Hashing for Message Authentication", RFC 2104, February 1997.
  • [LDAP] Wahl, M., Howes, T., and S Kille, "Lightweight Directory Access Protocol (v3)", RFC 2251, December 1997.
  • [MD5] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, April 1992.
  • [MSST98] Maughan, D., Schertler, M., Schneider, M., and J. Turner, "Internet Security Association and Key Management Protocol (ISAKMP)", RFC 2408, November 1998.
  • [Orm96] 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.
  • [PKCS1] Jonsson, J. and B. Kaliski, "Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography Specifications Version 2.1", RFC 3447, February 2003.
  • [PK01] Perlman, R., and Kaufman, C., "Analysis of the IPsec key exchange Standard", WET-ICE Security Conference, MIT,2001, http://sec.femto.org/wetice-2001/papers/radia-paper.pdf.
  • [Pip98] Piper, D., "The Internet IP Security Domain Of Interpretation for ISAKMP", RFC 2407, November 1998.
  • [RADIUS] Rigney, C., Willens, S., Rubens, A., and W. Simpson, "Remote Authentication Dial In User Service (RADIUS)", RFC 2865, June 2000.
  • [RFC4086] Eastlake, D., 3rd, Schiller, J., and S. Crocker, "Randomness Requirements for Security", BCP 106, RFC 4086, June 2005.
  • [RFC1958] Carpenter, B., "Architectural Principles of the Internet", RFC 1958, June 1996.
  • [RFC2401] Kent, S. and R. Atkinson, "Security Architecture for the Internet Protocol", RFC 2401, November 1998.
  • [RFC2474] 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.
  • [RFC2475] Blake, S., Black, D., Carlson, M., Davies, E., Wang, Z., and W. Weiss, "An Architecture for Differentiated Service", RFC 2475, December 1998.
  • [RFC2522] Karn, P. and W. Simpson, "Photuris: Session-Key Management Protocol", RFC 2522, March 1999.
  • [RFC2775] Carpenter, B., "Internet Transparency", RFC 2775, February 2000.
  • [RFC2983] Black, D., "Differentiated Services and Tunnels", RFC 2983, October 2000.
  • [RFC3439] Bush, R. and D. Meyer, "Some Internet Architectural Guidelines and Philosophy", RFC 3439, December 2002.
  • [RFC3715] Aboba, B. and W. Dixon, "IPsec-Network Address Translation (NAT) Compatibility Requirements", RFC 3715, March 2004.
  • [RFC4302] Kent, S., "IP Authentication Header", RFC 4302, December 2005.
  • [RFC4303] Kent, S., "IP Encapsulating Security Payload (ESP)", RFC 4303, December 2005.
  • [RSA] Rivest, R., Shamir, A., and Adleman, L., "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems", Communications of the ACM, v. 21, n. 2, February 1978.
  • [SHA] NIST, "Secure Hash Standard", FIPS 180-1, National Institute of Standards and Technology, U.S. Department of Commerce, May 1994.
  • [SIGMA] Krawczyk, H., "SIGMA: the `SIGn-and-MAc' Approach to Authenticated Diffie-Hellman and its Use in the IKE Protocols", in Advances in Cryptography - CRYPTO 2003 Proceedings, LNCS 2729, Springer, 2003. Available at: http://www.informatik.uni-trier.de/~ley/db/conf/crypto/crypto2003.html.
  • [SKEME] Krawczyk, H., "SKEME: A Versatile Secure Key Exchange Mechanism for Internet", from IEEE Proceedings of the 1996 Symposium on Network and Distributed Systems Security.
  • [X.501] ITU-T Recommendation X.501: Information Technology - Open Systems Interconnection - The Directory: Models, 1993.
  • [X.509] ITU-T Recommendation X.509 (1997 E): Information Technology - Open Systems Interconnection - The Directory: Authentication Framework, June 1997.

Appendix A: Summary of changes from IKEv1 ๐Ÿฆ‹

the glow-up chart! โœจ here's everything that changed from IKEv1, in the order the document lists it ๐Ÿ’–

The goals of this revision to IKE are:

  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 [PK01];
  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, and not commit any state to an exchange until the initiator can be cryptographically authenticated;
  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, to make it easier to make future revisions that do not break backward compatibility;
  11. To simplify and clarify how shared state is maintained in the presence of network failures and Denial of Service 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 ๐Ÿงฎ

there are two Diffie-Hellman groups defined here for IKE, and they were generated by Richard Schroeppel at the University of Arizona ๐ŸŒต the properties of these primes are described in [Orm96] ๐Ÿ’œ

The strength supplied by group one may not be sufficient for the mandatory-to-implement encryption algorithm and is here for historic reasons. so it's more of a vintage piece ๐Ÿ•ฐ๏ธ

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.


Editor's Address ๐Ÿ’Œ

Charlie Kaufman Microsoft Corporation 1 Microsoft Way Redmond, WA 98052

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


Copyright (C) The Internet Society (2005).

This document is subject to the rights, licenses and restrictions contained in BCP 78, and except as set forth therein, the authors retain all their rights.

This document and the information contained herein are provided on an "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.


Intellectual Property ๐Ÿ”

The IETF takes no position regarding the validity or scope of any Intellectual Property Rights or other rights that might be claimed to pertain to the implementation or use of the technology described in this document or the extent to which any license under such rights might or might not be available; nor does it represent that it has made any independent effort to identify any such rights. Information on the procedures with respect to rights in RFC documents can be found in BCP 78 and BCP 79.

Copies of IPR disclosures made to the IETF Secretariat and any assurances of licenses to be made available, or the result of an attempt made to obtain a general license or permission for the use of such proprietary rights by implementers or users of this specification can be obtained from the IETF on-line IPR repository at http://www.ietf.org/ipr.

The IETF invites any interested party to bring to its attention any copyrights, patents or patent applications, or other proprietary rights that may cover technology that may be required to implement this standard. Please address the information to the IETF at ietf-ipr@ietf.org.

Acknowledgement โœจ

okay bestie, last little bit of the doc ๐Ÿซถ funding for the RFC Editor function is currently provided by the Internet Society ๐Ÿ’– so that's who's keeping the lights on right now ๐ŸŒˆ

๐Ÿ“ฆ where this page comes from