[Cbor] CDDL degenericizer (cddlc tool 0.1.0 update)

Carsten Bormann <cabo@tzi.org> Wed, 25 January 2023 10:37 UTC

Return-Path: <cabo@tzi.org>
X-Original-To: cbor@ietfa.amsl.com
Delivered-To: cbor@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 5822EC14CF01 for <cbor@ietfa.amsl.com>; Wed, 25 Jan 2023 02:37:25 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.486
X-Spam-Level:
X-Spam-Status: No, score=-1.486 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, KHOP_HELO_FCRDNS=0.399, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01, URIBL_BLOCKED=0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=no autolearn_force=no
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KdCWeAMbmdxb for <cbor@ietfa.amsl.com>; Wed, 25 Jan 2023 02:37:20 -0800 (PST)
Received: from smtp.zfn.uni-bremen.de (gabriel-smtp.zfn.uni-bremen.de [IPv6:2001:638:708:32::15]) (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) by ietfa.amsl.com (Postfix) with ESMTPS id 48F90C14F74B for <cbor@ietf.org>; Wed, 25 Jan 2023 02:37:18 -0800 (PST)
Received: from [192.168.217.124] (p548dc9a4.dip0.t-ipconnect.de [84.141.201.164]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.zfn.uni-bremen.de (Postfix) with ESMTPSA id 4P20dk3LsDzDCcT; Wed, 25 Jan 2023 11:37:14 +0100 (CET)
From: Carsten Bormann <cabo@tzi.org>
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
X-Mao-Original-Outgoing-Id: 696335833.946051-d86fe22b6768f4bfcbc8000e61e2a0d3
Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\))
Date: Wed, 25 Jan 2023 11:37:14 +0100
Message-Id: <6557CE1A-0579-4F9F-8AC7-6DC80F625A43@tzi.org>
To: cbor@ietf.org
X-Mailer: Apple Mail (2.3608.120.23.2.7)
Archived-At: <https://mailarchive.ietf.org/arch/msg/cbor/mhAajmzOrOvVdXZi-KWbLbmytZQ>
Subject: [Cbor] CDDL degenericizer (cddlc tool 0.1.0 update)
X-BeenThere: cbor@ietf.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: "Concise Binary Object Representation \(CBOR\)" <cbor.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/cbor>, <mailto:cbor-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/cbor/>
List-Post: <mailto:cbor@ietf.org>
List-Help: <mailto:cbor-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/cbor>, <mailto:cbor-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 25 Jan 2023 10:37:25 -0000

Tool builders often want to process as minimal a subset of CDDL as possible.
One slight complication that not every tool builder wants to handle is processing the generics feature.

As the cddlc (note the “c” at the end) tool is gaining CDDL 2.0 functionality, I’m pushing out revisions that already do something useful; today’s release doesn’t add in actual CDDL 2.0 features yet, though.

cddlc version 0.1.0 now supports (all these require or imply the -r option):

— writing “processed” CDDL, using the -tcddl option
— expanding all generics, using the -x option.
— complaining about undefined rule names, using the -u option.

I have attached the output of

    cddlc -urxtcddl uccs.cddl

if you want to see how this works.
The point of course is not to use “processed” CDDL to obtain working copies for humans, but to feed this into tools such as validators or code generators.

As always:

    gem update cddlc

Note: A recent version of Ruby (3.x) is required to activate these additional features.

Bug reports are gladly accepted, as github issues [1], email, etc.
(I already know that any attempt at indentation is out of whack; maybe I shouldn’t try that…)

(Next: CDDL 2.0 import features.)

Grüße, Carsten

[1]: https://github.com/cabo/cddlc


*** uccs.cddl:

Claims-Set = {
 * $$Claims-Set-Claims
 * Claim-Label .feature "extended-claims-label" => any
}
Claim-Label = CBOR-ONLY<int> / text
string-or-uri = text

$$Claims-Set-Claims //= ( iss-claim-label => string-or-uri  )
$$Claims-Set-Claims //= ( sub-claim-label => string-or-uri  )
$$Claims-Set-Claims //= ( aud-claim-label => string-or-uri  )
$$Claims-Set-Claims //= ( exp-claim-label => ~time )
$$Claims-Set-Claims //= ( nbf-claim-label => ~time )
$$Claims-Set-Claims //= ( iat-claim-label => ~time )
$$Claims-Set-Claims //= ( cti-claim-label => bytes )

