[RFCs/IDs] [Plain Text] [Tracker] [WG] [Email] [Diff1] [Diff2] [Nits]

Versions: 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 RFC 4306

INTERNET-DRAFT                                Charlie Kaufman, Editor
draft-ietf-ipsec-ikev2-17.txt
Obsoletes: 2407, 2408, 2409                        September 23, 2004
Expires: March 2005


                 Internet Key Exchange (IKEv2) Protocol


Status of this Memo

   This document is an Internet-Draft and is subject to all provisions
   of Section 10 of RFC2026. Internet-Drafts are working documents of
   the Internet Engineering Task Force (IETF), its areas, and its
   working groups. Note that other groups may also distribute working
   documents as Internet-Drafts.

   Internet-Drafts are draft documents valid for a maximum of six months
   and may be updated, replaced, or obsoleted by other documents at any
   time. It is inappropriate to use Internet-Drafts as reference
   material or to cite them other than as "work in progress."

   The list of current Internet-Drafts can be accessed at
   http://www.ietf.org/1id-abstracts.html

   The list of Internet-Draft Shadow Directories can be accessed at
   http://www.ietf.org/shadow.html

   This document is a submission by the IPSEC Working Group of the
   Internet Engineering Task Force (IETF).  Comments should be submitted
   to the ipsec@lists.tislabs.com mailing list.

   Distribution of this memo is unlimited.

   This Internet-Draft expires in March 2005.

Copyright Notice

   Copyright (C) The Internet Society (2004).  All Rights Reserved.

Abstract

   This document describes version 2 of the Internet Key Exchange (IKE)
   protocol.  IKE is a component of IPsec used for performing mutual
   authentication and establishing and maintaining security associations
   (SAs).

   This version of the IKE specification combines the contents of what



IKEv2                 draft-ietf-ipsec-ikev2-17.txt             [Page 1]

Internet-Draft                                        September 23, 2004


   were previously separate documents, including ISAKMP (RFC 2408), IKE
   (RFC 2409), the Internet DOI (RFC 2407), NAT Traversal, Legacy
   authentication, and remote address acquisition.

   Version 2 of IKE does not interoperate with version 1, but it has
   enough of the header format in common that both versions can
   unambiguously run over the same UDP port.

Table of Contents


   1 Introduction...............................................3
   1.1 Usage Scenarios..........................................5
   1.2 The Initial Exchanges....................................7
   1.3 The CREATE_CHILD_SA Exchange.............................9
   1.4 The INFORMATIONAL Exchange..............................10
   1.5 Informational Messages outside of an IKE_SA.............12
   2 IKE Protocol Details and Variations.......................12
   2.1 Use of Retransmission Timers............................13
   2.2 Use of Sequence Numbers for Message ID..................13
   2.3 Window Size for overlapping requests....................14
   2.4 State Synchronization and Connection Timeouts...........15
   2.5 Version Numbers and Forward Compatibility...............16
   2.6 Cookies.................................................18
   2.7 Cryptographic Algorithm Negotiation.....................20
   2.8 Rekeying................................................21
   2.9 Traffic Selector Negotiation............................23
   2.10 Nonces.................................................25
   2.11 Address and Port Agility...............................26
   2.12 Reuse of Diffie-Hellman Exponentials...................26
   2.13 Generating Keying Material.............................27
   2.14 Generating Keying Material for the IKE_SA..............28
   2.15 Authentication of the IKE_SA...........................29
   2.16 Extensible Authentication Protocol Methods.............30
   2.17 Generating Keying Material for CHILD_SAs...............32
   2.18 Rekeying IKE_SAs using a CREATE_CHILD_SA exchange......33
   2.19 Requesting an internal address on a remote network.....33
   2.20 Requesting a Peer's Version............................35
   2.21 Error Handling.........................................35
   2.22 IPComp.................................................36
   2.23 NAT Traversal..........................................37
   2.24 ECN (Explicit Congestion Notification).................40
   3 Header and Payload Formats................................40
   3.1 The IKE Header..........................................40
   3.2 Generic Payload Header..................................43
   3.3 Security Association Payload............................44
   3.4 Key Exchange Payload....................................54
   3.5 Identification Payloads.................................55



IKEv2                 draft-ietf-ipsec-ikev2-17.txt             [Page 2]

Internet-Draft                                        September 23, 2004


   3.6 Certificate Payload.....................................57
   3.7 Certificate Request Payload.............................60
   3.8 Authentication Payload..................................62
   3.9 Nonce Payload...........................................62
   3.10 Notify Payload.........................................63
   3.11 Delete Payload.........................................71
   3.12 Vendor ID Payload......................................72
   3.13 Traffic Selector Payload...............................73
   3.14 Encrypted Payload......................................76
   3.15 Configuration Payload..................................77
   3.16 Extensible Authentication Protocol (EAP) Payload.......82
   4 Conformance Requirements..................................84
   5 Security Considerations...................................86
   6 IANA Considerations.......................................89
   7 Acknowledgements..........................................89
   8 References................................................90
   8.1 Normative References....................................90
   8.2 Informative References..................................91
   Appendix A: Summary of Changes from IKEv1...................94
   Appendix B: Diffie-Hellman Groups...........................96
   Change History (To be removed from RFC).....................97
   Editor's Address...........................................108
   Full Copyright Statement...................................108
   Intellectual Property Statement............................108

Requirements Terminology

   Keywords "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT" and
   "MAY" that appear in this document are to be interpreted as described
   in [Bra97].

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

1 Introduction

   IP Security (IPsec) provides confidentiality, data integrity, access
   control, and data source authentication to IP datagrams. These
   services are provided by maintaining shared state between the source
   and the sink of an IP datagram. This state defines, among other
   things, the specific services provided to the datagram, which
   cryptographic algorithms will be used to provide the services, and
   the keys used as input to the cryptographic algorithms.

   Establishing this shared state in a manual fashion does not scale
   well.  Therefore a protocol to establish this state dynamically is
   needed.  This memo describes such a protocol-- the Internet Key
   Exchange (IKE).  This is version 2 of IKE. Version 1 of IKE was



IKEv2                 draft-ietf-ipsec-ikev2-17.txt             [Page 3]

Internet-Draft                                        September 23, 2004


   defined in RFCs 2407, 2408, and 2409. This single document is
   intended to replace all three of those RFCs.

   Definitions of the primitive terms in this document (such as Security
   Association or SA) can be found in [RFC2401bis].

   IKE performs mutual authentication between two parties and
   establishes an IKE security association (SA) that includes shared
   secret information that can be used to efficiently establish SAs for
   ESP [RFC2406] and/or AH [RFC2402] and a set of cryptographic
   algorithms to be used by the SAs to protect the traffic that they
   carry.  In this document, the term "suite" or "cryptographic suite"
   refers to a complete set of algorithms used to protect an SA. An
   initiator proposes one or more suites by listing supported algorithms
   that can be combined into suites in a mix and match fashion.  IKE can
   also negotiate use of IPComp [IPCOMP] in connection with an ESP
   and/or AH SA.  We call the IKE SA an "IKE_SA". The SAs for ESP and/or
   AH that get set up through that IKE_SA we call "CHILD_SA"s.

   All IKE communications consist of pairs of messages: a request and a
   response. The pair is called an "exchange".  We call the first
   messages establishing an IKE_SA IKE_SA_INIT and IKE_AUTH exchanges
   and subsequent IKE exchanges CREATE_CHILD_SA or INFORMATIONAL
   exchanges. In the common case, there is a single IKE_SA_INIT exchange
   and a single IKE_AUTH exchange (a total of four messages) to
   establish the IKE_SA and the first CHILD_SA. In exceptional cases,
   there may be more than one of each of these exchanges. In all cases,
   all IKE_SA_INIT exchanges MUST complete before any other exchange
   type, then all IKE_AUTH exchanges MUST complete, and following that
   any number of CREATE_CHILD_SA and INFORMATIONAL exchanges may occur
   in any order.  In some scenarios, only a single CHILD_SA is needed
   between the IPsec endpoints and therefore there would be no
   additional exchanges. Subsequent exchanges MAY be used to establish
   additional CHILD_SAs between the same authenticated pair of endpoints
   and to perform housekeeping functions.

   IKE message flow always consists of a request followed by a response.
   It is the responsibility of the requester to ensure reliability.  If
   the response is not received within a timeout interval, the requester
   needs to retransmit the request (or abandon the connection).

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

   The second request/response (IKE_AUTH) transmits identities, proves
   knowledge of the secrets corresponding to the two identities, and
   sets up an SA for the first (and often only) AH and/or ESP CHILD_SA.



IKEv2                 draft-ietf-ipsec-ikev2-17.txt             [Page 4]

Internet-Draft                                        September 23, 2004


   The types of subsequent exchanges are CREATE_CHILD_SA (which creates
   a CHILD_SA), and INFORMATIONAL (which deletes an SA, reports error
   conditions, or does other housekeeping).  Every request requires a
   response. An INFORMATIONAL request with no payloads (other than the
   empty Encrypted payload required by the syntax) is commonly used as a
   check for liveness.  These subsequent exchanges cannot be used until
   the initial exchanges have completed.

   In the description that follows, we assume that no errors occur.
   Modifications to the flow should errors occur are described in
   section 2.21.

