<?xml version="1.0" encoding="UTF-8"?>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" category="std" consensus="true" docName="draft-bsipos-dtn-bpsec-cose-07" ipr="trust200902" submissionType="IETF" tocInclude="true" version="3" xml:lang="en">
  <front>
    <title abbrev="DTN BPSec COSE">
      DTN Bundle Protocol Security (BPSec) COSE Context
    </title>
    <seriesInfo name="Internet-Draft" value="draft-bsipos-dtn-bpsec-cose-07"/>
    <author fullname="Brian Sipos" initials="B." surname="Sipos">
      <organization abbrev="JHU/APL">The Johns Hopkins University Applied Physics Laboratory</organization>
      <address>
        <postal>
          <street>11100 Johns Hopkins Rd.</street>
          <city>Laurel</city>
          <region>MD</region>
          <code>20723</code>
          <country>United States of America</country>
        </postal>
        <email>brian.sipos+ietf@gmail.com</email>
      </address>
    </author>
    <date/>
    <area>Transport</area>
    <workgroup>Delay-Tolerant Networking</workgroup>
    <keyword>COSE</keyword>
    <keyword>DTN</keyword>
    <keyword>PKIX</keyword>
    <abstract>
      <t>
This document defines a security context suitable for using CBOR Object Signing and Encryption (COSE) algorithms within Bundle Protocol Security (BPSec) integrity and confidentiality blocks.
A profile for COSE, focused on asymmetric-keyed algorithms, and for PKIX certificates are also defined for BPSec interoperation.
      </t>
    </abstract>
  </front>
  <middle>
    <section anchor="sec-intro">
      <name>Introduction</name>
      <t>
The Bundle Protocol Security (BPSec) Specification <xref target="RFC9172"/> defines structure and encoding for Block Integrity Block (BIB) and Block Confidentiality Block (BCB) types but does not specify any security contexts to be used by either of the security block types.
The CBOR Object Signing and Encryption (COSE) specification <xref target="RFC8152"/> defines a structure, encoding, and algorithms to use for cryptographic signing and encryption.
      </t>
      <t>
This document describes how to use the algorithms and encodings of COSE within BPSec blocks to apply those algorithms to Bundle security in <xref target="sec-bpsec-context"/>.
A bare minimum of interoperability algorithms and algorithm parameters is specified by this document in <xref target="sec-COSE-profile"/>.
The focus of the recommended algorithms is to allow BPSec to be used in a Public Key Infrastructure (PKI) as described in <xref target="sec-pkix-env"/>.
      </t>
      <t>
Examples of specific uses are provided in <xref target="sec-examples"/> to aid in implementation support of the interoperability algorithms.
      </t>
      <section>
        <name>Scope</name>
        <t>
This document describes a profile of COSE which is tailored for use in BPSec and a method of including full COSE messages within BPSec security blocks.
This document does not address:
        </t>
        <ul spacing="normal">
          <li>
Policies or mechanisms for issuing Public Key Infrastructure Using X.509 (PKIX) certificates; provisioning, deploying, or accessing certificates and private keys; deploying or accessing certificate revocation lists (CRLs); or configuring security parameters on an individual entity or across a network.
          </li>
          <li>
Uses of COSE beyond the profile defined in this document.
          </li>
          <li>
How those COSE algorithms are intended to be used within a larger security context.
Many header parameters used by COSE (e.g., key identifiers) depend on the network environment and security policy related to that environment.
          </li>
        </ul>
      </section>
      <section anchor="sec-pkix-env">
        <name>PKIX Environments and CA Policy</name>
        <t>
This specification gives requirements about how to use PKIX certificates issued by a Certificate Authority (CA), but does not define any mechanisms for how those certificates come to be.
        </t>
        <t>
To support the PKIX uses defined in this document, the CA(s) issuing certificates for BP nodes are aware of the end use of the certificate, have a mechanism for verifying ownership of a Node ID, and are issuing certificates directly for that Node ID.
BPSec security acceptors authenticate the Node ID of security sources when verifying integrity (see <xref target="sec-context-auth"/>) using a public key provided by a PKIX certificate (see <xref target="sec-context-auth"/>) following the certificate profile of <xref target="sec-pkix-profile"/>.
        </t>
      </section>
      <section>
        <name>Use of CDDL</name>
        <t>
This document defines CBOR structure using the Concise Data Definition Language (CDDL) of <xref target="RFC8610"/>.
The entire CDDL structure can be extracted from the XML version of this document using the XPath expression:
        </t>
        <sourcecode>'//sourcecode[@type="cddl"]'</sourcecode>
        <t>
The following initial fragment defines the top-level symbols of this document's CDDL, including the ASB data structure with its parameter/result sockets.
        </t>
        <sourcecode type="cddl">
start = bpsec-cose-asb / AAD-list /
  primary-block / extension-block /
  MAC_structure / Sig_structure / Enc_structure / COSE_KeySet
        </sourcecode>
      </section>
      <section>
        <name>Requirements Language</name>
        <t>
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" 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="sec-bpsec-context">
      <name>BPSec Security Context</name>
      <t>
This document specifies a single security context for use in both BPSec integrity and confidentiality blocks.
This is done to save code points allocated to this specification and to simplify the encoding of COSE-in-BPSec; the BPSec block type uniquely defines the acceptable parameters and COSE messages which can be present.
      </t>
      <t>
The COSE security context SHALL have the Security Context ID specified in <xref target="sec-iana-bpsec-ctx"/>.
      </t>
      <t>
Both types of security block can use the same parameters, defined in <xref target="sec-ASB-parameters"/>, to carry public key-related information and each type of security block allows specific COSE message results, defined in <xref target="sec-ASB-results"/>.
      </t>
      <figure anchor="fig-context-CDDL">
        <name>COSE context declaration CDDL</name>
        <sourcecode type="cddl">
; Specialize the ASB for this context
bpsec-cose-asb = bpsec-context-use&lt;
  -1, ; Context ID TBD-COSE
  $bpsec-cose-param,
  $bpsec-cose-result
&gt;
$ext-data-asb /= bpsec-cose-asb
        </sourcecode>
      </figure>
      <section>
        <name>Security Scope</name>
        <t>
The scope here refers to the set of information used by the security context to cryptographically bind with the plaintext data being integrity-protected or confidentiality-protected.
This information is generically referred to as additional authenticated data (AAD), which is also the term used by COSE to describe the same data.
        </t>
        <t>
The sources for AAD within the COSE context are described below, controlled by the AAD Scope Flags parameter of <xref target="sec-ASB-param-AAD-scope"/>, and implemented as defined in <xref target="sec-context-AAD"/>.
The purpose of this parameter is identical to the AAD Scope parameter and Integrity Scope parameter of <xref target="RFC9173"/>.
        </t>
        <dl>
          <dt>Bundle Primary Block:</dt>
          <dd>
The primary block identifies a bundle and, once created, the contents of this block are immutable.
Changes to the primary block associated with the security target indicate that the target is no longer in its original bundle.
Including the primary block as part of AAD ensures that security target appears in the same bundle that the security source intended.
          </dd>
          <dt>Target Block Metadata:</dt>
          <dd>
When the target block is a canonical block (i.e., not the primary block) it contains its block-type-specific data (BTSD), which is the subject of the security operation, but also metadata identifying the block.
This metadata explicitly excludes the CRC type and value fields because the CRC is derived from the BTSD.
Including this metadata as part of AAD ensures that the target data appears in the same block that the security source intended.
          </dd>
          <dt>Security Block Metadata:</dt>
          <dd>
The BPSec block containing the security result for which the AAD is assembled also has metadata identifying the block.
This metadata explicitly excludes the CRC type and value fields because the security block does not have a full BTSD available at the time the AAD is needed.
Including this metadata as part of AAD ensures that the security result appears in the same block that the security source intended.
          </dd>
        </dl>
      </section>
      <section anchor="sec-ASB-parameters">
        <name>Parameters</name>
        <t>
Each COSE context parameter value SHALL consist of the COSE structure indicated by <xref target="tab-ASB-parameters"/> in its decoded (CBOR item) form.
Each security block MAY contain any number of each parameter type.
When a parameter is not present, the security acceptor SHALL use the Default Value of <xref target="tab-ASB-parameters"/>.
        </t>
        <table anchor="tab-ASB-parameters">
          <name>COSE Context Parameters</name>
          <thead>
            <tr>
              <th>Parameter ID</th>
              <th>Parameter Structure</th>
              <th>Reference</th>
              <th>Default Value</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>1</td>
              <td>COSE_Key</td>
              <td>
                <xref target="RFC8152"/>
              </td>
              <td>none</td>
            </tr>
            <tr>
              <td>2</td>
              <td>COSE_KeySet</td>
              <td>
                <xref target="RFC8152"/>
              </td>
              <td>none</td>
            </tr>
            <tr>
              <td>3</td>
              <td><tt>additional-protected</tt></td>
              <td><xref target="sec-ASB-param-additional"/> of this document</td>
              <td>
                <t><tt>''</tt> (empty byte string)</t>
              </td>
            </tr>
            <tr>
              <td>4</td>
              <td><tt>additional-unprotected</tt></td>
              <td><xref target="sec-ASB-param-additional"/> of this document</td>
              <td>
                <t><tt>{}</tt> (empty map)</t>
              </td>
            </tr>
            <tr>
              <td>5</td>
              <td><tt>AAD-scope</tt></td>
              <td><xref target="sec-ASB-param-AAD-scope"/> of this document</td>
              <td>
                <t><tt>0b111</tt> (all AAD contexts)</t>
              </td>
            </tr>
          </tbody>
        </table>
        <section anchor="sec-ASB-param-keys">
          <name>Raw Public Key Containers</name>
          <t>
Implementations capable of handling asymmetric-keyed algorithms SHOULD support raw public key handling in COSE_Key and COSE_KeySet parameters.
          </t>
          <t>
No more than one total COSE_Key or COSE_KeySet parameter SHALL be present in a single security block.
Security acceptors are sill required to aggregate multiple parameters, if present, in <xref target="sec-asym-keys"/>.
          </t>
          <t>
Key container parameters SHALL NOT contain any private key material.
The security parameters are all stored in the bundle as plaintext and are visible to any bundle handlers.
          </t>
          <figure anchor="fig-param-keys-cddl">
            <name>Key Containers CDDL</name>
            <sourcecode type="cddl">
$bpsec-cose-param /= [1, COSE_Key]
$bpsec-cose-param /= [2, COSE_KeySet]
            </sourcecode>
          </figure>
        </section>
        <section anchor="sec-ASB-param-additional">
          <name>Additional Header Maps</name>
          <t>
