RFC 7296
Internet Key Exchange Protocol Version 2 (IKEv2)
RFC 7296: Internet Key Exchange Protocol Version 2 (IKEv2) ๐
okay bestie, let's start with the title block ๐ This is RFC 7296, a Standards Track document in the STD 79 series with ISSN 2070-1721, dated October 2014 ๐ฆ It obsoletes RFC 5996 and doesn't update anything else. The authors are:
- C. Kaufman (Microsoft)
- P. Hoffman (VPN Consortium)
- Y. Nir (Check Point)
- P. Eronen (Independent)
- T. Kivinen (INSIDE Secure)
The IETF is the body that put this out ๐ธ
Abstract โจ
so this doc describes version 2 of the Internet Key Exchange (IKE) protocol ๐ IKE is a piece of IPsec, and its whole job is handling mutual authentication and setting up and maintaining Security Associations (SAs) ๐ฅ This one obsoletes RFC 5996 and includes all of its errata ๐ It also glow-ups IKEv2 into an Internet Standard ๐
Status of This Memo ๐
this is an Internet Standards Track document ๐
it's a product of the Internet Engineering Task Force (IETF) ๐ซถ it represents the consensus of the IETF community โจ it went through public review and got approved for publication by the Internet Engineering Steering Group (IESG) ๐ if you want more on Internet Standards, check out Section 2 of RFC 5741 ๐
info about the current status of this doc, any errata, and how to send feedback lives at http://www.rfc-editor.org/info/rfc7296 ๐ง
Copyright Notice ๐
Copyright (c) 2014 IETF Trust and the persons identified as the document authors. All rights reserved. ๐
this doc is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) as they stand on the publication date ๐ please read these carefully, because they spell out your rights and restrictions for this doc ๐ Code Components pulled out of this document must include Simplified BSD License text, as described in Section 4.e of the Trust Legal Provisions, and they come with no warranty, as described in the Simplified BSD License ๐ฅ
this document may contain material from IETF Documents or IETF Contributions published or made publicly available before November 10, 2008 ๐ฆ the people who control copyright in some of that older material may not have given the IETF Trust permission to allow changes outside the IETF Standards Process ๐ซ unless you get a proper license from those copyright holders, this document may not be modified outside the IETF Standards Process, and derivative works of it may not be created outside the IETF Standards Process either ๐ซ the exceptions are formatting it for publication as an RFC and translating it into languages other than English ๐ธ
Table of Contents ๐๏ธ
okay this is the full map of the doc, so you can find your way around ๐งญ
1. Introduction ....................................................5
1.1. Usage Scenarios ............................................7
1.1.1. Security Gateway to Security Gateway in
Tunnel Mode .........................................7
1.1.2. Endpoint-to-Endpoint Transport Mode .................8
1.1.3. Endpoint to Security Gateway in Tunnel Mode .........8
1.1.4. Other Scenarios .....................................9
1.2. The Initial Exchanges ......................................9
1.3. The CREATE_CHILD_SA Exchange ..............................13
1.3.1. Creating New Child SAs with the
CREATE_CHILD_SA Exchange ...........................14
1.3.2. Rekeying IKE SAs with the CREATE_CHILD_SA
Exchange ...........................................16
1.3.3. Rekeying Child SAs with the CREATE_CHILD_SA
Exchange ...........................................16
1.4. The INFORMATIONAL Exchange ................................17
1.4.1. Deleting an SA with INFORMATIONAL Exchanges ........18
1.5. Informational Messages outside of an IKE SA ...............19
1.6. Requirements Terminology ..................................20
1.7. Significant Differences between RFC 4306 and RFC 5996 .....20
1.8. Differences between RFC 5996 and This Document ............23
2. IKE Protocol Details and Variations ............................23
2.1. Use of Retransmission Timers ..............................24
2.2. Use of Sequence Numbers for Message ID ....................25
2.3. Window Size for Overlapping Requests ......................26
2.4. State Synchronization and Connection Timeouts .............28
2.5. Version Numbers and Forward Compatibility .................30
2.6. IKE SA SPIs and Cookies ...................................32
2.6.1. Interaction of COOKIE and INVALID_KE_PAYLOAD .......35
2.7. Cryptographic Algorithm Negotiation .......................35
2.8. Rekeying ..................................................36
2.8.1. Simultaneous Child SA Rekeying .....................38
2.8.2. Simultaneous IKE SA Rekeying .......................40
2.8.3. Rekeying the IKE SA versus Reauthentication ........42
2.9. Traffic Selector Negotiation ..............................42
2.9.1. Traffic Selectors Violating Own Policy .............45
2.9.2. Traffic Selectors in Rekeying ......................46
2.10. Nonces ...................................................46
2.11. Address and Port Agility .................................47
2.12. Reuse of Diffie-Hellman Exponentials .....................47
2.13. Generating Keying Material ...............................48
2.14. Generating Keying Material for the IKE SA ................49
2.15. Authentication of the IKE SA .............................50
2.16. Extensible Authentication Protocol Methods ...............52
2.17. Generating Keying Material for Child SAs .................54
2.18. Rekeying IKE SAs Using a CREATE_CHILD_SA Exchange ........55
2.19. Requesting an Internal Address on a Remote Network .......56
2.20. Requesting the Peer's Version ............................58
2.21. Error Handling ...........................................58
2.21.1. Error Handling in IKE_SA_INIT .....................59
2.21.2. Error Handling in IKE_AUTH ........................59
2.21.3. Error Handling after IKE SA is Authenticated ......60
2.21.4. Error Handling Outside IKE SA .....................60
2.22. IPComp ...................................................61
2.23. NAT Traversal ............................................62
2.23.1. Transport Mode NAT Traversal ......................66
2.24. Explicit Congestion Notification (ECN) ...................70
2.25. Exchange Collisions ......................................70
2.25.1. Collisions while Rekeying or Closing Child SAs ....71
2.25.2. Collisions while Rekeying or Closing IKE SAs ......71
3. Header and Payload Formats .....................................72
3.1. The IKE Header ............................................72
3.2. Generic Payload Header ....................................75
3.3. Security Association Payload ..............................77
3.3.1. Proposal Substructure ..............................80
3.3.2. Transform Substructure .............................81
3.3.3. Valid Transform Types by Protocol ..................85
3.3.4. Mandatory Transform IDs ............................85
3.3.5. Transform Attributes ...............................86
3.3.6. Attribute Negotiation ..............................88
3.4. Key Exchange Payload ......................................89
3.5. Identification Payloads ...................................90
3.6. Certificate Payload .......................................92
3.7. Certificate Request Payload ...............................95
3.8. Authentication Payload ....................................97
3.9. Nonce Payload .............................................98
3.10. Notify Payload ...........................................99
3.10.1. Notify Message Types .............................101
3.11. Delete Payload ..........................................104
3.12. Vendor ID Payload .......................................105
3.13. Traffic Selector Payload ................................106
3.13.1. Traffic Selector .................................108
3.14. Encrypted Payload .......................................110
3.15. Configuration Payload ...................................112
3.15.1. Configuration Attributes .........................113
3.15.2. Meaning of INTERNAL_IP4_SUBNET and
INTERNAL_IP6_SUBNET ..............................116
3.15.3. Configuration Payloads for IPv6 ..................118
3.15.4. Address Assignment Failures ......................119
3.16. Extensible Authentication Protocol (EAP) Payload ........120
4. Conformance Requirements ......................................122
5. Security Considerations .......................................124
5.1. Traffic Selector Authorization ...........................127
6. IANA Considerations ...........................................128
7. References ....................................................128
7.1. Normative References .....................................128
7.2. Informative References ...................................130
Appendix A. Summary of Changes from IKEv1 ........................136
Appendix B. Diffie-Hellman Groups ................................137
B.1. Group 1 - 768-bit MODP ....................................137
B.2. Group 2 - 1024-bit MODP ...................................137
Appendix C. Exchanges and Payloads ...............................138
C.1. IKE_SA_INIT Exchange ......................................138
C.2. IKE_AUTH Exchange without EAP .............................138
C.3. IKE_AUTH Exchange with EAP ................................139
C.4. CREATE_CHILD_SA Exchange for Creating or Rekeying
Child SAs .................................................140
C.5. CREATE_CHILD_SA Exchange for Rekeying the IKE SA ..........140
C.6. INFORMATIONAL Exchange ....................................141
Acknowledgements .................................................141
Authors' Addresses ...............................................142
1. Introduction โจ
okay bestie, IP Security (IPsec) is the thing that 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 a datagram. That state decides, among other things, which services get applied, which cryptographic algorithms do the work, and which keys get fed into those algorithms ๐ง.
Setting up that shared state by hand doesn't scale, honestly it's giving tedious ๐. So we need a protocol that builds the state dynamically, and that's exactly what this document describes: the Internet Key Exchange (IKE) ๐ฆ. Version 1 of IKE was defined in RFCs 2407 [DOI], 2408 [ISAKMP], and 2409 [IKEV1]. IKEv2 replaced all of those ๐ . IKEv2 was defined in [IKEV2] (RFC 4306) and clarified in [Clarif] (RFC 4718). Then [RFC5996] replaced and updated RFCs 4306 and 4718. This document replaces RFC 5996 ๐.
Quick tea: IKEv2 as stated in RFC 4306 was NOT backward compatible with the old stuff, which was a whole moment ๐ญ. RFC 5996 came in and revised RFC 4306 as a clarification, with minimal changes to IKEv2. This document replaces RFC 5996 too, just with a slight revision so it can move forward to Internet Standard ๐. The significant differences between RFCs 4306 and 5996 are in Section 1.7, and the differences between RFC 5996 and this document are in Section 1.8 โจ.
IKE does mutual authentication between two parties and sets up an IKE Security Association (SA). That SA holds shared secret information, which can be used to efficiently set up SAs for Encapsulating Security Payload (ESP) [ESP] or Authentication Header (AH) [AH], plus a set of cryptographic algorithms those SAs use to protect the traffic they carry ๐ฅ. In this doc, "suite" or "cryptographic suite" means a complete set of algorithms protecting an SA. An initiator proposes one or more suites by listing supported algorithms, which can be mixed and matched into suites ๐. IKE can also negotiate IP Compression (IPComp) [IP-COMP] alongside an ESP or AH SA. The SAs for ESP or AH that get set up through an IKE SA are what we call "Child SAs" ๐ธ.
Every IKE communication is a pair of messages: a request and a response. That pair is called an "exchange", and sometimes a "request/response pair" ๐. The first two exchanges that establish an IKE SA are the IKE_SA_INIT exchange and the IKE_AUTH exchange. Later IKE exchanges are either CREATE_CHILD_SA exchanges or INFORMATIONAL exchanges โจ. In the common case there's one IKE_SA_INIT exchange and one IKE_AUTH exchange, four messages total, to set up the IKE SA and the first Child SA ๐ซถ. In exceptional cases there can be more than one of each. In every case, all IKE_SA_INIT exchanges MUST complete before any other exchange type. After that, all IKE_AUTH exchanges MUST complete. Then any number of CREATE_CHILD_SA and INFORMATIONAL exchanges can happen, in any order ๐. In some setups, only one Child SA is needed between the IPsec endpoints, so there are no extra exchanges. Later exchanges MAY be used to set up more Child SAs between the same authenticated pair of endpoints, and to do housekeeping ๐ง.
An IKE message flow ALWAYS goes request then response, so it's the requester's job to make sure things are reliable ๐ . If the response doesn't show up within a timeout interval, the requester has to retransmit the request (or give up on the connection) ๐ญ.
The first exchange of an IKE session, IKE_SA_INIT, negotiates security parameters for the IKE SA, sends nonces, and sends Diffie-Hellman values ๐.
The second exchange, IKE_AUTH, transmits identities and proves you know the secrets behind both identities ๐. It also sets up an SA for the first (and often only) AH or ESP Child SA. If setting up that Child SA fails, the IKE SA still gets established, just without the Child SA ๐.
The later exchange types are CREATE_CHILD_SA, which creates a Child SA, and INFORMATIONAL, which deletes an SA, reports error conditions, or does other housekeeping ๐. Every request needs a response, no exceptions. An INFORMATIONAL request with no payloads (other than the empty Encrypted payload the syntax requires) is commonly used as a liveness check ๐. These later exchanges can't be used until the initial exchanges have completed ๐ธ.
For everything below, we assume no errors happen. Changes to the flow when errors do happen are described in Section 2.21 โญ.
1.1. Usage Scenarios
IKE negotiates ESP 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 in Tunnel Mode
+-+-+-+-+-+ +-+-+-+-+-+
| | IPsec | |
Protected|Tunnel | tunnel |Tunnel | Protected
Subnet <-->|Endpoint |<---------->|Endpoint |<--> Subnet
| | | |
+-+-+-+-+-+ +-+-+-+-+-+
Figure 1: Security Gateway to Security Gateway Tunnel
In this scenario, neither endpoint of the IP connection implements IPsec, but network nodes in between protect the traffic for part of the way ๐. The protection is 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 Mode
+-+-+-+-+-+ +-+-+-+-+-+
| | IPsec transport | |
|Protected| or tunnel mode SA |Protected|
|Endpoint |<---------------------------------------->|Endpoint |
| | | |
+-+-+-+-+-+ +-+-+-+-+-+
Figure 2: Endpoint to Endpoint
In this scenario, both endpoints of the IP connection implement IPsec, as required of hosts in [IPSECARCH] ๐. Transport mode is commonly used with no inner IP header. A single pair of addresses gets negotiated for the packets this SA protects ๐ง. These endpoints MAY implement application-layer access controls based on the IPsec authenticated identities of the participants ๐. This scenario enables the end-to-end security that has been a guiding principle of the Internet since [ARCHPRINC] and [TRANSPARENCY], and it's a way to limit the inherent complexity problems in networks, as noted in [ARCHGUIDEPHIL] ๐ซถ. Although this scenario may not be fully applicable to the IPv4 Internet, it's 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 ๐ฆ.
It's possible in this scenario that one or both protected endpoints end up 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 identify individual endpoints "behind" the NAT (see Section 2.23) ๐.
1.1.3. Endpoint to Security Gateway in Tunnel Mode
+-+-+-+-+-+ +-+-+-+-+-+
| | IPsec | | Protected
|Protected| tunnel |Tunnel | Subnet
|Endpoint |<------------------------>|Endpoint |<--- and/or
| | | | Internet
+-+-+-+-+-+ +-+-+-+-+-+
Figure 3: Endpoint to Security Gateway Tunnel
In this scenario, a protected endpoint (typically a portable roaming computer) connects back to its corporate network through an IPsec-protected tunnel ๐ผ. It might use the tunnel only to access information on the corporate network. Or it might tunnel all of its traffic back through the corporate network, to take advantage of the protection a corporate firewall gives against Internet-based attacks ๐ก๏ธ. Either way, the protected endpoint wants an IP address associated with the security gateway, so packets sent back to it go to the gateway and get tunneled back ๐. That IP address may be static, or it may be dynamically allocated by the security gateway. For that second case, IKEv2 includes a mechanism (namely, configuration payloads) that lets the initiator request an IP address owned by the security gateway, for use for the duration of its SA ๐ง.
In this scenario, packets use tunnel mode ๐ธ. On each packet from the protected endpoint, the outer IP header contains the source IP address tied to its current location (the address that will get traffic routed to the endpoint directly). The inner IP header contains the source IP address assigned by the security gateway (the address that will get traffic routed to the security gateway for forwarding to the endpoint). The outer destination address is always the security gateway's, while the inner destination address is the packet's ultimate destination ๐ .
In this scenario, the protected endpoint may be behind a NAT. When it is, the IP address the security gateway sees won't be the same as the one the protected endpoint sent, and the packets have to be UDP encapsulated to be routed properly ๐ญ. Interaction with NATs is covered in detail in Section 2.23 ๐.
1.1.4. Other Scenarios
There are other scenarios too, plus nested combinations of the ones above ๐. One notable example mixes parts of Sections 1.1.1 and 1.1.3. A subnet can route all of its external access through a remote security gateway using an IPsec tunnel, while the rest of the Internet routes to the subnet's addresses ๐. For example, someone's home network can be virtually on the Internet with static IP addresses, even though their connection comes from an ISP that gives the user's security gateway a single dynamically assigned IP address. The static IP addresses and an IPsec relay are provided by a third party located elsewhere ๐.
1.2. The Initial Exchanges โจ
Okay so IKE conversations always kick off with the IKE_SA_INIT and IKE_AUTH exchanges (back in IKEv1 these were called Phase 1) ๐ธ. Usually that's four messages, but in some setups the count can grow ๐. Every IKE conversation is just request/response pairs, going back and forth ๐ซถ. We'll do the base exchange first and then the variations. The first pair, IKE_SA_INIT, is where they agree on crypto algorithms, swap nonces, and do a Diffie-Hellman exchange [DH] ๐.
The second pair, IKE_AUTH, is where things get real ๐ญ. It authenticates the earlier messages, swaps identities and certificates, and sets up the first Child SA. Parts of these messages are encrypted and integrity protected with keys from IKE_SA_INIT, so eavesdroppers can't see the identities and every field in every message gets authenticated ๐ . See Section 2.14 for how those encryption keys get generated. (A man-in-the-middle who can't finish IKE_AUTH can still see the initiator's identity ๐.)
Everything after the initial exchange is cryptographically protected with the algorithms and keys negotiated in IKE_SA_INIT ๐ฆ. These later messages use the Encrypted payload syntax from Section 3.14, encrypted with keys derived as described in Section 2.14. Every later message includes an Encrypted payload, even when the text calls it "empty" ๐. For CREATE_CHILD_SA, IKE_AUTH, or INFORMATIONAL exchanges, the message after the header is encrypted, and the message including the header is integrity protected using the algorithms negotiated for the IKE SA ๐ฅ.
Every IKE message has a Message ID in its fixed header ๐. That's how requests and responses get matched up, and how retransmissions get spotted ๐.
Here are the payload names we'll be using in the descriptions below ๐:
Notation Payload
-----------------------------------------
AUTH Authentication
CERT Certificate
CERTREQ Certificate Request
CP Configuration
D Delete
EAP Extensible Authentication
HDR IKE header (not a payload)
IDi Identification - Initiator
IDr Identification - Responder
KE Key Exchange
Ni, Nr Nonce
N Notify
SA Security Association
SK Encrypted and Authenticated
TSi Traffic Selector - Initiator
TSr Traffic Selector - Responder
V Vendor ID
The details of what goes in each payload are in Section 3. Payloads that may optionally show up are wrapped in brackets, like [CERTREQ], which means a Certificate Request payload can optionally be included ๐ง.
Here's how the initial exchanges go ๐:
Initiator Responder
-------------------------------------------------------------------
HDR, SAi1, KEi, Ni -->
HDR carries the Security Parameter Indexes (SPIs), version numbers, Exchange Type, Message ID, and assorted flags ๐ท๏ธ. 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 one cryptographic suite from the initiator's options and states that choice in SAr1 ๐ฏ. It finishes the Diffie-Hellman exchange with KEr and sends its nonce in Nr ๐.
At this point, each party can work out a value called SKEYSEED (see Section 2.14), and every key for that IKE SA gets derived from it ๐๏ธ. The messages that follow are encrypted and integrity protected in their entirety, except for the message headers โจ. The keys used for encryption and integrity protection come from SKEYSEED and are called SK_e (encryption) and SK_a (authentication, a.k.a. integrity protection). See Sections 2.13 and 2.14 for the details of key derivation. Each direction gets its own SK_e and SK_a ๐. On top of the SK_e and SK_a derived from the Diffie-Hellman value for protecting the IKE SA, there's another value, SK_d, which is used to derive more 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 announces who it is with the IDi payload, proves it knows the secret tied to IDi, and protects the first message's contents with the AUTH payload (see Section 2.15) ๐ก๏ธ. It can also send its certificate(s) in CERT payload(s) and a list of 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. That's non-negotiable, bestie ๐ซ.
The optional IDr payload lets the initiator say which of the responder's identities it wants to talk to ๐ญ. This is handy when one machine is hosting multiple identities at the same IP address. If the responder doesn't accept the IDr the initiator proposed, the responder might use some other IDr to finish the exchange. If the initiator then doesn't accept that the responder used a different IDr than the one requested, the initiator can close the SA once it notices ๐ช.
The Traffic Selectors (TSi and TSr) are discussed in Section 2.9 ๐ฆ. The initiator starts negotiating a Child SA with the SAi2 payload. The remaining fields (starting with SAi2) are described under the CREATE_CHILD_SA exchange ๐งฉ.
<-- HDR, SK {IDr, [CERT,] AUTH,
SAr2, TSi, TSr}
The responder announces its identity with the IDr payload and 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 under the CREATE_CHILD_SA exchange ๐. Both parties in the IKE_AUTH exchange MUST verify that all signatures and Message Authentication Codes (MACs) are computed correctly ๐. If either side uses a shared secret for authentication, the names in the ID payload MUST correspond to the key used to generate the AUTH payload ๐.
Here's the tricky bit ๐ฌ. Since the initiator sends its Diffie-Hellman value in IKE_SA_INIT, it has to guess which Diffie-Hellman group the responder will pick from its list of supported groups ๐ฒ. If the guess is wrong, the responder replies with a Notify payload of type INVALID_KE_PAYLOAD that names the group it selected. In that case, the initiator MUST retry IKE_SA_INIT with the corrected Diffie-Hellman group ๐. The initiator MUST again propose its full set of acceptable cryptographic suites, because that rejection message wasn't authenticated. Otherwise an active attacker could trick both endpoints into negotiating a weaker suite instead of a stronger one they both prefer ๐จ.
If creating the Child SA during the IKE_AUTH exchange fails for some reason, the IKE SA still gets created as usual. The Notify message types in the IKE_AUTH exchange that don't stop an IKE SA from being set up include at least the following: NO_PROPOSAL_CHOSEN, TS_UNACCEPTABLE, SINGLE_PAIR_REQUIRED, INTERNAL_ADDRESS_FAILURE, and FAILED_CP_REQUIRED ๐.
If the failure is about creating the IKE SA itself (for example, an AUTHENTICATION_FAILED Notify error message comes back), then the IKE SA is not created ๐ . Heads up though: even though IKE_AUTH messages are encrypted and integrity protected, if the peer receiving this Notify error hasn't authenticated the other end yet (or fails to for some reason), it has to treat the information with caution โ ๏ธ. More precisely, assuming the MAC verifies correctly, the sender of the error Notify is known to be the responder of the IKE_SA_INIT exchange, but its identity can't be assured ๐คท.
Also, IKE_AUTH messages don't contain KEi/KEr or Ni/Nr payloads ๐. So the SA payloads in the IKE_AUTH exchange can't contain Transform Type 4 (Diffie-Hellman group) with any value other than NONE. Implementations SHOULD omit the whole transform substructure instead of sending the value NONE ๐งน.
1.3. The CREATE_CHILD_SA Exchange ๐ผ
The CREATE_CHILD_SA exchange is used to create new Child SAs and to rekey both IKE SAs and Child SAs ๐. It's a single request/response pair, and some of what it does used to be called a Phase 2 exchange in IKEv1 ๐ญ. It MAY be initiated by either end of the IKE SA once the initial exchanges are done ๐ค.
Rekeying an SA means creating a new SA and then deleting the old one ๐๏ธ. This section covers the first part, creating the new SAs. Section 2.8 covers the mechanics, like moving traffic from the old SAs to the new ones and deleting the old SAs. You have to read the two sections together to get the whole rekeying picture ๐.
Either endpoint can start a CREATE_CHILD_SA exchange, so in this section "initiator" just means whoever started this exchange ๐ฌ. An implementation MAY refuse all CREATE_CHILD_SA requests within an IKE SA ๐ โโ๏ธ.
The CREATE_CHILD_SA request MAY optionally contain a KE payload for an extra Diffie-Hellman exchange, which gives stronger forward secrecy guarantees for the Child SA ๐โจ. The Child SA's keying material is derived from SK_d (established when the IKE SA was set up), the nonces exchanged during CREATE_CHILD_SA, and the Diffie-Hellman value if KE payloads are included ๐งช.
If a CREATE_CHILD_SA exchange includes a KEi payload, at least one of the SA offers MUST include the Diffie-Hellman group of the KEi ๐. The Diffie-Hellman group of the KEi MUST be an element of the group the initiator expects the responder to accept (the initiator can propose additional Diffie-Hellman groups too) ๐ซ. If the responder picks a proposal using a different Diffie-Hellman group (other than NONE), the responder MUST reject the request and name its preferred group in the INVALID_KE_PAYLOAD Notify payload ๐ซ. That notification carries two octets of data: the accepted Diffie-Hellman group number, in big endian order ๐ข. When that happens, the CREATE_CHILD_SA exchange fails, and the initiator will probably retry with a Diffie-Hellman proposal and a KEi in the group the responder gave in INVALID_KE_PAYLOAD ๐.
The responder sends a NO_ADDITIONAL_SAS notification to say that a CREATE_CHILD_SA request is unacceptable because it won't accept any more Child SAs on this IKE SA ๐ . This notification can also be used to reject an IKE SA rekey ๐. Some minimal implementations only accept a single Child SA setup during the initial IKE exchange and reject any later attempts to add more ๐งธ.
1.3.1. Creating New Child SAs with the CREATE_CHILD_SA Exchange โจ
okay so a Child SA can be made by sending a CREATE_CHILD_SA request ๐ here's what that looks like:
Initiator Responder
-------------------------------------------------------------------
HDR, SK {SA, Ni, [KEi,]
TSi, TSr} -->
the initiator sends its SA offer(s) in the SA payload, a nonce in the Ni payload, optionally a Diffie-Hellman value in the KEi payload, and the proposed Traffic Selectors for the new Child SA in the TSi and TSr payloads ๐
and the response is giving:
<-- HDR, SK {SA, Nr, [KEr,]
TSi, TSr}
the responder replies (using the same Message ID to respond) with the accepted offer in an SA payload, a nonce in the Nr payload, and a Diffie-Hellman value in the KEr payload if KEi was included in the request and the selected cryptographic suite includes that group ๐ฆ
the Traffic Selectors for traffic that will go over that SA are set in the TS payloads in the response, and they might be a subset of what the initiator asked for. so not every wish gets granted ๐
the USE_TRANSPORT_MODE notification MAY be included in a request that also has an SA payload asking for a Child SA. it's basically asking for transport mode instead of tunnel mode for the SA being made ๐ง if the request is accepted, the response MUST also include a notification of type USE_TRANSPORT_MODE. if the responder says no, the Child SA gets set up in tunnel mode anyway. if that's a dealbreaker for the initiator, the initiator MUST delete the SA ๐ note: unless you're using this option to negotiate transport mode, every Child SA is going to use tunnel mode, no cap ๐ธ
the ESP_TFC_PADDING_NOT_SUPPORTED notification says the sending endpoint won't accept packets with Traffic Flow Confidentiality (TFC) padding over the Child SA being negotiated. if neither endpoint takes TFC padding, this notification shows up in both the request and the response. if it's only in one of them, TFC padding can still be sent in the other direction โจ
the NON_FIRST_FRAGMENTS_ALSO notification is for fragmentation control. check [IPSECARCH] if you want the full tea โ both parties have to agree before either one sends non-first fragments. it's only turned on if NON_FIRST_FRAGMENTS_ALSO is in both the request proposing the SA and the response accepting it. if the responder doesn't want to send or receive non-first fragments, it just leaves NON_FIRST_FRAGMENTS_ALSO out of its response, and it doesn't reject the whole Child SA creation ๐ซถ
an IPCOMP_SUPPORTED notification, which we cover in Section 2.22, can also be included in this exchange ๐
a failed attempt to create a Child SA SHOULD NOT tear down the IKE SA. there's zero reason to throw away all the work that went into setting up the IKE SA ๐ญ Section 2.21 has a list of the error messages that might pop up if creating a Child SA fails.
1.3.2. Rekeying IKE SAs with the CREATE_CHILD_SA Exchange ๐
this is the CREATE_CHILD_SA request for rekeying an IKE SA:
Initiator Responder
-------------------------------------------------------------------
HDR, SK {SA, Ni, KEi} -->
the initiator sends SA offer(s) in the SA payload, a nonce in the Ni payload, and a Diffie-Hellman value in the KEi payload. the KEi payload MUST be included ๐ a new initiator SPI goes in the SPI field of the SA payload. once a peer gets a request to rekey an IKE SA, or sends one, it SHOULD NOT start any new CREATE_CHILD_SA exchanges on the IKE SA that's being rekeyed. no side quests during the glow-up ๐
the response to rekeying an IKE SA looks like this:
<-- HDR, SK {SA, Nr, KEr}
the responder replies (using the same Message ID to respond) with the accepted offer in an SA payload, a nonce in the Nr payload, and a Diffie-Hellman value in the KEr payload if the selected cryptographic suite includes that group. a new responder SPI goes in the SPI field of the SA payload โจ
the new IKE SA resets its message counters to 0, no matter what they were on the old one. the first IKE requests from both sides on the new IKE SA will have Message ID 0. the old IKE SA keeps its numbering, so any later requests (like deleting the IKE SA) will have consecutive numbers ๐ the new IKE SA also resets its window size to 1, and the initiator of this rekey exchange becomes the new "original initiator" of the new IKE SA. main character energy, literally ๐
Section 2.18 also covers IKE SA rekeying in detail ๐ฆ
1.3.3. Rekeying Child SAs with the CREATE_CHILD_SA Exchange ๐
this is the CREATE_CHILD_SA request for rekeying a Child SA:
Initiator Responder
-------------------------------------------------------------------
HDR, SK {N(REKEY_SA), SA, Ni, [KEi,]
TSi, TSr} -->
the initiator sends SA offer(s) in the SA payload, a nonce in the Ni payload, optionally a Diffie-Hellman value in the KEi payload, and the proposed Traffic Selectors for the new Child SA in the TSi and TSr payloads ๐ง
the notifications from Section 1.3.1 can also show up in a rekeying exchange. usually they're the same ones that were used in the original exchange. like, when you rekey a transport mode SA, the USE_TRANSPORT_MODE notification gets used again ๐
the REKEY_SA notification MUST be included in a CREATE_CHILD_SA exchange if the whole point of the exchange is to replace an existing ESP or AH SA ๐ฅ the SA being rekeyed is identified by the SPI field in the Notify payload. it's the SPI the exchange initiator would expect to see in inbound ESP or AH packets. there's no data attached to this Notify message type. the Protocol ID field of the REKEY_SA notification is set to match the protocol of the SA we're rekeying, so 3 for ESP and 2 for AH ๐
the response for rekeying a Child SA looks like this:
<-- HDR, SK {SA, Nr, [KEr,]
TSi, TSr}
the responder replies (using the same Message ID to respond) with the accepted offer in an SA payload, a nonce in the Nr payload, and a Diffie-Hellman value in the KEr payload if KEi was included in the request and the selected cryptographic suite includes that group ๐ซถ
the Traffic Selectors for traffic that will go over that SA are set in the TS payloads in the response. they might be a subset of what the Child SA initiator proposed ๐ธ
1.4. The INFORMATIONAL Exchange ๐
sometimes during an IKE SA, peers want to send each other control messages about errors or about certain events. so IKE defines an INFORMATIONAL exchange for exactly that ๐ซถ INFORMATIONAL exchanges MUST ONLY happen after the initial exchanges, and they're cryptographically protected with the negotiated keys. some informational messages (not exchanges) can be sent outside the context of an IKE SA, so keep that in mind. Section 2.21 also covers error messages in great detail ๐
control messages 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 rekeyed) ๐
messages in an INFORMATIONAL exchange can contain zero or more Notification, Delete, and Configuration payloads. the recipient of an INFORMATIONAL exchange request MUST send some kind of response, or else the sender will think the message got lost in the network and resend it ๐ญ that response MAY be an empty message. the request message 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 ๐
the INFORMATIONAL exchange looks like this:
Initiator Responder
-------------------------------------------------------------------
HDR, SK {[N,] [D,]
[CP,] ...} -->
<-- HDR, SK {[N,] [D,]
[CP,] ...}
how an INFORMATIONAL exchange gets processed depends on its component payloads โจ
1.4.1. Deleting an SA with INFORMATIONAL Exchanges ๐๏ธ
ESP and AH SAs always come in pairs, with one SA in each direction ๐ฏ when an SA is closed, both members of the pair MUST be closed (meaning deleted). 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 (the ones you'd expect in the headers of inbound packets) of the SAs to delete. the recipient MUST close the designated SAs. one thing to remember: you never send Delete payloads for both sides of an SA in a single message. if there are a bunch of SAs to delete at once, put in Delete payloads for the inbound half of each SA pair in the INFORMATIONAL exchange ๐
usually, the response in the INFORMATIONAL exchange will have Delete payloads for the paired SAs going the other way. there's one exception, though ๐ if, by chance, both ends independently decide to close a set of SAs, each side might send a Delete payload and the two requests could cross paths 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, because that would mean deleting things twice and could, in theory, delete the wrong SA ๐
IKE SAs get deleted the same way, by sending an INFORMATIONAL exchange. deleting an IKE SA implicitly closes any Child SAs still negotiated under it ๐งน the response to a request that deletes the IKE SA is an empty INFORMATIONAL response โจ
half-closed ESP or AH connections are anomalous ๐ฉ a node with auditing capability should probably audit them if they stick around. this specification doesn't set 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 it MUST NOT unilaterally close them and reuse the SPIs. if connection state gets sufficiently messed up, a node MAY close the IKE SA, as described above. then it can rebuild the SAs it needs on a clean base under a new IKE SA ๐ท
1.5. Informational Messages outside of an IKE SA โจ
okay so sometimes a node gets a packet it literally can't process, but it still might wanna tell the sender what's up ๐ซถ
- if an ESP or AH packet shows up with an unrecognized SPI ๐ this might happen because the receiving node recently crashed and lost its state ๐, or because of some other system malfunction or attack
- if an encrypted IKE request packet arrives on port
500or4500with an unrecognized IKE SPI, same energy: maybe a recent crash that wiped its state, or some other malfunction or attack ๐ญ - if an IKE request packet arrives with a higher major version number than the implementation supports ๐
In the first case, if the receiving node has an active IKE SA to the IP address the packet came from, it MAY send an INVALID_SPI notification about the wayward packet over that IKE SA, in an INFORMATIONAL exchange ๐ฆ The Notification Data carries the SPI of the invalid packet. The recipient can't tell whether that SPI is for AH or ESP, but that's not a big deal, because in lots of cases the SPIs will be different for the two ๐ธ
If there's no suitable IKE SA, the node MAY send an informational message without cryptographic protection to the source IP address ๐ฎ It uses the source UDP port as the destination port if the packet was UDP (UDP-encapsulated ESP or AH). But the recipient should only treat it as a hint that something might be wrong, because anyone could easily forge it ๐ต๏ธโโ๏ธ
This message isn't part of an INFORMATIONAL exchange, and the receiving node MUST NOT respond to it, because replying could start a message loop ๐ Here's how it's built. There are no IKE SPI values that would mean anything to the recipient, so zero values or random values are both fine. This is the one exception to the Section 3.1 rule that prohibits zero IKE Initiator SPIs ๐ The Initiator flag is set to 1, the Response flag is set to 0, and the version flags are set in the normal fashion. You can read about those flags in Section 3.1 ๐
In the second and third cases, the message always gets sent without cryptographic protection (outside of an IKE SA) ๐ It includes either an INVALID_IKE_SPI or an INVALID_MAJOR_VERSION notification, with no notification data. It's a response message, so it goes back to the IP address and port it came from, with the same IKE SPIs. The Message ID and Exchange Type get copied from the request. The Response flag is set to 1, and the version flags are set in the normal fashion โจ
1.6. Requirements Terminology ๐
The primitive terms in this document (like Security Association or SA) are defined in [IPSECARCH], so go check there if you're lost ๐ง It's worth noting that parts of IKEv2 rely on some of the processing rules in [IPSECARCH], and this document points those out in various sections ๐
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [MUSTSHOULD] ๐
1.7. Significant Differences between RFC 4306 and RFC 5996 ๐
This document is full of clarifications and amplifications to IKEv2 [IKEV2] ๐ซถ A lot of those clarifications come from [Clarif]. The changes listed there were discussed in the IPsec Working Group and, after the Working Group was disbanded, on the IPsec mailing list ๐ That document goes deep on the areas of IKEv2 that were unclear, so it's super useful for implementers ๐ค
The protocol here keeps the same major version number (2) and minor version number (0) that RFC 4306 used. So the version number is not changed from RFC 4306 ๐ The small number of technical changes listed here aren't expected to affect RFC 4306 implementations that were already deployed when this document was published ๐
This document also makes the figures and references a bit more consistent than they were in [IKEV2] โจ
IKEv2 developers noticed that the SHOULD-level requirements in RFC 4306 are often unclear, because they don't say when it's OK to not obey them ๐ They also noticed some MUST-level requirements that have nothing to do with interoperability ๐ญ This document explains some of those requirements a bit more. All non-capitalized uses of the words SHOULD and MUST now mean their normal English sense, not the interoperability sense from [MUSTSHOULD] ๐
IKEv2 (and IKEv1) developers also pointed out that there's a ton of stuff in the tables of codes in Section 3.10.1 of RFC 4306. That meant implementers didn't have all the info they needed in the main body of the document ๐ So much of that material has been moved into the matching parts of the main body ๐ฆ
This document removes the discussion of nesting AH and ESP. That was a mistake in RFC 4306, caused by the lag between finishing RFC 4306 and RFC 4301 ๐ฅฒ Basically, IKEv2 is based on RFC 4301, which doesn't include the "SA bundles" that were part of RFC 2401. A single packet can still go through IPsec processing multiple times, but each pass uses its own SA, and the passes get coordinated by the forwarding tables. In IKEv2, each of those SAs has to be created with its own separate CREATE_CHILD_SA exchange ๐งฉ
This document removes the INTERNAL_ADDRESS_EXPIRY configuration attribute, because implementing it was seriously problematic ๐ Implementations that conform to this document MUST ignore proposals that have configuration attribute type 5, which was the old value for INTERNAL_ADDRESS_EXPIRY. This document also removed INTERNAL_IP6_NBNS as a configuration attribute ๐๏ธ
This document also removes the allowance for rejecting messages whose payloads weren't in the "right" order. Now implementations MUST NOT reject them ๐ โโ๏ธ That's because it was never clear where the payload orders were described, so it was kinda unfair to reject people for it ๐ฅบ
The lists of items from RFC 4306 that ended up in the IANA registry got trimmed down to only include items that were actually defined in RFC 4306 ๐ Also, a lot of those lists now start with a very important reminder for developers: they really should look at the IANA registry at development time, because new items have been added since RFC 4306 ๐๐ฅ
This document also clarifies when notifications are and aren't sent encrypted, depending on where the negotiation is at that moment ๐ It also goes further into how to negotiate combined-mode ciphers ๐
In Section 1.3.2, "The KEi payload SHOULD be included" was changed to "The KEi payload MUST be included". That change also led to edits in Section 2.18 ๐ธ
In Section 2.1, there's new material covering how the initiator's SPI and/or IP gets used to tell whether this is a "half-open" IKE SA or a brand new request ๐
This document clarifies how the critical flag is used in Section 2.5 ๐ซง
In Section 2.8, "Note that, when rekeying, the new Child SA MAY have different Traffic Selectors and algorithms than the old one" was changed to "Note that, when rekeying, the new Child SA SHOULD NOT have different Traffic Selectors and algorithms than the old one" ๐ The new Section 2.8.2 covers simultaneous IKE SA rekeying ๐ฆ
This document adds the restriction in Section 2.13 that all pseudorandom functions (PRFs) used with IKEv2 MUST take variable-sized keys. This shouldn't affect any implementations, because there were no standardized PRFs with fixed-size keys anyway ๐ฐ
Section 2.18 requires doing a Diffie-Hellman exchange when rekeying the IKE_SA ๐ In theory, RFC 4306 allowed a policy where the Diffie-Hellman exchange was optional, but that wasn't useful (or appropriate) when rekeying the IKE_SA ๐
Section 2.21 got a major glow-up ๐ซ It's been greatly expanded to cover the different cases where error responses are needed, and the right responses to them ๐
Section 2.23 clarified that, for NAT traversal, both UDP-encapsulated IPsec packets and non-UDP-encapsulated IPsec packets now need to be understood when receiving ๐ Added Section 2.23.1 describes NAT traversal when transport mode is requested ๐
Added Section 2.25, which explains how to act when there are timing collisions while deleting and/or rekeying SAs ๐ฅ It also defines two new error notifications: TEMPORARY_FAILURE and CHILD_SA_NOT_FOUND ๐ฅน
In Section 3.6, "Implementations MUST support the "http:" scheme for hash-and-URL lookup. The behavior of other URL schemes is not currently specified, and such schemes SHOULD NOT be used in the absence of a document specifying them" was added ๐
In Section 3.15.3, there's now a pointer to a new document about configuring IPv6 addresses ๐
Appendix C got expanded and clarified ๐โจ
1.8. Differences between RFC 5996 and This Document ๐
This document now clarifies, in the Abstract and the Introduction, that its status is Internet Standard ๐
The new Section 2.9.2 covers Traffic Selectors in rekeying ๐ซถ
Added a reference to RFC 6989 for reusing Diffie-Hellman exponentials (Section 2.12) ๐ง
Added the name "Last Substruc" for the Proposal Substructure and Transform Substructure headers (Sections 3.3.1 and 3.3.2), covering the 0 (last) or 2/3 (more) field ๐ท๏ธ
Added a reference to RFC 6989 for using groups that aren't Sophie Germain Modular Exponentiation (MODP) groups (Section 3.3.2) ๐
Added a reference to RFC 4945 in the Identification Payloads section (Section 3.5) ๐
Deprecated Raw RSA public keys in Section 3.6 ๐ชฆ There's new work in progress adding a more generic format for raw public keys ๐
Fixed Sections 3.6 and 3.10 as specified in the errata for RFC 5996 (RFC Errata IDs 2707 and 3036) ๐ ๏ธ
Added a note in the IANA Considerations section (Section 6) about deprecating the Raw RSA Key, and removed the old contents (which was already done during RFC 5996 processing) ๐งน There's also a note that IANA should update all references to RFC 5996 so they point to this document ๐
2. IKE Protocol Details and Variations โจ
okay so IKE normally listens and sends on UDP port 500 ๐, but IKE messages can also show up on UDP port 4500 with a slightly different format (see Section 2.23). UDP is a datagram protocol, which means it's unreliable, so 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 when those minimum performance requirements aren't met, IKE is designed to fail cleanly, as though the network were broken ๐ซถ.
IKEv2 messages are meant to be short, but they contain structures with no hard upper bound on size (digital certificates, I'm looking at you ๐), and IKEv2 itself has no mechanism for fragmenting large messages. IP does define a way to fragment oversized UDP messages, but implementations vary in the maximum message size they support ๐. Using IP fragmentation also opens an implementation up to denial-of-service (DoS) attacks [DOSUDPPROT] ๐. And finally, some NAT and/or firewall implementations may block IP fragments, so that's a whole vibe to watch out for ๐ซ.
All IKEv2 implementations MUST be able to send, receive, and process IKE messages that are up to 1280 octets long ๐ธ, and they SHOULD be able to send, receive, and process messages that are up to 3000 octets long โจ. IKEv2 implementations need to be aware of the maximum UDP message size they support, and they MAY shorten messages by leaving out some certificates or cryptographic suite proposals if that keeps messages below the maximum ๐ฆ. Using the "Hash and URL" formats instead of including certificates in exchanges where possible can avoid most problems ๐ง. Implementations and configuration need to keep in mind, however, that if the URL lookups are only possible after the Child SA is established, recursion issues could stop this technique from working ๐ตโ๐ซ.
The UDP payload of all packets containing IKE messages sent on port 4500 MUST begin with the prefix of four zeros, otherwise the receiver won't know how to handle them ๐จ.
2.1. Use of Retransmission Timers
All messages in IKE exist in pairs: a request and a response ๐. The setup of an IKE SA normally consists of two exchanges. Once the IKE SA is set up, either end of the Security Association can initiate requests at any time, and there can be many requests and responses "in flight" at any given moment ๐. But every message is labeled as either a request or a response, and for each exchange, one end of the Security Association is the initiator and the other is the responder โญ.
For every pair of IKE messages, the initiator is responsible for retransmission when 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 insofar as it causes a retransmission of the response ๐. The initiator MUST remember each request until it receives the corresponding response. The responder MUST remember each response until it receives a request whose sequence number is larger than or equal to the sequence number in the response plus its window size (see Section 2.3) ๐. To save memory, responders are allowed to forget the response after a timeout of several minutes. If the responder receives a retransmitted request for which it has already forgotten the response, it MUST ignore the request (and not, for example, attempt constructing a new response) ๐ .
IKE is a reliable protocol: the initiator MUST retransmit a request until it either receives a corresponding response or deems the IKE SA to have failed ๐ซถ. In the latter case, the initiator discards all state associated with the IKE SA and any Child SAs that were negotiated using that IKE SA ๐. A retransmission from the initiator MUST be bitwise identical to the original request. That means everything starting from the IKE header (the IKE SA initiator's SPI onwards) MUST be bitwise identical, while items before it (such as the IP and UDP headers) do not have to be identical ๐.
Retransmissions of the IKE_SA_INIT request need some special handling ๐ง. When a responder receives an IKE_SA_INIT request, it has to figure out whether the packet is a retransmission belonging to an existing "half-open" IKE SA (in which case the responder retransmits the same response), or a new request (in which case the responder creates a new IKE SA and sends a fresh response), or whether it belongs to an existing IKE SA where the IKE_AUTH request has already been received (in which case the responder ignores it) ๐ธ.
Using the initiator's SPI and/or IP address to tell these three cases apart is NOT enough, because two different peers behind a single NAT could choose the same initiator SPI ๐ฌ. Instead, a robust responder will do the IKE SA lookup using the whole packet, its hash, or the Ni payload ๐ง .
The retransmission policy for one-way messages is a bit different from the one for regular messages โจ. Because no acknowledgement is ever sent, there's no reason to gratuitously retransmit one-way messages. Since all these messages are errors, it makes sense to send them only once per "offending" packet, and to only retransmit if further offending packets are received ๐ฆ. Still, it also makes sense to limit retransmissions of such error messages ๐.
2.2. Use of Sequence Numbers for Message ID
Every IKE message contains a Message ID as part of its fixed header ๐ง. This Message ID is used to match up requests and responses and to identify retransmissions of messages. Retransmission of a message MUST use the same Message ID as the original message ๐.
The Message ID is a 32-bit quantity, which is zero for the IKE_SA_INIT messages (including retries of the message due to responses such as COOKIE and INVALID_KE_PAYLOAD), and it gets incremented for each subsequent exchange ๐. So the first pair of IKE_AUTH messages will have an ID of 1, the second (when EAP is used) will be 2, and so on ๐ข. The Message ID is reset to zero in the new IKE SA after the IKE SA is rekeyed ๐.
Each endpoint in the IKE Security Association maintains two "current" Message IDs: the next one to be used for a request it initiates, and the next one it expects to see in a request from the other end ๐ซถ. These counters increment as requests are generated and received. Responses always contain the same Message ID as the corresponding request ๐. That means that after the initial exchange, each integer n may appear as the Message ID in four distinct messages: the nth request from the original IKE initiator, the corresponding response, the nth request from the original IKE responder, and the corresponding response ๐ตโ๐ซ. If the two ends make a very different number of requests, the Message IDs in the two directions can be very different ๐. There's no ambiguity in the messages though, because the Initiator and Response flags in the message header specify which of the four messages a particular one is ๐ฏ.
Throughout this document, "initiator" refers to the party who initiated the exchange being described. The "original initiator" always refers to the party who initiated the exchange that resulted in the current IKE SA. In other words, if the "original responder" starts rekeying the IKE SA, that party becomes the "original initiator" of the new IKE SA ๐.
Note that Message IDs are cryptographically protected and provide protection against message replays ๐. In the unlikely event that Message IDs grow too large to fit in 32 bits, the IKE SA MUST be closed or rekeyed ๐ช.
2.3. Window Size for Overlapping Requests
The SET_WINDOW_SIZE notification asserts that the sending endpoint is capable of keeping state for multiple outstanding exchanges, which lets the recipient send multiple requests before getting a response to the first one ๐ช. The data associated with a SET_WINDOW_SIZE notification MUST be 4 octets long and contain the big endian representation of the number of messages the sender promises to keep ๐ข. The window size is always one until the initial exchanges complete ๐ฑ.
An IKE endpoint MUST wait for a response to each of its messages before sending a subsequent message, unless it has received a SET_WINDOW_SIZE Notify message from its peer informing it that the peer is prepared to maintain state for multiple outstanding messages in order to allow greater throughput ๐.
After an IKE SA is set up, to maximize IKE throughput, an IKE endpoint MAY issue multiple requests before getting a response to any of them, up to the limit set by its peer's SET_WINDOW_SIZE ๐๏ธ. These requests may pass one another over the network. An IKE endpoint MUST be prepared to accept and process a request while it has a request outstanding, so it can avoid a deadlock in this situation ๐. An IKE endpoint may also accept and process multiple requests while it has a request outstanding ๐.
An IKE endpoint MUST NOT exceed the peer's stated window size for transmitted IKE requests. In other words, if the responder stated its window size is N, then when the initiator needs to make a request X, it MUST wait until it has received responses to all requests up through request X-N ๐งฎ. An IKE endpoint MUST keep a copy of (or be able to regenerate exactly) each request it has sent until it receives the corresponding response ๐. An IKE endpoint MUST also keep a copy of (or be able to regenerate exactly) the number of previous responses equal to its declared window size, in case its response was lost and the initiator requests its retransmission by retransmitting the request ๐๏ธ.
An IKE endpoint supporting a window size greater than one ought to be capable of processing incoming requests out of order, to maximize performance in the event of network failures or packet reordering ๐.
The window size is normally a (possibly configurable) property of a particular implementation, and it is not related to congestion control (unlike the window size in TCP, for example) ๐
โโ๏ธ. In particular, what the responder should do when it receives a SET_WINDOW_SIZE notification containing a smaller value than is currently in effect is not defined ๐คทโโ๏ธ. Thus, there is currently no way to reduce the window size of an existing IKE SA; you can only increase it โฌ๏ธ. When rekeying an IKE SA, the new IKE SA starts with window size 1 until it is explicitly increased by sending a new SET_WINDOW_SIZE notification ๐ท.
The INVALID_MESSAGE_ID notification is sent when an IKE Message ID outside the supported window is received ๐ซ. This Notify message MUST NOT be sent in a response, and the invalid request MUST NOT be acknowledged ๐. Instead, inform the other side by initiating an INFORMATIONAL exchange with Notification Data containing the four-octet invalid Message ID ๐ฃ. Sending this notification is OPTIONAL, and notifications of this type MUST be rate limited ๐ข.
2.4. State Synchronization and Connection Timeouts โจ
okay bestie so an IKE endpoint is totally allowed to forget everything it knows about an IKE SA and all of its Child SAs at any time ๐ that's the expected move if an endpoint crashes and restarts. it's highkey important that when one side fails or resets, the other side actually notices, or else it keeps wasting bandwidth sending packets into SAs that got tossed and everything just falls into a black hole ๐ณ๏ธ๐
The INITIAL_CONTACT notification says "this is the only IKE SA active between these authenticated identities" ๐ It MAY be sent when an IKE SA is set up after a crash, and the recipient MAY use that info to delete any other IKE SAs it has to the same authenticated identity without waiting for a timeout. It MUST NOT be sent by an entity that may be replicated ๐ซ (e.g., a roaming user's credentials where the user is allowed to connect to the corporate firewall from two remote systems at the same time). If it's sent, the INITIAL_CONTACT notification MUST be in the first IKE_AUTH request or response, not as a separate exchange afterwards, and receiving parties MAY ignore it in other messages ๐
Since IKE is built to survive DoS attacks from the network, an endpoint MUST NOT conclude that the other endpoint has failed based on any routing information (e.g., ICMP messages) or IKE messages that arrive without cryptographic protection (e.g., Notify messages complaining about unknown SPIs) ๐
โโ๏ธ An endpoint MUST conclude that the other endpoint has failed only when repeated attempts to contact it have gone unanswered for a timeout period, or when a cryptographically protected INITIAL_CONTACT notification is received on a different IKE SA to the same authenticated identity. An endpoint should suspect that the other endpoint has failed based on routing information and then start a request to see whether the other endpoint is alive ๐ To check if the other side is alive, IKE specifies an empty INFORMATIONAL request that (like all IKE requests) needs 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 (fresh, i.e., not retransmitted) has been received from the other side recently, unprotected Notify messages MAY be ignored โจ Implementations MUST limit the rate at which they take actions based on unprotected messages ๐
The number of retries and length of timeouts aren't covered in this specification, because they don't affect interoperability ๐ฆ It's suggested that messages get retransmitted at least a dozen times over a period of at least several minutes before giving up on an SA, but different environments might need different rules. To be a good network citizen ๐ธ, retransmission times MUST increase exponentially so the network doesn't get flooded and an existing congestion situation doesn't get worse. If there has only been outgoing traffic on all of the SAs associated with an IKE SA, it's essential to confirm the liveness of the other endpoint to avoid black holes. If no cryptographically protected messages have been received on an IKE SA or any of its Child SAs recently, the system needs to do a liveness check so it doesn't keep sending messages to a dead peer ๐ (This is sometimes called "dead peer detection" or "DPD", although it's really detecting live peers, not dead ones ๐) Receiving a fresh cryptographically protected message on an IKE SA or any of its Child SAs ensures liveness of the IKE SA and all of its Child SAs ๐ Note that this puts requirements on the failure modes of an IKE endpoint. An implementation needs to stop sending over any SA if some failure stops it from receiving on all of the associated SAs. If a system creates Child SAs that can fail independently of one another without the associated IKE SA being able to send a delete message, then the system MUST negotiate such Child SAs using separate IKE SAs ๐ฅ
One type of DoS attack on the initiator of an IKE SA can be avoided if the initiator takes proper care ๐ Since the first two messages of an SA setup aren't cryptographically protected, an attacker could respond to the initiator's message before the genuine responder and poison the connection setup attempt. To prevent this, the initiator MAY be willing to accept multiple responses to its first message, treat each response as potentially legitimate, respond to each one, and then discard all the invalid half-open connections when it receives a valid cryptographically protected response to any one of its requests. Once a cryptographically valid response is received, all subsequent responses should be ignored, whether or not they're cryptographically valid ๐ซถ
Note that with these rules, there's no reason to negotiate and agree upon 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 get deleted ๐ญ
An IKE endpoint is allowed to 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 too โฐ Closing the IKE SA implicitly closes all associated Child SAs. In this case, an IKE endpoint SHOULD send a Delete payload saying it has closed the IKE SA, unless the other endpoint is no longer responding ๐
2.5. Version Numbers and Forward Compatibility
okay so this document describes version 2.0 of IKE, meaning the major version number is 2 and the minor version number is 0 ๐ This document replaces [IKEV2]. It's pretty likely that some implementations will want to support version 1.0 and version 2.0, and later on, other versions too ๐
The major version number should only be incremented if the packet formats or required actions have changed so dramatically that an older version node couldn't interoperate with a newer version node by just ignoring the fields it doesn't understand and taking the actions in the older specification ๐ตโ๐ซ The minor version number indicates new capabilities, and it MUST be ignored by a node with a smaller minor version number, but a node with the larger minor version number uses it for informational purposes โจ For example, it might indicate the ability to process a newly defined Notify message type. The node with the larger minor version number would simply note that its correspondent couldn't understand that message, and therefore wouldn't send it ๐ฆ
If an endpoint receives a message with a higher major version number, it MUST drop the message and SHOULD send an unauthenticated Notify message of type INVALID_MAJOR_VERSION containing the highest (closest) version number it supports ๐ซ If an endpoint supports major version n and major version m, it MUST support all versions between n and m. If it receives a message with a major version that it supports, it MUST respond with that version number. To keep two nodes from being tricked into talking on a lower major version than the maximum they both support, IKE has a flag that says the node can speak a higher major version number ๐
So the major version number in the IKE header tells you the version of the message, not the highest version the transmitter supports ๐ Say the initiator can speak versions n, n+1, and n+2, and the responder can speak versions n and n+1. Then they'll negotiate n+1, and the initiator will set a flag saying it can speak a higher version. If they get mixed up (maybe because of an active attacker sending error messages) and negotiate version n, then both will notice the other side can support a higher version number, and they MUST break the connection and reconnect using version n+1 ๐
Note that IKEv1 doesn't follow these rules, because there's no way in v1 to note that you can speak a higher version number ๐ So an active attacker can trick two v2-capable nodes into speaking v1. When a v2-capable node negotiates down to v1, it should note that fact in its logs ๐
Also, for forward compatibility, all fields marked RESERVED MUST be set to zero by an implementation running version 2.0, and their content MUST be ignored by an implementation running version 2.0 ("Be conservative in what you send and liberal in what you receive" [IP]) ๐ท This way, future versions of the protocol can use those fields for something that's guaranteed to be ignored by implementations that don't understand it ๐ง In the same spirit, payload types that aren't defined are reserved for future use. Implementations of a version where they're undefined MUST skip over those payloads and ignore their contents โญ
IKEv2 adds a "critical" flag to each payload header for even more forward-compatibility 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, which says an unsupported critical payload was included ๐
โโ๏ธ In that Notify payload, the Notification Data contains the one-octet payload type. If the critical flag isn't set and the payload type is unsupported, that payload MUST be ignored ๐ซ Payloads sent in IKE response messages MUST NOT have the critical flag set ๐ซ Note that the critical flag only applies to the payload type, not the contents. If the payload type is recognized but the payload contains something that isn't (like an unknown transform inside an SA payload, or an unknown Notify Message Type inside a Notify payload), the critical flag is ignored ๐ฅน
Although new payload types may be added in the future and may show up interleaved with the fields defined in this specification, implementations SHOULD send the payloads defined in this specification in the order shown in the figures in Sections 1 and 2 ๐ But implementations MUST NOT reject as invalid a message with those payloads in any other order ๐ โจ
2.6. IKE SA SPIs and Cookies โจ
okay so the first two eight-octet fields in the header, called the "IKE SPIs" ๐ฆ, work as the connection ID at the start of every IKE packet. Each endpoint picks one of the two SPIs, and it MUST pick them so they're unique IDs for an IKE SA. An SPI value of zero is special bc it means the sender doesn't know the remote SPI yet ๐
Incoming IKE packets get mapped to an IKE SA ONLY by the packet's SPI, not by stuff like the source IP address. ๐
Unlike ESP and AH, where only the recipient's SPI shows up in the header, IKE sends the sender's SPI in every message too ๐ธ The SPI picked by the original initiator of the IKE SA is always sent first, so if an endpoint has a bunch of IKE SAs open and wants to find the right one using the SPI it assigned, it has to check the Initiator flag in the header to figure out whether it assigned the first or the second eight octets. the way that's giving main character energy ๐
In the first message of an initial IKE exchange, the initiator won't know the responder's SPI yet, so it sets that field to zero ๐ง When the IKE_SA_INIT exchange doesn't end up creating an IKE SA because of INVALID_KE_PAYLOAD, NO_PROPOSAL_CHOSEN, or COOKIE, the responder's SPI will also be zero in the response. but if the responder sends a non-zero responder SPI, the initiator should not reject the response for only that reason โจ
Two expected attacks against IKE are state and CPU exhaustion, where the target gets flooded with session initiation requests from forged IP addresses ๐ These attacks get way less effective if a responder uses minimal CPU and doesn't commit any state to an SA until it knows the initiator can receive packets at the address it claims to be sending from. protect yourself bestie ๐ซถ
When a responder detects a large number of half-open IKE SAs, it SHOULD reply to IKE_SA_INIT requests with a response containing the COOKIE notification ๐ The data for this notification MUST be between 1 and 64 octets in length (inclusive), and how it's generated is described later in this section. If the IKE_SA_INIT response includes the COOKIE notification, the initiator MUST then retry the IKE_SA_INIT request, and include the COOKIE notification with the received data as the first payload, with all other payloads unchanged. the 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 change any initiator or responder state, except for passing the cookie around ๐ The message sequence numbers in the first four messages are all zero, and in the last two they're one. 'A' is the SPI the initiator assigned, and 'B' is the SPI the responder assigned ๐
An IKE implementation can do its responder cookie generation in a way that doesn't need any saved state to recognize its valid cookie when the second IKE_SA_INIT message shows up ๐ The exact algorithms and syntax for generating cookies don't affect interoperability, so they aren't specified here. 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 be:
Cookie = <VersionIDofSecret> | Hash(Ni | IPi | SPIi | <secret>)
where <secret> is a randomly generated secret known only to the responder, periodically changed, and | means concatenation. <VersionIDofSecret> should change whenever <secret> gets 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 IPi has to be the same as the source address it saw the first time ๐ฅ Putting SPIi into the calculation makes sure that if multiple IKE SAs are being set up in parallel, they all get different cookies (assuming the initiator picks unique SPIi's). Putting Ni in the hash makes sure an attacker who only sees message 2 can't successfully forge a message 3. Also, including SPIi in the hash stops an attacker from grabbing one cookie from the other end, then starting a bunch of IKE_SA_INIT exchanges all with different initiator SPIs (and maybe port numbers), so the responder thinks there are a lot of machines behind one NAT box all trying to connect ๐ญ
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 forever after <secret> changes, since that would defeat part of the DoS protection. The responder should change the value of <secret> frequently, especially if it's under attack ๐ซ
When one party gets an IKE_SA_INIT request with a cookie whose contents don't match the expected value, that party MUST ignore the cookie and process the message as if no cookie had been included. Usually that means sending a response with a new cookie ๐ The initiator should limit how many cookie exchanges it tries before giving up, possibly using exponential back-off. An attacker can forge multiple cookie responses to the initiator's IKE_SA_INIT message, and each forged cookie reply causes two packets to be sent: one from the initiator to the responder (which will reject those cookies), and one response from the responder to the initiator that includes the correct cookie ๐
A note on terminology: the term "cookies" comes from Karn and Simpson [PHOTURIS] in Photuris, an early proposal for key management with IPsec, and it stuck around ๐ช The Internet Security Association and Key Management Protocol (ISAKMP) [ISAKMP] fixed message header includes two eight-octet fields called "cookies", and that syntax is used by both IKEv1 and IKEv2. In IKEv2, though, they're called the "IKE SPI", and there's a new separate field in a Notify payload that holds the cookie โจ
2.6.1. Interaction of COOKIE and INVALID_KE_PAYLOAD ๐ธ
there are two common reasons the initiator might have to retry the IKE_SA_INIT exchange: the responder asks for a cookie, or it wants a different Diffie-Hellman group than the one in the KEi payload ๐ฅน If the initiator gets a cookie from the responder, it needs to decide whether to include the cookie in only the next retry of the IKE_SA_INIT request, or in all the retries after that too.
If the initiator only includes the cookie in the next retry, one extra round trip might be needed in some cases. An extra round trip is also needed if the initiator includes the cookie in all retries but the responder doesn't support that. For instance, if the responder includes the KEi payloads in the cookie calculation, it'll reject the request by sending a new cookie ๐คทโโ๏ธ
If both peers support including the cookie in all retries, a slightly shorter exchange can happen:
Initiator Responder
-----------------------------------------------------------
HDR(A,0), SAi1, KEi, Ni -->
<-- HDR(A,0), N(COOKIE)
HDR(A,0), N(COOKIE), SAi1, KEi, Ni -->
<-- HDR(A,0), N(INVALID_KE_PAYLOAD)
HDR(A,0), N(COOKIE), SAi1, KEi', Ni -->
<-- HDR(A,B), SAr1, KEr, Nr
Implementations SHOULD support this shorter exchange, but they MUST NOT fail if other implementations don't support it ๐ซถ
2.7. Cryptographic Algorithm Negotiation ๐
okay the payload type called "SA" is basically a proposal for a set of choices of IPsec protocols (IKE, ESP, or AH) for the SA, plus the cryptographic algorithms tied to each protocol ๐
An SA payload is made of one or more proposals. Each proposal includes one protocol. Each protocol has one or more transforms -- each one specifies a cryptographic algorithm. Each transform has zero or more attributes (attributes are only needed if the Transform ID doesn't fully specify the cryptographic algorithm) ๐ฆ
This hierarchy was designed to encode proposals for cryptographic suites efficiently when the number of supported suites is large, since multiple values can be acceptable for multiple transforms ๐ง The responder MUST choose a single suite, which can be any subset of the SA proposal following the rules below ๐
Each proposal contains one protocol. If a proposal gets accepted, the SA response MUST contain the same protocol. The responder MUST accept a single proposal or reject them all and return an error. That error is given in a notification of type NO_PROPOSAL_CHOSEN ๐ญ
Each IPsec protocol proposal contains one or more transforms, and each transform 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 the transforms ENCR_3DES, ENCR_AES w/keysize 128, ENCR_AES w/keysize 256, AUTH_HMAC_MD5, and AUTH_HMAC_SHA, then the accepted suite MUST contain one of the ENCR_ transforms and one of the AUTH_ transforms. Thus, six combinations are acceptable ๐
If an initiator proposes both normal ciphers with integrity protection AND combined-mode ciphers, then two proposals are needed. One proposal includes the normal ciphers with the integrity algorithms for them, and the other includes all the combined-mode ciphers without the integrity algorithms (because combined-mode ciphers aren't allowed to have any integrity algorithm other than "NONE") ๐
2.8. Rekeying โจ
okay so IKE SAs, ESP SAs, and AH SAs all run on secret keys, and those keys are only meant to last a little while and protect a limited amount of data ๐ that's what makes the whole SA's lifetime limited too. once an SA's lifetime runs out, it is MUST NOT used anymore ๐ if there's demand, new SAs MAY be set up to take their place. swapping out an expired SA for a fresh one is what we call "rekeying" ๐ฆ
minimal IPsec implementations don't have to bother with rekeying an SA without restarting the whole IKE SA, so that part is optional ๐ธ an implementation MAY turn down every CREATE_CHILD_SA request inside an IKE SA, no drama. but if an SA has expired or is about to, and the rekeying methods described here don't work, the implementation MUST close the IKE SA along with any Child SAs hanging off it, and then it MAY start new ones ๐ซถ implementations might want to support in-place rekeying too, because it's better for performance and probably means fewer packets get lost during the switch โจ
to rekey a Child SA inside an existing IKE SA, you make a new, equivalent SA (see Section 2.17 below). once that new one is set up, you delete the old one ๐ and heads up: when rekeying, the new Child SA SHOULD NOT have different Traffic Selectors and algorithms than the old one ๐
to rekey an IKE SA, you set up a new equivalent IKE SA (see Section 2.18 below) with the same peer, using a CREATE_CHILD_SA inside the existing IKE SA ๐ the new IKE SA inherits all of the original one's Child SAs, and it's the one used for all the control messages needed to keep those Child SAs running. after the new equivalent IKE SA exists, the initiator deletes the old IKE SA, and the Delete payload that deletes itself MUST be the last request sent over the old IKE SA ๐
SAs should be rekeyed proactively ๐ง that means the new SA gets set up before the old one expires and becomes unusable. there should also be enough time between the new SA being established and the old one going dead so traffic can actually move over to the new one ๐
here's a difference between IKEv1 and IKEv2 that's kind of iconic: in IKEv1, SA lifetimes were negotiated ๐ in IKEv2, each end of the SA is responsible for enforcing its own lifetime policy and rekeying the SA when it's necessary ๐ if the two ends have different lifetime policies, the end with the shorter lifetime will always end up being the one that asks for the rekey โญ if an SA has been inactive for a long time, and an endpoint wouldn't start the SA without traffic, the endpoint MAY choose to close the SA instead of rekeying it when its lifetime runs out. it can also do that if there's been no traffic since the last time the SA got rekeyed ๐
ngl this is kind of a big deal: IKEv2 is intentionally fine with parallel SAs that have the same Traffic Selectors between the same endpoints ๐ one reason is so you can have traffic quality of service (QoS) differences across the SAs (see [DIFFSERVFIELD], [DIFFSERVARCH], and Section 4.1 of [DIFFTUNNEL]). so unlike IKEv1, the combo of endpoints and Traffic Selectors might not uniquely identify an SA between those endpoints. because of that, the IKEv1 rekeying shortcut of deleting SAs based on duplicate Traffic Selectors SHOULD NOT be used ๐
there are timing windows, especially when packets go missing, where the endpoints might not agree on the state of an SA ๐ญ 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 the initiator never gets confused ๐ซถ the initiator MAY start sending on an SA as soon as it processes the response. the initiator, though, can't receive on a newly created SA until it gets and processes the response to its CREATE_CHILD_SA request. so how does the responder know when it's OK to send on the new SA? ๐ค
from a technical correctness and interoperability point of view, 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 mean packets get dropped for no reason, so an implementation MAY 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 other half of the SA pair, 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 keeps sending traffic on the old SA until one of those things happens. when establishing a new SA, the responder MAY hold off on sending messages on the new SA until it either receives one or a timeout happens โจ if an initiator gets a message on an SA it hasn't gotten a response for to its CREATE_CHILD_SA request, it reads that as a likely packet loss and retransmits the CREATE_CHILD_SA request ๐ฆ and an initiator MAY send a dummy ESP message on a newly created ESP SA if it has nothing queued, just to let the responder know it's ready to receive messages ๐ง
2.8.1. Simultaneous Child SA Rekeying
okay so if the two ends have the same lifetime policies, it's totally possible for both of them to start a rekey at the same time, which makes redundant SAs ๐ to lower the odds of that, the timing of rekeying requests SHOULD be jittered (delayed by a random amount of time after the need to rekey gets noticed) ๐
this kind of rekeying can temporarily leave you with multiple similar SAs between the same pairs of nodes ๐ when two SAs are eligible to receive packets, a node MUST accept incoming packets through either SA โจ if redundant SAs get created through a collision like this, the SA created with the lowest of the four nonces used in the two exchanges SHOULD be closed by the endpoint that created it. "Lowest" means an octet-by-octet comparison (instead of, say, comparing the nonces as big integers) ๐ค so you start by comparing the first octet; if they're equal, you move on to the next octet, and so on. if you hit the end of one nonce, that nonce is the lower one ๐ซถ the node that started the surviving rekeyed SA should delete the replaced SA once the new one is set up ๐
here's how this plays out for implementations ๐ฆ say hosts A and B have an existing Child SA pair with SPIs (SPIa1,SPIb1), and both start rekeying it at the same time:
Host A Host B
-------------------------------------------------------------------
send req1: N(REKEY_SA,SPIa1),
SA(..,SPIa2,..),Ni1,.. -->
<-- send req2: N(REKEY_SA,SPIb1),
SA(..,SPIb2,..),Ni2
recv req2 <--
at this point, A knows there's a simultaneous rekeying going on ๐ณ but it can't tell yet which exchange will have the lowest nonce, so it just notes the situation and responds as usual ๐
send resp2: SA(..,SPIa3,..),
Nr1,.. -->
--> recv req1
now B knows about the simultaneous rekeying too ๐ it responds as usual.
<-- send resp1: SA(..,SPIb3,..),
Nr2,..
recv resp1 <--
--> recv resp2
at this point there are three Child SA pairs between A and B (the old one and two new ones) ๐ A and B can now compare the nonces. suppose the lowest nonce was Nr1 in message resp2. then B (the sender of req2) deletes the redundant new SA, and A (the node that started the surviving rekeyed SA) deletes the old one ๐ง
send req3: D(SPIa1) -->
<-- send req4: D(SPIb2)
--> recv req3
<-- send resp3: D(SPIb1)
recv req4 <--
send resp4: D(SPIa3) -->
and just like that, the rekeying is finished โจ๐
but wait, there's a second possible sequence of events if some packets get lost and retransmissions kick in ๐ญ the rekeying starts as usual, but A's first packet (req1) gets lost.
Host A Host B
-------------------------------------------------------------------
send req1: N(REKEY_SA,SPIa1),
SA(..,SPIa2,..),
Ni1,.. --> (lost)
<-- send req2: N(REKEY_SA,SPIb1),
SA(..,SPIb2,..),Ni2
recv req2 <--
send resp2: SA(..,SPIa3,..),
Nr1,.. -->
--> recv resp2
<-- send req3: D(SPIb1)
recv req3 <--
send resp3: D(SPIa1) -->
--> recv resp3
from B's point of view, the rekeying is now done, and since it hasn't gotten A's req1 yet, it doesn't even know there was a simultaneous rekeying ๐ but A keeps retransmitting the message, and eventually it reaches B ๐ฅน
resend req1 -->
--> recv req1
to B, it looks like A is trying to rekey an SA that doesn't exist anymore ๐ so B responds to the request with something non-fatal, such as CHILD_SA_NOT_FOUND.
<-- send resp1: N(CHILD_SA_NOT_FOUND)
recv resp1 <--
when A gets this error, it already knows there was a simultaneous rekeying, so it can just ignore the error message ๐ ๐ซถ
2.8.2. Simultaneous IKE SA Rekeying โจ
Okay, this is probably the most complicated situation of all ๐ญ Both peers try to rekey the IKE_SA at the exact same moment. Basically, everything in Section 2.8 applies here too ๐ , but it's super important to make sure the Child SAs get inherited by the correct IKE_SA ๐
When both endpoints notice the simultaneous rekey, it works the same way as it does for Child SAs โจ After the CREATE_CHILD_SA exchanges, there are three IKE SAs between A and B: the old IKE SA and two new ones ๐ The new IKE SA with the lowest nonce SHOULD be deleted by the node that created it ๐๏ธ and the other surviving new IKE SA MUST inherit all the Child SAs ๐
There's also a special case that's kind of a plot twist ๐ One peer finishes its rekey before it even notices that the other peer is rekeying too. If only one peer detects the simultaneous rekey, redundant SAs don't get created ๐ฆ In this case, when the peer that didn't notice gets a request to rekey an IKE SA it has already successfully rekeyed, it SHOULD return TEMPORARY_FAILURE because that IKE SA is one it's currently trying to close (whether or not it has already sent the delete notification for the SA) ๐
โโ๏ธ If the peer that did notice gets the delete request for the old IKE SA from the other peer, it knows the other peer never detected the simultaneous rekey, so the first peer can forget its own rekey attempt ๐ซถ
Host A Host B
-------------------------------------------------------------------
send req1:
SA(..,SPIa1,..),Ni1,.. -->
<-- send req2: SA(..,SPIb1,..),Ni2,..
--> recv req1
<-- send resp1: SA(..,SPIb2,..),Nr2,..
recv resp1 <--
send req3: D() -->
--> recv req3
At this point, host B sees a request to close the IKE_SA. There's not much more to it than replying as usual ๐โโ๏ธ However, host B should stop retransmitting req2 ๐ Why? Because once host A receives resp3, it will delete all the state associated with the old IKE_SA and won't be able to reply to it ๐ญ
<-- send resp3: ()
โ ๏ธ The TEMPORARY_FAILURE notification wasn't in RFC 4306, and support for it isn't negotiated. So older peers that implement RFC 4306 but not this document may receive these notifications ๐ฌ They'll treat it like any other unknown error notification and stop the exchange. But since the other peer has already rekeyed, stopping doesn't cause any ill effects ๐
2.8.3. Rekeying the IKE SA versus Reauthentication ๐ธ
Okay, these two are different things in IKEv2, so don't mix them up ๐ โโ๏ธ Rekeying the IKE SA gets you brand-new keys for the IKE SA and resets the Message ID counters ๐ But it does NOT authenticate the parties again, because no AUTH or EAP payloads are involved.
Rekeying can be really important in some environments โจ But reauthentication (checking that the parties still have access to their long-term credentials) is often the bigger deal ๐
IKEv2 doesn't have any special support for reauthentication ๐คทโโ๏ธ Instead, you do it by creating a brand-new IKE SA from scratch (using IKE_SA_INIT/IKE_AUTH exchanges, with no REKEY_SA Notify payloads), creating new Child SAs inside that new IKE SA (also without REKEY_SA Notify payloads), and then deleting the old IKE SA, which deletes the old Child SAs along with it ๐งน
Here's the lowkey fun part ๐ Reauthentication also gives you new keys for the IKE SA and Child SAs. So even though you can rekey more often than you reauthenticate, a situation where the "authentication lifetime" is shorter than the "key lifetime" just doesn't make sense ๐
Creating a new IKE SA can be started by either party (the initiator or the responder of the original IKE SA) ๐ฏ But in practice, using EAP and/or Configuration payloads means reauthentication has to be started by the same party that started the original IKE SA ๐ IKEv2 doesn't currently let the responder ask for reauthentication in this case. There are extensions that add this ability, such as [REAUTH] ๐ฆ
2.9. Traffic Selector Negotiation ๐
Okay, this section is where the magic of "who gets to talk to whom" happens ๐ช When an RFC4301-compliant IPsec subsystem gets an IP packet that matches a "protect" selector in its Security Policy Database (SPD), it protects that packet with IPsec ๐ If there's no SA yet, IKE is the one that creates it. Maintaining a system's SPD is outside IKE's scope, though some implementations might update their SPD while IKE is running (for an example scenario, see Section 1.1.3) ๐
Traffic Selector (TS) payloads let endpoints share some of the info from their SPD with their peers ๐ซถ That info has to be handed to IKE from the SPD (for example, the PF_KEY API [PFKEY] uses the SADB_ACQUIRE message). TS payloads specify the selection criteria for the packets that will be forwarded over the newly set-up SA โจ
This can work as a consistency check in some scenarios, to make sure the SPDs match up ๐ In others, it guides dynamic updates of the SPD ๐
Two TS payloads show up in each message of the exchange that creates a Child SA pair ๐ Each TS payload holds one or more Traffic Selectors, and each Traffic Selector is made of an address range (IPv4 or IPv6), a port range, and an IP protocol ID.
The first TS payload is called TSi (Traffic Selector-initiator), and the second is called TSr (Traffic Selector-responder) ๐ง TSi gives the source address of traffic forwarded from the initiator of the Child SA pair (or the destination address of traffic forwarded to it). TSr gives the destination address of traffic forwarded to the responder of the Child SA pair (or the source address of traffic forwarded from it) ๐
Here's a concrete example, because examples make everything click ๐ Say the original initiator asks for a Child SA pair and wants to tunnel all traffic from the subnet 198.51.100.* on its side to the subnet 192.0.2.* on the responder's side. The initiator would put a single Traffic Selector in each TS payload. TSi would name the address range 198.51.100.0 - 198.51.100.255, and TSr would name the address range 192.0.2.0 - 192.0.2.255. If the responder is cool with that proposal, it sends back identical TS payloads ๐
IKEv2 lets the responder pick a subset of what the initiator proposed ๐ฐ This can happen when the two endpoints' configurations are being updated but only one end has the new info yet. Since the two endpoints might be set up by different people, the mismatch can stick around for a long time, even with no errors at all ๐ฌ It also allows for intentionally different configurations, like when one end is set to tunnel all addresses and depends on the other end to have the up-to-date list ๐
When the responder picks a subset, it narrows the Traffic Selectors down to some subset of the initiator's proposal (as long as the set doesn't become the null set) โ๏ธ If the type of a Traffic Selector is unknown, the responder ignores that Traffic Selector, so the unknown type never shows up in the narrowed set ๐ โโ๏ธ
Now, to help the responder pick the right range, 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 that includes the addresses from the packet that triggered the request ๐ฏ In our example, the initiator would put two Traffic Selectors in TSi: the first with the address range 198.51.100.43 - 198.51.100.43 plus the source port and IP protocol from the packet, and the second with 198.51.100.0 - 198.51.100.255 covering all ports and IP protocols. The initiator would do the same thing with two Traffic Selectors in TSr ๐
If the initiator creates the Child SA pair not in response to an arriving packet, but say, on startup, then there might be no specific addresses it prefers for the initial tunnel over any others. In that case, the first values in TSi and TSr can be ranges instead of specific values ๐ธ
The responder does the narrowing like this ๐ง
- If the responder's policy doesn't let it accept any part of the proposed Traffic Selectors, it responds with a
TS_UNACCEPTABLENotify message ๐ซ - If the responder's policy allows the entire set of traffic covered by TSi and TSr, no narrowing is needed, and the responder can return the same TSi and TSr values โ
- If the responder's policy allows it to accept the first selector of TSi and TSr, then the responder MUST narrow the Traffic Selectors to a subset that includes the initiator's first choices ๐ In the example above, the responder might respond with TSi being
198.51.100.43 - 198.51.100.43with all ports and IP protocols ๐ - If the responder's policy doesn't allow it to accept the first selector of TSi and TSr, the responder narrows to an acceptable subset of TSi and TSr ๐ซง
When narrowing happens, there may be several subsets that are each acceptable, but whose union isn't ๐คฏ In that case, the responder arbitrarily picks one of them, and MAY include an ADDITIONAL_TS_POSSIBLE notification in the response. The ADDITIONAL_TS_POSSIBLE notification says the responder narrowed the proposed Traffic Selectors, but other Traffic Selectors would also have been acceptable, just in a separate SA ๐ฆ There's no data associated with this Notify type. This case only happens when the initiator and responder are configured differently from each other. If they agree on the granularity of tunnels, the initiator will never request a tunnel wider than the responder will accept ๐
It's also possible for the responder's policy to contain multiple smaller ranges, all inside the initiator's Traffic Selector, with the responder's policy being that each of those ranges gets sent over a different SA ๐งฉ Picking up the example above, the responder might be willing to tunnel those addresses to and from the initiator, but require that each address pair sits on its own separately negotiated Child SA. If the initiator didn't generate its request based on a packet, but (for example) on startup, there wouldn't be those very specific first Traffic Selectors to help the responder pick the right range ๐ฉ The responder would have no way to figure out which pair of addresses should go in this tunnel, so it would have to guess or reject the request with a SINGLE_PAIR_REQUIRED Notify message ๐
The SINGLE_PAIR_REQUIRED error says 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 only for the specific traffic it's trying to forward โจ
Honestly, few implementations will have policies that require a separate SA for each address pair ๐ฅฑ Because of that, if only some parts of the TSi and TSr proposed by the initiator are acceptable to the responder, responders SHOULD narrow the selectors to an acceptable subset rather than use SINGLE_PAIR_REQUIRED ๐ซถ๐
2.9.1. Traffic Selectors Violating Own Policy ๐
okay so when you're making a brand new SA, the initiator has to avoid proposing Traffic Selectors that break its OWN policy ๐ซ if it doesn't, valid traffic can literally get dropped and nobody is happy ๐ญ btw if you use decorrelated policies from [IPSECARCH], this kind of policy violation can't happen at all ๐ซถ
let me show you with an example because it's giving drama ๐ฟ say host A has a policy where traffic to 198.51.100.66 gets sent through host B encrypted with AES, and all the OTHER hosts in 198.51.100.0/24 also go through B, but those have to use 3DES ๐ and host B accepts any mix of AES and 3DES ๐ฆ
now if host A proposes an SA that uses 3DES and puts 198.51.100.0 - 198.51.100.255 in TSr, host B is totally going to accept it ๐ฌ but then B can ALSO use that SA to send traffic from 198.51.100.66, and A is gonna drop those packets because A needs AES for that one ๐ even if A makes a brand new SA just for 198.51.100.66 with AES, B can keep using the first SA for that traffic whenever it wants ๐ the tea is that A should've followed its own policy when proposing and included a TSr of (198.51.100.0 - 198.51.100.65) and (198.51.100.67 - 198.51.100.255) instead ๐
the general idea: if (1) the initiator makes a proposal "for traffic X (TSi/TSr), do SA", and (2) for some subset X' of X, the initiator doesn't actually accept traffic X' with that SA, and (3) the initiator would be happy to accept traffic X' with some other SA' (!=SA), then valid traffic can get dropped unnecessarily ๐ญ because the responder can apply either SA or SA' to traffic X' ๐
2.9.2. Traffic Selectors in Rekeying ๐
rekeying is for replacing an existing Child SA with a new one โจ if the new SA were allowed to have a NARROWER set of selectors than the old one, then traffic that was fine on the old SA would get dropped on the new one, and that totally breaks the whole idea of "replacing" ๐ so the new SA MUST NOT have narrower selectors than the original ๐ซ if a rekeyed SA ever needed a narrower scope than the one being used right now, that would mean the policy changed in a way that makes the current SA against policy ๐ in that case the SA should have already been deleted once the policy change took effect ๐งน
when the initiator tries to rekey the Child SA, the proposed Traffic Selectors SHOULD be either the same as, or a superset of, the ones in the old Child SA ๐ basically they should match the currently active (decorrelated) policy ๐ and the responder MUST NOT narrow the Traffic Selectors below the scope that's currently in use ๐
because a rekeyed SA can never have a narrower scope than the one currently in use, there's no need for the selectors from the packet, so those selectors SHOULD NOT be sent ๐ซถ
2.10. Nonces ๐ธ
the IKE_SA_INIT messages each contain a nonce ๐ these nonces are used as inputs to cryptographic functions โจ the CREATE_CHILD_SA request and the CREATE_CHILD_SA response also contain nonces ๐ฆ those are used to add freshness to the key derivation technique that gets keys for Child SAs, and to make sure you get strong pseudorandom bits out of the Diffie-Hellman key ๐ nonces used in IKEv2 MUST be randomly chosen, MUST be at least 128 bits in size, and MUST be at least half the key size of the negotiated pseudorandom function (PRF) ๐ฅ the tricky part is the initiator picks the nonce BEFORE the negotiation outcome is known ๐ญ so the nonce has to be long enough for ALL the PRFs being proposed ๐ and if the same random number source is used for both keys and nonces, you have to be careful that the nonce use doesn't compromise the keys ๐
2.11. Address and Port Agility ๐ฆ
IKE runs over UDP ports 500 and 4500, and it implicitly sets up ESP and AH associations for the same IP addresses it runs over ๐ the IP addresses and ports in the outer header aren't cryptographically protected though, and IKE is designed to work even through Network Address Translation (NAT) boxes ๐ an implementation MUST accept incoming requests even if the source port is not 500 or 4500, and MUST respond to the address and port the request came from ๐ซถ it MUST also specify the address and port where the request was received as the source address and port in the response ๐ฌ IKE works exactly the same over IPv4 or IPv6 โจ
2.12. Reuse of Diffie-Hellman Exponentials ๐
IKE makes keying material using an ephemeral Diffie-Hellman exchange so it gets the property of "perfect forward secrecy" ๐ that means once a connection closes and its keys are forgotten, even someone who recorded all the data AND gets all the long-term keys of both endpoints still can't rebuild the keys to read the conversation, unless they brute force the whole session key space ๐ค
to get perfect forward secrecy, when a connection closes each endpoint MUST forget not only the keys used by the connection but also any information that could be used to recompute those keys ๐ง
computing Diffie-Hellman exponentials is super expensive, so an endpoint might want to reuse them for multiple connection setups ๐ there are a few reasonable ways to do that ๐ an endpoint could pick a new exponential only periodically, but that can mean less-than-perfect forward secrecy if some connection lasts shorter than the exponential's lifetime ๐ or it could track which exponential was used for each connection and only delete the info for that exponential once the connection it was used for closes ๐งน this lets the exponential be reused WITHOUT losing perfect forward secrecy, but you pay for it with more state to maintain ๐
whether and when to reuse Diffie-Hellman exponentials are private decisions, since they won't affect interoperability ๐ค an implementation that reuses exponentials MAY remember the exponential the other endpoint used in past exchanges, and if one gets reused, skip the second half of the calculation โก see [REUSE] and [RFC6989] for a security analysis of this practice and for extra security considerations when reusing ephemeral Diffie-Hellman keys ๐
2.13. Generating Keying Material ๐๏ธ
in the context of the IKE SA, four cryptographic algorithms get negotiated: an encryption algorithm, an integrity protection algorithm, a Diffie-Hellman group, and a pseudorandom function (PRF) ๐ the PRF is used to build keying material for ALL the cryptographic algorithms, in both the IKE SA and the Child SAs ๐
we assume each encryption algorithm and integrity protection algorithm uses a fixed-size key, and any randomly chosen value of that size can work as a key ๐ for algorithms that accept a variable-length key, a fixed key size MUST be specified as part of the negotiated cryptographic transform (check Section 3.3.5 for the Key Length transform attribute) ๐ 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 ๐งฎ
it's assumed PRFs accept keys of ANY length, but they have a preferred key size ๐ the preferred key size MUST be used as the length of SK_d, SK_pi, and SK_pr (see Section 2.14) ๐ for PRFs based on the HMAC construction, the preferred key size equals the length of the output of the underlying hash function ๐ง other types of PRFs MUST specify their preferred key size ๐
keying material is always derived as the output of the negotiated PRF algorithm ๐ธ and since you may need more keying material than the PRF's output size, the PRF gets used iteratively ๐ the term "prf+" describes a function that outputs a pseudorandom stream based on the inputs to a pseudorandom function called "prf" โจ here's the definition, 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)
...
this keeps going until all the material needed for ALL the required keys has come out of prf+ ๐ the keys are 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 generates 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 that gets concatenated to the end of each prf call is a single octet ๐ข and prf+ isn't defined beyond 255 times the size of the prf output ๐
2.14. Generating Keying Material for the IKE SA ๐๐
the shared keys get computed like this ๐ a quantity called SKEYSEED is calculated from the nonces exchanged during the IKE_SA_INIT exchange and the Diffie-Hellman shared secret set up in that exchange ๐ SKEYSEED is then used to calculate seven other secrets: SK_d, used for deriving new keys for the Child SAs made with this IKE SA; SK_ai and SK_ar, used as keys for the integrity protection algorithm that authenticates the component messages of later exchanges; SK_ei and SK_er, used for encrypting (and of course decrypting) all later exchanges; and SK_pi and SK_pr, which are used when generating an AUTH payload ๐ซถ the lengths of SK_d, SK_pi, and SK_pr MUST be the preferred key length of the agreed PRF ๐
here's how SKEYSEED and its buddies get computed ๐
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+ ๐ง) g^ir is the shared secret from the ephemeral Diffie-Hellman exchange ๐ฅ it's represented as a string of octets in big endian order, padded with zeros if needed to make it the length of the modulus ๐งฎ Ni and Nr are the nonces, stripped of any headers ๐ now for the historical backward-compatibility drama ๐ there are two PRFs that get special treatment here: if the negotiated PRF is AES-XCBC-PRF-128 [AESXCBCPRF128] or AES-CMAC-PRF-128 [AESCMACPRF128], then only the first 64 bits of Ni and the first 64 bits of Nr are used in calculating SKEYSEED, but ALL the bits are used as input to the prf+ function ๐ธ
last but not least ๐ the two directions of traffic flow 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 โจ
2.15. Authentication of the IKE SA โจ
Okay so, when you're not using extensible authentication (check out Section 2.16 for that one ๐ฆ), the peers prove who they are by each signing a block of data. Or, if you're feeling old-school, they can MAC it with a padded shared secret as the key. We'll get to that bit later in this section ๐ . Quick definitions first: IDi' and IDr' are the entire ID payloads minus the fixed header. Now, for the responder, the octets being signed start at the very first octet of the first SPI in the header of the second message (the IKE_SA_INIT response) and run all the way to the last octet of the last payload in that message. ๐ธ
Then we tack on two extra bits, just for the signing math: the initiator's nonce Ni (just the value, NOT the payload wrapped around it) and the value prf(SK_pr, IDr'). Neither Ni nor prf(SK_pr, IDr') ever gets sent over the wire, which is honestly so iconic ๐. The initiator does the same thing with the first message (the IKE_SA_INIT request), starting at the first octet of the first SPI and ending at the last octet of the last payload. Then it appends the responder's nonce Nr and prf(SK_pi, IDi'). And here's the big deal: each side has to sign the other side's nonce, because that's critical to the security of the whole exchange. No skipping that! ๐ฅ
Here's how the initiator's signed octets break down:
InitiatorSignedOctets = RealMessage1 | NonceRData | MACedIDForI
GenIKEHDR = [ four octets 0 if using port 4500 ] | RealIKEHDR
RealIKEHDR = SPIi | SPIr | . . . | Length
RealMessage1 = RealIKEHDR | RestOfMessage1
NonceRPayload = PayloadHeader | NonceRData
InitiatorIDPayload = PayloadHeader | RestOfInitIDPayload
RestOfInitIDPayload = IDType | RESERVED | InitIDData
MACedIDForI = prf(SK_pi, RestOfInitIDPayload)
And the responder's signed octets look like this:
ResponderSignedOctets = RealMessage2 | NonceIData | MACedIDForR
GenIKEHDR = [ four octets 0 if using port 4500 ] | RealIKEHDR
RealIKEHDR = SPIi | SPIr | . . . | Length
RealMessage2 = RealIKEHDR | RestOfMessage2
NonceIPayload = PayloadHeader | NonceIData
ResponderIDPayload = PayloadHeader | RestOfRespIDPayload
RestOfRespIDPayload = IDType | RESERVED | RespIDData
MACedIDForR = prf(SK_pr, RestOfRespIDPayload)
Heads up, though: ALL of the payloads get included under the signature, even the payload types that this document doesn't even define ๐. And if the first message gets sent more than once (say, with a responder cookie and/or a different Diffie-Hellman group), it's the latest version of that message that gets signed. Main character energy for the newest message only ๐.
Optionally, messages 3 and 4 MAY include a certificate, or a certificate chain, that proves the key used for a digital signature belongs to the name in the ID payload ๐. The signature or MAC gets computed with whatever algorithms match the type of key the signer is using, and those algorithms are specified by the Auth Method field in the Authentication payload. There's no rule saying the initiator and responder have to sign with the same cryptographic algorithms, since the choice depends on what kind of key each one has. For example, the initiator might be using a shared key while the responder has a public signature key and a certificate. It'll commonly be the case (but it's not required) that, if a shared secret is used for authentication, the very same key gets used in both directions โจ.
Now for a little reality check ๐. Deriving a shared key only from a user-chosen password, with no other source of randomness mixed in, is a super common move, and it's typically insecure. User-chosen passwords usually aren't unpredictable enough to hold up against dictionary attacks, and this authentication method doesn't prevent those attacks. (If you're using password-based auth for bootstrapping and IKE SA, you should use the method in Section 2.16 instead, since that one is designed to stop off-line dictionary attacks ๐ก๏ธ.) The pre-shared key needs to have as much unpredictability as the strongest key being negotiated.
For a pre-shared key, the AUTH value gets computed like this:
For the initiator:
AUTH = prf( prf(Shared Secret, "Key Pad for IKEv2"),
<InitiatorSignedOctets>)
For the responder:
AUTH = prf( prf(Shared Secret, "Key Pad for IKEv2"),
<ResponderSignedOctets>)
The string "Key Pad for IKEv2" is 17 ASCII characters, and there's no null termination on it. The shared secret can be any length you want ๐. So why the pad string? It's there so that, if the shared secret came from a password, the IKE implementation doesn't have to store the actual password in cleartext. It can store prf(Shared Secret,"Key Pad for IKEv2") instead, and that value can't be used as a password equivalent for any protocol other than IKEv2, which is kinda clever ๐ง. Again though, deriving the secret from a password is not secure. This construction exists purely because people are going to do it anyway ๐ญ.
The management interface where you hand over the shared secret MUST accept ASCII strings of at least 64 octets, and it MUST NOT add a null terminator before using them as shared secrets. It MUST also accept a hex encoding of the shared secret. It MAY accept other encodings, but only if the algorithm for translating that encoding into a binary string is specified ๐.
There are two types of EAP authentication (more on those in Section 2.16), and each type uses different values in the AUTH computations above. If the EAP method is key-generating, you swap in the master session key (MSK) in place of the shared secret in the computation. If it's a non-key-generating method, you substitute SK_pi and SK_pr, respectively, for the shared secret in the two AUTH computations ๐.
2.16. Extensible Authentication Protocol Methods ๐
Besides signing with public keys and using shared secrets, IKE also supports authentication with methods defined in RFC 3748 [EAP] ๐ฆ. These methods are usually asymmetric (think a user proving themselves to a server), and they may not be mutual. Because of that, they're typically used to authenticate the initiator to the responder, and they MUST be used alongside a public-key-signature-based authentication of the responder to the initiator ๐. These methods are often tied to mechanisms known as "Legacy Authentication" mechanisms ๐ฐ๏ธ.
The document references [EAP] on purpose, so new methods can be added in the future without updating this specification. Some simpler variations are documented right here, though ๐ . [EAP] defines an authentication protocol that needs a variable number of messages. In IKE, extensible authentication happens through additional IKE_AUTH exchanges, and those MUST be completed in order to initialize the IKE SA โจ.
So how does an initiator say "I wanna use EAP"? Easy: it leaves the AUTH payload out of the first message in the IKE_AUTH exchange. (Quick note: the AUTH payload is required for non-EAP authentication, so it isn't marked optional anywhere else in this document ๐.) When the initiator includes an IDi payload but no AUTH payload, it's basically saying "here's who I am," but it hasn't proven it yet ๐. If the responder is down to use an EAP method, it puts an Extensible Authentication Protocol (EAP) payload in the IKE_AUTH response, and it holds off on sending SAr2, TSi, and TSr until the initiator's authentication is finished in a later IKE_AUTH exchange. For a minimal EAP method, the initial SA setup goes 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}
As described in Section 2.2, when EAP is in play, each pair of IKE SA initial setup messages gets its message number bumped. The first pair of IKE_AUTH messages gets an ID of 1, the second pair gets 2, and so on ๐ข.
Now, for EAP methods that create a shared key as a side effect of authentication: that shared key MUST be used by both the initiator and 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 specification named MSK. And the shared key generated during an IKE exchange MUST NOT be used for any other purpose. Keep it for IKE only, bestie ๐ซถ.
EAP methods that don't establish a shared key SHOULD NOT be used ๐ซ. They're subject to a number of man-in-the-middle attacks [EAPMITM] if they get used in other protocols that don't use a server-authenticated tunnel. Please see the Security Considerations section for more details, because this stuff is serious ๐ฌ. If you do end up using 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 needs to be capable of extending the initial protocol exchange to at least ten IKE_AUTH exchanges. Why ten? Because the responder might send notification messages and/or retry the authentication prompt along the way ๐.
Once the protocol exchange defined by the chosen EAP method has successfully wrapped up, the responder MUST send an EAP payload containing the Success message ๐. Similarly, if the authentication method failed, the responder MUST send an EAP payload containing the Failure message ๐. The responder MAY also terminate the IKE exchange at any time by sending an EAP payload containing the Failure message, so it has that power too ๐.
After an extended exchange like this, the EAP AUTH payloads MUST be included in the two messages that follow the one containing the EAP Success message โจ.
When initiator authentication uses EAP, the contents of the IDi payload may be used only for Authentication, Authorization, and Accounting (AAA) routing purposes and for selecting which EAP method to use ๐งญ. This value may be different from the identity that the EAP method actually authenticated. So it's really important that policy lookups and access control decisions use the actual authenticated identity ๐. Often the EAP server is a separate AAA server that talks to the IKEv2 responder. In that setup, if the authenticated identity is different from the one in the IDi payload, it has to be sent from the AAA server over to the IKEv2 responder ๐.
2.17. Generating Keying Material for Child SAs โจ
okay so a single Child SA gets made during the IKE_AUTH exchange, and extra Child SAs can optionally be made in CREATE_CHILD_SA exchanges ๐ฆ Their keying material gets cooked up like this:
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 being created, or the fresh Ni and Nr from the CREATE_CHILD_SA exchange if it's a later one ๐
When a CREATE_CHILD_SA exchange includes 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. It's represented as an octet string in big endian order, padded with zeros in the high-order bits if necessary to make it the length of the modulus ๐ธ
A single CREATE_CHILD_SA negotiation can end up with multiple Security Associations. ESP and AH SAs come in pairs (one in each direction), so two SAs get created in a single Child SA negotiation for them ๐ Child SA negotiation can also include some future IPsec protocol(s) in addition to, or instead of, ESP or AH. For example, ROHC_INTEG as described in [ROHCV2]. Either way, keying material for each Child SA MUST be taken from the expanded KEYMAT using these rules:
- All keys for SAs carrying data from the initiator to the responder are taken before SAs going from the responder to the initiator.
- If multiple IPsec protocols are negotiated, keying material for each Child SA is taken in the order in which the protocol headers will appear in the encapsulated packet.
- If an IPsec protocol requires multiple keys, the order in which they are taken from the SA's keying material needs to be described in the protocol's specification. For ESP and AH, [IPSECARCH] defines the order, namely: the encryption key (if any) MUST be taken from the first bits and the integrity key (if any) MUST be taken from the remaining bits. ๐ฅ
Each cryptographic algorithm takes a fixed number of bits of keying material. That number is either specified as part of the algorithm or negotiated in SA payloads (see Section 2.13 for the description of key lengths, and Section 3.3.5 for the definition of the Key Length transform attribute) ๐ง
2.18. Rekeying IKE SAs Using a CREATE_CHILD_SA Exchange ๐
The CREATE_CHILD_SA exchange can be used to rekey an existing IKE SA (see Sections 1.3.2 and 2.8) ๐ The new initiator and responder SPIs go in the SPI fields of the Proposal structures inside the Security Association (SA) payloads. They do not go in the SPI fields of the IKE header. The TS payloads are omitted when rekeying an IKE SA. SKEYSEED for the new IKE SA is computed using SK_d from the existing IKE SA:
SKEYSEED = prf(SK_d (old), g^ir (new) | Ni | Nr)
where g^ir (new) is the shared secret from the ephemeral Diffie-Hellman exchange of this CREATE_CHILD_SA exchange (represented as an octet string in big endian order, padded with zeros if necessary to make it the length of the modulus). Ni and Nr are the two nonces, stripped of any headers ๐ฆ
The old and new IKE SA may have selected different PRFs. But because the rekeying exchange belongs to the old IKE SA, it's the old IKE SA's PRF that gets used to generate SKEYSEED. Not the new one, bestie ๐
The main reason for rekeying the IKE SA is to make sure that compromising old keying material doesn't tell you anything about the current keys, or the other way around. So implementations MUST perform a new Diffie-Hellman exchange when rekeying the IKE SA. In other words, an initiator MUST NOT propose the value "NONE" for the Diffie-Hellman transform, and a responder MUST NOT accept such a proposal. That means a successful exchange rekeying the IKE SA always includes the KEi/KEr payloads ๐
The new IKE SA MUST reset its message counters to 0 ๐
SK_d, SK_ai, SK_ar, SK_ei, and SK_er are computed from SKEYSEED as specified in Section 2.14. They use SPIi, SPIr, Ni, and Nr from the new exchange, and the new IKE SA's PRF ๐
2.19. Requesting an Internal Address on a Remote Network ๐
This is most common in the endpoint-to-security-gateway scenario. An endpoint might need an IP address inside the network protected by the security gateway, and that address may need to be assigned dynamically ๐ธ A request for a temporary address can be included in any request to create a Child SA (including the implicit request in message 3) by including a CP payload. Heads up though: it's usual to only assign one IP address during the IKE_AUTH exchange. That address persists at least until the IKE SA is deleted โญ
This function gives address allocation to an IPsec Remote Access Client (IRAC) that's trying to tunnel into a network protected by an IPsec Remote Access Server (IRAS). Since the IKE_AUTH exchange creates an IKE SA and a Child SA, the IRAC MUST request the IRAS-controlled address (and optionally other info about the protected network) in the IKE_AUTH exchange. The IRAS may get an address for the IRAC from any number of sources, like a DHCP/BOOTP (Bootstrap Protocol) server or its own address pool ๐ง
Initiator Responder
-------------------------------------------------------------------
HDR, SK {IDi, [CERT,]
[CERTREQ,] [IDr,] AUTH,
CP(CFG_REQUEST), SAi2,
TSi, TSr} -->
<-- HDR, SK {IDr, [CERT,] AUTH,
CP(CFG_REPLY), SAr2,
TSi, TSr}
In all cases, the CP payload MUST be inserted before the SA payload. In variations of the protocol with multiple IKE_AUTH exchanges, the CP payloads MUST be inserted in the messages containing the SA payloads ๐ซถ
CP(CFG_REQUEST) MUST contain at least an INTERNAL_ADDRESS attribute (either IPv4 or IPv6), but it MAY contain any number of additional attributes the initiator wants returned in the response ๐
Here's an example, message from initiator to responder:
CP(CFG_REQUEST)=
INTERNAL_ADDRESS()
TSi = (0, 0-65535, 0.0.0.0-255.255.255.255)
TSr = (0, 0-65535, 0.0.0.0-255.255.255.255)
NOTE: Traffic Selectors contain (protocol, port range, address range).
And the message from responder to initiator:
CP(CFG_REPLY)=
INTERNAL_ADDRESS(192.0.2.202)
INTERNAL_NETMASK(255.255.255.0)
INTERNAL_SUBNET(192.0.2.0/255.255.255.0)
TSi = (0, 0-65535, 192.0.2.202-192.0.2.202)
TSr = (0, 0-65535, 192.0.2.0-192.0.2.255)
All returned values are implementation dependent. As you can see in the example above, the IRAS MAY also send other attributes that weren't included in CP(CFG_REQUEST), and it MAY ignore the non-mandatory attributes it doesn't support ๐
The responder MUST NOT send a CFG_REPLY without having first received a CP(CFG_REQUEST) from the initiator. The reason? We don't want the IRAS doing an unnecessary configuration lookup if the IRAC can't process the REPLY anyway ๐
Now, if the IRAS's configuration requires CP to be used for a given identity IDi, but the IRAC failed to send a CP(CFG_REQUEST), then IRAS MUST fail the request and terminate the Child SA creation with a FAILED_CP_REQUIRED error. FAILED_CP_REQUIRED isn't fatal to the IKE SA. It just makes the Child SA creation fail. The initiator can fix this by starting a new Configuration payload request later on. There's no associated data in the FAILED_CP_REQUIRED error ๐ท
2.20. Requesting the Peer's Version ๐ญ
An IKE peer that wants to ask about the other peer's IKE software version information MAY use the method below. This is an example of a configuration request within an INFORMATIONAL exchange, after the IKE SA and first Child SA have been created ๐
An IKE implementation MAY decline to give out version information before authentication, or even after authentication, in case some implementation is known to have a security weakness. In that case, it MUST either return an empty string, or no CP payload if CP 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 ๐จ
There are a lot of kinds of errors that can happen during IKE processing ๐ญ The general rule is that if a request is received that's badly formatted, or unacceptable for reasons of policy (like no matching cryptographic algorithms), the response contains a Notify payload indicating the error. Whether or not to send that response depends on whether there's an authenticated IKE SA ๐
If there's an error parsing or processing a response packet, the general rule is to not send back any error message, because responses should not generate new requests (and a new request would be the only way to send back an error message). Errors like that in response packets should still cause the recipient to clean up the IKE state. For example, by sending a Delete for a bad SA ๐งน
Only authentication failures (AUTHENTICATION_FAILED and EAP failure) and malformed messages (INVALID_SYNTAX) lead to deleting the IKE SA without needing an explicit INFORMATIONAL exchange carrying a Delete payload. Other error conditions MAY require such an exchange if policy dictates that it's needed. If the exchange is terminated with EAP Failure, an AUTHENTICATION_FAILED notification is not sent ๐
2.21.1. Error Handling in IKE_SA_INIT ๐ง
Errors that happen before a cryptographically protected IKE SA is established need to be handled very carefully. It's a trade-off: you want to help the peer diagnose a problem by responding to the error, but you also don't want to become part of a DoS attack based on forged messages ๐ต๏ธโโ๏ธ
In an IKE_SA_INIT exchange, any error notification causes the exchange to fail. Some error notifications, like COOKIE, INVALID_KE_PAYLOAD or INVALID_MAJOR_VERSION, may lead to a subsequent successful exchange. Because all error notifications are completely unauthenticated, the recipient should keep trying for some time before giving up. The recipient should not immediately act based on the error notification unless corrective actions are defined in this specification, such as for COOKIE, INVALID_KE_PAYLOAD, and INVALID_MAJOR_VERSION ๐
2.21.2. Error Handling in IKE_AUTH โจ
okay so any error in an IKE_AUTH exchange that makes authentication fail (invalid shared secret, invalid ID, untrusted certificate issuer, revoked or expired certificate, etc.) SHOULD result in an AUTHENTICATION_FAILED notification ๐. If the error happened on the responder, that notification comes back in the protected response and is usually the only payload in there ๐. The IKE_AUTH messages are encrypted and integrity protected, but a peer that hasn't authenticated the other end yet still needs to treat that info with caution ๐.
If the error happens on the initiator, the notification MAY be returned in a separate INFORMATIONAL exchange, usually with no other payloads ๐ . This is an exception to the general rule about not starting new exchanges based on errors in responses ๐.
Note, though, that request messages with an unsupported critical payload, or where the whole message is malformed (rather than just bad payload contents), MUST be rejected in their entirety ๐ซ, and MUST only lead to an UNSUPPORTED_CRITICAL_PAYLOAD or INVALID_SYNTAX Notification sent as a response. The receiver should not verify the payloads related to authentication in this case.
If authentication succeeded in the IKE_AUTH exchange, the IKE SA is established โ
. However, establishing the Child SA or requesting configuration info may still fail, and that failure does not automatically cause the IKE SA to be deleted. A responder may include all the authentication payloads (IDr, CERT, and AUTH) while sending error notifications for the piggybacked exchanges (FAILED_CP_REQUIRED, NO_PROPOSAL_CHOSEN, and so on), and the initiator MUST NOT fail the authentication because of this ๐
โโ๏ธ. The initiator MAY, of course, for reasons of policy, later delete such an IKE SA.
In an IKE_AUTH exchange, or in the INFORMATIONAL exchange immediately following it (in case an error happened while processing a response to IKE_AUTH), the UNSUPPORTED_CRITICAL_PAYLOAD, INVALID_SYNTAX, and AUTHENTICATION_FAILED notifications are the only ones that cause the IKE SA to be deleted or not created, without a Delete payload. Extension documents may define new error notifications with these semantics, but MUST NOT use them unless the peer has been shown to understand them, such as by using the Vendor ID payload ๐ซถ.
2.21.3. Error Handling after IKE SA is Authenticated ๐ธ
After the IKE SA is authenticated, all requests having errors MUST result in a response notifying the other end of the error.
In normal situations there should not be cases where a valid response from one peer results in an error situation in the other peer, so there should not be any reason for a peer to send error messages to the other end except as a response. Sending those errors as an INFORMATIONAL exchange might lead to further errors that could cause loops ๐, so such errors SHOULD NOT be sent. If errors show that the peers don't have the same state, it might be good to delete the IKE SA, clean up the state, and start over ๐งน.
If a peer parsing a request notices that it is badly formatted (after it has passed the message authentication code checks and window checks) and it returns an INVALID_SYNTAX notification, then that error notification is considered fatal in both peers ๐. That means the IKE SA is deleted without needing an explicit Delete payload.
2.21.4. Error Handling Outside IKE SA ๐ฆ
A node needs to limit the rate at which it sends messages in response to unprotected messages ๐ฆ.
If a node receives a message on UDP port 500 or 4500 outside the context of an IKE SA it knows about (and the message is not a request to start an IKE SA), this may be the result of a recent crash of the node ๐ฅ. If the message is marked as a response, the node can audit the suspicious event but MUST NOT respond. If the message is marked as a request, the node can audit the suspicious event and MAY send a response. If a response is sent, it MUST be sent to the IP address and port it came from, with the same IKE SPIs and the Message ID copied. The response MUST NOT be cryptographically protected and MUST contain an INVALID_IKE_SPI Notify payload. The INVALID_IKE_SPI notification means an IKE message arrived with an unrecognized destination SPI, which usually means the recipient has rebooted and forgotten the IKE SA even exists ๐.
A peer receiving such an 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 that a genuine correspondent was tricked into sending ๐ต๏ธโโ๏ธ. A node should treat such a message (and also a network message like ICMP destination unreachable) as a hint that there might be problems with SAs to that IP address, and it should initiate a liveness check for any such IKE SA. An implementation SHOULD limit the frequency of such tests so it doesn't get tricked into joining a DoS attack ๐.
Translation: don't trust unprotected notifies just because they showed up, bestie ๐.
If an error occurs outside the context of an IKE request (e.g., the node is getting ESP messages on a nonexistent SPI), the node SHOULD initiate an INFORMATIONAL exchange with a Notify payload describing the problem ๐ฃ.
A node receiving a suspicious message from an IP address (and port, if NAT traversal is used) with which it has an IKE SA SHOULD send an IKE Notify payload in an IKE INFORMATIONAL exchange over that SA. The recipient MUST NOT change the state of any SAs as a result, but it may wish to audit the event to help diagnose malfunctions ๐.
2.22. IPComp ๐๏ธ
Use of IP Compression [IP-COMP] can be negotiated as part of setting up a Child SA ๐. While IP Compression adds an extra header to each packet along with a compression parameter index (CPI), the virtual "compression association" has no life outside the ESP or AH SA that contains it ๐ซง. Compression associations disappear when the corresponding ESP or AH SA goes away, and they aren't explicitly mentioned in any Delete payload.
Negotiation of IP Compression is separate from the negotiation of the cryptographic parameters for a Child SA ๐งฉ. A node requesting a Child SA MAY advertise its support for one or more compression algorithms through one or more Notify payloads of type IPCOMP_SUPPORTED ๐ข. This Notify message may be included only in a message containing an SA payload that negotiates a Child SA, and it shows the sender is willing to use IPComp on this SA. The response MAY indicate acceptance of a single compression algorithm with a Notify payload of type IPCOMP_SUPPORTED. These payloads MUST NOT occur in messages that do not contain SA payloads ๐
โโ๏ธ.
The data for this Notify message is a two-octet IPComp CPI, followed by 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 several supported algorithms, while a message accepting an SA may contain at most one.
The Transform IDs are listed here. The values in the following table were only current as of the publication date of RFC 4306 ๐ . Other values may have been added since then, or will be added after this document is published, so readers should check [IKEV2IANA] for the latest values ๐.
Name Number Defined In
----------------------------------------
IPCOMP_OUI 1 (UNSPECIFIED)
IPCOMP_DEFLATE 2 RFC 2394
IPCOMP_LZS 3 RFC 2395
IPCOMP_LZJH 4 RFC 3051
Although there has been discussion of allowing multiple compression algorithms to be accepted, and of having different compression algorithms for the two directions of a Child SA ๐ค, implementations of this specification MUST NOT accept an IPComp algorithm that was not proposed, MUST NOT accept more than one, and MUST NOT compress using an algorithm other than one proposed and accepted in the setup of the Child SA ๐ซ.
A side effect of separating IPComp negotiation from the cryptographic parameters is that you can't propose multiple cryptographic suites and propose IP Compression with some of them but not others ๐.
In some cases, Robust Header Compression (ROHC) may be more appropriate than IP Compression ๐. [ROHCV2] defines how to use ROHC with IKEv2 and IPsec โจ.
2.23. NAT Traversal โจ
Okay bestie, NAT gateways are a total hot-button topic ๐ Some people think NATs are evil and that we should never design protocols to make them work better ๐ IKEv2 does have some unintuitive processing rules so NATs are more likely to actually work, and I'm here for it ๐ซถ
NATs mostly exist because IPv4 addresses are scarce, though there are other reasons too ๐ธ Nodes "behind" a NAT have IP addresses that aren't globally unique. They come from a space that's unique inside the network behind that NAT, but the same addresses get reused 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, obviously ๐) When those nodes connect out to the real Internet, the NAT gateway "translates" the IP source address into one that will route back to the gateway. Traffic coming back from the Internet to the gateway has its destination address "translated" to the internal address that gets the packet to the right endnode ๐ฆ
NATs are designed to be "transparent" to endnodes, which is iconic of them honestly. Neither the software on the node behind the NAT nor the node on the Internet needs changes to talk through the NAT. Transparency is harder with some protocols than others ๐ง Protocols that carry IP addresses of the endpoints inside their payloads will break unless the NAT gateway understands the protocol and rewrites those internal references along with the ones in the headers. That kind of knowledge is inherently unreliable, is a network layer violation, and often causes subtle problems ๐ญ
Opening an IPsec connection through a NAT comes with its own special problems ๐ If the connection runs in transport mode, changing the IP addresses on packets makes the checksums fail, and the NAT can't fix the checksums 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 for that reason, IKEv2 is going to use UDP encapsulation of IKE and ESP packets ๐ This encoding is a little less efficient but it's easier for NATs to process. Also, firewalls might be configured to pass UDP-encapsulated IPsec traffic but not plain, unencapsulated ESP/AH, or the other way around ๐
It's super common for NATs to translate TCP and UDP port numbers as well as addresses, and to use the port numbers of inbound packets to decide which internal node gets a given packet ๐ Because of that, even though IKE packets MUST be sent to and from UDP port 500 or 4500, they MUST be accepted coming from any port, and responses MUST be sent to the port they came from ๐ซถ This is because the ports might get modified as packets pass through NATs. Similarly, the IP addresses of the IKE endpoints generally aren't included in the IKE payloads, since the payloads are cryptographically protected and NATs couldn't transparently modify them without breaking things ๐
Port 4500 is reserved for UDP-encapsulated ESP and IKE โญ An IPsec endpoint that discovers a NAT between itself and its correspondent (as described below) MUST send all subsequent traffic from port 4500, which NATs should not treat specially (as they might with port 500) ๐ฆ
An initiator can use port 4500 for both IKE and ESP, whether or not there's a NAT, even right at the beginning of IKE ๐ง When either side is using port 4500, sending ESP with UDP encapsulation is not required, but understanding received UDP-encapsulated ESP packets is required. UDP encapsulation MUST NOT be done on port 500. If Network Address Translation Traversal (NAT-T) is supported (that is, if NAT_DETECTION_*_IP payloads were exchanged during IKE_SA_INIT), all devices MUST be able to receive and process both UDP-encapsulated ESP and non-UDP-encapsulated ESP packets at any time ๐ฅ Either side can decide whether or not to use UDP encapsulation for ESP, regardless of what the other side chose. However, if a NAT is detected, both devices MUST use UDP encapsulation for ESP ๐ญ
The specific requirements for supporting NAT traversal [NATREQ] are listed below. Support for NAT traversal is optional. In this section only, requirements listed as MUST apply only to implementations supporting NAT traversal ๐ธ
- Both the IKE initiator and responder MUST include in their IKE_SA_INIT packets Notify payloads of type NAT_DETECTION_SOURCE_IP and NAT_DETECTION_DESTINATION_IP. Those payloads can be used to detect whether there's a NAT between the hosts, and which end is behind the NAT ๐ Their location in the IKE_SA_INIT packets is just after the Ni and Nr payloads (before the optional CERTREQ payload) ๐
- The data in a NAT_DETECTION_SOURCE_IP notification is a SHA-1 digest of the SPIs (in the order they appear in the header), IP address, and port from which this packet was sent. There MAY be multiple NAT_DETECTION_SOURCE_IP payloads in a message if the sender doesn't know which of several network attachments will be used to send the packet ๐ง
- The data in a NAT_DETECTION_DESTINATION_IP notification is a SHA-1 digest of the SPIs (in the order they appear in the header), IP address, and port to which this packet was sent ๐
- The recipient of either a NAT_DETECTION_SOURCE_IP or NAT_DETECTION_DESTINATION_IP notification MAY compare the supplied value to a SHA-1 hash of the SPIs, and the source or recipient IP address and port (respectively). If they don't match, it SHOULD enable NAT traversal. If there's a mismatch between the NAT_DETECTION_SOURCE_IP hash and all of the NAT_DETECTION_SOURCE_IP payloads received, the recipient MAY reject the connection attempt if NAT traversal is not supported. If the NAT_DETECTION_DESTINATION_IP hash mismatches, it means the system receiving the NAT_DETECTION_DESTINATION_IP payload is behind a NAT, and that system SHOULD start sending keepalive packets as defined in [UDPENCAPS]. Alternately, it MAY reject the connection attempt if NAT traversal is not supported ๐
- If none of the NAT_DETECTION_SOURCE_IP payload(s) received matches the expected value of the source IP and port found in the IP header of the packet containing the payload, it means the system sending those payloads is behind a NAT. In other words, someone along the route changed the source address of the original packet to match the NAT box's address ๐ญ In this case, the system receiving the payloads should allow dynamic updates of the other system's IP address, as described later ๐
- The IKE initiator MUST check the NAT_DETECTION_SOURCE_IP or NAT_DETECTION_DESTINATION_IP payloads if present. 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 zeros prepended, and the result immediately follows the UDP header. To tunnel ESP packets over UDP port 4500, the ESP header immediately follows the UDP header. Since the first four octets of the ESP header contain the SPI, and the SPI cannot validly be zero, it's always possible to tell ESP and IKE messages apart ๐ฆ
- Implementations MUST process received UDP-encapsulated ESP packets even when no NAT was detected ๐
- The original source and destination IP addresses needed for the transport mode TCP and UDP packet checksum fixup (see [UDPENCAPS]) are obtained from the Traffic Selectors associated with the exchange. For transport mode NAT traversal, the Traffic Selectors MUST contain exactly one IP address, which is then used as the original IP address. This is covered in greater detail in Section 2.23.1 ๐
- There are cases where a NAT box decides to remove mappings that are still alive (for example, the keepalive interval is too long, or the NAT box gets rebooted). A host will notice this if it receives a packet whose integrity protection validates, but that has a different port, address, or both from the one associated with the SA in the validated packet. When such a validated packet is found, a host that doesn't support other recovery methods, such as IKEv2 Mobility and Multihoming (MOBIKE) [MOBIKE], and that isn't behind a NAT, SHOULD send all packets (including retransmission packets) to the IP address and port in the validated packet. It SHOULD also store this as the new address and port combination for the SA (that is, it SHOULD dynamically update the address) โจ A host behind a NAT SHOULD NOT do this type of dynamic address update if a validated packet has different port and/or address values, because it opens a possible DoS attack (such as letting an attacker break the connection with a single packet) ๐จ Dynamic address updates should also only happen in response to a new packet. Otherwise, an attacker can revert the addresses with old replayed packets ๐ฑ Because of this, dynamic updates can only be done safely if replay protection is enabled. When IKEv2 is used with MOBIKE, dynamically updating the addresses as described above interferes with MOBIKE's way of recovering from the same situation. See Section 3.8 of [MOBIKE] for more information ๐ธ
2.23.1. Transport Mode NAT Traversal ๐ฆ
Okay so transport mode plus NAT traversal is where things get spicy ๐ถ๏ธ The Traffic Selectors in IKEv2 need special handling here, and the full scenario looks like this:
+------+ +------+ +------+ +------+
|Client| IP1 | NAT | IPN1 IPN2 | NAT | IP2 |Server|
|node |<------>| A |<---------->| B |<------->| |
+------+ +------+ +------+ +------+
(Every other scenario is just a simpler version of this one, so we're going full drama and using the complete setup ๐ )
There are two address-translating NATs in this picture: NAT A and NAT B. NAT A is a dynamic NAT that maps the client's source address IP1 to IPN1. NAT B is a static NAT set up so that connections arriving at the IPN2 address get mapped to the gateway's address IP2. In other words, the IPN2 destination address is mapped to IP2, which means the client can reach the server just by connecting to IPN2 โจ NAT B doesn't have to be static, but the client needs to know how to reach the server, and it can only do that if it somehow knows NAT B's outer address, which is IPN2. If NAT B is static, its address can simply be put into the client's configuration. Another option is to look it up with some other protocol (like DNS), but that's outside the scope of IKEv2 ๐
In this scenario, both the client and the server are configured to use transport mode for traffic that starts at the client node and is headed to the server ๐
When the client starts creating the IKEv2 SA and the Child SA for sending traffic to the server, it might have a triggering packet with a source IP address of IP1 and a destination IP address of IPN2. Its Peer Authorization Database (PAD) and SPD need to have a configuration that matches those addresses (or wildcard entries that cover them). Since this is transport mode, it uses exactly the same addresses as the Traffic Selectors and as the outer IP address of the IKE packets. For transport mode, it MUST use exactly one IP address in the TSi and TSr payloads. It can have multiple Traffic Selectors if it has, for example, multiple port ranges it wants to negotiate. But all TSi entries must use the IP1-IP1 range as their IP addresses, and all TSr entries must have the IPN2-IPN2 range as their IP addresses. The first Traffic Selector of TSi and TSr SHOULD be very specific, including protocol and port numbers, like the ones from the packet that triggered the request ๐ง
NAT A then replaces the source address of the IKE packet from IP1 with IPN1, and NAT B replaces the destination address of the IKE packet from IPN2 with IP2. So when the packet reaches the server, its Traffic Selectors are still exactly what the client sent, but the IP addresses of the IKE packet have been swapped to IPN1 and IP2 ๐ธ
When the server gets this packet, it normally looks in the Peer Authorization Database (PAD) described in RFC 4301 [IPSECARCH] based on the ID, and then searches the SPD based on the Traffic Selectors. But IP1 doesn't really mean anything to the server (it's the address the client has behind the NAT), so looking things up with it is pointless if transport mode is in use. On the other hand, the server can't know whether its policy allows transport mode until it finds the matching SPD entry. Tricky! ๐ญ
In this case, the server should first check that the initiator requested transport mode, and then do address substitution on the Traffic Selectors. It needs to store the old Traffic Selector IP addresses first, so they can be used later for the incremental checksum fixup. The IP address in TSi can be stored as the original source address, and the IP address in TSr can be stored as the original destination address. After that, if the other end was detected as being behind a NAT, the server replaces the IP address in the TSi payloads with the IP address taken from the source address of the received IKE packet (so IP1 in TSi becomes IPN1). If the server's own end was detected as being behind a NAT, it replaces the IP address in the TSr payloads with the IP address taken from the destination address of the received IKE packet (so IPN2 in TSr becomes IP2) ๐
Once the address substitution is done, the Traffic Selectors and the IKE UDP source and destination addresses look the same, and the server runs an SPD lookup based on those new Traffic Selectors. If it finds an entry that allows transport mode, that entry gets used โจ If it finds an entry that does not allow transport mode, the server MAY undo the address substitution and redo the SPD lookup using the original Traffic Selectors. If that second lookup succeeds, the server creates an SA in tunnel mode using the real Traffic Selectors sent by the other end ๐
This address substitution in transport mode is needed because the SPD is looked up using the addresses the local host actually sees. It also makes sure the Security Association Database (SAD) entries for the tunnel exit checks and the return packets are added using the addresses as the local operating system stack sees them ๐ฅ
Most of the time, the server's SPD will have wildcard entries that match any address. But it can also have different SPD entries for things like the outer addresses of different known NATs, which is a fun flex ๐
After the SPD lookup, the server does Traffic Selector narrowing based on the SPD entry it found. It uses the already substituted Traffic Selectors again, so it sends back Traffic Selectors with IPN1 and IP2 as their IP addresses. It can still narrow down the protocol number or the port ranges used by the Traffic Selectors. The SAD entry created for the Child SA has the addresses as the server sees them, namely IPN1 and IP2 ๐ฆ
When the client gets the server's response for the Child SA, it does similar processing. If a transport mode SA was created, the client can store the original returned Traffic Selectors as the original source and destination addresses. Then it replaces the IP addresses in the Traffic Selectors with the ones from the IP header of the IKE packet: IPN1 gets replaced with IP1, and IP2 gets replaced with IPN2. After that, it uses those Traffic Selectors when verifying the SA against the Traffic Selectors it sent, and when installing the SAD entry ๐ซถ
Here's the quick cheat sheet for NAT traversal in transport mode ๐
For the client proposing transport mode:
- The TSi entries MUST have exactly one IP address, and that MUST match the source address of the IKE SA.
- The TSr entries MUST have exactly one IP address, and that MUST match the destination address of the IKE SA.
- The first TSi and TSr Traffic Selectors SHOULD be very specific, including protocol and port numbers, like the ones from the packet that triggered the request.
- There MAY be multiple TSi and TSr entries.
- If transport mode for the SA was selected (that is, if the server included a USE_TRANSPORT_MODE notification in its response):
- Store the original Traffic Selectors as the received source and destination address.
- If the server is behind a NAT, substitute the IP address in the TSr entries with the remote address of the IKE SA.
- If the client is behind a NAT, substitute the IP address in the TSi entries with the local address of the IKE SA.
- Do the address substitution before using those Traffic Selectors for anything other than storing their original content. This includes verifying that the other end narrowed the Traffic Selectors correctly, creating the SAD entry, and so on.
For the responder, when transport mode is proposed by the client:
- Store the original Traffic Selector IP addresses as the received source and destination address, in case undoing the address substitution is needed. They're also used as the "real source and destination address" specified by [UDPENCAPS], and for the TCP/UDP checksum fixup.
- If the client is behind a NAT, substitute the IP address in the TSi entries with the remote address of the IKE SA.
- If the server is behind a NAT, substitute the IP address in the TSr entries with the local address of the IKE SA.
- Do the PAD and SPD lookup using the ID and the substituted Traffic Selectors.
- If no SPD entry was found, or (if one was found) the SPD entry does not allow transport mode, undo the Traffic Selector substitutions. Then do the PAD and SPD lookup again using the ID and the original Traffic Selectors, but this time also search for a tunnel mode SPD entry (that is, fall back to tunnel mode) ๐
- However, if a transport mode SPD entry was found, do normal traffic selection narrowing based on the substituted Traffic Selectors and the SPD entry. Use the resulting Traffic Selectors when creating SAD entries and when sending Traffic Selectors back to the client โจ
2.24. Explicit Congestion Notification (ECN) ๐ธ
When IPsec tunnels behave the way they were originally specified in [IPSECARCH-OLD], ECN usage is not appropriate for the outer IP headers, because tunnel decapsulation processing throws away ECN congestion indications, and that's bad for the network ๐ฌ ECN support for IKEv1-based IPsec tunnels needs multiple operating modes and negotiation (see [ECN]). IKEv2 makes this way simpler by requiring that ECN be usable in the outer IP headers of all tunnel mode Child SAs created by IKEv2. Specifically, the tunnel encapsulators and decapsulators for all tunnel mode SAs created by IKEv2 MUST support the ECN full-functionality option for tunnels specified in [ECN], and they MUST implement the tunnel encapsulation and decapsulation processing specified in [IPSECARCH] so that ECN congestion indications don't get discarded ๐
2.25. Exchange Collisions ๐ฅ
Because IKEv2 exchanges can be started by either peer, it's possible for two exchanges affecting the same SA to partly overlap. This can leave the SA state information temporarily out of sync, and a peer might receive a request it can't process in the normal way ๐
Obviously, using a window size greater than 1 leads to more complicated situations, especially if requests get processed out of order. This section focuses on the problems that can come up even with a window size of 1, and it suggests solutions ๐งฉ
A TEMPORARY_FAILURE notification SHOULD be sent when a peer receives a request that can't be completed because of a temporary condition, such as a rekeying operation. When a peer receives a TEMPORARY_FAILURE notification, it MUST NOT immediately retry the operation. It MUST wait so the sender can finish whatever operation caused the temporary condition. The recipient MAY retry the request one or more times over a period of several minutes. If a peer keeps receiving TEMPORARY_FAILURE on the same IKE SA after several minutes, it SHOULD conclude that the state information is out of sync and close the IKE SA ๐ญ
A CHILD_SA_NOT_FOUND notification SHOULD be sent when a peer receives a request to rekey a Child SA that doesn't exist. The SA the initiator tried to rekey is indicated by the SPI field in the Notify payload, which is copied from the SPI field in the REKEY_SA notification. A peer that receives a CHILD_SA_NOT_FOUND notification SHOULD silently delete the Child SA (if it still exists) and send a request to create a new Child SA from scratch (if the Child SA doesn't exist yet) ๐
2.25.1. Collisions while Rekeying or Closing Child SAs
okay so what if both peers try to do Child SA stuff at the exact same time? ๐ญ if a peer gets a request to rekey a Child SA that it's currently trying to close, it SHOULD reply with TEMPORARY_FAILURE ๐ if it gets a request to rekey a Child SA that it's already rekeying, it SHOULD reply as usual, and SHOULD get ready to close the redundant SAs later based on the nonces (see Section 2.8.1) ๐ฆ and if the Child SA doesn't even exist, it SHOULD reply with CHILD_SA_NOT_FOUND ๐
now for closing. if a peer gets a request to close a Child SA it's already trying to close, it SHOULD reply without a Delete payload (see Section 1.4.1) โจ if it's currently rekeying that Child SA instead, it SHOULD reply as usual, with a Delete payload ๐ซถ and if the Child SA is already gone, it SHOULD reply without a Delete payload ๐
last one in this part: if a peer gets a request to rekey the IKE SA, and it's currently creating, rekeying, or closing a Child SA of that IKE SA, it SHOULD reply with TEMPORARY_FAILURE ๐ธ no cap, that's a lot of juggling!
2.25.2. Collisions while Rekeying or Closing IKE SAs
this one is the IKE SA version, bestie ๐ if a peer gets a request to rekey an IKE SA it's already rekeying, it SHOULD reply as usual, and SHOULD get ready to close redundant SAs and move inherited Child SAs later based on the nonces (see Section 2.8.2) ๐ฅ but if it's currently trying to close that IKE SA, it SHOULD reply with TEMPORARY_FAILURE ๐
if a peer gets a request to close an IKE SA it's currently rekeying, it SHOULD reply as usual, and forget about its own rekeying request ๐ฆ and if it gets a request to close an IKE SA it's already trying to close, it SHOULD reply as usual, and forget about its own close request ๐
finally, if a peer gets a request to create or rekey a Child SA while it's currently rekeying the IKE SA, it SHOULD reply with TEMPORARY_FAILURE ๐ญ but if the request is to delete a Child SA during that same IKE SA rekey, it SHOULD reply as usual, with a Delete payload โจ
3. Header and Payload Formats โจ
in the tables in this section, some cryptographic primitives and configuration attributes are marked as "UNSPECIFIED" ๐ these are items with no known specs, so interoperability is currently impossible. a future spec might describe how to use them, but until that happens, implementations SHOULD NOT try to use anything marked "UNSPECIFIED" if they want to be interoperable ๐ซถ
3.1. The IKE Header ๐
IKE messages use UDP ports 500 and/or 4500, with one IKE message per UDP datagram. basically everything from the start of the packet through the UDP header is mostly ignored, except the IP addresses and UDP ports get reversed and used for return packets ๐ฆ on UDP port 500, IKE messages begin right after the UDP header. on UDP port 4500, IKE messages have four octets of zeros prepended. those four zeros aren't part of the IKE message and don't count in any of the length fields or checksums defined by IKE ๐ธ
each IKE message begins with the IKE header, which this document calls HDR ๐ after the header come one or more IKE payloads, and each one is identified by a Next Payload field in the payload before it. so you go through the payloads in the order they appear by checking the Next Payload field in the IKE header, then the Next Payload field in each payload, until a Next Payload field of zero says there's nothing more ๐ง if you find an "Encrypted" payload, it gets decrypted and its contents get parsed as more payloads. an Encrypted payload MUST be the last payload in a packet, and an Encrypted payload MUST NOT contain another Encrypted payload ๐ฅ
the responder's SPI in the header identifies an instance of an IKE Security Association ๐ which means one IKE instance can juggle multiple sessions with multiple peers, including multiple sessions with the same peer ๐คฏ
all multi-octet fields representing integers are laid out in big endian order (also known as "most significant byte first", or "network byte order") ๐
the IKE header format looks 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 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 ๐
here's what each field does, bestie ๐
- Initiator's SPI (8 octets): a value chosen by the initiator to identify a unique IKE Security Association. this value MUST NOT be zero ๐
- Responder's SPI (8 octets): a value chosen by the responder to identify a unique IKE Security Association. this value MUST be zero in the first message of an IKE initial exchange (including repeats of that message including a cookie) ๐ธ
- Next Payload (1 octet): tells you what type of payload immediately follows the header. the format and value of each payload are defined below ๐ง
- Major Version (4 bits): the major version of the IKE protocol in use. implementations based on this version of IKE MUST set the major version to 2. implementations based on previous versions of IKE and ISAKMP MUST set the major version to 1. implementations based on this document's version (version 2) of IKE MUST reject or ignore messages containing a version number greater than 2 with an INVALID_MAJOR_VERSION notification message as described in Section 2.5 ๐ฅ
- Minor Version (4 bits): the minor version of the IKE protocol in use. implementations based on this version of IKE MUST set the minor version to 0. they MUST ignore the minor version number of received messages ๐
- Exchange Type (1 octet): the type of exchange being used. this constrains the payloads sent in each message in an exchange. the values in the following table are only current as of the publication date of RFC 4306. other values may have been added since then or will be added after the publication of this document. readers should refer to [IKEV2IANA] for the latest values ๐ฆ
Exchange Type Value
----------------------------------
IKE_SA_INIT 34
IKE_AUTH 35
CREATE_CHILD_SA 36
INFORMATIONAL 37
- Flags (1 octet): specific options set for the message. presence of an option is indicated by the appropriate bit in the flags field being set. the bits look like this:
+-+-+-+-+-+-+-+-+
|X|X|R|V|I|X|X|X|
+-+-+-+-+-+-+-+-+
in the description below, a bit being 'set' means its value is '1', while 'cleared' means its value is '0'. 'X' bits MUST be cleared when sending and MUST be ignored on receipt ๐
- R (Response): this bit indicates that this message is a response to a message containing the same Message ID. this bit MUST be cleared in all request messages and MUST be set in all responses. an IKE endpoint MUST NOT generate a response to a message that is marked as being a response (with one exception; see Section 2.21.2) ๐
- V (Version): this bit indicates that the transmitter is capable of speaking a higher major version number of the protocol than the one indicated in the major version number field. implementations of IKEv2 MUST clear this bit when sending and MUST ignore it in incoming messages ๐ธ
- I (Initiator): this bit MUST be set in messages sent by the original initiator of the IKE SA and MUST be cleared in messages sent by the original responder. it's used by the recipient to determine which eight octets of the SPI were generated by the recipient. this bit changes to reflect who initiated the last rekey of the IKE SA โจ
- Message ID (4 octets, unsigned integer): the message identifier used to control retransmission of lost packets and matching of requests and responses. it's essential to the security of the protocol because it's used to prevent message replay attacks. see Sections 2.1 and 2.2 ๐
- Length (4 octets, unsigned integer): the length of the total message (header + payloads) in octets ๐
3.2. Generic Payload Header โจ
okay bestie, every IKE payload from Sections 3.3 through 3.16 starts with the same generic payload header ๐ It's shown in Figure 5 below. Each payload's figure below will include this header too, but to keep things short, I'm not going to re-describe every field each time ๐
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload |C| RESERVED | Payload Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 5: Generic Payload Header
Here's the breakdown of the generic payload header fields ๐ฆ
- Next Payload (1 octet) - This is the identifier for the payload type of the next payload in the message ๐ If the current payload is the last one in the message, this field is 0. This is the "chaining" trick: you can tack on extra payloads by appending each one to the end of the message and setting the Next Payload field of the payload before it to point at the new payload's type ๐ The one 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 inside it. So in its header, the Next Payload field is set to the payload type of the first contained payload (instead of 0), and the Next Payload field of the last contained payload is set to zero ๐ The payload type values are listed in the table below. Heads up: those values are only current as of the publication date of RFC 4306. Other values may have been added since then, or will be added after this document comes out, so check [IKEV2IANA] for the latest ones ๐
Next Payload Type Notation Value
--------------------------------------------------
No Next Payload 0
Security Association SA 33
Key Exchange KE 34
Identification - Initiator IDi 35
Identification - Responder IDr 36
Certificate CERT 37
Certificate Request CERTREQ 38
Authentication AUTH 39
Nonce Ni, Nr 40
Notify N 41
Delete D 42
Vendor ID V 43
Traffic Selector - Initiator TSi 44
Traffic Selector - Responder TSr 45
Encrypted and Authenticated SK 46
Configuration CP 47
Extensible Authentication EAP 48
Payload type values 1-32 should not be assigned in the future, so there's no overlap with the code assignments for IKEv1 ๐
- Critical (1 bit) - This one is a whole mood ๐ฅ It MUST be set to zero if the sender wants the recipient to skip this payload when it doesn't understand the payload type code in the Next Payload field of the previous payload. It MUST be set to one if the sender wants the recipient to reject the entire message when it doesn't understand the payload type. The recipient MUST ignore it if they do understand the payload type. And for payload types defined in this document, it MUST be set to zero ๐ธ Quick note: the critical bit is about the current payload, not the "next" payload whose type code sits in the first octet, so don't mix those up ๐ญ The reason we don't set it for payloads defined in this document is that all implementations MUST understand all payload types defined here, so they have to ignore the critical bit's value anyway ๐ง Skipped payloads are expected to still have valid Next Payload and Payload Length fields. See Section 2.5 for more on this bit ๐
- RESERVED (7 bits) - These MUST be sent as zero, and MUST be ignored on receipt ๐ซถ
- Payload Length (2 octets, unsigned integer) - This is the length in octets of the current payload, including the generic payload header ๐ฆ
Lowkey the most important thing to remember: a lot of payloads have "RESERVED" fields, and some payloads (in IKEv2, and historically in IKEv1) aren't aligned to 4-octet boundaries. Don't assume everything lines up neatly ๐
3.3. Security Association Payload โจ
The Security Association payload, which we'll call SA in this doc, is how we negotiate the attributes of a Security Association ๐. Putting SA payloads together takes 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 contains a single IPsec protocol (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, and they're nested like a set of matryoshka dolls ๐ช. 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 all the complexity and hierarchy is so that multiple possible combinations of algorithms can be encoded in a single SA. Sometimes you get a choice of algorithms, and other times you get a combination of them. For example, an initiator might want to propose using ESP with either (3DES and HMAC_MD5) or (AES and HMAC_SHA1) ๐.
One of the reasons the semantics of the SA payload changed from ISAKMP and IKEv1 is to make the encodings more compact in common cases ๐ธ.
The Proposal structure contains a Proposal Num and an IPsec protocol ID. Each structure MUST have a proposal number one (1) greater than the previous structure. The first Proposal in the initiator's SA payload MUST have a Proposal Num of one (1) ๐ง. One reason to use multiple proposals is to offer both standard crypto ciphers and combined-mode ciphers. Combined-mode ciphers include both integrity and encryption in a single encryption algorithm, so they MUST either offer no integrity algorithm or a single integrity algorithm of "NONE", with no integrity algorithm being the RECOMMENDED method ๐. If an initiator wants to propose both combined-mode ciphers and normal ciphers, it must include two proposals: one has all the combined-mode ciphers, and the other has all the normal ciphers with the integrity algorithms.
For example, one such proposal would have two proposal structures. Proposal 1 is ESP with AES-128, AES-192, and AES-256 bits in Cipher Block Chaining (CBC) mode, with either HMAC-SHA1-96 or XCBC-96 as the integrity algorithm. Proposal 2 is AES-128 or AES-256 in GCM mode with an 8-octet Integrity Check Value (ICV) ๐. Both proposals allow the use of ESNs (Extended Sequence Numbers) but don't require them. Here's how it looks:
SA Payload
|
+--- Proposal #1 ( Proto ID = ESP(3), SPI size = 4,
| | 7 transforms, SPI = 0x052357bb )
| |
| +-- Transform ENCR ( Name = ENCR_AES_CBC )
| | +-- Attribute ( Key Length = 128 )
| |
| +-- Transform ENCR ( Name = ENCR_AES_CBC )
| | +-- Attribute ( Key Length = 192 )
| |
| +-- Transform ENCR ( Name = ENCR_AES_CBC )
| | +-- Attribute ( Key Length = 256 )
| |
| +-- Transform INTEG ( Name = AUTH_HMAC_SHA1_96 )
| +-- Transform INTEG ( Name = AUTH_AES_XCBC_96 )
| +-- Transform ESN ( Name = ESNs )
| +-- Transform ESN ( Name = No ESNs )
|
+--- Proposal #2 ( Proto ID = ESP(3), SPI size = 4,
| 4 transforms, SPI = 0x35a1d6f2 )
|
+-- Transform ENCR ( Name = AES-GCM with a 8 octet ICV )
| +-- Attribute ( Key Length = 128 )
|
+-- Transform ENCR ( Name = AES-GCM with a 8 octet ICV )
| +-- Attribute ( Key Length = 256 )
|
+-- Transform ESN ( Name = ESNs )
+-- Transform ESN ( Name = No ESNs )
Each Proposal/Protocol structure is followed by one or more transform structures. The number of different transforms is generally determined by the Protocol ๐งฉ. AH generally has two transforms: Extended Sequence Numbers (ESNs) and an integrity check algorithm. ESP generally has three: ESN, an encryption algorithm, and an integrity check algorithm. IKE generally has four: a Diffie-Hellman group, an integrity check algorithm, a PRF algorithm, and an encryption algorithm. For each Protocol, the set of permissible transforms is assigned Transform ID numbers, which show up in the header of each transform ๐ท๏ธ.
If there are multiple transforms with the same Transform Type, the proposal is an OR of those transforms. If there are multiple transforms with different Transform Types, the proposal is an AND of the different groups ๐. For example, to propose ESP with (3DES or AES-CBC) and (HMAC_MD5 or HMAC_SHA), the ESP proposal would contain two Transform Type 1 candidates (one for 3DES and one for AES-CBC) and two Transform Type 3 candidates (one for HMAC_MD5 and one for HMAC_SHA). That effectively proposes four combinations of algorithms. If the initiator only wanted a subset of those, like (3DES and HMAC_MD5) or (IDEA and HMAC_SHA), there's no way to encode that as multiple transforms within a single Proposal. Instead, the initiator would have to construct two different Proposals, each with two transforms ๐.
A given transform MAY have one or more Attributes. Attributes are necessary when the transform can be used in more than one way, like when an encryption algorithm has a variable key size. The transform specifies the algorithm and the attribute specifies the key size. Most transforms don't have attributes ๐ฏ. A transform MUST NOT have multiple attributes of the same type. To propose alternate values for an attribute (for example, multiple key sizes for the AES encryption algorithm), an 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
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Last Substruc | RESERVED | Proposal Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Proposal Num | Protocol ID | SPI Size |Num Transforms|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~ SPI (variable) ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ <Transforms> ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 7: Proposal Substructure
Last Substruc(1 octet) - Says whether or not this is the last Proposal Substructure in the SA. It's0if this was the last Proposal Substructure, and2if there are more Proposal Substructures. This syntax is inherited from ISAKMP, but it's kind of unnecessary, because the last Proposal could be identified from the length of the SA ๐. The value (2) corresponds to a payload type of Proposal in IKEv1, and the first four octets of the Proposal structure are designed to look somewhat like the header of a payload.RESERVED(1 octet) - MUST be sent as zero; MUST be ignored on receipt ๐ซ.Proposal Length(2 octets, unsigned integer) - Length of this proposal, including all transforms and attributes that follow ๐.Proposal Num(1 octet) - When a proposal is made, the first proposal in an SA payload MUST be 1, and subsequent proposals MUST be one more than the previous proposal (indicating an OR of the two proposals). When a proposal is accepted, the proposal number in the SA payload MUST match the number on the proposal sent that was accepted ๐ข.Protocol ID(1 octet) - Specifies the IPsec protocol identifier for the current negotiation. The values in the following table are only current as of the publication date of RFC 4306. Other values may have been added since then, or will be added after the publication of this document. Readers should refer to [IKEV2IANA] for the latest values ๐.
Protocol Protocol ID
-----------------------------------
IKE 1
AH 2
ESP 3
SPI Size(1 octet) - For an initial IKE SA negotiation, this field MUST be zero; the SPI is obtained from the outer header. During subsequent negotiations, it is equal to the size, in octets, of the SPI of the corresponding protocol (8 for IKE, 4 for ESP and AH) ๐.Num Transforms(1 octet) - Specifies the number of transforms in this proposal ๐ข.SPI(variable) - The sending entity's SPI. Even if the SPI Size is not a multiple of 4 octets, there is no padding applied to the payload. When the SPI Size field is zero, this field is not present in the Security Association payload ๐ซง.Transforms(variable) - One or more transform substructures ๐.
3.3.2. Transform Substructure ๐
Okay bestie, the transform substructure is where the actual crypto choices live, so let's get into it โจ
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Last Substruc | RESERVED | Transform Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Transform Type | RESERVED | Transform ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~ Transform Attributes ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 8: Transform Substructure
o Last Substruc (1 octet) - Specifies whether or not this is the last Transform Substructure in the Proposal. This field has a value of 0 if this was the last Transform Substructure, and a value of 3 if there are more Transform Substructures. This syntax is inherited from ISAKMP, but is unnecessary because the last transform could be identified from the length of the proposal. The value (3) corresponds to a payload type of Transform in IKEv1, and the first four octets of the Transform structure are designed to look somewhat like the header of a payload. ๐ธ
o RESERVED - MUST be sent as zero; MUST be ignored on receipt. ๐ซถ
o Transform Length - The length (in octets) of the Transform Substructure including Header and Attributes. ๐
o 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. ๐ฆ
o Transform ID (2 octets) - The specific instance of the Transform Type being proposed. ๐
The Transform Type values are listed below. The values in the following table are only current as of the publication date of RFC 4306. Other values may have been added since then or will be added after the publication of this document. Readers should refer to [IKEV2IANA] for the latest values.
Description Trans. Used In Type
Encryption Algorithm (ENCR) 1 IKE and ESP Pseudorandom Function (PRF) 2 IKE Integrity Algorithm (INTEG) 3 IKE*, AH, optional in ESP Diffie-Hellman Group (D-H) 4 IKE, optional in AH & ESP Extended Sequence Numbers (ESN) 5 AH and ESP
(*) Negotiating an integrity algorithm is mandatory for the Encrypted payload format specified in this document. For example, [AEAD] specifies additional formats based on authenticated encryption, in which a separate integrity algorithm is not negotiated. ๐ฅ
For Transform Type 1 (Encryption Algorithm), the Transform IDs are listed below. The values in the following table are only current as of the publication date of RFC 4306. Other values may have been added since then or will be added after the publication of this document. Readers should refer to [IKEV2IANA] for the latest values.
Name Number Defined In
ENCR_DES_IV64 1 (UNSPECIFIED) ENCR_DES 2 [RFC2405], [DES] ENCR_3DES 3 [RFC2451] ENCR_RC5 4 [RFC2451] ENCR_IDEA 5 [RFC2451], [IDEA] ENCR_CAST 6 [RFC2451] ENCR_BLOWFISH 7 [RFC2451] ENCR_3IDEA 8 (UNSPECIFIED) ENCR_DES_IV32 9 (UNSPECIFIED) ENCR_NULL 11 [RFC2410] ENCR_AES_CBC 12 [RFC3602] ENCR_AES_CTR 13 [RFC3686]
For Transform Type 2 (Pseudorandom Function), the Transform IDs are listed below. The values in the following table are only current as of the publication date of RFC 4306. Other values may have been added since then or will be added after the publication of this document. Readers should refer to [IKEV2IANA] for the latest values.
Name Number Defined In
PRF_HMAC_MD5 1 [RFC2104], [MD5] PRF_HMAC_SHA1 2 [RFC2104], [FIPS.180-4.2012] PRF_HMAC_TIGER 3 (UNSPECIFIED)
For Transform Type 3 (Integrity Algorithm), defined Transform IDs are listed below. The values in the following table are only current as of the publication date of RFC 4306. Other values may have been added since then or will be added after the publication of this document. Readers should refer to [IKEV2IANA] for the latest values.
Name Number Defined In
NONE 0 AUTH_HMAC_MD5_96 1 [RFC2403] AUTH_HMAC_SHA1_96 2 [RFC2404] AUTH_DES_MAC 3 (UNSPECIFIED) AUTH_KPDK_MD5 4 (UNSPECIFIED) AUTH_AES_XCBC_96 5 [RFC3566]
For Transform Type 4 (Diffie-Hellman group), defined Transform IDs are listed below. The values in the following table are only current as of the publication date of RFC 4306. Other values may have been added since then or will be added after the publication of this document. Readers should refer to [IKEV2IANA] for the latest values.
Name Number Defined In
NONE 0 768-bit MODP Group 1 Appendix B 1024-bit MODP Group 2 Appendix B 1536-bit MODP Group 5 [ADDGROUP] 2048-bit MODP Group 14 [ADDGROUP] 3072-bit MODP Group 15 [ADDGROUP] 4096-bit MODP Group 16 [ADDGROUP] 6144-bit MODP Group 17 [ADDGROUP] 8192-bit MODP Group 18 [ADDGROUP]
Although ESP and AH do not directly include a Diffie-Hellman exchange, a Diffie-Hellman group MAY be negotiated for the Child SA. This allows the peers to employ Diffie-Hellman in the CREATE_CHILD_SA exchange, providing perfect forward secrecy for the generated Child SA keys. โจ
Note that the MODP Diffie-Hellman groups listed above do not need any special validity tests to be performed, but other types of groups (elliptic curve groups, and MODP groups with small subgroups) need to have some additional tests performed on them to use them securely. See "Additional Diffie-Hellman Tests for IKEv2" ([RFC6989]) for more information. ๐ง
For Transform Type 5 (Extended Sequence Numbers), defined Transform IDs are listed below. The values in the following table are only current as of the publication date of RFC 4306. Other values may have been added since then or will be added after the publication of this document. Readers should refer to [IKEV2IANA] for the latest values.
Name Number
No Extended Sequence Numbers 0 Extended Sequence Numbers 1
Note that an initiator who supports ESNs will usually include two ESN transforms, with values "0" and "1", in its proposals. A proposal containing a single ESN transform with value "1" means that using normal (non-extended) sequence numbers is not acceptable. ๐
Numerous additional Transform Types have been defined since the publication of RFC 4306. Please refer to the IANA "Internet Key Exchange Version 2 (IKEv2) Parameters" registry for details. ๐
3.3.3. Valid Transform Types by Protocol ๐
Here's the lowdown on which transform types each protocol needs, no cap ๐ญ
The number and type of transforms that accompany an SA payload are dependent on the protocol in the SA itself. An SA payload proposing the establishment of an SA has the following mandatory and optional Transform Types. A compliant implementation MUST understand all mandatory and optional types for each protocol it supports (though it 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
(*) Negotiating an integrity algorithm is mandatory for the Encrypted payload format specified in this document. For example, [AEAD] specifies additional formats based on authenticated encryption, in which a separate integrity algorithm is not negotiated. ๐
3.3.4. Mandatory Transform IDs ๐
Okay so this part is about which suites you have to support, and it's giving "the list is changing too fast to put in here" ๐
The specification of suites that MUST and SHOULD be supported for interoperability has been removed from this document because they are likely to change more rapidly than this document evolves. At the time of publication of this document, [RFC4307] specifies these suites, but note that it might be updated in the future, and other RFCs might specify different sets of suites. ๐
An important lesson learned from IKEv1 is that no system should only implement the mandatory algorithms and expect them to be the best choice for all customers. ๐ฆ
It is likely that IANA will add additional transforms in the future, and some users may want to use private suites, especially for IKE where implementations should be capable of supporting different parameters, up to certain size limits. In support of this goal, all implementations of IKEv2 SHOULD include a management facility that allows specification (by a user or system administrator) of Diffie-Hellman parameters (the generator, modulus, and exponent lengths and values) for new Diffie-Hellman groups. Implementations SHOULD provide a management interface through which these parameters and the associated Transform IDs may be entered (by a user or system administrator), to enable negotiating such groups. โจ
All implementations of IKEv2 MUST include a management facility that enables a user or system administrator to specify the suites that are acceptable for use with IKE. Upon receipt of a payload with a set of Transform IDs, the implementation MUST compare the transmitted Transform IDs against those locally configured via the management controls, to verify that the proposed suite is acceptable based on local policy. The implementation MUST reject SA proposals that are not authorized by these IKE suite controls. Note that cryptographic suites that MUST be implemented need not be configured as acceptable to local policy. ๐ซถ
Heads up: the MUSTs and SHOULDs in this section are the important ones, so don't skip them ๐
3.3.5. Transform Attributes ๐
okay so every transform in a Security Association payload can bring along attributes that tweak or finish off its spec ๐ which attributes are valid totally depends on the transform. rn there's only ONE attribute type defined: Key Length โจ, used by certain encryption transforms with variable-length keys (more on that below ๐ฆ).
Attributes are type/value pairs. Some have a fixed two-octet value, and others have a variable-length value. 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
Wait, I need to keep the figure exact, so here's the whole thing, character for character ๐
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|A| Attribute Type | AF=0 Attribute Length |
|F| | AF=1 Attribute Value |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| AF=0 Attribute Value |
| AF=1 Not Transmitted |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 9: Data Attributes ๐ง
- Attribute Format (AF) (1 bit) - tells you whether the data attribute uses the Type/Length/Value (TLV) format or the shorter Type/Value (TV) format. If AF is zero (0), the attribute uses TLV. If AF is one (1), it uses TV, with a two-byte value ๐
- Attribute Type (15 bits) - the unique ID for each type of attribute (see below) ๐
- Attribute Value (variable length) - the value that goes with the attribute type. If AF is a zero (0), this field's length comes from the Attribute Length field. If AF is a one (1), the Attribute Value is 2 octets long ๐
The only currently defined attribute type (Key Length) is fixed length. The variable-length encoding spec is only there for future extensions ๐ฎ Attributes described as fixed length MUST NOT be encoded using the variable-length encoding unless that length exceeds two bytes. Variable-length attributes MUST NOT be encoded as fixed-length, even if their value fits into two octets. Note: this is a change from IKEv1, where the flexibility may have made the composer's life easier but definitely made the parser's life harder ๐
The values in the table below are only current as of the publication date of RFC 4306. Other values may have been added since then, or will be added after this document is published. Readers should check [IKEV2IANA] for the latest values ๐
Attribute Type Value Attribute Format
------------------------------------------------------------
Key Length (in bits) 14 TV
Values 0-13 and 15-17 were used in a similar context in IKEv1, and should not be assigned except to matching values ๐
The Key Length attribute gives the key length in bits (it MUST use network byte order) for certain transforms, like so ๐
- The Key Length attribute MUST NOT be used with transforms that use a fixed-length key. For example, this includes ENCR_DES, ENCR_IDEA, and all the Type 2 (Pseudorandom Function) and Type 3 (Integrity Algorithm) transforms specified in this document. It is recommended that future Type 2 or 3 transforms do not use this attribute ๐ซถ
- Some transforms say the Key Length attribute MUST always be included. Leaving it out isn't allowed, and proposals that don't contain it MUST be rejected. For example, this includes ENCR_AES_CBC and ENCR_AES_CTR ๐ญ
- Some transforms allow variable-length keys but also specify a default key length if the attribute isn't included. For example, these transforms include ENCR_RC5 and ENCR_BLOWFISH ๐ฆ
Implementation note: to support interoperability and let endpoints upgrade independently, implementers of this protocol SHOULD accept values that they deem to supply greater security. For instance, if a peer is configured to accept a variable-length cipher with a key length of X bits and gets offered that cipher with a bigger key length, the implementation SHOULD accept the offer if it supports using the longer key ๐ฅ
This capability lets a responder express a concept of "at least" a certain level of security: "a key length of at least X bits for cipher Y" โจ However, the attribute always comes back unchanged (see the next section), so an initiator willing to accept multiple key lengths has to include multiple transforms with the same Transform Type, each with a different Key Length attribute ๐
3.3.6. Attribute Negotiation ๐ธ
During Security Association negotiation, initiators present offers to responders. Responders MUST select a single complete set of parameters from the offers (or reject all of them if none are acceptable) ๐ If there are multiple proposals, the responder MUST choose a single proposal. If the selected proposal has multiple transforms with the same type, the responder MUST choose a single one. Any attributes of a selected transform MUST be returned unmodified. The initiator of an exchange MUST check that the accepted offer is consistent with one of its proposals, and if it isn't, the initiator MUST terminate the exchange ๐ฑ
If the responder gets a proposal containing a Transform Type it doesn't understand, or a proposal missing a mandatory Transform Type, it MUST consider that proposal unacceptable. Other proposals in the same SA payload still get processed as usual ๐ง Similarly, if the responder gets a transform it doesn't understand, or one containing a Transform Attribute it doesn't understand, it MUST consider that transform unacceptable. Other transforms with the same Transform Type are processed as usual. This is what lets new Transform Types and Transform Attributes get defined in the future ๐ฎ
Negotiating Diffie-Hellman groups is a bit of a special challenge, bestie ๐ฅน SA offers include proposed attributes and a Diffie-Hellman public number (KE) in the same message. If, in the initial exchange, the initiator offers to use one of several Diffie-Hellman groups, it SHOULD pick the one the responder is most likely to accept, and include a KE for that group. If the responder selects a proposal using a different Diffie-Hellman group (other than NONE), the responder will indicate the correct group in the response, and the initiator SHOULD pick an element of that group for its KE value when retrying the first message. It SHOULD, however, keep proposing its full supported set of groups, to prevent a man-in-the-middle downgrade attack ๐จ If one of the proposals offered is for the Diffie-Hellman group NONE, and the responder selects that group, then it MUST ignore the initiator's KE payload and omit the KE payload from the response ๐
3.4. Key Exchange Payload ๐
The Key Exchange payload, denoted KE in this document, is used to swap Diffie-Hellman public numbers as part of a Diffie-Hellman 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 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Diffie-Hellman Group Num | 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 of the payload. For MODP groups, the length of the Diffie-Hellman public value MUST equal the length of the prime modulus the exponentiation was done over, prepending zero bits to the value if needed ๐ข
The Diffie-Hellman Group Num tells you which Diffie-Hellman group the Key Exchange Data was computed in (see Section 3.3.2). This Diffie-Hellman Group Num MUST match a Diffie-Hellman group specified in a proposal in the SA payload sent in the same message, and SHOULD match the Diffie-Hellman group in the first group of the first proposal, if one exists. If none of the proposals in that SA payload specifies a Diffie-Hellman group, the KE payload MUST NOT be present. If the selected proposal uses a different Diffie-Hellman group (other than NONE), the message MUST be rejected with a Notify payload of type INVALID_KE_PAYLOAD. See also Sections 1.2 and 2.7 โญ
The payload type for the Key Exchange payload is thirty-four (34) ๐
3.5. Identification Payloads ๐
Okay so the Identification payloads (we write them as IDi and IDr in this doc) are how peers say "hey, this is who I am" ๐ซถ. That identity can be used for policy lookup, but it doesn't have to match anything in the CERT payload. Both fields can be used by an implementation to make access control decisions ๐ . When you use the ID_IPV4_ADDR/ID_IPV6_ADDR identity types in IDi/IDr payloads, IKEv2 does not require this address to match the address in the IP header of IKEv2 packets, or anything in the TSi/TSr payloads. The contents of IDi/IDr are used purely to fetch the policy and authentication data related to the other party. Main character energy, but only for that one job โจ.
NOTE: In IKEv1, two ID payloads were used in each direction to hold Traffic Selector (TS) information for data passing over the SA. In IKEv2, this information is carried in TS payloads (see Section 3.13). ๐
The Peer Authorization Database (PAD) as described in RFC 4301 [IPSECARCH] explains how the ID payload is used in IKEv2. It gives a formal model for binding identity to policy, and it also offers services that handle the nitty-gritty of policy enforcement ๐ฅ. The PAD is meant to link the SPD and the IKE Security Association management. See Section 4.4.3 of RFC 4301 for more details.
The Identification payload is the IKE generic payload header followed by these identification fields ๐ง:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload |C| RESERVED | Payload Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| ID Type | RESERVED |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Identification Data ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 11: Identification Payload Format
- ID Type (1 octet) - Specifies the type of Identification being used.
- RESERVED - MUST be sent as zero; MUST be ignored on receipt.
- Identification Data (variable length) - Value, as indicated by the Identification Type. The length of the Identification Data is computed from the size in the ID payload header.
The payload types for the Identification payload are thirty-five (35) for IDi and thirty-six (36) for IDr ๐ธ.
Here's the table of assigned semantics for the Identification Type field. Heads up: these values were only current as of the publication date of RFC 4306. Other values may have been added since then, or will be added after this document is published. Readers should check [IKEV2IANA] for the latest values ๐.
ID Type Value
-------------------------------------------------------------------
ID_IPV4_ADDR 1
A single four (4) octet IPv4 address.
ID_FQDN 2
A fully-qualified domain name string. An example of an ID_FQDN
is "example.com". The string MUST NOT contain any terminators
(e.g., NULL, CR, etc.). All characters in the ID_FQDN are ASCII;
for an "internationalized domain name", the syntax is as defined
in [IDNA], for example "xn--tmonesimerkki-bfbb.example.net".
ID_RFC822_ADDR 3
A fully-qualified RFC 822 email address string. An example of a
ID_RFC822_ADDR is "jsmith@example.com". The string MUST NOT
contain any terminators. Because of [EAI], implementations would
be wise to treat this field as UTF-8 encoded text, not as
pure ASCII.
ID_IPV6_ADDR 5
A single sixteen (16) octet IPv6 address.
ID_DER_ASN1_DN 9
The binary Distinguished Encoding Rules (DER) encoding of an
ASN.1 X.500 Distinguished Name [PKIX].
ID_DER_ASN1_GN 10
The binary DER encoding of an ASN.1 X.509 GeneralName [PKIX].
ID_KEY_ID 11
An opaque octet stream that may be used to pass vendor-
specific information necessary to do certain proprietary
types of identification.
Two implementations will only interoperate if each one can generate a type of ID that the other accepts ๐ค. 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 four types. Implementations SHOULD be capable of generating and accepting all of these types. IPv6-capable implementations MUST additionally be configurable to accept ID_IPV6_ADDR. IPv6-only implementations MAY be configurable to send only ID_IPV6_ADDR instead of ID_IPV4_ADDR for IP addresses ๐ฆ.
EAP [EAP] doesn't mandate any particular identifier type, but EAP is often used with Network Access Identifiers (NAIs) defined in [NAI] ๐. NAIs look a bit like email addresses (think "joe@example.com"), but the syntax isn't exactly the same as the email address syntax in [MAILFORMAT]. For NAIs that include the realm component, the ID_RFC822_ADDR identification type SHOULD be used. Responder implementations should not attempt to verify that the contents actually conform to the exact syntax given in [MAILFORMAT], but instead should accept any reasonable-looking NAI. For NAIs that do not include the realm component, the ID_KEY_ID identification type SHOULD be used.
For more on matching Identification payloads with the contents of the PKIX Certificates, see "The Internet IP Security PKI Profile of IKEv1/ISAKMP, IKEv2, and PKIX" ([RFC4945]) ๐.
3.6. Certificate Payload ๐
The Certificate payload (we call it CERT in this doc) is how IKE carries certificates or other authentication-related info ๐. Certificate payloads SHOULD be included in an exchange if the sender has certificates available. The Hash and URL formats of the Certificate payloads should be used in case the peer has indicated it can retrieve this information from elsewhere using an HTTP_CERT_LOOKUP_SUPPORTED Notify payload. Also, the name "Certificate payload" is kind of misleading ๐, because not every authentication mechanism uses certificates, and data other than certificates may be passed in this payload.
Here's how the Certificate payload is laid out:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload |C| RESERVED | Payload Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Cert Encoding | |
+-+-+-+-+-+-+-+-+ |
~ Certificate Data ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 12: Certificate Payload Format
- Certificate Encoding (1 octet) - This field indicates the type of certificate or certificate-related information contained in the Certificate Data field. The values in the following table are only current as of the publication date of RFC 4306. Other values may have been added since then, or will be added after this document is published. Readers should refer to [IKEV2IANA] for the latest values.
Certificate Encoding Value
----------------------------------------------------
PKCS #7 wrapped X.509 certificate 1 UNSPECIFIED
PGP Certificate 2 UNSPECIFIED
DNS Signed Key 3 UNSPECIFIED
X.509 Certificate - Signature 4
Kerberos Token 6 UNSPECIFIED
Certificate Revocation List (CRL) 7
Authority Revocation List (ARL) 8 UNSPECIFIED
SPKI Certificate 9 UNSPECIFIED
X.509 Certificate - Attribute 10 UNSPECIFIED
Deprecated (was Raw RSA Key) 11 DEPRECATED
Hash and URL of X.509 certificate 12
Hash and URL of X.509 bundle 13
- Certificate Data (variable length) - Actual encoding of certificate data. The type of certificate is indicated by the Certificate Encoding field.
The payload type for the Certificate payload is thirty-seven (37) ๐.
This document doesn't define the specific syntax for some of the certificate type codes above. The types whose syntax is defined here are:
- "X.509 Certificate - Signature" contains a DER-encoded X.509 certificate whose public key is used to validate the sender's AUTH payload. Note that with this encoding, if a chain of certificates needs to be sent, multiple CERT payloads are used, and only the first of them holds the public key used to validate the sender's AUTH payload.
- "Certificate Revocation List" contains a DER-encoded X.509 certificate revocation list.
- Hash and URL encodings keep IKE messages short by replacing long data structures with a 20-octet SHA-1 hash (see [FIPS.180-4.2012]) of the replaced value, followed by a variable-length URL that resolves to the DER-encoded data structure itself. This is more efficient when the endpoints have certificate data cached, and it makes IKE less subject to DoS attacks that get easier to pull off when IKE messages are big enough to need IP fragmentation [DOSUDPPROT] ๐ก๏ธ.
The "Hash and URL of a bundle" type uses the following ASN.1 definition for the X.509 bundle ๐งพ:
CertBundle
{ iso(1) identified-organization(3) dod(6) internet(1)
security(5) mechanisms(5) pkix(7) id-mod(0)
id-mod-cert-bundle(34) }
DEFINITIONS EXPLICIT TAGS ::=
BEGIN
IMPORTS
Certificate, CertificateList
FROM PKIX1Explicit88
{ iso(1) identified-organization(3) dod(6)
internet(1) security(5) mechanisms(5) pkix(7)
id-mod(0) id-pkix1-explicit(18) } ;
CertificateOrCRL ::= CHOICE {
cert [0] Certificate,
crl [1] CertificateList }
CertificateBundle ::= SEQUENCE OF CertificateOrCRL
END
Implementations MUST be capable of being configured to send and accept up to four X.509 certificates in support of authentication. They MUST ALSO be capable of being configured to send and accept the two Hash and URL formats (with HTTP URLs). Wait, correction, to keep this exact: implementations MUST be capable of being configured to send and accept the two Hash and URL formats (with HTTP URLs). If multiple certificates are sent, the first certificate MUST contain the public key associated with the private key used to sign the AUTH payload. The other certificates may be sent in any order โจ.
Implementations MUST support the "http:" scheme for hash-and-URL lookup ๐ธ. The behavior of other URL schemes [URLS] is not currently specified, and such schemes SHOULD NOT be used in the absence of a document specifying them.
3.7. Certificate Request Payload โจ
Okay bestie, the Certificate Request payload (CERTREQ ๐) is how you ask for your preferred certificates over IKE. It can show up in the IKE_INIT_SA response and/or the IKE_AUTH request. Certificate Request payloads MAY be included in an exchange when the sender needs to get the receiver's certificate ๐ซถ
The layout is:
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 one is encoded as the SHA-1 hash of the Subject Public Key Info element (see Section 4.1.2.7 of [PKIX]) from each Trust Anchor certificate. The 20-octet hashes are concatenated and included with no other formatting. ๐ฅ
The contents of the Certification Authority field are defined only for X.509 certificates, which are types 4, 12, and 13. Other values SHOULD NOT be used until Standards-Track specifications that specify their use are published. ๐
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 figure out whether the processor has any certificates of this type. If it does, the Certification Authority field is inspected to see whether 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 block communication by strictly sticking to a certificate chosen from the CERTREQ, when an alternate certificate could be selected by the sender that would still let the recipient successfully validate and trust it through trust conveyed by cross-certification, CRLs, or other out-of-band configured means. So 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 a preferred CA is sent in the CERTREQ, but an alternate might be acceptable (perhaps after prompting a human operator). ๐
The HTTP_CERT_LOOKUP_SUPPORTED notification MAY be included in any message that can include a CERTREQ payload. It indicates that the sender is capable of looking up certificates based on an HTTP-based URL (and so presumably would prefer to receive certificate specifications in that format) ๐
3.8. Authentication Payload ๐
The Authentication payload, denoted AUTH in this document, carries data used for authentication purposes. The syntax of the Authentication Data changes depending on the Auth Method, as specified below. ๐
The layout is:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload |C| RESERVED | Payload Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Auth Method | RESERVED |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Authentication Data ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 14: Authentication Payload Format ๐ธ
- Auth Method (1 octet) - Specifies the method of authentication used. The types of signatures are listed here. The values in the following table are only current as of the publication date of RFC 4306. Other values may have been added since then or will be added after the publication of this document. Readers should refer to [IKEV2IANA] for the latest values. ๐
Mechanism Value
-----------------------------------------------------------------
RSA Digital Signature 1
Shared Key Message Integrity Code 2
DSS Digital Signature 3
Here's what each mechanism looks like ๐
RSA Digital Signature (1): Computed as specified in Section 2.15 using an RSA private key with the RSASSA-PKCS1-v1_5 signature scheme specified in [PKCS1]. Implementers should note that IKEv1 used a different method for RSA signatures. To promote interoperability, implementations that support this type SHOULD support signatures that use SHA-1 as the hash function, and SHOULD use SHA-1 as the default hash function when generating signatures. Implementations can use the certificates received from a given peer as a hint for selecting a mutually understood hash function for the AUTH payload signature. Note, however, that the hash algorithm used in the AUTH payload signature doesn't have to be the same as any hash algorithm(s) used in the certificate(s). โจ
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. ๐
DSS Digital Signature (3): Computed as specified in Section 2.15 using a DSS private key (see [DSS]) over a SHA-1 hash. ๐งฉ
- RESERVED - MUST be sent as zero; MUST be ignored on receipt. ๐ โโ๏ธ
- Authentication Data (variable length) - see Section 2.15. ๐
The payload type for the Authentication payload is thirty-nine (39) ๐ฆ
3.9. Nonce Payload ๐
The Nonce payload, denoted as Ni and Nr in this document for the initiator's and responder's nonce respectively, contains random data used to guarantee liveness during an exchange and to protect against replay attacks. Main character energy ๐
The layout is:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload |C| RESERVED | Payload Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Nonce Data ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 15: Nonce Payload Format ๐ธ
- Nonce Data (variable length) - Contains the random data generated by the transmitting entity. ๐
The payload type for the Nonce payload is forty (40) ๐ง
The size of the Nonce Data MUST be between 16 and 256 octets, inclusive. Nonce values MUST NOT be reused. ๐จ
3.10. Notify Payload ๐
Okay so the Notify payload (we call it N in this doc ๐ ) is how an IKE peer passes along informational stuff, like error conditions and state transitions. It can show up in a response (usually to explain why a request got rejected ๐), in an INFORMATIONAL exchange (to report an error that wasn't in an IKE request), or in any other message to flag sender capabilities or tweak what the request means โจ
The layout looks 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 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Protocol ID | SPI Size | Notify Message Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Security Parameter Index (SPI) ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Notification Data ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 16: Notify Payload Format
- Protocol ID (1 octet) - If this notification concerns an existing SA whose SPI is given in the SPI field, this field indicates the type of that SA. For notifications concerning Child SAs, this field MUST contain either (2) to indicate AH or (3) to indicate ESP. Of the notifications defined in this document, the SPI is included only with INVALID_SELECTORS, REKEY_SA, and CHILD_SA_NOT_FOUND. If the SPI field is empty, this field MUST be sent as zero and MUST be ignored on receipt.
- SPI Size (1 octet) - Length in octets of the SPI as defined by the IPsec protocol ID or zero if no SPI is applicable. For a notification concerning the IKE SA, the SPI Size MUST be zero and the field must be empty.
- Notify Message Type (2 octets) - Specifies the type of notification message.
- SPI (variable length) - Security Parameter Index.
- Notification Data (variable length) - Status or error data transmitted in addition to the Notify Message Type. Values for this field are type specific (see below).
The payload type for the Notify payload is forty-one (41) ๐
3.10.1. Notify Message Types ๐จ
Notification info can be error messages explaining why an SA couldn't be established ๐ญ It can also be status data that a process managing an SA database wants to share with a peer process ๐ง
The table below lists the notification messages and their 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 for reporting errors. An implementation receiving a Notify payload with one of these types that it does not recognize in a response MUST assume that the corresponding request has failed entirely. Unrecognized error types in a request and status types in a request or response MUST be ignored, and they should be logged.
Notify payloads with status types MAY be added to any message and MUST be ignored if not recognized. They are intended to indicate capabilities, and as part of SA negotiation, are used to negotiate non-cryptographic parameters. ๐
More info on error handling is in Section 2.21.
The values in the following table are only current as of the publication date of RFC 4306, plus two error types added in this document. Other values may have been added since then or will be added after the publication of this document. Readers should refer to [IKEV2IANA] for the latest values.
NOTIFY messages: error types Value
-------------------------------------------------------------------
UNSUPPORTED_CRITICAL_PAYLOAD 1
See Section 2.5.
INVALID_IKE_SPI 4
See Section 2.21.
INVALID_MAJOR_VERSION 5
See Section 2.5.
INVALID_SYNTAX 7
Indicates the IKE message that was received was invalid because
some type, length, or value was out of range or because the
request was rejected for policy reasons. To avoid a DoS
attack using forged messages, this status may only be
returned for and in an encrypted packet if the Message ID and
cryptographic checksum were valid. To avoid leaking information
to someone probing a node, this status MUST be sent in response
to any error not covered by one of the other status types.
To aid debugging, more detailed error information should be
written to a console or log.
INVALID_MESSAGE_ID 9
See Section 2.3.
INVALID_SPI 11
See Section 1.5.
NO_PROPOSAL_CHOSEN 14
None of the proposed crypto suites was acceptable. This can be
sent in any case where the offered proposals (including but not
limited to SA payload values, USE_TRANSPORT_MODE notify,
IPCOMP_SUPPORTED notify) are not acceptable for the responder.
This can also be used as "generic" Child SA error when Child SA
cannot be created for some other reason. See also Section 2.7.
INVALID_KE_PAYLOAD 17
See Sections 1.2 and 1.3.
AUTHENTICATION_FAILED 24
Sent in the response to an IKE_AUTH message when, for some
reason, the authentication failed. There is no associated
data. See also Section 2.21.2.
SINGLE_PAIR_REQUIRED 34
See Section 2.9.
NO_ADDITIONAL_SAS 35
See Section 1.3.
INTERNAL_ADDRESS_FAILURE 36
See Section 3.15.4.
FAILED_CP_REQUIRED 37
See Section 2.19.
TS_UNACCEPTABLE 38
See Section 2.9.
INVALID_SELECTORS 39
MAY be sent in an IKE INFORMATIONAL exchange when a node receives
an ESP or AH packet whose selectors do not match those of the SA
on which it was delivered (and that caused the packet to be
dropped). The Notification Data contains the start of the
offending packet (as in ICMP messages) and the SPI field of the
notification is set to match the SPI of the Child SA.
TEMPORARY_FAILURE 43
See Section 2.25.
CHILD_SA_NOT_FOUND 44
See Section 2.25.
NOTIFY messages: status types Value
-------------------------------------------------------------------
INITIAL_CONTACT 16384
See Section 2.4.
SET_WINDOW_SIZE 16385
See Section 2.3.
ADDITIONAL_TS_POSSIBLE 16386
See Section 2.9.
IPCOMP_SUPPORTED 16387
See Section 2.22.
NAT_DETECTION_SOURCE_IP 16388
See Section 2.23.
NAT_DETECTION_DESTINATION_IP 16389
See Section 2.23.
COOKIE 16390
See Section 2.6.
USE_TRANSPORT_MODE 16391
See Section 1.3.1.
HTTP_CERT_LOOKUP_SUPPORTED 16392
See Section 3.6.
REKEY_SA 16393
See Section 1.3.3.
ESP_TFC_PADDING_NOT_SUPPORTED 16394
See Section 1.3.1.
NON_FIRST_FRAGMENTS_ALSO 16395
See Section 1.3.1.
3.11. Delete Payload ๐งน
The Delete payload (denoted D in this doc ๐) carries a protocol-specific Security Association identifier that the sender has removed from its Security Association database, so it's no longer valid ๐ฆ You can send multiple SPIs in one Delete payload, but each SPI MUST be for the same protocol. Mixing protocol identifiers MUST NOT be done in the Delete payload ๐ โโ๏ธ It's allowed, though, to include multiple Delete payloads in a single INFORMATIONAL exchange where each one lists SPIs for a different protocol โจ Figure 17 shows the format.
Deleting the IKE SA is signalled by a protocol ID of 1 (IKE) with no SPIs. Deleting 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 | Num 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.
- Num of SPIs (2 octets, unsigned integer) - The number of SPIs contained in the Delete payload. The size of each SPI is defined by the SPI Size field.
- Security Parameter Index(es) (variable length) - Identifies the specific Security Association(s) to delete. The length of this field is determined by the SPI Size and Num of SPIs fields.
The payload type for the Delete payload is forty-two (42) ๐
3.12. Vendor ID Payload ๐
okay so the Vendor ID payload (we call it V in this doc) holds a vendor-defined constant ๐ vendors use it to spot and recognize remote instances of their own implementations ๐ซถ and it's lowkey genius because it lets a vendor test new features while staying backward compatible โจ
A Vendor ID payload MAY announce that the sender can accept certain extensions to the protocol, or it MAY just name the implementation as a debugging aid ๐ A Vendor ID payload MUST NOT change the interpretation of any information defined in this specification (aka the critical bit MUST be set to 0) ๐ โโ๏ธ Multiple Vendor ID payloads MAY be sent ๐ธ and no implementation is required to send any Vendor ID payload at all, bestie ๐
A Vendor ID payload can be sent as part of any message ๐ When you get a familiar Vendor ID payload, you can use the private use numbers described throughout this document, like private payloads, private exchanges, private notifications, etc. ๐ง Unfamiliar Vendor IDs MUST be ignored ๐
Writers of documents who want to extend this protocol MUST define a Vendor ID payload to announce the ability to implement the extension in the document ๐ documents 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 goes away ๐ iconic glow-up behavior ๐
The Vendor ID payload fields look like this:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload |C| RESERVED | Payload Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Vendor ID (VID) ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 18: Vendor ID Payload Format ๐ฆ
- Vendor ID (variable length) - It is the responsibility of the person choosing the Vendor ID to make sure it's unique even though there's no central registry for IDs ๐ Good practice is to include a company name, a person name, or some such info. If you want to show off, you might include the latitude, longitude, and time where you were when you picked the ID, plus 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 document, lets peers identify packet flows for processing by IPsec security services ๐ก๏ธ It's made 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 ๐
There's no requirement that TSi and TSr contain the same number of individual Traffic Selectors ๐ So they're interpreted like this: a packet matches a given TSi/TSr if it matches at least one of the individual selectors in TSi, and at least one of the individual selectors in TSr ๐
For instance, the following Traffic Selectors:
TSi = ((17, 100, 198.51.100.66-198.51.100.66),
(17, 200, 198.51.100.66-198.51.100.66))
TSr = ((17, 300, 0.0.0.0-255.255.255.255),
(17, 400, 0.0.0.0-255.255.255.255))
would match UDP packets from 198.51.100.66 to anywhere, with any of the four combinations of source/destination ports (100,300), (100,400), (200,300), and (200, 400) ๐ฆ
Thus, some types of policies may require several Child SA pairs ๐ For instance, a policy matching only source/destination ports (100,300) and (200,400), but not the other two combinations, cannot be negotiated as a single Child SA pair ๐
3.13.1. Traffic Selector โจ
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| TS Type |IP Protocol ID*| Selector Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Start Port* | End Port* |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Starting Address* ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Ending Address* ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 20: Traffic Selector ๐ฅ
Note: All fields other than TS Type and Selector Length depend on the TS Type. The fields shown are for TS Types 7 and 8, the only two values currently defined.
- TS Type (one octet) - Specifies the type of Traffic Selector ๐ท๏ธ
- IP protocol ID (1 octet) - Value specifying an associated IP protocol ID (such as UDP, TCP, and 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 (2 octets, unsigned integer) - Specifies the length of this Traffic Selector substructure including the header ๐
- Start Port (2 octets, unsigned integer) - Value specifying the smallest port number allowed by this Traffic Selector. For protocols for which port is undefined (including protocol 0), or if all ports are allowed, this field MUST be zero. ICMP and ICMPv6 Type and Code values, as well as Mobile IP version 6 (MIPv6) mobility header (MH) Type values, are represented in this field as specified in Section 4.4.1.1 of [IPSECARCH]. ICMP Type and Code values are treated as a single 16-bit integer port number, with Type in the most significant eight bits and Code in the least significant eight bits. MIPv6 MH Type values are treated as a single 16-bit integer port number, with Type in the most significant eight bits and the least significant eight bits set to zero. ๐ง
- End Port (2 octets, unsigned integer) - Value specifying the largest port number allowed by this Traffic Selector. For protocols for which port is undefined (including protocol 0), or if all ports are allowed, this field MUST be 65535. ICMP and ICMPv6 Type and Code values, as well as MIPv6 MH Type values, are represented in this field as specified in Section 4.4.1.1 of [IPSECARCH]. ICMP Type and Code values are treated as a single 16-bit integer port number, with Type in the most significant eight bits and Code in the least significant eight bits. MIPv6 MH Type values are treated as a single 16-bit integer port number, with Type in the most significant eight bits and the least significant eight bits set to zero. ๐ง
- 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 [IPSECARCH] that wish to indicate "ANY" ports MUST set the start port to 0 and the end port to 65535; note that according to [IPSECARCH], "ANY" includes "OPAQUE" ๐ฏ Systems working with [IPSECARCH] that wish to indicate "OPAQUE" ports, but not "ANY" ports, MUST set the start port to 65535 and the end port to 0 ๐ฏ
The Traffic Selector types 7 and 8 can also refer to ICMP or ICMPv6 type and code fields, as well as MH Type fields for the IPv6 mobility header [MIPV6]. Note, however, that neither ICMP nor MIPv6 packets have separate source and destination fields. The method for specifying the Traffic Selectors for ICMP and MIPv6 is shown by example in Section 4.4.1.3 of [IPSECARCH] ๐
The following table lists values for the Traffic Selector Type field and the corresponding Address Selector Data. The values in the following table are only current as of the publication date of RFC 4306. Other values may have been added since then or will be added after the publication of this document. Readers should refer to [IKEV2IANA] for the latest values ๐
TS Type Value
-------------------------------------------------------------------
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.
3.14. Encrypted Payload ๐โจ
Okay so the Encrypted payload, which we write as SK {...} in this doc, is basically a bag that holds other payloads in encrypted form ๐๐. If it shows up in a message, it MUST be the last payload in there. Usually it's the only payload too, lowkey iconic. It's also called the "Encrypted and Authenticated" payload ๐ฆ.
The encryption and integrity algorithms get negotiated during IKE SA setup, and the keys get computed the way Sections 2.14 and 2.18 spell out ๐๏ธ.
This doc covers the crypto processing for Encrypted payloads using a block cipher in CBC mode, plus an integrity check algorithm that makes a fixed-length checksum over a message of variable size ๐งฎ. The design is modeled after the ESP algorithms in RFCs 2104 [HMAC], 4303 [ESP], and 2451 [ESPCBC]. This doc fully specifies the crypto processing for IKE data, but if you want the design reasoning, go read those ones ๐. Future docs can specify Encrypted payload processing for other transform types, like counter mode encryption and authenticated encryption algorithms ๐. Peers MUST NOT negotiate transforms that don't have such a spec, no exceptions ๐ โโ๏ธ.
When an authenticated encryption algorithm protects the IKE SA, building the Encrypted payload works differently than what's described here. Check [AEAD] for more on authenticated encryption and how it's used in IKEv2 ๐ซถ.
The payload type for Encrypted is forty-six (46). It's the IKE generic payload header followed by these fields ๐ :
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload |C| RESERVED | Payload Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Initialization Vector |
| (length is block size for encryption algorithm) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~ Encrypted IKE Payloads ~
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| | Padding (0-255 octets) |
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
| | Pad Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
~ Integrity Checksum Data ~
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 21: Encrypted Payload Format ๐ผ๏ธ
Next Payload- The payload type of the first embedded payload. Heads up, this one's the odd duck ๐ฆ. Normally the Encrypted payload is the last one in the message, so the Next Payload field would usually be zero. But since the content is embedded payloads and there was no natural place to put the type of the first one, that type gets stashed right here โจ.Payload Length- Includes the lengths of the header, initialization vector (IV), Encrypted IKE payloads, Padding, Pad Length, and Integrity Checksum Data ๐.Initialization Vector- For CBC mode ciphers, the IV length equals the block length of the underlying encryption algorithm. Senders MUST select a new unpredictable IV for every message, and recipients MUST accept any value ๐ฒ. The reader is encouraged to consult [MODES] for advice on IV generation. Real talk, using the final ciphertext block of the previous message is NOT considered unpredictable, so don't do that ๐. For modes other than CBC, the IV format and processing is specified in the document that specifies the encryption algorithm and mode.- IKE payloads 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 is 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, though ๐ซถ. This field is encrypted with the negotiated cipher too.
- Integrity Checksum Data is 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 that was negotiated.
3.15. Configuration Payload ๐
The Configuration payload, which we denote CP in this document, is how IKE peers swap configuration info ๐ธ. The whole point is for an IRAC to request an internal IP address from an IRAS, and to exchange other stuff you'd normally get from Dynamic Host Configuration Protocol (DHCP) if the IRAC were plugged straight into a LAN ๐ป.
The Configuration payload is defined like this:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload |C| RESERVED | Payload Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 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 that the Configuration Attributes represent. Heads up, the values in the table below are only current as of the publication date of RFC 4306. Other values might have been added since then, or could get added after this doc is published. For the latest values, check [IKEV2IANA] ๐.
CFG Type Value
--------------------------
CFG_REQUEST 1
CFG_REPLY 2
CFG_SET 3
CFG_ACK 4
RESERVED(3 octets) - MUST be sent as zero, and MUST be ignored on receipt ๐คซ.Configuration Attributes(variable length) - These are type length value (TLV) structures specific to the Configuration payload, and they're defined below. There can be zero or more Configuration Attributes in this payload ๐.
3.15.1. Configuration Attributes โจ
Okay bestie, let's talk about the attribute format ๐ It's a tiny header box with a variable-length value hanging off the end, and it's honestly so tidy:
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|R| Attribute Type | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Value ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 23: Configuration Attribute Format
- Reserved (1 bit) ๐: This bit MUST be set to zero and MUST be ignored on receipt.
- Attribute Type (15 bits) ๐ท๏ธ: A unique identifier for each of the Configuration Attribute Types.
- Length (2 octets, unsigned integer) ๐: Length in octets of value.
- Value (0 or more octets) ๐ : The variable-length value of this Configuration Attribute. The attribute types are listed next.
Quick heads up: the values in the table below were only current as of the publication date of RFC 4306, except INTERNAL_ADDRESS_EXPIRY and INTERNAL_IP6_NBNS, which were removed by RFC 5996 ๐ฅฒ. Other values might've been added since then or will be added after this document is published, so go check [IKEV2IANA] for the latest values ๐ธ
Attribute Type Value Multi-Valued Length
------------------------------------------------------------
INTERNAL_IP4_ADDRESS 1 YES* 0 or 4 octets
INTERNAL_IP4_NETMASK 2 NO 0 or 4 octets
INTERNAL_IP4_DNS 3 YES 0 or 4 octets
INTERNAL_IP4_NBNS 4 YES 0 or 4 octets
INTERNAL_IP4_DHCP 6 YES 0 or 4 octets
APPLICATION_VERSION 7 NO 0 or more
INTERNAL_IP6_ADDRESS 8 YES* 0 or 17 octets
INTERNAL_IP6_DNS 10 YES 0 or 16 octets
INTERNAL_IP6_DHCP 12 YES 0 or 16 octets
INTERNAL_IP4_SUBNET 13 YES 0 or 8 octets
SUPPORTED_ATTRIBUTES 14 NO Multiple of 2
INTERNAL_IP6_SUBNET 15 YES 17 octets
* These attributes may be multi-valued on return only if
multiple values were requested.
- INTERNAL_IP4_ADDRESS, INTERNAL_IP6_ADDRESS ๐ : This is an address on the internal network, sometimes called a red node address or private address, and it MAY be a private address on the Internet. In a request message, the address specified is a requested address (or a zero-length address 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 octets 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 16-octet IPv6 address, and the second is a one-octet prefix-length as defined in [ADDRIPV6]. The requested address is valid as long as this IKE SA (or its rekeyed successors) requesting the address is valid. There's more detail on this in Section 3.15.3 ๐.
- INTERNAL_IP4_NETMASK ๐ญ: The internal network's netmask. Only one netmask is allowed in the request and response messages (e.g., 255.255.255.0), and it MUST be used only with an INTERNAL_IP4_ADDRESS attribute. INTERNAL_IP4_NETMASK in a CFG_REPLY means roughly the same thing as INTERNAL_IP4_SUBNET containing the same information ("send traffic to these addresses through me"), but it also implies a link boundary. For instance, the client could use its own address and the netmask to calculate the broadcast address of the link ๐ก. An empty INTERNAL_IP4_NETMASK attribute can be included in a CFG_REQUEST to request this information (although the gateway can send the information even when it wasn't requested). Non-empty values for this attribute in a CFG_REQUEST don't make sense, so they MUST NOT be included ๐ โโ๏ธ.
- INTERNAL_IP4_DNS, INTERNAL_IP6_DNS ๐บ๏ธ: 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 ๐ช: Specifies an address of a NetBios Name Server (WINS) within the network. Multiple NBNS servers MAY be requested. The responder MAY respond with zero or more NBNS server attributes.
- INTERNAL_IP4_DHCP, INTERNAL_IP6_DHCP ๐ฌ: Tells 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 info of the IPsec host. It's 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 has two fields: the first is an IP address and the second is a netmask. Multiple sub-networks MAY be requested. The responder MAY respond with zero or more sub-network attributes. More on this in Section 3.15.2 ๐ฆ.
- SUPPORTED_ATTRIBUTES ๐: When used within a Request, this attribute MUST be zero-length and asks the responder to reply with all of the attributes it supports. The response contains an attribute holding a set of attribute identifiers, each in 2 octets. The length divided by 2 (octets) tells you how many supported attributes are in the response ๐งฎ.
- INTERNAL_IP6_SUBNET ๐: The protected sub-networks that this edge-device protects. This attribute has two fields: the first is a 16-octet IPv6 address, and the second is a one-octet prefix-length as defined in [ADDRIPV6]. Multiple sub-networks MAY be requested. The responder MAY respond with zero or more sub-network attributes. More on this in Section 3.15.2 ๐ซถ.
Also, no recommendations are made in this document about how an implementation actually figures out what to send in a response ๐คทโโ๏ธ. For example, we don't recommend any specific method for an IRAS to pick which DNS server gets returned to a requesting IRAC. That part is totally up to you, bestie ๐.
The CFG_REQUEST and CFG_REPLY pair lets an IKE endpoint request information from its peer ๐. If an attribute in the CFG_REQUEST Configuration payload is not zero-length, it's taken 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 ๐. Unrecognized or unsupported attributes MUST be ignored in both requests and responses.
The CFG_SET and CFG_ACK pair lets an IKE endpoint push configuration data to its peer ๐. Here, the CFG_SET Configuration payload contains attributes the initiator wants its peer to change. The responder MUST return a Configuration payload if it accepted any of the configuration data, and that payload MUST contain the attributes the responder accepted, with zero-length data. Any attributes it did not accept MUST NOT be in the CFG_ACK Configuration payload. If no attributes were accepted, the responder MUST return either an empty CFG_ACK payload or a response message without a CFG_ACK payload. There are currently no defined uses for the CFG_SET/CFG_ACK exchange, though they may be used with extensions based on Vendor IDs ๐ง. An implementation of this specification MAY ignore CFG_SET payloads ๐.
3.15.2. Meaning of INTERNAL_IP4_SUBNET and INTERNAL_IP6_SUBNET ๐
Okay, so INTERNAL_IP4/6_SUBNET attributes can point out additional subnets that need one or more separate SAs and can be reached through the gateway announcing the attributes ๐ฃ๏ธ. They can also express the gateway's policy about what traffic should go through it. The client gets to choose whether other traffic (covered by TSr but not in INTERNAL_IP4/6_SUBNET) goes through the gateway or straight to the destination. So traffic to the addresses listed in the INTERNAL_IP4/6_SUBNET attributes should be sent through the gateway that announces them. If there are no existing Child SAs whose Traffic Selectors cover the address in question, new SAs need to be created ๐ฅน.
Let's do an example. Say there are two subnets, 198.51.100.0/26 and 192.0.2.0/24, and the client's request contains the following:
CP(CFG_REQUEST) =
INTERNAL_IP4_ADDRESS()
TSi = (0, 0-65535, 0.0.0.0-255.255.255.255)
TSr = (0, 0-65535, 0.0.0.0-255.255.255.255)
Then a valid response could be the following (where TSr and INTERNAL_IP4_SUBNET contain the same information) ๐:
CP(CFG_REPLY) =
INTERNAL_IP4_ADDRESS(198.51.100.234)
INTERNAL_IP4_SUBNET(198.51.100.0/255.255.255.192)
INTERNAL_IP4_SUBNET(192.0.2.0/255.255.255.0)
TSi = (0, 0-65535, 198.51.100.234-198.51.100.234)
TSr = ((0, 0-65535, 198.51.100.0-198.51.100.63),
(0, 0-65535, 192.0.2.0-192.0.2.255))
In these cases, the INTERNAL_IP4_SUBNET doesn't really carry any useful info ๐.
A different possible response would be this one ๐ซ:
CP(CFG_REPLY) =
INTERNAL_IP4_ADDRESS(198.51.100.234)
INTERNAL_IP4_SUBNET(198.51.100.0/255.255.255.192)
INTERNAL_IP4_SUBNET(192.0.2.0/255.255.255.0)
TSi = (0, 0-65535, 198.51.100.234-198.51.100.234)
TSr = (0, 0-65535, 0.0.0.0-255.255.255.255)
That response means the client can send all its traffic through the gateway, but the gateway doesn't mind if the client sends traffic not included by INTERNAL_IP4_SUBNET directly to the destination (without going through the gateway) ๐โโ๏ธ.
A different situation comes up if the gateway has a policy that requires traffic for the two subnets to be carried in separate SAs. Then a response like this tells the client that if it wants access to the second subnet, it needs to create a separate SA ๐:
CP(CFG_REPLY) =
INTERNAL_IP4_ADDRESS(198.51.100.234)
INTERNAL_IP4_SUBNET(198.51.100.0/255.255.255.192)
INTERNAL_IP4_SUBNET(192.0.2.0/255.255.255.0)
TSi = (0, 0-65535, 198.51.100.234-198.51.100.234)
TSr = (0, 0-65535, 198.51.100.0-198.51.100.63)
INTERNAL_IP4_SUBNET can also be useful if the client's TSr only included part of the address space ๐ง. For instance, if the client requests the following:
CP(CFG_REQUEST) =
INTERNAL_IP4_ADDRESS()
TSi = (0, 0-65535, 0.0.0.0-255.255.255.255)
TSr = (0, 0-65535, 192.0.2.155-192.0.2.155)
then the gateway's response might be:
CP(CFG_REPLY) =
INTERNAL_IP4_ADDRESS(198.51.100.234)
INTERNAL_IP4_SUBNET(198.51.100.0/255.255.255.192)
INTERNAL_IP4_SUBNET(192.0.2.0/255.255.255.0)
TSi = (0, 0-65535, 198.51.100.234-198.51.100.234)
TSr = (0, 0-65535, 192.0.2.155-192.0.2.155)
Because the meaning of INTERNAL_IP4_SUBNET/INTERNAL_IP6_SUBNET in CFG_REQUESTs is unclear, they can't be used reliably in CFG_REQUESTs ๐ซ๐ .
3.15.3. Configuration Payloads for IPv6 โจ
okay so the IPv6 Configuration payloads are based on the IPv4 ones, but they don't fully follow the "normal IPv6 way of doing things" ๐ IPv6 stateless autoconfiguration and router advertisement messages aren't used, and neighbor discovery isn't either. there's also an extra doc that talks about IPv6 configuration in IKEv2, [IPV6CONFIG]. right now it's experimental, but the hope is that with more implementation experience it'll get the same standards treatment as this one ๐ค๐
a client can get an IPv6 address through the INTERNAL_IP6_ADDRESS Configuration payload. here's what a minimal exchange could look like ๐ฆ
CP(CFG_REQUEST) =
INTERNAL_IP6_ADDRESS()
INTERNAL_IP6_DNS()
TSi = (0, 0-65535, :: - FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF)
TSr = (0, 0-65535, :: - FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF)
CP(CFG_REPLY) =
INTERNAL_IP6_ADDRESS(2001:DB8:0:1:2:3:4:5/64)
INTERNAL_IP6_DNS(2001:DB8:99:88:77:66:55:44)
TSi = (0, 0-65535, 2001:DB8:0:1:2:3:4:5 - 2001:DB8:0:1:2:3:4:5)
TSr = (0, 0-65535, :: - FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF)
the client MAY send a non-empty INTERNAL_IP6_ADDRESS attribute in the CFG_REQUEST to ask for a specific address or interface identifier ๐ the gateway checks first whether that address is acceptable, and if it is, it sends that one back. if it isn't acceptable, the gateway tries the interface identifier with some other prefix. if even that doesn't work, the gateway picks a different interface identifier ๐
the INTERNAL_IP6_ADDRESS attribute also has a prefix length field. when it shows up in a CFG_REPLY, it's the IPv6 version of the INTERNAL_IP4_NETMASK attribute from the IPv4 side ๐ธ
this approach is reasonably simple, but it has some limits ๐ญ IPsec tunnels set up with IKEv2 aren't fully featured "interfaces" in the IPv6 addressing architecture sense [ADDRIPV6]. they don't necessarily have link-local addresses, and that can complicate protocols that assume they're there, like [MLDV2] ๐
3.15.4. Address Assignment Failures ๐จ
if the responder runs into an error while trying to assign an IP address to the initiator during processing of a Configuration payload, it replies with an INTERNAL_ADDRESS_FAILURE notification. the IKE SA still gets created even if the initial Child SA can't be created because of this failure. if the error happens inside an IKE_AUTH exchange, no Child SA gets created. there are also some messier error cases ๐ซ
if the responder doesn't support Configuration payloads at all, it can just ignore every Configuration payload. this kind of implementation never sends INTERNAL_ADDRESS_FAILURE notifications ๐
if the initiator needs an IP address assigned, it treats a response without a CFG_REPLY as an error ๐ซ
the initiator might ask for a type of address (IPv4 or IPv6) that the responder doesn't support, even though the responder does support Configuration payloads. in that case the responder just ignores the unsupported type and handles the rest of the request as usual ๐ง
if the initiator asks for multiple addresses of a type the responder supports, and some (but not all) of those requests fail, the responder replies with only the addresses that succeeded. it only sends INTERNAL_ADDRESS_FAILURE if no addresses at all can be assigned ๐
if the initiator doesn't get the IP address(es) its policy requires, it MAY keep the IKE SA up and retry the Configuration payload in a separate INFORMATIONAL exchange after a suitable timeout. or it MAY tear down the IKE SA by sending a Delete payload inside a separate INFORMATIONAL exchange, and then retry the IKE SA from the beginning after some timeout ๐ that timeout shouldn't be too short (especially if the IKE SA is being started from scratch) because these errors may not get fixed quickly. the timeout should likely be several minutes โณ for example, an address shortage on the responder will probably only get fixed when more entries go back into the address pool as other clients disconnect, or when the responder gets reconfigured with a bigger address pool ๐
3.16. Extensible Authentication Protocol (EAP) Payload ๐ฆ
the Extensible Authentication Protocol payload, which this document calls EAP, lets IKE SAs get authenticated using the protocol defined in RFC 3748 [EAP] and its later extensions ๐ when you use EAP, you need to pick an appropriate EAP method. tons of these have been defined, each one spelling out how the protocol gets used with different authentication mechanisms. EAP method types are listed in [EAP-IANA]. a quick summary of the EAP format is included here so it's clear ๐
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Payload |C| RESERVED | Payload Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ EAP Message ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 24: EAP Payload Format
the payload type for an EAP payload is forty-eight (48) ๐ฅ
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Code | Identifier | Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Type_Data...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 25: EAP Message Format
here's the breakdown of the EAP message fields ๐
- Code (1 octet) - Indicates whether this message is a Request (1), Response (2), Success (3), or Failure (4).
- Identifier (1 octet) - Used in PPP to tell replayed messages apart from repeated ones. Since in IKE, EAP runs over a reliable protocol, the Identifier serves no function here. In a response message, this octet MUST be set to match the identifier in the corresponding request.
- Length (2 octets, unsigned integer) - The length of the EAP message. 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. Note that since IKE passes an indication of initiator identity in the first message in the IKE_AUTH exchange, the responder SHOULD NOT send EAP Identity requests (type 1). The initiator MAY, however, respond to such requests if it receives them.
- Type_Data (variable length) - Varies with the Type of Request and the associated Response. For the documentation of the EAP methods, see [EAP].
Note that since IKE passes an indication of initiator identity in the first message in the IKE_AUTH exchange, the responder SHOULD NOT send EAP Identity requests. The initiator MAY, however, respond to such requests if it receives them. ๐
4. Conformance Requirements โจ
okay so, IKEv2 needs every implementation to play nicely together, bestie ๐ซถ so there are "MUST support" requirements on top of the ones listed elsewhere. BUT ngl, IKEv2 is a security protocol, so its whole thing is letting only authorized parties finish setting up SAs ๐. That means a particular implementation can be configured with restrictions on algorithms and trusted authorities, and those restrictions can stop it from interoperating with everyone. Not a bug, just main character security energy ๐
IKEv2 is designed so you can build a minimal implementation that still talks to every compliant implementation ๐ฆ These are the features a minimal implementation is allowed to skip:
- Ability to negotiate SAs through a NAT and tunnel the resulting ESP SA over UDP.
- Ability to request (and respond to a request for) a temporary IP address on the remote end of a tunnel.
- Ability to support EAP-based authentication.
- Ability to support window sizes greater than one.
- Ability to establish multiple ESP or AH SAs within a single IKE SA.
- Ability to rekey SAs.
Now for the non-negotiable interop stuff ๐ All implementations MUST be capable of parsing all payload types (even if the only goal is skipping over them) and ignoring any payload type they don't support, UNLESS the critical bit is set in the payload header. If the critical bit is set in a payload header the implementation doesn't support, all implementations MUST reject the messages containing those payloads. Strict but fair, periodt ๐ค
Every implementation MUST be capable of doing the four-message IKE_SA_INIT and IKE_AUTH exchanges that establish two SAs (one for IKE, one for ESP or AH) ๐ธ 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 request with an empty response. (Quick reminder: inside an IKE SA, an "empty" message is an IKE header followed by an Encrypted payload with no payloads inside it ๐ง)
A minimal implementation MAY support the CREATE_CHILD_SA exchange only enough to recognize requests and reject them with a Notify payload of type NO_ADDITIONAL_SAS ๐ It does not need to be able to initiate CREATE_CHILD_SA or INFORMATIONAL exchanges. When an SA expires (based on locally configured lifetime or octets-passed values), an implementation MAY either try to renew it with a CREATE_CHILD_SA exchange, OR it MAY delete (close) the old SA and create a new one. If the responder rejects the CREATE_CHILD_SA request with a NO_ADDITIONAL_SAS notification, the implementation MUST be capable of instead deleting the old SA and creating a new one. Plan B is mandatory, bestie ๐
Implementations are not required to support requesting temporary IP addresses or responding to such requests ๐ฆ But if an implementation does support issuing those requests AND its policy requires using temporary IP addresses, it MUST include a CP payload in the first message of the IKE_AUTH exchange containing at least a field of type INTERNAL_IP4_ADDRESS or INTERNAL_IP6_ADDRESS. Every other field is optional. If an implementation supports responding to such requests, it MUST parse the CP payload of type CFG_REQUEST in the first message of the IKE_AUTH exchange and recognize a field of type INTERNAL_IP4_ADDRESS or INTERNAL_IP6_ADDRESS. If it supports leasing an address of the appropriate type, it MUST return a CP payload of type CFG_REPLY containing an address of the requested type. The responder may include any other related attributes โจ
Last but NOT least, to be called a conforming implementation, it MUST be possible to configure it to accept the following ๐
- Public Key Infrastructure using X.509 (PKIX) Certificates containing and signed by RSA keys of size 1024 or 2048 bits, where the ID passed is any of
ID_KEY_ID,ID_FQDN,ID_RFC822_ADDR, orID_DER_ASN1_DN. - Shared key authentication where the ID passed is any of
ID_KEY_ID,ID_FQDN, orID_RFC822_ADDR. - Authentication where the responder is authenticated using PKIX Certificates and the initiator is authenticated using shared key authentication.
That's the whole minimum-viable IKEv2 checklist, bestie ๐๐
5. Security Considerations โจ
okay bestie, this is the dramatic part ๐ While this protocol is designed to minimize disclosure of configuration info to unauthenticated peers, some disclosure is unavoidable ๐ญ One peer or the other has to identify itself first and prove who it is first. To avoid probing, the initiator is required to identify itself first, and is usually required to authenticate itself first ๐ซถ The initiator can still learn that the responder supports IKE and which cryptographic protocols it supports ๐ฆ The responder (or someone pretending to be the responder) can not only probe the initiator for its identity, but may also use CERTREQ payloads to figure out which certificates the initiator is willing to use ๐
Using EAP authentication changes the probing game a bit ๐ When EAP authentication is used, the responder proves its identity before the initiator does, so an initiator that knew the name of a valid initiator could probe the responder for both its name and its certificates ๐
Repeated rekeying with CREATE_CHILD_SA and no extra Diffie-Hellman exchanges leaves all SAs vulnerable to cryptanalysis of a single key ๐ฑ Implementers should take note of this and set a limit on CREATE_CHILD_SA exchanges between exponentiations ๐ This document does not prescribe such a limit, so that's on you, bestie ๐
The strength of a key derived from a Diffie-Hellman exchange with any of the groups defined here depends on the inherent strength of the group, the size of the exponent used, and the entropy from the random number generator ๐ง Because of all those inputs, it's really hard to pin down the strength of a key for any of the defined groups ๐ธ Diffie-Hellman group number two, used with a strong random number generator and an exponent no less than 200 bits, is common for use with 3DES. Group five gives you more security than group two ๐ฅ Group one is for historic purposes only and doesn't provide sufficient strength, except for use with DES, which is also historic-use only ๐ Implementations should keep these estimates in mind when setting policy and negotiating security parameters โจ
Note that these limitations are about the Diffie-Hellman groups themselves ๐ Nothing in IKE prohibits using stronger groups, and nothing dilutes the strength you get from stronger groups (it's limited by the strength of the other algorithms negotiated, including the PRF) ๐ Honestly, the extensible framework of IKE encourages defining more groups, and elliptic curve groups may greatly increase strength while using much smaller numbers ๐ญ๐ซถ
It is assumed that all Diffie-Hellman exponents are erased from memory after use ๐งน
The IKE_SA_INIT and IKE_AUTH exchanges happen before the initiator has been authenticated ๐ณ So an implementation of this protocol needs to be completely robust when deployed on any insecure network ๐ก๏ธ Implementation vulnerabilities, especially DoS attacks, can be exploited by unauthenticated peers ๐ This is especially worrying because EAP-based authentication allows an unlimited number of messages ๐
The strength of all keys is limited by the size of the output of the negotiated PRF ๐ For this reason, a PRF whose output is less than 128 bits (e.g., 3DES-CBC) MUST NOT be used with this protocol. That's a hard no, bestie ๐ซ
The security of this protocol depends heavily on the randomness of the randomly chosen parameters ๐ฒ These should be generated by a strong random or properly seeded pseudorandom source (see [RANDOMNESS]). Implementers should take care that random numbers used for both keys and nonces are engineered so they don't undermine the security of the keys ๐
For info on the reasoning behind many of the cryptographic design choices in this protocol, check out [SIGMA] and [SKEME] ๐ Even though the security of negotiated Child SAs doesn't depend on the strength of the encryption and integrity protection negotiated in the IKE SA, implementations MUST NOT negotiate NONE as the IKE integrity protection algorithm or ENCR_NULL as the IKE encryption algorithm ๐ซโจ
When using pre-shared keys, a huge consideration is how to make sure those secrets are actually random ๐ The strongest practice is making sure any pre-shared key has as much randomness as the strongest key being negotiated ๐ช Deriving a shared secret from a password, name, or other low-entropy source is not secure ๐ญ Those sources are open to dictionary and social-engineering attacks, among others ๐ โโ๏ธ
The NAT_DETECTION_*_IP notifications contain a hash of the addresses and ports, which tries to hide internal IP addresses behind a NAT ๐ But the IPv4 address space is only 32 bits and is usually very sparse, so an attacker could find the internal address behind the NAT box by trying all possible IP addresses and looking for the matching hash ๐ฑ The port numbers are normally fixed to 500, and the SPIs can be pulled out of the packet, which brings the number of hash calculations down to 2^32 ๐ With an educated guess about the use of private address space, the number of hash calculations is much smaller ๐ So designers should not assume that using IKE won't leak internal address information ๐ซ
When using an EAP authentication method that doesn't generate a shared key for protecting a later AUTH payload, certain man-in-the-middle and server-impersonation attacks are possible [EAPMITM] ๐ต๏ธโโ๏ธ These vulnerabilities happen when EAP is also used in protocols that aren't protected with a secure tunnel ๐จ EAP is a general-purpose authentication protocol that's often used to provide single-signon facilities, so a deployed IPsec solution that relies on an EAP authentication method that doesn't generate a shared key (also known as a non-key-generating EAP method) can get compromised just because a totally unrelated application uses the same non-key-generating EAP method in an unprotected way ๐ฑ This isn't limited to just EAP. It can happen in other scenarios where an authentication infrastructure is reused ๐ For example, if the EAP mechanism used by IKEv2 utilizes a token authenticator, a man-in-the-middle attacker could impersonate the web server, intercept the token authentication exchange, and use it to start an IKEv2 connection ๐
Okay, this is the main warning: use of non-key-generating EAP methods SHOULD be avoided where possible. Where they are used, it is extremely important that all usages of these EAP methods SHOULD utilize a protected tunnel, where the initiator validates the responder's certificate before starting the EAP authentication ๐จ๐จ
Implementers should describe the vulnerabilities of using non-key-generating EAP methods in their implementation documentation, so the admins deploying IPsec solutions know about these dangers ๐๐ซถ
An implementation using EAP MUST also use public-key-based authentication of the server to the client before the EAP authentication begins, even if the EAP method offers mutual authentication ๐ This avoids extra IKEv2 protocol variations and protects the EAP data from active attackers ๐ก๏ธ
If IKEv2 messages are long enough that IP-level fragmentation is necessary, attackers could stop the exchange from completing by exhausting the reassembly buffers ๐ญ You can cut down the chances by using the Hash and URL encodings instead of sending certificates (see Section 3.6) ๐ง More mitigations are discussed in [DOSUDPPROT] โจ
Admission control is critical to the security of the protocol ๐ For example, trust anchors used for identifying IKE peers should probably be different from those used for other forms of trust, like the ones used to identify public web servers ๐ Also, even though IKE gives you a lot of leeway in defining security policy for a trusted peer's identity, credentials, and how they correlate, having that policy defined explicitly is essential for a secure implementation ๐
5.1. Traffic Selector Authorization ๐ฆ
IKEv2 relies on information in the Peer Authorization Database (PAD) to decide what kind of Child SAs a peer is allowed to create ๐ This process is described in Section 4.4.3 of [IPSECARCH]. When a peer requests creating a Child SA with some Traffic Selectors, the PAD must contain "Child SA Authorization Data" linking the identity authenticated by IKEv2 and the addresses permitted for those Traffic Selectors ๐
For example, the PAD might be set up so that the authenticated identity "sgw23.example.com" is allowed to create Child SAs for 192.0.2.0/24, meaning this security gateway is a valid "representative" for those addresses ๐ธ Host-to-host IPsec needs similar entries, linking, for example, "fooserver4.example.com" with 198.51.100.66/32, meaning this identity is a valid "owner" or "representative" of that address ๐ง
As noted in [IPSECARCH], "It is necessary to impose these constraints on creation of child SAs to prevent an authenticated peer from spoofing IDs associated with other, legitimate peers". In the example above, a correct PAD setup stops sgw23 from creating Child SAs with address 198.51.100.66, and stops fooserver4 from creating Child SAs with addresses from 192.0.2.0/24 ๐ โโ๏ธโจ
It's really important to know that just sending IKEv2 packets from some particular address doesn't mean you have permission to create Child SAs with that address in the Traffic Selectors ๐ For example, even if sgw23 could spoof its IP address as 198.51.100.66, it still couldn't create Child SAs matching fooserver4's traffic ๐
The IKEv2 specification doesn't say exactly how IP address assignment using Configuration payloads interacts with the PAD ๐คทโโ๏ธ Our interpretation is that when a security gateway assigns an address using Configuration payloads, it also creates a temporary PAD entry linking the authenticated peer identity and the newly allocated inner address ๐
It's been recognized that configuring the PAD correctly can be hard in some environments ๐ญ For instance, if IPsec is used between a pair of hosts whose addresses are allocated dynamically using DHCP, it's extremely difficult to make sure the PAD specifies the correct "owner" for each IP address ๐ฅฒ That would need a mechanism to securely convey address assignments from the DHCP server and link them to identities authenticated using IKEv2 ๐
Because of this limitation, some vendors have been known to configure their PADs to let an authenticated peer create Child SAs with Traffic Selectors containing the same address that was used for the IKEv2 packets ๐ Where IP spoofing is possible (i.e., almost everywhere), this basically lets any peer create Child SAs with any Traffic Selectors ๐ That's not an appropriate or secure configuration in most circumstances ๐ซ See [H2HIPSEC] for an extensive discussion of this issue and the limitations of host-to-host IPsec in general ๐
6. IANA Considerations ๐
[IKEV2] defined many field types and values. IANA has already registered those types and values in [IKEV2IANA], so they aren't listed here again ๐
One item has been deprecated from the "IKEv2 Certificate Encodings" registry: "Raw RSA Key" ๐๏ธ
IANA has updated all references to RFC 5996 to point to this document ๐
7. References ๐
7.1. Normative References ๐โจ
okay so these are the docs the spec literally can't function without, bestie ๐ every one of these gets a full citation below, exactly as written, so nobody has to guess which RFC is which ๐ซถ
[ADDGROUP] Kivinen, T. and M. Kojo, "More Modular Exponential (MODP)
Diffie-Hellman groups for Internet Key Exchange (IKE)",
RFC 3526, May 2003,
<http://www.rfc-editor.org/info/rfc3526>.
[ADDRIPV6] Hinden, R. and S. Deering, "IP Version 6 Addressing
Architecture", RFC 4291, February 2006,
<http://www.rfc-editor.org/info/rfc4291>.
[AEAD] Black, D. and D. McGrew, "Using Authenticated Encryption
Algorithms with the Encrypted Payload of the Internet Key
Exchange version 2 (IKEv2) Protocol", RFC 5282, August
2008, <http://www.rfc-editor.org/info/rfc5282>.
[AESCMACPRF128]
Song, J., Poovendran, R., Lee, J., and T. Iwata, "The
Advanced Encryption Standard-Cipher-based Message
Authentication Code-Pseudo-Random Function-128 (AES-CMAC-
PRF-128) Algorithm for the Internet Key Exchange Protocol
(IKE)", RFC 4615, August 2006,
<http://www.rfc-editor.org/info/rfc4615>.
[AESXCBCPRF128]
Hoffman, P., "The AES-XCBC-PRF-128 Algorithm for the
Internet Key Exchange Protocol (IKE)", RFC 4434, February
2006, <http://www.rfc-editor.org/info/rfc4434>.
[EAP] Aboba, B., Blunk, L., Vollbrecht, J., Carlson, J., and H.
Levkowetz, "Extensible Authentication Protocol (EAP)", RFC
3748, June 2004, <http://www.rfc-editor.org/info/rfc3748>.
[ECN] Ramakrishnan, K., Floyd, S., and D. Black, "The Addition
of Explicit Congestion Notification (ECN) to IP", RFC
3168, September 2001,
<http://www.rfc-editor.org/info/rfc3168>.
[ESPCBC] Pereira, R. and R. Adams, "The ESP CBC-Mode Cipher
Algorithms", RFC 2451, November 1998,
<http://www.rfc-editor.org/info/rfc2451>.
[IKEV2IANA]
IANA, "Internet Key Exchange Version 2 (IKEv2)
Parameters",
<http://www.iana.org/assignments/ikev2-parameters/>.
[IPSECARCH]
Kent, S. and K. Seo, "Security Architecture for the
Internet Protocol", RFC 4301, December 2005,
<http://www.rfc-editor.org/info/rfc4301>.
[MUSTSHOULD]
Bradner, S., "Key words for use in RFCs to Indicate
Requirement Levels", BCP 14, RFC 2119, March 1997,
<http://www.rfc-editor.org/info/rfc2119>.
[PKCS1] Jonsson, J. and B. Kaliski, "Public-Key Cryptography
Standards (PKCS) #1: RSA Cryptography Specifications
Version 2.1", RFC 3447, February 2003,
<http://www.rfc-editor.org/info/rfc3447>.
[PKIX] Cooper, D., Santesson, S., Farrell, S., Boeyen, S.,
Housley, R., and W. Polk, "Internet X.509 Public Key
Infrastructure Certificate and Certificate Revocation List
(CRL) Profile", RFC 5280, May 2008,
<http://www.rfc-editor.org/info/rfc5280>.
[RFC4307] Schiller, J., "Cryptographic Algorithms for Use in the
Internet Key Exchange Version 2 (IKEv2)", RFC 4307,
December 2005, <http://www.rfc-editor.org/info/rfc4307>.
[UDPENCAPS]
Huttunen, A., Swander, B., Volpe, V., DiBurro, L., and M.
Stenberg, "UDP Encapsulation of IPsec ESP Packets", RFC
3948, January 2005,
<http://www.rfc-editor.org/info/rfc3948>.
[URLS] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform
Resource Identifier (URI): Generic Syntax", STD 66, RFC
3986, January 2005,
<http://www.rfc-editor.org/info/rfc3986>.
that's the whole normative crew, no cap ๐ธ keep going with me, the next part picks up right where this one leaves off ๐ฆ
7.2. Informative References โจ
okay bestie, this is the background reading list ๐๐ง these are the docs the spec points to for extra context. none of them are required to implement IKEv2, but they're the receipts behind a lot of the design choices ๐
here's the full list, copied exactly so every citation tag, title, and link stays intact ๐ฆ
[AH] Kent, S., "IP Authentication Header", RFC 4302, December
2005, <http://www.rfc-editor.org/info/rfc4302>.
[ARCHGUIDEPHIL]
Bush, R. and D. Meyer, "Some Internet Architectural
Guidelines and Philosophy", RFC 3439, December 2002,
<http://www.rfc-editor.org/info/rfc3439>.
[ARCHPRINC]
Carpenter, B., "Architectural Principles of the Internet",
RFC 1958, June 1996,
<http://www.rfc-editor.org/info/rfc1958>.
[Clarif] Eronen, P. and P. Hoffman, "IKEv2 Clarifications and
Implementation Guidelines", RFC 4718, October 2006,
<http://www.rfc-editor.org/info/rfc4718>.
[DES] American National Standards Institute, "American National
Standard for Information Systems-Data Link Encryption",
ANSI X3.106, 1983.
[DH] Diffie, W. and M. Hellman, "New Directions in
Cryptography", IEEE Transactions on Information Theory,
V.IT-22 n. 6, June 1977.
[DIFFSERVARCH]
Blake, S., Black, D., Carlson, M., Davies, E., Wang, Z.,
and W. Weiss, "An Architecture for Differentiated
Services", RFC 2475, December 1998,
<http://www.rfc-editor.org/info/rfc2475>.
[DIFFSERVFIELD]
Nichols, K., Blake, S., Baker, F., and D. Black,
"Definition of the Differentiated Services Field (DS
Field) in the IPv4 and IPv6 Headers", RFC 2474, December
1998, <http://www.rfc-editor.org/info/rfc2474>.
[DIFFTUNNEL]
Black, D., "Differentiated Services and Tunnels", RFC
2983, October 2000,
<http://www.rfc-editor.org/info/rfc2983>.
[DOI] Piper, D., "The Internet IP Security Domain of
Interpretation for ISAKMP", RFC 2407, November 1998,
<http://www.rfc-editor.org/info/rfc2407>.
[DOSUDPPROT]
Kaufman, C., Perlman, R., and B. Sommerfeld, "DoS
protection for UDP-based protocols", ACM Conference on
Computer and Communications Security, October 2003.
[DSS] National Institute of Standards and Technology, U.S.
Department of Commerce, "Digital Signature Standard
(DSS)", FIPS 186-4, July 2013,
<http://nvlpubs.nist.gov/nistpubs/FIPS/
NIST.FIPS.186-4.pdf>.
[EAI] Yang, A., Steele, S., and N. Freed, "Internationalized
Email Headers", RFC 6532, February 2012,
<http://www.rfc-editor.org/info/rfc6532>.
[EAP-IANA] IANA, "Extensible Authentication Protocol (EAP) Registry:
Method Types",
<http://http://www.iana.org/assignments/eap-eke/>.
[EAPMITM] Asokan, N., Niemi, V., and K. Nyberg, "Man-in-the-Middle
in Tunneled Authentication Protocols", November 2002,
<http://eprint.iacr.org/2002/163>.
[ESP] Kent, S., "IP Encapsulating Security Payload (ESP)", RFC
4303, December 2005,
<http://www.rfc-editor.org/info/rfc4303>.
[EXCHANGEANALYSIS]
Perlman, R. and C. Kaufman, "Analysis of the IPsec key
exchange Standard", WET-ICE Security Conference, MIT,
2001, <http://www.computer.org/csdl/proceedings/
wetice/2001/1269/00/12690150.pdf>.
[FIPS.180-4.2012]
National Institute of Standards and Technology, U.S.
Department of Commerce, "Secure Hash Standard (SHS)", FIPS
180-4, March 2012,
<http://csrc.nist.gov/publications/fips/fips180-4/
fips-180-4.pdf>.
[H2HIPSEC] Aura, T., Roe, M., and A. Mohammed, "Experiences with
Host-to-Host IPsec", 13th International Workshop on
Security Protocols, Cambridge, UK, April 2005.
[HMAC] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed-
Hashing for Message Authentication", RFC 2104, February
1997, <http://www.rfc-editor.org/info/rfc2104>.
[IDEA] Lai, X., "On the Design and Security of Block Ciphers",
ETH Series in Information Processing, v. 1, Konstanz:
Hartung-Gorre Verlag, 1992.
[IDNA] Klensin, J., "Internationalized Domain Names for
Applications (IDNA): Definitions and Document Framework",
RFC 5890, August 2010,
<http://www.rfc-editor.org/info/rfc5890>.
[IKEV1] Harkins, D. and D. Carrel, "The Internet Key Exchange
(IKE)", RFC 2409, November 1998,
<http://www.rfc-editor.org/info/rfc2409>.
[IKEV2] Kaufman, C., "Internet Key Exchange (IKEv2) Protocol", RFC
4306, December 2005,
<http://www.rfc-editor.org/info/rfc4306>.
[IP] Postel, J., "Internet Protocol", STD 5, RFC 791, September
1981, <http://www.rfc-editor.org/info/rfc791>.
[IP-COMP] Shacham, A., Monsour, B., Pereira, R., and M. Thomas, "IP
Payload Compression Protocol (IPComp)", RFC 3173,
September 2001, <http://www.rfc-editor.org/info/rfc3173>.
[IPSECARCH-OLD]
Kent, S. and R. Atkinson, "Security Architecture for the
Internet Protocol", RFC 2401, November 1998,
<http://www.rfc-editor.org/info/rfc2401>.
[IPV6CONFIG]
Eronen, P., Laganier, J., and C. Madson, "IPv6
Configuration in Internet Key Exchange Protocol Version 2
(IKEv2)", RFC 5739, February 2010,
<http://www.rfc-editor.org/info/rfc5739>.
[ISAKMP] Maughan, D., Schneider, M., and M. Schertler, "Internet
Security Association and Key Management Protocol
(ISAKMP)", RFC 2408, November 1998,
<http://www.rfc-editor.org/info/rfc2408>.
[MAILFORMAT]
Resnick, P., Ed., "Internet Message Format", RFC 5322,
October 2008, <http://www.rfc-editor.org/info/rfc5322>.
[MD5] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321,
April 1992, <http://www.rfc-editor.org/info/rfc1321>.
[MIPV6] Perkins, C., Johnson, D., and J. Arkko, "Mobility Support
in IPv6", RFC 6275, July 2011,
<http://www.rfc-editor.org/info/rfc6275>.
[MLDV2] Vida, R. and L. Costa, "Multicast Listener Discovery
Version 2 (MLDv2) for IPv6", RFC 3810, June 2004,
<http://www.rfc-editor.org/info/rfc3810>.
[MOBIKE] Eronen, P., "IKEv2 Mobility and Multihoming Protocol
(MOBIKE)", RFC 4555, June 2006,
<http://www.rfc-editor.org/info/rfc4555>.
[MODES] Dworkin, M., "Recommendation for Block Cipher Modes of
Operation", National Institute of Standards and
Technology, NIST Special Publication 800-38A 2001 Edition,
December 2001.
[NAI] Aboba, B., Beadles, M., Arkko, J., and P. Eronen, "The
Network Access Identifier", RFC 4282, December 2005,
<http://www.rfc-editor.org/info/rfc4282>.
[NATREQ] Aboba, B. and W. Dixon, "IPsec-Network Address Translation
(NAT) Compatibility Requirements", RFC 3715, March 2004,
<http://www.rfc-editor.org/info/rfc3715>.
[OAKLEY] Orman, H., "The OAKLEY Key Determination Protocol", RFC
2412, November 1998,
<http://www.rfc-editor.org/info/rfc2412>.
[PFKEY] McDonald, D., Metz, C., and B. Phan, "PF_KEY Key
Management API, Version 2", RFC 2367, July 1998,
<http://www.rfc-editor.org/info/rfc2367>.
[PHOTURIS] Karn, P. and W. Simpson, "Photuris: Session-Key Management
Protocol", RFC 2522, March 1999,
<http://www.rfc-editor.org/info/rfc2522>.
[RANDOMNESS]
Eastlake 3rd, D., Schiller, J., and S. Crocker,
"Randomness Requirements for Security", BCP 106, RFC 4086,
June 2005, <http://www.rfc-editor.org/info/rfc4086>.
[REAUTH] Nir, Y., "Repeated Authentication in Internet Key Exchange
(IKEv2) Protocol", RFC 4478, April 2006,
<http://www.rfc-editor.org/info/rfc4478>.
[REUSE] Menezes, A. and B. Ustaoglu, "On Reusing Ephemeral Keys In
Diffie-Hellman Key Agreement Protocols", December 2008,
<http://www.cacr.math.uwaterloo.ca/techreports/2008/
cacr2008-24.pdf>.
[RFC4945] Korver, B., "The Internet IP Security PKI Profile of
IKEv1/ISAKMP, IKEv2, and PKIX", RFC 4945, August 2007,
<http://www.rfc-editor.org/info/rfc4945>.
[RFC5996] Kaufman, C., Hoffman, P., Nir, Y., and P. Eronen,
"Internet Key Exchange Protocol Version 2 (IKEv2)", RFC
5996, September 2010,
<http://www.rfc-editor.org/info/rfc5996>.
[RFC6989] Sheffer, Y. and S. Fluhrer, "Additional Diffie-Hellman
Tests for the Internet Key Exchange Protocol Version 2
(IKEv2)", RFC 6989, July 2013,
<http://www.rfc-editor.org/info/rfc6989>.
[ROHCV2] Ertekin, E., Christou, C., Jasani, R., Kivinen, T., and C.
Bormann, "IKEv2 Extensions to Support Robust Header
Compression over IPsec", RFC 5857, May 2010,
<http://www.rfc-editor.org/info/rfc5857>.
[SIGMA] Krawczyk, H., "SIGMA: the 'SIGn-and-MAc' Approach to
Authenticated Diffie-Hellman and its Use in the IKE
Protocols", Advances in Cryptography - CRYPTO 2003
Proceedings LNCS 2729, 2003,
<http://www.informatik.uni-trier.de/~ley/db/conf/crypto/
crypto2003.html>.
[SKEME] Krawczyk, H., "SKEME: A Versatile Secure Key Exchange
Mechanism for Internet", IEEE Proceedings of the 1996
Symposium on Network and Distributed Systems Security,
1996.
[TRANSPARENCY]
Carpenter, B., "Internet Transparency", RFC 2775, February
2000, <http://www.rfc-editor.org/info/rfc2775>.
that's the whole informative list, so pretty ๐ we've got the RFC 4302 AH, the ESP, the IKEv1 stuff, and the big crypto receipts like DH, SIGMA, and REUSE ๐ฅ
Appendix A. Summary of Changes from IKEv1 โจ
Okay bestie, here's the glow-up story from IKEv1 to IKEv2 ๐ The goals of this revision to IKE are:
- Goal one: put the WHOLE IKE protocol in a single doc ๐ so it replaces RFCs 2407, 2408, and 2409, and bakes in the later stuff for NAT traversal, Extensible Authentication, and Remote Address acquisition ๐
- Goal two: swap the eight different initial exchanges for ONE four-message exchange ๐ฆ Changes to authentication mechanisms only touch a single AUTH payload instead of restructuring the whole exchange, so it's giving simplicity โจ see [EXCHANGEANALYSIS]
- Remove the Domain of Interpretation (DOI), Situation (SIT), and Labeled Domain Identifier fields, plus the Commit and Authentication only bits ๐๏ธ literally no more clutter
- Lower IKE's latency in the common case ๐โโ๏ธ The initial exchange becomes 2 round trips (4 messages), and you can piggyback setup of a Child SA onto that exchange ๐ง
- Replace the cryptographic syntax for protecting the IKE messages themselves with one based closely on ESP ๐ Simpler to implement, simpler to analyse for security ๐
- Reduce the number of possible error states by making the protocol reliable (every message gets acknowledged) and sequenced ๐ This also shortens CREATE_CHILD_SA exchanges from 3 messages down to 2 ๐
- Boost robustness: the responder doesn't do significant processing until it gets a message proving the initiator can receive messages at its claimed IP address ๐ก๏ธ no cap, main character energy for the responder ๐
- Fix cryptographic weaknesses like the problem with symmetries in hashes used for authentication (documented by Tero Kivinen) ๐ซถ
- Give Traffic Selectors their own payload type instead of overloading ID payloads, and make the Traffic Selectors that can be specified way more flexible ๐
- Specify required behavior under certain error conditions, or when data that isn't understood is received, so future revisions can happen without breaking backward compatibility ๐ธ
- Simplify and clarify how shared state is maintained when there are network failures and DoS attacks ๐ and
- Keep existing syntax and magic numbers to the extent possible, so IKEv1 implementations can be enhanced to support IKEv2 with minimum effort โจ iconic, honestly
Appendix B. Diffie-Hellman Groups ๐ธ
There are two Diffie-Hellman groups defined here for use in IKE ๐ They were generated by Richard Schroeppel at the University of Arizona, and the properties of these primes are described in [OAKLEY].
The strength supplied by group 1 may not be sufficient for typical uses, so it's only here for historic reasons ๐
Additional Diffie-Hellman groups have been defined in [ADDGROUP] ๐
B.1. Group 1 - 768-bit MODP
This group is assigned ID 1 (one) ๐
The prime is: 2^768 - 2 ^704 - 1 + 2^64 * { [2^638 pi] + 149686 } Its hexadecimal value is:
FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1
29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD
EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245
E485B576 625E7EC6 F44C42E9 A63A3620 FFFFFFFF FFFFFFFF
The generator is 2 โจ
B.2. Group 2 - 1024-bit MODP
This group is assigned ID 2 (two) ๐ฆ
The prime is 2^1024 - 2^960 - 1 + 2^64 * { [2^894 pi] + 129093 }. Its hexadecimal value is:
FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1
29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD
EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245
E485B576 625E7EC6 F44C42E9 A637ED6B 0BFF5CB6 F406B7ED
EE386BFB 5A899FA5 AE9F2411 7C4B1FE6 49286651 ECE65381
FFFFFFFF FFFFFFFF
The generator is 2 ๐
Appendix C. Exchanges and Payloads ๐ง
This appendix is a quick cheat sheet of the IKEv2 exchanges and which payloads can show up in which message ๐ It's purely informative; if it disagrees with the body of this document, the other text is considered correct ๐
Vendor ID (V) payloads may be included in any place in any message ๐ This sequence shows what the most logical places for them are.
C.1. IKE_SA_INIT Exchange
request --> [N(COOKIE),]
SA, KE, Ni,
[N(NAT_DETECTION_SOURCE_IP)+,
N(NAT_DETECTION_DESTINATION_IP),]
[V+][N+]
normal response <-- SA, KE, Nr,
(no cookie) [N(NAT_DETECTION_SOURCE_IP),
N(NAT_DETECTION_DESTINATION_IP),]
[[N(HTTP_CERT_LOOKUP_SUPPORTED),] CERTREQ+,]
[V+][N+]
cookie response <-- N(COOKIE),
[V+][N+]
different Diffie- <-- N(INVALID_KE_PAYLOAD),
Hellman group [V+][N+]
wanted
C.2. IKE_AUTH Exchange without EAP
request --> IDi, [CERT+,]
[N(INITIAL_CONTACT),]
[[N(HTTP_CERT_LOOKUP_SUPPORTED),] CERTREQ+,]
[IDr,]
AUTH,
[CP(CFG_REQUEST),]
[N(IPCOMP_SUPPORTED)+,]
[N(USE_TRANSPORT_MODE),]
[N(ESP_TFC_PADDING_NOT_SUPPORTED),]
[N(NON_FIRST_FRAGMENTS_ALSO),]
SA, TSi, TSr,
[V+][N+]
response <-- IDr, [CERT+,]
AUTH,
[CP(CFG_REPLY),]
[N(IPCOMP_SUPPORTED),]
[N(USE_TRANSPORT_MODE),]
[N(ESP_TFC_PADDING_NOT_SUPPORTED),]
[N(NON_FIRST_FRAGMENTS_ALSO),]
SA, TSi, TSr,
[N(ADDITIONAL_TS_POSSIBLE),]
[V+][N+]
error in Child SA <-- IDr, [CERT+,]
creation AUTH,
N(error),
[V+][N+]
C.3. IKE_AUTH Exchange with EAP
first request --> IDi,
[N(INITIAL_CONTACT),]
[[N(HTTP_CERT_LOOKUP_SUPPORTED),] CERTREQ+,]
[IDr,]
[CP(CFG_REQUEST),]
[N(IPCOMP_SUPPORTED)+,]
[N(USE_TRANSPORT_MODE),]
[N(ESP_TFC_PADDING_NOT_SUPPORTED),]
[N(NON_FIRST_FRAGMENTS_ALSO),]
SA, TSi, TSr,
[V+][N+]
first response <-- IDr, [CERT+,] AUTH,
EAP,
[V+][N+]
/ --> EAP
repeat 1..N times |
\ <-- EAP
last request --> AUTH
last response <-- AUTH,
[CP(CFG_REPLY),]
[N(IPCOMP_SUPPORTED),]
[N(USE_TRANSPORT_MODE),]
[N(ESP_TFC_PADDING_NOT_SUPPORTED),]
[N(NON_FIRST_FRAGMENTS_ALSO),]
SA, TSi, TSr,
[N(ADDITIONAL_TS_POSSIBLE),]
[V+][N+]
C.4. CREATE_CHILD_SA Exchange for Creating or Rekeying Child SAs
request --> [N(REKEY_SA),]
[CP(CFG_REQUEST),]
[N(IPCOMP_SUPPORTED)+,]
[N(USE_TRANSPORT_MODE),]
[N(ESP_TFC_PADDING_NOT_SUPPORTED),]
[N(NON_FIRST_FRAGMENTS_ALSO),]
SA, Ni, [KEi,] TSi, TSr,
[V+][N+]
normal <-- [CP(CFG_REPLY),]
response [N(IPCOMP_SUPPORTED),]
[N(USE_TRANSPORT_MODE),]
[N(ESP_TFC_PADDING_NOT_SUPPORTED),]
[N(NON_FIRST_FRAGMENTS_ALSO),]
SA, Nr, [KEr,] TSi, TSr,
[N(ADDITIONAL_TS_POSSIBLE),]
[V+][N+]
error case <-- N(error)
different Diffie- <-- N(INVALID_KE_PAYLOAD),
Hellman group [V+][N+]
wanted
C.5. CREATE_CHILD_SA Exchange for Rekeying the IKE SA
request --> SA, Ni, KEi,
[V+][N+]
response <-- SA, Nr, KEr,
[V+][N+]
C.6. INFORMATIONAL Exchange
request --> [N+,]
[D+,]
[CP(CFG_REQUEST)]
response <-- [N+,]
[D+,]
[CP(CFG_REPLY)]
Acknowledgements ๐ซถ
Many individuals in the IPsecME Working Group were super helpful, contributing ideas and text for this document, and also reviewing the clarifications suggested by others ๐
The acknowledgements from the IKEv2 document were:
This document is a collaborative effort of the entire IPsec WG. If there were no limit to the number of authors that could appear on an RFC, the following, in alphabetical order, would have been listed: Bill Aiello, Stephane Beaulieu, Steve Bellovin, Sara Bitan, Matt Blaze, Ran Canetti, Darren Dukes, Dan Harkins, Paul Hoffman, John Ioannidis, Charlie Kaufman, Steve Kent, Angelos Keromytis, Tero Kivinen, Hugo Krawczyk, Andrew Krywaniuk, Radia Perlman, Omer Reingold, and Michael Richardson. Many other people contributed to the design. It is an evolution of IKEv1, ISAKMP, and the IPsec DOI, each of which has its own list of authors. Hugh Daniel suggested the feature of having the initiator, in message 3, specify a name for the responder, and gave the feature the cute name "You Tarzan, Me Jane" ๐ญ๐ David Faucher and Valery Smyslov helped refine the design of the Traffic Selector negotiation ๐
Authors' Addresses ๐
Charlie Kaufman
Charlie Kaufman
Microsoft
1 Microsoft Way
Redmond, WA 98052
United States
EMail: charliekaufman@outlook.com
Paul Hoffman
Paul Hoffman
VPN Consortium
127 Segre Place
Santa Cruz, CA 95060
United States
Phone: 1-831-426-9827
EMail: paul.hoffman@vpnc.org
Yoav Nir
Yoav Nir
Check Point Software Technologies Ltd.
5 Hasolelim St.
Tel Aviv 6789735
Israel
EMail: ynir.ietf@gmail.com
Pasi Eronen
Pasi Eronen
Independent
EMail: pe@iki.fi
Tero Kivinen
Tero Kivinen
INSIDE Secure
Eerikinkatu 28
HELSINKI FI-00180
Finland
EMail: kivinen@iki.fi
๐ฆ where this page comes from
- ietf: rfc7296 2014-10
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms