<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE rfc SYSTEM "rfc2629.dtd">

<rfc category="std" ipr="trust200902" updates="7296" docName="draft-ietf-ipsecme-ikev2-downgrade-prevention-03">

<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>

<?rfc toc="yes" ?>
<?rfc symrefs="yes" ?>
<?rfc sortrefs="no"?>
<?rfc iprnotified="no" ?>
<?rfc strict="yes" ?>

    <front>
        <title abbrev="Downgrade Prevention for IKEv2">Downgrade Prevention for the Internet Key Exchange Protocol Version 2 (IKEv2)</title>
        <author initials='V.' surname="Smyslov" fullname='Valery Smyslov'>
            <organization>ELVIS-PLUS</organization>
            <address>
                <postal>
                    <country>RU</country>
                </postal>
                <phone></phone>
                <email>svan@elvis.ru</email>
            </address>
        </author>
        <author initials="C." surname="Patton" fullname="Christopher Patton">
            <organization>Cloudflare</organization>
            <address>
              <postal>
                    <country>US</country>
                </postal>
                <phone></phone><email>chrispatton+ietf@gmail.com</email>
            </address>
        </author>
        <date/>
        <abstract>
            <t> This document describes an extension to the Internet Key Exchange protocol version 2 (IKEv2)
            that prevents particular downgrade attacks on this protocol by having the peers confirm
            they have participated in the same conversation.
            </t>

			<t> This document updates RFC 7296.
			</t>
        </abstract>
    </front>

    <middle>
        <section title="Introduction">
            <t> The Internet Key Exchange version 2 protocol (IKEv2) <xref target="RFC7296" /> provides
            authenticated key exchange in the IP Security (IPsec) architecture. The cryptographic design of IKEv2 is based
            on the SIGn-and-MAc (SIGMA) protocol <xref target="SIGMA" />. The protocol allows peers to mutually
            authenticate themselves and to derive session keys that are used to protect traffic.
            </t>

			<t> This document modifies the way peers construct the data to be authenticated in IKEv2,
			and thus updates RFC 7296.
			</t>

            <t>(RFC EDITOR: Please remove this paragraph.) This document is being developed at
            <eref target="https://github.com/smyslov/ikev2-downgrade-prevention"/>.
            </t>

        </section>

        <section anchor="mustshouldmay" title="Terminology and Notation">
            <t> The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT",
            "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted
            as described in BCP 14 <xref target="RFC2119" /> <xref target="RFC8174" /> when, and only when,
            they appear in all capitals, as shown here.
            </t>

            <t> It is assumed that readers are familiar with the IKEv2 protocol <xref target="RFC7296" />.
            </t>
        </section>

        <section anchor="ikeauth" title="Authentication in IKEv2">
            <t> The details of how authentication is performed in IKEv2 are defined in Section 2.15 of IKEv2 <xref target="RFC7296" />.
            Peers sign (or MAC) some blocks of data that consist of various parts of protocol data (see also SIGMA <xref target="SIGMA" /> for the rationale). 
            The definition of these blocks of data is provided below for convenience.
            </t>

            <t>The initiator's signed octets can be described as:
            </t>

            <figure align="center">
                <artwork align="left"><![CDATA[
   InitiatorSignedOctets = RealMessage1 | NonceRData | MACedIDForI
   GenIKEHDR = [ four octets 0 if using port 4500 ] | RealIKEHDR
   RealIKEHDR =  SPIi | SPIr |  . . . | Length
   RealMessage1 = RealIKEHDR | RestOfMessage1
   NonceRPayload = PayloadHeader | NonceRData
   InitiatorIDPayload = PayloadHeader | RestOfInitIDPayload
   RestOfInitIDPayload = IDType | RESERVED | InitIDData
   MACedIDForI = prf(SK_pi, RestOfInitIDPayload)
              ]]></artwork>
           </figure>

            <t>The responder's signed octets can be described as:
            </t>

          <figure align="center">
              <artwork align="left"><![CDATA[
   ResponderSignedOctets = RealMessage2 | NonceIData | MACedIDForR
   GenIKEHDR = [ four octets 0 if using port 4500 ] | RealIKEHDR
   RealIKEHDR =  SPIi | SPIr |  . . . | Length
   RealMessage2 = RealIKEHDR | RestOfMessage2
   NonceIPayload = PayloadHeader | NonceIData
   ResponderIDPayload = PayloadHeader | RestOfRespIDPayload
   RestOfRespIDPayload = IDType | RESERVED | RespIDData
   MACedIDForR = prf(SK_pr, RestOfRespIDPayload)
               ]]></artwork>
            </figure>

            <t> In particular, the initiator, but not the responder, authenticates the IKE_SA_INIT request
            (RealMessage1) and the responder, but not the initiator, authenticates the IKE_SA_INIT response (RealMessage2).
            Thus, each side authenticates only the initial message it has sent and not the initial message it has received.
            </t>
        </section>

        <section anchor="attack" title="Downgrade Attacks Description">
	    <t> The way authentication is performed in IKEv2 allows at least two kinds of downgrade attacks.
	    The first of these is a key-compromise impersonation (KCI) attack and requires
            a set of preconditions that are not common, but still plausible. In particular:
            </t>

            <ol>
                <li><t> The attacker must be on the path with the ability to intercept communications between
                the peers and to modify their messages.</t></li>
                <li><t> Security policies for both initiator and responder must include both "strong" and "weak" key exchange methods
                <!-- (with some definition of "strong" and "weak") --> and the attacker must be able to break "weak" key exchange
                methods in real time.</t></li>
                <li><t> The attacker must either have a long-term authentication key for one of the peers or must be able
                to break the authentication algorithm used by one of the peers in real time.</t></li>
            </ol>

	    <t> Having these preconditions the goal of the attacker is to eavesdrop on communication between the peers.
	    While the attack requires impersonating one of these peers to the other, impersonation is not its primary goal.
            </t>

            <t> In case the attacker knows the initiator's long-term authentication key, the attack can be mounted as follows.</t>

            <ol>
                <li><t> The initiator sends the IKE_SA_INIT request message with a list of proposed algorithms that includes
                both "weak" and "strong" key exchange methods.</t>

                    <figure align="center">
                        <artwork align="left"><![CDATA[
 original request     --> IKE_SA_INIT(SA(strong, weak), KE, Ni)
                     ]]></artwork>
                    </figure>

                </li>

                <li><t> The attacker intercepts this message and re-injects a modified message without "strong" key exchange methods.
                    </t>

                    <figure align="center">
                        <artwork align="left"><![CDATA[
 modified request     --> IKE_SA_INIT(SA(weak), KE, Ni)
                     ]]></artwork>
                    </figure>

                <t> Note that this may require an additional step for the attack to succeed if the initiator includes
                a Key Exchange Data value for a "strong" key exchange method in the request. In this case the attacker intercepts
                this message and responds with the INVALID_KE_PAYLOAD notification indicating that the initiator
                must include a Key Exchange Data value for a "weak" key exchange method. Then this message is intercepted
                and re-injected without "strong" key exchange methods.</t></li>

                <li><t> The responder receives this message and selects one of the "weak" key exchange methods (since the message
                does not include any "strong" ones), then it sends back a response message, which the attacker allows to pass through without modifications.</t>

                <figure align="center">
                    <artwork align="left"><![CDATA[
 response     <-- IKE_SA_INIT(SA(weak), KE, Nr)
                 ]]></artwork>
                </figure>

                </li>

                <li><t> Since the attacker has seen both Key Exchange Data values and can break the selected "weak" key exchange method in real time,
                it calculates the SK_* session keys that allow the attacker to read and modify the content of the encrypted
                IKE messages.</t></li>

                <li><t> The initiator receives the IKE_SA_INIT response message, accepts the responder's selected algorithms,
                including the "weak" key exchange method (since it is allowed by its policy), and starts the IKE_AUTH exchange. It computes the AUTH payload,
                thus authenticating the IKE_SA_INIT request message it has sent.</t>

                <figure align="center">
                    <artwork align="left"><![CDATA[
 original request    --> IKE_AUTH(IDi, AUTH, SA, TSi, TSr)
                 ]]></artwork>
                </figure>

                </li>

                <li><t> The attacker intercepts this message, decrypts it and modifies the AUTH payload so
                that it allegedly authenticates the IKE_SA_INIT request message that was modified and injected by the attacker. The attacker
                is able to do this because it knows the session keys and the initiator's long-term authentication key.</t>

                <figure align="center">
                    <artwork align="left"><![CDATA[
 modified request    --> IKE_AUTH(IDi, AUTH', SA, TSi, TSr)
                 ]]></artwork>
                </figure>

                </li>

                <li><t> The responder receives this message, verifies the AUTH payload and sends back the IKE_AUTH response message,
                which the attacker allows to pass through.</t>

                <figure align="center">
                    <artwork align="left"><![CDATA[
 response            <-- IKE_AUTH(IDr, AUTH, SA, TSi, TSr)
                 ]]></artwork>
                </figure>

                </li>

                <li><t> At this point the peers have established a connection using the "weak" key exchange method.
                Note, that this is allowed by their security policies, but without the attacker's intervention they
                would have used a more secure "strong" key exchange method. The attacker essentially forced
                the peers to use a "weak" method that it is able to break, thus downgrading the security properties
                of the connection so that it can read the peers' communication.</t></li>
            </ol>

            <t> A variant of this attack can be mounted if the attacker has the responder’s long-term authentication key.
            In this case the attacker cannot change the set of algorithms from which the responder makes its choice, but still may be able to
            force peers not to use some protocol extensions, in particular those that are initially proposed by the responder.
            </t>

            <t> The second type of attack is an identity misbinding attack described in &quot;Downgrade Resilience in Key-Exchange Protocols&quot; (IEEE Security &amp; Privacy 2016) <xref target="DOWNGRADE" />. The
            attacker's goal is once again to eavesdrop on the communication between two peers, but unlike the KCI attack, it does
            not need to compromise one of the peers. Instead, the attacker only needs to know the long-term authentication key of
            some party with whom one of the peers is configured to communicate.
            </t>

            <t> In particular, suppose the attacker wants to eavesdrop on communication between initiator I and responder R and
            has access to the long-term authentication key of a different initiator A. The attack works exactly the same way as the previous
            one, with one exception: after decrypting I's IKE_AUTH request it modifies it by replacing I's identity IDi with A's identity IDa and authenticates the modified request
            with A's long-term authentication key. At the end of the attack, initiator I will believe it has
            established a connection with responder R, but responder R will believe it has established a connection with initiator
	        A (whose authentication key is known to the attacker). Nevertheless, the attacker will be able to read the encrypted
	        messages sent between I and R.
            </t>

            <t> This attack used to be less relevant when cryptographic algorithms were considered secure or insecure because peers would disable 
            the insecure ones according to their security policy and not negotiate them. 
            On the other hand, the coexistence of old and new algorithms in the post-quantum (or any other) migration makes this attack more relevant. 
            With migration to quantum-resistant algorithms the KCI or identity misbinding attacks 
            could be mounted on a hybrid PQ/T <xref target="RFC9370" /> or pure post-quantum key exchange; where an attacker able to break 
            a traditional key exchange method (e.g. by means of a quantum computer) prevents peers from executing quantum-resistant key exchange method(s).
            </t>
        </section>

        <section anchor="solution" title="Downgrade Attacks Prevention">
            <t> This document defines an IKEv2 extension that detects attempts to mount the downgrade attacks described in
            <xref target="attack" />. If both peers support this extension and
            if at least one non-compromised authentication key is used by the peers in the protocol run then:
            </t>

            <ul>
                <li><t> An attacker cannot fool any protocol participant that its peer does not support this extension without being detected.
                </t></li>

                <li><t> An attacker cannot modify the IKE_SA_INIT messages without being detected.
                </t></li>
            </ul>

            <t> If this extension is not supported by both peers, then the IKEv2 negotiation runs as defined in IKEv2 <xref target="RFC7296" />.
            </t>

            <t> The idea is that both the IKE_SA_INIT request and the IKE_SA_INIT response messages must be directly authenticated
            by both peers. Thus, if at least one non-compromised key is used in the IKE SA establishing, then any modification
            of the IKE_SA_INIT messages will be detected. In particular, for the attacks described in <xref target="attack" />,
            it is necessary that the attacker forward the responder’s signed octets. Since the attacker is presumed to be incapable of forging 
            a valid signature on behalf of the responder, an attempt by the attacker to remove the responder’s commitment to this extension 
            would invalidate the signature in the AUTH payload. Consequently, while an attacker could strip support for this extension from the initiator, 
            it could not do so from the responder.
            </t>

            <t> In essence, the peers use this extension to confirm they have had the same
            conversation, a property enjoyed by many modern authenticated key exchange protocols that may have other benefits beyond
            downgrade protection, like TLS 1.3 <xref target="RFC8446" />.
            </t>
        </section>

        <section anchor="protocol" title="Protocol Details">
            <t> The initiator supporting this extension includes a new status type notification IKE_SA_INIT_FULL_TRANSCRIPT_AUTH
            in the IKE_SA_INIT request message. The Notify Message Type for this notification
            is 16447, Protocol ID and SPI Size are both set to 0 and the notification data is empty.
            </t>

            <t> If the responder supports this extension then it also includes this notification in the response message
            regardless of whether it was received in the request or not.

            <figure align="center">
                <artwork align="left"><![CDATA[
Initiator                       Responder
------------------------------------------------------------------
HDR, SAi1, KEi, Ni,
N(IKE_SA_INIT_FULL_TRANSCRIPT_AUTH)  --->
                              <---  HDR, SAr1, KEr, Nr, [CERTREQ,]
                               N(IKE_SA_INIT_FULL_TRANSCRIPT_AUTH)
            ]]></artwork>
            </figure>

            If a peer sent and received the IKE_SA_INIT_FULL_TRANSCRIPT_AUTH notification, then it uses the modified construction of the blocks of data
            to be signed (or MAC'ed) compared to the definition from Section 2.15 of IKEv2 <xref target="RFC7296" />:
            </t>

            <figure align="center">
                <artwork align="left"><![CDATA[
InitiatorSignedOctets = ZeroPrefix | RealMessage2 
                        | RealMessage1 | NonceRData | MACedIDForI

ResponderSignedOctets = ZeroPrefix | RealMessage1 
                        | RealMessage2 | NonceIData | MACedIDForR
            ]]></artwork>
            </figure>

            <t> where RealMessage1, RealMessage2, NonceIData, NonceRData, MACedIDForI and MACedIDForR are defined in Section 2.15 of IKEv2 <xref target="RFC7296" />,
				and ZeroPrefix is 8 octets of zero. ZeroPrefix serves a role of a domain separator making the new authentication blocks of data 
				always different from authentication blocks of data defined in Section 2.15 of IKEv2 <xref target="RFC7296" />, because in both RealMessage1 and RealMessage2 the first 8 octets 
				constitute IKE Initiator's SPI that can never be zero.
            </t>

        </section>

        <section anchor="interaction" title="Interaction with other IKEv2 Extensions">
            <section anchor="ike_intermediate" title="Interaction with the IKE_INTERMEDIATE Exchange">
                <t> The IKE_INTERMEDIATE exchange <xref target="RFC9242" /> also modifies blocks of data to be signed (or MAC'ed).
                This modification is described in Section 3.3.2 of IKE_INTERMEDIAE exchange <xref target="RFC9242" /> and can be
                summarized as an addition of a new piece of data (IntAuth) to the end of the blocks of data from Section 2.15 of IKEv2 <xref target="RFC7296" />.
                If peers support extension defined in this document, then they <bcp14>MUST</bcp14> treat modified blocks of data to be signed (or MAC'ed)
                defined in <xref target="protocol" /> as replacements for blocks of data defined in Section 2.15 of IKEv2 <xref target="RFC7296" />,
                so that in case of IKE_INTERMEDIATE the IntAuth is added to these modified blocks.
                </t>

                <aside><t> Authentication of the IKE_INTERMEDIATE exchange includes messages sent in both directions,
                thus the attacker cannot change its messages without being detected.
                </t></aside>
            </section>

            <section anchor="ike_resumption" title="Interaction with the IKE Session Resumption">
                <t>IKE Session Resumption <xref target="RFC5723" /> allows peers to quickly restore IKE SA upon a failure.
                To be able to do it a security gateway provides a client with session ticket that allows the gateway
                to restore the IKE SA if this ticket is later presented by the client. IKE Session Resumption <xref target="RFC5723" /> contains
                the list of IKE SA parameters marking each of parameter as either "restored from the ticket" or 
                "re-negotiated at the time of resumption".
                </t>

                <t>The information of whether an implementation used the new authentication logic for old SA <bcp14>MUST</bcp14> be stored
                in the ticket and the implementation <bcp14>MUST</bcp14> act the same way when doing resumption.
                This means that in the IKE_SESSION_RESUME exchange peers do not send the IKE_SA_INIT_FULL_TRANSCRIPT_AUTH notification
                and do not expect it in the received messages.
                </t>

                <aside>
                    <t>During IKE SA resumption no cryptographic algorithms are negotiated and peers do not use their long-term credentials for authentication,
                    which is based on session keys from the old SA. For this reason, the attack defined in <xref target="attack" /> cannot be directly mounted.
                    However, authentication of the full transcript is good cryptographic practice and once implemented for the IKE_SA_INIT exchange,
                    can easily be used for the IKE_SESSION_RESUME exchange as well.
                    </t>
                </aside>

                <t>If there is a chance that the state of this feature can be changed during SA inactivity
                (e.g., a host is upgraded or its configuration was changed), it is <bcp14>RECOMMENDED</bcp14>
                that the host do not use IKE SA resumption and does a full handshake instead.
                </t>
            </section>
        </section>

        <section anchor="security" title="Security Considerations">
	    <t> The IKEv2 extension defined in this document protects against downgrade attacks on IKEv2 described in <xref target="attack" />.
            It only provides this protection when both peers implement the extension.
            </t>

            <t> The attacks described in this document can also be mitigated by disabling support for weak key
            exchange methods. Doing so is feasible when the peer is known out-of-band to support strong key
            exchange methods, but this information may not be available in all deployment scenarios for IKEv2.
            </t>

            <t> The attacks can also be mitigated by mixing a pre-shared key into the session key calculation.
            An attacker that does not know this pre-shared key will be unable to decrypt even if it manages to
            downgrade the key exchange.
            However, the use of a pre-shared key is negotiated by one of extensions Mixing Preshared Keys in IKEv2 <xref target="RFC8784" /> or
            Mixing Preshared Keys in the IKE_INTERMEDIATE and CREATE_CHILD_SA Exchanges <xref target="RFC9867" />, and this negotiation is itself subject to downgrade attack.
            It is therefore necessary for each of the peers to mandate the use of a pre-shared key and abort the
            connection if negotiation fails.
            </t>

            <aside>
                <t> Note, that mixing pre-shared keys to exchange does not help if the PPK key is one of the long term authentication information that has leaked.
                </t>
            </aside>
        </section>

        <section anchor="iana" title="IANA Considerations">
            <t>This document defines new Notify Message Type in the "IKEv2 Notify Message Status Types" registry:</t>
            <figure align="center">
                <artwork align="left"><![CDATA[
16447       IKE_SA_INIT_FULL_TRANSCRIPT_AUTH
                ]]></artwork>
            </figure>
        </section>

    </middle>

    <back>
        <references title='Normative References'>
            <?rfc include="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml" ?>
            <?rfc include="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml" ?>
            <?rfc include="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7296.xml" ?>
        </references>

        <references title='Informative References'>
            <?rfc include="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5723.xml" ?>
            <?rfc include="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8446.xml" ?>
            <?rfc include="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8784.xml" ?>
            <?rfc include="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.9242.xml" ?>
            <?rfc include="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.9370.xml" ?>
            <?rfc include="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.9867.xml" ?>
            <reference anchor="SIGMA">
              <front>
                <title>SIGMA: The ‘SIGn-and-MAc’ Approach to Authenticated Diffie-Hellman and Its Use in the IKE Protocols</title>
                <author fullname="Hugo Krawczyk" initials="H." surname="Krawczyk">
                  <organization/>
                </author>
                <date year="2003"/>
              </front>
              <seriesInfo name="Lecture Notes in Computer Science" value="pp. 400-425"/>
              <seriesInfo name="DOI" value="10.1007/978-3-540-45146-4_24"/>
              <seriesInfo name="ISBN" value="[&quot;9783540406747&quot;, &quot;9783540451464&quot;]"/>
              <refcontent>Springer Berlin Heidelberg</refcontent>
            </reference>
            <reference anchor="DOWNGRADE" target="https://ia.cr/2016/072">
              <front>
                <title>Downgrade Resilience in Key-Exchange Protocols</title>
                <author fullname="Karthikeyan Bhargavan" initials="K." surname="Bhargavan">
                  <organization/>
                </author>
                <author fullname="Christina Brzuska" initials="C." surname="Brzuska">
                  <organization/>
                </author>
                <author fullname="Cédric Fournet" initials="C." surname="Fournet">
                  <organization/>
                </author>
                <author fullname="Markulf Kohlweiss" initials="M." surname="Kohlweiss">
                  <organization/>
                </author>
                <author fullname="Santiago Zanella-Béguelin" initials="S." surname="Zanella-Béguelin">
                  <organization/>
                </author>
                <author fullname="Matthew Green" initials="M." surname="Green">
                  <organization/>
                </author>
                <date month="January" year="2016"/>
              </front>
              <seriesInfo name="Cryptology ePrint Archive" value="Paper 2016/072"/>
            </reference>
        </references>

    <section anchor="ack" title="Acknowledgements" numbered="false">
        <t> Thanks to those who contributed to mailing list discussions that shaped this document.
        Tero Kivinen suggested adding protocol diagrams for readability, Shubham Kumar discussed
        applicability of downgrade prevention to IKE session resumption.
        </t>
    </section>

    </back>
</rfc>