iss-claim-label = JC<"iss", 1>
sub-claim-label = JC<"sub", 2>
aud-claim-label = JC<"aud", 3>
exp-claim-label = JC<"exp", 4>
nbf-claim-label = JC<"nbf", 5>
iat-claim-label = JC<"iat", 6>
cti-claim-label = CBOR-ONLY<7>  ; jti in JWT: different name and text

JSON-ONLY<J> = J .feature "json"
CBOR-ONLY<C> = C .feature "cbor"
JC<J,C> = JSON-ONLY<J> / CBOR-ONLY<C>


; [RFC8747]
$$Claims-Set-Claims //= ( 8: CWT-cnf ) ; cnf
CWT-cnf = {
  (1: CWT-COSE-Key) //
  (2: CWT-Encrypted_COSE_Key) //
  (3: CWT-kid)
}

CWT-COSE-Key = COSE_Key
CWT-Encrypted_COSE_Key = COSE_Encrypt / COSE_Encrypt0
CWT-kid = bytes

; [RFC8693]
$$Claims-Set-Claims //= ( 9: CWT-scope ) ; scope
; TO DO: understand what this means:
; scope The scope of an access token as defined in [RFC6749].
; scope 9 byte string or text string [IESG] [RFC8693, Section 4.2]
CWT-scope = bytes / text

; [RFC-ietf-ace-oauth-authz-45, Section 5.10]
$$Claims-Set-Claims //= ( 38: CWT-ace-profile ) ; ace_profile
CWT-ace-profile = $CWT-ACE-Profiles /
  int .feature "ace_profile-extend"
; fill in from IANA registry
;   https://www.iana.org/assignments/ace/ace.xhtml#ace-profiles :
$CWT-ACE-Profiles /= 1 ; coap_dtls

$$Claims-Set-Claims //= ( 39: CWT-cnonce ) ; cnonce
CWT-cnonce = bytes

$$Claims-Set-Claims //= ( 40: CWT-exi ) ; exi
CWT-exi = uint ; in seconds (5.10.3)

;;; insert CDDL from 9052-to-be to complete these CDDL definitions.



*** Output of cddlc -urxtcddl uccs.cddl:

;;; *** undefined: COSE_Key
;;; *** undefined: COSE_Encrypt
;;; *** undefined: COSE_Encrypt0
Claims-Set = {
  * $$Claims-Set-Claims,
  * Claim-Label .feature "extended-claims-label" => any,
}
Claim-Label = int .feature "cbor" / text
string-or-uri = text
$$Claims-Set-Claims = (iss-claim-label => string-or-uri // sub-claim-label => string-or-uri // aud-claim-label => string-or-uri // exp-claim-label => ~time // nbf-claim-label => ~time // iat-claim-label => ~time // cti-claim-label => bytes // 8 => CWT-cnf // 9 => CWT-scope // 38 => CWT-ace-profile // 39 => CWT-cnonce // 40 => CWT-exi)
iss-claim-label = "iss" .feature "json" / 1 .feature "cbor"
sub-claim-label = "sub" .feature "json" / 2 .feature "cbor"
aud-claim-label = "aud" .feature "json" / 3 .feature "cbor"
exp-claim-label = "exp" .feature "json" / 4 .feature "cbor"
nbf-claim-label = "nbf" .feature "json" / 5 .feature "cbor"
iat-claim-label = "iat" .feature "json" / 6 .feature "cbor"
cti-claim-label = 7 .feature "cbor"
CWT-cnf = {1 => CWT-COSE-Key // 2 => CWT-Encrypted_COSE_Key // 3 => CWT-kid}
CWT-COSE-Key = COSE_Key
CWT-Encrypted_COSE_Key = COSE_Encrypt / COSE_Encrypt0
CWT-kid = bytes
CWT-scope = bytes / text
CWT-ace-profile = $CWT-ACE-Profiles / int .feature "ace_profile-extend"
$CWT-ACE-Profiles = 1
CWT-cnonce = bytes
CWT-exi = uint