The two parameters Additional Protected and Additional Unprotected allow de-duplicating header items which are common to all COSE results.
Both additional header values contain a CBOR map which is to be merged with each of the result's unprotected headers.
Although the additional header items are all treated as unprotected from the perspective of the COSE message, the additional protected map is included within the <tt>external_aad</tt> (see <xref target="sec-context-AAD"/>).
The expected use of additional header map is to contain a certificate (chain) or identifier (see <xref target="sec-asym-keys"/>) which applies to all results in the same security block.
          </t>
          <t>
Following the same pattern as COSE, when both additional header maps are present in a single security block they SHALL not contain any duplicated labels.
Security acceptors SHALL treat a pair of additional header maps containing duplicated labels as invalid.
          </t>
          <t>
No more than one of each Additional Protected and Additional Unprotected parameter SHALL be present in a single security block.
Security acceptors SHALL treat a security block with multiple instances of either additional header type as invalid.
There is no well-defined behavior for a security acceptor to handle multiple Additional Protected parameters.
          </t>
          <t>
Security sources SHOULD NOT include an additional header parameter which represents an empty map.
Security acceptors SHALL handle empty header map parameters, specifically the Additional Protected parameter because it is part of the <tt>external_aad</tt>.
          </t>
          <t>
Security acceptors SHALL treat the aggregate of both additional header maps as being present in the <tt>unprotected</tt> header map of the highest-layers of the COSE message of each result.
For single-layer messages (i.e., COSE_Encrypt0, COSE_MAC0, and COSE_Sign1) the additional headers apply to the message itself (layer 1) and for other messages the additional headers apply to the final recipients.
If the same header label is present in a additional header map and a COSE layer's headers the item in the result header SHALL take precedence (i.e., the additional header items are added only if they are not already present in a layer's header).
          </t>
          <t>
Additional header maps SHALL NOT contain any private key material.
The security parameters are all stored in the bundle as plaintext and are visible to any bundle handlers.
          </t>
          <figure anchor="fig-additional-cddl">
            <name>Additional Headers CDDL</name>
            <sourcecode type="cddl">
$bpsec-cose-param /= [3, additional-protected]
additional-protected = empty_or_serialized_map

$bpsec-cose-param /= [4, additional-unprotected]
additional-unprotected = header_map
            </sourcecode>
          </figure>
        </section>
        <section anchor="sec-ASB-param-AAD-scope">
          <name>AAD Scope</name>
          <t>
The AAD Scope parameter controls what data is included in the AAD for both integrity and confidentiality operations.
The AAD Scope parameter SHALL be encoded as a uint value with bit flags defined in <xref target="tab-AAD-scope-flags"/>.
All reserved bits SHALL be set to zero (which will be elided by CBOR encoding) by security sources.
All reserved bits SHALL be ignored by security acceptors.
The default value for this parameter has all flags set, meaning the AAD includes all available context.
The flags of this parameter value are identical to the AAD Scope flags of <xref section="4.3.4" target="RFC9173"/> and Integrity Scope flags of <xref section="3.3.3" target="RFC9173"/>.
          </t>
          <t>
A CDDL representation of this definition is included in <xref target="fig-AAD-scope-cddl"/> for reference.
          </t>
          <table anchor="tab-AAD-scope-flags">
            <name>AAD Scope Flags</name>
            <thead>
              <tr>
                <th>Name</th>
                <th>Code</th>
                <th>Description</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>has-primary-ctx</td>
                <td><tt>0b001</tt></td>
                <td>If bit is set, indicates that the primary block is included in AAD scope.</td>
              </tr>
              <tr>
                <td>has-target-ctx</td>
                <td><tt>0b010</tt></td>
                <td>If bit is set, indicates that the target block metadata is included in AAD scope.</td>
              </tr>
              <tr>
                <td>has-security-ctx</td>
                <td><tt>0b100</tt></td>
                <td>If bit is set, indicates that the security block metadata is included in AAD scope.</td>
              </tr>
              <tr>
                <td>Reserved</td>
                <td>others</td>
                <td/>
              </tr>
            </tbody>
          </table>
          <figure anchor="fig-AAD-scope-cddl">
            <name>AAD Scope CDDL</name>
            <sourcecode type="cddl">
$bpsec-cose-param /= [5, AAD-scope]
AAD-scope = uint .bits AAD-scope-flags
AAD-scope-flags = &amp;(
    has-primary-ctx: 0,
    has-target-ctx: 1,
    has-security-ctx: 2,
)
            </sourcecode>
          </figure>
        </section>
      </section>
      <section anchor="sec-ASB-results">
        <name>Results</name>
        <t>
Although each COSE context result is a COSE message, the types of message allowed depend upon the security block type in which the result is present: only MAC or signature messages are allowed in a BIB and only encryption messages are allowed in a BCB.
        </t>
        <t>
The code points for Result ID values are identical to the  existing COSE message-marking tags in <xref section="2" target="RFC8152"/>.
This avoids the need for value-mapping between code points of the two registries.
        </t>
        <t>
When embedding COSE messages, the message CBOR structure SHALL be encoded as a byte string used as the result value.
This allows a security acceptor to skip over unwanted results without needing to decode the result structure.
When embedding COSE messages, the CBOR-tagged form SHALL NOT be used.
The Result ID values already provide the same information as the COSE tags (using the same code points).
        </t>
        <t>
These generic requirements are formalized in the CDDL fragment of <xref target="fig-results-CDDL"/>.
        </t>
        <figure anchor="fig-results-CDDL">
          <name>COSE context results CDDL</name>
          <sourcecode type="cddl">
$bpsec-cose-result /= [16, bstr .cbor COSE_Encrypt0]
$bpsec-cose-result /= [17, bstr .cbor COSE_Mac0]
$bpsec-cose-result /= [18, bstr .cbor COSE_Sign1]
$bpsec-cose-result /= [96, bstr .cbor COSE_Encrypt]
$bpsec-cose-result /= [97, bstr .cbor COSE_Mac]
$bpsec-cose-result /= [98, bstr .cbor COSE_Sign]
          </sourcecode>
        </figure>
        <section anchor="sec-ASB-results-BIB">
          <name>Integrity Messages</name>
          <t>
When used within a Block Integrity Block, the COSE context SHALL allow only the Result IDs from <xref target="tab-BIB-results"/>.
Each integrity result value SHALL consist of the COSE message indicated by <xref target="tab-BIB-results"/> in its non-tagged encoded form.
        </t>
          <table anchor="tab-BIB-results">
            <name>COSE Integrity Results</name>
            <thead>
              <tr>
                <th>Result ID</th>
                <th>Result Structure</th>
                <th>Reference</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>97</td>
                <td>encoded COSE_Mac</td>
                <td>
                  <xref target="RFC8152"/>
                </td>
              </tr>
              <tr>
                <td>17</td>
                <td>encoded COSE_Mac0</td>
                <td>
                  <xref target="RFC8152"/>
                </td>
              </tr>
              <tr>
                <td>98</td>
                <td>encoded COSE_Sign</td>
                <td>
                  <xref target="RFC8152"/>
                </td>
              </tr>
              <tr>
                <td>18</td>
                <td>encoded COSE_Sign1</td>
                <td>
                  <xref target="RFC8152"/>
                </td>
              </tr>
            </tbody>
          </table>
          <t>
Each integrity result SHALL use the "detached" payload form with <tt>null</tt> payload value.
The integrity result for COSE_Mac and COSE_Mac0 messages are computed by the procedure in <xref section="6.3" target="RFC8152"/>.
The integrity result for COSE_Sign and COSE_Sign1 messages are computed by the procedure in <xref section="4.4" target="RFC8152"/>.
          </t>
          <t>
The COSE "protected attributes from the application" used for a signature or MAC result SHALL be the encoded data defined in <xref target="sec-context-AAD"/>.
The COSE payload used for a signature or MAC result SHALL be either the BTSD of the target, if the target is not the primary block, or an empty byte string if the target is the primary block.
          </t>
        </section>
        <section anchor="sec-ASB-results-BCB">
          <name>Confidentiality Messages</name>
          <t>
When used within a Block Confidentiality Block, COSE context SHALL allow only the Result IDs from <xref target="tab-BCB-results"/>.
Each confidentiality result value SHALL consist of the COSE message indicated by <xref target="tab-BCB-results"/> in its non-tagged encoded form.
          </t>
          <table anchor="tab-BCB-results">
            <name>COSE Confidentiality Results</name>
            <thead>
              <tr>
                <th>Result ID</th>
                <th>Result Structure</th>
                <th>Reference</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>96</td>
                <td>encoded COSE_Encrypt</td>
                <td>
                  <xref target="RFC8152"/>
                </td>
              </tr>
              <tr>
                <td>16</td>
                <td>encoded COSE_Encrypt0</td>
                <td>
                  <xref target="RFC8152"/>
                </td>
              </tr>
            </tbody>
          </table>
          <t>
Only algorithms which support Authenticated Encryption with Authenticated Data (AEAD) SHALL be usable in the first (content) layer of a confidentiality result.
Because COSE encryption with AEAD appends the authentication tag with the ciphertext, the size of the BTSD will grow after an encryption operation.
Security acceptors MUST NOT assume that the size of the plaintext is the same as the size of the ciphertext.
          </t>
          <t>
Each confidentiality result SHALL use the "detached" payload form with <tt>null</tt> payload value.
The confidentiality result for COSE_Encrypt and COSE_Encrypt0 messages are computed by the procedure in <xref section="5.3" target="RFC8152"/>.
          </t>
          <t>
The COSE "protected attributes from the application" used for an encryption result SHALL be the encoded data defined in <xref target="sec-context-AAD"/>.
The COSE payload used for an encryption result SHALL be the BTSD of the target.
Because confidentiality of the primary block is disallowed by BPSec, there is no logic here for handling a BCB with a target on the primary block.
          </t>
        </section>
      </section>
      <section>
        <name>Key Considerations</name>
        <t>
This specification does not impose any additional key requirements beyond those already specified for each COSE algorithm required in <xref target="sec-COSE-profile"/>.
        </t>
      </section>
      <section>
        <name>Canonicalization Algorithms</name>
        <t>
Generating or processing COSE messages for the COSE context follows the profile defined in <xref target="sec-COSE-profile"/> with the "protected attributes from the application" (i.e., the <tt>external_aad</tt> item) generated as defined in <xref target="sec-context-AAD"/>.
        </t>
        <section anchor="sec-context-AAD">
          <name>Generating AAD</name>
          <t>
