[COSE] The one-byte saving from use of a sequence

Laurence Lundblade <lgl@island-resort.com> Fri, 14 May 2021 04:05 UTC

Return-Path: <lgl@island-resort.com>
X-Original-To: cose@ietfa.amsl.com
Delivered-To: cose@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 578003A2105 for <cose@ietfa.amsl.com>; Thu, 13 May 2021 21:05:20 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.895
X-Spam-Level:
X-Spam-Status: No, score=-1.895 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, HTML_MESSAGE=0.001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001] autolearn=ham autolearn_force=no
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 jbZt2xogSL6O for <cose@ietfa.amsl.com>; Thu, 13 May 2021 21:05:17 -0700 (PDT)
Received: from p3plsmtpa12-07.prod.phx3.secureserver.net (p3plsmtpa12-07.prod.phx3.secureserver.net [68.178.252.236]) (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 719D43A2103 for <cose@ietf.org>; Thu, 13 May 2021 21:05:17 -0700 (PDT)
Received: from [192.168.1.81] ([76.167.193.86]) by :SMTPAUTH: with ESMTPA id hP4elO0kBsAmmhP4elrBto; Thu, 13 May 2021 21:05:16 -0700
X-CMAE-Analysis: v=2.4 cv=I5Sg+Psg c=1 sm=1 tr=0 ts=609df6fc a=t2DvPg6iSvRzsOFYbaV4uQ==:117 a=t2DvPg6iSvRzsOFYbaV4uQ==:17 a=heOqQe2DE3k1QwOxLlYA:9 a=QEXdDO2ut3YA:10 a=1-D98BhsrBLQsJTa:21 a=_W_S_7VecoQA:10
X-SECURESERVER-ACCT: lgl@island-resort.com
From: Laurence Lundblade <lgl@island-resort.com>
Content-Type: multipart/alternative; boundary="Apple-Mail=_3486AA8E-81EE-4461-B037-3F60E4F37B78"
Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.17\))
Date: Thu, 13 May 2021 21:05:16 -0700
References: <CAJFkdRwmFZy7PGgJNUpr6New9Op=9cpUg56mmmNFGzhn8pWmXQ@mail.gmail.com> <YFjTK7GSzs1EtPR2@LK-Perkele-VII2.locald> <A8BC22D5-B869-47ED-9F70-C24D51DE0401@ericsson.com>
To: cose <cose@ietf.org>
In-Reply-To: <A8BC22D5-B869-47ED-9F70-C24D51DE0401@ericsson.com>
Message-Id: <A4F794D5-94A0-48F1-9303-4A6A2E7F6E76@island-resort.com>
X-Mailer: Apple Mail (2.3445.104.17)
X-CMAE-Envelope: MS4xfEPkB9F8yiQtKL7cLa90MNU+ZH8gxYpqLOd7QTzdeWGZGf8UvRvcVoEdcN73/t1wPl+Vmd1Mf6pK/+7kyl/LmW2vEZm3B1FA7CGXZj39bSkyIZISQk9M PRVyNnvs61tSerboaJQytdu7QWICM2llS84hxAuSTZ9chgrcHcW/2/r3AL2MHWjqkjTIBepEEt2qhA==
Archived-At: <https://mailarchive.ietf.org/arch/msg/cose/QhW8O5ZJnPuvBmfv74hndAF-PF0>
Subject: [COSE] The one-byte saving from use of a sequence
X-BeenThere: cose@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: CBOR Object Signing and Encryption <cose.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/cose>, <mailto:cose-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cose/>
List-Post: <mailto:cose@ietf.org>
List-Help: <mailto:cose-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/cose>, <mailto:cose-request@ietf.org?subject=subscribe>
X-List-Received-Date: Fri, 14 May 2021 04:05:21 -0000

If I’m thinking right, the one-byte saving from using a sequence rather than array for CBORCertificate only happens when using CBORCertificate in a non-CBOR protocol. When you put CBORCertificate in a CBOR protocol, it has to be an array (or a bstr-wrapped sequence) so it can be distinguished from the surrounding CBOR. In non-CBOR protocols, the surrounding protocol (e.g., the DER, or the TLS records) provides the framing for what is the cert, so the array is not needed.

I’d like to see CBORCertificate an array in the main definition. Then when CBORCertificate is put in a non-CBOR protocol, it can be “unwrapped" to save the byte. The CDDL notation for that would be ~CBORCertificate. (I’ve been reading up on CDDL unwrapping lately, so hopefully I got that right).

This also aligns CBORCertificate with the other CBOR protocols I’ve seen so far. They use an array or map to hold the top-level messages together.

Also, I’m pretty sure the CDDL for COSE_C5 is wrong in the -08 draft. It says:

    COSE_C5 = [ + CBORCertificate ]

With CBORCertificate defined as a CDDL group, no framing structure to distinguish the individual CBORCertificates is generated. The array defined by this is not of individual certs, but of an aggregation of all the certificate data items. It would not be possible to decode correctly. Making CBORCertificate an array solves this problem.

We should expect CBORCertificate to be incorporated into lots and lots of other CBOR-based protocols. If we are making a mistake like this because of CBORCertificate being a sequence and not an array, it seems others may as well. So another reason for the main definition of CBORCertificate to be an array.

LL