Re: [saag] ASN.1 vs. DER Encoding

Nico Williams <nico@cryptonector.com> Mon, 22 April 2019 21:14 UTC

Return-Path: <nico@cryptonector.com>
X-Original-To: saag@ietfa.amsl.com
Delivered-To: saag@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 6412F1200EB for <saag@ietfa.amsl.com>; Mon, 22 Apr 2019 14:14:59 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.001
X-Spam-Level:
X-Spam-Status: No, score=-2.001 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=cryptonector.com
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 3_KTmTdzaquy for <saag@ietfa.amsl.com>; Mon, 22 Apr 2019 14:14:57 -0700 (PDT)
Received: from firebrick.maple.relay.mailchannels.net (firebrick.maple.relay.mailchannels.net [23.83.214.59]) (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 C12AC1200B9 for <saag@ietf.org>; Mon, 22 Apr 2019 14:14:56 -0700 (PDT)
X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com
Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id EC94B125666; Mon, 22 Apr 2019 21:14:55 +0000 (UTC)
Received: from pdx1-sub0-mail-a17.g.dreamhost.com (unknown [100.96.11.48]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 9EC8912593D; Mon, 22 Apr 2019 21:14:55 +0000 (UTC)
X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com
Received: from pdx1-sub0-mail-a17.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.17.2); Mon, 22 Apr 2019 21:14:55 +0000
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|nico@cryptonector.com
X-MailChannels-Auth-Id: dreamhost
X-Grain-Ruddy: 2cb708214e0f241e_1555967695783_13166951
X-MC-Loop-Signature: 1555967695783:38432849
X-MC-Ingress-Time: 1555967695782
Received: from pdx1-sub0-mail-a17.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a17.g.dreamhost.com (Postfix) with ESMTP id 436527F6EC; Mon, 22 Apr 2019 14:14:55 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=cryptonector.com; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=cryptonector.com; bh=JwWXPN5N+5llJy ghH/vsbSfvVwM=; b=Xe7MFreRc5OEhoDoKpf/sQJkFMPo5bHZh9ChuDEU4rcUfn TE5yHayvwaT2oeK0Bi8yG6RuHTsBOzXkSHL2JZ+FLx7omNTWi9XF3Iej/Xa0lAa7 hyS3u/+g2eDAlcTCPzLsOz0rRCsCH8qpN3etfsEj44wZxK8WL7uf42u9aQSQY=
Received: from localhost (unknown [24.28.108.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: nico@cryptonector.com) by pdx1-sub0-mail-a17.g.dreamhost.com (Postfix) with ESMTPSA id 83D377F6DA; Mon, 22 Apr 2019 14:14:52 -0700 (PDT)
Date: Mon, 22 Apr 2019 16:14:50 -0500
X-DH-BACKEND: pdx1-sub0-mail-a17
From: Nico Williams <nico@cryptonector.com>
To: Phillip Hallam-Baker <phill@hallambaker.com>
Cc: Stephen Farrell <stephen.farrell@cs.tcd.ie>, "saag@ietf.org" <saag@ietf.org>
Message-ID: <20190422211449.GD3137@localhost>
References: <20190326164951.GX4211@localhost> <20190326214816.GB4211@localhost> <1553679912618.8510@cs.auckland.ac.nz> <20190327151545.GG4211@localhost> <20190330153101.GT35679@kduck.mit.edu> <C3D9DD15-AB23-4B42-BA61-A4E4CD826B77@huitema.net> <F6387640-20F3-4B3C-8E61-58CAF7828CA1@tzi.org> <269bee5d-e225-3484-04ed-3e5de6c19081@cs.tcd.ie> <CAMm+Lwi1pNje_9HMYnf-gQN8scggQDTUB0z0uCsy9trtaYKBsg@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: inline
In-Reply-To: <CAMm+Lwi1pNje_9HMYnf-gQN8scggQDTUB0z0uCsy9trtaYKBsg@mail.gmail.com>
User-Agent: Mutt/1.9.4 (2018-02-28)
X-VR-OUT-STATUS: OK
X-VR-OUT-SCORE: -100
X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduuddrgeeigddugeelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepfffhvffukfhfgggtuggjfgesthdtredttdervdenucfhrhhomheppfhitghoucghihhllhhirghmshcuoehnihgtohestghrhihpthhonhgvtghtohhrrdgtohhmqeenucfkphepvdegrddvkedruddtkedrudekfeenucfrrghrrghmpehmohguvgepshhmthhppdhhvghloheplhhotggrlhhhohhsthdpihhnvghtpedvgedrvdekrddutdekrddukeefpdhrvghtuhhrnhdqphgrthhhpefpihgtohcuhghilhhlihgrmhhsuceonhhitghosegtrhihphhtohhnvggtthhorhdrtghomheqpdhmrghilhhfrhhomhepnhhitghosegtrhihphhtohhnvggtthhorhdrtghomhdpnhhrtghpthhtohepnhhitghosegtrhihphhtohhnvggtthhorhdrtghomhenucevlhhushhtvghrufhiiigvpedt
Archived-At: <https://mailarchive.ietf.org/arch/msg/saag/MUkQ6It6LGcktTIk9R_y2nQxwEs>
Subject: Re: [saag] ASN.1 vs. DER Encoding
X-BeenThere: saag@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Security Area Advisory Group <saag.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/saag>, <mailto:saag-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/saag/>
List-Post: <mailto:saag@ietf.org>
List-Help: <mailto:saag-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/saag>, <mailto:saag-request@ietf.org?subject=subscribe>
X-List-Received-Date: Mon, 22 Apr 2019 21:14:59 -0000

On Mon, Apr 22, 2019 at 04:47:24PM -0400, Phillip Hallam-Baker wrote:
> 3) Having six encoding rules is a defect, not a strength. The point of
> standards is to remove choices that don't really matter. Having six
> incompatible encodings makes it matter.

Six?  I believe there's more.  Ever heard of GSER?

BER, DER, CER, PER, OER, XER, JER(?), GSER, and who knows what else.

You could easily make encoding rules for ASN.1 out of XDR, NDR, CBOR,
and many others.

It's not a defect of the spec.  It's a defect of history.

In 1984 the ITU-T crowd loved themselfs some TLV encodings.

The IETF crowd did not.  Thus PER.  But PER never took off because the
specs weren't free at the time, and there was no tooling.  TLVs at least
looked easy.

Meanwhile the IETF loved itself some text-based protocols -- lots of
them.  And while neither XML nor JSON came from the IETF, they found a
home here.

It turns out there's a great deal of demand for both, a) "textual", and
b) binary encodings.  And for (b), TLV kinda sucks, but it's what we've
done for 30 years in many cases.  We also have "bits on the wire"
encodings.