The encoding of this AAD is identical to the AAD of <xref section="4.7.2" target="RFC9173"/> and the front items of IPPT of <xref section="3.7" target="RFC9173"/>.
          </t>
          <t>
The AAD used for both integrity and confidentiality messages SHALL be the deterministically encoded form of a CBOR sequence containing the following:
          </t>
          <ol>
            <li>
The first item SHALL be the AAD Scope value itself, which is a <tt>uint</tt>.
            </li>
            <li>
The next item SHALL be the CBOR array (unencoded) form of the primary block of the bundle if the AAD Scope has the has-primary-ctx flag set.
            </li>
            <li>
The next items SHALL be the first three fields of the target block (i.e., the block type code, block number, and control flags) if the AAD Scope has the has-target-ctx flag set.
            </li>
            <li>
The next items SHALL be the first three fields of the security block containing the result (i.e., the block type code, block number, and control flags) if the AAD Scope has the has-security-ctx flag set.
            </li>
            <li>
The last item SHALL be the Additional Protected header map, which is a <tt>bstr</tt>, and has a default value of the empty <tt>bstr</tt>.
            </li>
          </ol>
          <t>
A CDDL representation of this data is shown below in <xref target="fig-AAD-CDDL"/>.
          </t>
          <figure anchor="fig-AAD-CDDL">
            <name>COSE context AAD CDDL</name>
            <sourcecode type="cddl">
; Encoded as a CBOR sequence
AAD-list = [
    AAD-structure,
    ; copy of additional-protected (or default empty bstr)
    additional-protected
]

; Identical to the definition of RFC 9173
AAD-structure = (
    AAD-scope,
    ? primary-block,  ; present if has-primary-ctx flag set
    ? block-metadata, ; present if has-target-ctx flag set
    ? block-metadata, ; present if has-security-ctx flag set
)
; Selected fields of a canonical block
block-metadata = (
    block-type-code: uint,
    block-number: uint,
    block-control-flags,
)
            </sourcecode>
          </figure>
        </section>
        <section>
          <name>Payload Data</name>
          <t>
When correlating between BPSec target BTSD and COSE plaintext or payload, any byte string SHALL be handled in its decoded (CBOR item) form.
This means any CBOR header or tag in a source encoding are ignored for the purposes of security processing.
This also means that if the source byte string was encoded in a non-conforming way, for example in indefinite-length form or with a non-minimum-size length, the security processing always treats it in a deterministically encoded CBOR form.
        </t>
        </section>
      </section>
      <section>
        <name>Processing</name>
        <t>
This section describes block-level requirements for handling COSE security data.
        </t>
        <t>
All security results generated for BIB or BCB blocks SHALL conform to the COSE profile of <xref target="sec-COSE-profile"/> with header augmentation as defined in <xref target="sec-ASB-param-additional"/>.
        </t>
        <section anchor="sec-context-auth">
          <name>Node Authentication</name>
          <t>
This section explains how the certificate profile of <xref target="sec-pkix-profile"/> is used by a security acceptor to both validate an end-entity certificate and to use that certificate to authenticate the security source for an integrity result.
For a confidentiality result, some of the requirements in this section are implicit in an implementation using a private key associated with a certificate used by a result recipient.
It is an implementation matter to ensure that a BP agent is configured to generate or receive results associated with valid certificates.
          </t>
          <t>
A security source MAY prohibit generating a result (either integrity or confidentiality) for an end-entity certificate which is not considered valid according to <xref target="sec-context-auth-valid-cert"/>.
Generating a result which is likely to be discarded is wasteful of bundle size and transport resources.
          </t>
          <section>
            <name>Certificate Identification</name>
            <t>
Because of the standard policy of using separate certificates for transport, signing, and encryption (see <xref target="sec-pkix-multiple-certs"/>) a single Node ID is likely to be associated with multiple certificates, and any or all of those certificates MAY be present within an "x5bag" in an Additional Protected parameter (see <xref target="sec-ASB-param-additional"/>).
When present, a security acceptor SHALL use an "x5chain" or "x5t" to identify an end-entity certificate to use for result processing.
Security acceptors SHALL NOT assume that a validated certificate containing a NODE-ID matching a security source is enough to associate a certificate with a COSE message or recipient (see <xref target="sec-asym-keys"/>).
            </t>
          </section>
          <section anchor="sec-context-auth-valid-cert">
            <name>Certificate Validation</name>
            <t>
For each end-entity certificate contained in or identified by by a COSE result, the security acceptor SHALL perform the certification path validation of <xref section="6" target="RFC5280"/> up to one of the acceptor's trusted CA certificates.
When evaluating a certificate Validity period, the security acceptor SHALL use the bundle Creation Timestamp time (if not unknown) as the reference instead of the current time.
If enabled by local policy, the entity SHALL perform an OCSP check of each certificate providing OCSP authority information in accordance with <xref target="RFC6960"/>.
If certificate validation fails or if security policy disallows a certificate for any reason, the acceptor SHALL treat the associated security result as failed.
Leaving out part of the certification chain can cause the entity to fail to validate a certificate if the left-out certificates are unknown to the entity (see <xref target="sec-threat-untrust-cert"/>).
            </t>
            <t>
For each end-entity certificate contained in or identified by a COSE context result, the security acceptor SHALL apply security policy to the Key Usage extension (if present) and Extended Key Usage extension (if present) in accordance with <xref section="4.2.1.12" target="RFC5280"/> and the profile in <xref target="sec-pkix-profile"/>.
            </t>
          </section>
          <section anchor="sec-context-auth-valid-nodeid">
            <name>Node ID Authentication</name>
            <t>
If required by security policy, for each end-entity certificate referenced by a COSE context integrity result the security acceptor SHALL validate the certificate NODE-ID in accordance with <xref section="6" target="RFC6125"/> using the NODE-ID reference identifier from the Security Source of the containing security block.
If the NODE-ID validation result is Failure or if the result is Absent and security policy requires an authenticated Node ID, the security acceptor SHALL treat the result as failed.
            </t>
          </section>
        </section>
        <section anchor="sec-context-auth-policy-rec">
          <name>Policy Recommendations</name>
          <t>
A RECOMMENDED security policy is to enable the use of OCSP checking when internet connectivity is present.
A RECOMMENDED security policy is that if an Extended Key Usage is present that it needs to contain <tt>id-kp-bundleSecurity</tt> of <xref target="IANA-SMI"/> to be usable as an end-entity certificate for COSE security results.
A RECOMMENDED security policy is to require a validated Node ID (of <xref target="sec-context-auth-valid-nodeid"/>) and to ignore any other identifiers in the end-entity certificate.
          </t>
          <t>
This policy relies on and informs the certificate requirements in <xref target="sec-asym-keys-policy-rec"/> and <xref target="sec-pkix-profile"/>.
This policy assumes that a DTN-aware CA (see <xref target="sec-pkix-env"/>) will only issue a certificate for a Node ID when it has verified that the private key holder actually controls the DTN node; this is needed to avoid the threat identified in <xref target="sec-threat-node-impersonation"/>.
This policy requires that a certificate contain a NODE-ID and allows the certificate to also contain network-level identifiers.
A tailored policy on a more controlled network could relax the requirement on Node ID validation and/or Extended Key Usage presence.
          </t>
        </section>
      </section>
    </section>
    <section anchor="sec-COSE-profile">
      <name>COSE Profile</name>
      <t>
This section contains requirements which apply to the use of COSE within the BPSec security context defined in this document.
Other variations of COSE within BPSec can be used but are not expected to be interoperable or usable by all security acceptors.
      </t>
      <section anchor="sec-COSE-messages">
        <name>COSE Messages</name>
        <t>
When generating a BPSec result, security sources SHALL use only COSE labels with a uint value.
When processing a BPSec result, security acceptors MAY handle COSE labels with with a tstr value.
        </t>
        <t>
When used in a BPSec result, each COSE message SHALL contain an explicit algorithm identifier in the lower (content) layers.
When available and not implied by the bundle source, a COSE message SHALL contain a key identifier in the highest (recipient) layer.
See <xref target="sec-asym-keys"/> for specifics about asymmetric key identifiers.
When a key identifier is not available, BPSec acceptors SHALL use the Security Source (if available) and the Bundle Source to imply which keys can be used for security operations.
Using implied keys has an interoperability risk, see <xref target="sec-threat-unident-key"/> for details.
A BPSec security operation always occurs within the context of the immutable primary block with its parameters (specifically the Source Node ID) and the security block with its optional Security Source.
        </t>
        <t>
The algorithms required by this profile focuses on networks using shared symmetric-keys, with recommended algorithms for Elliptic Curve (EC) keypairs and RSA keypairs.
The focus of this profile is to enable interoperation between security sources and acceptors on an open network, where more explicit COSE parameters make it easier for BPSec acceptors to avoid assumptions and avoid out-of-band parameters.
The requirements of this profile still allow the use of potentially not-easily-interoperable algorithms and message/recipient configurations for use by private networks, where message size is more important than explicit COSE parameters.
        </t>
      </section>
      <section anchor="sec-interop-alg">
        <name>Interoperability Algorithms</name>
        <t>
The set of integrity algorithms needed for interoperability is listed here.
The full set of COSE algorithms available is managed at <xref target="IANA-COSE"/>.
        </t>
        <t>
Implementations conforming to this specification SHALL support the symmetric keyed and key-encryption algorithms of <xref target="tab-interop"/>.
Implementations capable of doing so SHOULD support the asymmetric keyed and key-encryption algorithms of <xref target="tab-interop"/>.
        </t>
        <aside>
          <t>
