idnits 2.17.1 draft-ietf-cose-rfc8152bis-struct-07.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The abstract seems to contain references ([I-D.ietf-cose-RFC8152bis-algs]), which it shouldn't. Please replace those with straight textual mentions of the documents in question. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (17 November 2019) is 1615 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) ** Obsolete normative reference: RFC 7049 (Obsoleted by RFC 8949) -- Possible downref: Non-RFC (?) normative reference: ref. 'DSS' ** Downref: Normative reference to an Informational RFC: RFC 8032 == Outdated reference: A later version (-12) exists of draft-ietf-cose-rfc8152bis-algs-05 ** Downref: Normative reference to an Informational draft: draft-ietf-cose-rfc8152bis-algs (ref. 'I-D.ietf-cose-rfc8152bis-algs') -- Obsolete informational reference (is this intentional?): RFC 8152 (Obsoleted by RFC 9052, RFC 9053) -- Obsolete informational reference (is this intentional?): RFC 2633 (Obsoleted by RFC 3851) -- Obsolete informational reference (is this intentional?): RFC 5751 (Obsoleted by RFC 8551) Summary: 4 errors (**), 0 flaws (~~), 2 warnings (==), 5 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 COSE Working Group J. Schaad 3 Internet-Draft August Cellars 4 Obsoletes: 8152 (if approved) 17 November 2019 5 Intended status: Standards Track 6 Expires: 20 May 2020 8 CBOR Object Signing and Encryption (COSE): Structures and Process 9 draft-ietf-cose-rfc8152bis-struct-07 11 Abstract 13 Concise Binary Object Representation (CBOR) is a data format designed 14 for small code size and small message size. There is a need for the 15 ability to have basic security services defined for this data format. 16 This document defines the CBOR Object Signing and Encryption (COSE) 17 protocol. This specification describes how to create and process 18 signatures, message authentication codes, and encryption using CBOR 19 for serialization. This specification additionally describes how to 20 represent cryptographic keys using CBOR. 22 This document along with [I-D.ietf-cose-rfc8152bis-algs] obsoletes 23 RFC8152. 25 Contributing to this document 27 This note is to be removed before publishing as an RFC. 29 The source for this draft is being maintained in GitHub. Suggested 30 changes should be submitted as pull requests at https://github.com/ 31 cose-wg/cose-rfc8152bis. Instructions are on that page as well. 32 Editorial changes can be managed in GitHub, but any substantial 33 issues need to be discussed on the COSE mailing list. 35 Status of This Memo 37 This Internet-Draft is submitted in full conformance with the 38 provisions of BCP 78 and BCP 79. 40 Internet-Drafts are working documents of the Internet Engineering 41 Task Force (IETF). Note that other groups may also distribute 42 working documents as Internet-Drafts. The list of current Internet- 43 Drafts is at https://datatracker.ietf.org/drafts/current/. 45 Internet-Drafts are draft documents valid for a maximum of six months 46 and may be updated, replaced, or obsoleted by other documents at any 47 time. It is inappropriate to use Internet-Drafts as reference 48 material or to cite them other than as "work in progress." 49 This Internet-Draft will expire on 20 May 2020. 51 Copyright Notice 53 Copyright (c) 2019 IETF Trust and the persons identified as the 54 document authors. All rights reserved. 56 This document is subject to BCP 78 and the IETF Trust's Legal 57 Provisions Relating to IETF Documents (https://trustee.ietf.org/ 58 license-info) in effect on the date of publication of this document. 59 Please review these documents carefully, as they describe your rights 60 and restrictions with respect to this document. Code Components 61 extracted from this document must include Simplified BSD License text 62 as described in Section 4.e of the Trust Legal Provisions and are 63 provided without warranty as described in the Simplified BSD License. 65 Table of Contents 67 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 68 1.1. Design Changes from JOSE . . . . . . . . . . . . . . . . 5 69 1.2. Changes from RFC8152 . . . . . . . . . . . . . . . . . . 6 70 1.3. Requirements Terminology . . . . . . . . . . . . . . . . 6 71 1.4. CBOR Grammar . . . . . . . . . . . . . . . . . . . . . . 6 72 1.5. CBOR-Related Terminology . . . . . . . . . . . . . . . . 8 73 1.6. Document Terminology . . . . . . . . . . . . . . . . . . 8 74 2. Basic COSE Structure . . . . . . . . . . . . . . . . . . . . 9 75 3. Header Parameters . . . . . . . . . . . . . . . . . . . . . . 13 76 3.1. Common COSE Headers Parameters . . . . . . . . . . . . . 14 77 4. Signing Objects . . . . . . . . . . . . . . . . . . . . . . . 18 78 4.1. Signing with One or More Signers . . . . . . . . . . . . 18 79 4.2. Signing with One Signer . . . . . . . . . . . . . . . . . 20 80 4.3. Externally Supplied Data . . . . . . . . . . . . . . . . 21 81 4.4. Signing and Verification Process . . . . . . . . . . . . 22 82 5. Counter Signatures . . . . . . . . . . . . . . . . . . . . . 24 83 5.1. Full Countersignatures . . . . . . . . . . . . . . . . . 24 84 5.2. Abbreviated Countersignatures . . . . . . . . . . . . . . 25 85 6. Encryption Objects . . . . . . . . . . . . . . . . . . . . . 26 86 6.1. Enveloped COSE Structure . . . . . . . . . . . . . . . . 26 87 6.1.1. Content Key Distribution Methods . . . . . . . . . . 28 88 6.2. Single Recipient Encrypted . . . . . . . . . . . . . . . 28 89 6.3. How to Encrypt and Decrypt for AEAD Algorithms . . . . . 29 90 6.4. How to Encrypt and Decrypt for AE Algorithms . . . . . . 31 91 7. MAC Objects . . . . . . . . . . . . . . . . . . . . . . . . . 33 92 7.1. MACed Message with Recipients . . . . . . . . . . . . . . 33 93 7.2. MACed Messages with Implicit Key . . . . . . . . . . . . 34 94 7.3. How to Compute and Verify a MAC . . . . . . . . . . . . . 35 95 8. Key Objects . . . . . . . . . . . . . . . . . . . . . . . . . 36 96 8.1. COSE Key Common Parameters . . . . . . . . . . . . . . . 37 98 9. Taxonomy of Algorithms used by COSE . . . . . . . . . . . . . 39 99 9.1. Signature Algorithms . . . . . . . . . . . . . . . . . . 40 100 9.2. Message Authentication Code (MAC) Algorithms . . . . . . 41 101 9.3. Content Encryption Algorithms . . . . . . . . . . . . . . 41 102 9.4. Key Derivation Functions (KDFs) . . . . . . . . . . . . . 42 103 9.5. Content Key Distribution Methods . . . . . . . . . . . . 42 104 9.5.1. Direct Encryption . . . . . . . . . . . . . . . . . . 43 105 9.5.2. Key Wrap . . . . . . . . . . . . . . . . . . . . . . 43 106 9.5.3. Key Transport . . . . . . . . . . . . . . . . . . . . 44 107 9.5.4. Direct Key Agreement . . . . . . . . . . . . . . . . 44 108 9.5.5. Key Agreement with Key Wrap . . . . . . . . . . . . . 45 109 10. CBOR Encoding Restrictions . . . . . . . . . . . . . . . . . 46 110 11. Application Profiling Considerations . . . . . . . . . . . . 46 111 12. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 47 112 12.1. CBOR Tag Assignment . . . . . . . . . . . . . . . . . . 48 113 12.2. COSE Header Parameters Registry . . . . . . . . . . . . 48 114 12.3. COSE Header Algorithm Parameters Registry . . . . . . . 48 115 12.4. COSE Key Common Parameters Registry . . . . . . . . . . 48 116 12.5. Media Type Registrations . . . . . . . . . . . . . . . . 49 117 12.5.1. COSE Security Message . . . . . . . . . . . . . . . 49 118 12.5.2. COSE Key Media Type . . . . . . . . . . . . . . . . 50 119 12.6. CoAP Content-Formats Registry . . . . . . . . . . . . . 52 120 13. Security Considerations . . . . . . . . . . . . . . . . . . . 52 121 14. Implementation Status . . . . . . . . . . . . . . . . . . . . 54 122 14.1. Author's Versions . . . . . . . . . . . . . . . . . . . 54 123 14.2. JavaScript Version . . . . . . . . . . . . . . . . . . . 55 124 14.3. Python Version . . . . . . . . . . . . . . . . . . . . . 55 125 14.4. COSE Testing Library . . . . . . . . . . . . . . . . . . 56 126 15. References . . . . . . . . . . . . . . . . . . . . . . . . . 56 127 15.1. Normative References . . . . . . . . . . . . . . . . . . 56 128 15.2. Informative References . . . . . . . . . . . . . . . . . 57 129 Appendix A. Guidelines for External Data Authentication of 130 Algorithms . . . . . . . . . . . . . . . . . . . . . . . 60 131 Appendix B. Two Layers of Recipient Information . . . . . . . . 63 132 Appendix C. Examples . . . . . . . . . . . . . . . . . . . . . . 65 133 C.1. Examples of Signed Messages . . . . . . . . . . . . . . . 65 134 C.1.1. Single Signature . . . . . . . . . . . . . . . . . . 65 135 C.1.2. Multiple Signers . . . . . . . . . . . . . . . . . . 66 136 C.1.3. Counter Signature . . . . . . . . . . . . . . . . . . 67 137 C.1.4. Signature with Criticality . . . . . . . . . . . . . 68 138 C.2. Single Signer Examples . . . . . . . . . . . . . . . . . 69 139 C.2.1. Single ECDSA Signature . . . . . . . . . . . . . . . 69 140 C.3. Examples of Enveloped Messages . . . . . . . . . . . . . 70 141 C.3.1. Direct ECDH . . . . . . . . . . . . . . . . . . . . . 70 142 C.3.2. Direct Plus Key Derivation . . . . . . . . . . . . . 71 143 C.3.3. Counter Signature on Encrypted Content . . . . . . . 72 144 C.3.4. Encrypted Content with External Data . . . . . . . . 73 145 C.4. Examples of Encrypted Messages . . . . . . . . . . . . . 74 146 C.4.1. Simple Encrypted Message . . . . . . . . . . . . . . 74 147 C.4.2. Encrypted Message with a Partial IV . . . . . . . . . 75 148 C.5. Examples of MACed Messages . . . . . . . . . . . . . . . 75 149 C.5.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 75 150 C.5.2. ECDH Direct MAC . . . . . . . . . . . . . . . . . . . 76 151 C.5.3. Wrapped MAC . . . . . . . . . . . . . . . . . . . . . 77 152 C.5.4. Multi-Recipient MACed Message . . . . . . . . . . . . 78 153 C.6. Examples of MAC0 Messages . . . . . . . . . . . . . . . . 79 154 C.6.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 79 155 C.7. COSE Keys . . . . . . . . . . . . . . . . . . . . . . . . 80 156 C.7.1. Public Keys . . . . . . . . . . . . . . . . . . . . . 80 157 C.7.2. Private Keys . . . . . . . . . . . . . . . . . . . . 81 158 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 83 159 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 84 161 1. Introduction 163 There has been an increased focus on small, constrained devices that 164 make up the Internet of Things (IoT). One of the standards that has 165 come out of this process is "Concise Binary Object Representation 166 (CBOR)" [RFC7049]. CBOR extended the data model of the JavaScript 167 Object Notation (JSON) [RFC8259] by allowing for binary data, among 168 other changes. CBOR has been adopted by several of the IETF working 169 groups dealing with the IoT world as their encoding of data 170 structures. CBOR was designed specifically to be both small in terms 171 of messages transport and implementation size and be a schema-free 172 decoder. A need exists to provide message security services for IoT, 173 and using CBOR as the message-encoding format makes sense. 175 The JOSE working group produced a set of documents [RFC7515] 176 [RFC7516] [RFC7517] [RFC7518] using JSON that specified how to 177 process encryption, signatures, and Message Authentication Code (MAC) 178 operations and how to encode keys using JSON. This document along 179 with [I-D.ietf-cose-rfc8152bis-algs] defines the CBOR Object Signing 180 and Encryption (COSE) standard, which does the same thing for the 181 CBOR encoding format. While there is a strong attempt to keep the 182 flavor of the original JSON Object Signing and Encryption (JOSE) 183 documents, two considerations are taken into account: 185 * CBOR has capabilities that are not present in JSON and are 186 appropriate to use. One example of this is the fact that CBOR has 187 a method of encoding binary directly without first converting it 188 into a base64-encoded string. 190 * COSE is not a direct copy of the JOSE specification. In the 191 process of creating COSE, decisions that were made for JOSE were 192 re-examined. In many cases, different results were decided on as 193 the criteria were not always the same. 195 This document contains: 197 * The description of the structure for the CBOR objects which are 198 transmitted over the wire. Two objects are defined for 199 encryption, signing and message authentication. One object is 200 defined for transporting keys and one for transporting groups of 201 keys. 203 * The procedures used to build the inputs to the cryptographic 204 functions required for each of the structures. 206 * A starting set of attributes that apply to the different security 207 objects. 209 This document does not contain the rules and procedures for using 210 specific cryptographic algorithms. Details on specific algorithms 211 can be found in [I-D.ietf-cose-rfc8152bis-algs] and [RFC8230]. 212 Details for additional algorithms are expected to be defined in 213 future documents. 215 One feature that is present in CMS [RFC5652] that is not present in 216 this standard is a digest structure. This omission is deliberate. 217 It is better for the structure to be defined in each document as 218 different protocols will want to include a different set of fields as 219 part of the structure. While an algorithm identifier and the digesst 220 value are going to be common to all applications, the two values may 221 not always be adjacent as the algorithm could be defined once with 222 multiple values. Applications may additionally want to define 223 additional data fields as part of the stucture. A common structure 224 is going to include a URI or other pointer to where the data that is 225 being hashed is kept, allowing this to be application specific. 227 1.1. Design Changes from JOSE 229 * Define a single top message structure so that encrypted, signed, 230 and MACed messages can easily be identified and still have a 231 consistent view. 233 * Signed messages distinguish between the protected and unprotected 234 parameters that relate to the content from those that relate to 235 the signature. 237 * MACed messages are separated from signed messages. 239 * MACed messages have the ability to use the same set of recipient 240 algorithms as enveloped messages for obtaining the MAC 241 authentication key. 243 * Use binary encodings for binary data rather than base64url 244 encodings. 246 * Combine the authentication tag for encryption algorithms with the 247 ciphertext. 249 * The set of cryptographic algorithms has been expanded in some 250 directions and trimmed in others. 252 1.2. Changes from RFC8152 254 * Split the orignal document into this document and 255 [I-D.ietf-cose-rfc8152bis-algs]. 257 * Add some text describing why there is no digest structure defined 258 by COSE. 260 * Rearrange the text around counter signatures and define a CBOR Tag 261 for a standalone countersignature. 263 1.3. Requirements Terminology 265 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 266 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 267 "OPTIONAL" in this document are to be interpreted as described in BCP 268 14 [RFC2119] [RFC8174] when, and only when, they appear in all 269 capitals, as shown here. 271 1.4. CBOR Grammar 273 There was not a standard CBOR grammar available when COSE was 274 originally written. For that reason the CBOR structures defined here 275 are described in prose. Since that time CBOR Data Definition 276 Language (CDDL) [RFC8610] has been published as an RFC. The CBOR 277 grammar presented in this document is compatible with CDDL. 279 The document was developed by first working on the grammar and then 280 developing the prose to go with it. An artifact of this is that the 281 prose was written using the primitive type strings defined by CBOR 282 Data Definition Language (CDDL) [RFC8610]. In this specification, 283 the following primitive types are used: 285 any -- non-specific value that permits all CBOR values to be 286 placed here. 288 bool -- a boolean value (true: major type 7, value 21; false: 289 major type 7, value 20). 291 bstr -- byte string (major type 2). 293 int -- an unsigned integer or a negative integer. 295 nil -- a null value (major type 7, value 22). 297 nint -- a negative integer (major type 1). 299 tstr -- a UTF-8 text string (major type 3). 301 uint -- an unsigned integer (major type 0). 303 Two syntaxes from CDDL appear in this document as shorthand. These 304 are: 306 FOO / BAR -- indicates that either FOO or BAR can appear here. 308 [+ FOO] -- indicates that the type FOO appears one or more times 309 in an array. 311 Two of the constraints defined by CDDL are also used in this 312 document. These are: 314 type1 .cbor type2 -- indicates that the contents of type1, usually 315 bstr, contains a value of type2. 317 type1 .size integer -- indicates that the contents of type1 is 318 integer bytes long 320 As well as the prose description, a version of a CBOR grammar is 321 presented in CDDL. The CDDL grammar is informational; the prose 322 description is normative. 324 The collected CDDL can be extracted from the XML version of this 325 document via the following XPath expression below. (Depending on the 326 XPath evaluator one is using, it may be necessary to deal with > 327 as an entity.) 329 //sourcecode[@type='CDDL']/text() 331 CDDL expects the initial non-terminal symbol to be the first symbol 332 in the file. For this reason, the first fragment of CDDL is 333 presented here. 335 start = COSE_Messages / COSE_Key / COSE_KeySet / Internal_Types 337 ; This is defined to make the tool quieter: 338 Internal_Types = Sig_structure / Enc_structure / MAC_structure 339 The non-terminal Internal_Types is defined for dealing with the 340 automated validation tools used during the writing of this document. 341 It references those non-terminals that are used for security 342 computations but are not emitted for transport. 344 1.5. CBOR-Related Terminology 346 In JSON, maps are called objects and only have one kind of map key: a 347 string. In COSE, we use strings, negative integers, and unsigned 348 integers as map keys. The integers are used for compactness of 349 encoding and easy comparison. The inclusion of strings allows for an 350 additional range of short encoded values to be used as well. Since 351 the word "key" is mainly used in its other meaning, as a 352 cryptographic key, we use the term "label" for this usage as a map 353 key. 355 The presence of a label in a COSE map that is not a string or an 356 integer is an error. Applications can either fail processing or 357 process messages by ignoring incorrect labels; however, they MUST NOT 358 create messages with incorrect labels. 360 A CDDL grammar fragment defines the non-terminal 'label', as in the 361 previous paragraph, and 'values', which permits any value to be used. 363 label = int / tstr 364 values = any 366 1.6. Document Terminology 368 In this document, we use the following terminology: 370 Byte is a synonym for octet. 372 Constrained Application Protocol (CoAP) is a specialized web transfer 373 protocol for use in constrained systems. It is defined in [RFC7252]. 375 Authenticated Encryption (AE) [RFC5116] algorithms are those 376 encryption algorithms that provide an authentication check of the 377 contents algorithm with the encryption service. 379 Authenticated Encryption with Associated Data (AEAD) [RFC5116] 380 algorithms provide the same content authentication service as AE 381 algorithms, but they additionally provide for authentication of non- 382 encrypted data as well. 384 Context is used throughout the document to represent information that 385 is not part of the COSE message. Information which is part of the 386 context can come from several different sources including: Protocol 387 interactions, associated key structures and program configuration. 388 The context to use can be implicit, identified using the 'kid 389 context' header field defined in [RFC8613], or identified by a 390 protocol specific identifier. Context should generally be included 391 in the cryptographic configuration, for more details see Section 4.3. 393 2. Basic COSE Structure 395 The COSE object structure is designed so that there can be a large 396 amount of common code when parsing and processing the different types 397 of security messages. All of the message structures are built on the 398 CBOR array type. The first three elements of the array always 399 contain the same information: 401 1. The set of protected header parameters wrapped in a bstr. 403 2. The set of unprotected header parameters as a map. 405 3. The content of the message. The content is either the plaintext 406 or the ciphertext as appropriate. The content may be detached 407 (i.e. transported separately from the COSE structure), but the 408 location is still used. The content is wrapped in a bstr when 409 present and is a nil value when detached. 411 Elements after this point are dependent on the specific message type. 413 COSE messages are built using the concept of layers to separate 414 different types of cryptographic concepts. As an example of how this 415 works, consider the COSE_Encrypt message (Section 6.1). This message 416 type is broken into two layers: the content layer and the recipient 417 layer. In the content layer, the plaintext is encrypted and 418 information about the encrypted message is placed. In the recipient 419 layer, the content encryption key (CEK) is encrypted and information 420 about how it is encrypted for each recipient is placed. A single 421 layer version of the encryption message COSE_Encrypt0 (Section 6.2) 422 is provided for cases where the CEK is pre-shared. 424 Identification of which type of message has been presented is done by 425 the following methods: 427 1. The specific message type is known from the context. This may be 428 defined by a marker in the containing structure or by 429 restrictions specified by the application protocol. 431 2. The message type is identified by a CBOR tag. Messages with a 432 CBOR tag are known in this specification as tagged messages, 433 while those without the CBOR tag are known as untagged messages. 435 This document defines a CBOR tag for each of the message 436 structures. These tags can be found in Table 1. 438 3. When a COSE object is carried in a media type of 'application/ 439 cose', the optional parameter 'cose-type' can be used to identify 440 the embedded object. The parameter is OPTIONAL if the tagged 441 version of the structure is used. The parameter is REQUIRED if 442 the untagged version of the structure is used. The value to use 443 with the parameter for each of the structures can be found in 444 Table 1. 446 4. When a COSE object is carried as a CoAP payload, the CoAP 447 Content-Format Option can be used to identify the message 448 content. The CoAP Content-Format values can be found in Table 2. 449 The CBOR tag for the message structure is not required as each 450 security message is uniquely identified. 452 +------+------------------+-----------------------+-------------+ 453 | CBOR | cose-type | Data Item | Semantics | 454 | Tag | | | | 455 +======+==================+=======================+=============+ 456 | 98 | cose-sign | COSE_Sign | COSE Signed | 457 | | | | Data Object | 458 +------+------------------+-----------------------+-------------+ 459 | 18 | cose-sign1 | COSE_Sign1 | COSE Single | 460 | | | | Signer Data | 461 | | | | Object | 462 +------+------------------+-----------------------+-------------+ 463 | 96 | cose-encrypt | COSE_Encrypt | COSE | 464 | | | | Encrypted | 465 | | | | Data Object | 466 +------+------------------+-----------------------+-------------+ 467 | 16 | cose-encrypt0 | COSE_Encrypt0 | COSE Single | 468 | | | | Recipient | 469 | | | | Encrypted | 470 | | | | Data Object | 471 +------+------------------+-----------------------+-------------+ 472 | 97 | cose-mac | COSE_Mac | COSE MACed | 473 | | | | Data Object | 474 +------+------------------+-----------------------+-------------+ 475 | 17 | cose-mac0 | COSE_Mac0 | COSE Mac w/ | 476 | | | | o | 477 | | | | Recipients | 478 | | | | Object | 479 +------+------------------+-----------------------+-------------+ 480 | TBD0 | cose-countersign | COSE_Countersignature | COSE | 481 | | | | standalone | 482 | | | | counter | 483 | | | | signature | 484 +------+------------------+-----------------------+-------------+ 486 Table 1: COSE Message Identification 488 +---------------------------+----------+-----+------------+ 489 | Media Type | Encoding | ID | Reference | 490 +===========================+==========+=====+============+ 491 | application/cose; cose- | | 98 | [[THIS | 492 | type="cose-sign" | | | DOCUMENT]] | 493 +---------------------------+----------+-----+------------+ 494 | application/cose; cose- | | 18 | [[THIS | 495 | type="cose-sign1" | | | DOCUMENT]] | 496 +---------------------------+----------+-----+------------+ 497 | application/cose; cose- | | 96 | [[THIS | 498 | type="cose-encrypt" | | | DOCUMENT]] | 499 +---------------------------+----------+-----+------------+ 500 | application/cose; cose- | | 16 | [[THIS | 501 | type="cose-encrypt0" | | | DOCUMENT]] | 502 +---------------------------+----------+-----+------------+ 503 | application/cose; cose- | | 97 | [[THIS | 504 | type="cose-mac" | | | DOCUMENT]] | 505 +---------------------------+----------+-----+------------+ 506 | application/cose; cose- | | 17 | [[THIS | 507 | type="cose-mac0" | | | DOCUMENT]] | 508 +---------------------------+----------+-----+------------+ 509 | application/cose-key | | 101 | [[THIS | 510 | | | | DOCUMENT]] | 511 +---------------------------+----------+-----+------------+ 512 | application/cose-key-set | | 102 | [[THIS | 513 | | | | DOCUMENT]] | 514 +---------------------------+----------+-----+------------+ 516 Table 2: CoAP Content-Formats for COSE 518 The following CDDL fragment identifies all of the top messages 519 defined in this document. Separate non-terminals are defined for the 520 tagged and the untagged versions of the messages. 522 COSE_Messages = COSE_Untagged_Message / COSE_Tagged_Message 524 COSE_Untagged_Message = COSE_Sign / COSE_Sign1 / 525 COSE_Encrypt / COSE_Encrypt0 / 526 COSE_Mac / COSE_Mac0 / COSE_Countersignature 528 COSE_Tagged_Message = COSE_Sign_Tagged / COSE_Sign1_Tagged / 529 COSE_Encrypt_Tagged / COSE_Encrypt0_Tagged / 530 COSE_Mac_Tagged / COSE_Mac0_Tagged / COSE_Countersignature_Tagged 532 3. Header Parameters 534 The structure of COSE has been designed to have two buckets of 535 information that are not considered to be part of the payload itself, 536 but are used for holding information about content, algorithms, keys, 537 or evaluation hints for the processing of the layer. These two 538 buckets are available for use in all of the structures except for 539 keys. While these buckets are present, they may not all be usable in 540 all instances. For example, while the protected bucket is defined as 541 part of the recipient structure, some of the algorithms used for 542 recipient structures do not provide for authenticated data. If this 543 is the case, the protected bucket is left empty. 545 Both buckets are implemented as CBOR maps. The map key is a 'label' 546 (Section 1.5). The value portion is dependent on the definition for 547 the label. Both maps use the same set of label/value pairs. The 548 integer and string values for labels have been divided into several 549 sections including a standard range, a private range, and a range 550 that is dependent on the algorithm selected. The defined labels can 551 be found in the "COSE Header Parameters" IANA registry 552 (Section 12.2). 554 The two buckets are: 556 protected: Contains parameters about the current layer that are 557 cryptographically protected. This bucket MUST be empty if it is 558 not going to be included in a cryptographic computation. This 559 bucket is encoded in the message as a binary object. This value 560 is obtained by CBOR encoding the protected map and wrapping it in 561 a bstr object. Senders SHOULD encode a zero-length map as a zero- 562 length byte string rather than as a zero-length map (encoded as 563 h'a0'). The zero-length binary encoding is preferred because it 564 is both shorter and the version used in the serialization 565 structures for cryptographic computation. After encoding the map, 566 the value is wrapped in the binary object. Recipients MUST accept 567 both a zero-length binary value and a zero-length map encoded in 568 the binary value. The wrapping allows for the encoding of the 569 protected map to be transported with a greater chance that it will 570 not be altered in transit. (Badly behaved intermediates could 571 decode and re-encode, but this will result in a failure to verify 572 unless the re-encoded byte string is identical to the decoded byte 573 string.) This avoids the problem of all parties needing to be 574 able to do a common canonical encoding. 576 unprotected: Contains parameters about the current layer that are 577 not cryptographically protected. 579 Only parameters that deal with the current layer are to be placed at 580 that layer. As an example of this, the parameter 'content type' 581 describes the content of the message being carried in the message. 582 As such, this parameter is placed only in the content layer and is 583 not placed in the recipient or signature layers. In principle, one 584 should be able to process any given layer without reference to any 585 other layer. With the exception of the COSE_Sign structure, the only 586 data that needs to cross layers is the cryptographic key. 588 The buckets are present in all of the security objects defined in 589 this document. The fields in order are the 'protected' bucket (as a 590 CBOR 'bstr' type) and then the 'unprotected' bucket (as a CBOR 'map' 591 type). The presence of both buckets is required. The parameters 592 that go into the buckets come from the IANA "COSE Header Parameters" 593 registry (Section 12.2). Some common parameters are defined in the 594 next section. 596 Labels in each of the maps MUST be unique. When processing messages, 597 if a label appears multiple times, the message MUST be rejected as 598 malformed. Applications SHOULD verify that the same label does not 599 occur in both the protected and unprotected headers. If the message 600 is not rejected as malformed, attributes MUST be obtained from the 601 protected bucket before they are obtained from the unprotected 602 bucket. 604 The following CDDL fragment represents the two header buckets. A 605 group "Headers" is defined in CDDL that represents the two buckets in 606 which attributes are placed. This group is used to provide these two 607 fields consistently in all locations. A type is also defined that 608 represents the map of common headers. 610 Headers = ( 611 protected : empty_or_serialized_map, 612 unprotected : header_map 613 ) 615 header_map = { 616 Generic_Headers, 617 * label => values 618 } 620 empty_or_serialized_map = bstr .cbor header_map / bstr .size 0 622 3.1. Common COSE Headers Parameters 624 This section defines a set of common header parameters. A summary of 625 these parameters can be found in Table 3. This table should be 626 consulted to determine the value of label and the type of the value. 628 The set of header parameters defined in this section are: 630 alg: This parameter is used to indicate the algorithm used for the 631 security processing. This parameter MUST be authenticated where 632 the ability to do so exists. This support is provided by AEAD 633 algorithms or construction (COSE_Sign, COSE_Sign1, COSE_Mac, and 634 COSE_Mac0). This authentication can be done either by placing the 635 parameter in the protected header bucket or as part of the 636 externally supplied data. The value is taken from the "COSE 637 Algorithms" registry (see [COSE.Algorithms]). 639 crit: The parameter is used to indicate which protected header 640 labels an application that is processing a message is required to 641 understand. Parameters defined in this document do not need to be 642 included as they should be understood by all implementations. 643 When present, this parameter MUST be placed in the protected 644 header bucket. The array MUST have at least one value in it. 646 Not all labels need to be included in the 'crit' parameter. The 647 rules for deciding which header labels are placed in the array 648 are: 650 * Integer labels in the range of 0 to 7 SHOULD be omitted. 652 * Integer labels in the range -1 to -128 can be omitted as they 653 are algorithm dependent. If an application can correctly 654 process an algorithm, it can be assumed that it will correctly 655 process all of the common parameters associated with that 656 algorithm. Integer labels in the range -129 to -65536 SHOULD 657 be included as these would be less common parameters that might 658 not be generally supported. 660 * Labels for parameters required for an application MAY be 661 omitted. Applications should have a statement if the label can 662 be omitted. 664 The header parameter values indicated by 'crit' can be processed 665 by either the security library code or an application using a 666 security library; the only requirement is that the parameter is 667 processed. If the 'crit' value list includes a value for which 668 the parameter is not in the protected bucket, this is a fatal 669 error in processing the message. 671 content type: This parameter is used to indicate the content type of 672 the data in the payload or ciphertext fields. Integers are from 673 the "CoAP Content-Formats" IANA registry table [COAP.Formats]. 674 Text values following the syntax of "/" 675 where and are defined in Section 4.2 of 677 [RFC6838]. Leading and trailing whitespace is also omitted. 678 Textual content values along with parameters and subparameters can 679 be located using the IANA "Media Types" registry. Applications 680 SHOULD provide this parameter if the content structure is 681 potentially ambiguous. 683 kid: This parameter identifies one piece of data that can be used as 684 input to find the needed cryptographic key. The value of this 685 parameter can be matched against the 'kid' member in a COSE_Key 686 structure. Other methods of key distribution can define an 687 equivalent field to be matched. Applications MUST NOT assume that 688 'kid' values are unique. There may be more than one key with the 689 same 'kid' value, so all of the keys associated with this 'kid' 690 may need to be checked. The internal structure of 'kid' values is 691 not defined and cannot be relied on by applications. Key 692 identifier values are hints about which key to use. This is not a 693 security-critical field. For this reason, it can be placed in the 694 unprotected headers bucket. 696 IV: This parameter holds the Initialization Vector (IV) value. For 697 some symmetric encryption algorithms, this may be referred to as a 698 nonce. The IV can be placed in the unprotected header as 699 modifying the IV will cause the decryption to yield plaintext that 700 is readily detectable as garbled. 702 Partial IV: This parameter holds a part of the IV value. When using 703 the COSE_Encrypt0 structure, a portion of the IV can be part of 704 the context associated with the key (Context IV) while a portion 705 can be changed with each message (Parital IV). This field is used 706 to carry a value that causes the IV to be changed for each 707 message. The Parital IV can be placed in the unprotected header 708 as modifying the value will cause the decryption to yield 709 plaintext that is readily detectable as garbled. The 710 'Initialization Vector' and 'Partial Initialization Vector' 711 parameters MUST NOT both be present in the same security layer. 713 The message IV is generated by the following steps: 715 1. Left-pad the Partial IV with zeros to the length of IV. 717 2. XOR the padded Partial IV with the context IV. 719 counter signature: This parameter holds one or more counter 720 signature values. Counter signatures provide a method of having a 721 second party sign some data. The counter signature parameter can 722 occur as an unprotected attribute in any of the following 723 structures: COSE_Sign1, COSE_Signature, COSE_Encrypt, 724 COSE_recipient, COSE_Encrypt0, COSE_Mac, and COSE_Mac0. These 725 structures all have the same beginning elements, so that a 726 consistent calculation of the counter signature can be computed. 727 Details on counter signatures are found in Section 5. 729 +---------+-----+----------------+-----------------+----------------+ 730 | Name |Label| Value Type | Value Registry | Description | 731 +=========+=====+================+=================+================+ 732 | alg | 1 | int / tstr | COSE Algorithms | Cryptographic | 733 | | | | registry |algorithm to use| 734 +---------+-----+----------------+-----------------+----------------+ 735 | crit | 2 | [+ label] | COSE Header |Critical headers| 736 | | | | Parameters |to be understood| 737 | | | | registry | | 738 +---------+-----+----------------+-----------------+----------------+ 739 | content | 3 | tstr / uint | CoAP Content- |Content type of | 740 | type | | |Formats or Media | the payload | 741 | | | |Types registries | | 742 +---------+-----+----------------+-----------------+----------------+ 743 | kid | 4 | bstr | | Key identifier | 744 +---------+-----+----------------+-----------------+----------------+ 745 | IV | 5 | bstr | | Full | 746 | | | | | Initialization | 747 | | | | | Vector | 748 +---------+-----+----------------+-----------------+----------------+ 749 | Partial | 6 | bstr | | Partial | 750 | IV | | | | Initialization | 751 | | | | | Vector | 752 +---------+-----+----------------+-----------------+----------------+ 753 | counter | 7 |COSE_Signature /| | CBOR-encoded | 754 |signature| | [+ | | signature | 755 | | |COSE_Signature ]| | structure | 756 +---------+-----+----------------+-----------------+----------------+ 758 Table 3: Common Header Parameters 760 The CDDL fragment that represents the set of headers defined in this 761 section is given below. Each of the headers is tagged as optional 762 because they do not need to be in every map; headers required in 763 specific maps are discussed above. 765 Generic_Headers = ( 766 ? 1 => int / tstr, ; algorithm identifier 767 ? 2 => [+label], ; criticality 768 ? 3 => tstr / int, ; content type 769 ? 4 => bstr, ; key identifier 770 ? 5 => bstr, ; IV 771 ? 6 => bstr, ; Partial IV 772 ? 7 => COSE_Signature / [+COSE_Signature] ; Counter signature 773 ) 775 4. Signing Objects 777 COSE supports two different signature structures. COSE_Sign allows 778 for one or more signatures to be applied to the same content. 779 COSE_Sign1 is restricted to a single signer. The structures cannot 780 be converted between each other; as the signature computation 781 includes a parameter identifying which structure is being used, the 782 converted structure will fail signature validation. 784 4.1. Signing with One or More Signers 786 The COSE_Sign structure allows for one or more signatures to be 787 applied to a message payload. Parameters relating to the content and 788 parameters relating to the signature are carried along with the 789 signature itself. These parameters may be authenticated by the 790 signature, or just present. An example of a parameter about the 791 content is the content type. Examples of parameters about the 792 signature would be the algorithm and key used to create the signature 793 and counter signatures. 795 RFC 5652 indicates that: 797 | When more than one signature is present, the successful validation 798 | of one signature associated with a given signer is usually treated 799 | as a successful signature by that signer. However, there are some 800 | application environments where other rules are needed. An 801 | application that employs a rule other than one valid signature for 802 | each signer must specify those rules. Also, where simple matching 803 | of the signer identifier is not sufficient to determine whether 804 | the signatures were generated by the same signer, the application 805 | specification must describe how to determine which signatures were 806 | generated by the same signer. Support for different communities 807 | of recipients is the primary reason that signers choose to include 808 | more than one signature. 810 For example, the COSE_Sign structure might include signatures 811 generated with the Edwards-curve Digital Signature Algorithm (EdDSA) 812 [RFC8032] and with the Elliptic Curve Digital Signature Algorithm 813 (ECDSA) [DSS]. This allows recipients to verify the signature 814 associated with one algorithm or the other. More-detailed 815 information on multiple signature evaluations can be found in 816 [RFC5752]. 818 The signature structure can be encoded as either tagged or untagged 819 depending on the context it will be used in. A tagged COSE_Sign 820 structure is identified by the CBOR tag 98. The CDDL fragment that 821 represents this is: 823 COSE_Sign_Tagged = #6.98(COSE_Sign) 825 A COSE Signed Message is defined in two parts. The CBOR object that 826 carries the body and information about the body is called the 827 COSE_Sign structure. The CBOR object that carries the signature and 828 information about the signature is called the COSE_Signature 829 structure. Examples of COSE Signed Messages can be found in 830 Appendix C.1. 832 The COSE_Sign structure is a CBOR array. The fields of the array in 833 order are: 835 protected: This is as described in Section 3. 837 unprotected: This is as described in Section 3. 839 payload: This field contains the serialized content to be signed. 840 If the payload is not present in the message, the application is 841 required to supply the payload separately. The payload is wrapped 842 in a bstr to ensure that it is transported without changes. If 843 the payload is transported separately ("detached content"), then a 844 nil CBOR object is placed in this location, and it is the 845 responsibility of the application to ensure that it will be 846 transported without changes. 848 Note: When a signature with a message recovery algorithm is used 849 (Section 9.1), the maximum number of bytes that can be recovered 850 is the length of the payload. The size of the payload is reduced 851 by the number of bytes that will be recovered. If all of the 852 bytes of the payload are consumed, then the payload is encoded as 853 a zero-length binary string rather than as being absent. 855 signatures: This field is an array of signatures. Each signature is 856 represented as a COSE_Signature structure. 858 The CDDL fragment that represents the above text for COSE_Sign 859 follows. 861 COSE_Sign = [ 862 Headers, 863 payload : bstr / nil, 864 signatures : [+ COSE_Signature] 865 ] 867 The COSE_Signature structure is a CBOR array. The fields of the 868 array in order are: 870 protected: This is as described in Section 3. 872 unprotected: This is as described in Section 3. 874 signature: This field contains the computed signature value. The 875 type of the field is a bstr. Algorithms MUST specify padding if 876 the signature value is not a multiple of 8 bits. 878 The CDDL fragment that represents the above text for COSE_Signature 879 follows. 881 COSE_Signature = [ 882 Headers, 883 signature : bstr 884 ] 886 4.2. Signing with One Signer 888 The COSE_Sign1 signature structure is used when only one signature is 889 going to be placed on a message. The parameters dealing with the 890 content and the signature are placed in the same pair of buckets 891 rather than having the separation of COSE_Sign. 893 The structure can be encoded as either tagged or untagged depending 894 on the context it will be used in. A tagged COSE_Sign1 structure is 895 identified by the CBOR tag 18. The CDDL fragment that represents 896 this is: 898 COSE_Sign1_Tagged = #6.18(COSE_Sign1) 900 The CBOR object that carries the body, the signature, and the 901 information about the body and signature is called the COSE_Sign1 902 structure. Examples of COSE_Sign1 messages can be found in 903 Appendix C.2. 905 The COSE_Sign1 structure is a CBOR array. The fields of the array in 906 order are: 908 protected: This is as described in Section 3. 910 unprotected: This is as described in Section 3. 912 payload: This is as described in Section 4.1. 914 signature: This field contains the computed signature value. The 915 type of the field is a bstr. 917 The CDDL fragment that represents the above text for COSE_Sign1 918 follows. 920 COSE_Sign1 = [ 921 Headers, 922 payload : bstr / nil, 923 signature : bstr 924 ] 926 4.3. Externally Supplied Data 928 One of the features offered in the COSE document is the ability for 929 applications to provide additional data to be authenticated, but that 930 is not carried as part of the COSE object. The primary reason for 931 supporting this can be seen by looking at the CoAP message structure 932 [RFC7252], where the facility exists for options to be carried before 933 the payload. Examples of data that can be placed in this location 934 would be the CoAP code or CoAP options. If the data is in the header 935 section, then it is available for proxies to help in performing its 936 operations. For example, the Accept Option can be used by a proxy to 937 determine if an appropriate value is in the proxy's cache. But the 938 sender can cause a failure at the server if a proxy, or an attacker, 939 changes the set of accept values by including the field in the 940 application supplied data. 942 This document describes the process for using a byte array of 943 externally supplied authenticated data; the method of constructing 944 the byte array is a function of the application. Applications that 945 use this feature need to define how the externally supplied 946 authenticated data is to be constructed. Such a construction needs 947 to take into account the following issues: 949 * If multiple items are included, applications need to ensure that 950 the same byte string cannot produced if there are different 951 inputs. This would occur by appending the strings 'AB' and 'CDE' 952 or by appending the strings 'ABC' and 'DE'. This is usually 953 addressed by making fields a fixed width and/or encoding the 954 length of the field as part of the output. Using options from 955 CoAP [RFC7252] as an example, these fields use a TLV structure so 956 they can be concatenated without any problems. 958 * If multiple items are included, an order for the items needs to be 959 defined. Using options from CoAP as an example, an application 960 could state that the fields are to be ordered by the option 961 number. 963 * Applications need to ensure that the byte string is going to be 964 the same on both sides. Using options from CoAP might give a 965 problem if the same relative numbering is kept. An intermediate 966 node could insert or remove an option, changing how the relative 967 number is done. An application would need to specify that the 968 relative number must be re-encoded to be relative only to the 969 options that are in the external data. 971 4.4. Signing and Verification Process 973 In order to create a signature, a well-defined byte string is needed. 974 The Sig_structure is used to create the canonical form. This signing 975 and verification process takes in the body information (COSE_Sign or 976 COSE_Sign1), the signer information (COSE_Signature), and the 977 application data (external source). A Sig_structure is a CBOR array. 978 The fields of the Sig_structure in order are: 980 1. A text string identifying the context of the signature. The 981 context string is: 983 "Signature" for signatures using the COSE_Signature structure. 985 "Signature1" for signatures using the COSE_Sign1 structure. 987 "CounterSignature" for signatures used as counter signature 988 attributes. 990 "CounterSignature0" for signatures used as CounterSignature0 991 attributes. 993 2. The protected attributes from the body structure encoded in a 994 bstr type. If there are no protected attributes, a bstr of 995 length zero is used. 997 3. The protected attributes from the signer structure encoded in a 998 bstr type. If there are no protected attributes, a bstr of 999 length zero is used. This field is omitted for the COSE_Sign1 1000 signature structure and CounterSignature0 attributes. 1002 4. The protected attributes from the application encoded in a bstr 1003 type. If this field is not supplied, it defaults to a zero- 1004 length binary string. (See Section 4.3 for application guidance 1005 on constructing this field.) 1007 5. The payload to be signed encoded in a bstr type. The payload is 1008 placed here independent of how it is transported. 1010 The CDDL fragment that describes the above text is: 1012 Sig_structure = [ 1013 context : "Signature" / "Signature1" / "CounterSignature" / 1014 "CounterSignature0", 1015 body_protected : empty_or_serialized_map, 1016 ? sign_protected : empty_or_serialized_map, 1017 external_aad : bstr, 1018 payload : bstr 1019 ] 1021 How to compute a signature: 1023 1. Create a Sig_structure and populate it with the appropriate 1024 fields. 1026 2. Create the value ToBeSigned by encoding the Sig_structure to a 1027 byte string, using the encoding described in Section 10. 1029 3. Call the signature creation algorithm passing in K (the key to 1030 sign with), alg (the algorithm to sign with), and ToBeSigned (the 1031 value to sign). 1033 4. Place the resulting signature value in the correct location. 1034 This is the 'signature' field of the COSE_Signature, COSE_Sign1 1035 or COSE_Countersignature structures. This is the value of the 1036 Countersignature0 attribute. 1038 The steps for verifying a signature are: 1040 1. Create a Sig_structure object and populate it with the 1041 appropriate fields. 1043 2. Create the value ToBeSigned by encoding the Sig_structure to a 1044 byte string, using the encoding described in Section 10. 1046 3. Call the signature verification algorithm passing in K (the key 1047 to verify with), alg (the algorithm used sign with), ToBeSigned 1048 (the value to sign), and sig (the signature to be verified). 1050 In addition to performing the signature verification, the application 1051 performs the appropriate checks to ensure that the key is correctly 1052 paired with the signing identity and that the signing identity is 1053 authorized before performing actions. 1055 5. Counter Signatures 1057 COSE supports two different forms for counter signatures. Full 1058 countersignatures use the structure COSE_Countersign. This is same 1059 structure as COSE_Signature and thus it can have protected 1060 attributes, chained countersignatures and information about 1061 identifying the key. Abbreviated countersignatures use the structure 1062 COSE_Countersign1. This structure only contains the signature value 1063 and nothing else. The structures cannot be converted between each 1064 other; as the signature computation includes a parameter identifying 1065 which structure is being used, the converted structure will fail 1066 signature validation. 1068 COSE was designed for uniformity in how the data strutures are 1069 specified. One result of this is that for COSE one can expand the 1070 concept of countersignatures beyond just the idea of signing a 1071 signature to being able to sign most of the structures without having 1072 to create a new signing layer. When creating a countersignature, one 1073 needs to be clear about the security properties that result. When 1074 done on a COSE_Signature, the normal countersignature semantics are 1075 preserved. That is the countersignature makes a statement about the 1076 existence of a signature and, when used as a timestamp, a time point 1077 at which the signature exists. When done on a COSE_Mac or a 1078 COSE_Mac0, one effectively upgrades the MAC operation to a signature 1079 operation. When done on a COSE_Encrypt or COSE_Encrypt0, the 1080 existence of the encrypted data is attested to. It should be noted 1081 that there is a big difference between attesting to the encrypted 1082 data as opposed to attesting to the unencrypted data. If the latter 1083 is what is desired, then one needs to apply a signature to the data 1084 and then encrypt that. It is always possible to construct cases 1085 where the decryption is successful, while providing completely 1086 different answers by using a different key. This situation is not 1087 detectable by a countersignature on the encrypted data. 1089 5.1. Full Countersignatures 1091 The COSE_Countersignature structure allows for the same set of 1092 capabilities of a COSE_Signature. This means that all of the 1093 capabilities of a signature are duplicated with this structure. 1094 Specifically, the countersigner does not need to be related to the 1095 producer of what is being counter signed as key and algorithm 1096 identification can be placed in the countersignature attributes. 1097 This also means that the countersignature can itself be 1098 countersigned. This is a feature required by protocols such as long- 1099 term archiving services. More information on how this is used can be 1100 found in the evidence record syntax described in [RFC4998]. 1102 The full countersignature structure can be encoded as either a tagged 1103 or untagged depending on the context it is used in. A tagged 1104 COSE_Countersign structure is identified by the CBOR tag TBD0. The 1105 CDDL fragment for full countersignatures is: 1107 COSE_CounterSignature_Tagged = #6.98(COSE_CounterSignature) 1108 COSE_CounterSignature = COSE_Signature 1110 The details of the fields of a countersignature can be found in 1111 Section 4.1. The process of creating and validating abbreviated 1112 countersignatures is defined in Section 4.4. 1114 An example of a counter signature on a signature can be found in 1115 Appendix C.1.3. An example of a counter signature in an encryption 1116 object can be found in Appendix C.3.3. 1118 It should be noted that only a signature algorithm with appendix (see 1119 Section 9.1) can be used for counter signatures. This is because the 1120 body should be able to be processed without having to evaluate the 1121 counter signature, and this is not possible for signature schemes 1122 with message recovery. 1124 5.2. Abbreviated Countersignatures 1126 Abbreviated countersignatures were designed primarily to deal with 1127 the problem of having group encrypted messaging, but still needing to 1128 know who originated the message. The objective was to keep the 1129 countersignature as small as possible while still providing the 1130 needed security. For abbreviated countersignatures, there is no 1131 provision for any protected attributes related to the signing 1132 operation. Instead, the parameters for computing or verifying the 1133 abbreviated countersignature are inferred from the same context used 1134 to describe the encryption, signature, or MAC processing. 1136 The byte string representing the signature value is placed in the 1137 CounterSignature0 attribute. This attribute is then encoded as an 1138 unprotected header. The attribute is defined below. 1140 The process of creating and validating abbreviated countersignatures 1141 is defined in Section 4.4. 1143 +-------------------+-------+------------+-------+------------------+ 1144 | Name | Label | Value | Value | Description | 1145 | | | Type | | | 1146 +===================+=======+============+=======+==================+ 1147 | CounterSignature0 | 9 | bstr | | Abbreviated | 1148 | | | | | Countersignature | 1149 +-------------------+-------+------------+-------+------------------+ 1151 Table 4: Header Parameter for CounterSignature0 1153 6. Encryption Objects 1155 COSE supports two different encryption structures. COSE_Encrypt0 is 1156 used when a recipient structure is not needed because the key to be 1157 used is known implicitly. COSE_Encrypt is used the rest of the time. 1158 This includes cases where there are multiple recipients or a 1159 recipient algorithm other than direct (i.e. pre-shared secret) is 1160 used. 1162 6.1. Enveloped COSE Structure 1164 The enveloped structure allows for one or more recipients of a 1165 message. There are provisions for parameters about the content and 1166 parameters about the recipient information to be carried in the 1167 message. The protected parameters associated with the content are 1168 authenticated by the content encryption algorithm. The protected 1169 parameters associated with the recipient are authenticated by the 1170 recipient algorithm (when the algorithm supports it). Examples of 1171 parameters about the content are the type of the content and the 1172 content encryption algorithm. Examples of parameters about the 1173 recipient are the recipient's key identifier and the recipient's 1174 encryption algorithm. 1176 The same techniques and nearly the same structure is used for 1177 encrypting both the plaintext and the keys. This is different from 1178 the approach used by both "Cryptographic Message Syntax (CMS)" 1179 [RFC5652] and "JSON Web Encryption (JWE)" [RFC7516] where different 1180 structures are used for the content layer and for the recipient 1181 layer. Two structures are defined: COSE_Encrypt to hold the 1182 encrypted content and COSE_recipient to hold the encrypted keys for 1183 recipients. Examples of encrypted messages can be found in 1184 Appendix C.3. 1186 The COSE_Encrypt structure can be encoded as either tagged or 1187 untagged depending on the context it will be used in. A tagged 1188 COSE_Encrypt structure is identified by the CBOR tag 96. The CDDL 1189 fragment that represents this is: 1191 COSE_Encrypt_Tagged = #6.96(COSE_Encrypt) 1193 The COSE_Encrypt structure is a CBOR array. The fields of the array 1194 in order are: 1196 protected: This is as described in Section 3. 1198 unprotected: This is as described in Section 3. 1200 ciphertext: This field contains the ciphertext encoded as a bstr. 1201 If the ciphertext is to be transported independently of the 1202 control information about the encryption process (i.e., detached 1203 content), then the field is encoded as a nil value. 1205 recipients: This field contains an array of recipient information 1206 structures. The type for the recipient information structure is a 1207 COSE_recipient. 1209 The CDDL fragment that corresponds to the above text is: 1211 COSE_Encrypt = [ 1212 Headers, 1213 ciphertext : bstr / nil, 1214 recipients : [+COSE_recipient] 1215 ] 1217 The COSE_recipient structure is a CBOR array. The fields of the 1218 array in order are: 1220 protected: This is as described in Section 3. 1222 unprotected: This is as described in Section 3. 1224 ciphertext: This field contains the encrypted key encoded as a bstr. 1225 All encoded keys are symmetric keys; the binary value of the key 1226 is the content. If there is not an encrypted key, then this field 1227 is encoded as a nil value. 1229 recipients: This field contains an array of recipient information 1230 structures. The type for the recipient information structure is a 1231 COSE_recipient (an example of this can be found in Appendix B). 1232 If there are no recipient information structures, this element is 1233 absent. 1235 The CDDL fragment that corresponds to the above text for 1236 COSE_recipient is: 1238 COSE_recipient = [ 1239 Headers, 1240 ciphertext : bstr / nil, 1241 ? recipients : [+COSE_recipient] 1242 ] 1244 6.1.1. Content Key Distribution Methods 1246 An encrypted message consists of an encrypted content and an 1247 encrypted CEK for one or more recipients. The CEK is encrypted for 1248 each recipient, using a key specific to that recipient. The details 1249 of this encryption depend on which class the recipient algorithm 1250 falls into. Specific details on each of the classes can be found in 1251 Section 9.5. A short summary of the five content key distribution 1252 methods is: 1254 direct: The CEK is the same as the identified previously distributed 1255 symmetric key or is derived from a previously distributed secret. 1256 No CEK is transported in the message. 1258 symmetric key-encryption keys (KEK): The CEK is encrypted using a 1259 previously distributed symmetric KEK. Also known as key wrap. 1261 key agreement: The recipient's public key and a sender's private key 1262 are used to generate a pairwise secret, a Key Derivation Function 1263 (KDF) is applied to derive a key, and then the CEK is either the 1264 derived key or encrypted by the derived key. 1266 key transport: The CEK is encrypted with the recipient's public key. 1268 passwords: The CEK is encrypted in a KEK that is derived from a 1269 password. As of when this document was published, no password 1270 algorithms have been defined. 1272 6.2. Single Recipient Encrypted 1274 The COSE_Encrypt0 encrypted structure does not have the ability to 1275 specify recipients of the message. The structure assumes that the 1276 recipient of the object will already know the identity of the key to 1277 be used in order to decrypt the message. If a key needs to be 1278 identified to the recipient, the enveloped structure ought to be 1279 used. 1281 Examples of encrypted messages can be found in Appendix C.3. 1283 The COSE_Encrypt0 structure can be encoded as either tagged or 1284 untagged depending on the context it will be used in. A tagged 1285 COSE_Encrypt0 structure is identified by the CBOR tag 16. The CDDL 1286 fragment that represents this is: 1288 COSE_Encrypt0_Tagged = #6.16(COSE_Encrypt0) 1290 The COSE_Encrypt0 structure is a CBOR array. The fields of the array 1291 in order are: 1293 protected: This is as described in Section 3. 1295 unprotected: This is as described in Section 3. 1297 ciphertext: This is as described in Section 6.1. 1299 The CDDL fragment for COSE_Encrypt0 that corresponds to the above 1300 text is: 1302 COSE_Encrypt0 = [ 1303 Headers, 1304 ciphertext : bstr / nil, 1305 ] 1307 6.3. How to Encrypt and Decrypt for AEAD Algorithms 1309 The encryption algorithm for AEAD algorithms is fairly simple. The 1310 first step is to create a consistent byte string for the 1311 authenticated data structure. For this purpose, we use an 1312 Enc_structure. The Enc_structure is a CBOR array. The fields of the 1313 Enc_structure in order are: 1315 1. A text string identifying the context of the authenticated data 1316 structure. The context string is: 1318 "Encrypt0" for the content encryption of a COSE_Encrypt0 data 1319 structure. 1321 "Encrypt" for the first layer of a COSE_Encrypt data structure 1322 (i.e., for content encryption). 1324 "Enc_Recipient" for a recipient encoding to be placed in an 1325 COSE_Encrypt data structure. 1327 "Mac_Recipient" for a recipient encoding to be placed in a 1328 MACed message structure. 1330 "Rec_Recipient" for a recipient encoding to be placed in a 1331 recipient structure. 1333 2. The protected attributes from the body structure encoded in a 1334 bstr type. If there are no protected attributes, a bstr of 1335 length zero is used. 1337 3. The protected attributes from the application encoded in a bstr 1338 type. If this field is not supplied, it defaults to a zero- 1339 length bstr. (See Section 4.3 for application guidance on 1340 constructing this field.) 1342 The CDDL fragment that describes the above text is: 1344 Enc_structure = [ 1345 context : "Encrypt" / "Encrypt0" / "Enc_Recipient" / 1346 "Mac_Recipient" / "Rec_Recipient", 1347 protected : empty_or_serialized_map, 1348 external_aad : bstr 1349 ] 1351 How to encrypt a message: 1353 1. Create an Enc_structure and populate it with the appropriate 1354 fields. 1356 2. Encode the Enc_structure to a byte string (Additional 1357 Authenticated Data (AAD)), using the encoding described in 1358 Section 10. 1360 3. Determine the encryption key (K). This step is dependent on the 1361 class of recipient algorithm being used. For: 1363 No Recipients: The key to be used is determined by the algorithm 1364 and key at the current layer. Examples are key transport keys 1365 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1366 secrets. 1368 Direct Encryption and Direct Key Agreement: The key is 1369 determined by the key and algorithm in the recipient 1370 structure. The encryption algorithm and size of the key to be 1371 used are inputs into the KDF used for the recipient. (For 1372 direct, the KDF can be thought of as the identity operation.) 1373 Examples of these algorithms are found in Sections 6.1.2 and 1374 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1376 Other: The key is randomly or pseudorandomly generated. 1378 4. Call the encryption algorithm with K (the encryption key), P (the 1379 plaintext), and AAD. Place the returned ciphertext into the 1380 'ciphertext' field of the structure. 1382 5. For recipients of the message, recursively perform the encryption 1383 algorithm for that recipient, using K (the encryption key) as the 1384 plaintext. 1386 How to decrypt a message: 1388 1. Create an Enc_structure and populate it with the appropriate 1389 fields. 1391 2. Encode the Enc_structure to a byte string (AAD), using the 1392 encoding described in Section 10. 1394 3. Determine the decryption key. This step is dependent on the 1395 class of recipient algorithm being used. For: 1397 No Recipients: The key to be used is determined by the algorithm 1398 and key at the current layer. Examples are key transport keys 1399 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1400 secrets. 1402 Direct Encryption and Direct Key Agreement: The key is 1403 determined by the key and algorithm in the recipient 1404 structure. The encryption algorithm and size of the key to be 1405 used are inputs into the KDF used for the recipient. (For 1406 direct, the KDF can be thought of as the identity operation.) 1408 Other: The key is determined by decoding and decrypting one of 1409 the recipient structures. 1411 4. Call the decryption algorithm with K (the decryption key to use), 1412 C (the ciphertext), and AAD. 1414 6.4. How to Encrypt and Decrypt for AE Algorithms 1416 How to encrypt a message: 1418 1. Verify that the 'protected' field is empty. 1420 2. Verify that there was no external additional authenticated data 1421 supplied for this operation. 1423 3. Determine the encryption key. This step is dependent on the 1424 class of recipient algorithm being used. For: 1426 No Recipients: The key to be used is determined by the algorithm 1427 and key at the current layer. Examples are key transport keys 1428 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1429 secrets. 1431 Direct Encryption and Direct Key Agreement: The key is 1432 determined by the key and algorithm in the recipient 1433 structure. The encryption algorithm and size of the key to be 1434 used are inputs into the KDF used for the recipient. (For 1435 direct, the KDF can be thought of as the identity operation.) 1436 Examples of these algorithms are found in Sections 6.1.2 and 1437 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1439 Other: The key is randomly generated. 1441 4. Call the encryption algorithm with K (the encryption key to use) 1442 and P (the plaintext). Place the returned ciphertext into the 1443 'ciphertext' field of the structure. 1445 5. For recipients of the message, recursively perform the encryption 1446 algorithm for that recipient, using K (the encryption key) as the 1447 plaintext. 1449 How to decrypt a message: 1451 1. Verify that the 'protected' field is empty. 1453 2. Verify that there was no external additional authenticated data 1454 supplied for this operation. 1456 3. Determine the decryption key. This step is dependent on the 1457 class of recipient algorithm being used. For: 1459 No Recipients: The key to be used is determined by the algorithm 1460 and key at the current layer. Examples are key transport keys 1461 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1462 secrets. 1464 Direct Encryption and Direct Key Agreement: The key is 1465 determined by the key and algorithm in the recipient 1466 structure. The encryption algorithm and size of the key to be 1467 used are inputs into the KDF used for the recipient. (For 1468 direct, the KDF can be thought of as the identity operation.) 1469 Examples of these algorithms are found in Sections 6.1.2 and 1470 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1472 Other: The key is determined by decoding and decrypting one of 1473 the recipient structures. 1475 4. Call the decryption algorithm with K (the decryption key to use) 1476 and C (the ciphertext). 1478 7. MAC Objects 1480 COSE supports two different MAC structures. COSE_MAC0 is used when a 1481 recipient structure is not needed because the key to be used is 1482 implicitly known. COSE_MAC is used for all other cases. These 1483 include a requirement for multiple recipients, the key being unknown, 1484 or a recipient algorithm of other than direct. 1486 In this section, we describe the structure and methods to be used 1487 when doing MAC authentication in COSE. This document allows for the 1488 use of all of the same classes of recipient algorithms as are allowed 1489 for encryption. 1491 When using MAC operations, there are two modes in which they can be 1492 used. The first is just a check that the content has not been 1493 changed since the MAC was computed. Any class of recipient algorithm 1494 can be used for this purpose. The second mode is to both check that 1495 the content has not been changed since the MAC was computed and to 1496 use the recipient algorithm to verify who sent it. The classes of 1497 recipient algorithms that support this are those that use a pre- 1498 shared secret or do static-static (SS) key agreement (without the key 1499 wrap step). In both of these cases, the entity that created and sent 1500 the message MAC can be validated. (This knowledge of the sender 1501 assumes that there are only two parties involved and that you did not 1502 send the message to yourself.) The origination property can be 1503 obtained with both of the MAC message structures. 1505 7.1. MACed Message with Recipients 1507 The multiple recipient MACed message uses two structures: the 1508 COSE_Mac structure defined in this section for carrying the body and 1509 the COSE_recipient structure (Section 6.1) to hold the key used for 1510 the MAC computation. Examples of MACed messages can be found in 1511 Appendix C.5. 1513 The MAC structure can be encoded as either tagged or untagged 1514 depending on the context it will be used in. A tagged COSE_Mac 1515 structure is identified by the CBOR tag 97. The CDDL fragment that 1516 represents this is: 1518 COSE_Mac_Tagged = #6.97(COSE_Mac) 1520 The COSE_Mac structure is a CBOR array. The fields of the array in 1521 order are: 1523 protected: This is as described in Section 3. 1525 unprotected: This is as described in Section 3. 1527 payload: This field contains the serialized content to be MACed. If 1528 the payload is not present in the message, the application is 1529 required to supply the payload separately. The payload is wrapped 1530 in a bstr to ensure that it is transported without changes. If 1531 the payload is transported separately (i.e., detached content), 1532 then a nil CBOR value is placed in this location, and it is the 1533 responsibility of the application to ensure that it will be 1534 transported without changes. 1536 tag: This field contains the MAC value. 1538 recipients: This is as described in Section 6.1. 1540 The CDDL fragment that represents the above text for COSE_Mac 1541 follows. 1543 COSE_Mac = [ 1544 Headers, 1545 payload : bstr / nil, 1546 tag : bstr, 1547 recipients :[+COSE_recipient] 1548 ] 1550 7.2. MACed Messages with Implicit Key 1552 In this section, we describe the structure and methods to be used 1553 when doing MAC authentication for those cases where the recipient is 1554 implicitly known. 1556 The MACed message uses the COSE_Mac0 structure defined in this 1557 section for carrying the body. Examples of MACed messages with an 1558 implicit key can be found in Appendix C.6. 1560 The MAC structure can be encoded as either tagged or untagged 1561 depending on the context it will be used in. A tagged COSE_Mac0 1562 structure is identified by the CBOR tag 17. The CDDL fragment that 1563 represents this is: 1565 COSE_Mac0_Tagged = #6.17(COSE_Mac0) 1567 The COSE_Mac0 structure is a CBOR array. The fields of the array in 1568 order are: 1570 protected: This is as described in Section 3. 1572 unprotected: This is as described in Section 3. 1574 payload: This is as described in Section 7.1. 1576 tag: This field contains the MAC value. 1578 The CDDL fragment that corresponds to the above text is: 1580 COSE_Mac0 = [ 1581 Headers, 1582 payload : bstr / nil, 1583 tag : bstr, 1584 ] 1586 7.3. How to Compute and Verify a MAC 1588 In order to get a consistent encoding of the data to be 1589 authenticated, the MAC_structure is used to have a canonical form. 1590 The MAC_structure is a CBOR array. The fields of the MAC_structure 1591 in order are: 1593 1. A text string that identifies the structure that is being 1594 encoded. This string is "MAC" for the COSE_Mac structure. This 1595 string is "MAC0" for the COSE_Mac0 structure. 1597 2. The protected attributes from the COSE_MAC structure. If there 1598 are no protected attributes, a zero-length bstr is used. 1600 3. The protected attributes from the application encoded as a bstr 1601 type. If this field is not supplied, it defaults to a zero- 1602 length binary string. (See Section 4.3 for application guidance 1603 on constructing this field.) 1605 4. The payload to be MACed encoded in a bstr type. The payload is 1606 placed here independent of how it is transported. 1608 The CDDL fragment that corresponds to the above text is: 1610 MAC_structure = [ 1611 context : "MAC" / "MAC0", 1612 protected : empty_or_serialized_map, 1613 external_aad : bstr, 1614 payload : bstr 1615 ] 1617 The steps to compute a MAC are: 1619 1. Create a MAC_structure and populate it with the appropriate 1620 fields. 1622 2. Create the value ToBeMaced by encoding the MAC_structure to a 1623 byte string, using the encoding described in Section 10. 1625 3. Call the MAC creation algorithm passing in K (the key to use), 1626 alg (the algorithm to MAC with), and ToBeMaced (the value to 1627 compute the MAC on). 1629 4. Place the resulting MAC in the 'tag' field of the COSE_Mac or 1630 COSE_Mac0 structure. 1632 5. For COSE_Mac structures, encrypt and encode the MAC key for each 1633 recipient of the message. 1635 The steps to verify a MAC are: 1637 1. Create a MAC_structure object and populate it with the 1638 appropriate fields. 1640 2. Create the value ToBeMaced by encoding the MAC_structure to a 1641 byte string, using the encoding described in Section 10. 1643 3. For COSE_Mac structures, obtain the cryptographic key from one of 1644 the recipients of the message. 1646 4. Call the MAC creation algorithm passing in K (the key to use), 1647 alg (the algorithm to MAC with), and ToBeMaced (the value to 1648 compute the MAC on). 1650 5. Compare the MAC value to the 'tag' field of the COSE_Mac or 1651 COSE_Mac0 structure. 1653 8. Key Objects 1655 A COSE Key structure is built on a CBOR map object. The set of 1656 common parameters that can appear in a COSE Key can be found in the 1657 IANA "COSE Key Common Parameters" registry (Section 12.4). 1658 Additional parameters defined for specific key types can be found in 1659 the IANA "COSE Key Type Parameters" registry ([COSE.KeyParameters]). 1661 A COSE Key Set uses a CBOR array object as its underlying type. The 1662 values of the array elements are COSE Keys. A COSE Key Set MUST have 1663 at least one element in the array. Examples of COSE Key Sets can be 1664 found in Appendix C.7. 1666 Each element in a COSE Key Set MUST be processed independently. If 1667 one element in a COSE Key Set is either malformed or uses a key that 1668 is not understood by an application, that key is ignored and the 1669 other keys are processed normally. 1671 The element "kty" is a required element in a COSE_Key map. 1673 The CDDL grammar describing COSE_Key and COSE_KeySet is: 1675 COSE_Key = { 1676 1 => tstr / int, ; kty 1677 ? 2 => bstr, ; kid 1678 ? 3 => tstr / int, ; alg 1679 ? 4 => [+ (tstr / int) ], ; key_ops 1680 ? 5 => bstr, ; Base IV 1681 * label => values 1682 } 1684 COSE_KeySet = [+COSE_Key] 1686 8.1. COSE Key Common Parameters 1688 This document defines a set of common parameters for a COSE Key 1689 object. Table 5 provides a summary of the parameters defined in this 1690 section. There are also parameters that are defined for specific key 1691 types. Key-type-specific parameters can be found in 1692 [I-D.ietf-cose-rfc8152bis-algs]. 1694 +---------+-------+--------+------------+--------------------+ 1695 | Name | Label | CBOR | Value | Description | 1696 | | | Type | Registry | | 1697 +=========+=======+========+============+====================+ 1698 | kty | 1 | tstr / | COSE Key | Identification of | 1699 | | | int | Types | the key type | 1700 +---------+-------+--------+------------+--------------------+ 1701 | kid | 2 | bstr | | Key identification | 1702 | | | | | value -- match to | 1703 | | | | | kid in message | 1704 +---------+-------+--------+------------+--------------------+ 1705 | alg | 3 | tstr / | COSE | Key usage | 1706 | | | int | Algorithms | restriction to | 1707 | | | | | this algorithm | 1708 +---------+-------+--------+------------+--------------------+ 1709 | key_ops | 4 | [+ | | Restrict set of | 1710 | | | (tstr/ | | permissible | 1711 | | | int)] | | operations | 1712 +---------+-------+--------+------------+--------------------+ 1713 | Base IV | 5 | bstr | | Base IV to be xor- | 1714 | | | | | ed with Partial | 1715 | | | | | IVs | 1716 +---------+-------+--------+------------+--------------------+ 1718 Table 5: Key Map Labels 1720 kty: This parameter is used to identify the family of keys for this 1721 structure and, thus, the set of key-type-specific parameters to be 1722 found. The set of values defined in this document can be found in 1723 [COSE.KeyTypes]. This parameter MUST be present in a key object. 1724 Implementations MUST verify that the key type is appropriate for 1725 the algorithm being processed. The key type MUST be included as 1726 part of the trust decision process. 1728 alg: This parameter is used to restrict the algorithm that is used 1729 with the key. If this parameter is present in the key structure, 1730 the application MUST verify that this algorithm matches the 1731 algorithm for which the key is being used. If the algorithms do 1732 not match, then this key object MUST NOT be used to perform the 1733 cryptographic operation. Note that the same key can be in a 1734 different key structure with a different or no algorithm 1735 specified; however, this is considered to be a poor security 1736 practice. 1738 kid: This parameter is used to give an identifier for a key. The 1739 identifier is not structured and can be anything from a user- 1740 provided string to a value computed on the public portion of the 1741 key. This field is intended for matching against a 'kid' 1742 parameter in a message in order to filter down the set of keys 1743 that need to be checked. 1745 key_ops: This parameter is defined to restrict the set of operations 1746 that a key is to be used for. The value of the field is an array 1747 of values from Table 6. Algorithms define the values of key ops 1748 that are permitted to appear and are required for specific 1749 operations. The set of values matches that in [RFC7517] and 1750 [W3C.WebCrypto]. 1752 Base IV: This parameter is defined to carry the base portion of an 1753 IV. It is designed to be used with the Partial IV header 1754 parameter defined in Section 3.1. This field provides the ability 1755 to associate a Partial IV with a key that is then modified on a 1756 per message basis with the Partial IV. 1758 Extreme care needs to be taken when using a Base IV in an 1759 application. Many encryption algorithms lose security if the same 1760 IV is used twice. 1762 If different keys are derived for each sender, using the same Base 1763 IV with Partial IVs starting at zero is likely to ensure that the 1764 IV would not be used twice for a single key. If different keys 1765 are derived for each sender, starting at the same Base IV is 1766 likely to satisfy this condition. If the same key is used for 1767 multiple senders, then the application needs to provide for a 1768 method of dividing the IV space up between the senders. This 1769 could be done by providing a different base point to start from or 1770 a different Partial IV to start with and restricting the number of 1771 messages to be sent before rekeying. 1773 +---------+-------+----------------------------------------------+ 1774 | Name | Value | Description | 1775 +=========+=======+==============================================+ 1776 | sign | 1 | The key is used to create signatures. | 1777 | | | Requires private key fields. | 1778 +---------+-------+----------------------------------------------+ 1779 | verify | 2 | The key is used for verification of | 1780 | | | signatures. | 1781 +---------+-------+----------------------------------------------+ 1782 | encrypt | 3 | The key is used for key transport | 1783 | | | encryption. | 1784 +---------+-------+----------------------------------------------+ 1785 | decrypt | 4 | The key is used for key transport | 1786 | | | decryption. Requires private key fields. | 1787 +---------+-------+----------------------------------------------+ 1788 | wrap | 5 | The key is used for key wrap encryption. | 1789 | key | | | 1790 +---------+-------+----------------------------------------------+ 1791 | unwrap | 6 | The key is used for key wrap decryption. | 1792 | key | | Requires private key fields. | 1793 +---------+-------+----------------------------------------------+ 1794 | derive | 7 | The key is used for deriving keys. Requires | 1795 | key | | private key fields. | 1796 +---------+-------+----------------------------------------------+ 1797 | derive | 8 | The key is used for deriving bits not to be | 1798 | bits | | used as a key. Requires private key fields. | 1799 +---------+-------+----------------------------------------------+ 1800 | MAC | 9 | The key is used for creating MACs. | 1801 | create | | | 1802 +---------+-------+----------------------------------------------+ 1803 | MAC | 10 | The key is used for validating MACs. | 1804 | verify | | | 1805 +---------+-------+----------------------------------------------+ 1807 Table 6: Key Operation Values 1809 9. Taxonomy of Algorithms used by COSE 1811 In this section, a taxonomy of the different algorithm types that can 1812 be used in COSE is laid out. This taxonomy should not be considered 1813 to be exhaustive as there are new algorithm structures that could be 1814 found or are not known to the author. 1816 9.1. Signature Algorithms 1818 There are two signature algorithm schemes. The first is signature 1819 with appendix. In this scheme, the message content is processed and 1820 a signature is produced; the signature is called the appendix. This 1821 is the scheme used by algorithms such as ECDSA and the RSA 1822 Probabilistic Signature Scheme (RSASSA-PSS). (In fact, the SSA in 1823 RSASSA-PSS stands for Signature Scheme with Appendix.) 1825 The signature functions for this scheme are: 1827 signature = Sign(message content, key) 1829 valid = Verification(message content, key, signature) 1831 The second scheme is signature with message recovery (an example of 1832 such an algorithm is [PVSig]). In this scheme, the message content 1833 is processed, but part of it is included in the signature. Moving 1834 bytes of the message content into the signature allows for smaller 1835 signatures; the signature size is still potentially large, but the 1836 message content has shrunk. This has implications for systems 1837 implementing these algorithms and for applications that use them. 1838 The first is that the message content is not fully available until 1839 after a signature has been validated. Until that point, the part of 1840 the message contained inside of the signature is unrecoverable. The 1841 second is that the security analysis of the strength of the signature 1842 is very much based on the structure of the message content. Messages 1843 that are highly predictable require additional randomness to be 1844 supplied as part of the signature process. In the worst case, it 1845 becomes the same as doing a signature with appendix. Finally, in the 1846 event that multiple signatures are applied to a message, all of the 1847 signature algorithms are going to be required to consume the same 1848 number of bytes of message content. This means that the mixing of 1849 the different schemes in a single message is not supported, and if a 1850 recovery signature scheme is used, then the same amount of content 1851 needs to be consumed by all of the signatures. 1853 The signature functions for this scheme are: 1855 signature, message sent = Sign(message content, key) 1857 valid, message content = Verification(message sent, key, signature) 1859 Signature algorithms are used with the COSE_Signature and COSE_Sign1 1860 structures. At this time, only signatures with appendixes are 1861 defined for use with COSE; however, considerable interest has been 1862 expressed in using a signature with message recovery algorithm due to 1863 the effective size reduction that is possible. Implementations will 1864 need to keep this in mind for later possible integration. 1866 9.2. Message Authentication Code (MAC) Algorithms 1868 Message Authentication Codes (MACs) provide data authentication and 1869 integrity protection. They provide either no or very limited data 1870 origination. A MAC, for example, cannot be used to prove the 1871 identity of the sender to a third party. 1873 MACs use the same scheme as signature with appendix algorithms. The 1874 message content is processed and an authentication code is produced. 1875 The authentication code is frequently called a tag. 1877 The MAC functions are: 1879 tag = MAC_Create(message content, key) 1881 valid = MAC_Verify(message content, key, tag) 1883 MAC algorithms can be based on either a block cipher algorithm (i.e., 1884 AES-MAC) or a hash algorithm (i.e., a Hash-based Message 1885 Authentication Code (HMAC)). [I-D.ietf-cose-rfc8152bis-algs] defines 1886 a MAC algorithm using each of these constructions. 1888 MAC algorithms are used in the COSE_Mac and COSE_Mac0 structures. 1890 9.3. Content Encryption Algorithms 1892 Content encryption algorithms provide data confidentiality for 1893 potentially large blocks of data using a symmetric key. They provide 1894 integrity on the data that was encrypted; however, they provide 1895 either no or very limited data origination. (One cannot, for 1896 example, be used to prove the identity of the sender to a third 1897 party.) The ability to provide data origination is linked to how the 1898 CEK is obtained. 1900 COSE restricts the set of legal content encryption algorithms to 1901 those that support authentication both of the content and additional 1902 data. The encryption process will generate some type of 1903 authentication value, but that value may be either explicit or 1904 implicit in terms of the algorithm definition. For simplicity's 1905 sake, the authentication code will normally be defined as being 1906 appended to the ciphertext stream. The encryption functions are: 1908 ciphertext = Encrypt(message content, key, additional data) 1910 valid, message content = Decrypt(ciphertext, key, additional data) 1911 Most AEAD algorithms are logically defined as returning the message 1912 content only if the decryption is valid. Many but not all 1913 implementations will follow this convention. The message content 1914 MUST NOT be used if the decryption does not validate. 1916 These algorithms are used in COSE_Encrypt and COSE_Encrypt0. 1918 9.4. Key Derivation Functions (KDFs) 1920 KDFs are used to take some secret value and generate a different one. 1921 The secret value comes in three flavors: 1923 * Secrets that are uniformly random: This is the type of secret that 1924 is created by a good random number generator. 1926 * Secrets that are not uniformly random: This is type of secret that 1927 is created by operations like key agreement. 1929 * Secrets that are not random: This is the type of secret that 1930 people generate for things like passwords. 1932 General KDFs work well with the first type of secret, can do 1933 reasonably well with the second type of secret, and generally do 1934 poorly with the last type of secret. Functions like PBES2 [RFC8018] 1935 need to be used for non-random secrets. 1937 The same KDF can be set up to deal with the first two types of 1938 secrets in a different way. The KDF defined in section 5.1 of 1939 [I-D.ietf-cose-rfc8152bis-algs] is such a function. This is 1940 reflected in the set of algorithms defined around the HMAC-based 1941 Extract-and-Expand Key Derivation Function (HKDF). 1943 When using KDFs, one component that is included is context 1944 information. Context information is used to allow for different 1945 keying information to be derived from the same secret. The use of 1946 context-based keying material is considered to be a good security 1947 practice. 1949 9.5. Content Key Distribution Methods 1951 Content key distribution methods (recipient algorithms) can be 1952 defined into a number of different classes. COSE has the ability to 1953 support many classes of recipient algorithms. In this section, a 1954 number of classes are listed. The names of the recipient algorithm 1955 classes used here are the same as those defined in [RFC7516]. Other 1956 specifications use different terms for the recipient algorithm 1957 classes or do not support some of the recipient algorithm classes. 1959 9.5.1. Direct Encryption 1961 The direct encryption class algorithms share a secret between the 1962 sender and the recipient that is used either directly or after 1963 manipulation as the CEK. When direct encryption mode is used, it 1964 MUST be the only mode used on the message. 1966 The COSE_Recipient structure for the recipient is organized as 1967 follows: 1969 * The 'protected' field MUST be a zero-length item unless it is used 1970 in the computation of the content key. 1972 * The 'alg' parameter MUST be present. 1974 * A parameter identifying the shared secret SHOULD be present. 1976 * The 'ciphertext' field MUST be a zero-length item. 1978 * The 'recipients' field MUST be absent. 1980 9.5.2. Key Wrap 1982 In key wrap mode, the CEK is randomly generated and that key is then 1983 encrypted by a shared secret between the sender and the recipient. 1984 All of the currently defined key wrap algorithms for COSE are AE 1985 algorithms. Key wrap mode is considered to be superior to direct 1986 encryption if the system has any capability for doing random key 1987 generation. This is because the shared key is used to wrap random 1988 data rather than data that has some degree of organization and may in 1989 fact be repeating the same content. The use of key wrap loses the 1990 weak data origination that is provided by the direct encryption 1991 algorithms. 1993 The COSE_Encrypt structure for the recipient is organized as follows: 1995 * The 'protected' field MUST be absent if the key wrap algorithm is 1996 an AE algorithm. 1998 * The 'recipients' field is normally absent, but can be used. 1999 Applications MUST deal with a recipient field being present that 2000 has an unsupported algorithm, not being able to decrypt that 2001 recipient is an acceptable way of dealing with it. Failing to 2002 process the message is not an acceptable way of dealing with it. 2004 * The plaintext to be encrypted is the key from next layer down 2005 (usually the content layer). 2007 * At a minimum, the 'unprotected' field MUST contain the 'alg' 2008 parameter and SHOULD contain a parameter identifying the shared 2009 secret. 2011 9.5.3. Key Transport 2013 Key transport mode is also called key encryption mode in some 2014 standards. Key transport mode differs from key wrap mode in that it 2015 uses an asymmetric encryption algorithm rather than a symmetric 2016 encryption algorithm to protect the key. A set of key transport 2017 algorithms are defined in [RFC8230]. 2019 When using a key transport algorithm, the COSE_Encrypt structure for 2020 the recipient is organized as follows: 2022 * The 'protected' field MUST be absent. 2024 * The plaintext to be encrypted is the key from the next layer down 2025 (usually the content layer). 2027 * At a minimum, the 'unprotected' field MUST contain the 'alg' 2028 parameter and SHOULD contain a parameter identifying the 2029 asymmetric key. 2031 9.5.4. Direct Key Agreement 2033 The 'direct key agreement' class of recipient algorithms uses a key 2034 agreement method to create a shared secret. A KDF is then applied to 2035 the shared secret to derive a key to be used in protecting the data. 2036 This key is normally used as a CEK or MAC key, but could be used for 2037 other purposes if more than two layers are in use (see Appendix B). 2039 The most commonly used key agreement algorithm is Diffie-Hellman, but 2040 other variants exist. Since COSE is designed for a store and forward 2041 environment rather than an online environment, many of the DH 2042 variants cannot be used as the receiver of the message cannot provide 2043 any dynamic key material. One side effect of this is that perfect 2044 forward secrecy (see [RFC4949]) is not achievable. A static key will 2045 always be used for the receiver of the COSE object. 2047 Two variants of DH that are supported are: 2049 Ephemeral-Static (ES) DH: where the sender of the message creates 2050 a one-time DH key and uses a static key for the recipient. The 2051 use of the ephemeral sender key means that no additional random 2052 input is needed as this is randomly generated for each message. 2054 Static-Static (SS) DH: where a static key is used for both the 2055 sender and the recipient. The use of static keys allows for the 2056 recipient to get a weak version of data origination for the 2057 message. When static-static key agreement is used, then some 2058 piece of unique data for the KDF is required to ensure that a 2059 different key is created for each message. 2061 When direct key agreement mode is used, there MUST be only one 2062 recipient in the message. This method creates the key directly, and 2063 that makes it difficult to mix with additional recipients. If 2064 multiple recipients are needed, then the version with key wrap needs 2065 to be used. 2067 The COSE_Encrypt structure for the recipient is organized as follows: 2069 * At a minimum, headers MUST contain the 'alg' parameter and SHOULD 2070 contain a parameter identifying the recipient's asymmetric key. 2072 * The headers SHOULD identify the sender's key for the static-static 2073 versions and MUST contain the sender's ephemeral key for the 2074 ephemeral-static versions. 2076 9.5.5. Key Agreement with Key Wrap 2078 Key Agreement with Key Wrap uses a randomly generated CEK. The CEK 2079 is then encrypted using a key wrap algorithm and a key derived from 2080 the shared secret computed by the key agreement algorithm. The 2081 function for this would be: 2083 encryptedKey = KeyWrap(KDF(DH-Shared, context), CEK) 2085 The COSE_Encrypt structure for the recipient is organized as follows: 2087 * The 'protected' field is fed into the KDF context structure. 2089 * The plaintext to be encrypted is the key from the next layer down 2090 (usually the content layer). 2092 * The 'alg' parameter MUST be present in the layer. 2094 * A parameter identifying the recipient's key SHOULD be present. A 2095 parameter identifying the sender's key SHOULD be present. 2097 10. CBOR Encoding Restrictions 2099 There has been an attempt to limit the number of places where the 2100 document needs to impose restrictions on how the CBOR Encoder needs 2101 to work. We have managed to narrow it down to the following 2102 restrictions: 2104 * The restriction applies to the encoding of the Sig_structure, the 2105 Enc_structure, and the MAC_structure. 2107 * Encoding MUST be done using definite lengths and values MUST be 2108 the minimum possible length. This means that the integer 1 is 2109 encoded as "0x01" and not "0x1801". 2111 * Applications MUST NOT generate messages with the same label used 2112 twice as a key in a single map. Applications MUST NOT parse and 2113 process messages with the same label used twice as a key in a 2114 single map. Applications can enforce the parse and process 2115 requirement by using parsers that will fail the parse step or by 2116 using parsers that will pass all keys to the application, and the 2117 application can perform the check for duplicate keys. 2119 11. Application Profiling Considerations 2121 This document is designed to provide a set of security services, but 2122 not impose algorithm implementation requirements for specific usage. 2123 The interoperability requirements are provided for how each of the 2124 individual services are used and how the algorithms are to be used 2125 for interoperability. The requirements about which algorithms and 2126 which services are needed are deferred to each application. 2128 An example of a profile can be found in [RFC8613] where one was 2129 developed for carrying content in combination with CoAP headers. 2131 It is intended that a profile of this document be created that 2132 defines the interoperability requirements for that specific 2133 application. This section provides a set of guidelines and topics 2134 that need to be considered when profiling this document. 2136 * Applications need to determine the set of messages defined in this 2137 document that they will be using. The set of messages corresponds 2138 fairly directly to the set of security services that are needed 2139 and to the security levels needed. 2141 * Applications may define new header parameters for a specific 2142 purpose. Applications will often times select specific header 2143 parameters to use or not to use. For example, an application 2144 would normally state a preference for using either the IV or the 2145 Partial IV parameter. If the Partial IV parameter is specified, 2146 then the application also needs to define how the fixed portion of 2147 the IV is determined. 2149 * When applications use externally defined authenticated data, they 2150 need to define how that data is encoded. This document assumes 2151 that the data will be provided as a byte string. More information 2152 can be found in Section 4.3. 2154 * Applications need to determine the set of security algorithms that 2155 are to be used. When selecting the algorithms to be used as the 2156 mandatory-to-implement set, consideration should be given to 2157 choosing different types of algorithms when two are chosen for a 2158 specific purpose. An example of this would be choosing HMAC- 2159 SHA512 and AES-CMAC as different MAC algorithms; the construction 2160 is vastly different between these two algorithms. This means that 2161 a weakening of one algorithm would be unlikely to lead to a 2162 weakening of the other algorithms. Of course, these algorithms do 2163 not provide the same level of security and thus may not be 2164 comparable for the desired security functionality. 2166 * Applications may need to provide some type of negotiation or 2167 discovery method if multiple algorithms or message structures are 2168 permitted. The method can be as simple as requiring 2169 preconfiguration of the set of algorithms to providing a discovery 2170 method built into the protocol. S/MIME provided a number of 2171 different ways to approach the problem that applications could 2172 follow: 2174 - Advertising in the message (S/MIME capabilities) [RFC5751]. 2176 - Advertising in the certificate (capabilities extension) 2177 [RFC4262]. 2179 - Minimum requirements for the S/MIME, which have been updated 2180 over time [RFC2633] [RFC5751] (note that [RFC2633] has been 2181 obsoleted by [RFC5751]). 2183 12. IANA Considerations 2185 The registeries and registrations listed below were created during 2186 processing of RFC 8152 [RFC8152]. The only known action at this time 2187 is to update the references. 2189 12.1. CBOR Tag Assignment 2191 IANA assigned tags in the "CBOR Tags" registry as part of processing 2192 [RFC8152]. IANA is requested to update the references from [RFC8152] 2193 to this document. 2195 IANA is requested to register a new tag for the CounterSignature 2196 type. 2198 * Tag: TBD0 2200 * Data Item: COSE_Signature 2202 * Semantics: COSE standalone counter signature 2204 * Reference: [[this document]] 2206 12.2. COSE Header Parameters Registry 2208 IANA created a registry titled "COSE Header Parameters" as part of 2209 processing [RFC8152]. The registry has been created to use the 2210 "Expert Review Required" registration procedure [RFC8126]. 2212 IANA is requested to update the reference for entries in the table 2213 from [RFC8152] to this document. This document does not update the 2214 expert review guidelines provided in [RFC8152]. 2216 12.3. COSE Header Algorithm Parameters Registry 2218 IANA created a registry titled "COSE Header Algorithm Parameters" as 2219 part of processing [RFC8152]. The registry has been created to use 2220 the "Expert Review Required" registration procedure [RFC8126]. 2222 IANA is requested to update the references from [RFC8152] to this 2223 document. This document does not update the expert review guidelines 2224 provided in [RFC8152]. 2226 12.4. COSE Key Common Parameters Registry 2228 IANA created a registry titled "COSE Key Common Parameters" as part 2229 of the processing of [RFC8152]. The registry has been created to use 2230 the "Expert Review Required" registration procedure [RFC8126]. 2232 IANA is requested to update the reference for entries in the table 2233 from [RFC8152] to this document. This document does not update the 2234 expert review guidelines provided in [RFC8152]. 2236 12.5. Media Type Registrations 2238 12.5.1. COSE Security Message 2240 This section registers the 'application/cose' media type in the 2241 "Media Types" registry. These media types are used to indicate that 2242 the content is a COSE message. 2244 Type name: application 2246 Subtype name: cose 2248 Required parameters: N/A 2250 Optional parameters: cose-type 2252 Encoding considerations: binary 2254 Security considerations: See the Security Considerations section 2255 of [[This Document]]. 2257 Interoperability considerations: N/A 2259 Published specification: [[this document]] 2261 Applications that use this media type: IoT applications sending 2262 security content over HTTP(S) transports. 2264 Fragment identifier considerations: N/A 2266 Additional information: 2268 - Deprecated alias names for this type: N/A 2270 - Magic number(s): N/A 2272 - File extension(s): cbor 2274 - Macintosh file type code(s): N/A 2276 Person & email address to contact for further information: 2277 iesg@ietf.org 2279 Intended usage: COMMON 2281 Restrictions on usage: N/A 2283 Author: Jim Schaad, ietf@augustcellars.com 2284 Change Controller: IESG 2286 Provisional registration? No 2288 12.5.2. COSE Key Media Type 2290 This section registers the 'application/cose-key' and 'application/ 2291 cose-key-set' media types in the "Media Types" registry. These media 2292 types are used to indicate, respectively, that content is a COSE_Key 2293 or COSE_KeySet object. 2295 The template for registering 'application/cose-key' is: 2297 Type name: application 2299 Subtype name: cose-key 2301 Required parameters: N/A 2303 Optional parameters: N/A 2305 Encoding considerations: binary 2307 Security considerations: See the Security Considerations section 2308 of [[This Document]]. 2310 Interoperability considerations: N/A 2312 Published specification: [[this document]] 2314 Applications that use this media type: Distribution of COSE based 2315 keys for IoT applications. 2317 Fragment identifier considerations: N/A 2319 Additional information: 2321 - Deprecated alias names for this type: N/A 2323 - Magic number(s): N/A 2325 - File extension(s): cbor 2327 - Macintosh file type code(s): N/A 2329 Person & email address to contact for further information: 2330 iesg@ietf.org 2331 Intended usage: COMMON 2333 Restrictions on usage: N/A 2335 Author: Jim Schaad, ietf@augustcellars.com 2337 Change Controller: IESG 2339 Provisional registration? No 2341 The template for registering 'application/cose-key-set' is: 2343 Type name: application 2345 Subtype name: cose-key-set 2347 Required parameters: N/A 2349 Optional parameters: N/A 2351 Encoding considerations: binary 2353 Security considerations: See the Security Considerations section 2354 of [[This Document]]. 2356 Interoperability considerations: N/A 2358 Published specification: [[this document]] 2360 Applications that use this media type: Distribution of COSE based 2361 keys for IoT applications. 2363 Fragment identifier considerations: N/A 2365 Additional information: 2367 - Deprecated alias names for this type: N/A 2369 - Magic number(s): N/A 2371 - File extension(s): cbor 2373 - Macintosh file type code(s): N/A 2375 Person & email address to contact for further information: 2376 iesg@ietf.org 2378 Intended usage: COMMON 2379 Restrictions on usage: N/A 2381 Author: Jim Schaad, ietf@augustcellars.com 2383 Change Controller: IESG 2385 Provisional registration? No 2387 12.6. CoAP Content-Formats Registry 2389 IANA added the following entries to the "CoAP Content-Formats" 2390 registry while processing [RFC8152]. IANA is requested to update the 2391 reference value from [RFC8152] to [[This Document]]. 2393 13. Security Considerations 2395 There are a number of security considerations that need to be taken 2396 into account by implementers of this specification. The security 2397 considerations that are specific to an individual algorithm are 2398 placed next to the description of the algorithm. While some 2399 considerations have been highlighted here, additional considerations 2400 may be found in the documents listed in the references. 2402 Implementations need to protect the private key material for any 2403 individuals. There are some cases that need to be highlighted on 2404 this issue. 2406 * Using the same key for two different algorithms can leak 2407 information about the key. It is therefore recommended that keys 2408 be restricted to a single algorithm. 2410 * Use of 'direct' as a recipient algorithm combined with a second 2411 recipient algorithm exposes the direct key to the second 2412 recipient. 2414 * Several of the algorithms in [I-D.ietf-cose-rfc8152bis-algs] have 2415 limits on the number of times that a key can be used without 2416 leaking information about the key. 2418 The use of ECDH and direct plus KDF (with no key wrap) will not 2419 directly lead to the private key being leaked; the one way function 2420 of the KDF will prevent that. There is, however, a different issue 2421 that needs to be addressed. Having two recipients requires that the 2422 CEK be shared between two recipients. The second recipient therefore 2423 has a CEK that was derived from material that can be used for the 2424 weak proof of origin. The second recipient could create a message 2425 using the same CEK and send it to the first recipient; the first 2426 recipient would, for either static-static ECDH or direct plus KDF, 2427 make an assumption that the CEK could be used for proof of origin 2428 even though it is from the wrong entity. If the key wrap step is 2429 added, then no proof of origin is implied and this is not an issue. 2431 Although it has been mentioned before, the use of a single key for 2432 multiple algorithms has been demonstrated in some cases to leak 2433 information about that key, provide the opportunity for attackers to 2434 forge integrity tags, or gain information about encrypted content. 2435 Binding a key to a single algorithm prevents these problems. Key 2436 creators and key consumers are strongly encouraged not only to create 2437 new keys for each different algorithm, but to include that selection 2438 of algorithm in any distribution of key material and strictly enforce 2439 the matching of algorithms in the key structure to algorithms in the 2440 message structure. In addition to checking that algorithms are 2441 correct, the key form needs to be checked as well. Do not use an 2442 'EC2' key where an 'OKP' key is expected. 2444 Before using a key for transmission, or before acting on information 2445 received, a trust decision on a key needs to be made. Is the data or 2446 action something that the entity associated with the key has a right 2447 to see or a right to request? A number of factors are associated 2448 with this trust decision. Some of the ones that are highlighted here 2449 are: 2451 * What are the permissions associated with the key owner? 2453 * Is the cryptographic algorithm acceptable in the current context? 2455 * Have the restrictions associated with the key, such as algorithm 2456 or freshness, been checked and are they correct? 2458 * Is the request something that is reasonable, given the current 2459 state of the application? 2461 * Have any security considerations that are part of the message been 2462 enforced (as specified by the application or 'crit' parameter)? 2464 There are a large number of algorithms presented in 2465 [I-D.ietf-cose-rfc8152bis-algs] that use nonce values. Nonces 2466 generally have some type of restriction on their values. Generally a 2467 nonce needs to be a unique value either for a key or for some other 2468 conditions. In all of these cases, there is no known requirement on 2469 the nonce being both unique and unpredictable; under these 2470 circumstances, it's reasonable to use a counter for creation of the 2471 nonce. In cases where one wants the pattern of the nonce to be 2472 unpredictable as well as unique, one can use a key created for that 2473 purpose and encrypt the counter to produce the nonce value. 2475 One area that has been starting to get exposure is doing traffic 2476 analysis of encrypted messages based on the length of the message. 2477 This specification does not provide for a uniform method of providing 2478 padding as part of the message structure. An observer can 2479 distinguish between two different strings (for example, 'YES' and 2480 'NO') based on the length for all of the content encryption 2481 algorithms that are defined in [I-D.ietf-cose-rfc8152bis-algs] 2482 document. This means that it is up to the applications to document 2483 how content padding is to be done in order to prevent or discourage 2484 such analysis. (For example, the strings could be defined as 'YES' 2485 and 'NO '.) 2487 14. Implementation Status 2489 This section is to be removed before publishing as an RFC. 2491 This section records the status of known implementations of the 2492 protocol defined by this specification at the time of posting of this 2493 Internet-Draft, and is based on a proposal described in [RFC7942]. 2494 The description of implementations in this section is intended to 2495 assist the IETF in its decision processes in progressing drafts to 2496 RFCs. Please note that the listing of any individual implementation 2497 here does not imply endorsement by the IETF. Furthermore, no effort 2498 has been spent to verify the information presented here that was 2499 supplied by IETF contributors. This is not intended as, and must not 2500 be construed to be, a catalog of available implementations or their 2501 features. Readers are advised to note that other implementations may 2502 exist. 2504 According to [RFC7942], "this will allow reviewers and working groups 2505 to assign due consideration to documents that have the benefit of 2506 running code, which may serve as evidence of valuable experimentation 2507 and feedback that have made the implemented protocols more mature. 2508 It is up to the individual working groups to use this information as 2509 they see fit". 2511 14.1. Author's Versions 2513 There are three different implementations that have been created by 2514 the author of the document both to create the examples that are 2515 included in the document and to validate the structures and 2516 methodology used in the design of COSE. 2518 * Implementation Location: https://github.com/cose-wg 2520 * Primary Maintainer: Jim Schaad 2521 * Languages: There are three different languages that are currently 2522 supported: Java, C# and C. 2524 * Cryptography: The Java and C# libraries use Bouncy Castle to 2525 provide the required cryptography. The C version uses OPENSSL 2526 Version 1.0 for the cryptography. 2528 * Coverage: The C version currently does not have full countersign 2529 support. The other two versions do. They do have support to 2530 allow for implicit algorithm support as they allow for the 2531 application to set attributes that are not to be sent in the 2532 message. 2534 * Testing: All of the examples in the example library are generated 2535 by the C# library and then validated using the Java and C 2536 libraries. All three libraries have tests to allow for the 2537 creating of the same messages that are in the example library 2538 followed by validating them. These are not compared against the 2539 example library. The Java and C# libraries have unit testing 2540 included. Not all of the MUST statements in the document have 2541 been implemented as part of the libraries. One such statement is 2542 the requirement that unique labels be present. 2544 * Licensing: Revised BSD License 2546 14.2. JavaScript Version 2548 * Implementation Location: https://github.com/erdtman/cose-js 2550 * Primary Maintainer: Samuel Erdtman 2552 * Languages: JavaScript 2554 * Cryptography: TBD 2556 * Coverage: Full Encrypt, Signature and MAC objects are supported. 2558 * Testing: Basic testing against the common example library. 2560 * Licensing: Apache License 2.0 2562 14.3. Python Version 2564 * Implementation Location: https://github.com/TimothyClaeys/COSE- 2565 PYTHON 2567 * Primary Maintainer: Timothy Claeys 2568 * Languages: Python 2570 * Cryptography: pyecdsak, crypto python libraries 2572 * Coverage: TBD 2574 * Testing: Basic testing plus running against the common example 2575 library. 2577 * Licensing: BSD 3-Clause License 2579 14.4. COSE Testing Library 2581 * Implementation Location: https://github.com/cose-wg/Examples 2583 * Primary Maintainer: Jim Schaad 2585 * Description: A set of tests for the COSE library is provided as 2586 part of the implementation effort. Both success and fail tests 2587 have been provided. All of the examples in this document are part 2588 of this example set. 2590 * Coverage: An attempt has been made to have test cases for every 2591 message type and algorithm in the document. Currently examples 2592 dealing with counter signatures, and ECDH with Curve24459 and 2593 Goldilocks are missing. 2595 * Licensing: Public Domain 2597 15. References 2599 15.1. Normative References 2601 [COAP.Formats] 2602 IANA, "CoAP Content-Formats", 2603 . 2606 [COSE.Algorithms] 2607 IANA, "COSE Algorithms", 2608 . 2611 [COSE.KeyParameters] 2612 IANA, "COSE Key Parameters", 2613 . 2616 [COSE.KeyTypes] 2617 IANA, "COSE Key Types", 2618 . 2621 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2622 Requirement Levels", BCP 14, RFC 2119, 2623 DOI 10.17487/RFC2119, March 1997, 2624 . 2626 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 2627 Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, 2628 October 2013, . 2630 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2631 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 2632 May 2017, . 2634 [DSS] National Institute of Standards and Technology, "Digital 2635 Signature Standard (DSS)", DOI 10.6028/NIST.FIPS.186-4, 2636 FIPS PUB 186-4, July 2013, 2637 . 2640 [RFC8032] Josefsson, S. and I. Liusvaara, "Edwards-Curve Digital 2641 Signature Algorithm (EdDSA)", RFC 8032, 2642 DOI 10.17487/RFC8032, January 2017, 2643 . 2645 [I-D.ietf-cose-rfc8152bis-algs] 2646 Schaad, J., "CBOR Object Signing and Encryption (COSE): 2647 Initial Algorithms", Work in Progress, Internet-Draft, 2648 draft-ietf-cose-rfc8152bis-algs-05, 11 September 2019, 2649 . 2652 15.2. Informative References 2654 [RFC8152] Schaad, J., "CBOR Object Signing and Encryption (COSE)", 2655 RFC 8152, DOI 10.17487/RFC8152, July 2017, 2656 . 2658 [RFC8610] Birkholz, H., Vigano, C., and C. Bormann, "Concise Data 2659 Definition Language (CDDL): A Notational Convention to 2660 Express Concise Binary Object Representation (CBOR) and 2661 JSON Data Structures", RFC 8610, DOI 10.17487/RFC8610, 2662 June 2019, . 2664 [RFC8018] Moriarty, K., Ed., Kaliski, B., and A. Rusch, "PKCS #5: 2665 Password-Based Cryptography Specification Version 2.1", 2666 RFC 8018, DOI 10.17487/RFC8018, January 2017, 2667 . 2669 [RFC2633] Ramsdell, B., Ed., "S/MIME Version 3 Message 2670 Specification", RFC 2633, DOI 10.17487/RFC2633, June 1999, 2671 . 2673 [RFC4262] Santesson, S., "X.509 Certificate Extension for Secure/ 2674 Multipurpose Internet Mail Extensions (S/MIME) 2675 Capabilities", RFC 4262, DOI 10.17487/RFC4262, December 2676 2005, . 2678 [RFC4949] Shirey, R., "Internet Security Glossary, Version 2", 2679 FYI 36, RFC 4949, DOI 10.17487/RFC4949, August 2007, 2680 . 2682 [RFC5116] McGrew, D., "An Interface and Algorithms for Authenticated 2683 Encryption", RFC 5116, DOI 10.17487/RFC5116, January 2008, 2684 . 2686 [RFC5652] Housley, R., "Cryptographic Message Syntax (CMS)", STD 70, 2687 RFC 5652, DOI 10.17487/RFC5652, September 2009, 2688 . 2690 [RFC5751] Ramsdell, B. and S. Turner, "Secure/Multipurpose Internet 2691 Mail Extensions (S/MIME) Version 3.2 Message 2692 Specification", RFC 5751, DOI 10.17487/RFC5751, January 2693 2010, . 2695 [RFC5752] Turner, S. and J. Schaad, "Multiple Signatures in 2696 Cryptographic Message Syntax (CMS)", RFC 5752, 2697 DOI 10.17487/RFC5752, January 2010, 2698 . 2700 [RFC5990] Randall, J., Kaliski, B., Brainard, J., and S. Turner, 2701 "Use of the RSA-KEM Key Transport Algorithm in the 2702 Cryptographic Message Syntax (CMS)", RFC 5990, 2703 DOI 10.17487/RFC5990, September 2010, 2704 . 2706 [RFC6838] Freed, N., Klensin, J., and T. Hansen, "Media Type 2707 Specifications and Registration Procedures", BCP 13, 2708 RFC 6838, DOI 10.17487/RFC6838, January 2013, 2709 . 2711 [RFC8259] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 2712 Interchange Format", STD 90, RFC 8259, 2713 DOI 10.17487/RFC8259, December 2017, 2714 . 2716 [RFC7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 2717 Application Protocol (CoAP)", RFC 7252, 2718 DOI 10.17487/RFC7252, June 2014, 2719 . 2721 [RFC7515] Jones, M., Bradley, J., and N. Sakimura, "JSON Web 2722 Signature (JWS)", RFC 7515, DOI 10.17487/RFC7515, May 2723 2015, . 2725 [RFC7516] Jones, M. and J. Hildebrand, "JSON Web Encryption (JWE)", 2726 RFC 7516, DOI 10.17487/RFC7516, May 2015, 2727 . 2729 [RFC7517] Jones, M., "JSON Web Key (JWK)", RFC 7517, 2730 DOI 10.17487/RFC7517, May 2015, 2731 . 2733 [RFC7518] Jones, M., "JSON Web Algorithms (JWA)", RFC 7518, 2734 DOI 10.17487/RFC7518, May 2015, 2735 . 2737 [RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for 2738 Writing an IANA Considerations Section in RFCs", BCP 26, 2739 RFC 8126, DOI 10.17487/RFC8126, June 2017, 2740 . 2742 [PVSig] Brown, D. and D. Johnson, "Formal Security Proofs for a 2743 Signature Scheme with Partial Message Recovery", 2744 DOI 10.1007/3-540-45353-9_11, LNCS Volume 2020, June 2000, 2745 . 2747 [W3C.WebCrypto] 2748 Watson, M., "Web Cryptography API", W3C Recommendation, 2749 January 2017, . 2751 [RFC8613] Selander, G., Mattsson, J., Palombini, F., and L. Seitz, 2752 "Object Security for Constrained RESTful Environments 2753 (OSCORE)", RFC 8613, DOI 10.17487/RFC8613, July 2019, 2754 . 2756 [RFC8230] Jones, M., "Using RSA Algorithms with CBOR Object Signing 2757 and Encryption (COSE) Messages", RFC 8230, 2758 DOI 10.17487/RFC8230, September 2017, 2759 . 2761 [RFC7942] Sheffer, Y. and A. Farrel, "Improving Awareness of Running 2762 Code: The Implementation Status Section", BCP 205, 2763 RFC 7942, DOI 10.17487/RFC7942, July 2016, 2764 . 2766 [RFC4998] Gondrom, T., Brandner, R., and U. Pordesch, "Evidence 2767 Record Syntax (ERS)", RFC 4998, DOI 10.17487/RFC4998, 2768 August 2007, . 2770 Appendix A. Guidelines for External Data Authentication of Algorithms 2772 During development of COSE, the requirement that the algorithm 2773 identifier be located in the protected attributes was relaxed from a 2774 must to a should. There were two basic reasons that have been 2775 advanced to support this position. First, the resulting message will 2776 be smaller if the algorithm identifier is omitted from the most 2777 common messages in a CoAP environment. Second, there is a potential 2778 bug that will arise if full checking is not done correctly between 2779 the different places that an algorithm identifier could be placed 2780 (the message itself, an application statement, the key structure that 2781 the sender possesses, and the key structure the recipient possesses). 2783 This appendix lays out how such a change can be made and the details 2784 that an application needs to specify in order to use this option. 2785 Two different sets of details are specified: those needed to omit an 2786 algorithm identifier and those needed to use a variant on the counter 2787 signature attribute that contains no attributes about itself. 2789 Three sets of recommendations are laid out. The first set of 2790 recommendations apply to having an implicit algorithm identified for 2791 a single layer of a COSE object. The second set of recommendations 2792 apply to having multiple implicit algorithms identified for multiple 2793 layers of a COSE object. The third set of recommendations apply to 2794 having implicit algorithms for multiple COSE object constructs. 2796 The key words from [RFC2119] are deliberately not used here. This 2797 specification can provide recommendations, but it cannot enforce 2798 them. 2800 This set of recommendations applies to the case where an application 2801 is distributing a fixed algorithm along with the key information for 2802 use in a single COSE object. This normally applies to the smallest 2803 of the COSE objects, specifically COSE_Sign1, COSE_Mac0, and 2804 COSE_Encrypt0, but could apply to the other structures as well. 2806 The following items should be taken into account: 2808 * Applications need to list the set of COSE structures that implicit 2809 algorithms are to be used in. Applications need to require that 2810 the receipt of an explicit algorithm identifier in one of these 2811 structures will lead to the message being rejected. This 2812 requirement is stated so that there will never be a case where 2813 there is any ambiguity about the question of which algorithm 2814 should be used, the implicit or the explicit one. This applies 2815 even if the transported algorithm identifier is a protected 2816 attribute. This applies even if the transported algorithm is the 2817 same as the implicit algorithm. 2819 * Applications need to define the set of information that is to be 2820 considered to be part of a context when omitting algorithm 2821 identifiers. At a minimum, this would be the key identifier (if 2822 needed), the key, the algorithm, and the COSE structure it is used 2823 with. Applications should restrict the use of a single key to a 2824 single algorithm. As noted for some of the algorithms in 2825 [I-D.ietf-cose-rfc8152bis-algs], the use of the same key in 2826 different related algorithms can lead to leakage of information 2827 about the key, leakage about the data or the ability to perform 2828 forgeries. 2830 * In many cases, applications that make the algorithm identifier 2831 implicit will also want to make the context identifier implicit 2832 for the same reason. That is, omitting the context identifier 2833 will decrease the message size (potentially significantly 2834 depending on the length of the identifier). Applications that do 2835 this will need to describe the circumstances where the context 2836 identifier is to be omitted and how the context identifier is to 2837 be inferred in these cases. (An exhaustive search over all of the 2838 keys would normally not be considered to be acceptable.) An 2839 example of how this can be done is to tie the context to a 2840 transaction identifier. Both would be sent on the original 2841 message, but only the transaction identifier would need to be sent 2842 after that point as the context is tied into the transaction 2843 identifier. Another way would be to associate a context with a 2844 network address. All messages coming from a single network 2845 address can be assumed to be associated with a specific context. 2846 (In this case, the address would normally be distributed as part 2847 of the context.) 2849 * Applications cannot rely on key identifiers being unique unless 2850 they take significant efforts to ensure that they are computed in 2851 such a way as to create this guarantee. Even when an application 2852 does this, the uniqueness might be violated if the application is 2853 run in different contexts (i.e., with a different context 2854 provider) or if the system combines the security contexts from 2855 different applications together into a single store. 2857 * Applications should continue the practice of protecting the 2858 algorithm identifier. Since this is not done by placing it in the 2859 protected attributes field, applications should define an 2860 application-specific external data structure that includes this 2861 value. This external data field can be used as such for content 2862 encryption, MAC, and signature algorithms. It can be used in the 2863 SuppPrivInfo field for those algorithms that use a KDF to derive a 2864 key value. Applications may also want to protect other 2865 information that is part of the context structure as well. It 2866 should be noted that those fields, such as the key or a Base IV, 2867 are protected by virtue of being used in the cryptographic 2868 computation and do not need to be included in the external data 2869 field. 2871 The second case is having multiple implicit algorithm identifiers 2872 specified for a multiple layer COSE object. An example of how this 2873 would work is the encryption context that an application specifies, 2874 which contains a content encryption algorithm, a key wrap algorithm, 2875 a key identifier, and a shared secret. The sender omits sending the 2876 algorithm identifier for both the content layer and the recipient 2877 layer leaving only the key identifier. The receiver then uses the 2878 key identifier to get the implicit algorithm identifiers. 2880 The following additional items need to be taken into consideration: 2882 * Applications that want to support this will need to define a 2883 structure that allows for, and clearly identifies, both the COSE 2884 structure to be used with a given key and the structure and 2885 algorithm to be used for the secondary layer. The key for the 2886 secondary layer is computed as normal from the recipient layer. 2888 The third case is having multiple implicit algorithm identifiers, but 2889 targeted at potentially unrelated layers or different COSE objects. 2890 There are a number of different scenarios where this might be 2891 applicable. Some of these scenarios are: 2893 * Two contexts are distributed as a pair. Each of the contexts is 2894 for use with a COSE_Encrypt message. Each context will consist of 2895 distinct secret keys and IVs and potentially even different 2896 algorithms. One context is for sending messages from party A to 2897 party B, and the second context is for sending messages from party 2898 B to party A. This means that there is no chance for a reflection 2899 attack to occur as each party uses different secret keys to send 2900 its messages; a message that is reflected back to it would fail to 2901 decrypt. 2903 * Two contexts are distributed as a pair. The first context is used 2904 for encryption of the message, and the second context is used to 2905 place a counter signature on the message. The intention is that 2906 the second context can be distributed to other entities 2907 independently of the first context. This allows these entities to 2908 validate that the message came from an individual without being 2909 able to decrypt the message and see the content. 2911 * Two contexts are distributed as a pair. The first context 2912 contains a key for dealing with MACed messages, and the second 2913 context contains a different key for dealing with encrypted 2914 messages. This allows for a unified distribution of keys to 2915 participants for different types of messages that have different 2916 keys, but where the keys may be used in a coordinated manner. 2918 For these cases, the following additional items need to be 2919 considered: 2921 * Applications need to ensure that the multiple contexts stay 2922 associated. If one of the contexts is invalidated for any reason, 2923 all of the contexts associated with it should also be invalidated. 2925 Appendix B. Two Layers of Recipient Information 2927 All of the currently defined recipient algorithm classes only use two 2928 layers of the COSE_Encrypt structure. The first layer is the message 2929 content, and the second layer is the content key encryption. 2930 However, if one uses a recipient algorithm such as the RSA Key 2931 Encapsulation Mechanism (RSA-KEM) (see Appendix A of RSA-KEM 2932 [RFC5990]), then it makes sense to have three layers of the 2933 COSE_Encrypt structure. 2935 These layers would be: 2937 * Layer 0: The content encryption layer. This layer contains the 2938 payload of the message. 2940 * Layer 1: The encryption of the CEK by a KEK. 2942 * Layer 2: The encryption of a long random secret using an RSA key 2943 and a key derivation function to convert that secret into the KEK. 2945 This is an example of what a triple layer message would look like. 2946 The message has the following layers: 2948 * Layer 0: Has a content encrypted with AES-GCM using a 128-bit key. 2950 * Layer 1: Uses the AES Key Wrap algorithm with a 128-bit key. 2952 * Layer 2: Uses ECDH Ephemeral-Static direct to generate the layer 1 2953 key. 2955 In effect, this example is a decomposed version of using the 2956 ECDH-ES+A128KW algorithm. 2958 Size of binary file is 183 bytes 2960 96( 2961 [ 2962 / protected / h'a10101' / { 2963 \ alg \ 1:1 \ AES-GCM 128 \ 2964 } / , 2965 / unprotected / { 2966 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 2967 }, 2968 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e2852948658f0 2969 811139868826e89218a75715b', 2970 / recipients / [ 2971 [ 2972 / protected / h'', 2973 / unprotected / { 2974 / alg / 1:-3 / A128KW / 2975 }, 2976 / ciphertext / h'dbd43c4e9d719c27c6275c67d628d493f090593db82 2977 18f11', 2978 / recipients / [ 2979 [ 2980 / protected / h'a1013818' / { 2981 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 2982 } / , 2983 / unprotected / { 2984 / ephemeral / -1:{ 2985 / kty / 1:2, 2986 / crv / -1:1, 2987 / x / -2:h'b2add44368ea6d641f9ca9af308b4079aeb519f11 2988 e9b8a55a600b21233e86e68', 2989 / y / -3:false 2990 }, 2991 / kid / 4:'meriadoc.brandybuck@buckland.example' 2992 }, 2993 / ciphertext / h'' 2994 ] 2995 ] 2996 ] 2997 ] 2998 ] 2999 ) 3001 Appendix C. Examples 3003 This appendix includes a set of examples that show the different 3004 features and message types that have been defined in this document. 3005 To make the examples easier to read, they are presented using the 3006 extended CBOR diagnostic notation (defined in [RFC8610]) rather than 3007 as a binary dump. 3009 A GitHub project has been created at that contains not only the examples presented in this 3011 document, but a more complete set of testing examples as well. Each 3012 example is found in a JSON file that contains the inputs used to 3013 create the example, some of the intermediate values that can be used 3014 in debugging the example and the output of the example presented both 3015 as a hex dump and in CBOR diagnostic notation format. Some of the 3016 examples at the site are designed failure testing cases; these are 3017 clearly marked as such in the JSON file. If errors in the examples 3018 in this document are found, the examples on GitHub will be updated, 3019 and a note to that effect will be placed in the JSON file. 3021 As noted, the examples are presented using the CBOR's diagnostic 3022 notation. A Ruby-based tool exists that can convert between the 3023 diagnostic notation and binary. This tool can be installed with the 3024 command line: 3026 gem install cbor-diag 3028 The diagnostic notation can be converted into binary files using the 3029 following command line: 3031 diag2cbor.rb < inputfile > outputfile 3033 The examples can be extracted from the XML version of this document 3034 via an XPath expression as all of the sourcecode is tagged with the 3035 attribute type='CBORdiag'. (Depending on the XPath evaluator one is 3036 using, it may be necessary to deal with > as an entity.) 3038 //sourcecode[@type='CDDL']/text() 3040 C.1. Examples of Signed Messages 3042 C.1.1. Single Signature 3044 This example uses the following: 3046 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3048 Size of binary file is 103 bytes 3049 98( 3050 [ 3051 / protected / h'', 3052 / unprotected / {}, 3053 / payload / 'This is the content.', 3054 / signatures / [ 3055 [ 3056 / protected / h'a10126' / { 3057 \ alg \ 1:-7 \ ECDSA 256 \ 3058 } / , 3059 / unprotected / { 3060 / kid / 4:'11' 3061 }, 3062 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3063 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3064 98f53afd2fa0f30a' 3065 ] 3066 ] 3067 ] 3068 ) 3070 C.1.2. Multiple Signers 3072 This example uses the following: 3074 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3076 * Signature Algorithm: ECDSA w/ SHA-512, Curve P-521 3078 Size of binary file is 277 bytes 3079 98( 3080 [ 3081 / protected / h'', 3082 / unprotected / {}, 3083 / payload / 'This is the content.', 3084 / signatures / [ 3085 [ 3086 / protected / h'a10126' / { 3087 \ alg \ 1:-7 \ ECDSA 256 \ 3088 } / , 3089 / unprotected / { 3090 / kid / 4:'11' 3091 }, 3092 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3093 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3094 98f53afd2fa0f30a' 3095 ], 3096 [ 3097 / protected / h'a1013823' / { 3098 \ alg \ 1:-36 3099 } / , 3100 / unprotected / { 3101 / kid / 4:'bilbo.baggins@hobbiton.example' 3102 }, 3103 / signature / h'00a2d28a7c2bdb1587877420f65adf7d0b9a06635dd1 3104 de64bb62974c863f0b160dd2163734034e6ac003b01e8705524c5c4ca479a952f024 3105 7ee8cb0b4fb7397ba08d009e0c8bf482270cc5771aa143966e5a469a09f613488030 3106 c5b07ec6d722e3835adb5b2d8c44e95ffb13877dd2582866883535de3bb03d01753f 3107 83ab87bb4f7a0297' 3108 ] 3109 ] 3110 ] 3111 ) 3113 C.1.3. Counter Signature 3115 This example uses the following: 3117 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3119 * The same parameters are used for both the signature and the 3120 counter signature. 3122 Size of binary file is 180 bytes 3123 98( 3124 [ 3125 / protected / h'', 3126 / unprotected / { 3127 / countersign / 7:[ 3128 / protected / h'a10126' / { 3129 \ alg \ 1:-7 \ ECDSA 256 \ 3130 } / , 3131 / unprotected / { 3132 / kid / 4:'11' 3133 }, 3134 / signature / h'5ac05e289d5d0e1b0a7f048a5d2b643813ded50bc9e4 3135 9220f4f7278f85f19d4a77d655c9d3b51e805a74b099e1e085aacd97fc29d72f887e 3136 8802bb6650cceb2c' 3137 ] 3138 }, 3139 / payload / 'This is the content.', 3140 / signatures / [ 3141 [ 3142 / protected / h'a10126' / { 3143 \ alg \ 1:-7 \ ECDSA 256 \ 3144 } / , 3145 / unprotected / { 3146 / kid / 4:'11' 3147 }, 3148 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3149 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3150 98f53afd2fa0f30a' 3151 ] 3152 ] 3153 ] 3154 ) 3156 C.1.4. Signature with Criticality 3158 This example uses the following: 3160 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3162 * There is a criticality marker on the "reserved" header parameter 3164 Size of binary file is 125 bytes 3165 98( 3166 [ 3167 / protected / h'a2687265736572766564f40281687265736572766564' / 3168 { 3169 "reserved":false, 3170 \ crit \ 2:[ 3171 "reserved" 3172 ] 3173 } / , 3174 / unprotected / {}, 3175 / payload / 'This is the content.', 3176 / signatures / [ 3177 [ 3178 / protected / h'a10126' / { 3179 \ alg \ 1:-7 \ ECDSA 256 \ 3180 } / , 3181 / unprotected / { 3182 / kid / 4:'11' 3183 }, 3184 / signature / h'3fc54702aa56e1b2cb20284294c9106a63f91bac658d 3185 69351210a031d8fc7c5ff3e4be39445b1a3e83e1510d1aca2f2e8a7c081c7645042b 3186 18aba9d1fad1bd9c' 3187 ] 3188 ] 3189 ] 3190 ) 3192 C.2. Single Signer Examples 3194 C.2.1. Single ECDSA Signature 3196 This example uses the following: 3198 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3200 Size of binary file is 98 bytes 3201 18( 3202 [ 3203 / protected / h'a10126' / { 3204 \ alg \ 1:-7 \ ECDSA 256 \ 3205 } / , 3206 / unprotected / { 3207 / kid / 4:'11' 3208 }, 3209 / payload / 'This is the content.', 3210 / signature / h'8eb33e4ca31d1c465ab05aac34cc6b23d58fef5c083106c4 3211 d25a91aef0b0117e2af9a291aa32e14ab834dc56ed2a223444547e01f11d3b0916e5 3212 a4c345cacb36' 3213 ] 3214 ) 3216 C.3. Examples of Enveloped Messages 3218 C.3.1. Direct ECDH 3220 This example uses the following: 3222 * CEK: AES-GCM w/ 128-bit key 3224 * Recipient class: ECDH Ephemeral-Static, Curve P-256 3226 Size of binary file is 151 bytes 3227 96( 3228 [ 3229 / protected / h'a10101' / { 3230 \ alg \ 1:1 \ AES-GCM 128 \ 3231 } / , 3232 / unprotected / { 3233 / iv / 5:h'c9cf4df2fe6c632bf7886413' 3234 }, 3235 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 3236 c52a357da7a644b8070a151b0', 3237 / recipients / [ 3238 [ 3239 / protected / h'a1013818' / { 3240 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 3241 } / , 3242 / unprotected / { 3243 / ephemeral / -1:{ 3244 / kty / 1:2, 3245 / crv / -1:1, 3246 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 3247 bf054e1c7b4d91d6280', 3248 / y / -3:true 3249 }, 3250 / kid / 4:'meriadoc.brandybuck@buckland.example' 3251 }, 3252 / ciphertext / h'' 3253 ] 3254 ] 3255 ] 3256 ) 3258 C.3.2. Direct Plus Key Derivation 3260 This example uses the following: 3262 * CEK: AES-CCM w/ 128-bit key, truncate the tag to 64 bits 3264 * Recipient class: Use HKDF on a shared secret with the following 3265 implicit fields as part of the context. 3267 - salt: "aabbccddeeffgghh" 3269 - PartyU identity: "lighting-client" 3271 - PartyV identity: "lighting-server" 3273 - Supplementary Public Other: "Encryption Example 02" 3275 Size of binary file is 91 bytes 3277 96( 3278 [ 3279 / protected / h'a1010a' / { 3280 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3281 } / , 3282 / unprotected / { 3283 / iv / 5:h'89f52f65a1c580933b5261a76c' 3284 }, 3285 / ciphertext / h'753548a19b1307084ca7b2056924ed95f2e3b17006dfe93 3286 1b687b847', 3287 / recipients / [ 3288 [ 3289 / protected / h'a10129' / { 3290 \ alg \ 1:-10 3291 } / , 3292 / unprotected / { 3293 / salt / -20:'aabbccddeeffgghh', 3294 / kid / 4:'our-secret' 3295 }, 3296 / ciphertext / h'' 3297 ] 3298 ] 3299 ] 3300 ) 3302 C.3.3. Counter Signature on Encrypted Content 3304 This example uses the following: 3306 * CEK: AES-GCM w/ 128-bit key 3308 * Recipient class: ECDH Ephemeral-Static, Curve P-256 3310 Size of binary file is 326 bytes 3311 96( 3312 [ 3313 / protected / h'a10101' / { 3314 \ alg \ 1:1 \ AES-GCM 128 \ 3315 } / , 3316 / unprotected / { 3317 / iv / 5:h'c9cf4df2fe6c632bf7886413', 3318 / countersign / 7:[ 3319 / protected / h'a1013823' / { 3320 \ alg \ 1:-36 3321 } / , 3322 / unprotected / { 3323 / kid / 4:'bilbo.baggins@hobbiton.example' 3324 }, 3325 / signature / h'00929663c8789bb28177ae28467e66377da12302d7f9 3326 594d2999afa5dfa531294f8896f2b6cdf1740014f4c7f1a358e3a6cf57f4ed6fb02f 3327 cf8f7aa989f5dfd07f0700a3a7d8f3c604ba70fa9411bd10c2591b483e1d2c31de00 3328 3183e434d8fba18f17a4c7e3dfa003ac1cf3d30d44d2533c4989d3ac38c38b71481c 3329 c3430c9d65e7ddff' 3330 ] 3331 }, 3332 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 3333 c52a357da7a644b8070a151b0', 3334 / recipients / [ 3335 [ 3336 / protected / h'a1013818' / { 3337 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 3338 } / , 3339 / unprotected / { 3340 / ephemeral / -1:{ 3341 / kty / 1:2, 3342 / crv / -1:1, 3343 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 3344 bf054e1c7b4d91d6280', 3345 / y / -3:true 3346 }, 3347 / kid / 4:'meriadoc.brandybuck@buckland.example' 3348 }, 3349 / ciphertext / h'' 3350 ] 3351 ] 3352 ] 3353 ) 3355 C.3.4. Encrypted Content with External Data 3357 This example uses the following: 3359 * CEK: AES-GCM w/ 128-bit key 3361 * Recipient class: ECDH static-Static, Curve P-256 with AES Key Wrap 3363 * Externally Supplied AAD: h'0011bbcc22dd44ee55ff660077' 3365 Size of binary file is 173 bytes 3367 96( 3368 [ 3369 / protected / h'a10101' / { 3370 \ alg \ 1:1 \ AES-GCM 128 \ 3371 } / , 3372 / unprotected / { 3373 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 3374 }, 3375 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e28529d8f5335 3376 e5f0165eee976b4a5f6c6f09d', 3377 / recipients / [ 3378 [ 3379 / protected / h'a101381f' / { 3380 \ alg \ 1:-32 \ ECHD-SS+A128KW \ 3381 } / , 3382 / unprotected / { 3383 / static kid / -3:'peregrin.took@tuckborough.example', 3384 / kid / 4:'meriadoc.brandybuck@buckland.example', 3385 / U nonce / -22:h'0101' 3386 }, 3387 / ciphertext / h'41e0d76f579dbd0d936a662d54d8582037de2e366fd 3388 e1c62' 3389 ] 3390 ] 3391 ] 3392 ) 3394 C.4. Examples of Encrypted Messages 3396 C.4.1. Simple Encrypted Message 3398 This example uses the following: 3400 * CEK: AES-CCM w/ 128-bit key and a 64-bit tag 3402 Size of binary file is 52 bytes 3403 16( 3404 [ 3405 / protected / h'a1010a' / { 3406 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3407 } / , 3408 / unprotected / { 3409 / iv / 5:h'89f52f65a1c580933b5261a78c' 3410 }, 3411 / ciphertext / h'5974e1b99a3a4cc09a659aa2e9e7fff161d38ce71cb45ce 3412 460ffb569' 3413 ] 3414 ) 3416 C.4.2. Encrypted Message with a Partial IV 3418 This example uses the following: 3420 * CEK: AES-CCM w/ 128-bit key and a 64-bit tag 3422 * Prefix for IV is 89F52F65A1C580933B52 3424 Size of binary file is 41 bytes 3426 16( 3427 [ 3428 / protected / h'a1010a' / { 3429 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3430 } / , 3431 / unprotected / { 3432 / partial iv / 6:h'61a7' 3433 }, 3434 / ciphertext / h'252a8911d465c125b6764739700f0141ed09192de139e05 3435 3bd09abca' 3436 ] 3437 ) 3439 C.5. Examples of MACed Messages 3441 C.5.1. Shared Secret Direct MAC 3443 This example uses the following: 3445 * MAC: AES-CMAC, 256-bit key, truncated to 64 bits 3447 * Recipient class: direct shared secret 3449 Size of binary file is 57 bytes 3450 97( 3451 [ 3452 / protected / h'a1010f' / { 3453 \ alg \ 1:15 \ AES-CBC-MAC-256//64 \ 3454 } / , 3455 / unprotected / {}, 3456 / payload / 'This is the content.', 3457 / tag / h'9e1226ba1f81b848', 3458 / recipients / [ 3459 [ 3460 / protected / h'', 3461 / unprotected / { 3462 / alg / 1:-6 / direct /, 3463 / kid / 4:'our-secret' 3464 }, 3465 / ciphertext / h'' 3466 ] 3467 ] 3468 ] 3469 ) 3471 C.5.2. ECDH Direct MAC 3473 This example uses the following: 3475 * MAC: HMAC w/SHA-256, 256-bit key 3477 * Recipient class: ECDH key agreement, two static keys, HKDF w/ 3478 context structure 3480 Size of binary file is 214 bytes 3481 97( 3482 [ 3483 / protected / h'a10105' / { 3484 \ alg \ 1:5 \ HMAC 256//256 \ 3485 } / , 3486 / unprotected / {}, 3487 / payload / 'This is the content.', 3488 / tag / h'81a03448acd3d305376eaa11fb3fe416a955be2cbe7ec96f012c99 3489 4bc3f16a41', 3490 / recipients / [ 3491 [ 3492 / protected / h'a101381a' / { 3493 \ alg \ 1:-27 \ ECDH-SS + HKDF-256 \ 3494 } / , 3495 / unprotected / { 3496 / static kid / -3:'peregrin.took@tuckborough.example', 3497 / kid / 4:'meriadoc.brandybuck@buckland.example', 3498 / U nonce / -22:h'4d8553e7e74f3c6a3a9dd3ef286a8195cbf8a23d 3499 19558ccfec7d34b824f42d92bd06bd2c7f0271f0214e141fb779ae2856abf585a583 3500 68b017e7f2a9e5ce4db5' 3501 }, 3502 / ciphertext / h'' 3503 ] 3504 ] 3505 ] 3506 ) 3508 C.5.3. Wrapped MAC 3510 This example uses the following: 3512 * MAC: AES-MAC, 128-bit key, truncated to 64 bits 3514 * Recipient class: AES Key Wrap w/ a pre-shared 256-bit key 3516 Size of binary file is 109 bytes 3517 97( 3518 [ 3519 / protected / h'a1010e' / { 3520 \ alg \ 1:14 \ AES-CBC-MAC-128//64 \ 3521 } / , 3522 / unprotected / {}, 3523 / payload / 'This is the content.', 3524 / tag / h'36f5afaf0bab5d43', 3525 / recipients / [ 3526 [ 3527 / protected / h'', 3528 / unprotected / { 3529 / alg / 1:-5 / A256KW /, 3530 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 3531 }, 3532 / ciphertext / h'711ab0dc2fc4585dce27effa6781c8093eba906f227 3533 b6eb0' 3534 ] 3535 ] 3536 ] 3537 ) 3539 C.5.4. Multi-Recipient MACed Message 3541 This example uses the following: 3543 * MAC: HMAC w/ SHA-256, 128-bit key 3545 * Recipient class: Uses three different methods 3547 1. ECDH Ephemeral-Static, Curve P-521, AES Key Wrap w/ 128-bit 3548 key 3550 2. AES Key Wrap w/ 256-bit key 3552 Size of binary file is 309 bytes 3553 97( 3554 [ 3555 / protected / h'a10105' / { 3556 \ alg \ 1:5 \ HMAC 256//256 \ 3557 } / , 3558 / unprotected / {}, 3559 / payload / 'This is the content.', 3560 / tag / h'bf48235e809b5c42e995f2b7d5fa13620e7ed834e337f6aa43df16 3561 1e49e9323e', 3562 / recipients / [ 3563 [ 3564 / protected / h'a101381c' / { 3565 \ alg \ 1:-29 \ ECHD-ES+A128KW \ 3566 } / , 3567 / unprotected / { 3568 / ephemeral / -1:{ 3569 / kty / 1:2, 3570 / crv / -1:3, 3571 / x / -2:h'0043b12669acac3fd27898ffba0bcd2e6c366d53bc4db 3572 71f909a759304acfb5e18cdc7ba0b13ff8c7636271a6924b1ac63c02688075b55ef2 3573 d613574e7dc242f79c3', 3574 / y / -3:true 3575 }, 3576 / kid / 4:'bilbo.baggins@hobbiton.example' 3577 }, 3578 / ciphertext / h'339bc4f79984cdc6b3e6ce5f315a4c7d2b0ac466fce 3579 a69e8c07dfbca5bb1f661bc5f8e0df9e3eff5' 3580 ], 3581 [ 3582 / protected / h'', 3583 / unprotected / { 3584 / alg / 1:-5 / A256KW /, 3585 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 3586 }, 3587 / ciphertext / h'0b2c7cfce04e98276342d6476a7723c090dfdd15f9a 3588 518e7736549e998370695e6d6a83b4ae507bb' 3589 ] 3590 ] 3591 ] 3592 ) 3594 C.6. Examples of MAC0 Messages 3596 C.6.1. Shared Secret Direct MAC 3598 This example uses the following: 3600 * MAC: AES-CMAC, 256-bit key, truncated to 64 bits 3601 * Recipient class: direct shared secret 3603 Size of binary file is 37 bytes 3605 17( 3606 [ 3607 / protected / h'a1010f' / { 3608 \ alg \ 1:15 \ AES-CBC-MAC-256//64 \ 3609 } / , 3610 / unprotected / {}, 3611 / payload / 'This is the content.', 3612 / tag / h'726043745027214f' 3613 ] 3614 ) 3616 Note that this example uses the same inputs as Appendix C.5.1. 3618 C.7. COSE Keys 3620 C.7.1. Public Keys 3622 This is an example of a COSE Key Set. This example includes the 3623 public keys for all of the previous examples. 3625 In order the keys are: 3627 * An EC key with a kid of "meriadoc.brandybuck@buckland.example" 3629 * An EC key with a kid of "peregrin.took@tuckborough.example" 3631 * An EC key with a kid of "bilbo.baggins@hobbiton.example" 3633 * An EC key with a kid of "11" 3635 Size of binary file is 481 bytes 3637 [ 3638 { 3639 -1:1, 3640 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 3641 8551d', 3642 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 3643 4d19c', 3644 1:2, 3645 2:'meriadoc.brandybuck@buckland.example' 3646 }, 3647 { 3648 -1:1, 3649 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 3650 09eff', 3651 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 3652 c117e', 3653 1:2, 3654 2:'11' 3655 }, 3656 { 3657 -1:3, 3658 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 3659 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 3660 f42ad', 3661 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 3662 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 3663 d9475', 3664 1:2, 3665 2:'bilbo.baggins@hobbiton.example' 3666 }, 3667 { 3668 -1:1, 3669 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 3670 d6280', 3671 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 3672 822bb', 3673 1:2, 3674 2:'peregrin.took@tuckborough.example' 3675 } 3676 ] 3678 C.7.2. Private Keys 3680 This is an example of a COSE Key Set. This example includes the 3681 private keys for all of the previous examples. 3683 In order the keys are: 3685 * An EC key with a kid of "meriadoc.brandybuck@buckland.example" 3687 * A shared-secret key with a kid of "our-secret" 3689 * An EC key with a kid of "peregrin.took@tuckborough.example" 3691 * A shared-secret key with a kid of "018c0ae5-4d9b-471b- 3692 bfd6-eef314bc7037" 3694 * An EC key with a kid of "bilbo.baggins@hobbiton.example" 3696 * An EC key with a kid of "11" 3698 Size of binary file is 816 bytes 3700 [ 3701 { 3702 1:2, 3703 2:'meriadoc.brandybuck@buckland.example', 3704 -1:1, 3705 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 3706 8551d', 3707 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 3708 4d19c', 3709 -4:h'aff907c99f9ad3aae6c4cdf21122bce2bd68b5283e6907154ad911840fa 3710 208cf' 3711 }, 3712 { 3713 1:2, 3714 2:'11', 3715 -1:1, 3716 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 3717 09eff', 3718 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 3719 c117e', 3720 -4:h'57c92077664146e876760c9520d054aa93c3afb04e306705db609030850 3721 7b4d3' 3722 }, 3723 { 3724 1:2, 3725 2:'bilbo.baggins@hobbiton.example', 3726 -1:3, 3727 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 3728 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 3729 f42ad', 3730 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 3731 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 3732 d9475', 3733 -4:h'00085138ddabf5ca975f5860f91a08e91d6d5f9a76ad4018766a476680b 3734 55cd339e8ab6c72b5facdb2a2a50ac25bd086647dd3e2e6e99e84ca2c3609fdf177f 3735 eb26d' 3736 }, 3737 { 3738 1:4, 3739 2:'our-secret', 3740 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 3741 27188' 3742 }, 3743 { 3744 1:2, 3745 -1:1, 3746 2:'peregrin.took@tuckborough.example', 3747 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 3748 d6280', 3749 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 3750 822bb', 3751 -4:h'02d1f7e6f26c43d4868d87ceb2353161740aacf1f7163647984b522a848 3752 df1c3' 3753 }, 3754 { 3755 1:4, 3756 2:'our-secret2', 3757 -1:h'849b5786457c1491be3a76dcea6c4271' 3758 }, 3759 { 3760 1:4, 3761 2:'018c0ae5-4d9b-471b-bfd6-eef314bc7037', 3762 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 3763 27188' 3764 } 3765 ] 3767 Acknowledgments 3769 This document is a product of the COSE working group of the IETF. 3771 The following individuals are to blame for getting me started on this 3772 project in the first place: Richard Barnes, Matt Miller, and Martin 3773 Thomson. 3775 The initial version of the specification was based to some degree on 3776 the outputs of the JOSE and S/MIME working groups. 3778 The following individuals provided input into the final form of the 3779 document: Carsten Bormann, John Bradley, Brain Campbell, Michael B. 3781 Jones, Ilari Liusvaara, Francesca Palombini, Ludwig Seitz, and Goran 3782 Selander. 3784 Author's Address 3786 Jim Schaad 3787 August Cellars 3789 Email: ietf@augustcellars.com