Re: [Lwip] [IPsec] draft-ietf-lwig-minimal-esp shepherd writeup

Tero Kivinen <kivinen@iki.fi> Mon, 22 March 2021 15:07 UTC

Return-Path: <kivinen@iki.fi>
X-Original-To: lwip@ietfa.amsl.com
Delivered-To: lwip@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 759983A006A; Mon, 22 Mar 2021 08:07:32 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -0.201
X-Spam-Level:
X-Spam-Status: No, score=-0.201 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=unavailable autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=iki.fi
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iOLgIc38ufgE; Mon, 22 Mar 2021 08:07:26 -0700 (PDT)
Received: from lahtoruutu.iki.fi (lahtoruutu.iki.fi [185.185.170.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id BEE233A0061; Mon, 22 Mar 2021 08:07:25 -0700 (PDT)
Received: from fireball.acr.fi (fireball.kivinen.iki.fi [IPv6:2001:1bc8:100d::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kivinen) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 890561B0004B; Mon, 22 Mar 2021 17:07:19 +0200 (EET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1616425639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q7wIgx23Jys7t6Ootw3MBBAtnLGYQt2OdPza+DpRie4=; b=mjgmT1rBOSD/0ImTJNj0Yil0q8GykIvlK2p79JcrCj9Z1FUvvMUBHj2vbmnIuHArSfMfut bdy+CwuHflNzDUBIQlClOK4+L/BmnWXLh4Gf65F6HIa2kUaXUDHeP2Y0WDZo9q0wBAk1e5 zZINuTC2xOqyUInNZeYqi8/KGspLg71Puam5hqPlXgAcD70B1btpD343/oKdXIvCkxKVV/ NVYbeliQL65zc0/G4kw4DXrNUTh0jzG6Cp6IcliqfrFf0X4TUXB5M4anlr4nET5XsF+a2K dYsc+4k20RE77Nlno8Uc002L/EGnaBxaekogxyYniQNOqvzWlRPyRW5gOgKqYg==
Received: by fireball.acr.fi (Postfix, from userid 15204) id A829625C1272; Mon, 22 Mar 2021 17:07:17 +0200 (EET)
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-ID: <24664.45733.636417.217300@fireball.acr.fi>
Date: Mon, 22 Mar 2021 17:07:17 +0200
From: Tero Kivinen <kivinen@iki.fi>
To: Paul Wouters <paul@nohats.ca>
Cc: Daniel Migault <mglt.ietf@gmail.com>, Mohit Sethi M <mohit.m.sethi=40ericsson.com@dmarc.ietf.org>, "ipsec@ietf.org" <ipsec@ietf.org>, "lwip@ietf.org" <lwip@ietf.org>, ipsecme-chairs@ietf.org
In-Reply-To: <cea14f52-52bb-6f3f-1266-a457978dd43@nohats.ca>
References: <67654664-717b-1017-707b-0b4dfde52d24@ericsson.com> <CADZyTkkgCiy9hf7DE42oGd-5Mw3pjVB3_Y89U8KovxNctQBWZw@mail.gmail.com> <cea14f52-52bb-6f3f-1266-a457978dd43@nohats.ca>
X-Mailer: VM 8.2.0b under 26.3 (x86_64--netbsd)
X-Edit-Time: 45 min
X-Total-Time: 63 min
ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=kivinen smtp.mailfrom=kivinen@iki.fi
ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1616425639; a=rsa-sha256; cv=none; b=pwvghvkQy+DmCY2YLfmniSXZQV6tlVhVUJvVQy/hVHaELjIKjMrWVmtOgzBgqzuTho9a5q gg92YUIGFnaVgIdpwHFgNkf3A+DIjcaSBH+yVC7gPfQOFeX9ebGFXDSbeoahlXB8gx878q 5W8VwetLUfQHFXlL9s8M8/DXf1hd9I9eDkc1O+r6GOBPeuLGO3mWUOxT8c9GrBb96afPa7 ytRNr+laOjvLJ9NyWxuSlVGF/ObFYvFsItqP/pvBsUUQNmr3BB/ITmYLe4neNpSpFxXvHY B/rNZQYyPrmm3ySioyoPhGbv2aPe2bvgkd73/vjEqbcmfN2u51AH6vUjO3mEqg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1616425639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q7wIgx23Jys7t6Ootw3MBBAtnLGYQt2OdPza+DpRie4=; b=Kc36+roClWHwv8t14ieke/p73WzrgDJq0y5NcneD9VNHsoNUrjIR+5qTQLB1pVh9qw7QOR K5THtjr78DzhkaWNSRBngQBGJ0tLk7sG1cGsWgiPwMjIoFsf5MiHuiFmkrNbOEFPq9qZBS Za648QaBZjJEhX4BBbqDCiDJS0qtI09V34FLeXrS7QqW/F/9FywaQXB0/GKxcDVrFThPB+ evkbIoad9P9vmQlIzHeJ4eSe/05fczz/tWeN+Yj/nIzgEDdHuMgRx/zMTlcmumIr9QBKY1 eKcUC4BkGzfWtl1LUCR1hcYnK8qUOVzA7snJQFG1J3N/QXcuKe5UWAN2PwkjhA==
Archived-At: <https://mailarchive.ietf.org/arch/msg/lwip/QdxJ1HWFnAWzk0wMrhJxnBt4WMw>
Subject: Re: [Lwip] [IPsec] draft-ietf-lwig-minimal-esp shepherd writeup
X-BeenThere: lwip@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Lightweight IP stack. Official mailing list for IETF LWIG Working Group." <lwip.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/lwip>, <mailto:lwip-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/lwip/>
List-Post: <mailto:lwip@ietf.org>
List-Help: <mailto:lwip-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/lwip>, <mailto:lwip-request@ietf.org?subject=subscribe>
X-List-Received-Date: Mon, 22 Mar 2021 15:07:33 -0000

Paul Wouters writes:
> On Sun, 21 Mar 2021, Daniel Migault wrote:
> 
> (replying to some issues here, but also added a full review of the document)
> 
> Side note: I am bit confused why this document would not be a document
> from the IPsecME WG ? I know we talked about this before? Did we decide
> against adoption at IPsecME ? Can the authors, WG chairs of IPsecME or
> the responsible AD shed some light on the history here?
> 
> In general, this draft is very "wordy" because it is trying to steer
> itself around a lot of problems, without making firm decisions. But
> the point of an RFC is that it should make clear decisions that
> implementers can adopt clearly. As such, I'm not in favour of this
> draft. I believe I stated this before?

This draft does not change anything in the ESP, it only gives
guidelines to the lightweight implementations so they can more easily
understand what kind of optimizations are allowed by standard ESP and
what benefits or concerns there might be from selecting them.

Because it does not change ESP, it is not really IPsecME WG job. It is
similar than RFC7815 Minimal IKEv2 Initiator Implementation document,
which was also published from the LWIG WG and not from the IPsecME WG. 

> But it seems that although my comments caused the draft to be modified,
> it still allows non-random SPIs:

This document cannot mandate that SPIs need to be random, as no such
requirement is in the standard ESP RFC. Requiring SPIs to be random
would be a change from RFC4303, and as such cannot be done in this
document.

For example RFC4301 defines SPI as follows in its Appendix A:
Glossary:

----------------------------------------------------------------------
   Security Parameters Index (SPI)
      An arbitrary 32-bit value that is used by a receiver to identify
      the SA to which an incoming packet should be bound.  For a unicast
      SA, the SPI can be used by itself to specify an SA, or it may be
      used in conjunction with the IPsec protocol type.  Additional IP
      address information is used to identify multicast SAs.  The SPI is
      carried in AH and ESP protocols to enable the receiving system to
      select the SA under which a received packet will be processed.  An
      SPI has only local significance, as defined by the creator of the
      SA (usually the receiver of the packet carrying the SPI); thus an
      SPI is generally viewed as an opaque bit string.  However, the
      creator of an SA may choose to interpret the bits in an SPI to
      facilitate local processing.
----------------------------------------------------------------------

>From the last sentence it is clear that SPI can also be non-random.
You can for example take last 8 bits of the SPI and use that as CPU
identifier, and use next 16-bits before that as index to the SPI table
on that CPU specific SPI table, and use 0xff as first 8-bits just so
you never end up having any reserved numbers for your SPI, i.e., have
SPI as 0xffiiiicc, where iiii is index and cc is cpu id. 

> So I feel I raised a security issue, and the text just copied my concern
> but still basically states implementations MAY do this. I believe this
> is wrong.

But wasn't that attack you referenced, talking about IKE SPIs, not ESP
SPIs? At least that is what I remember about that attack...

Also even IKE SPIs are not required to be random, they are just
required to be unique and non-zero.

> If such a device cannot generate 4 random bytes, how is it performing a
> DiffieHellman key exchange? Or is it presumed that IKE is done
> elsewhere? In which case "elsewhere" can generate 4 random bytes.

I do not think SPI issue is about generating it, but using it for each
incoming packet. If device has only support for 4 incoming SPIs, it
might just create SPIs using format 0x8000000x, where x is the index
in its SAD. Then getting address of SAD structure in memory could
simply be (SPI << (sad_table_shift)) + sad_table_start_address after
checking that (spi & 0xfffffffc) == 0x80000000.

Generation of the SPI is single operation, and as such not an issue.
Mapping SPI -> SAD entry must be done for every incoming packet, and
saving cycles from there might make difference.

> What about IVs ? If you cannot generate 4 bytes of random, how it is
> going to generate the IVs required for ESP?

Implicit Initialization Vector (IV) for Counter-Based Ciphers in
Encapsulating Security Payload (ESP), RFC 8750,

> > In fact, the SPI does not necessarily need to be randomly generated.
> 
> Yes it is does, see the above link on an attack against IKE where the
> randomized SPI made offline attacks impossible and online attacks
> impractical.

IKE SPI or ESP SPI? My understanding those attacks were against IKE,
not against ESP.

And if what you are saying is true, then we as an IPsecME needs to
start making modification to the ESP to actually require the SPI to be
random. Currently it does not need to be random, just unique from the
local point of view.

> The secion on Sequence Numbers concerns me too, and for the same reasons
> as above. If you cannot keep a sequence number as state, you cannot do
> any AEAD encryption. I believe it is a bad idea to still write
> specifications today that require non-AEAD algorithms. Once you can do
> it for AEAD, then you can do it for SN too (and using the other draft
> that specified re-using the SN for one of these for other saves you
> those bytes once).

You can use AEAD encryption with sequence numbers generated by time
without any problems. I would expect most of the IoT devices will use
AEAD ciphers, as for example IEEE Std 802.15.4 is only defined to
support AEAD ciphers, and the only one currently defined there is
AES-CCM, and that AEAD AES-CCM is used with timebased nonces when used
with TSCH currently.

The problem with regular sequence numbers is that you need to store
them to stable storage every time you go sleep. Storing the SA
information (keys, SPIs etc) to the flash once after the creation of
the SA can be done, as that is just one flash write per SA creation.

Syncing sequence number to flash after every packet would quickly wear
out the flash, and most likely also slow down the system greatly, as
writing to flash is not that fast operation than reading from there.
Note, that lots of these IoT devices wake up, do something, send few
packets, and then go back to sleep. They do have separete hardware
that allows them to wake up after certain timeout, and most likely
also timers that start running when the device was booted up, so they
might have concept of time with certain granularity. They might NOT
have real time clocks or any information how their internal clock
relates to real world clock, and their internal clocks/timers might
not be very accurate, but they should be enough to know that each time
they wake up their time is greater than what it was last time they
woke up. 

> Again, I do not think that we should write RFCs where to disable
> security meassures because the device is too constrained. If that is
> the case, perhaps IPsec is not the protocol that should be used? Yes,
> we can use IPsec without replay protection, but it is unwise to do so.
> Handwaving it to be the implementors or application's problem is a bit
> dangerous (though not as dangerous as the SPI case above)

If you want to change this we need to revise RFC4303 and RFC4301.
Replay protection has always been optional for the receiver. There are
lots of ways to do things in a way where you do NOT need replay
protection on the ESP layer.

The problem with replay protection is again that it needs to be stored
across sleeps, i.e., written to the flash memory.

If the IoT device you are talking about is for example temperature
sensor and the protocol is such that sensor wakes up every 60 seconds,
sends sensor measurement over ESP, and waits for ACK back from the
controller, and after receiving the ACK it goes back to sleep, there
is no need to have replay protection on the sensor end. Yes, attacker
who can block the connection between the sensor and controller, can
replay ACKs and cause the sensor to be happy and not notice that it
has lost connection to the controller, but on the other hand even if
the sensor would notice that it has lost the connection to controller,
there is nothing it can do, as there is no way of indicating that
information other than over the radio and attacker is already blocking
that. Temperature sensors usually do not have displays or keyboards,
and even when there might be LEDs on the board, they do not help much
when the sensor is inside the building wall.
-- 
kivinen@iki.fi