The layer-1 required list is identical to the <xref target="RFC9173"/> context list.
          </t>
        </aside>
        <table anchor="tab-interop">
          <name>Interoperability Algorithms</name>
          <thead>
            <tr>
              <th>BPSec Block</th>
              <th>COSE Layer</th>
              <th>Name</th>
              <th>Code</th>
              <th>Implementation Requirements</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>Integrity</td>
              <td>1</td>
              <td>HMAC 256/256</td>
              <td>5</td>
              <td>Required</td>
            </tr>
            <tr>
              <td>Integrity</td>
              <td>1</td>
              <td>ES256</td>
              <td>-7</td>
              <td>Recommended</td>
            </tr>
            <tr>
              <td>Integrity</td>
              <td>1</td>
              <td>EdDSA</td>
              <td>-8</td>
              <td>Recommended</td>
            </tr>
            <tr>
              <td>Integrity</td>
              <td>1</td>
              <td>PS256</td>
              <td>-37</td>
              <td>Recommended</td>
            </tr>
            <tr>
              <td>Confidentiality</td>
              <td>1</td>
              <td>A256GCM</td>
              <td>3</td>
              <td>Required</td>
            </tr>
            <tr>
              <td>Confidentiality</td>
              <td>2</td>
              <td>A256KW</td>
              <td>-5</td>
              <td>Required</td>
            </tr>
            <tr>
              <td>Confidentiality</td>
              <td>2</td>
              <td>ECDH-ES + A256KW</td>
              <td>-31</td>
              <td>Recommended</td>
            </tr>
            <tr>
              <td>Confidentiality</td>
              <td>2</td>
              <td>ECDH-SS + A256KW</td>
              <td>-34</td>
              <td>Recommended</td>
            </tr>
            <tr>
              <td>Confidentiality</td>
              <td>2</td>
              <td>RSAES-OAEP w/ SHA-256</td>
              <td>-41</td>
              <td>Recommended</td>
            </tr>
          </tbody>
        </table>
        <t>
The following are recommended key and recipient uses within COSE/BPSec:
        </t>
        <dl newline="false" spacing="normal">
          <dt>Symmetric Key Integrity:</dt>
          <dd>
When generating a BIB result from a symmetric key, implementations SHALL use a COSE_Mac0 using the private key directly.
When a COSE_Mac0 is used with a direct key, the headers SHALL include a key identifier ("kid" header).
          </dd>
          <dt>EC Keypair Integrity:</dt>
          <dd>
When generating a BIB result from an EC keypair, implementations SHALL use a COSE_Sign1 using the private key directly.
When a COSE_Sign1 is used with an EC keypair, the headers SHALL include a public key identifier (see <xref target="sec-asym-keys"/>).
          </dd>
          <dt>RSA Keypair Integrity:</dt>
          <dd>
When generating a BIB result from an RSA keypair, implementations SHALL use a COSE_Sign1 using the private key directly.
When a COSE_Sign1 is used with an RSA keypair, the headers SHALL include a public key identifier (see <xref target="sec-asym-keys"/>).
When a COSE signature is generated with an RSA keypair, the signature uses a PSS salt in accordance with <xref section="2" target="RFC8230"/>.
          </dd>
          <dt>Symmetric Key Confidentiality:</dt>
          <dd>
When generating a BCB result from an symmetric key, implementations SHALL use a COSE_Encrypt message with a recipient containing an indirect (wrapped or derived) content encryption key (CEK).
When generating a BCB result from a symmetric key, implementations SHOULD NOT use COSE_Encrypt0 or COSE_Encrypt with direct CEK.
Doing so risks key overuse and the vulnerabilities associated with large amount of ciphertext from the same key.
When a COSE_Encrypt is used with an overall key-encryption key (KEK), the recipient layer SHALL include a key identifier for the KEK.
            </dd>
          <dt>EC Keypair Confidentiality:</dt>
          <dd>
When generating a BCB result from an EC keypair, implementations SHALL use a COSE_Encrypt message with a recipient containing an indirect (wrapped or derived) CEK.
When a COSE_Encrypt is used with an EC keypair, the recipient layer SHALL include a public key identifier (see <xref target="sec-asym-keys"/>).
When a COSE_Encrypt is used with an EC keypair, the security source SHALL either generate an ephemeral EC keypair or choose a unique PartyU Nonce for each security operation.
When processing a COSE_Encrypt with an EC keypair, the security acceptor SHALL process all KDF and HMAC context data from the recipient headers in accordance with <xref section="11.2" target="RFC8152"/> even though the source is not required to provide any of those parameters.
            </dd>
          <dt>RSA Keypair Confidentiality:</dt>
          <dd>
When generating a BCB result from an RSA keypair, implementations SHALL use a COSE_Encrypt message with a recipient containing a key-wrapped CEK.
When a COSE_Encrypt is used with an RSA keypair, the recipient layer SHALL include a public key identifier (see <xref target="sec-asym-keys"/>).
            </dd>
        </dl>
      </section>
      <section anchor="sec-asym-keys">
        <name>Asymmetric Key Types and Identifiers</name>
        <t>
This section applies when a BIB uses a public key for verification or key-wrap, or when a BCB uses a public key for encryption or key-wrap.
When using asymmetric keyed algorithms, the security source SHALL include a public key container or public key identifier as a recipient header.
The public key identifier SHALL be either a "kid" of <xref target="RFC8152"/>, an "x5t" or "x5chain" of <xref target="I-D.ietf-cose-x509"/>, or an equivalent identifier.
        </t>
        <t>
When a BIB result contains a "kid" identifier, the security source MAY include an appropriate COSE public key "COSE_Key" in a key container security parameter (see <xref target="sec-ASB-param-keys"/>).
When BIB result contains a "x5t" identifier, the security source MAY include an appropriate PKIX certificate container ("x5chain" or "x5bag" of <xref target="I-D.ietf-cose-x509"/>) in a direct COSE header or an additional header security parameter (see <xref target="sec-ASB-param-additional"/>).
When a BIB result contains an "x5chain", the security source SHOULD NOT also include an "x5t" as the first certificate in the chain is implicitly the applicable end-entity certificate.
For a BIB, if all potential security acceptors are known to possess related public key and/or certificate data then the public key or additional header parameters can be omitted.
Risks of not including related data are described in <xref target="sec-threat-unident-key"/> and <xref target="sec-threat-notrust-key"/>.
        </t>
        <t>
When present, public keys and certificates SHOULD be included as additional header parameters rather than within result COSE messages.
This provides size efficiency when multiple security results are present because they will all be from the same security source and likely share the same public key material.
Security acceptors SHALL still process public keys or certificates present in a result message or recipient as applying to that individual COSE level.
        </t>
        <t>
Security acceptors SHALL aggregate all COSE_Key objects from all parameters within a single BIB or BCB, independent of encoded type or order of parameters.
Because each context contains a single set of security parameters which apply to all results in the same context, security acceptors SHALL treat all public keys as being related to the security source itself and potentially applying to every result.
        </t>
        <section anchor="sec-asym-keys-policy-rec">
          <name>Policy Recommendations</name>
          <t>
The RECOMMENDED priority policy for including PKIX material for BIB results is as follows:
          </t>
          <ol>
            <li>When receivers are not known to possess certificate chains, a full chain is included (as an "x5chain").</li>
            <li>When receivers are known to possess root and intermediate CAs, just the end-entity certificate is included (again as an "x5chain").</li>
            <li>When receivers are known to possess associated chains including end-entity certificates, a certificate thumbnail (as an "x5t").</li>
            <li>Some arbitrary identifier is used to correlate to an end-entity certificate (as a "kid").</li>
            <li>The BIB Security Source is used to imply an associated end-entity certificate which identifies that Node ID.</li>
          </ol>
          <t>
When PKIX certificates are used by security acceptors and the end-entity certificate is not explicitly trusted (i.e. pinned), the security acceptor SHALL perform the certification path validation of <xref target="sec-context-auth-valid-cert"/> up to one or more trusted CA certificates.
Leaving out part of the certification chain can cause the security acceptor to fail to validate a BIB if the left-out certificates are unknown to the acceptor (see <xref target="sec-threat-notrust-key"/>).
          </t>
          <t>
Any end-entity certificate associated with a BPSec security source SHALL adhere to the profile of <xref target="sec-pkix-profile"/>.
          </t>
        </section>
      </section>
    </section>
    <section anchor="sec-pkix-profile">
      <name>PKIX Certificate Profile</name>
      <t>
This section contains requirements on certificates used for the COSE context, while <xref target="sec-asym-keys"/> contains requirements for how such certificates are transported or identified.
      </t>
      <t>
All end-entity certificates used for BPSec SHALL conform to <xref target="RFC5280"/>, or any updates or successors to that profile.
      </t>
      <t>
This profile requires Version 3 certificates due to the extensions used by this profile.
Security acceptors SHALL reject as invalid Version 1 and Version 2 end-entity certificates.
      </t>
      <t>
Security acceptors SHALL accept certificates that contain an empty Subject field or contain a Subject without a Common Name.
Identity information in end-entity certificates is contained entirely in the subjectAltName extension as a NODE-ID, as defined in <xref section="4.4.1" target="RFC9174"/>.
      </t>
      <t>
All end-entity and CA certificates used for BPSec SHOULD contain both a Subject Key Identifier extension in accordance with <xref section="4.2.1.2" target="RFC5280"/> and an Authority Key Identifier extension in accordance with <xref section="4.2.1.1" target="RFC5280"/>.
Security acceptors SHOULD NOT rely on either a Subject Key Identifier and an Authority Key Identifier being present in any received certificate.
Including key identifiers simplifies the work of an entity needing to assemble a certification chain.
      </t>
      <t>
A BPSec end-entity certificate SHALL contain a NODE-ID which authenticates the Node ID of the security source (for integrity) or the security acceptor (for confidentiality).
The identifier type NODE-ID is defined in <xref section="4.4.1" target="RFC9174"/>.
      </t>
      <t>
When allowed by CA policy, a BPSec end-entity certificate SHOULD contain a PKIX Extended Key Usage extension in accordance with <xref section="4.2.1.12" target="RFC5280"/>.
When the PKIX Extended Key Usage extension is present, it SHALL contain a key purpose <tt>id-kp-bundleSecurity</tt> of <xref target="IANA-SMI"/>.
The <tt>id-kp-bundleSecurity</tt> purpose MAY be combined with other purposes in the same certificate.
      </t>
      <t>
When allowed by CA policy, a BPSec end-entity certificate SHALL contain a PKIX Key Usage extension in accordance with <xref section="4.2.1.3" target="RFC5280"/>.
The PKIX Key Usage bits which are consistent with COSE security are: digitalSignature, nonRepudiation, keyEncipherment, and keyAgreement.
The specific algorithms used by COSE messages in security results determine which of those key uses are exercised.
See <xref target="sec-pkix-multiple-certs"/> for discussion of key use policies across multiple certificates.
      </t>
      <t>
A BPSec end-entity certificate MAY contain an Online Certificate Status Protocol (OCSP) URI within an Authority Information Access extension in accordance with <xref section="4.2.2.1" target="RFC5280"/>.
Security acceptors are not expected to have continuous internet connectivity sufficient to perform OCSP verification.
      </t>
      <section anchor="sec-pkix-multiple-certs">
        <name>Multiple-Certificate Uses</name>
        <t>
