<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude"
     submissionType="independent"
     category="info"
     tocDepth="3"
     docName="draft-rundgren-cotx-04"
     ipr="trust200902"
     obsoletes=""
     updates=""
     xml:lang="en"
     tocInclude="true"
     symRefs="true"
     sortRefs="true"
     version="3">
    <front>
      <title abbrev="COTX">
        CBOR Object Type Extension (COTX)
      </title>
      <author fullname="Anders Rundgren" initials="A." surname="Rundgren" role="editor">
          <organization>Independent</organization>
          <address>
              <postal>
                  <city>Montpellier</city>
                  <country>France</country>
              </postal>
              <email>anders.rundgren.net@gmail.com</email>
              <uri>https://www.linkedin.com/in/andersrundgren/</uri>
          </address>
      </author>
      <date year="2023"/>
      <area>Application</area>
      <workgroup>CBOR</workgroup>
      <keyword>CBOR</keyword>
      <keyword>URL</keyword>
      <keyword>Identfier</keyword>
      <keyword>Type</keyword>

      <abstract>
        <t>
          This document describes a CBOR tag for augmenting CBOR data items
          with type identifiers in the form of arbitrary CBOR text strings.
          This design enables type identifiers to optionally be expressed as URLs,
          potentially pointing to Web pages holding related descriptions
          in human readable form, as well as being compatible with established
          methods for adding type information to JSON and XML data.
        </t>
      </abstract>
    </front>
    <middle>
      <section anchor="cotx.intro" numbered="true" toc="default">
        <name>Introduction</name>
        <t>
          This specification introduces a method for augmenting data expressed in the
          CBOR <xref target="RFC8949" format="default"/> notation,
          with a type identifier mechanism based on CBOR text strings.
        </t>
        <t>
          The primary purposes of the text based type identifier tag described in
          this document are:
        </t>
        <ul spacing="normal">
          <li>
            Enabling developers defining application
            specific type identifiers without necessarily having to go
            through an external registration process.
          </li>
          <li>
            By supporting URLs <xref target="URL" format="default"/> as
            type identifiers, related human readable information may
            (through dereferencing), be provided for usage with Web browsers.
            Since URLs are compatible with firmly established
            methods for adding type information to JSON and XML data,
            this design may simplify a switch to CBOR.
            See also <xref target="cotx.uri-and-uri" format="default"/>.
          </li>
        </ul>
        <t>
          This specification is also intended to provide a path for ISO
          using CBOR as a possible alternative to XML by supporting
          their current URN
          <xref target="RFC8141" format="default"/>
          based type identifier naming scheme.
          See also <xref target="cotx.urn" format="default"/>.
        </t>
        <t>
          By applying the typing scheme to top level CBOR objects,
          additional functionality is enabled including:
        </t>
        <ul spacing="normal">
          <li>
            Support for embedding CBOR objects in other CBOR and non-CBOR constructs,
            as well as storage in databases, without being forced adding
            information about the object.
          </li>
          <li>
            Remove the need for application specific media types.
            In many cases "application/cbor" would suffice.
          </li>
        </ul>
        <section anchor="cotx.terms" numbered="true" toc="default">
          <name>Terminology</name>
          <t>
            In this document the term CBOR "object" is used interchangeably with
            the CBOR <xref target="RFC8949" format="default"/> "data item".
          </t>
          <t>
            The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST&nbsp;NOT</bcp14>",
            "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>
              SHALL&nbsp;NOT
            </bcp14>", "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>", 
            "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
            "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" 
            in this document are to be interpreted as
            described in BCP 14 <xref target="RFC2119"/> 
            <xref target="RFC8174"/> when, and only when, they
            appear in all capitals, as shown here.
          </t>
        </section>
      </section>

      <section anchor="cotx.spec" numbered="true" toc="default">
        <name>Specification</name>
        <t>
          This specification builds on the CBOR <xref target="RFC8949" format="default"/>
          tag feature (major type 6), by defining a
          fixed tag with the preliminary decimal value of 1010.
          See also <xref target="cotx.iana" format="default"/>.
        </t>
        <t>
          This tag MUST in turn enclose a CBOR array (major type 4) with two elements,
          where the first element MUST contain a type identifier in
          textual format indicating the definition of a CBOR object,
          while the second element MUST hold an instance of the associated object itself.
          The type identifier MUST be a valid CBOR text string (major type 3),
          while the only constraint on the targeted object is that it MUST be a valid CBOR object.
        </t>
        <t>
          The syntax expressed in CBOR diagnostic notation
          (section 8 of <xref target="RFC8949" format="default"/>) would read as:
        </t>
        <t>
          &nbsp;&nbsp;&nbsp;&nbsp;1010([<em>Object Type Identifier</em>, <em>Object Instance Data</em>])
        </t>
        <t>
          Note that real-world usages will typically impose constraints
          like requiring type identifiers to be expressed as HTTPS URLs etc.
        </t>
        <section anchor="cotx.sample" numbered="true" toc="default">
          <name>Sample</name>
          <t>
            Consider the following sample:
          </t>
          <sourcecode>