1.1 Usage Scenarios

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

1.1.1 Security Gateway to Security Gateway Tunnel

                    +-+-+-+-+-+            +-+-+-+-+-+
                    !         ! IPsec      !         !
       Protected    !Tunnel   ! Tunnel     !Tunnel   !     Protected
       Subnet   <-->!Endpoint !<---------->!Endpoint !<--> Subnet
                    !         !            !         !
                    +-+-+-+-+-+            +-+-+-+-+-+

             Figure 1:  Security Gateway to Security Gateway Tunnel

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

1.1.2 Endpoint to Endpoint Transport

       +-+-+-+-+-+                                          +-+-+-+-+-+
       !         !                 IPsec Transport          !         !
       !Protected!                or Tunnel Mode SA         !Protected!
       !Endpoint !<---------------------------------------->!Endpoint !
       !         !                                          !         !
       +-+-+-+-+-+                                          +-+-+-+-+-+

                       Figure 2:  Endpoint to Endpoint

   In this scenario, both endpoints of the IP connection implement



IKEv2                 draft-ietf-ipsec-ikev2-17.txt             [Page 5]

Internet-Draft                                        September 23, 2004


   IPsec, as required of hosts in [RFC2401bis]. Transport mode will
   commonly be used with no inner IP header.  If there is an inner IP
   header, the inner addresses will be the same as the outer addresses.
   A single pair of addresses will be negotiated for packets to be
   protected by this SA. These endpoints MAY implement application layer
   access controls based on the IPsec authenticated identities of the
   participants. This scenario enables the end-to-end security that has
   been a guiding principle for the Internet since [RFC1958], [RFC2775],
   and a method of limiting the inherent problems with complexity in
   networks noted by [RFC3439].  While this scenario may not be fully
   applicable to the IPv4 Internet, it has been deployed successfully in
   specific scenarios within intranets using IKEv1. It should be more
   broadly enabled during the transition to IPv6 and with the adoption
   of IKEv2.

   It is possible in this scenario that one or both of the protected
   endpoints will be behind a network address translation (NAT) node, in
   which case the tunneled packets will have to be UDP encapsulated so
   that port numbers in the UDP headers can be used to identify
   individual endpoints "behind" the NAT (see section 2.23).

1.1.3 Endpoint to Security Gateway Transport

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

                 Figure 3:  Endpoint to Security Gateway Tunnel

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

   In this scenario, packets will use tunnel mode. On each packet from
   the protected endpoint, the outer IP header will contain the source



IKEv2                 draft-ietf-ipsec-ikev2-17.txt             [Page 6]

Internet-Draft                                        September 23, 2004


   IP address associated with its current location (i.e., the address
   that will get traffic routed to the endpoint directly) while the
   inner IP header will contain the source IP address assigned by the
   security gateway (i.e., the address that will get traffic routed to
   the security gateway for forwarding to the endpoint). The outer
   destination address will always be that of the security gateway,
   while the inner destination address will be the ultimate destination
   for the packet.

   In this scenario, it is possible that the protected endpoint will be
   behind a NAT. In that case, the IP address as seen by the security
   gateway will not be the same as the IP address sent by the protected
   endpoint, and packets will have to be UDP encapsulated in order to be
   routed properly.

1.1.4 Other Scenarios

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

1.2 The Initial Exchanges

   Communication using IKE always begins with IKE_SA_INIT and IKE_AUTH
   exchanges (known in IKEv1 as Phase 1). These initial exchanges
   normally consist of four messages, though in some scenarios that
   number can grow. All communications using IKE consist of
   request/response pairs.  We'll describe the base exchange first,
   followed by variations.  The first pair of messages (IKE_SA_INIT)
   negotiate cryptographic algorithms, exchange nonces, and do a Diffie-
   Hellman exchange.

   The second pair of messages (IKE_AUTH) authenticate the previous
   messages, exchange identities and certificates, and establish the
   first CHILD_SA. Parts of these messages are encrypted and integrity
   protected with keys established through the IKE_SA_INIT exchange, so
   the identities are hidden from eavesdroppers and all fields in all
   the messages are authenticated.

   In the following description, the payloads contained in the message
   are indicated by names such as SA. The details of the contents of



IKEv2                 draft-ietf-ipsec-ikev2-17.txt             [Page 7]

Internet-Draft                                        September 23, 2004


   each payload are described later. Payloads which may optionally
   appear will be shown in brackets, such as [CERTREQ], would indicate
   that optionally a certificate request payload can be included.

   The initial exchanges are as follows:

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

   HDR contains the SPIs, version numbers, and flags of various sorts.
   The SAi1 payload states the cryptographic algorithms the initiator
   supports for the IKE_SA.  The KE payload sends the initiator's
   Diffie-Hellman value. Ni is the initiator's nonce.

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

   The responder chooses a cryptographic suite from the initiator's
   offered choices and expresses that choice in the SAr1 payload,
   completes the Diffie-Hellman exchange with the KEr payload, and sends
   its nonce in the Nr payload.

   At this point in the negotiation each party can generate SKEYSEED,
   from which all keys are derived for that IKE_SA.  All but the headers
   of all the messages that follow are encrypted and integrity
   protected.  The keys used for the encryption and integrity protection
   are derived from SKEYSEED and are known as SK_e (encryption) and SK_a
   (authentication, a.k.a.  integrity protection). A separate SK_e and
   SK_a is computed for each direction.  In addition to the keys SK_e
   and SK_a derived from the DH value for protection of the IKE_SA,
   another quantity SK_d is derived and used for derivation of further
   keying material for CHILD_SAs.  The notation SK { ... } indicates
   that these 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 asserts its identity with the IDi payload, proves
   knowledge of the secret corresponding to IDi and integrity protects
   the contents of the first message using the AUTH payload (see section
   2.15).  It might also send its certificate(s) in CERT payload(s) and
   a list of its trust anchors in CERTREQ payload(s). If any CERT
   payloads are included, the first certificate provided MUST contain
   the public key used to verify the AUTH field.  The optional payload
   IDr enables the initiator to specify which of the responder's
   identities it wants to talk to. This is useful when the machine on
   which the responder is running is hosting multiple identities at the



IKEv2                 draft-ietf-ipsec-ikev2-17.txt             [Page 8]

Internet-Draft                                        September 23, 2004


   same IP address.  The initiator begins negotiation of a CHILD_SA
   using the SAi2 payload. The final fields (starting with SAi2) are
   described in the description of the CREATE_CHILD_SA exchange.

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

   The responder asserts its identity with the IDr payload, optionally
   sends one or more certificates (again with the certificate containing
   the public key used to verify AUTH listed first), authenticates its
   identity and protects the integrity of the second message with the
   AUTH payload, and completes negotiation of a CHILD_SA with the
   additional fields described below in the CREATE_CHILD_SA exchange.

   The recipients of messages 3 and 4 MUST verify that all signatures
   and MACs are computed correctly and that the names in the ID payloads
   correspond to the keys used to generate the AUTH payload.

1.3 The CREATE_CHILD_SA Exchange

   This exchange consists of a single request/response pair, and was
   referred to as a phase 2 exchange in IKEv1. It MAY be initiated by
   either end of the IKE_SA after the initial exchanges are completed.

   All messages following the initial exchange are cryptographically
   protected using the cryptographic algorithms and keys negotiated in
   the first two messages of the IKE exchange.  These subsequent
   messages use the syntax of the Encrypted Payload described in section
   3.14. All subsequent messages included an Encrypted Payload, even if
   they are referred to in the text as "empty".

   Either endpoint may initiate a CREATE_CHILD_SA exchange, so in this
   section the term initiator refers to the endpoint initiating this
   exchange.

   A CHILD_SA is created by sending a CREATE_CHILD_SA request.  The
   CREATE_CHILD_SA request MAY optionally contain a KE payload for an
   additional Diffie-Hellman exchange to enable stronger guarantees of
   forward secrecy for the CHILD_SA. The keying material for the
   CHILD_SA is a function of SK_d established during the establishment
   of the IKE_SA, the nonces exchanged during the CREATE_CHILD_SA
   exchange, and the Diffie-Hellman value (if KE payloads are included
   in the CREATE_CHILD_SA exchange).

   In the CHILD_SA created as part of the initial exchange, a second KE
   payload and nonce MUST NOT be sent. The nonces from the initial
   exchange are used in computing the keys for the CHILD_SA.




IKEv2                 draft-ietf-ipsec-ikev2-17.txt             [Page 9]

Internet-Draft                                        September 23, 2004


   The CREATE_CHILD_SA request contains:

       Initiator                                 Responder
      -----------                               -----------
       HDR, SK {[N], 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 in the TSi and TSr payloads. If this
   CREATE_CHILD_SA exchange is rekeying an existing SA other than the
   IKE_SA, the leading N payload of type REKEY_SA MUST identify the SA
   being rekeyed. If this CREATE_CHILD_SA exchange is not rekeying an
   existing SA, the N payload MUST be omitted.  If the SA offers include
   different Diffie-Hellman groups, KEi MUST be an element of the group
   the initiator expects the responder to accept. If it guesses wrong,
   the CREATE_CHILD_SA exchange will fail and it will have to retry with
   a different KEi.

   The message following the header is encrypted and the message
   including the header is integrity protected using the cryptographic
   algorithms negotiated for the IKE_SA.

   The CREATE_CHILD_SA response contains:

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

   The responder replies (using the same Message ID to respond) with the
   accepted offer in an SA payload, and a Diffie-Hellman value in the
   KEr payload if KEi was included in the request and the selected
   cryptographic suite includes that group.  If the responder chooses a
   cryptographic suite with a different group, it MUST reject the
   request. The initiator SHOULD repeat the request, but now with a KEi
   payload from the group the responder selected.

   The traffic selectors for traffic to be sent on that SA are specified
   in the TS payloads, which may be a subset of what the initiator of
   the CHILD_SA proposed. Traffic selectors are omitted if this
   CREATE_CHILD_SA request is being used to change the key of the
   IKE_SA.

1.4 The INFORMATIONAL Exchange

   At various points during the operation of an IKE_SA, peers may desire
   to convey control messages to each other regarding errors or
   notifications of certain events. To accomplish this IKE defines an
   INFORMATIONAL exchange.  INFORMATIONAL exchanges MUST ONLY occur



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 10]

Internet-Draft                                        September 23, 2004


   after the initial exchanges and are cryptographically protected with
   the negotiated keys.

   Control messages that pertain to an IKE_SA MUST be sent under that
   IKE_SA. Control messages that pertain to CHILD_SAs MUST be sent under
   the protection of the IKE_SA which generated them (or its successor
   if the IKE_SA was replaced for the purpose of rekeying).

   Messages in an INFORMATIONAL Exchange contain zero or more
   Notification, Delete, and Configuration payloads. The Recipient of an
   INFORMATIONAL Exchange request MUST send some response (else the
   Sender will assume the message was lost in the network and will
   retransmit it). That response MAY be a message with no payloads. The
   request message in an INFORMATIONAL Exchange MAY also contain no
   payloads. This is the expected way an endpoint can ask the other
   endpoint to verify that it is alive.

   ESP and AH SAs always exist in pairs, with one SA in each direction.
   When an SA is closed, both members of the pair MUST be closed. When
   SAs are nested, as when data (and IP headers if in tunnel mode) are
   encapsulated first with IPComp, then with ESP, and finally with AH
   between the same pair of endpoints, all of the SAs MUST be deleted
   together. Each endpoint MUST close its incoming SAs and allow the
   other endpoint to close the other SA in each pair. To delete an SA,
   an INFORMATIONAL Exchange with one or more delete payloads is sent
   listing the SPIs (as they would be expected in the headers of inbound
   packets) of the SAs to be deleted. The recipient MUST close the
   designated SAs. Normally, the reply in the INFORMATIONAL Exchange
   will contain delete payloads for the paired SAs going in the other
   direction. There is one exception.  If by chance both ends of a set
   of SAs independently decide to close them, each may send a delete
   payload and the two requests may cross in the network. If a node
   receives a delete request for SAs for which it has already issued a
   delete request, it MUST delete the outgoing SAs while processing the
   request and the incoming SAs while processing the response. In that
   case, the responses MUST NOT include delete payloads for the deleted
   SAs, since that would result in duplicate deletion and could in
   theory delete the wrong SA.

   A node SHOULD regard half closed connections as anomalous and audit
   their existence should they persist. Note that this specification
   nowhere specifies time periods, so it is up to individual endpoints
   to decide how long to wait. A node MAY refuse to accept incoming data
   on half closed connections but MUST NOT unilaterally close them and
   reuse the SPIs. If connection state becomes sufficiently messed up, a
   node MAY close the IKE_SA which will implicitly close all SAs
   negotiated under it. It can then rebuild the SAs it needs on a clean
   base under a new IKE_SA.



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 11]

Internet-Draft                                        September 23, 2004


   The INFORMATIONAL Exchange is defined as:

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

   The processing of an INFORMATIONAL Exchange is determined by its
   component payloads.

1.5 Informational Messages outside of an IKE_SA

   If an encrypted IKE packet arrives on port 500 or 4500 with an
   unrecognized SPI, it could be because the receiving node has recently
   crashed and lost state or because of some other system malfunction or
   attack. If the receiving node has an active IKE_SA to the IP address
   from whence the packet came, it MAY send a notification of the
   wayward packet over that IKE_SA in an informational exchange.  If it
   does not have such an IKE_SA, it MAY send an Informational message
   without cryptographic protection to the source IP address. Such a
   message is not part of an informational exchange, and the receiving
   node MUST NOT respond to it. Doing so could cause a message loop.

2 IKE Protocol Details and Variations

   IKE normally listens and sends on UDP port 500, though IKE messages
   may also be received on UDP port 4500 with a slightly different
   format (see section 2.23).  Since UDP is a datagram (unreliable)
   protocol, IKE includes in its definition recovery from transmission
   errors, including packet loss, packet replay, and packet forgery. IKE
   is designed to function so long as (1) at least one of a series of
   retransmitted packets reaches its destination before timing out; and
   (2) the channel is not so full of forged and replayed packets so as
   to exhaust the network or CPU capacities of either endpoint. Even in
   the absence of those minimum performance requirements, IKE is
   designed to fail cleanly (as though the network were broken).

   While IKEv2 messages are intended to be short, they contain
   structures with no hard upper bound on size (in particular, X.509
   certificates), and IKEv2 itself does not have a mechanism for
   fragmenting large messages. IP defines a mechanism for fragmentation
   of oversize UDP messages, but implementations vary in the maximum
   message size supported. Further, use of IP fragmentation opens an
   implementation to denial of service attacks [KPS03]. Finally, some
   NAT and/or firewall implementations may block IP fragments.

   All IKEv2 implementations MUST be able to send, receive, and process
   IKE messages that are up to 1280 bytes long, and they SHOULD be able



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 12]

Internet-Draft                                        September 23, 2004


   to send, receive, and process messages that are up to 3000 bytes
   long.  IKEv2 implementations SHOULD be aware of the maximum UDP
   message size supported and MAY shorten messages by leaving out some
   certificates or cryptographic suite proposals if that will keep
   messages below the maximum.  Use of the "Hash and URL" formats rather
   then including certificates in exchanges where possible can avoid
   most problems. Implementations and configuration should keep in mind,
   however, that if the URL lookups are only possible after the IPsec SA
   is established, recursion issues could prevent this technique from
   working.

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 request/response pairs.
   Once the IKE_SA is set up, either end of the security association may
   initiate requests at any time, and there can be many requests and
   responses "in flight" at any given moment. But each message is
   labeled as either a request or a response and for each
   request/response pair 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 in the event of a timeout. The responder MUST never
   retransmit a response unless it receives a retransmission of the
   request. In that event, the responder MUST ignore the retransmitted
   request except insofar as it triggers 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 the
   sequence number in the response plus its window size (see section
   2.3).

   IKE is a reliable protocol, in the sense that the initiator MUST
   retransmit a request until either it receives a corresponding reply
   OR it deems the IKE security association to have failed and it
   discards all state associated with the IKE_SA and any CHILD_SAs
   negotiated using that IKE_SA.

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.

   The Message ID is a 32 bit quantity, which is zero for the first IKE
   request in each direction. The IKE_SA initial setup messages will
   always be numbered 0 and 1.  Each endpoint in the IKE Security



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 13]

Internet-Draft                                        September 23, 2004


   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 very
   different numbers of requests, the Message IDs in the two directions
   can be very different. There is no ambiguity in the messages,
   however, because the (I)nitiator and (R)esponse bits in the message
   header specify which of the four messages a particular one is.

   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. Rekeying an IKE_SA resets the sequence numbers.

2.3 Window Size for overlapping requests

   In order to maximize IKE throughput, an IKE endpoint MAY issue
   multiple requests before getting a response to any of them if the
   other endpoint has indicated its ability to handle such requests. For
   simplicity, an IKE implementation MAY choose to process requests
   strictly in order and/or wait for a response to one request before
   issuing another. Certain rules must be followed to assure
   interoperability between implementations using different strategies.

   After an IKE_SA is set up, either end can initiate one or more
   requests. These requests may pass one another over the network. An
   IKE endpoint MUST be prepared to accept and process a request while
   it has a request outstanding in order to avoid a deadlock in this
   situation. An IKE endpoint SHOULD be prepared to accept and process
   multiple requests while it has a request outstanding.

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

   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



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 14]