A RECOMMENDED security policy is to limit asymmetric keys (and thus public key certificates) to single uses among the following:
        </t>
        <dl>
          <dt>Bundle transport:</dt>
          <dd>With key uses as defined in the convergence layer specification(s).</dd>
          <dt>Block signing:</dt>
          <dd>With key use digitalSignature and/or nonRepudiation.</dd>
          <dt>Block encryption:</dt>
          <dd>With key use keyEncipherment and/or keyAgreement.</dd>
        </dl>
        <t>
This policy is the same one recommended by <xref section="6" target="RFC8551"/> for email security and by Section 5.2 of <xref target="NIST-SP800-57"/> more generally.
Effectively this means that a BP node uses separate certificates for transport (e.g., as a TCPCL entity), BIB signing (as a security source), and BCB encryption (as a security acceptor).
        </t>
      </section>
    </section>
    <section removeInRFC="true">
      <name>Implementation Status</name>
      <t>
[NOTE to the RFC Editor: please remove this section before publication, as well as the reference to <xref target="RFC7942"/>, <xref target="github-dtn-bpsec-cose"/>, <xref target="github-dtn-demo-agent"/>, and <xref target="github-dtn-wireshark"/>.]
      </t>
      <t>
This section records the status of known implementations of the
protocol defined by this specification at the time of posting of
this Internet-Draft, and is based on a proposal described in
<xref target="RFC7942"/>.
The description of implementations in this section is
intended to assist the IETF in its decision processes in progressing
drafts to RFCs. Please note that the listing of any individual
implementation here does not imply endorsement by the IETF.
Furthermore, no effort has been spent to verify the information
presented here that was supplied by IETF contributors. This is not
intended as, and must not be construed to be, a catalog of available
implementations or their features. Readers are advised to note that
other implementations can exist.
      </t>
      <t>
An example implementation of COSE over Blocks has been created as a GitHub project <xref target="github-dtn-bpsec-cose"/> and is intended to use as a proof-of-concept and as a possible source of interoperability testing.
This example implementation only handles CBOR encoding/decoding and cryptographic functions, it does not construct actual BIB or BCB and does not integrate with a BP Agent.
      </t>
    </section>
    <section anchor="sec-security">
      <name>Security Considerations</name>
      <t>
This section separates security considerations into threat categories based on guidance of BCP 72 <xref target="RFC3552"/>.
      </t>
      <t>
All of the security considerations of the underlying BPSec <xref target="RFC9172"/> apply to these new security contexts.
      </t>
      <section>
        <name>Threat: BPSec Block Replay</name>
        <t>
The bundle's primary block contains fields which uniquely identify a bundle: the Source Node ID, Creation Timestamp, and fragment parameters (see <xref section="4.3.1" target="RFC9171"/>).
These same fields are used to correlate Administrative Records with the bundles for which the records were generated.
Including the primary block in the AAD Scope for integrity and confidentiality (see <xref target="sec-ASB-param-AAD-scope"/>) binds the verification of the secured block to its parent bundle and disallows replay of any block with its BIB or BCB.
        </t>
        <t>
This profile of COSE limits the encryption algorithms to only AEAD in order to include the context of the encrypted data as AAD.
If an agent mistakenly allows the use of non-AEAD encryption when decrypting and verifying a BCB, the possibility of block replay attack is present.
        </t>
      </section>
      <section anchor="sec-threat-untrust-cert">
        <name>Threat: Untrusted End-Entity Certificate</name>
        <t>
The profile in <xref target="sec-context-auth"/> uses end-entity certificates chained up to a trusted root CA.
A security source can include a certificate set which does not contain the full chain, possibly excluding intermediate or root CAs.
In an environment where security acceptors are known to already contain needed root and intermediate CAs there is no need to include those CAs, but this has a risk of an acceptor not actually having one of the needed CAs.
        </t>
      </section>
      <section>
        <name>Threat: Certificate Validation Vulnerabilities</name>
        <t>
Even when a security acceptor is operating properly an attacker can attempt to exploit vulnerabilities within certificate check algorithms or configuration to authenticate using an invalid certificate.
An invalid certificate exploit could lead to higher-level security issues and/or denial of service to the Node ID being impersonated.
        </t>
        <t>
There are many reasons, described in <xref target="RFC5280"/> and <xref target="RFC6125"/>, why a certificate can fail to validate, including using the certificate outside of its valid time interval, using purposes for which it was not authorized, or using it after it has been revoked by its CA.
Validating a certificate is a complex task and can require network connectivity outside of the primary BP convergence layer network path(s) if a mechanism such as OCSP <xref target="RFC6960"/> is used by the CA.
The configuration and use of particular certificate validation methods are outside of the scope of this document.
        </t>
      </section>
      <section anchor="sec-threat-node-impersonation">
        <name>Threat: BP Node Impersonation</name>
        <t>
When certificates are referenced by BIB results it is possible that the certificate does not contain a NODE-ID or does contain one but has a mismatch with the actual security source (see <xref target="sec-pkix-env"/>).
Having a CA-validated certificate does not alone guarantee the identity of the security source from which the certificate is provided; additional validation procedures in <xref target="sec-context-auth"/> bind the Node ID based on the contents of the certificate.
        </t>
      </section>
      <section anchor="sec-threat-unident-key">
        <name>Threat: Unidentifiable Key</name>
        <t>
The profile in <xref target="sec-interop-alg"/> recommends key identifiers when possible and the parameters in section <xref target="sec-ASB-parameters"/> allow encoding public keys where available.
If the application using a COSE Integrity or COSE Confidentiality context leaves out key identification data (in a COSE recipient structure), the security acceptor for those BPSec blocks only has the primary block available to use when verifying or decrypting the target block.
This leads to a situation, identified in BPSec Security Considerations, where a signature is verified to be valid but not from the expected Security Source.
        </t>
        <t>
Because the key identifier headers are unprotected (see <xref target="sec-asym-keys"/>), there is still the possibility that an active attacker removes or alters key identifier(s) in the result.
This can cause the security acceptor to not be able to properly verify a valid signature or not use the correct private key to decrypt valid ciphertext.
        </t>
      </section>
      <section anchor="sec-threat-notrust-key">
        <name>Threat: Non-Trusted Public Key</name>
        <t>
The profile in <xref target="sec-interop-alg"/> allows the use of PKIX which typically involves end-entity certificates chained up to a trusted root CA.
This allows a BIB to contain end-entity certificates not previously known to a security acceptor but still trust the certificate by verifying it up to a trusted CA.
In an environment where security acceptors are known to already contain needed root and intermediate CAs there is no need to include those CAs in a proper chain within the security parameters, but this has a risk of an acceptor not actually having one of the needed CAs.
        </t>
        <t>
Because the security parameters are not included as AAD, there is still the possibility that an active attacker removes or alters certification chain data in the parameters.
This can cause the security acceptor to be able to verify a valid signature but not trust the public key used to perform the verification.
        </t>
      </section>
      <section>
        <name>Threat: Passive Leak of Key Material</name>
        <t>
It is important that the key requirements of <xref target="sec-ASB-parameters"/> apply only to public keys and PKIX certificates.
Including non-public key material in ASB parameters will expose that material in the bundle data and over the bundle convergence layer during transport.
        </t>
      </section>
      <section>
        <name>Threat: Algorithm Vulnerabilities</name>
        <t>
Because this use of COSE leaves the specific algorithms chosen for BIB and BCB use up to the applications securing bundle data, it is important to use only COSE algorithms which are marked as recommended in the IANA registry <xref target="IANA-COSE"/>.
        </t>
      </section>
    </section>
    <section anchor="sec-iana">
      <name>IANA Considerations</name>
      <t>
Registration procedures referred to in this section are defined in <xref target="RFC8126"/>.
      </t>
      <section anchor="sec-iana-bpsec-ctx">
        <name>BPSec Security Contexts</name>
        <t>
Within the "Bundle Protocol" registry <xref target="IANA-BUNDLE"/>, the following entry has been added to the "BPSec Security Context Identifiers" sub-registry.
        </t>
        <table>
          <thead>
            <tr>
              <th>Value</th>
              <th>Description</th>
              <th>Reference</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>TBD-COSE</td>
              <td>COSE</td>
              <td>This specification.</td>
            </tr>
          </tbody>
        </table>
      </section>
    </section>
  </middle>
  <back>
    <references>
      <name>References</name>
      <references>
        <name>Normative References</name>
        <reference anchor="IANA-BUNDLE" target="https://www.iana.org/assignments/bundle/">
          <front>
            <title>Bundle Protocol</title>
            <author>
              <organization>IANA</organization>
            </author>
            <date/>
          </front>
        </reference>
        <reference anchor="IANA-COSE" target="https://www.iana.org/assignments/cose/">
          <front>
            <title>CBOR Object Signing and Encryption (COSE)</title>
            <author>
              <organization>IANA</organization>
            </author>
            <date/>
          </front>
        </reference>
        <reference anchor="IANA-SMI" target="https://www.iana.org/assignments/smi-numbers/">
          <front>
            <title>Structure of Management Information (SMI) Numbers</title>
            <author>
              <organization>IANA</organization>
            </author>
            <date/>
          </front>
        </reference>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.5280.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.6125.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.6960.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8126.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8152.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8230.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8551.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8610.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.9172.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.9174.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.ietf-cose-x509.xml"/>
      </references>
      <references>
        <name>Informative References</name>
        <reference anchor="NIST-SP800-57" target="https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r5.pdf">
          <front>
            <title>Recommendation for Key Management - Part 1: General</title>
            <author>
              <organization>National Institute of Standards and Technology</organization>
            </author>
            <date month="May" year="2020"/>
          </front>
          <refcontent>NIST Special Publication 800-57 Revision 4, DOI 10.6028/NIST.SP.800-57pt1r5</refcontent>
        </reference>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.3552.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.7942.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.9171.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.9173.xml"/>
        <reference anchor="github-dtn-bpsec-cose" target="https://github.com/BrianSipos/dtn-bpsec-cose/">
          <front>
            <title>DTN Bundle Protocol Security COSE Security Context</title>
            <author fullname="Brian Sipos" initials="B." surname="Sipos">
              <organization abbrev="JHU/APL">The Johns Hopkins University Applied Physics Laboratory</organization>
            </author>
            <date/>
          </front>
        </reference>
        <reference anchor="github-dtn-demo-agent" target="https://github.com/BrianSipos/dtn-demo-agent/">
          <front>
            <title>Demo Convergence Layer Agent</title>
            <author fullname="Brian Sipos" initials="B." surname="Sipos">
              <organization abbrev="JHU/APL">The Johns Hopkins University Applied Physics Laboratory</organization>
            </author>
            <date/>
          </front>
        </reference>
        <reference anchor="github-dtn-wireshark" target="https://github.com/BrianSipos/dtn-demo-agent/">
          <front>
            <title>Wireshark Plugin Dissectors for DTN</title>
            <author fullname="Brian Sipos" initials="B." surname="Sipos">
              <organization abbrev="JHU/APL">The Johns Hopkins University Applied Physics Laboratory</organization>
            </author>
            <date/>
          </front>
        </reference>
      </references>
    </references>
    <section anchor="sec-examples">
      <name>Examples</name>
      <t>
