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

Nico Williams <nico@cryptonector.com> Wed, 27 March 2019 17:09 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 2A367120287 for <saag@ietfa.amsl.com>; Wed, 27 Mar 2019 10:09:03 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2
X-Spam-Level:
X-Spam-Status: No, score=-2 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, URIBL_BLOCKED=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 sqR6hoysaawj for <saag@ietfa.amsl.com>; Wed, 27 Mar 2019 10:09:01 -0700 (PDT)
Received: from eastern.maple.relay.mailchannels.net (eastern.maple.relay.mailchannels.net [23.83.214.55]) (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 7BF40120306 for <saag@ietf.org>; Wed, 27 Mar 2019 10:08:57 -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 831931425A6; Wed, 27 Mar 2019 17:08:56 +0000 (UTC)
Received: from pdx1-sub0-mail-a26.g.dreamhost.com (100-96-3-137.trex.outbound.svc.cluster.local [100.96.3.137]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 4E7AF1423D7; Wed, 27 Mar 2019 17:08:55 +0000 (UTC)
X-Sender-Id: dreamhost|x-authsender|nico@cryptonector.com
Received: from pdx1-sub0-mail-a26.g.dreamhost.com ([TEMPUNAVAIL]. [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.17.2); Wed, 27 Mar 2019 17:08:56 +0000
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|nico@cryptonector.com
X-MailChannels-Auth-Id: dreamhost
X-Versed-Gusty: 258d0eb81d0ae1f2_1553706535987_347150508
X-MC-Loop-Signature: 1553706535987:2374941727
X-MC-Ingress-Time: 1553706535987
Received: from pdx1-sub0-mail-a26.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a26.g.dreamhost.com (Postfix) with ESMTP id 412AB80751; Wed, 27 Mar 2019 10:08:52 -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=s85x56awalJKYz /49xxRquv3bEY=; b=xxEaYNTM7tR+1+RnPT9eymE599yApWpSIgOzPgZ+BUcSYs 2H1gs+WXBwmG8y+3R0NP79NNW3f2Kl+9tcJHN3cUfNmU+qvnTT7SYba1YwCGd5Dp zf9j8nrt+HjyrXREhjN6cOtED34WczyqsaysGnfi5oAk9uqijDvpw7TNpNPg0=
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-a26.g.dreamhost.com (Postfix) with ESMTPSA id AAFBD80752; Wed, 27 Mar 2019 10:08:49 -0700 (PDT)
Date: Wed, 27 Mar 2019 12:08:47 -0500
X-DH-BACKEND: pdx1-sub0-mail-a26
From: Nico Williams <nico@cryptonector.com>
To: Peter Gutmann <pgut001@cs.auckland.ac.nz>
Cc: Carl Wallace <carl@redhoundsoftware.com>, "saag@ietf.org" <saag@ietf.org>
Message-ID: <20190327170846.GI4211@localhost>
References: <21dec229-5b5c-8d52-6817-edac2e39ceec@openca.org> <20198.1553629138@dooku.sandelman.ca> <20190326200103.GR3822@straasha.imrryr.org> <D8BFFE5D.D8084%carl@redhoundsoftware.com> <20190326222740.GE4211@localhost> <1553680145271.97708@cs.auckland.ac.nz>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: inline
In-Reply-To: <1553680145271.97708@cs.auckland.ac.nz>
User-Agent: Mutt/1.9.4 (2018-02-28)
X-VR-OUT-STATUS: OK
X-VR-OUT-SCORE: -100
X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedutddrkedvgdelvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpeffhffvuffkfhggtggujggfsehttdertddtredvnecuhfhrohhmpefpihgtohcuhghilhhlihgrmhhsuceonhhitghosegtrhihphhtohhnvggtthhorhdrtghomheqnecukfhppedvgedrvdekrddutdekrddukeefnecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehlohgtrghlhhhoshhtpdhinhgvthepvdegrddvkedruddtkedrudekfedprhgvthhurhhnqdhprghthheppfhitghoucghihhllhhirghmshcuoehnihgtohestghrhihpthhonhgvtghtohhrrdgtohhmqedpmhgrihhlfhhrohhmpehnihgtohestghrhihpthhonhgvtghtohhrrdgtohhmpdhnrhgtphhtthhopehnihgtohestghrhihpthhonhgvtghtohhrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd
Archived-At: <https://mailarchive.ietf.org/arch/msg/saag/vgS5d_32qdaWTiiCZ1oTEnYAC0g>
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: Wed, 27 Mar 2019 17:09:03 -0000

On Wed, Mar 27, 2019 at 09:49:09AM +0000, Peter Gutmann wrote:
> Nico Williams <nico@cryptonector.com> writes:
> 
> >Something similar can be said of SSHv2's encoding rules.
> 
> The ones that arbitrarily mix binary data and comma-delimited text strings?

You can do that in ASN.1 too if you want...  That was just lack of
discipline in using the features of the encoding.  I agree that it's
awful.

> Of all the encodings I've had to write parsers for, SSH's one scares me the
> most.

I've seen terrible DER hand-rolled codecs...  It's hard to say which is
worse for hand-coding.  But ad-hoc, informal designs like TLS' or SSH's
preclude code generation, so in that sense they are easily the worst.

XDR is one that's in the middle: you get a formal language, and the
encoding is trivial enough that you can hand-roll it with very good
chances of getting it right *if* you have suitable library.

(In Heimdal we have the krb5_{storage,store,ret}_*() functions, a subset
of which gives you XDR, and which make it easy to write safe codecs.
These should really be renamed heim_*() and moved from libkrb5 to
libheimbase, where they can do more good outside krb5 context.)

> It's also the one where I've found the most crashes in the other
> system while developing the code and getting various bits slightly
> wrong, e.g. sending "foo," or ",," as a value, or getting a binary
> length field slightly wrong in combination with text-string data.

I believe that.