Internet-Draft                                        September 23, 2004


   corresponding response. An IKE endpoint MUST keep a copy of (or be
   able to regenerate exactly) the number of previous responses equal to
   its declared window size in case its response was lost and the
   initiator requests its retransmission by retransmitting the request.

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

2.4 State Synchronization and Connection Timeouts

   An IKE endpoint is allowed to forget all of its state associated with
   an IKE_SA and the collection of corresponding CHILD_SAs at any time.
   This is the anticipated behavior in the event of an endpoint crash
   and restart. It is important when an endpoint either fails or
   reinitializes its state that the other endpoint detect those
   conditions and not continue to waste network bandwidth by sending
   packets over discarded SAs and having them fall into a black hole.

   Since IKE is designed to operate in spite of Denial of Service (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 initiate a
   request to see whether the other endpoint is alive. To check whether
   the other side is alive, IKE specifies an empty INFORMATIONAL message
   that (like all IKE requests) requires an acknowledgment (note that
   within the context of an IKE_SA, an "empty" message consists of an
   IKE header followed by an Encrypted payload that contains no
   payloads). If a cryptographically protected message has been received
   from the other side recently, unprotected notifications MAY be
   ignored. Implementations MUST limit the rate at which they take
   actions based on unprotected messages.

   Numbers of retries and lengths of timeouts are not covered in this
   specification because they do not affect interoperability. It is
   suggested that messages be retransmitted at least a dozen times over
   a period of at least several minutes before giving up on an SA, but
   different environments may require different rules.  To be a good
   network citizen, retranmission times MUST increase exponentially to
   avoid flooding the network and making an existing congestion
   situation worse.  If there has only been outgoing traffic on all of



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 15]

Internet-Draft                                        September 23, 2004


   the SAs associated with an IKE_SA, it is essential to confirm
   liveness of the other endpoint to avoid black holes. If no
   cryptographically protected messages have been received on an IKE_SA
   or any of its CHILD_SAs recently, the system needs to perform a
   liveness check in order to prevent sending messages to a dead peer.
   Receipt of a fresh cryptographically protected message on an IKE_SA
   or any of its CHILD_SAs assures liveness of the IKE_SA and all of its
   CHILD_SAs. Note that this places requirements on the failure modes of
   an IKE endpoint. An implementation MUST NOT continue sending on any
   SA if some failure prevents it from receiving on all of the
   associated SAs. If CHILD_SAs can fail independently from one another
   without the associated IKE_SA being able to send a delete message,
   then they MUST be negotiated by separate IKE_SAs.

   There is a Denial of Service attack on the initiator of an IKE_SA
   that can be avoided if the initiator takes the proper care. Since the
   first two messages of an SA setup are not 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 as potentially legitimate,
   respond to it, 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 are cryptographically valid.

   Note that with these rules, there is no reason to negotiate and agree
   upon an SA lifetime. If IKE presumes the partner is dead, based on
   repeated lack of acknowledgment to an IKE message, then the IKE SA
   and all CHILD_SAs set up through that IKE_SA are deleted.

   An IKE endpoint may at any time delete inactive CHILD_SAs to recover
   resources used to hold their state. If an IKE endpoint chooses to
   delete CHILD_SAs, it MUST send Delete payloads to the other end
   notifying it of the deletion. It MAY similarly time out the IKE_SA.
   Closing the IKE_SA implicitly closes all associated CHILD_SAs. In
   this case, an IKE endpoint SHOULD send a Delete payload indicating
   that it has closed the IKE_SA.

2.5 Version Numbers and Forward Compatibility

   This document describes version 2.0 of IKE, meaning the major version
   number is 2 and the minor version number is zero. It is likely that
   some implementations will want to support both version 1.0 and
   version 2.0, and in the future, other versions.

   The major version number should only be incremented if the packet



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 16]

Internet-Draft                                        September 23, 2004


   formats or required actions have changed so dramatically that an
   older version node would not be able to interoperate with a newer
   version node if it simply ignored the fields it did not understand
   and took the actions specified in the older specification. The minor
   version number indicates new capabilities, and MUST be ignored by a
   node with a smaller minor version number, but used for informational
   purposes by the node with the larger minor version number. For
   example, it might indicate the ability to process a newly defined
   notification message. The node with the larger minor version number
   would simply note that its correspondent would not be able to
   understand that message and therefore would not send it.

   If an endpoint receives a message with a higher major version number,
   it MUST drop the message and SHOULD send an unauthenticated
   notification message containing the highest 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. In order to prevent two nodes from being tricked
   into corresponding with a lower major version number than the maximum
   that they both support, IKE has a flag that indicates that the node
   is capable of speaking a higher major version number.

   Thus the major version number in the IKE header indicates the version
   number of the message, not the highest version number that the
   transmitter supports. If the initiator is capable of speaking
   versions n, n+1, and n+2, and the responder is capable of speaking
   versions n and n+1, then they will negotiate speaking n+1, where the
   initiator will set the flag indicating its ability to speak a higher
   version. If they mistakenly (perhaps through an active attacker
   sending error messages) negotiate to version n, then both will notice
   that the other side can support a higher version number, and they
   MUST break the connection and reconnect using version n+1.

   Note that IKEv1 does not follow these rules, because there is no way
   in v1 of noting that you are capable of speaking 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 a version 2.0 implementation and their content MUST be
   ignored by a version 2.0 implementation ("Be conservative in what you
   send and liberal in what you receive"). In this way, future versions
   of the protocol can use those fields in a way that is guaranteed to
   be ignored by implementations that do not understand them.
   Similarly, payload types that are not defined are reserved for future
   use and implementations of version 2.0 MUST skip over those payloads



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 17]

Internet-Draft                                        September 23, 2004


   and ignore their contents.

   IKEv2 adds a "critical" flag to each payload header for further
   flexibility for forward compatibility. If the critical flag is set
   and the payload type is unrecognized, the message MUST be rejected
   and the response to the IKE request containing that payload MUST
   include a Notify payload UNSUPPORTED_CRITICAL_PAYLOAD, indicating an
   unsupported critical payload was included. If the critical flag is
   not set and the payload type is unsupported, that payload MUST be
   ignored.

   While new payload types may be added in the future and may appear
   interleaved with the fields defined in this specification,
   implementations MUST send the payloads defined in this specification
   in the order shown in the figures in section 2 and implementations
   SHOULD reject as invalid a message with those payloads in any other
   order.

2.6 Cookies

   The term "cookies" originates with Karn and Simpson [RFC2522] in
   Photuris, an early proposal for key management with IPsec, and it has
   persisted.  The ISAKMP fixed message header includes two eight octet
   fields titled "cookies", and that syntax is used by both IKEv1 and
   IKEv2 though in IKEv2 they are referred to as the IKE SPI and there
   is a new separate field in a Notify payload holding the cookie. The
   initial two eight octet fields in the header are used as a connection
   identifier at the beginning of IKE packets. Each endpoint chooses one
   of the two SPIs and SHOULD choose them so as to be unique identifiers
   of an IKE_SA. An SPI value of zero is special and indicates that the
   remote SPI value is not yet known by the sender.

   Unlike ESP and AH where only the recipient's SPI appears in the
   header of a message, in IKE the sender's SPI is also sent in every
   message. Since the SPI chosen by the original initiator of the IKE_SA
   is always sent first, an endpoint with multiple IKE_SAs open that
   wants to find the appropriate IKE_SA using the SPI it assigned must
   look at the I(nitiator) Flag bit in the header to determine whether
   it assigned the first or the second eight octets.

   In the first message of an initial IKE exchange, the initiator will
   not know the responder's SPI value and will therefore set that field
   to zero.

   An expected attack against IKE is state and CPU exhaustion, where the
   target is flooded with session initiation requests from forged IP
   addresses. This attack can be made less effective if an
   implementation of a responder uses minimal CPU and commits no state



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 18]

Internet-Draft                                        September 23, 2004


   to an SA until it knows the initiator can receive packets at the
   address from which it claims to be sending them. To accomplish this,
   a responder SHOULD - when it detects a large number of half-open
   IKE_SAs - reject initial IKE messages unless they contain a Notify
   payload of type COOKIE. It SHOULD instead send an unprotected IKE
   message as a response and include COOKIE Notify payload with the
   cookie data to be returned.  Initiators who receive such responses
   MUST retry the IKE_SA_INIT with a Notify payload of type COOKIE
   containing the responder supplied cookie data as the first payload
   and all other payloads unchanged.  The initial exchange will then be
   as follows:

       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 do not affect any initiator or responder state
   except for communicating the cookie. In particular, the message
   sequence numbers in the first four messages will all be zero and the
   message sequence numbers in the last two messages will be one. 'A' is
   the SPI assigned by the initiator, while 'B' is the SPI assigned by
   the responder.

   An IKE implementation SHOULD implement its responder cookie
   generation in such a way as to not require any saved state to
   recognize its valid cookie when the second IKE_SA_INIT message
   arrives.  The exact algorithms and syntax they use to generate
   cookies does not affect interoperability and hence is not specified
   here. The following is an example of how an endpoint could use
   cookies to implement limited DOS protection.

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

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




IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 19]

Internet-Draft                                        September 23, 2004


   where <secret> is a randomly generated secret known only to the
   responder and periodically changed and | indicates concatenation.
   <VersionIDofSecret> should be changed whenever <secret> is
   regenerated.  The cookie can be recomputed when the IKE_SA_INIT
   arrives the second time and compared to the cookie in the received
   message. If it matches, the responder knows that SPIr was generated
   since the last change to <secret> and that IPi must be the same as
   the source address it saw the first time. Incorporating SPIi into the
   calculation assures that if multiple IKE_SAs are being set up in
   parallel they will all get different cookies (assuming the initiator
   chooses unique SPIi's).  Incorporating Ni into the hash assures that
   an attacker who sees only message 2 can't successfully forge a
   message 3.

   If a new value for <secret> is chosen while there are connections in
   the process of being initialized, an IKE_SA_INIT might be returned
   with other than the current <VersionIDofSecret>.  The responder in
   that case MAY reject the message by sending another response with a
   new cookie or it MAY keep the old value of <secret> around for a
   short time and accept cookies computed from either one.  The
   responder SHOULD NOT accept cookies indefinitely after <secret> is
   changed, since that would defeat part of the denial of service
   protection. The responder SHOULD change the value of <secret>
   frequently, especially if under attack.

2.7 Cryptographic Algorithm Negotiation

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

   An SA payload consists of one or more proposals. Each proposal
   includes one or more protocols (usually one). Each protocol contains
   one or more transforms - each specifying a cryptographic algorithm.
   Each transform contains zero or more attributes (attributes are only
   needed if the transform identifier does not completely specify the
   cryptographic algorithm).

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


      Each proposal contains one or more protocols. If a proposal is
      accepted, the SA response MUST contain the same protocols in the
      same order as the proposal. The responder MUST accept a single



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 20]

Internet-Draft                                        September 23, 2004


      proposal or reject them all and return an error. (Example: if a
      single proposal contains ESP and AH and that proposal is accepted,
      both ESP and AH MUST be accepted. If ESP and AH are included in
      separate proposals, the responder MUST accept only one of them).

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

   Since the initiator sends its Diffie-Hellman value in the
   IKE_SA_INIT, it must guess the Diffie-Hellman group that the
   responder will select from its list of supported groups.  If the
   initiator guesses wrong, the responder will respond with a Notify
   payload of type INVALID_KE_PAYLOAD indicating the selected group.  In
   this case, the initiator MUST retry the IKE_SA_INIT with the
   corrected Diffie-Hellman group. The initiator MUST again propose its
   full set of acceptable cryptographic suites because the rejection
   message was unauthenticated and otherwise an active attacker could
   trick the endpoints into negotiating a weaker suite than a stronger
   one that they both prefer.

2.8 Rekeying

   IKE, ESP, and AH security associations use secret keys which SHOULD
   only be used for a limited amount of time and to protect a limited
   amount of data. This limits the lifetime of the entire security
   association. When the lifetime of a security association expires the
   security association MUST NOT be used.  If there is demand, new
   security associations MAY be established.  Reestablishment of
   security associations to take the place of ones which expire is
   referred to as "rekeying".

   To allow for minimal IPsec implementations, the ability to rekey SAs
   without restarting the entire IKE_SA is optional. An implementation
   MAY refuse all CREATE_CHILD_SA requests within an IKE_SA. If an SA
   has expired or is about to expire and rekeying attempts using the
   mechanisms described here fail, an implementation MUST close the
   IKE_SA and any associated CHILD_SAs and then MAY start new ones.
   Implementations SHOULD support in place rekeying of SAs, since doing
   so offers better performance and is likely to reduce the number of
   packets lost during the transition.

   To rekey a CHILD_SA within an existing IKE_SA, create a new,



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 21]

Internet-Draft                                        September 23, 2004


   equivalent SA (see section 2.17 below), and when the new one is
   established, delete the old one.  To rekey an IKE_SA, establish a new
   equivalent IKE_SA (see section 2.18 below) with the peer to whom the
   old IKE_SA is shared using a CREATE_CHILD_SA within the existing
   IKE_SA. An IKE_SA so created inherits all of the original IKE_SA's
   CHILD_SAs.  Use the new IKE_SA for all control messages needed to
   maintain the CHILD_SAs created by the old IKE_SA, and delete the old
   IKE_SA. The Delete payload to delete itself MUST be the last request
   sent over an IKE_SA.

   SAs SHOULD be rekeyed proactively, i.e., the new SA should be
   established before the old one expires and becomes unusable. Enough
   time should elapse between the time the new SA is established and the
   old one becomes unusable so that traffic can be switched over to the
   new SA.

   A difference between IKEv1 and IKEv2 is that in IKEv1 SA lifetimes
   were negotiated. In IKEv2, each end of the SA is responsible for
   enforcing its own lifetime policy on the SA and rekeying the SA when
   necessary.  If the two ends have different lifetime policies, the end
   with the shorter lifetime will end up always being the one to request
   the rekeying.  If an SA bundle has been inactive for a long time and
   if an endpoint would not initiate the SA in the absence of traffic,
   the endpoint MAY choose to close the SA instead of rekeying it when
   its lifetime expires. It SHOULD do so if there has been no traffic
   since the last time the SA was rekeyed.

   If the two ends have the same lifetime policies, it is possible that
   both will initiate a rekeying at the same time (which will result in
   redundant SAs). To reduce the probability of this happening, the
   timing of rekeying requests SHOULD be jittered (delayed by a random
   amount of time after the need for rekeying is noticed).

   This form of rekeying may temporarily result in multiple similar SAs
   between the same pairs of nodes. When there are two SAs eligible to
   receive packets, a node MUST accept incoming packets through either
   SA. If redundant SAs are created though such a collision, the SA
   created with the lowest of the four nonces used in the two exchanges
   SHOULD be closed by the endpoint that created it.

   Note that IKEv2 deliberately allows parallel SAs with the same
   traffic selectors between common endpoints. One of the purposes of
   this is to support traffic QoS differences among the SAs (see section
   4.1 of [RFC2983]). Hence unlike IKEv1, the combination of the
   endpoints and the traffic selectors may not uniquely identify an SA
   between those endpoints, so the IKEv1 rekeying heuristic of deleting
   SAs on the basis of duplicate traffic selectors SHOULD NOT be used.




IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 22]

Internet-Draft                                        September 23, 2004


   The node that initiated the surviving rekeyed SA SHOULD delete the
   replaced SA after the new one is established.

   There are timing windows - particularly in the presence of lost
   packets - where endpoints may not agree on the state of an SA. The
   responder to a CREATE_CHILD_SA MUST be prepared to accept messages on
   an SA before sending its response to the creation request, so there
   is no ambiguity for the initiator. The initiator MAY begin sending on
   an SA as soon as it processes the response. The initiator, however,
   cannot receive on a newly created SA until it receives and processes
   the response to its CREATE_CHILD_SA request. How, then, is the
   responder to know when it is OK to send on the newly created SA?

   From a technical correctness and interoperability perspective, the
   responder MAY begin sending on an SA as soon as it sends its response
   to the CREATE_CHILD_SA request. In some situations, however, this
   could result in packets unnecessarily being dropped, so an
   implementation MAY want to defer such sending.

   The responder can be assured that the initiator is prepared to
   receive messages on an SA if either (1) it has received a
   cryptographically valid message on the new SA, or (2) the new SA
   rekeys an existing SA and it receives an IKE request to close the
   replaced SA. When rekeying an SA, the responder SHOULD continue to
   send requests on the old SA until it one of those events occurs. When
   establishing a new SA, the responder MAY defer sending messages on a
   new SA until either it receives one or a timeout has occurred. If an
   initiator receives a message on an SA for which it has not received a
   response to its CREATE_CHILD_SA request, it SHOULD interpret that as
   a likely packet loss and retransmit the CREATE_CHILD_SA request. An
   initiator MAY send a dummy message on a newly created SA if it has no
   messages queued in order to assure the responder that the initiator
   is ready to receive messages.

2.9 Traffic Selector Negotiation

   When an IP packet is received by an RFC2401 compliant IPsec subsystem
   and matches a "protect" selector in its SPD, the subsystem MUST
   protect that packet with IPsec. When no SA exists yet it is the task
   of IKE to create it. Maintenance of a system's SPD is outside the
   scope of IKE (see [PFKEY] for an example protocol), though some
   implementations might update their SPD in connection with the running
   of IKE (for an example scenario, see section 1.1.3).

   Traffic Selector (TS) payloads allow endpoints to communicate some of
   the information from their SPD to their peers. TS payloads specify
   the selection criteria for packets that will be forwarded over the
   newly set up SA.  This can serve as a consistency check in some



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 23]