These examples are intended to have the correct structure of COSE security blocks but in some cases use simplified algorithm parameters or smaller key sizes than are required by the actual COSE profile defined in this documents.
Each example indicates how it differs from the actual profile if there is a meaningful difference.
      </t>
      <t>
All of these examples operate within the context of the bundle primary block of <xref target="fig-ex-primary-block"/> with a security target block of <xref target="fig-ex-target-block"/>.
All example figures use the extended diagnostic notation <xref target="RFC8610"/>.
      </t>
      <figure anchor="fig-ex-primary-block">
        <name>Primary block CBOR diagnostic</name>
        <sourcecode type="cbor">
[
  7, / BP version /
  0, / flags /
  0, / CRC type /
  [1, "//dst/svc"], / destination /
  [1, "//src/"], / source /
  [1, "//src/"], / report-to /
  [0, 40], / timestamp /
  1000000 / lifetime /
]
        </sourcecode>
      </figure>
      <figure anchor="fig-ex-target-block">
        <name>Target block CBOR diagnostic</name>
        <sourcecode type="cbor">
[
  1, / type code: payload /
  1, / block num /
  0, / flags /
  0, / CRC type /
  &lt;&lt;"hello"&gt;&gt; / block-type-specific-data /
]
        </sourcecode>
      </figure>
      <t>
All of the block integrity block examples operate within the context of the "frame" block of <xref target="fig-ex-bib-frame"/>, and block confidentiality block examples within the frame block of <xref target="fig-ex-bcb-frame"/>.
      </t>
      <figure anchor="fig-ex-bib-frame">
        <name>Block integrity block frame CBOR diagnostic</name>
        <sourcecode type="cbor">
[
  11, / type code: BIB /
  3, / block num /
  0, / flags /
  0, / CRC type /
  '' / BTSD to be replaced /
]
        </sourcecode>
      </figure>
      <figure anchor="fig-ex-bcb-frame">
        <name>Block confidentiality block CBOR diagnostic</name>
        <sourcecode type="cbor">
[
  12, / type code: BCB /
  3, / block num /
  0, / flags /
  0, / CRC type /
  '' / BTSD to be replaced /
]
        </sourcecode>
      </figure>
      <t>
All of the examples also operate within a security block containing the AAD Scope parameter with only "has-primary-ctx" and "has-target-ctx" flags set.
This results in a consistent <tt>AAD-list</tt> as shown in <xref target="fig-ex-AAD-list"/>, which is encoded as the byte string for COSE <tt>external_aad</tt> in all of the examples.
      </t>
      <figure anchor="fig-ex-AAD-list">
        <name>Example scope AAD-list CBOR-sequence diagnostic</name>
        <sourcecode type="cbor">
3, / scope /
[ 7, 0, 0, [ 1, "//dst/svc" ], [ 1, "//src/" ], [ 1, "//src/" ],
  [ 0, 40 ], 1000000 ], / primary-ctx /
1, 1, 0, / target-ctx /
'' / additional-protected /
        </sourcecode>
      </figure>
      <t>
The only differences between these examples which use EC or RSA keypairs and a use of a PKIX public key certificate are: the parameters would have an x5chain parameter instead of a COSE_Key type, and the recipient would contain an "x5t" value instead of a "kid" value.
Neither of these is a change to a protected header so, given the same private key, there would be no change to the signature or wrapped-key data.
      </t>
      <t>
Because each of the encryption examples use the same CEK within the same AAD, the target ciphertext is also identical.
The target block after application of the encryption is shown in <xref target="fig-ex-encrypt-target-final"/>.
      </t>
      <figure anchor="fig-ex-encrypt-target-final">
        <name>Encrypted Target block CBOR diagnostic</name>
        <sourcecode type="cbor">
[
  1, / type code: payload /
  1, / block num /
  0, / flags /
  0, / CRC type /
  h'1fd25f64a2eea12d4bb6c02d25bf33cec45f3e4f96b1' / ciphertext /
]
        </sourcecode>
      </figure>
      <section>
        <name>Symmetric Key COSE_Mac0</name>
        <t>
This is an example of a MAC with recipient having a 256-bit symmetric key identified by a "kid".
        </t>
        <figure>
          <name>Symmetric Key</name>
          <sourcecode type="cbor">
[
  {
    / kty / 1: 4, / symmetric /
    / kid / 2: 'ExampleMAC',
    / k / -1: h'13bf9cead057c0aca2c9e52471ca4b19ddfaf4c0784e3f3e8e39
99dbae4ce45c'
  }
]
          </sourcecode>
        </figure>
        <t>
The <tt>external_aad</tt> is the encoded data from <xref target="fig-ex-AAD-list"/>.
The <tt>payload</tt> is the encoded target BTSD from <xref target="fig-ex-target-block"/>.
        </t>
        <figure anchor="fig-ex-mac-struct">
          <name><tt>MAC_structure</tt> CBOR diagnostic</name>
          <sourcecode type="cbor">
[
  "MAC0", / context /
  h'a10105', / protected /
  h'03880700008201692f2f6473742f7376638201662f2f7372632f8201662f2f73
72632f820018281a000f424001010040', / external_aad /
  h'6568656c6c6f' / payload /
]
          </sourcecode>
        </figure>
        <figure anchor="fig-ex-mac-asb">
          <name>Abstract Security Block CBOR diagnostic</name>
          <sourcecode type="cbor">
[1], / targets /
-1, / security context TBD-COSE /
1, / flags: params-present /
[1, "//src/"], / security source /
[ / parameters /
  [
    5, / AAD-scope /
    0b011 / has-primary-ctx | has-target-ctx /
  ]
],
[
  [ / target block #1 /
    [ / result /
      17, / COSE_Mac0 tag /
      &lt;&lt;[
        &lt;&lt;{ / protected /
           / alg / 1:5 / HMAC 256//256 /
        }&gt;&gt;,
        { / unprotected /
          / kid / 4:'ExampleMAC'
        },
        null, / payload detached /
        h'48d325a89fe966b982d0a603b75b352b1cbe50903ad025b9126431dfdb
bb0389' / tag /
      ]&gt;&gt;
    ]
  ]
]
          </sourcecode>
        </figure>
        <t>
The final bundle is encoded as the byte string:
        </t>
        <sourcecode type="cbor">
h'9f880700008201692f2f6473742f7376638201662f2f7372632f8201662f2f7372
632f820018281a000f4240850b030000584c810100018201662f2f7372632f818205
038181821158358443a10105a1044a4578616d706c654b6579f6582048d325a89fe9
66b982d0a603b75b352b1cbe50903ad025b9126431dfdbbb03898501010000466568
656c6c6fff'
        </sourcecode>
      </section>
      <section>
        <name>EC Keypair COSE_Sign1</name>
        <t>
This is an example of a signature with a recipient having a P-256 curve EC keypair identified by a "kid".
The associated public key is included as a security parameter.
        </t>
        <figure>
          <name>Example Keys</name>
          <sourcecode type="cbor">
[
  { / signing private key /
    / kty / 1: 2, / EC2 /
    / kid / 2: 'ExampleEC2',
    / crv / -1: 1, / P-256 /
    / x / -2: h'44c1fa63b84f172b50541339c50beb0e630241ecb4eebbddb8b5
e4fe0a1787a8',
    / y / -3: h'059451c7630d95d0b550acbd02e979b3f4f74e645b74715fafbc
1639960a0c7a',
    / d / -4: h'dd6e7d8c4c0e0c0bd3ae1b4a2fa86b9a09b7efee4a233772cf51
89786ea63842'
  }
]
          </sourcecode>
        </figure>
        <t>
The <tt>external_aad</tt> is the encoded data from <xref target="fig-ex-AAD-list"/>.
The <tt>payload</tt> is the encoded target BTSD from <xref target="fig-ex-target-block"/>.
        </t>
        <figure anchor="fig-ex-sign-ec2-struct">
          <name><tt>Sig_structure</tt> CBOR diagnostic</name>
          <sourcecode type="cbor">
[
  "Signature1", / context /
  h'a10126', / protected /
  h'03880700008201692f2f6473742f7376638201662f2f7372632f8201662f2f73
72632f820018281a000f424001010040', / external_aad /
  h'6568656c6c6f' / payload /
]
          </sourcecode>
        </figure>
        <figure anchor="fig-ex-sign-ec2-asb">
          <name>Abstract Security Block CBOR diagnostic</name>
          <sourcecode type="cbor">
[1], / targets /
-1, / security context TBD-COSE /
1, / flags: params-present /
[1, "//src/"], / security source /
[ / parameters /
  [
    5, / AAD-scope /
    0b011 / has-primary-ctx | has-target-ctx /
  ]
],
[
  [ / target block #1 /
    [ / result /
      18, / COSE_Sign1 tag /
      &lt;&lt;[
        &lt;&lt;{ / protected /
           / alg / 1:-7 / ES256 /
        }&gt;&gt;,
        { / unprotected /
          / kid / 4:'ExampleEC2'
        },
        null, / payload detached /
        h'b8eb3feb581fde875f277ed757512f1a4b107fcd46373ebc53d2af5549
8bb07e335a06ef035f16622ca143a6cc1e390441714155e1571e18a3c767bf5128c1
b0' / signature /
      ]&gt;&gt;
    ]
  ]
]
          </sourcecode>
        </figure>
        <t>
The final bundle is encoded as the byte string:
        </t>
        <sourcecode type="cbor">
h'9f880700008201692f2f6473742f7376638201662f2f7372632f8201662f2f7372
632f820018281a000f4240850b030000586c810100018201662f2f7372632f818205
038181821258558443a10126a1044a4578616d706c65454332f65840b8eb3feb581f
de875f277ed757512f1a4b107fcd46373ebc53d2af55498bb07e335a06ef035f1662
2ca143a6cc1e390441714155e1571e18a3c767bf5128c1b08501010000466568656c
6c6fff'
        </sourcecode>
      </section>
      <section>
        <name>RSA Keypair COSE_Sign1</name>
        <t>