1010(["https://example.com/myobject", {
  1: "data",
  2: "more data"
}])
          </sourcecode>
          <t>
            Converting the sample above to CBOR expressed in hexadecimal notation (here shown with
            embedded comments as well), should result in the following output:
          </t>
          <sourcecode>
D9 03F2                             # tag(1010)
   82                               # array(2)
      78 1C                         # text(28)
         68747470733A2F2F6578616D706C652E636F6D2F6D796F626A656374
                                    # "https://example.com/myobject"
      A2                            # map(2)
         01                         # unsigned(1)
         64                         # text(4)
            64617461                # "data"
         02                         # unsigned(2)
         69                         # text(9)
            6D6F72652064617461      # "more data"
          </sourcecode>
          <t>
            In a typical implementation "https://example.com/myobject" would
            also serve as a hyper-link to human readable information about the identifier, 
            accessed through a Web browser.
          </t>
        </section>
      </section>

      <section anchor="cotx.iana" numbered="true" toc="default">
        <name>IANA Considerations</name>
        <t>
          In the registry <xref target="IANA.cbor-tags"/>,
          IANA is requested to allocate the tag defined in <xref target="tab-tag-value"/>.
        </t>
        <table anchor="tab-tag-value">
          <name>Values for Tag Numbers</name>
          <thead>
            <tr>
              <th align="right">Tag</th>
              <th align="left">Data Item</th>
              <th align="left">Semantics</th>
              <th align="left">Reference</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td align="right">1010</td>
              <td align="left">array: [id: text string, obj: any]</td>
              <td align="left">Object type identifier</td>
              <td align="left">draft-rundgren-cotx-04</td>
            </tr>
          </tbody>
        </table>
      </section>

      <section anchor="cotx.security" numbered="true" toc="default">
        <name>Security Considerations</name>
        <t>
          This specification inherits all the security considerations
          of CBOR <xref target="RFC8949" format="default"/>.
        </t>
        <t>
          URL-based type identifiers MUST NOT be used for automatically
          downloading CBOR schema data like CDDL
          <xref target="RFC8610" format="default"/>
          to CBOR processors, since this
          introduces potential vulnerabilities.
        </t>
        <t>
          The availability of type information does in no way limit the need
          for input data validation. 
        </t>
        <t>
          For signed CBOR objects, it is RECOMMENDED to include the object type
          identifier extension in the signature calculation as well.
          The same considerations apply to encryption using AEAD algorithms.
        </t>
      </section>
    </middle>
    <back>
      <references>
        <name>References</name>
        <references>
            <name>Normative References</name>

            <xi:include
                href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
            <xi:include
                href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
            <xi:include
                href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8949.xml"/>

          <reference anchor="IANA.cbor-tags" target="https://www.iana.org/assignments/cbor-tags">
            <front>
              <title>Concise Binary Object Representation (CBOR) Tags</title>
              <author>
                <organization abbrev="IANA">Internet Assigned Numbers Authority</organization>
              </author>
              <date day="19" month="September" year="2013"/>
            </front>
          </reference>
        </references>
        <references>
            <name>Informative References</name>

            <xi:include
                href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4151.xml"/>
            <xi:include
                href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5141.xml"/>
            <xi:include
                href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8141.xml"/>
            <xi:include
                href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8610.xml"/>

          <reference anchor="XSD" target="http://www.w3.org/TR/xmlschema11-1/">
            <front>
              <title>XML Schema Definition Language (XSD) 1.1 Part 1: Structures</title>
              <author>
                <organization>W3C</organization>
              </author>
              <date/>
            </front>
          </reference>

          <reference anchor="URL" target="https://url.spec.whatwg.org/">
            <front>
              <title>Living Standard — Last Updated 3 May 2022</title>
              <author>
                <organization>What WG</organization>
              </author>
              <date/>
            </front>
          </reference>
 
        </references>

      </references>

      <section anchor="cotx.uri-and-uri" numbered="true" toc="default">
        <name>URI and URL Identifiers</name>
        <t>
          The primary reason for using URI or URL 
          <xref target="URL" format="default"/>
          based type identifiers is for maintaining a single
          name-space for the entire specification of a system.
          Note that the referenced URL specification does not distinguish
          between URIs and URLs.
        </t>
        <t>
          This non-normative section describes different methods for dealing
          with type identifiers expressed as URIs or URLs.
        </t>
        <section anchor="cotx.url.own.domain" numbered="true" toc="default">
          <name>Registering a Dedicated Domain</name>
          <t>
            A core issue with identifiers depending on domain (DNS) names is that
            domain names may not necessarily remain valid during the anticipated
            life-time of an identifier.  The owner of a domain name may due
            to organizational changes, neglect, lack of interest, or even death,
            lose control over its use, effectively leaving associated identifiers orphaned.
          </t>
        </section>
        <section anchor="cotx.url.sub.domain" numbered="true" toc="default">
          <name>Using a Sub-domain</name>
          <t>
            An alternative is using a dedicated sub-domain belonging to an
            entity that is likely to survive for the foreseeable future.
            With the advent of public repositories like GitHub, this appears
            to be a simpler, cheaper, and more robust solution than maintaining
            dedicated domain names.
          </t>
        </section>
        <section anchor="cotx.tag.uri" numbered="true" toc="default">
          <name>The 'tag' URI Scheme</name>
          <t>
            For applications where strict control over the name-space is
            hard to achieve, the 'tag' URI scheme
            <xref target="RFC4151" format="default"/>
            may be used.
          </t>
        </section>
      </section>
      <section anchor="cotx.urn" numbered="true" toc="default">
        <name>URN Identifiers</name>
        <t>
          ISO currently use URN <xref target="RFC8141" format="default"/>
          <xref target="RFC5141" format="default"/> based type identifiers like
          "urn:iso:std:iso:20022:tech:xsd:pain.001.001.10" for data definitions
          using XML schema <xref target="XSD" format="default"/>.
          This method could be applied to CBOR and CDDL
          <xref target="RFC8610" format="default"/> as well.
        </t>
      </section>
      
      <section anchor="cotx.acknowledgements" numbered="false" toc="default">
        <name>Acknowledgements</name>
        <t>
          People who have contributed with
          valuable feedback to this specification include
          <contact fullname="Christian Amsüss"/>,
          <contact fullname="Carsten Bormann"/>, and
          <contact fullname="Joe Hildebrand"/>.
        </t>
      </section>

      <section anchor="cotx.document.history" numbered="false" toc="default">
        <name>Document History</name>
        <t>
            [[ This section to be removed by the RFC Editor before publication as
            an RFC ]]
        </t>
        <t>Version 00:</t>
        <ul spacing="normal">
          <li>
              Initial publication.
          </li>
        </ul>
        <t>Version 01:</t>
        <ul spacing="normal">
          <li>
            IANA reference update.
          </li>
        </ul>
        <t>Version 02:</t>
        <ul spacing="normal">
          <li>
            Made type identifier a CBOR text string.
          </li>
          <li>
            Wordsmithing.
          </li>
        </ul>
        <t>Version 03:</t>
        <ul spacing="normal">
          <li>
            Cleaner abstract and intro.
          </li>
        </ul>
        <t>Version 04:</t>
        <ul spacing="normal">
          <li>
            Type identifier throughout the spec.
          </li>
        </ul>
      </section>
    </back>
</rfc>