Internet-Draft                                        September 23, 2004


   scenarios to assure that the SPDs are consistent. In others, it
   guides the dynamic update of the SPD.

   Two TS payloads appear in each of the messages in the exchange that
   creates a CHILD_SA pair. Each TS payload contains one or more Traffic
   Selectors. Each Traffic Selector consists of an address range (IPv4
   or IPv6), a port range, and an IP protocol ID. In support of the
   scenario described in section 1.1.3, an initiator may request that
   the responder assign an IP address and tell the initiator what it is.

   IKEv2 allows the responder to choose a subset of the traffic proposed
   by the initiator.  This could happen when the configuration of the
   two endpoints are being updated but only one end has received the new
   information.  Since the two endpoints may be configured by different
   people, the incompatibility may persist for an extended period even
   in the absence of errors. It also allows for intentionally different
   configurations, as when one end is configured to tunnel all addresses
   and depends on the other end to have the up to date list.

   The first of the two TS payloads is known as TSi (Traffic Selector-
   initiator).  The second is known as TSr (Traffic Selector-responder).
   TSi specifies the source address of traffic forwarded from (or the
   destination address of traffic forwarded to) the initiator of the
   CHILD_SA pair. TSr specifies the destination address of the traffic
   forwarded from (or the source address of the traffic forwarded to)
   the responder of the CHILD_SA pair.  For example, if the original
   initiator request the creation of a CHILD_SA pair, and wishes to
   tunnel all traffic from subnet 192.0.1.* on the initiator's side to
   subnet 192.0.2.* on the responder's side, the initiator would include
   a single traffic selector in each TS payload. TSi would specify the
   address range (192.0.1.0 - 192.0.1.255) and TSr would specify the
   address range (192.0.2.0 - 192.0.2.255). Assuming that proposal was
   acceptable to the responder, it would send identical TS payloads
   back. [Note: the IP address range 192.0.1.* has been reserved for use
   in examples in RFCs and similar documents. This document needed two
   such ranges, and so also used 192.0.2.*. This should not be confused
   with any actual address].

   The responder is allowed to narrow the choices by selecting a subset
   of the traffic, for instance by eliminating or narrowing the range of
   one or more members of the set of traffic selectors, provided the set
   does not become the NULL set.

   It is possible for the responder's policy to contain multiple smaller
   ranges, all encompassed by the initiator's traffic selector, and with
   the responder's policy being that each of those ranges should be sent
   over a different SA. Continuing the example above, the responder
   might have a policy of being willing to tunnel those addresses to and



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 24]

Internet-Draft                                        September 23, 2004


   from the initiator, but might require that each address pair be on a
   separately negotiated CHILD_SA. If the initiator generated its
   request in response to an incoming packet from 192.0.1.43 to
   192.0.2.123, there would be no way for the responder to determine
   which pair of addresses should be included in this tunnel, and it
   would have to make a guess or reject the request with a status of
   SINGLE_PAIR_REQUIRED.

   To enable the responder to choose the appropriate range in this case,
   if the initiator has requested the SA due to a data packet, the
   initiator SHOULD include as the first traffic selector in each of TSi
   and TSr a very specific traffic selector including the addresses in
   the packet triggering the request. In the example, the initiator
   would include in TSi two traffic selectors: the first containing the
   address range (192.0.1.43 - 192.0.1.43) and the source port and IP
   protocol from the packet and the second containing (192.0.1.0 -
   192.0.1.255) with all ports and IP protocols. The initiator would
   similarly include two traffic selectors in TSr.

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

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

2.10 Nonces

   The IKE_SA_INIT messages each contain a nonce. These nonces are used
   as inputs to cryptographic functions.  The CREATE_CHILD_SA request
   and the CREATE_CHILD_SA response also contain nonces. These nonces
   are used to add freshness to the key derivation technique used to



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 25]

Internet-Draft                                        September 23, 2004


   obtain keys for CHILD_SA, and to ensure creation of strong
   pseudorandom bits from the Diffie-Hellman key. Nonces used in IKEv2
   MUST be randomly chosen, MUST be at least 128 bits in size, and MUST
   be at least half the key size of the negotiated prf. ("prf" refers to
   "pseudo-random function", one of the cryptographic algorithms
   negotiated in the IKE exchange). If the same random number source is
   used for both keys and nonces, care must be taken to ensure that the
   latter use does not compromise the former.

2.11 Address and Port Agility

   IKE runs over UDP ports 500 and 4500, and implicitly sets up ESP and
   AH associations for the same IP addresses it runs over. The IP
   addresses and ports in the outer header are, however, not themselves
   cryptographically protected, 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 from which the request was
   received. It MUST specify the address and port at which the request
   was received as the source address and port in the response.  IKE
   functions identically over IPv4 or IPv6.

2.12 Reuse of Diffie-Hellman Exponentials

   IKE generates keying material using an ephemeral Diffie-Hellman
   exchange in order to gain the property of "perfect forward secrecy".
   This means that once a connection is closed and its corresponding
   keys are forgotten, even someone who has recorded all of the data
   from the connection and gets access to all of the long-term keys of
   the two endpoints cannot reconstruct the keys used to protect the
   conversation without doing a brute force search of the session key
   space.

   Achieving perfect forward secrecy requires that when a connection is
   closed, each endpoint MUST forget not only the keys used by the
   connection but any information that could be used to recompute those
   keys. In particular, it MUST forget the secrets used in the Diffie-
   Hellman calculation and any state that may persist in the state of a
   pseudo-random number generator that could be used to recompute the
   Diffie-Hellman secrets.

   Since the computing of Diffie-Hellman exponentials is computationally
   expensive, an endpoint may find it advantageous to reuse those
   exponentials for multiple connection setups. There are several
   reasonable strategies for doing this. An endpoint could choose a new
   exponential only periodically though this could result in less-than-
   perfect forward secrecy if some connection lasts for less than the
   lifetime of the exponential. Or it could keep track of which



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 26]

Internet-Draft                                        September 23, 2004


   exponential was used for each connection and delete the information
   associated with the exponential only when some corresponding
   connection was closed. This would allow the exponential to be reused
   without losing perfect forward secrecy at the cost of maintaining
   more state.

   Decisions as to whether and when to reuse Diffie-Hellman exponentials
   is a private decision in the sense that it will not affect
   interoperability.  An implementation that reuses exponentials MAY
   choose to remember the exponential used by the other endpoint on past
   exchanges and if one is reused to avoid the second half of the
   calculation.

2.13 Generating Keying Material

   In the context of the IKE_SA, four cryptographic algorithms are
   negotiated: an encryption algorithm, an integrity protection
   algorithm, a Diffie-Hellman group, and a pseudo-random function
   (prf). The pseudo-random function is used for the construction of
   keying material for all of the cryptographic algorithms used in both
   the IKE_SA and the CHILD_SAs.

   We assume that each encryption algorithm and integrity protection
   algorithm uses a fixed size key, and that any randomly chosen value
   of that fixed size can serve as an appropriate key. For algorithms
   that accept a variable length key, a fixed key size MUST be specified
   as part of the cryptographic transform negotiated.  For algorithms
   for which not all values are valid keys (such as DES or 3DES with key
   parity), they algorithm by which keys are derived from arbitrary
   values MUST be specified by the cryptographic transform.  For
   integrity protection functions based on HMAC, the fixed key size is
   the size of the output of the underlying hash function. When the prf
   function takes a variable length key, variable length data, and
   produces a fixed length output (e.g., when using HMAC), the formulas
   in this document apply. When the key for the prf function has fixed
   length, the data provided as a key is truncated or padded with zeros
   as necessary unless exceptional processing is explained following the
   formula.

   Keying material will always be derived as the output of the
   negotiated prf algorithm. Since the amount of keying material needed
   may be greater than the size of the output of the prf algorithm, we
   will use the prf iteratively.  We will use the terminology prf+ to
   describe the function that outputs a pseudo-random stream based on
   the inputs to a prf as follows: (where | indicates concatenation)

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




IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 27]

Internet-Draft                                        September 23, 2004


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

   continuing as needed to compute all required keys. The keys are taken
   from the output string without regard to boundaries (e.g., if the
   required keys are a 256 bit AES key and a 160 bit HMAC key, and the
   prf function generates 160 bits, the AES key will come from T1 and
   the beginning of T2, while the HMAC key will come from the rest of T2
   and the beginning of T3).

   The constant concatenated to the end of each string feeding the prf
   is a single octet. prf+ in this document is not defined beyond 255
   times the size of the prf output.

2.14 Generating Keying Material for the IKE_SA

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

   SKEYSEED and its derivatives are computed as follows:

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

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

   (indicating that the quantities SK_d, SK_ai, SK_ar, SK_ei, SK_er,
   SK_pi, and SK_pr are taken in order from the generated bits of the
   prf+).  g^ir is the shared secret from the ephemeral Diffie-Hellman
   exchange.  g^ir is represented as a string of octets in big endian
   order padded with zeros if necessary to make it the length of the
   modulus. Ni and Nr are the nonces, stripped of any headers. If the
   negotiated prf takes a fixed length key and the lengths of Ni and Nr
   do not add up to that length, half the bits must come from Ni and
   half from Nr, taking the first bits of each.

   The two directions of traffic flow use different keys. The keys used



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 28]