That's why we have all the ASN.1 encoding rules, XDR, NDR, XML,
FastInfoSet, JSON, a whole bunch of "binary JSON" formats (including
ones not brought to the IETF, such as PostgreSQL's JSONB, which is
actually quite neat), and now all the *buffers rules (protocolbuffers,
flatbuffers), and who knows what else I might be missing.  Oh, and
things like MIME, which in fact are encoding rules.  And SSHv2, and TLS,
and...  And S-expressions, and Perl5 data dumper, and...

Easy, safe prediction: we'll have more encoding rules soon.

> 4) The DER encoding rules are botched. They require use of nested length
> delimited fields for a start which is inherently insecure unless the
> receiver checks every inner structure to make sure that it is correctly
> nested inside the outer.

Yes.  The decisions made in both DER and CER make both of them difficult
to use in actuality.  The ITU-T could have made better choices for a
canonical flavor of BER :(

> 5) The botched DER encoding is even worse because the nested lengths is the
> use of nested variable length length specifiers. This means that the only
> efficient strategy for encoding ASN.1 is to fill the buffer in the REVERSE
> order starting with the last item.

It's worse: you have to realloc as you go, or build a rope, or do one
pass to compute length and one to encode.  DER is truly awful.

> 7) To add insult to injury, the canonicalization that DER encoding purports
> to provide is of absolutely no value. If I am checking the signature of
> octet sequence X, absolutely harm should come from the possibility that
> there exist an octet sequence Y that has identical semantics which could
> have been signed instead. Yes, I can construct ludicrous scenarios in which
> that would be true but any system that relied on canonicalization is broken.

Agreed.  And yet even now we find people who want a canonical JSON :( :(

> 8) PKIX requires DER but does not provide a canonical form for a
> certificate. You cannot strip an X.509 certificate to its elements, put
> those elements into an X.500 directory and then reassemble the cert even if
> you want to because the extensions are specified as a list, not a set.
> Given that 1TB of SSD currently costs $125 and certificates are a few KB at
> most, this would be a very silly thing to want to try in any case even if
> there were any people still operating X.500 directories.

One thing we've learned is that we *don't* want directories or white
pages of any kind, not outside the corporate environment.

And x.400/x.500 naming is an awful disaster.

Another thing is that the specific form a certificate takes is not
terribly interesting, but the names and issuer are.  And even the issuer
wouldn't be that interesting in a properly hierarchical PKI, but we
never got one (except for DNSSEC).

Nico
--