This is an example of a signature with a recipient having a 1024-bit RSA keypair identified by a "kid".
The associated public key is included as a security parameter.
        </t>
        <t>
This key strength is not supposed to be a secure configuration, only intended to explain the procedure.
This signature uses a random salt, so the full signature output is not deterministic.
        </t>
        <figure>
          <name>Example Keys</name>
          <sourcecode type="cbor">
[
  { / signing private key /
    / kty / 1: 3, / RSA /
    / kid / 2: 'ExampleRSA',
    / n / -1: h'b0b5fd85f52c91844007443c9f9371980025f76d51fc9c676812
31da610cb291ba637ce813bffdb2e9c653258607389ec97dad3db295fded67744ed6
20707db36804e74e56a494030a73608fc8d92f2f0578d2d85cc201ef0ff22d7835d2
d147d3b90a6884276235a01c2be99dfc597f79554362fc1eb03639cac5ccaddb29
25',
    / e / -2: h'010001',
    / d / -3: h'9b5d26ad6445ef1aab80b809e4f329684e9912d556c4166f041d
1b1fb93c04b4037ffd0dbe6f8a8a86e70bab6e0f6344983a9ada27ed9ff7de816fde
eb5e7be48e607ce5fda4581ca6338a9e019fb3689b28934192b6a190cdda910abb5a
86a2f7b6f9cd5011049d8de52ddfef73aa06df401c55623ec196720f54920deb4f
01',
    / p / -4: h'db22d94e7784a27b568cbf985307ea8d6430ff6b88c18a7086fd
4f57a326572f2250c39e48a6f8e2201661c2dfe12c7386835b649714d050aa36123e
c3d00e75',
    / q / -5: h'ce7016adc5f326b7520397c5978ee2f50e69279983d54c5d76f0
5bcd61de0879d7056c923540dff9cbae95dcc0e5e86b52b3c902dc9669c8021c6955
7effb9f1',
    / dP / -6: h'6a6fcaccea106a3b2e16bf18e57b7ad9a2488a4758ed68a8af6
86a194f0d585b7477760c738d6665aee0302bcf4237ad0530d83b4b86b887f5a4bdc
7eea427e1',
    / dQ / -7: h'28a4cae245b1dcb285142e027a1768b9c4af915b59285a93a04
22c60e05edd9e57663afd023d169bd0ad3bd62da8563d231840802ebbf271ad70b89
05ba3af91',
    / qInv / -8: h'07b5a61733896270a6bd2bb1654194c54e2bc0e061b543a4e
d9fa73c4bc79c87148aa92a451c4ab8262b6377a9c7b97f869160ca6f5d853ee4b65
f4f92865ca3'
  }
]
          </sourcecode>
        </figure>
        <t>
The <tt>external_aad</tt> is the encoded data from <xref target="fig-ex-AAD-list"/>.
The <tt>payload</tt> is the encoded target BTSD from <xref target="fig-ex-target-block"/>.
        </t>
        <figure anchor="fig-ex-sign-rsa-struct">
          <name><tt>Sig_structure</tt> CBOR diagnostic</name>
          <sourcecode type="cbor">
[
  "Signature1", / context /
  h'a1013824', / protected /
  h'03880700008201692f2f6473742f7376638201662f2f7372632f8201662f2f73
72632f820018281a000f424001010040', / external_aad /
  h'6568656c6c6f' / payload /
]
          </sourcecode>
        </figure>
        <figure anchor="fig-ex-sign-rsa-asb">
          <name>Abstract Security Block CBOR diagnostic</name>
          <sourcecode type="cbor">
[1], / targets /
-1, / security context TBD-COSE /
1, / flags: params-present /
[1, "//src/"], / security source /
[ / parameters /
  [
    5, / AAD-scope /
    0b011 / has-primary-ctx | has-target-ctx /
  ]
],
[
  [ / target block #1 /
    [ / result /
      18, / COSE_Sign1 tag /
      &lt;&lt;[
        &lt;&lt;{ / protected /
           / alg / 1:-37 / PS256 /
        }&gt;&gt;,
        { / unprotected /
          / kid / 4:'ExampleRSA'
        },
        null, / payload detached /
        h'57a263315f4641e40b7481fdf6140d10a9d51cdbf29b33a4c31e8477a9
cad07cedf2df4b0016f44af69599ed8031e26deae2c26bc9407c31e550437cb9c569
f6af80feb14ef54ad740bf02b3f68047961dbe7ea5b13ac2610ff2706abf83f50f59
51e21c2610b79b1719ff99da66ccabeb5600132625267ea75772d450b7eb
cb' / signature /
      ]&gt;&gt;
    ]
  ]
]
          </sourcecode>
        </figure>
        <t>
The final bundle is encoded as the byte string:
        </t>
        <sourcecode type="cbor">
h'9f880700008201692f2f6473742f7376638201662f2f7372632f8201662f2f7372
632f820018281a000f4240850b03000058ad810100018201662f2f7372632f818205
038181821258968444a1013824a1044a4578616d706c65525341f6588057a263315f
4641e40b7481fdf6140d10a9d51cdbf29b33a4c31e8477a9cad07cedf2df4b0016f4
4af69599ed8031e26deae2c26bc9407c31e550437cb9c569f6af80feb14ef54ad740
bf02b3f68047961dbe7ea5b13ac2610ff2706abf83f50f5951e21c2610b79b1719ff
99da66ccabeb5600132625267ea75772d450b7ebcb8501010000466568656c6c6f
ff'
        </sourcecode>
      </section>
      <section>
        <name>Symmetric KEK COSE_Encrypt</name>
        <t>
This is an example of an encryption with a random CEK and an explicit key-encryption key (KEK) identified by a "kid".
The keys used are shown in <xref target="fig-ex-encrypt-symm-keys"/>.
        </t>
        <figure anchor="fig-ex-encrypt-symm-keys">
          <name>Example Keys</name>
          <sourcecode type="cbor">
[
  {
    / kty / 1: 4, / symmetric /
    / kid / 2: 'ExampleKEK',
    / k / -1: h'0e8a982b921d1086241798032fedc1f883eab72e4e43bb2d11cf
ae38ad7a972e'
  },
  {
    / kty / 1: 4, / symmetric /
    / kid / 2: 'ExampleCEK',
    / k / -1: h'13bf9cead057c0aca2c9e52471ca4b19ddfaf4c0784e3f3e8e39
99dbae4ce45c'
  }
]
          </sourcecode>
        </figure>
        <t>
The <tt>external_aad</tt> is the encoded data from <xref target="fig-ex-AAD-list"/>.
        </t>
        <figure anchor="fig-ex-encrypt-symm-struct">
          <name><tt>Enc_structure</tt> CBOR diagnostic</name>
          <sourcecode type="cbor">
[
  "Encrypt", / context /
  h'a10103', / protected /
  h'03880700008201692f2f6473742f7376638201662f2f7372632f8201662f2f73
72632f820018281a000f424001010040', / external_aad /
]
          </sourcecode>
        </figure>
        <t>
The ASB item for this encryption operation is shown in <xref target="fig-ex-encrypt-symm-asb"/> and corresponds with the updated target block (containing the ciphertext) of <xref target="fig-ex-encrypt-target-final"/>.
        </t>
        <figure anchor="fig-ex-encrypt-symm-asb">
          <name>Abstract Security Block CBOR diagnostic</name>
          <sourcecode type="cbor">
[1], / targets /
-1, / security context TBD-COSE /
1, / flags: params-present /
[1, "//src/"], / security source /
[ / parameters /
  [
    5, / AAD-scope /
    0b011 / has-primary-ctx | has-target-ctx /
  ]
],
[
  [ / target block #1 /
    [ / result /
      96, / COSE_Encrypt tag /
      &lt;&lt;[
        &lt;&lt;{ / protected /
           / alg / 1:3 / A256GCM /
        }&gt;&gt;,
        { / unprotected /
          / iv / 5: h'6f3093eba5d85143c3dc484a'
        },
        null, / payload detached /
        [
          [ / recipient /
            h'', / protected /
            { / unprotected /
              / alg / 1:-5, / A256KW /
              / kid / 4:'ExampleKEK'
            },
            h'917f2045e1169502756252bf119a94cdac6a9d8944245b5a9a26d4
03a6331159e3d691a708e9984d' / key-wrapped /
          ]
        ]
      ]&gt;&gt;
    ]
  ]
]
          </sourcecode>
        </figure>
        <t>
The final bundle is encoded as the byte string:
        </t>
        <sourcecode type="cbor">
h'9f880700008201692f2f6473742f7376638201662f2f7372632f8201662f2f7372
632f820018281a000f4240850c0300005869810100018201662f2f7372632f818205
03818182186058518443a10103a1054c6f3093eba5d85143c3dc484af6818340a201
24044a4578616d706c654b454b5828917f2045e1169502756252bf119a94cdac6a9d
8944245b5a9a26d403a6331159e3d691a708e9984d8501010000561fd25f64a2ee52
8b86b0c2f3785b531e634d6ef31c74ff'
        </sourcecode>
      </section>
      <section>
        <name>EC Keypair COSE_Encrypt</name>
        <t>
This is an example of an encryption with an P-256 curve ephemeral sender keypair and a static recipient keypair identified by a "kid".
The keys used are shown in <xref target="fig-ex-encrypt-ec2-keys"/>.
        </t>
        <figure anchor="fig-ex-encrypt-ec2-keys">
          <name>Example Keys</name>
          <sourcecode type="cbor">
[
  { / sender ephemeral private key /
    / kty / 1: 2, / EC2 /
    / crv / -1: 1, / P-256 /
    / x / -2: h'fedaba748882050d1bef8ba992911898f554450952070aeb4788
ca57d1df6bcc',
    / y / -3: h'ceaa8e7ff4751a4f81c70e98f1713378b0bd82a1414a2f493c1c
9c0670f28d62',
    / d / -4: h'a2e4ed4f2e21842999b0e9ebdaad7465efd5c29bd5761f5c2088
0f9d9c3b122a'
  },
  { / recipient private key /
    / kty / 1: 2, / EC2 /
    / kid / 2: 'ExampleEC2',
    / crv / -1: 1, / P-256 /
    / x / -2: h'44c1fa63b84f172b50541339c50beb0e630241ecb4eebbddb8b5
e4fe0a1787a8',
    / y / -3: h'059451c7630d95d0b550acbd02e979b3f4f74e645b74715fafbc
1639960a0c7a',
    / d / -4: h'dd6e7d8c4c0e0c0bd3ae1b4a2fa86b9a09b7efee4a233772cf51
89786ea63842'
  },
  {
    / kty / 1: 4, / symmetric /
    / kid / 2: 'ExampleCEK',
    / k / -1: h'13bf9cead057c0aca2c9e52471ca4b19ddfaf4c0784e3f3e8e39
99dbae4ce45c'
  }
]
          </sourcecode>
        </figure>
        <t>