Internet-Draft                                        September 23, 2004


   to protect messages from the original initiator are SK_ai and SK_ei.
   The keys used to protect messages in the other direction are SK_ar
   and SK_er. Each algorithm takes a fixed number of bits of keying
   material, which is specified as part of the algorithm.  For integrity
   algorithms based on a keyed hash, the key size is always equal to the
   length of the output of the underlying hash function.

2.15 Authentication of the IKE_SA

   When not using extensible authentication (see section 2.16), the
   peers are authenticated by having each sign (or MAC using a shared
   secret as the key) a block of data.  For the responder, the octets to
   be signed start with the first octet of the first SPI in the header
   of the second message and end with the last octet of the last payload
   in the second message.  Appended to this (for purposes of computing
   the signature) are the initiator's nonce Ni (just the value, not the
   payload containing it), and the value prf(SK_pr,IDr') where IDr' is
   the responder's ID payload excluding the fixed header. Note that
   neither the nonce Ni nor the value prf(SK_pr,IDr') are transmitted.
   Similarly, the initiator signs the first message, starting with the
   first octet of the first SPI in the header and ending with the last
   octet of the last payload.  Appended to this (for purposes of
   computing the signature) are the responder's nonce Nr, and the value
   prf(SK_pi,IDi'). In the above calculation, IDi' and IDr' are the
   entire ID payloads excluding the fixed header.  It is critical to the
   security of the exchange that each side sign the other side's nonce.

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

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



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 29]

Internet-Draft                                        September 23, 2004


   This is typically insecure because user chosen passwords are unlikely
   to have sufficient unpredictability to resist dictionary attacks and
   these attacks are not prevented in this authentication method.
   (Applications using password-based authentication for bootstrapping
   and IKE_SA should use the authentication method in section 2.16,
   which is designed to prevent off-line dictionary attacks).  The pre-
   shared key SHOULD contain as much unpredictability as the strongest
   key being negotiated.  In the case of a pre-shared key, the AUTH
   value is computed as:

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

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

2.16 Extensible Authentication Protocol Methods

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

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



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 30]

Internet-Draft                                        September 23, 2004


   An initiator indicates a desire to use extensible authentication by
   leaving out the AUTH payload from message 3. By including an IDi
   payload but not an AUTH payload, the initiator has declared an
   identity but has not proven it. If the responder is willing to use an
   extensible authentication method, it will place an EAP payload in
   message 4 and defer sending SAr2, TSi, and TSr until initiator
   authentication is complete in a subsequent IKE_AUTH exchange. In the
   case of a minimal extensible authentication, the initial SA
   establishment will appear as follows:

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

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

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

                                  <--    HDR, SK {IDr, [CERT,] AUTH,
                                                EAP }

       HDR, SK {EAP}              -->

                                  <--    HDR, SK {EAP (success)}

       HDR, SK {AUTH}             -->

                                  <--    HDR, SK {AUTH, SAr2, TSi, TSr }

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

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

   The initiator of an IKE_SA using EAP SHOULD be capable of extending
   the initial protocol exchange to at least ten IKE_AUTH exchanges in



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 31]

Internet-Draft                                        September 23, 2004


   the event the responder sends notification messages and/or retries
   the authentication prompt.  Once the protocol exchange defined by the
   chosen EAP authentication method has successfully terminated, the
   responder MUST send an EAP payload containing the Success message.
   Similarly, if the authentication method has failed, the responder
   MUST send an EAP payload containing the Failure message. The
   responder MAY at any time terminate the IKE exchange by sending an
   EAP payload containing the Failure message.

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

2.17 Generating Keying Material for CHILD_SAs

   CHILD_SAs are created either by being piggybacked on the IKE_AUTH
   exchange, or in a CREATE_CHILD_SA exchange. Keying material for them
   is generated as follows:

      KEYMAT = prf+(SK_d, Ni | Nr)

   Where Ni and Nr are the Nonces from the IKE_SA_INIT exchange if this
   request is the first CHILD_SA created or the fresh Ni and Nr from the
   CREATE_CHILD_SA exchange if this is a subsequent creation.

   For CREATE_CHILD_SA exchanges including 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 (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 CHILD_SA negotiation may result in multiple security
   associations. ESP and AH SAs exist in pairs (one in each direction),
   and four SAs could be created in a single CHILD_SA negotiation if a
   combination of ESP and AH is being negotiated.

   Keying material MUST be taken from the expanded KEYMAT in the
   following order:

      All keys for SAs carrying data from the initiator to the responder
      are taken before SAs going in the reverse direction.

      If multiple IPsec protocols are negotiated, keying material is
      taken in the order in which the protocol headers will appear in



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 32]

Internet-Draft                                        September 23, 2004


      the encapsulated packet.

      If a single protocol has both encryption and authentication keys,
      the encryption key is taken from the first octets of KEYMAT and
      the authentication key is taken from the next octets.

   Each cryptographic algorithm takes a fixed number of bits of keying
   material specified as part of the algorithm.

2.18 Rekeying IKE_SAs using a CREATE_CHILD_SA exchange

   The CREATE_CHILD_SA exchange can be used to rekey an existing IKE_SA
   (see section 2.8).  New initiator and responder SPIs are supplied in
   the SPI fields. 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 as follows:

       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) and Ni and Nr are the two nonces
   stripped of any headers.

   The new IKE_SA MUST reset its message counters to 0.

   SK_d, SK_ai, SK_ar, and SK_ei, and SK_er are computed from SKEYSEED
   as specified in section 2.14.

2.19 Requesting an internal address on a remote network

   Most commonly occurring in the endpoint to security gateway scenario,
   an endpoint may need an IP address in the network protected by the
   security gateway, and may need to have that address dynamically
   assigned. A request for such 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.

   This function provides address allocation to an IRAC (IPsec Remote
   Access Client) trying to tunnel into a network protected by an IRAS
   (IPsec Remote Access Server).  Since the IKE_AUTH exchange creates an
   IKE_SA and a CHILD_SA, the IRAC MUST request the IRAS controlled
   address (and optionally other information concerning the protected
   network) in the IKE_AUTH exchange.  The IRAS may procure an address
   for the IRAC from any number of sources such as a DHCP/BOOTP server
   or its own address pool.




IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 33]

Internet-Draft                                        September 23, 2004


       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 where there are 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 MAY contain any number of additional
   attributes the initiator wants returned in the response.

   For example, message from initiator to responder:
      CP(CFG_REQUEST)=
        INTERNAL_ADDRESS(0.0.0.0)
        INTERNAL_NETMASK(0.0.0.0)
        INTERNAL_DNS(0.0.0.0)
      TSi = (0, 0-65536,0.0.0.0-255.255.255.255)
      TSr = (0, 0-65536,0.0.0.0-255.255.255.255)

   NOTE: Traffic Selectors contain (protocol, port range, address range)

   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-65536,192.0.2.202-192.0.2.202)
      TSr = (0, 0-65536,192.0.2.0-192.0.2.255)

   All returned values will be implementation dependent.  As can be seen
   in the above example, the IRAS MAY also send other attributes that
   were not included in CP(CFG_REQUEST) and MAY ignore the non-
   mandatory attributes that it does not support.

   The responder MUST NOT send a CFG_REPLY without having first received
   a CP(CFG_REQUEST) from the initiator, because we do not want the IRAS
   to perform an unnecessary configuration lookup if the IRAC cannot
   process the REPLY. In the case where the IRAS's configuration
   requires that CP be used for a given identity IDi, but IRAC has



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 34]

Internet-Draft                                        September 23, 2004


   failed to send a CP(CFG_REQUEST), IRAS MUST fail the request, and
   terminate the IKE exchange with a FAILED_CP_REQUIRED error.

2.20 Requesting the Peer's Version

   An IKE peer wishing to inquire 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
   prior to authentication or even after authentication to prevent
   trolling in case some implementation is known to have some security
   weakness. In that case, it MUST either return an empty string or no
   CP payload if CP is not supported.

       Initiator                           Responder
      -----------------------------       --------------------------
      HDR, SK{CP(CFG_REQUEST)}      -->
                                    <--    HDR, SK{CP(CFG_REPLY)}

      CP(CFG_REQUEST)=
        APPLICATION_VERSION("")

      CP(CFG_REPLY)
        APPLICATION_VERSION("foobar v1.3beta, (c) Foo Bar Inc.")

2.21 Error Handling

   There are many kinds of errors that can occur during IKE processing.
   If a request is received that is badly formatted or unacceptable for
   reasons of policy (e.g., no matching cryptographic algorithms), the
   response MUST contain a Notify payload indicating the error. 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.

   Errors that occur before a cryptographically protected IKE_SA is
   established must be handled very carefully. There is a trade-off
   between wanting to be helpful in diagnosing a problem and responding
   to it and wanting to avoid being a dupe in a denial of service attack
   based on forged messages.

   If a node receives a message on UDP port 500 or 4500 outside the
   context of an IKE_SA known to it (and not a request to start one), it
   may be the result of a recent crash of the node.  If the message is
   marked as a response, the node MAY audit the suspicious event but



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 35]