The <tt>external_aad</tt> is the encoded data from <xref target="fig-ex-AAD-list"/>.
        </t>
        <figure anchor="fig-ex-encrypt-ec2-struct">
          <name><tt>Enc_structure</tt> CBOR diagnostic</name>
          <sourcecode type="cbor">
[
  "Encrypt", / context /
  h'a10103', / protected /
  h'03880700008201692f2f6473742f7376638201662f2f7372632f8201662f2f73
72632f820018281a000f424001010040', / external_aad /
]
          </sourcecode>
        </figure>
        <t>
The ASB item for this encryption operation is shown in <xref target="fig-ex-encrypt-ec2-asb"/> and corresponds with the updated target block (containing the ciphertext) of <xref target="fig-ex-encrypt-target-final"/>.
        </t>
        <figure anchor="fig-ex-encrypt-ec2-asb">
          <name>Abstract Security Block CBOR diagnostic</name>
          <sourcecode type="cbor">
[1], / targets /
-1, / security context TBD-COSE /
1, / flags: params-present /
[1, "//src/"], / security source /
[ / parameters /
  [
    5, / AAD-scope /
    0b011 / has-primary-ctx | has-target-ctx /
  ]
],
[
  [ / target block #1 /
    [ / result /
      96, / COSE_Encrypt tag /
      &lt;&lt;[
        &lt;&lt;{ / protected /
           / alg / 1:3 / A256GCM /
        }&gt;&gt;,
        { / unprotected /
          / iv / 5: h'6f3093eba5d85143c3dc484a'
        },
        null, / payload detached /
        [
          [ / recipient /
            h'', / protected /
            { / unprotected /
              / alg / 1:-31, / ECDH-ES + A256KW /
              / kid / 4:'ExampleEC2',
              / ephemeral key / -1:{
                1:2,
                -1:1,
                -2:h'fedaba748882050d1bef8ba992911898f554450952070ae
b4788ca57d1df6bcc',
                -3:h'ceaa8e7ff4751a4f81c70e98f1713378b0bd82a1414a2f4
93c1c9c0670f28d62'
              }
            },
            h'cb530b03f1e4b09ec1a0ca19afafbf280284106ab407aaf9bfed6e
666c8f2f9ab5465cf11ef02756' / key-wrapped /
          ]
        ]
      ]&gt;&gt;
    ]
  ]
]
          </sourcecode>
        </figure>
        <t>
The final bundle is encoded as the byte string:
        </t>
        <sourcecode type="cbor">
h'9f880700008201692f2f6473742f7376638201662f2f7372632f8201662f2f7372
632f820018281a000f4240850c03000058b6810100018201662f2f7372632f818205
038181821860589e8443a10103a1054c6f3093eba5d85143c3dc484af6818340a301
381e044a4578616d706c6545433220a401022001215820fedaba748882050d1bef8b
a992911898f554450952070aeb4788ca57d1df6bcc225820ceaa8e7ff4751a4f81c7
0e98f1713378b0bd82a1414a2f493c1c9c0670f28d625828cb530b03f1e4b09ec1a0
ca19afafbf280284106ab407aaf9bfed6e666c8f2f9ab5465cf11ef0275685010100
00561fd25f64a2ee528b86b0c2f3785b531e634d6ef31c74ff'
        </sourcecode>
      </section>
      <section>
        <name>RSA Keypair COSE_Encrypt</name>
        <t>
This is an example of an encryption with a recipient having a 1024-bit RSA keypair identified by a "kid".
The associated public key is included as a security parameter.
        </t>
        <t>
This key strength is not supposed to be a secure configuration, only intended to explain the procedure.
This padding scheme uses a random salt, so the full layer-2 ciphertext output is not deterministic.
        </t>
        <figure anchor="fig-ex-encrypt-rsa-keys">
          <name>Example Keys</name>
          <sourcecode type="cbor">
[
  { / recipient private key /
    / kty / 1: 3, / RSA /
    / kid / 2: 'ExampleRSA',
    / n / -1: h'b0b5fd85f52c91844007443c9f9371980025f76d51fc9c676812
31da610cb291ba637ce813bffdb2e9c653258607389ec97dad3db295fded67744ed6
20707db36804e74e56a494030a73608fc8d92f2f0578d2d85cc201ef0ff22d7835d2
d147d3b90a6884276235a01c2be99dfc597f79554362fc1eb03639cac5ccaddb29
25',
    / e / -2: h'010001',
    / d / -3: h'9b5d26ad6445ef1aab80b809e4f329684e9912d556c4166f041d
1b1fb93c04b4037ffd0dbe6f8a8a86e70bab6e0f6344983a9ada27ed9ff7de816fde
eb5e7be48e607ce5fda4581ca6338a9e019fb3689b28934192b6a190cdda910abb5a
86a2f7b6f9cd5011049d8de52ddfef73aa06df401c55623ec196720f54920deb4f
01',
    / p / -4: h'db22d94e7784a27b568cbf985307ea8d6430ff6b88c18a7086fd
4f57a326572f2250c39e48a6f8e2201661c2dfe12c7386835b649714d050aa36123e
c3d00e75',
    / q / -5: h'ce7016adc5f326b7520397c5978ee2f50e69279983d54c5d76f0
5bcd61de0879d7056c923540dff9cbae95dcc0e5e86b52b3c902dc9669c8021c6955
7effb9f1',
    / dP / -6: h'6a6fcaccea106a3b2e16bf18e57b7ad9a2488a4758ed68a8af6
86a194f0d585b7477760c738d6665aee0302bcf4237ad0530d83b4b86b887f5a4bdc
7eea427e1',
    / dQ / -7: h'28a4cae245b1dcb285142e027a1768b9c4af915b59285a93a04
22c60e05edd9e57663afd023d169bd0ad3bd62da8563d231840802ebbf271ad70b89
05ba3af91',
    / qInv / -8: h'07b5a61733896270a6bd2bb1654194c54e2bc0e061b543a4e
d9fa73c4bc79c87148aa92a451c4ab8262b6377a9c7b97f869160ca6f5d853ee4b65
f4f92865ca3'
  },
  {
    / kty / 1: 4, / symmetric /
    / kid / 2: 'ExampleCEK',
    / k / -1: h'13bf9cead057c0aca2c9e52471ca4b19ddfaf4c0784e3f3e8e39
99dbae4ce45c'
  }
]
          </sourcecode>
        </figure>
        <t>
The <tt>external_aad</tt> is the encoded data from <xref target="fig-ex-AAD-list"/>.
        </t>
        <figure anchor="fig-ex-encrypt-rsa-struct">
          <name><tt>Enc_structure</tt> CBOR diagnostic</name>
          <sourcecode type="cbor">
[
  "Encrypt", / context /
  h'a10103', / protected /
  h'03880700008201692f2f6473742f7376638201662f2f7372632f8201662f2f73
72632f820018281a000f424001010040', / external_aad /
]
          </sourcecode>
        </figure>
        <t>
The ASB item for this encryption operation is shown in <xref target="fig-ex-encrypt-rsa-asb"/> and corresponds with the updated target block (containing the ciphertext) of <xref target="fig-ex-encrypt-target-final"/>.
        </t>
        <figure anchor="fig-ex-encrypt-rsa-asb">
          <name>Abstract Security Block CBOR diagnostic</name>
          <sourcecode type="cbor">
[1], / targets /
-1, / security context TBD-COSE /
1, / flags: params-present /
[1, "//src/"], / security source /
[ / parameters /
  [
    5, / AAD-scope /
    0b011 / has-primary-ctx | has-target-ctx /
  ]
],
[
  [ / target block #1 /
    [ / result /
      96, / COSE_Encrypt tag /
      &lt;&lt;[
        &lt;&lt;{ / protected /
           / alg / 1:3 / A256GCM /
        }&gt;&gt;,
        { / unprotected /
          / iv / 5: h'6f3093eba5d85143c3dc484a'
        },
        null, / payload detached /
        [
          [ / recipient /
            h'', / protected /
            { / unprotected /
              / alg / 1:-41, / RSAES-OAEP w SHA-256 /
              / kid / 4:'ExampleRSA'
            },
            h'98123325e3f124321a109a374e8a43a33252f79c67a3ec9e3158f6
7a0664671d444a80b7f6c05fa4f91635e1a372481db3f7b0b60e0eb9c4b479340f72
71f14925a32604f9e4b3e944f5a0422ac21745148363bc49e85361ab9344a9b63ea8
0a127f74eda2fb0d992780fba4d48a5bc520609ba6fd5c668d6614bfa4623a31
1e' / key-wrapped /
          ]
        ]
      ]&gt;&gt;
    ]
  ]
]
          </sourcecode>
        </figure>
        <t>
The final bundle is encoded as the byte string:
        </t>
        <sourcecode type="cbor">
h'9f880700008201692f2f6473742f7376638201662f2f7372632f8201662f2f7372
632f820018281a000f4240850c03000058c2810100018201662f2f7372632f818205
03818182186058aa8443a10103a1054c6f3093eba5d85143c3dc484af6818340a201
3828044a4578616d706c65525341588098123325e3f124321a109a374e8a43a33252
f79c67a3ec9e3158f67a0664671d444a80b7f6c05fa4f91635e1a372481db3f7b0b6
0e0eb9c4b479340f7271f14925a32604f9e4b3e944f5a0422ac21745148363bc49e8
5361ab9344a9b63ea80a127f74eda2fb0d992780fba4d48a5bc520609ba6fd5c668d
6614bfa4623a311e8501010000561fd25f64a2ee528b86b0c2f3785b531e634d6ef3
1c74ff'
        </sourcecode>
      </section>
    </section>
    <section anchor="sec-doc-ack" numbered="false">
      <name>Acknowledgments</name>
      <t>
The interoperability minimum algorithms and parameters are based on those available in <xref target="RFC9173"/>.
      </t>
    </section>
  </back>
</rfc>