Internet-Draft                                        September 23, 2004


   MUST NOT respond. If the message is marked as a request, the node MAY
   audit the suspicious event and MAY send a response. If a response is
   sent, the response MUST be sent to the IP address and port from
   whence it came with the same IKE SPIs and the Message ID copied. The
   response MUST NOT be cryptographically protected and MUST contain a
   Notify payload indicating INVALID_IKE_SPI.

   A node 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 might be a response the genuine correspondent was
   tricked into sending. A node SHOULD treat such a message (and also a
   network message like ICMP destination unreachable) as a hint that
   there might be problems with SAs to that IP address and SHOULD
   initiate a liveness test for any such IKE_SA. An implementation
   SHOULD limit the frequency of such tests to avoid being tricked into
   participating in a denial of service attack.

   A node receiving a suspicious message from an IP address with which
   it has an IKE_SA MAY send an IKE Notify payload in an IKE
   INFORMATIONAL exchange over that SA. The recipient MUST NOT change
   the state of any SA's as a result but SHOULD audit the event to aid
   in diagnosing malfunctions. A node MUST limit the rate at which it
   will send messages in response to unprotected messages.

2.22 IPComp

   Use of IP compression [IPCOMP] can be negotiated as part of the setup
   of a CHILD_SA. While IP compression involves an extra header in each
   packet and a CPI (compression parameter index), 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 is not explicitly mentioned
   in any DELETE payload.

   Negotiation of IP compression is separate from the negotiation of
   cryptographic parameters associated with a CHILD_SA. A node
   requesting a CHILD_SA MAY advertise its support for one or more
   compression algorithms though one or more Notify payloads of type
   IPCOMP_SUPPORTED. The response MAY indicate acceptance of a single
   compression algorithm with a Notify payload of type IPCOMP_SUPPORTED.
   These payloads MUST NOT occur messages that do not contain SA
   payloads.

   While there has been discussion of allowing multiple compression
   algorithms to be accepted and to have different compression
   algorithms available 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



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 36]

Internet-Draft                                        September 23, 2004


   MUST NOT compress using an algorithm other than one proposed and
   accepted in the setup of the CHILD_SA.

   A side effect of separating the negotiation of IPComp from
   cryptographic parameters is that it is not possible to propose
   multiple cryptographic suites and propose IP compression with some of
   them but not others.

2.23 NAT Traversal

   NAT (Network Address Translation) gateways are a controversial
   subject.  This section briefly describes what they are and how they
   are likely to act on IKE traffic. Many people believe that NATs are
   evil and that we should not design our protocols so as to make them
   work better. IKEv2 does specify some unintuitive processing rules in
   order that NATs are more likely to work.

   NATs exist primarily because of the shortage of IPv4 addresses,
   though there are other rationales. IP nodes that are "behind" a NAT
   have IP addresses that are not globally unique, but rather are
   assigned from some space that is unique within the network behind the
   NAT but which are likely to be reused by nodes behind other NATs.
   Generally, nodes behind NATs can communicate with other nodes behind
   the same NAT and with nodes with globally unique addresses, but not
   with nodes behind other NATs.  There are exceptions to that rule.
   When those nodes make connections to nodes on the real Internet, the
   NAT gateway "translates" the IP source address to an address that
   will be routed back to the gateway. Messages to the gateway from the
   Internet have their destination addresses "translated" to the
   internal address that will route the packet to the correct endnode.

   NATs are designed to be "transparent" to endnodes. Neither software
   on the node behind the NAT nor the node on the Internet require
   modification to communicate through the NAT. Achieving this
   transparency is more difficult with some protocols than with others.
   Protocols that include IP addresses of the endpoints within the
   payloads of the packet will fail unless the NAT gateway understands
   the protocol and modifies the internal references as well as those in
   the headers. Such knowledge is inherently unreliable, is a network
   layer violation, and often results in subtle problems.

   Opening an IPsec connection through a NAT introduces special
   problems.  If the connection runs in transport mode, changing the IP
   addresses on packets will cause the checksums to fail and the NAT
   cannot correct the checksums because they are cryptographically
   protected. Even in tunnel mode, there are routing problems because
   transparently translating the addresses of AH and ESP packets
   requires special logic in the NAT and that logic is heuristic and



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 37]

Internet-Draft                                        September 23, 2004


   unreliable in nature. For that reason, IKEv2 can negotiate UDP
   encapsulation of IKE and ESP packets.  This encoding is slightly less
   efficient but is easier for NATs to process. In addition, firewalls
   may be configured to pass IPsec traffic over UDP but not ESP/AH or
   vice versa.

   It is a common practice of NATs to translate TCP and UDP port numbers
   as well as addresses and use the port numbers of inbound packets to
   decide which internal node should get a given packet. For this
   reason, even though IKE packets MUST be sent from and to UDP port
   500, they MUST be accepted coming from any port and responses MUST be
   sent to the port from whence they came. This is because the ports may
   be modified as the packets pass through NATs. Similarly, IP addresses
   of the IKE endpoints are generally not included in the IKE payloads
   because the payloads are cryptographically protected and could not be
   transparently modified by NATs.

   Port 4500 is reserved for UDP encapsulated ESP and IKE.  When working
   through a NAT, it is generally better to pass IKE packets over port
   4500 because some older NATs handle IKE traffic on port 500 cleverly
   in an attempt to transparently establish IPsec connections between
   endpoints that don't handle NAT traversal themselves. Such NATs may
   interfere with the straightforward NAT traversal envisioned by this
   document, so an IPsec endpoint that discovers a NAT between it and
   its correspondent MUST send all subsequent traffic to and from port
   4500, which NATs should not treat specially (as they might with port
   500).

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

      IKE MUST listen on port 4500 as well as port 500. IKE MUST respond
      to the IP address and port from which packets arrived.

      Both IKE initiator and responder MUST include in their IKE_SA_INIT
      packets Notify payloads of type NAT_DETECTION_SOURCE_IP and
      NAT_DETECTION_DESTINATION_IP. Those payloads can be used to detect
      if there is NAT between the hosts, and which end is behind the
      NAT. The location of the payloads in the IKE_SA_INIT packets are
      just after the Ni and Nr payloads (before the optional CERTREQ
      payload).

      If none of the NAT_DETECTION_SOURCE_IP payload(s) received matches
      the hash of the source IP and port found from the IP header of the
      packet containing the payload, it means that the other end is
      behind NAT (i.e., someone along the route changed the source



IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 38]

Internet-Draft                                        September 23, 2004


      address of the original packet to match the address of the NAT
      box). In this case this end should allow dynamic update of the
      other ends IP address, as described later.

      If the NAT_DETECTION_DESTINATION_IP payload received does not
      match the hash of the destination IP and port found from the IP
      header of the packet containing the payload, it means that this
      end is behind a NAT. In this case, this end SHOULD start sending
      keepalive packets as explained in [Hutt04].

      The IKE initiator MUST check these payloads if present and if they
      do not match the addresses in the outer packet MUST tunnel all
      future IKE and ESP packets associated with this IKE_SA over UDP
      port 4500.

      To tunnel IKE packets over UDP port 4500, the IKE header has four
      octets of zero prepended and the result immediately follows the
      UDP header. To tunnel ESP packets over UDP port 4500, the ESP
      header immediately follows the UDP header. Since the first four
      bytes of the ESP header contain the SPI, and the SPI cannot
      validly be zero, it is always possible to distinguish ESP and IKE
      messages.

      The original source and destination IP address required for the
      transport mode TCP and UDP packet checksum fixup (see [Hutt04])
      are obtained from the Traffic Selectors associated with the
      exchange. In the case of NAT traversal, the Traffic Selectors MUST
      contain exactly one IP address which is then used as the original
      IP address.

      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 is rebooted). To recover in these cases, hosts that
      are not behind a NAT SHOULD send all packets (including
      retransmission packets) to the IP address and port from the last
      valid authenticated packet from the other end (i.e., dynamically
      update the address). A host behind a NAT SHOULD NOT do this
      because it opens a DoS attack possibility. Any authenticated IKE
      packet or any authenticated UDP encapsulated ESP packet can be
      used to detect that the IP address or the port has changed.

      Note that similar but probably not identical actions will likely
      be needed to make IKE work with Mobile IP, but such processing is
      not addressed by this document.







IKEv2                 draft-ietf-ipsec-ikev2-17.txt            [Page 39]

Internet-Draft                                        September 23, 2004


2.24 ECN (Explicit Congestion Notification)

   When IPsec tunnels behave as originally specified in [RFC2401], ECN
   usage is not appropriate for the outer IP headers because tunnel
   decapsulation processing discards ECN congestion indications to the
   detriment of the network. ECN support for IPsec tunnels for
   IKEv1-based IPsec requires multiple operating modes and negotiation
   (see RFC3168</