idnits 2.17.1 draft-ietf-cose-rfc8152bis-struct-15.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 == Line 2967 has weird spacing: '...otected h'a10...' == Line 2985 has weird spacing: '...otected h'a10...' == Line 3251 has weird spacing: '...otected h'a10...' == Line 3336 has weird spacing: '...otected h'a10...' == Line 3360 has weird spacing: '...otected h'a10...' == (3 more instances...) -- The document date (1 February 2021) is 1152 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) -- Possible downref: Normative reference to a draft: ref. 'I-D.ietf-cbor-7049bis' ** 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) == Outdated reference: A later version (-10) exists of draft-ietf-core-groupcomm-bis-02 == Outdated reference: A later version (-13) exists of draft-irtf-cfrg-argon2-12 -- No information found for draft-ietf-cose-countersign - is the name correct? Summary: 2 errors (**), 0 flaws (~~), 9 warnings (==), 6 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) 1 February 2021 5 Intended status: Standards Track 6 Expires: 5 August 2021 8 CBOR Object Signing and Encryption (COSE): Structures and Process 9 draft-ietf-cose-rfc8152bis-struct-15 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 5 August 2021. 51 Copyright Notice 53 Copyright (c) 2021 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. Requirements Terminology . . . . . . . . . . . . . . . . 6 69 1.2. Changes from RFC8152 . . . . . . . . . . . . . . . . . . 6 70 1.3. Design Changes from JOSE . . . . . . . . . . . . . . . . 6 71 1.4. CBOR Grammar . . . . . . . . . . . . . . . . . . . . . . 7 72 1.5. CBOR-Related Terminology . . . . . . . . . . . . . . . . 8 73 1.6. Document Terminology . . . . . . . . . . . . . . . . . . 9 74 2. Basic COSE Structure . . . . . . . . . . . . . . . . . . . . 10 75 3. Header Parameters . . . . . . . . . . . . . . . . . . . . . . 13 76 3.1. Common COSE Header Parameters . . . . . . . . . . . . . . 15 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. Encryption Objects . . . . . . . . . . . . . . . . . . . . . 24 83 5.1. Enveloped COSE Structure . . . . . . . . . . . . . . . . 24 84 5.1.1. Content Key Distribution Methods . . . . . . . . . . 26 85 5.2. Single Recipient Encrypted . . . . . . . . . . . . . . . 26 86 5.3. How to Encrypt and Decrypt for AEAD Algorithms . . . . . 27 87 5.4. How to Encrypt and Decrypt for AE Algorithms . . . . . . 29 88 6. MAC Objects . . . . . . . . . . . . . . . . . . . . . . . . . 30 89 6.1. MACed Message with Recipients . . . . . . . . . . . . . . 31 90 6.2. MACed Messages with Implicit Key . . . . . . . . . . . . 32 91 6.3. How to Compute and Verify a MAC . . . . . . . . . . . . . 33 92 7. Key Objects . . . . . . . . . . . . . . . . . . . . . . . . . 34 93 7.1. COSE Key Common Parameters . . . . . . . . . . . . . . . 35 94 8. Taxonomy of Algorithms used by COSE . . . . . . . . . . . . . 37 95 8.1. Signature Algorithms . . . . . . . . . . . . . . . . . . 38 96 8.2. Message Authentication Code (MAC) Algorithms . . . . . . 40 97 8.3. Content Encryption Algorithms . . . . . . . . . . . . . . 40 98 8.4. Key Derivation Functions (KDFs) . . . . . . . . . . . . . 41 99 8.5. Content Key Distribution Methods . . . . . . . . . . . . 41 100 8.5.1. Direct Encryption . . . . . . . . . . . . . . . . . . 42 101 8.5.2. Key Wrap . . . . . . . . . . . . . . . . . . . . . . 42 102 8.5.3. Key Transport . . . . . . . . . . . . . . . . . . . . 43 103 8.5.4. Direct Key Agreement . . . . . . . . . . . . . . . . 43 104 8.5.5. Key Agreement with Key Wrap . . . . . . . . . . . . . 44 105 9. CBOR Encoding Restrictions . . . . . . . . . . . . . . . . . 45 106 10. Application Profiling Considerations . . . . . . . . . . . . 45 107 11. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 46 108 11.1. COSE Header Parameters Registry . . . . . . . . . . . . 47 109 11.2. COSE Key Common Parameters Registry . . . . . . . . . . 47 110 11.3. Media Type Registrations . . . . . . . . . . . . . . . . 47 111 11.3.1. COSE Security Message . . . . . . . . . . . . . . . 47 112 11.3.2. COSE Key Media Type . . . . . . . . . . . . . . . . 48 113 11.4. CoAP Content-Formats Registry . . . . . . . . . . . . . 50 114 11.5. CBOR Tags Registry . . . . . . . . . . . . . . . . . . . 50 115 11.6. Expert Review Instructions . . . . . . . . . . . . . . . 51 116 12. Security Considerations . . . . . . . . . . . . . . . . . . . 52 117 13. Implementation Status . . . . . . . . . . . . . . . . . . . . 53 118 13.1. Author's Versions . . . . . . . . . . . . . . . . . . . 54 119 13.2. JavaScript Version . . . . . . . . . . . . . . . . . . . 55 120 13.3. Python Version . . . . . . . . . . . . . . . . . . . . . 55 121 13.4. COSE Testing Library . . . . . . . . . . . . . . . . . . 55 122 14. References . . . . . . . . . . . . . . . . . . . . . . . . . 56 123 14.1. Normative References . . . . . . . . . . . . . . . . . . 56 124 14.2. Informative References . . . . . . . . . . . . . . . . . 56 125 Appendix A. Guidelines for External Data Authentication of 126 Algorithms . . . . . . . . . . . . . . . . . . . . . . . 60 127 Appendix B. Two Layers of Recipient Information . . . . . . . . 63 128 Appendix C. Examples . . . . . . . . . . . . . . . . . . . . . . 65 129 C.1. Examples of Signed Messages . . . . . . . . . . . . . . . 66 130 C.1.1. Single Signature . . . . . . . . . . . . . . . . . . 66 131 C.1.2. Multiple Signers . . . . . . . . . . . . . . . . . . 67 132 C.1.3. Signature with Criticality . . . . . . . . . . . . . 68 133 C.2. Single Signer Examples . . . . . . . . . . . . . . . . . 69 134 C.2.1. Single ECDSA Signature . . . . . . . . . . . . . . . 69 135 C.3. Examples of Enveloped Messages . . . . . . . . . . . . . 70 136 C.3.1. Direct ECDH . . . . . . . . . . . . . . . . . . . . . 70 137 C.3.2. Direct Plus Key Derivation . . . . . . . . . . . . . 71 138 C.3.3. Encrypted Content with External Data . . . . . . . . 72 139 C.4. Examples of Encrypted Messages . . . . . . . . . . . . . 73 140 C.4.1. Simple Encrypted Message . . . . . . . . . . . . . . 73 141 C.4.2. Encrypted Message with a Partial IV . . . . . . . . . 74 142 C.5. Examples of MACed Messages . . . . . . . . . . . . . . . 74 143 C.5.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 74 144 C.5.2. ECDH Direct MAC . . . . . . . . . . . . . . . . . . . 75 145 C.5.3. Wrapped MAC . . . . . . . . . . . . . . . . . . . . . 76 146 C.5.4. Multi-Recipient MACed Message . . . . . . . . . . . . 77 147 C.6. Examples of MAC0 Messages . . . . . . . . . . . . . . . . 78 148 C.6.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 78 149 C.7. COSE Keys . . . . . . . . . . . . . . . . . . . . . . . . 79 150 C.7.1. Public Keys . . . . . . . . . . . . . . . . . . . . . 79 151 C.7.2. Private Keys . . . . . . . . . . . . . . . . . . . . 80 152 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 82 153 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 83 155 1. Introduction 157 There has been an increased focus on small, constrained devices that 158 make up the Internet of Things (IoT). One of the standards that has 159 come out of this process is "Concise Binary Object Representation 160 (CBOR)" [I-D.ietf-cbor-7049bis]. CBOR extended the data model of the 161 JavaScript Object Notation (JSON) [STD90] by allowing for binary 162 data, among other changes. CBOR has been adopted by several of the 163 IETF working groups dealing with the IoT world as their encoding of 164 data structures. CBOR was designed specifically both to be small in 165 terms of messages transported and implementation size and to be a 166 schema-free decoder. A need exists to provide message security 167 services for IoT, and using CBOR as the message-encoding format makes 168 sense. 170 The JOSE working group produced a set of documents [RFC7515] 171 [RFC7516] [RFC7517] [RFC7518] that specified how to process 172 encryption, signatures, and Message Authentication Code (MAC) 173 operations and how to encode keys using JSON. This document defines 174 the CBOR Object Signing and Encryption (COSE) standard, which does 175 the same thing for the CBOR encoding format. This document is 176 combined with [I-D.ietf-cose-rfc8152bis-algs] which provides an 177 initial set of algorithms. While there is a strong attempt to keep 178 the flavor of the original JSON Object Signing and Encryption (JOSE) 179 documents, two considerations are taken into account: 181 * CBOR has capabilities that are not present in JSON and are 182 appropriate to use. One example of this is the fact that CBOR has 183 a method of encoding binary directly without first converting it 184 into a base64-encoded text string. 186 * COSE is not a direct copy of the JOSE specification. In the 187 process of creating COSE, decisions that were made for JOSE were 188 re-examined. In many cases, different results were decided on as 189 the criteria were not always the same. 191 This document contains: 193 * The description of the structure for the CBOR objects which are 194 transmitted over the wire. Two objects are defined for each of 195 encryption, signing and message authentication. One object is 196 defined for transporting keys and one for transporting groups of 197 keys. 199 * The procedures used to build the inputs to the cryptographic 200 functions required for each of the structures. 202 * A set of attributes that apply to the different security objects. 204 This document does not contain the rules and procedures for using 205 specific cryptographic algorithms. Details on specific algorithms 206 can be found in [I-D.ietf-cose-rfc8152bis-algs] and [RFC8230]. 207 Details for additional algorithms are expected to be defined in 208 future documents. 210 COSE was initially designed as part of a solution to provide security 211 to Constrained RESTful Environments (CoRE), and this is done using 212 [RFC8613] and [I-D.ietf-core-groupcomm-bis]. However, COSE is not 213 restricted to just these cases and can be used in any place where one 214 would consider either JOSE or CMS [RFC5652] for the purpose of 215 providing security services. COSE, like JOSE and CMS, is only for 216 use in store and forward or offline protocols. The use of COSE in 217 online protocols needing encryption, require that an online key 218 establishment process be done before sending objects back and forth. 219 Any application which uses COSE for security services first needs to 220 determine what security services are required and then select the 221 appropriate COSE structures and cryptographic algorithms based on 222 those needs. Section 10 provides additional information on what 223 applications need to specify when using COSE. 225 One feature that is present in CMS that is not present in this 226 standard is a digest structure. This omission is deliberate. It is 227 better for the structure to be defined in each protocol as different 228 protocols will want to include a different set of fields as part of 229 the structure. While an algorithm identifier and the digest value 230 are going to be common to all applications, the two values may not 231 always be adjacent as the algorithm could be defined once with 232 multiple values. Applications may additionally want to define 233 additional data fields as part of the structure. One such 234 application-specific element would be to include a URI or other 235 pointer to where the data that is being hashed can be obtained. 236 [I-D.ietf-cose-hash-algs] contains one such possible structure along 237 with defining a set of digest algorithms. 239 During the process of advancing COSE to Internet Standard, it was 240 noticed the description of the security properties of 241 countersignatures was incorrect for the COSE_Sign1 structure. Since 242 the security properties that were described, those of a true 243 countersignature, were those that the working group desired, the 244 decision was made to remove all of the countersignature text from 245 this document and create a new document [I-D.ietf-cose-countersign] 246 to both deprecate the old countersignature algorithm and header 247 parameters and to define a new algorithm and header parameters with 248 the desired security properties. 250 1.1. Requirements Terminology 252 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 253 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 254 "OPTIONAL" in this document are to be interpreted as described in BCP 255 14 [RFC2119] [RFC8174] when, and only when, they appear in all 256 capitals, as shown here. 258 1.2. Changes from RFC8152 260 * Split the original document into this document and 261 [I-D.ietf-cose-rfc8152bis-algs]. 263 * Add some text describing why there is no digest structure defined 264 by COSE. 266 * Text clarifications and changes in terminology. 268 * All of the details relating to countersignatures have been removed 269 and placed in [I-D.ietf-cose-countersign]. 271 1.3. Design Changes from JOSE 273 * Define a single overall message structure so that encrypted, 274 signed, and MACed messages can easily be identified and still have 275 a consistent view. 277 * Signed messages distinguish between the protected and unprotected 278 header parameters that relate to the content and those that relate 279 to the signature. 281 * MACed messages are separated from signed messages. 283 * MACed messages have the ability to use the same set of recipient 284 algorithms as enveloped messages for obtaining the MAC 285 authentication key. 287 * Use binary encodings, rather than base64url encodings, to encode 288 binary data. 290 * Combine the authentication tag for encryption algorithms with the 291 ciphertext. 293 * The set of cryptographic algorithms has been expanded in some 294 directions and trimmed in others. 296 1.4. CBOR Grammar 298 There was not a standard CBOR grammar available when COSE was 299 originally written. For that reason the CBOR data objects defined 300 here are described in prose. Since that time CBOR Data Definition 301 Language (CDDL) [RFC8610] has been published as an RFC. The CBOR 302 grammar presented in this document is compatible with CDDL. 304 The document was developed by first working on the grammar and then 305 developing the prose to go with it. An artifact of this is that the 306 prose was written using the primitive type strings defined by CBOR 307 Data Definition Language (CDDL) [RFC8610]. In this specification, 308 the following primitive types are used: 310 any -- non-specific value that permits all CBOR values to be 311 placed here. 313 bool -- a boolean value (true: major type 7, value 21; false: 314 major type 7, value 20). 316 bstr -- byte string (major type 2). 318 int -- an unsigned integer or a negative integer. 320 nil -- a null value (major type 7, value 22). 322 nint -- a negative integer (major type 1). 324 tstr -- a UTF-8 text string (major type 3). 326 uint -- an unsigned integer (major type 0). 328 Two syntaxes from CDDL appear in this document as shorthand. These 329 are: 331 FOO / BAR -- indicates that either FOO or BAR can appear here. 333 [+ FOO] -- indicates that the type FOO appears one or more times 334 in an array. 336 * FOO -- indicates that the type FOO appears zero or more times. 338 Two of the constraints defined by CDDL are also used in this 339 document. These are: 341 type1 .cbor type2 -- indicates that the contents of type1, usually 342 bstr, contains a value of type2. 344 type1 .size integer -- indicates that the contents of type1 is 345 integer bytes long 347 As well as the prose description, a version of a CBOR grammar is 348 presented in CDDL. The CDDL grammar is informational; the prose 349 description is normative. 351 The collected CDDL can be extracted from the XML version of this 352 document via the following XPath expression below. (Depending on the 353 XPath evaluator one is using, it may be necessary to deal with > 354 as an entity.) 356 //sourcecode[@type='CDDL']/text() 358 CDDL expects the initial non-terminal symbol to be the first symbol 359 in the file. For this reason, the first fragment of CDDL is 360 presented here. 362 start = COSE_Messages / COSE_Key / COSE_KeySet / Internal_Types 364 ; This is defined to make the tool quieter: 365 Internal_Types = Sig_structure / Enc_structure / MAC_structure 367 The non-terminal Internal_Types is defined for dealing with the 368 automated validation tools used during the writing of this document. 369 It references those non-terminals that are used for security 370 computations but are not emitted for transport. 372 1.5. CBOR-Related Terminology 374 In JSON, maps are called objects and only have one kind of map key: a 375 text string. In COSE, we use text strings, negative integers, and 376 unsigned integers as map keys. The integers are used for compactness 377 of encoding and easy comparison. The inclusion of text strings 378 allows for an additional range of short encoded values to be used as 379 well. Since the word "key" is mainly used in its other meaning, as a 380 cryptographic key, we use the term "label" for this usage as a map 381 key. 383 The presence a label that is neither a text string or an integer, in 384 a CBOR map, is an error. Applications can either fail processing or 385 process messages by ignoring incorrect labels; however, they MUST NOT 386 create messages with incorrect labels. 388 A CDDL grammar fragment defines the non-terminal 'label', as in the 389 previous paragraph, and 'values', which permits any value to be used. 391 label = int / tstr 392 values = any 394 1.6. Document Terminology 396 In this document, we use the following terminology: 398 Byte is a synonym for octet. 400 Constrained Application Protocol (CoAP) is a specialized web transfer 401 protocol for use in constrained systems. It is defined in [RFC7252]. 403 Authenticated Encryption (AE) [RFC5116] algorithms are encryption 404 algorithms that provide an authentication check of the contents with 405 the encryption service. An example of an AE algorithm used in COSE 406 is AES Key Wrap [RFC3394]. These algorithms are used for key 407 encryption algorithms, but AEAD algorithms would be preferred. 409 Authenticated Encryption with Associated Data (AEAD) [RFC5116] 410 algorithms provide the same authentication service of the content as 411 AE algorithms do. They also allow for associated data to be included 412 in the authentication service, but which is not part of the encrypted 413 body. An example of an AEAD algorithm used in COSE is AES-GCM 414 [RFC5116]. These algorithms are used for content encryption and can 415 be used for key encryption as well. 417 Context is used throughout the document to represent information that 418 is not part of the COSE message. Information which is part of the 419 context can come from several different sources including: Protocol 420 interactions, associated key structures, and program configuration. 421 The context to use can be implicit, identified using the 'kid 422 context' header parameter defined in [RFC8613], or identified by a 423 protocol-specific identifier. Context should generally be included 424 in the cryptographic construction; for more details see Section 4.3. 426 The term 'byte string' is used for sequences of bytes, while the term 427 'text string' is used for sequences of characters. 429 2. Basic COSE Structure 431 The COSE object structure is designed so that there can be a large 432 amount of common code when parsing and processing the different types 433 of security messages. All of the message structures are built on the 434 CBOR array type. The first three elements of the array always 435 contain the same information: 437 1. The protected header parameters, encoded and wrapped in a bstr. 439 2. The unprotected header parameters as a map. 441 3. The content of the message. The content is either the plaintext 442 or the ciphertext as appropriate. The content may be detached 443 (i.e. transported separately from the COSE structure), but the 444 location is still used. The content is wrapped in a bstr when 445 present and is a nil value when detached. 447 Elements after this point are dependent on the specific message type. 449 COSE messages are built using the concept of layers to separate 450 different types of cryptographic concepts. As an example of how this 451 works, consider the COSE_Encrypt message (Section 5.1). This message 452 type is broken into two layers: the content layer and the recipient 453 layer. The content layer contains the encrypted plaintext and 454 information about the encrypted message. The recipient layer 455 contains the encrypted content encryption key (CEK) and information 456 about how it is encrypted for each recipient. A single layer version 457 of the encryption message COSE_Encrypt0 (Section 5.2) is provided for 458 cases where the CEK is pre-shared. 460 Identification of which type of message has been presented is done by 461 the following methods: 463 1. The specific message type is known from the context. This may be 464 defined by a marker in the containing structure or by 465 restrictions specified by the application protocol. 467 2. The message type is identified by a CBOR tag. Messages with a 468 CBOR tag are known in this specification as tagged messages, 469 while those without the CBOR tag are known as untagged messages. 470 This document defines a CBOR tag for each of the message 471 structures. These tags can be found in Table 1. 473 3. When a COSE object is carried in a media type of 'application/ 474 cose', the optional parameter 'cose-type' can be used to identify 475 the embedded object. The parameter is OPTIONAL if the tagged 476 version of the structure is used. The parameter is REQUIRED if 477 the untagged version of the structure is used. The value to use 478 with the parameter for each of the structures can be found in 479 Table 1. 481 4. When a COSE object is carried as a CoAP payload, the CoAP 482 Content-Format Option can be used to identify the message 483 content. The CoAP Content-Format values can be found in Table 2. 484 The CBOR tag for the message structure is not required as each 485 security message is uniquely identified. 487 +==========+===============+===============+=======================+ 488 | CBOR Tag | cose-type | Data Item | Semantics | 489 +==========+===============+===============+=======================+ 490 | 98 | cose-sign | COSE_Sign | COSE Signed Data | 491 | | | | Object | 492 +----------+---------------+---------------+-----------------------+ 493 | 18 | cose-sign1 | COSE_Sign1 | COSE Single Signer | 494 | | | | Data Object | 495 +----------+---------------+---------------+-----------------------+ 496 | 96 | cose-encrypt | COSE_Encrypt | COSE Encrypted Data | 497 | | | | Object | 498 +----------+---------------+---------------+-----------------------+ 499 | 16 | cose-encrypt0 | COSE_Encrypt0 | COSE Single Recipient | 500 | | | | Encrypted Data Object | 501 +----------+---------------+---------------+-----------------------+ 502 | 97 | cose-mac | COSE_Mac | COSE MACed Data | 503 | | | | Object | 504 +----------+---------------+---------------+-----------------------+ 505 | 17 | cose-mac0 | COSE_Mac0 | COSE Mac w/o | 506 | | | | Recipients Object | 507 +----------+---------------+---------------+-----------------------+ 509 Table 1: COSE Message Identification 511 +===========================+==========+=====+============+ 512 | Media Type | Encoding | ID | Reference | 513 +===========================+==========+=====+============+ 514 | application/cose; cose- | | 98 | [[THIS | 515 | type="cose-sign" | | | DOCUMENT]] | 516 +---------------------------+----------+-----+------------+ 517 | application/cose; cose- | | 18 | [[THIS | 518 | type="cose-sign1" | | | DOCUMENT]] | 519 +---------------------------+----------+-----+------------+ 520 | application/cose; cose- | | 96 | [[THIS | 521 | type="cose-encrypt" | | | DOCUMENT]] | 522 +---------------------------+----------+-----+------------+ 523 | application/cose; cose- | | 16 | [[THIS | 524 | type="cose-encrypt0" | | | DOCUMENT]] | 525 +---------------------------+----------+-----+------------+ 526 | application/cose; cose- | | 97 | [[THIS | 527 | type="cose-mac" | | | DOCUMENT]] | 528 +---------------------------+----------+-----+------------+ 529 | application/cose; cose- | | 17 | [[THIS | 530 | type="cose-mac0" | | | DOCUMENT]] | 531 +---------------------------+----------+-----+------------+ 532 | application/cose-key | | 101 | [[THIS | 533 | | | | DOCUMENT]] | 534 +---------------------------+----------+-----+------------+ 535 | application/cose-key-set | | 102 | [[THIS | 536 | | | | DOCUMENT]] | 537 +---------------------------+----------+-----+------------+ 539 Table 2: CoAP Content-Formats for COSE 541 The following CDDL fragment identifies all of the top messages 542 defined in this document. Separate non-terminals are defined for the 543 tagged and the untagged versions of the messages. 545 COSE_Messages = COSE_Untagged_Message / COSE_Tagged_Message 547 COSE_Untagged_Message = COSE_Sign / COSE_Sign1 / 548 COSE_Encrypt / COSE_Encrypt0 / 549 COSE_Mac / COSE_Mac0 551 COSE_Tagged_Message = COSE_Sign_Tagged / COSE_Sign1_Tagged / 552 COSE_Encrypt_Tagged / COSE_Encrypt0_Tagged / 553 COSE_Mac_Tagged / COSE_Mac0_Tagged 555 3. Header Parameters 557 The structure of COSE has been designed to have two buckets of 558 information that are not considered to be part of the payload itself, 559 but are used for holding information about content, algorithms, keys, 560 or evaluation hints for the processing of the layer. These two 561 buckets are available for use in all of the structures except for 562 keys. While these buckets are present, they may not always be usable 563 in all instances. For example, while the protected bucket is defined 564 as part of the recipient structure, some of the algorithms used for 565 recipient structures do not provide for authenticated data. If this 566 is the case, the protected bucket is left empty. 568 Both buckets are implemented as CBOR maps. The map key is a 'label' 569 (Section 1.5). The value portion is dependent on the definition for 570 the label. Both maps use the same set of label/value pairs. The 571 integer and text string values for labels have been divided into 572 several sections including a standard range, a private range, and a 573 range that is dependent on the algorithm selected. The defined 574 labels can be found in the "COSE Header Parameters" IANA registry 575 (Section 11.1). 577 The two buckets are: 579 protected: Contains parameters about the current layer that are 580 cryptographically protected. This bucket MUST be empty if it is 581 not going to be included in a cryptographic computation. This 582 bucket is encoded in the message as a binary object. This value 583 is obtained by CBOR encoding the protected map and wrapping it in 584 a bstr object. Senders SHOULD encode a zero-length map as a zero- 585 length byte string rather than as a zero-length map (encoded as 586 h'a0'). The zero-length binary encoding is preferred because it 587 is both shorter and the version used in the serialization 588 structures for cryptographic computation. Recipients MUST accept 589 both a zero-length byte string and a zero-length map encoded in a 590 byte string. 592 Wrapping the encoding with a byte string allows for the protected 593 map to be transported with a greater chance that it will not be 594 altered accidentally in transit. (Badly behaved intermediates 595 could decode and re-encode, but this will result in a failure to 596 verify unless the re-encoded byte string is identical to the 597 decoded byte string.) This avoids the problem of all parties 598 needing to be able to do a common canonical encoding of the map 599 for input to cyprtographic operations. 601 unprotected: Contains parameters about the current layer that are 602 not cryptographically protected. 604 Only header parameters that deal with the current layer are to be 605 placed at that layer. As an example of this, the header parameter 606 'content type' describes the content of the message being carried in 607 the message. As such, this header parameter is placed only in the 608 content layer and is not placed in the recipient or signature layers. 609 In principle, one should be able to process any given layer without 610 reference to any other layer. With the exception of the COSE_Sign 611 structure, the only data that needs to cross layers is the 612 cryptographic key. 614 The buckets are present in all of the security objects defined in 615 this document. The fields in order are the 'protected' bucket (as a 616 CBOR 'bstr' type) and then the 'unprotected' bucket (as a CBOR 'map' 617 type). The presence of both buckets is required. The header 618 parameters that go into the buckets come from the IANA "COSE Header 619 Parameters" registry (Section 11.1). Some header parameters are 620 defined in the next section. 622 Labels in each of the maps MUST be unique. When processing messages, 623 if a label appears multiple times, the message MUST be rejected as 624 malformed. Applications SHOULD verify that the same label does not 625 occur in both the protected and unprotected header parameters. If 626 the message is not rejected as malformed, attributes MUST be obtained 627 from the protected bucket, and only if not found are attributes 628 obtained from the unprotected bucket. 630 The following CDDL fragment represents the two header parameter 631 buckets. A group "Headers" is defined in CDDL that represents the 632 two buckets in which attributes are placed. This group is used to 633 provide these two fields consistently in all locations. A type is 634 also defined that represents the map of common header parameters. 636 Headers = ( 637 protected : empty_or_serialized_map, 638 unprotected : header_map 639 ) 641 header_map = { 642 Generic_Headers, 643 * label => values 644 } 646 empty_or_serialized_map = bstr .cbor header_map / bstr .size 0 648 3.1. Common COSE Header Parameters 650 This section defines a set of common header parameters. A summary of 651 these header parameters can be found in Table 3. This table should 652 be consulted to determine the value of label and the type of the 653 value. 655 The set of header parameters defined in this section are: 657 alg: This header parameter is used to indicate the algorithm used 658 for the security processing. This header parameter MUST be 659 authenticated where the ability to do so exists. This support is 660 provided by AEAD algorithms or construction (e.g. COSE_Sign and 661 COSE_Mac0). This authentication can be done either by placing the 662 header parameter in the protected header parameter bucket or as 663 part of the externally supplied data Section 4.3). The value is 664 taken from the "COSE Algorithms" registry (see [COSE.Algorithms]). 666 crit: This header parameter is used to indicate which protected 667 header parameters an application that is processing a message is 668 required to understand. Header parameters defined in this 669 document do not need to be included as they should be understood 670 by all implementations. When present, this the 'crit' header 671 parameter MUST be placed in the protected header parameter bucket. 672 The array MUST have at least one value in it. 674 Not all header parameter labels need to be included in the 'crit' 675 header parameter. The rules for deciding which header parameters 676 are placed in the array are: 678 * Integer labels in the range of 0 to 7 SHOULD be omitted. 680 * Integer labels in the range -1 to -128 can be omitted. 681 Algorithms can assign labels in this range where the ability to 682 process the content of the label is considered to be core to 683 implementing the algorithm. Algorithms can assign labels 684 outside of this range where the ability to process the content 685 of the label is not considered to be core, but needs to be 686 understood to correctly process this instance. Integer labels 687 in the range -129 to -65536 SHOULD be included as these would 688 be less common header parameters that might not be generally 689 supported. 691 * Labels for header parameters required for an application MAY be 692 omitted. Applications should have a statement if the label can 693 be omitted. 695 The header parameters indicated by 'crit' can be processed by 696 either the security library code or an application using a 697 security library; the only requirement is that the header 698 parameter is processed. If the 'crit' value list includes a label 699 for which the header parameter is not in the protected header 700 parameters bucket, this is a fatal error in processing the 701 message. 703 content type: This header parameter is used to indicate the content 704 type of the data in the payload or ciphertext fields. Integers 705 are from the "CoAP Content-Formats" IANA registry table 706 [COAP.Formats]. Text values following the syntax of "/" where and are 708 defined in Section 4.2 of [RFC6838]. Leading and trailing 709 whitespace is also omitted. Textual content values along with 710 parameters and subparameters can be located using the IANA "Media 711 Types" registry. Applications SHOULD provide this header 712 parameter if the content structure is potentially ambiguous. 714 kid: This header parameter identifies one piece of data that can be 715 used as input to find the needed cryptographic key. The value of 716 this header parameter can be matched against the 'kid' member in a 717 COSE_Key structure. Other methods of key distribution can define 718 an equivalent field to be matched. Applications MUST NOT assume 719 that 'kid' values are unique. There may be more than one key with 720 the same 'kid' value, so all of the keys associated with this 721 'kid' may need to be checked. The internal structure of 'kid' 722 values is not defined and cannot be relied on by applications. 723 Key identifier values are hints about which key to use. This is 724 not a security-critical field. For this reason, it can be placed 725 in the unprotected header parameters bucket. 727 IV: This header parameter holds the Initialization Vector (IV) 728 value. For some symmetric encryption algorithms, this may be 729 referred to as a nonce. The IV can be placed in the unprotected 730 bucket as modifying the IV will cause the decryption to yield 731 plaintext that is readily detectable as garbled. 733 Partial IV: This header parameter holds a part of the IV value. 734 When using the COSE_Encrypt0 structure, a portion of the IV can be 735 part of the context associated with the key (Context IV) while a 736 portion can be changed with each message (Partial IV). This field 737 is used to carry a value that causes the IV to be changed for each 738 message. The Partial IV can be placed in the unprotected bucket 739 as modifying the value will cause the decryption to yield 740 plaintext that is readily detectable as garbled. The 741 'Initialization Vector' and 'Partial Initialization Vector' header 742 parameters MUST NOT both be present in the same security layer. 744 The message IV is generated by the following steps: 746 1. Left-pad the Partial IV with zeros to the length of IV 747 (determined by the algorithm). 749 2. XOR the padded Partial IV with the context IV. 751 +=========+=======+========+=====================+==================+ 752 | Name | Label | Value | Value Registry | Description | 753 | | | Type | | | 754 +=========+=======+========+=====================+==================+ 755 | alg | 1 | int / | COSE Algorithms | Cryptographic | 756 | | | tstr | registry | algorithm to use | 757 +---------+-------+--------+---------------------+------------------+ 758 | crit | 2 | [+ | COSE Header | Critical header | 759 | | | label] | Parameters | parameters to be | 760 | | | | registry | understood | 761 +---------+-------+--------+---------------------+------------------+ 762 | content | 3 | tstr / | CoAP Content- | Content type of | 763 | type | | uint | Formats or Media | the payload | 764 | | | | Types registries | | 765 +---------+-------+--------+---------------------+------------------+ 766 | kid | 4 | bstr | | Key identifier | 767 +---------+-------+--------+---------------------+------------------+ 768 | IV | 5 | bstr | | Full | 769 | | | | | Initialization | 770 | | | | | Vector | 771 +---------+-------+--------+---------------------+------------------+ 772 | Partial | 6 | bstr | | Partial | 773 | IV | | | | Initialization | 774 | | | | | Vector | 775 +---------+-------+--------+---------------------+------------------+ 777 Table 3: Common Header Parameters 779 The CDDL fragment that represents the set of header parameters 780 defined in this section is given below. Each of the header 781 parameters is tagged as optional because they do not need to be in 782 every map; header parameters required in specific maps are discussed 783 above. 785 Generic_Headers = ( 786 ? 1 => int / tstr, ; algorithm identifier 787 ? 2 => [+label], ; criticality 788 ? 3 => tstr / int, ; content type 789 ? 4 => bstr, ; key identifier 790 ? 5 => bstr, ; IV 791 ? 6 => bstr ; Partial IV 792 ) 794 4. Signing Objects 796 COSE supports two different signature structures. COSE_Sign allows 797 for one or more signatures to be applied to the same content. 798 COSE_Sign1 is restricted to a single signer. The structures cannot 799 be converted between each other; as the signature computation 800 includes a parameter identifying which structure is being used, the 801 converted structure will fail signature validation. 803 4.1. Signing with One or More Signers 805 The COSE_Sign structure allows for one or more signatures to be 806 applied to a message payload. Header parameters relating to the 807 content and header parameters relating to the signature are carried 808 along with the signature itself. These header parameters may be 809 authenticated by the signature, or just present. An example of a 810 header parameter about the content is the content type header 811 parameter. An example of a header parameter about the signature 812 would be the algorithm and key used to create the signature. 814 RFC 5652 indicates that: 816 | When more than one signature is present, the successful validation 817 | of one signature associated with a given signer is usually treated 818 | as a successful signature by that signer. However, there are some 819 | application environments where other rules are needed. An 820 | application that employs a rule other than one valid signature for 821 | each signer must specify those rules. Also, where simple matching 822 | of the signer identifier is not sufficient to determine whether 823 | the signatures were generated by the same signer, the application 824 | specification must describe how to determine which signatures were 825 | generated by the same signer. Support for different communities 826 | of recipients is the primary reason that signers choose to include 827 | more than one signature. 829 For example, the COSE_Sign structure might include signatures 830 generated with the Edwards-curve Digital Signature Algorithm (EdDSA) 831 [RFC8032] and with the Elliptic Curve Digital Signature Algorithm 832 (ECDSA) [DSS]. This allows recipients to verify the signature 833 associated with one algorithm or the other. More-detailed 834 information on multiple signature evaluations can be found in 835 [RFC5752]. 837 The signature structure can be encoded as either tagged or untagged 838 depending on the context it will be used in. A tagged COSE_Sign 839 structure is identified by the CBOR tag 98. The CDDL fragment that 840 represents this is: 842 COSE_Sign_Tagged = #6.98(COSE_Sign) 844 A COSE Signed Message is defined in two parts. The CBOR object that 845 carries the body and information about the body is called the 846 COSE_Sign structure. The CBOR object that carries the signature and 847 information about the signature is called the COSE_Signature 848 structure. Examples of COSE Signed Messages can be found in 849 Appendix C.1. 851 The COSE_Sign structure is a CBOR array. The fields of the array in 852 order are: 854 protected: This is as described in Section 3. 856 unprotected: This is as described in Section 3. 858 payload: This field contains the serialized content to be signed. 859 If the payload is not present in the message, the application is 860 required to supply the payload separately. The payload is wrapped 861 in a bstr to ensure that it is transported without changes. If 862 the payload is transported separately ("detached content"), then a 863 nil CBOR object is placed in this location, and it is the 864 responsibility of the application to ensure that it will be 865 transported without changes. 867 Note: When a signature with a message recovery algorithm is used 868 (Section 8.1), the maximum number of bytes that can be recovered 869 is the length of the original payload. The size of the encoded 870 payload is reduced by the number of bytes that will be recovered. 871 If all of the bytes of the original payload are consumed, then the 872 transmitted payload is encoded as a zero-length byte string rather 873 than as being absent. 875 signatures: This field is an array of signatures. Each signature is 876 represented as a COSE_Signature structure. 878 The CDDL fragment that represents the above text for COSE_Sign 879 follows. 881 COSE_Sign = [ 882 Headers, 883 payload : bstr / nil, 884 signatures : [+ COSE_Signature] 885 ] 887 The COSE_Signature structure is a CBOR array. The fields of the 888 array in order are: 890 protected: This is as described in Section 3. 892 unprotected: This is as described in Section 3. 894 signature: This field contains the computed signature value. The 895 type of the field is a bstr. Algorithms MUST specify padding if 896 the signature value is not a multiple of 8 bits. 898 The CDDL fragment that represents the above text for COSE_Signature 899 follows. 901 COSE_Signature = [ 902 Headers, 903 signature : bstr 904 ] 906 4.2. Signing with One Signer 908 The COSE_Sign1 signature structure is used when only one signature is 909 going to be placed on a message. The header parameters dealing with 910 the content and the signature are placed in the same pair of buckets 911 rather than having the separation of COSE_Sign. 913 The structure can be encoded as either tagged or untagged depending 914 on the context it will be used in. A tagged COSE_Sign1 structure is 915 identified by the CBOR tag 18. The CDDL fragment that represents 916 this is: 918 COSE_Sign1_Tagged = #6.18(COSE_Sign1) 920 The CBOR object that carries the body, the signature, and the 921 information about the body and signature is called the COSE_Sign1 922 structure. Examples of COSE_Sign1 messages can be found in 923 Appendix C.2. 925 The COSE_Sign1 structure is a CBOR array. The fields of the array in 926 order are: 928 protected: This is as described in Section 3. 930 unprotected: This is as described in Section 3. 932 payload: This is as described in Section 4.1. 934 signature: This field contains the computed signature value. The 935 type of the field is a bstr. 937 The CDDL fragment that represents the above text for COSE_Sign1 938 follows. 940 COSE_Sign1 = [ 941 Headers, 942 payload : bstr / nil, 943 signature : bstr 944 ] 946 4.3. Externally Supplied Data 948 One of the features offered in the COSE document is the ability for 949 applications to provide additional data to be authenticated, but that 950 is not carried as part of the COSE object. The primary reason for 951 supporting this can be seen by looking at the CoAP message structure 952 [RFC7252], where the facility exists for options to be carried before 953 the payload. Examples of data that can be placed in this location 954 would be the CoAP code or CoAP options. If the data is in the 955 headers of the CoAP message, then it is available for proxies to help 956 in performing its operations. For example, the Accept Option can be 957 used by a proxy to determine if an appropriate value is in the 958 proxy's cache. But the sender can cause a failure at the server if a 959 proxy, or an attacker, changes the set of accept values by including 960 the field in the externally supplied data. 962 This document describes the process for using a byte array of 963 externally supplied authenticated data; the method of constructing 964 the byte array is a function of the application. Applications that 965 use this feature need to define how the externally supplied 966 authenticated data is to be constructed. Such a construction needs 967 to take into account the following issues: 969 * If multiple items are included, applications need to ensure that 970 the same byte string cannot be produced if there are different 971 inputs. This would occur by concatenating the text strings 'AB' 972 and 'CDE' or by concatenating the text strings 'ABC' and 'DE'. 973 This is usually addressed by making fields a fixed width and/or 974 encoding the length of the field as part of the output. Using 975 options from CoAP [RFC7252] as an example, these fields use a TLV 976 structure so they can be concatenated without any problems. 978 * If multiple items are included, an order for the items needs to be 979 defined. Using options from CoAP as an example, an application 980 could state that the fields are to be ordered by the option 981 number. 983 * Applications need to ensure that the byte string is going to be 984 the same on both sides. Using options from CoAP might give a 985 problem if the same relative numbering is kept. An intermediate 986 node could insert or remove an option, changing how the relative 987 number is done. An application would need to specify that the 988 relative number must be re-encoded to be relative only to the 989 options that are in the external data. 991 4.4. Signing and Verification Process 993 In order to create a signature, a well-defined byte string is needed. 994 The Sig_structure is used to create the canonical form. This signing 995 and verification process takes in the body information (COSE_Sign or 996 COSE_Sign1), the signer information (COSE_Signature), and the 997 application data (external source). A Sig_structure is a CBOR array. 998 The fields of the Sig_structure in order are: 1000 1. A context text string identifying the context of the signature. 1001 The context text string is: 1003 "Signature" for signatures using the COSE_Signature structure. 1005 "Signature1" for signatures using the COSE_Sign1 structure. 1007 2. The protected attributes from the body structure encoded in a 1008 bstr type. If there are no protected attributes, a zero-length 1009 byte string is used. 1011 3. The protected attributes from the signer structure encoded in a 1012 bstr type. If there are no protected attributes, a zero-length 1013 byte string is used. This field is omitted for the COSE_Sign1 1014 signature structure. 1016 4. The externally supplied data from the application encoded in a 1017 bstr type. If this field is not supplied, it defaults to a zero- 1018 length byte string. (See Section 4.3 for application guidance on 1019 constructing this field.) 1021 5. The payload to be signed encoded in a bstr type. The payload is 1022 placed here independent of how it is transported. 1024 The CDDL fragment that describes the above text is: 1026 Sig_structure = [ 1027 context : "Signature" / "Signature1", 1028 body_protected : empty_or_serialized_map, 1029 ? sign_protected : empty_or_serialized_map, 1030 external_aad : bstr, 1031 payload : bstr 1032 ] 1034 How to compute a signature: 1036 1. Create a Sig_structure and populate it with the appropriate 1037 fields. 1039 2. Create the value ToBeSigned by encoding the Sig_structure to a 1040 byte string, using the encoding described in Section 9. 1042 3. Call the signature creation algorithm passing in K (the key to 1043 sign with), alg (the algorithm to sign with), and ToBeSigned (the 1044 value to sign). 1046 4. Place the resulting signature value in the correct location. 1047 This is the 'signature' field of the COSE_Signature or COSE_Sign1 1048 structure. 1050 The steps for verifying a signature are: 1052 1. Create a Sig_structure and populate it with the appropriate 1053 fields. 1055 2. Create the value ToBeSigned by encoding the Sig_structure to a 1056 byte string, using the encoding described in Section 9. 1058 3. Call the signature verification algorithm passing in K (the key 1059 to verify with), alg (the algorithm used sign with), ToBeSigned 1060 (the value to sign), and sig (the signature to be verified). 1062 In addition to performing the signature verification, the application 1063 performs the appropriate checks to ensure that the key is correctly 1064 paired with the signing identity and that the signing identity is 1065 authorized before performing actions. 1067 5. Encryption Objects 1069 COSE supports two different encryption structures. COSE_Encrypt0 is 1070 used when a recipient structure is not needed because the key to be 1071 used is known implicitly. COSE_Encrypt is used the rest of the time. 1072 This includes cases where there are multiple recipients or a 1073 recipient algorithm other than direct (i.e. pre-shared secret) is 1074 used. 1076 5.1. Enveloped COSE Structure 1078 The enveloped structure allows for one or more recipients of a 1079 message. There are provisions for header parameters about the 1080 content and header parameters about the recipient information to be 1081 carried in the message. The protected header parameters associated 1082 with the content are authenticated by the content encryption 1083 algorithm. The protected header parameters associated with the 1084 recipient are authenticated by the recipient algorithm (when the 1085 algorithm supports it). Examples of header parameters about the 1086 content are the type of the content and the content encryption 1087 algorithm. Examples of header parameters about the recipient are the 1088 recipient's key identifier and the recipient's encryption algorithm. 1090 The same techniques and nearly the same structure are used for 1091 encrypting both the plaintext and the keys. This is different from 1092 the approach used by both "Cryptographic Message Syntax (CMS)" 1093 [RFC5652] and "JSON Web Encryption (JWE)" [RFC7516] where different 1094 structures are used for the content layer and for the recipient 1095 layer. Two structures are defined: COSE_Encrypt to hold the 1096 encrypted content and COSE_recipient to hold the encrypted keys for 1097 recipients. Examples of encrypted messages can be found in 1098 Appendix C.3. 1100 The COSE_Encrypt structure can be encoded as either tagged or 1101 untagged depending on the context it will be used in. A tagged 1102 COSE_Encrypt structure is identified by the CBOR tag 96. The CDDL 1103 fragment that represents this is: 1105 COSE_Encrypt_Tagged = #6.96(COSE_Encrypt) 1107 The COSE_Encrypt structure is a CBOR array. The fields of the array 1108 in order are: 1110 protected: This is as described in Section 3. 1112 unprotected: This is as described in Section 3. 1114 ciphertext: This field contains the ciphertext encoded as a bstr. 1116 If the ciphertext is to be transported independently of the 1117 control information about the encryption process (i.e., detached 1118 content), then the field is encoded as a nil value. 1120 recipients: This field contains an array of recipient information 1121 structures. The type for the recipient information structure is a 1122 COSE_recipient. 1124 The CDDL fragment that corresponds to the above text is: 1126 COSE_Encrypt = [ 1127 Headers, 1128 ciphertext : bstr / nil, 1129 recipients : [+COSE_recipient] 1130 ] 1132 The COSE_recipient structure is a CBOR array. The fields of the 1133 array in order are: 1135 protected: This is as described in Section 3. 1137 unprotected: This is as described in Section 3. 1139 ciphertext: This field contains the encrypted key encoded as a bstr. 1140 All encoded keys are symmetric keys; the binary value of the key 1141 is the content. If there is not an encrypted key, then this field 1142 is encoded as a nil value. 1144 recipients: This field contains an array of recipient information 1145 structures. The type for the recipient information structure is a 1146 COSE_recipient (an example of this can be found in Appendix B). 1147 If there are no recipient information structures, this element is 1148 absent. 1150 The CDDL fragment that corresponds to the above text for 1151 COSE_recipient is: 1153 COSE_recipient = [ 1154 Headers, 1155 ciphertext : bstr / nil, 1156 ? recipients : [+COSE_recipient] 1157 ] 1159 5.1.1. Content Key Distribution Methods 1161 An encrypted message consists of an encrypted content and an 1162 encrypted CEK for one or more recipients. The CEK is encrypted for 1163 each recipient, using a key specific to that recipient. The details 1164 of this encryption depend on which class the recipient algorithm 1165 falls into. Specific details on each of the classes can be found in 1166 Section 8.5. A short summary of the five content key distribution 1167 methods is: 1169 direct: The CEK is the same as the identified previously distributed 1170 symmetric key or is derived from a previously distributed secret. 1171 No CEK is transported in the message. 1173 symmetric key-encryption keys (KEK): The CEK is encrypted using a 1174 previously distributed symmetric KEK. Also known as key wrap. 1176 key agreement: The recipient's public key and a sender's private key 1177 are used to generate a pairwise secret, a Key Derivation Function 1178 (KDF) is applied to derive a key, and then the CEK is either the 1179 derived key or encrypted by the derived key. 1181 key transport: The CEK is encrypted with the recipient's public key. 1183 passwords: The CEK is encrypted in a KEK that is derived from a 1184 password. As of when this document was published, no password 1185 algorithms have been defined. 1187 5.2. Single Recipient Encrypted 1189 The COSE_Encrypt0 encrypted structure does not have the ability to 1190 specify recipients of the message. The structure assumes that the 1191 recipient of the object will already know the identity of the key to 1192 be used in order to decrypt the message. If a key needs to be 1193 identified to the recipient, the enveloped structure ought to be 1194 used. 1196 Examples of encrypted messages can be found in Appendix C.3. 1198 The COSE_Encrypt0 structure can be encoded as either tagged or 1199 untagged depending on the context it will be used in. A tagged 1200 COSE_Encrypt0 structure is identified by the CBOR tag 16. The CDDL 1201 fragment that represents this is: 1203 COSE_Encrypt0_Tagged = #6.16(COSE_Encrypt0) 1205 The COSE_Encrypt0 structure is a CBOR array. The fields of the array 1206 in order are: 1208 protected: This is as described in Section 3. 1210 unprotected: This is as described in Section 3. 1212 ciphertext: This is as described in Section 5.1. 1214 The CDDL fragment for COSE_Encrypt0 that corresponds to the above 1215 text is: 1217 COSE_Encrypt0 = [ 1218 Headers, 1219 ciphertext : bstr / nil, 1220 ] 1222 5.3. How to Encrypt and Decrypt for AEAD Algorithms 1224 The encryption algorithm for AEAD algorithms is fairly simple. The 1225 first step is to create a consistent byte string for the 1226 authenticated data structure. For this purpose, we use an 1227 Enc_structure. The Enc_structure is a CBOR array. The fields of the 1228 Enc_structure in order are: 1230 1. A context text string identifying the context of the 1231 authenticated data structure. The context text string is: 1233 "Encrypt0" for the content encryption of a COSE_Encrypt0 data 1234 structure. 1236 "Encrypt" for the first layer of a COSE_Encrypt data structure 1237 (i.e., for content encryption). 1239 "Enc_Recipient" for a recipient encoding to be placed in an 1240 COSE_Encrypt data structure. 1242 "Mac_Recipient" for a recipient encoding to be placed in a 1243 MACed message structure. 1245 "Rec_Recipient" for a recipient encoding to be placed in a 1246 recipient structure. 1248 2. The protected attributes from the body structure encoded in a 1249 bstr type. If there are no protected attributes, a zero-length 1250 byte string is used. 1252 3. The externally supplied data from the application encoded in a 1253 bstr type. If this field is not supplied, it defaults to a zero- 1254 length byte string. (See Section 4.3 for application guidance on 1255 constructing this field.) 1257 The CDDL fragment that describes the above text is: 1259 Enc_structure = [ 1260 context : "Encrypt" / "Encrypt0" / "Enc_Recipient" / 1261 "Mac_Recipient" / "Rec_Recipient", 1262 protected : empty_or_serialized_map, 1263 external_aad : bstr 1264 ] 1266 How to encrypt a message: 1268 1. Create an Enc_structure and populate it with the appropriate 1269 fields. 1271 2. Encode the Enc_structure to a byte string (Additional 1272 Authenticated Data (AAD)), using the encoding described in 1273 Section 9. 1275 3. Determine the encryption key (K). This step is dependent on the 1276 class of recipient algorithm being used. For: 1278 No Recipients: The key to be used is determined by the algorithm 1279 and key at the current layer. Examples are key transport keys 1280 (Section 8.5.3), key wrap keys (Section 8.5.2), or pre-shared 1281 secrets. 1283 Direct Encryption and Direct Key Agreement: The key is 1284 determined by the key and algorithm in the recipient 1285 structure. The encryption algorithm and size of the key to be 1286 used are inputs into the KDF used for the recipient. (For 1287 direct, the KDF can be thought of as the identity operation.) 1288 Examples of these algorithms are found in Sections 6.1.2 and 1289 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1291 Other: The key is randomly or pseudo-randomly generated. 1293 4. Call the encryption algorithm with K (the encryption key), P (the 1294 plaintext), and AAD. Place the returned ciphertext into the 1295 'ciphertext' field of the structure. 1297 5. For recipients of the message, recursively perform the encryption 1298 algorithm for that recipient, using K (the encryption key) as the 1299 plaintext. 1301 How to decrypt a message: 1303 1. Create an Enc_structure and populate it with the appropriate 1304 fields. 1306 2. Encode the Enc_structure to a byte string (AAD), using the 1307 encoding described in Section 9. 1309 3. Determine the decryption key. This step is dependent on the 1310 class of recipient algorithm being used. For: 1312 No Recipients: The key to be used is determined by the algorithm 1313 and key at the current layer. Examples are key transport keys 1314 (Section 8.5.3), key wrap keys (Section 8.5.2), or pre-shared 1315 secrets. 1317 Direct Encryption and Direct Key Agreement: The key is 1318 determined by the key and algorithm in the recipient 1319 structure. The encryption algorithm and size of the key to be 1320 used are inputs into the KDF used for the recipient. (For 1321 direct, the KDF can be thought of as the identity operation.) 1323 Other: The key is determined by decoding and decrypting one of 1324 the recipient structures. 1326 4. Call the decryption algorithm with K (the decryption key to use), 1327 C (the ciphertext), and AAD. 1329 5.4. How to Encrypt and Decrypt for AE Algorithms 1331 How to encrypt a message: 1333 1. Verify that the 'protected' field is empty. 1335 2. Verify that there was no external additional authenticated data 1336 supplied for this operation. 1338 3. Determine the encryption key. This step is dependent on the 1339 class of recipient algorithm being used. For: 1341 No Recipients: The key to be used is determined by the algorithm 1342 and key at the current layer. Examples are key transport keys 1343 (Section 8.5.3), key wrap keys (Section 8.5.2), or pre-shared 1344 secrets. 1346 Direct Encryption and Direct Key Agreement: The key is 1347 determined by the key and algorithm in the recipient 1348 structure. The encryption algorithm and size of the key to be 1349 used are inputs into the KDF used for the recipient. (For 1350 direct, the KDF can be thought of as the identity operation.) 1351 Examples of these algorithms are found in Sections 6.1.2 and 1352 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1354 Other: The key is randomly generated. 1356 4. Call the encryption algorithm with K (the encryption key to use) 1357 and P (the plaintext). Place the returned ciphertext into the 1358 'ciphertext' field of the structure. 1360 5. For recipients of the message, recursively perform the encryption 1361 algorithm for that recipient, using K (the encryption key) as the 1362 plaintext. 1364 How to decrypt a message: 1366 1. Verify that the 'protected' field is empty. 1368 2. Verify that there was no external additional authenticated data 1369 supplied for this operation. 1371 3. Determine the decryption key. This step is dependent on the 1372 class of recipient algorithm being used. For: 1374 No Recipients: The key to be used is determined by the algorithm 1375 and key at the current layer. Examples are key transport keys 1376 (Section 8.5.3), key wrap keys (Section 8.5.2), or pre-shared 1377 secrets. 1379 Direct Encryption and Direct Key Agreement: The key is 1380 determined by the key and algorithm in the recipient 1381 structure. The encryption algorithm and size of the key to be 1382 used are inputs into the KDF used for the recipient. (For 1383 direct, the KDF can be thought of as the identity operation.) 1384 Examples of these algorithms are found in Sections 6.1.2 and 1385 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1387 Other: The key is determined by decoding and decrypting one of 1388 the recipient structures. 1390 4. Call the decryption algorithm with K (the decryption key to use) 1391 and C (the ciphertext). 1393 6. MAC Objects 1395 COSE supports two different MAC structures. COSE_MAC0 is used when a 1396 recipient structure is not needed because the key to be used is 1397 implicitly known. COSE_MAC is used for all other cases. These 1398 include a requirement for multiple recipients, the key being unknown, 1399 or a recipient algorithm of other than direct. 1401 In this section, we describe the structure and methods to be used 1402 when doing MAC authentication in COSE. This document allows for the 1403 use of all of the same classes of recipient algorithms as are allowed 1404 for encryption. 1406 When using MAC operations, there are two modes in which they can be 1407 used. The first is just a check that the content has not been 1408 changed since the MAC was computed. Any class of recipient algorithm 1409 can be used for this purpose. The second mode is to both check that 1410 the content has not been changed since the MAC was computed and to 1411 use the recipient algorithm to verify who sent it. The classes of 1412 recipient algorithms that support this are those that use a pre- 1413 shared secret or do static-static (SS) key agreement (without the key 1414 wrap step). In both of these cases, the entity that created and sent 1415 the message MAC can be validated. (This knowledge of the sender 1416 assumes that there are only two parties involved and that you did not 1417 send the message to yourself.) The origination property can be 1418 obtained with both of the MAC message structures. 1420 6.1. MACed Message with Recipients 1422 The multiple recipient MACed message uses two structures: the 1423 COSE_Mac structure defined in this section for carrying the body and 1424 the COSE_recipient structure (Section 5.1) to hold the key used for 1425 the MAC computation. Examples of MACed messages can be found in 1426 Appendix C.5. 1428 The MAC structure can be encoded as either tagged or untagged 1429 depending on the context it will be used in. A tagged COSE_Mac 1430 structure is identified by the CBOR tag 97. The CDDL fragment that 1431 represents this is: 1433 COSE_Mac_Tagged = #6.97(COSE_Mac) 1435 The COSE_Mac structure is a CBOR array. The fields of the array in 1436 order are: 1438 protected: This is as described in Section 3. 1440 unprotected: This is as described in Section 3. 1442 payload: This field contains the serialized content to be MACed. If 1443 the payload is not present in the message, the application is 1444 required to supply the payload separately. The payload is wrapped 1445 in a bstr to ensure that it is transported without changes. If 1446 the payload is transported separately (i.e., detached content), 1447 then a nil CBOR value is placed in this location, and it is the 1448 responsibility of the application to ensure that it will be 1449 transported without changes. 1451 tag: This field contains the MAC value. 1453 recipients: This is as described in Section 5.1. 1455 The CDDL fragment that represents the above text for COSE_Mac 1456 follows. 1458 COSE_Mac = [ 1459 Headers, 1460 payload : bstr / nil, 1461 tag : bstr, 1462 recipients :[+COSE_recipient] 1463 ] 1465 6.2. MACed Messages with Implicit Key 1467 In this section, we describe the structure and methods to be used 1468 when doing MAC authentication for those cases where the recipient is 1469 implicitly known. 1471 The MACed message uses the COSE_Mac0 structure defined in this 1472 section for carrying the body. Examples of MACed messages with an 1473 implicit key can be found in Appendix C.6. 1475 The MAC structure can be encoded as either tagged or untagged 1476 depending on the context it will be used in. A tagged COSE_Mac0 1477 structure is identified by the CBOR tag 17. The CDDL fragment that 1478 represents this is: 1480 COSE_Mac0_Tagged = #6.17(COSE_Mac0) 1482 The COSE_Mac0 structure is a CBOR array. The fields of the array in 1483 order are: 1485 protected: This is as described in Section 3. 1487 unprotected: This is as described in Section 3. 1489 payload: This is as described in Section 6.1. 1491 tag: This field contains the MAC value. 1493 The CDDL fragment that corresponds to the above text is: 1495 COSE_Mac0 = [ 1496 Headers, 1497 payload : bstr / nil, 1498 tag : bstr, 1499 ] 1501 6.3. How to Compute and Verify a MAC 1503 In order to get a consistent encoding of the data to be 1504 authenticated, the MAC_structure is used to have a canonical form. 1505 The MAC_structure is a CBOR array. The fields of the MAC_structure 1506 in order are: 1508 1. A context text string that identifies the structure that is being 1509 encoded. This context text string is "MAC" for the COSE_Mac 1510 structure. This context text string is "MAC0" for the COSE_Mac0 1511 structure. 1513 2. The protected attributes from the COSE_MAC structure. If there 1514 are no protected attributes, a zero-length bstr is used. 1516 3. The externally supplied data from the application encoded as a 1517 bstr type. If this field is not supplied, it defaults to a zero- 1518 length byte string. (See Section 4.3 for application guidance on 1519 constructing this field.) 1521 4. The payload to be MACed encoded in a bstr type. The payload is 1522 placed here independent of how it is transported. 1524 The CDDL fragment that corresponds to the above text is: 1526 MAC_structure = [ 1527 context : "MAC" / "MAC0", 1528 protected : empty_or_serialized_map, 1529 external_aad : bstr, 1530 payload : bstr 1531 ] 1533 The steps to compute a MAC are: 1535 1. Create a MAC_structure and populate it with the appropriate 1536 fields. 1538 2. Create the value ToBeMaced by encoding the MAC_structure to a 1539 byte string, using the encoding described in Section 9. 1541 3. Call the MAC creation algorithm passing in K (the key to use), 1542 alg (the algorithm to MAC with), and ToBeMaced (the value to 1543 compute the MAC on). 1545 4. Place the resulting MAC in the 'tag' field of the COSE_Mac or 1546 COSE_Mac0 structure. 1548 5. For COSE_Mac structures, encrypt and encode the MAC key for each 1549 recipient of the message. 1551 The steps to verify a MAC are: 1553 1. Create a MAC_structure and populate it with the appropriate 1554 fields. 1556 2. Create the value ToBeMaced by encoding the MAC_structure to a 1557 byte string, using the encoding described in Section 9. 1559 3. For COSE_Mac structures, obtain the cryptographic key from one of 1560 the recipients of the message. 1562 4. Call the MAC creation algorithm passing in K (the key to use), 1563 alg (the algorithm to MAC with), and ToBeMaced (the value to 1564 compute the MAC on). 1566 5. Compare the MAC value to the 'tag' field of the COSE_Mac or 1567 COSE_Mac0 structure. 1569 7. Key Objects 1571 A COSE Key structure is built on a CBOR map. The set of common 1572 parameters that can appear in a COSE Key can be found in the IANA 1573 "COSE Key Common Parameters" registry (Section 11.2). Additional 1574 parameters defined for specific key types can be found in the IANA 1575 "COSE Key Type Parameters" registry ([COSE.KeyParameters]). 1577 A COSE Key Set uses a CBOR array object as its underlying type. The 1578 values of the array elements are COSE Keys. A COSE Key Set MUST have 1579 at least one element in the array. Examples of COSE Key Sets can be 1580 found in Appendix C.7. 1582 Each element in a COSE Key Set MUST be processed independently. If 1583 one element in a COSE Key Set is either malformed or uses a key that 1584 is not understood by an application, that key is ignored and the 1585 other keys are processed normally. 1587 The element "kty" is a required element in a COSE_Key map. 1589 The CDDL grammar describing COSE_Key and COSE_KeySet is: 1591 COSE_Key = { 1592 1 => tstr / int, ; kty 1593 ? 2 => bstr, ; kid 1594 ? 3 => tstr / int, ; alg 1595 ? 4 => [+ (tstr / int) ], ; key_ops 1596 ? 5 => bstr, ; Base IV 1597 * label => values 1598 } 1600 COSE_KeySet = [+COSE_Key] 1602 7.1. COSE Key Common Parameters 1604 This document defines a set of common parameters for a COSE Key 1605 object. Table 4 provides a summary of the parameters defined in this 1606 section. There are also parameters that are defined for specific key 1607 types. Key-type-specific parameters can be found in 1608 [I-D.ietf-cose-rfc8152bis-algs]. 1610 +=========+=======+========+============+====================+ 1611 | Name | Label | CBOR | Value | Description | 1612 | | | Type | Registry | | 1613 +=========+=======+========+============+====================+ 1614 | kty | 1 | tstr / | COSE Key | Identification of | 1615 | | | int | Types | the key type | 1616 +---------+-------+--------+------------+--------------------+ 1617 | kid | 2 | bstr | | Key identification | 1618 | | | | | value -- match to | 1619 | | | | | kid in message | 1620 +---------+-------+--------+------------+--------------------+ 1621 | alg | 3 | tstr / | COSE | Key usage | 1622 | | | int | Algorithms | restriction to | 1623 | | | | | this algorithm | 1624 +---------+-------+--------+------------+--------------------+ 1625 | key_ops | 4 | [+ | | Restrict set of | 1626 | | | (tstr/ | | permissible | 1627 | | | int)] | | operations | 1628 +---------+-------+--------+------------+--------------------+ 1629 | Base IV | 5 | bstr | | Base IV to be xor- | 1630 | | | | | ed with Partial | 1631 | | | | | IVs | 1632 +---------+-------+--------+------------+--------------------+ 1634 Table 4: Key Map Labels 1636 kty: This parameter is used to identify the family of keys for this 1637 structure and, thus, the set of key-type-specific parameters to be 1638 found. The set of values defined in this document can be found in 1639 [COSE.KeyTypes]. This parameter MUST be present in a key object. 1640 Implementations MUST verify that the key type is appropriate for 1641 the algorithm being processed. The key type MUST be included as 1642 part of the trust decision process. 1644 alg: This parameter is used to restrict the algorithm that is used 1645 with the key. If this parameter is present in the key structure, 1646 the application MUST verify that this algorithm matches the 1647 algorithm for which the key is being used. If the algorithms do 1648 not match, then this key object MUST NOT be used to perform the 1649 cryptographic operation. Note that the same key can be in a 1650 different key structure with a different or no algorithm 1651 specified; however, this is considered to be a poor security 1652 practice. 1654 kid: This parameter is used to give an identifier for a key. The 1655 identifier is not structured and can be anything from a user- 1656 provided byte string to a value computed on the public portion of 1657 the key. This field is intended for matching against a 'kid' 1658 parameter in a message in order to filter down the set of keys 1659 that need to be checked. The value of the identifier is not a 1660 unique value and can occur in other key objects, even for 1661 different keys. 1663 key_ops: This parameter is defined to restrict the set of operations 1664 that a key is to be used for. The value of the field is an array 1665 of values from Table 5. Algorithms define the values of key ops 1666 that are permitted to appear and are required for specific 1667 operations. The set of values matches that in [RFC7517] and 1668 [W3C.WebCrypto]. 1670 Base IV: This parameter is defined to carry the base portion of an 1671 IV. It is designed to be used with the Partial IV header 1672 parameter defined in Section 3.1. This field provides the ability 1673 to associate a Base IV with a key that is then modified on a per 1674 message basis with the Partial IV. 1676 Extreme care needs to be taken when using a Base IV in an 1677 application. Many encryption algorithms lose security if the same 1678 IV is used twice. 1680 If different keys are derived for each sender, starting at the 1681 same Base IV is likely to satisfy this condition. If the same key 1682 is used for multiple senders, then the application needs to 1683 provide for a method of dividing the IV space up between the 1684 senders. This could be done by providing a different base point 1685 to start from or a different Partial IV to start with and 1686 restricting the number of messages to be sent before rekeying. 1688 +=========+=======+==============================================+ 1689 | Name | Value | Description | 1690 +=========+=======+==============================================+ 1691 | sign | 1 | The key is used to create signatures. | 1692 | | | Requires private key fields. | 1693 +---------+-------+----------------------------------------------+ 1694 | verify | 2 | The key is used for verification of | 1695 | | | signatures. | 1696 +---------+-------+----------------------------------------------+ 1697 | encrypt | 3 | The key is used for key transport | 1698 | | | encryption. | 1699 +---------+-------+----------------------------------------------+ 1700 | decrypt | 4 | The key is used for key transport | 1701 | | | decryption. Requires private key fields. | 1702 +---------+-------+----------------------------------------------+ 1703 | wrap | 5 | The key is used for key wrap encryption. | 1704 | key | | | 1705 +---------+-------+----------------------------------------------+ 1706 | unwrap | 6 | The key is used for key wrap decryption. | 1707 | key | | Requires private key fields. | 1708 +---------+-------+----------------------------------------------+ 1709 | derive | 7 | The key is used for deriving keys. Requires | 1710 | key | | private key fields. | 1711 +---------+-------+----------------------------------------------+ 1712 | derive | 8 | The key is used for deriving bits not to be | 1713 | bits | | used as a key. Requires private key fields. | 1714 +---------+-------+----------------------------------------------+ 1715 | MAC | 9 | The key is used for creating MACs. | 1716 | create | | | 1717 +---------+-------+----------------------------------------------+ 1718 | MAC | 10 | The key is used for validating MACs. | 1719 | verify | | | 1720 +---------+-------+----------------------------------------------+ 1722 Table 5: Key Operation Values 1724 8. Taxonomy of Algorithms used by COSE 1726 In this section, a taxonomy of the different algorithm types that can 1727 be used in COSE is laid out. This taxonomy should not be considered 1728 to be exhaustive. New algorithms will be created which will not fit 1729 into this taxonomy. 1731 8.1. Signature Algorithms 1733 Signature algorithms provide data origination and data integrity 1734 services. Data origination provides the ability to infer who 1735 originated the data based on who signed the data. Data integrity 1736 provides the ability to verify that the data has not been modified 1737 since it was signed. 1739 There are two general signature algorithm schemes. The first is 1740 signature with appendix. In this scheme, the message content is 1741 processed and a signature is produced; the signature is called the 1742 appendix. This is the scheme used by algorithms such as ECDSA and 1743 the RSA Probabilistic Signature Scheme (RSASSA-PSS). (In fact, the 1744 SSA in RSASSA-PSS stands for Signature Scheme with Appendix.) 1746 The signature functions for this scheme are: 1748 signature = Sign(message content, key) 1750 valid = Verification(message content, key, signature) 1752 The second scheme is signature with message recovery (an example of 1753 such an algorithm is [PVSig]). In this scheme, the message content 1754 is processed, but part of it is included in the signature. Moving 1755 bytes of the message content into the signature allows for smaller 1756 signatures; the signature size is still potentially large, but the 1757 message content has shrunk. This has implications for systems 1758 implementing these algorithms and for applications that use them. 1759 The first is that the message content is not fully available until 1760 after a signature has been validated. Until that point, the part of 1761 the message contained inside of the signature is unrecoverable. The 1762 second is that the security analysis of the strength of the signature 1763 can be very much dependent on the structure of the message content. 1764 Finally, in the event that multiple signatures are applied to a 1765 message, all of the signature algorithms are going to be required to 1766 consume the same bytes of message content. This means that the 1767 mixing of the signature with message recovery and signature with 1768 appendix schemes in a single message is not supported. 1770 The signature functions for this scheme are: 1772 signature, message sent = Sign(message content, key) 1774 valid, message content = Verification(message sent, key, signature) 1776 No message recovery signature algorithms have been formally defined 1777 for COSE yet, and given the new constraints arising from this 1778 schemes, while some of these issues have already been identified 1779 there is a high probability that additional issues will arise when 1780 integrating message recovery signature algorithms. The first 1781 algorithm defined is going to need to make decisions about these 1782 issues and those decisions are likely to be binding on any further 1783 algorithms defined. 1785 We use the following terms below: 1787 message content bytes: The byte provided by the application to be 1788 signed. 1790 to-be-signed bytes: The byte string passed into the signature 1791 algorithm. 1793 recovered bytes: The bytes recovered during the signature 1794 verification process. 1796 Some of the issues that have already been identified are: 1798 * The to-be-signed bytes are not the same as the message content 1799 bytes. This is because we build a larger to-be-signed message 1800 during the signature processing. The recovered bytes length may 1801 exceed the message content length, but not the length of the to- 1802 be-signed bytes. This may lead to privacy considerations if, for 1803 example, the externally supplied data contains confidential 1804 information. 1806 * There may be difficulties in determining where the recovered bytes 1807 match up with the to-be-signed bytes, because the recovered bytes 1808 contains data not in the message content bytes. One possible 1809 option would be to create a padding scheme to prevent that. 1811 * Not all message recovery signature algorithms take the recovered 1812 bytes from the end of the to-be-signed bytes. This is a problem 1813 because the message content bytes are at the end of the to-be- 1814 signed bytes. If the bytes to be recovered are taken from the 1815 start of the to-be-signed bytes then, by default, none of the 1816 message content bytes may be included in the recovered bytes. One 1817 possible option to deal with this is to reverse the to-be-signed 1818 data in the event that recovered bytes are taken from the start 1819 rather than end of the to-be-signed bytes. 1821 Signature algorithms are used with the COSE_Signature and COSE_Sign1 1822 structures. At the time of this writing, only signatures with 1823 appendixes are defined for use with COSE; however, considerable 1824 interest has been expressed in using a signature with message 1825 recovery algorithm due to the effective size reduction that is 1826 possible. 1828 8.2. Message Authentication Code (MAC) Algorithms 1830 Message Authentication Codes (MACs) provide data authentication and 1831 integrity protection. They provide either no or very limited data 1832 origination. A MAC, for example, cannot be used to prove the 1833 identity of the sender to a third party. 1835 MACs use the same scheme as signature with appendix algorithms. The 1836 message content is processed and an authentication code is produced. 1837 The authentication code is frequently called a tag. 1839 The MAC functions are: 1841 tag = MAC_Create(message content, key) 1843 valid = MAC_Verify(message content, key, tag) 1845 MAC algorithms can be based on either a block cipher algorithm (i.e., 1846 AES-MAC) or a hash algorithm (i.e., a Hash-based Message 1847 Authentication Code (HMAC)). [I-D.ietf-cose-rfc8152bis-algs] defines 1848 a MAC algorithm using each of these constructions. 1850 MAC algorithms are used in the COSE_Mac and COSE_Mac0 structures. 1852 8.3. Content Encryption Algorithms 1854 Content encryption algorithms provide data confidentiality for 1855 potentially large blocks of data using a symmetric key. They provide 1856 integrity on the data that was encrypted; however, they provide 1857 either no or very limited data origination. (One cannot, for 1858 example, be used to prove the identity of the sender to a third 1859 party.) The ability to provide data origination is linked to how the 1860 CEK is obtained. 1862 COSE restricts the set of legal content encryption algorithms to 1863 those that support authentication both of the content and additional 1864 data. The encryption process will generate some type of 1865 authentication value, but that value may be either explicit or 1866 implicit in terms of the algorithm definition. For simplicity's 1867 sake, the authentication code will normally be defined as being 1868 appended to the ciphertext stream. The encryption functions are: 1870 ciphertext = Encrypt(message content, key, additional data) 1872 valid, message content = Decrypt(ciphertext, key, additional data) 1873 Most AEAD algorithms are logically defined as returning the message 1874 content only if the decryption is valid. Many but not all 1875 implementations will follow this convention. The message content 1876 MUST NOT be used if the decryption does not validate. 1878 These algorithms are used in COSE_Encrypt and COSE_Encrypt0. 1880 8.4. Key Derivation Functions (KDFs) 1882 KDFs are used to take some secret value and generate a different one. 1883 The secret value comes in three flavors: 1885 * Secrets that are uniformly random: This is the type of secret that 1886 is created by a good random number generator. 1888 * Secrets that are not uniformly random: This is type of secret that 1889 is created by operations like key agreement. 1891 * Secrets that are not random: This is the type of secret that 1892 people generate for things like passwords. 1894 General KDFs work well with the first type of secret, can do 1895 reasonably well with the second type of secret, and generally do 1896 poorly with the last type of secret. Functions like Argon2 1897 [I-D.irtf-cfrg-argon2] need to be used for non-random secrets. 1899 The same KDF can be set up to deal with the first two types of 1900 secrets in a different way. The KDF defined in section 5.1 of 1901 [I-D.ietf-cose-rfc8152bis-algs] is such a function. This is 1902 reflected in the set of algorithms defined around the HMAC-based 1903 Extract-and-Expand Key Derivation Function (HKDF). 1905 When using KDFs, one component that is included is context 1906 information. Context information is used to allow for different 1907 keying information to be derived from the same secret. The use of 1908 context-based keying material is considered to be a good security 1909 practice. 1911 8.5. Content Key Distribution Methods 1913 Content key distribution methods (recipient algorithms) can be 1914 defined into a number of different classes. COSE has the ability to 1915 support many classes of recipient algorithms. In this section, a 1916 number of classes are listed. The names of the recipient algorithm 1917 classes used here are the same as those defined in [RFC7516]. Other 1918 specifications use different terms for the recipient algorithm 1919 classes or do not support some of the recipient algorithm classes. 1921 8.5.1. Direct Encryption 1923 The direct encryption class algorithms share a secret between the 1924 sender and the recipient that is used either directly or after 1925 manipulation as the CEK. When direct encryption mode is used, it 1926 MUST be the only mode used on the message. 1928 The COSE_Recipient structure for the recipient is organized as 1929 follows: 1931 * The 'protected' field MUST be a zero-length byte string unless it 1932 is used in the computation of the content key. 1934 * The 'alg' header parameter MUST be present. 1936 * A header parameter identifying the shared secret SHOULD be 1937 present. 1939 * The 'ciphertext' field MUST be a zero-length byte string. 1941 * The 'recipients' field MUST be absent. 1943 8.5.2. Key Wrap 1945 In key wrap mode, the CEK is randomly generated and that key is then 1946 encrypted by a shared secret between the sender and the recipient. 1947 All of the currently defined key wrap algorithms for COSE are AE 1948 algorithms. Key wrap mode is considered to be superior to direct 1949 encryption if the system has any capability for doing random key 1950 generation. This is because the shared key is used to wrap random 1951 data rather than data that has some degree of organization and may in 1952 fact be repeating the same content. The use of key wrap loses the 1953 weak data origination that is provided by the direct encryption 1954 algorithms. 1956 The COSE_Recipient structure for the recipient is organized as 1957 follows: 1959 * The 'protected' field MUST be absent if the key wrap algorithm is 1960 an AE algorithm. 1962 * The 'recipients' field is normally absent, but can be used. 1963 Applications MUST deal with a recipient field being present that 1964 has an unsupported algorithm. Failing to decrypt that specific 1965 recipient is an acceptable way of dealing with it. Failing to 1966 process the message is not an acceptable way of dealing with it. 1968 * The plaintext to be encrypted is the key from next layer down 1969 (usually the content layer). 1971 * At a minimum, the 'unprotected' field MUST contain the 'alg' 1972 header parameter and SHOULD contain a header parameter identifying 1973 the shared secret. 1975 8.5.3. Key Transport 1977 Key transport mode is also called key encryption mode in some 1978 standards. Key transport mode differs from key wrap mode in that it 1979 uses an asymmetric encryption algorithm rather than a symmetric 1980 encryption algorithm to protect the key. A set of key transport 1981 algorithms are defined in [RFC8230]. 1983 When using a key transport algorithm, the COSE_Recipient structure 1984 for the recipient is organized as follows: 1986 * The 'protected' field MUST be absent. 1988 * The plaintext to be encrypted is the key from the next layer down 1989 (usually the content layer). 1991 * At a minimum, the 'unprotected' field MUST contain the 'alg' 1992 header parameter and SHOULD contain a parameter identifying the 1993 asymmetric key. 1995 8.5.4. Direct Key Agreement 1997 The 'direct key agreement' class of recipient algorithms uses a key 1998 agreement method to create a shared secret. A KDF is then applied to 1999 the shared secret to derive a key to be used in protecting the data. 2000 This key is normally used as a CEK or MAC key, but could be used for 2001 other purposes if more than two layers are in use (see Appendix B). 2003 The most commonly used key agreement algorithm is Diffie-Hellman, but 2004 other variants exist. Since COSE is designed for a store and forward 2005 environment rather than an online environment, many of the DH 2006 variants cannot be used as the receiver of the message cannot provide 2007 any dynamic key material. One side effect of this is that forward 2008 secrecy (see [RFC4949]) is not achievable. A static key will always 2009 be used for the receiver of the COSE object. 2011 Two variants of DH that are supported are: 2013 Ephemeral-Static (ES) DH: where the sender of the message creates 2014 a one-time DH key and uses a static key for the recipient. The 2015 use of the ephemeral sender key means that no additional random 2016 input is needed as this is randomly generated for each message. 2018 Static-Static (SS) DH: where a static key is used for both the 2019 sender and the recipient. The use of static keys allows for the 2020 recipient to get a weak version of data origination for the 2021 message. When static-static key agreement is used, then some 2022 piece of unique data for the KDF is required to ensure that a 2023 different key is created for each message. 2025 When direct key agreement mode is used, there MUST be only one 2026 recipient in the message. This method creates the key directly, and 2027 that makes it difficult to mix with additional recipients. If 2028 multiple recipients are needed, then the version with key wrap needs 2029 to be used. 2031 The COSE_Recipient structure for the recipient is organized as 2032 follows: 2034 * At a minimum, headers MUST contain the 'alg' header parameter and 2035 SHOULD contain a header parameter identifying the recipient's 2036 asymmetric key. 2038 * The headers SHOULD identify the sender's key for the static-static 2039 versions and MUST contain the sender's ephemeral key for the 2040 ephemeral-static versions. 2042 8.5.5. Key Agreement with Key Wrap 2044 Key Agreement with Key Wrap uses a randomly generated CEK. The CEK 2045 is then encrypted using a key wrap algorithm and a key derived from 2046 the shared secret computed by the key agreement algorithm. The 2047 function for this would be: 2049 encryptedKey = KeyWrap(KDF(DH-Shared, context), CEK) 2051 The COSE_Recipient structure for the recipient is organized as 2052 follows: 2054 * The 'protected' field is fed into the KDF context structure. 2056 * The plaintext to be encrypted is the key from the next layer down 2057 (usually the content layer). 2059 * The 'alg' header parameter MUST be present in the layer. 2061 * A header parameter identifying the recipient's key SHOULD be 2062 present. A header parameter identifying the sender's key SHOULD 2063 be present. 2065 9. CBOR Encoding Restrictions 2067 This document limits the restrictions it imposes on how the CBOR 2068 Encoder needs to work. It has been narrowed down to the following 2069 restrictions: 2071 * The restriction applies to the encoding of the Sig_structure, the 2072 Enc_structure, and the MAC_structure. 2074 * Encoding MUST be done using definite lengths and the value's 2075 length MUST be the minimum possible length. This means that the 2076 integer 1 is encoded as "0x01" and not "0x1801". 2078 * Applications MUST NOT generate messages with the same label used 2079 twice as a key in a single map. Applications MUST NOT parse and 2080 process messages with the same label used twice as a key in a 2081 single map. Applications can enforce the parse and process 2082 requirement by using parsers that will fail the parse step or by 2083 using parsers that will pass all keys to the application, and the 2084 application can perform the check for duplicate keys. 2086 10. Application Profiling Considerations 2088 This document is designed to provide a set of security services, but 2089 not impose algorithm implementation requirements for specific usage. 2090 The interoperability requirements are provided for how each of the 2091 individual services are used and how the algorithms are to be used 2092 for interoperability. The requirements about which algorithms and 2093 which services are needed are deferred to each application. 2095 An example of a profile can be found in [RFC8613] where one was 2096 developed for carrying content in combination with CoAP headers. 2098 It is intended that a profile of this document be created that 2099 defines the interoperability requirements for that specific 2100 application. This section provides a set of guidelines and topics 2101 that need to be considered when profiling this document. 2103 * Applications need to determine the set of messages defined in this 2104 document that they will be using. The set of messages corresponds 2105 fairly directly to the set of security services that are needed 2106 and to the security levels needed. 2108 * Applications may define new header parameters for a specific 2109 purpose. Applications will often times select specific header 2110 parameters to use or not to use. For example, an application 2111 would normally state a preference for using either the IV or the 2112 Partial IV header parameter. If the Partial IV header parameter 2113 is specified, then the application also needs to define how the 2114 fixed portion of the IV is determined. 2116 * When applications use externally defined authenticated data, they 2117 need to define how that data is encoded. This document assumes 2118 that the data will be provided as a byte string. More information 2119 can be found in Section 4.3. 2121 * Applications need to determine the set of security algorithms that 2122 are to be used. When selecting the algorithms to be used as the 2123 mandatory-to-implement set, consideration should be given to 2124 choosing different types of algorithms when two are chosen for a 2125 specific purpose. An example of this would be choosing HMAC- 2126 SHA512 and AES-CMAC as different MAC algorithms; the construction 2127 is vastly different between these two algorithms. This means that 2128 a weakening of one algorithm would be unlikely to lead to a 2129 weakening of the other algorithms. Of course, these algorithms do 2130 not provide the same level of security and thus may not be 2131 comparable for the desired security functionality. Additional 2132 guidance can be found in [BCP201]. 2134 * Applications may need to provide some type of negotiation or 2135 discovery method if multiple algorithms or message structures are 2136 permitted. The method can be as simple as requiring pre- 2137 configuration of the set of algorithms to providing a discovery 2138 method built into the protocol. S/MIME provided a number of 2139 different ways to approach the problem that applications could 2140 follow: 2142 - Advertising in the message (S/MIME capabilities) [RFC5751]. 2144 - Advertising in the certificate (capabilities extension) 2145 [RFC4262]. 2147 - Minimum requirements for the S/MIME, which have been updated 2148 over time [RFC2633] [RFC5751] (note that [RFC2633] has been 2149 obsoleted by [RFC5751]). 2151 11. IANA Considerations 2153 The registries and registrations listed below were created during 2154 processing of RFC 8152 [RFC8152]. The majority of the following 2155 actions are to update the references to point to this document. 2157 Note that while [I-D.ietf-cose-rfc8152bis-algs] also updates the 2158 registries and registrations originally established by [RFC8152], the 2159 requested updates are mutually exclusive. The updates requested in 2160 this document do not conflict or overlap with the updates requested 2161 in [I-D.ietf-cose-rfc8152bis-algs], and vice versa. 2163 11.1. COSE Header Parameters Registry 2165 IANA created a registry titled "COSE Header Parameters" as part of 2166 processing [RFC8152]. IANA is requested to update the reference for 2167 this registry from [RFC8152] to this document. IANA is also 2168 requested to update the reference for all entries, except "counter 2169 signature" and "CounterSignature0", in the table from [RFC8152] to 2170 this document. The reference for "counter signature" and 2171 "CounterSignature0" are to be left as-is. 2173 11.2. COSE Key Common Parameters Registry 2175 IANA created a registry titled "COSE Key Common Parameters" as part 2176 of the processing of [RFC8152]. IANA is requested to update the 2177 reference for this registry from [RFC8152] to this document. IANA is 2178 also requested to update the reference for entries in the table from 2179 [RFC8152] to this document. 2181 11.3. Media Type Registrations 2183 11.3.1. COSE Security Message 2185 This section registers the 'application/cose' media type in the 2186 "Media Types" registry. These media types are used to indicate that 2187 the content is a COSE message. 2189 Type name: application 2191 Subtype name: cose 2193 Required parameters: N/A 2195 Optional parameters: cose-type 2197 Encoding considerations: binary 2199 Security considerations: See the Security Considerations section 2200 of [[This Document]]. 2202 Interoperability considerations: N/A 2204 Published specification: [[this document]] 2205 Applications that use this media type: IoT applications sending 2206 security content over HTTP(S) transports. 2208 Fragment identifier considerations: N/A 2210 Additional information: 2212 - Deprecated alias names for this type: N/A 2214 - Magic number(s): N/A 2216 - File extension(s): cbor 2218 - Macintosh file type code(s): N/A 2220 Person & email address to contact for further information: 2221 iesg@ietf.org 2223 Intended usage: COMMON 2225 Restrictions on usage: N/A 2227 Author: Jim Schaad, ietf@augustcellars.com 2229 Change Controller: IESG 2231 Provisional registration? No 2233 11.3.2. COSE Key Media Type 2235 This section registers the 'application/cose-key' and 'application/ 2236 cose-key-set' media types in the "Media Types" registry. These media 2237 types are used to indicate, respectively, that content is a COSE_Key 2238 or COSE_KeySet object. 2240 The template for registering 'application/cose-key' is: 2242 Type name: application 2244 Subtype name: cose-key 2246 Required parameters: N/A 2248 Optional parameters: N/A 2250 Encoding considerations: binary 2251 Security considerations: See the Security Considerations section 2252 of [[This Document]]. 2254 Interoperability considerations: N/A 2256 Published specification: [[this document]] 2258 Applications that use this media type: Distribution of COSE based 2259 keys for IoT applications. 2261 Fragment identifier considerations: N/A 2263 Additional information: 2265 - Deprecated alias names for this type: N/A 2267 - Magic number(s): N/A 2269 - File extension(s): cbor 2271 - Macintosh file type code(s): N/A 2273 Person & email address to contact for further information: 2274 iesg@ietf.org 2276 Intended usage: COMMON 2278 Restrictions on usage: N/A 2280 Author: Jim Schaad, ietf@augustcellars.com 2282 Change Controller: IESG 2284 Provisional registration? No 2286 The template for registering 'application/cose-key-set' is: 2288 Type name: application 2290 Subtype name: cose-key-set 2292 Required parameters: N/A 2294 Optional parameters: N/A 2296 Encoding considerations: binary 2297 Security considerations: See the Security Considerations section 2298 of [[This Document]]. 2300 Interoperability considerations: N/A 2302 Published specification: [[this document]] 2304 Applications that use this media type: Distribution of COSE based 2305 keys for IoT applications. 2307 Fragment identifier considerations: N/A 2309 Additional information: 2311 - Deprecated alias names for this type: N/A 2313 - Magic number(s): N/A 2315 - File extension(s): cbor 2317 - Macintosh file type code(s): N/A 2319 Person & email address to contact for further information: 2320 iesg@ietf.org 2322 Intended usage: COMMON 2324 Restrictions on usage: N/A 2326 Author: Jim Schaad, ietf@augustcellars.com 2328 Change Controller: IESG 2330 Provisional registration? No 2332 11.4. CoAP Content-Formats Registry 2334 IANA added entries to the "CoAP Content-Formats" registry while 2335 processing [RFC8152]. IANA is requested to update the reference 2336 value from [RFC8152] to [[This Document]]. 2338 11.5. CBOR Tags Registry 2340 IANA is requested to update the references from [RFC8152] to [[This 2341 Document]]. 2343 11.6. Expert Review Instructions 2345 All of the IANA registries established by [RFC8152] are, at least in 2346 part, defined as expert review. This section gives some general 2347 guidelines for what the experts should be looking for, but they are 2348 being designated as experts for a reason, so they should be given 2349 substantial latitude. 2351 Expert reviewers should take into consideration the following points: 2353 * Point squatting should be discouraged. Reviewers are encouraged 2354 to get sufficient information for registration requests to ensure 2355 that the usage is not going to duplicate one that is already 2356 registered, and that the point is likely to be used in 2357 deployments. The zones tagged as private use are intended for 2358 testing purposes and closed environments; code points in other 2359 ranges should not be assigned for testing. 2361 * Specifications are required for the standards track range of point 2362 assignment. Specifications should exist for specification 2363 required ranges, but early assignment before a specification is 2364 available is considered to be permissible. Specifications are 2365 needed for the first-come, first-serve range if they are expected 2366 to be used outside of closed environments in an interoperable way. 2367 When specifications are not provided, the description provided 2368 needs to have sufficient information to identify what the point is 2369 being used for. 2371 * Experts should take into account the expected usage of fields when 2372 approving point assignment. The fact that there is a range for 2373 standards track documents does not mean that a standards track 2374 document cannot have points assigned outside of that range. The 2375 length of the encoded value should be weighed against how many 2376 code points of that length are left, the size of device it will be 2377 used on, and the number of code points left that encode to that 2378 size. 2380 * When algorithms are registered, vanity registrations should be 2381 discouraged. One way to do this is to require registrations to 2382 provide additional documentation on security analysis of the 2383 algorithm. Another thing that should be considered is requesting 2384 an opinion on the algorithm from the Crypto Forum Research Group 2385 (CFRG). Algorithms that do not meet the security requirements of 2386 the community and the messages structures should not be 2387 registered. 2389 12. Security Considerations 2391 There are a number of security considerations that need to be taken 2392 into account by implementers of this specification. While some 2393 considerations have been highlighted here, additional considerations 2394 may be found in the documents listed in the references. 2396 Implementations need to protect the private key material for any 2397 individuals. There are some cases that need to be highlighted on 2398 this issue. 2400 * Using the same key for two different algorithms can leak 2401 information about the key. It is therefore recommended that keys 2402 be restricted to a single algorithm. 2404 * Use of 'direct' as a recipient algorithm combined with a second 2405 recipient algorithm exposes the direct key to the second 2406 recipient. 2408 * Several of the algorithms in [I-D.ietf-cose-rfc8152bis-algs] have 2409 limits on the number of times that a key can be used without 2410 leaking information about the key. 2412 The use of ECDH and direct plus KDF (with no key wrap) will not 2413 directly lead to the private key being leaked; the one way function 2414 of the KDF will prevent that. There is, however, a different issue 2415 that needs to be addressed. Having two recipients requires that the 2416 CEK be shared between two recipients. The second recipient therefore 2417 has a CEK that was derived from material that can be used for the 2418 weak proof of origin. The second recipient could create a message 2419 using the same CEK and send it to the first recipient; the first 2420 recipient would, for either static-static ECDH or direct plus KDF, 2421 make an assumption that the CEK could be used for proof of origin 2422 even though it is from the wrong entity. If the key wrap step is 2423 added, then no proof of origin is implied and this is not an issue. 2425 Although it has been mentioned before, the use of a single key for 2426 multiple algorithms has been demonstrated in some cases to leak 2427 information about that key, provide the opportunity for attackers to 2428 forge integrity tags, or gain information about encrypted content. 2429 Binding a key to a single algorithm prevents these problems. Key 2430 creators and key consumers are strongly encouraged not only to create 2431 new keys for each different algorithm, but to include that selection 2432 of algorithm in any distribution of key material and strictly enforce 2433 the matching of algorithms in the key structure to algorithms in the 2434 message structure. In addition to checking that algorithms are 2435 correct, the key form needs to be checked as well. Do not use an 2436 'EC2' key where an 'OKP' key is expected. 2438 Before using a key for transmission, or before acting on information 2439 received, a trust decision on a key needs to be made. Is the data or 2440 action something that the entity associated with the key has a right 2441 to see or a right to request? A number of factors are associated 2442 with this trust decision. Some of the ones that are highlighted here 2443 are: 2445 * What are the permissions associated with the key owner? 2447 * Is the cryptographic algorithm acceptable in the current context? 2449 * Have the restrictions associated with the key, such as algorithm 2450 or freshness, been checked and are they correct? 2452 * Is the request something that is reasonable, given the current 2453 state of the application? 2455 * Have any security considerations that are part of the message been 2456 enforced (as specified by the application or 'crit' header 2457 parameter)? 2459 One area that has been getting exposure is traffic analysis of 2460 encrypted messages based on the length of the message. This 2461 specification does not provide for a uniform method of providing 2462 padding as part of the message structure. An observer can 2463 distinguish between two different messages (for example, 'YES' and 2464 'NO') based on the length for all of the content encryption 2465 algorithms that are defined in [I-D.ietf-cose-rfc8152bis-algs] 2466 document. This means that it is up to the applications to document 2467 how content padding is to be done in order to prevent or discourage 2468 such analysis. (For example, the text strings could be defined as 2469 'YES' and 'NO '.) 2471 13. Implementation Status 2473 This section is to be removed before publishing as an RFC. 2475 This section records the status of known implementations of the 2476 protocol defined by this specification at the time of posting of this 2477 Internet-Draft, and is based on a proposal described in [RFC7942]. 2478 The description of implementations in this section is intended to 2479 assist the IETF in its decision processes in progressing drafts to 2480 RFCs. Please note that the listing of any individual implementation 2481 here does not imply endorsement by the IETF. Furthermore, no effort 2482 has been spent to verify the information presented here that was 2483 supplied by IETF contributors. This is not intended as, and must not 2484 be construed to be, a catalog of available implementations or their 2485 features. Readers are advised to note that other implementations may 2486 exist. 2488 According to [RFC7942], "this will allow reviewers and working groups 2489 to assign due consideration to documents that have the benefit of 2490 running code, which may serve as evidence of valuable experimentation 2491 and feedback that have made the implemented protocols more mature. 2492 It is up to the individual working groups to use this information as 2493 they see fit". 2495 13.1. Author's Versions 2497 There are three different implementations that have been created by 2498 the author of the document both to create the examples that are 2499 included in the document and to validate the structures and 2500 methodology used in the design of COSE. 2502 * Implementation Location: https://github.com/cose-wg 2504 * Primary Maintainer: Jim Schaad 2506 * Languages: There are three different languages that are currently 2507 supported: Java, C# and C. 2509 * Cryptography: The Java and C# libraries use Bouncy Castle to 2510 provide the required cryptography. The C version uses OPENSSL 2511 Version 1.1 for the cryptography. 2513 * Coverage: All versions have support to allow for implicit 2514 algorithm support as they allow for the application to set 2515 attributes that are not to be sent in the message. 2517 * Testing: All of the examples in the example library are generated 2518 by the C# library and then validated using the Java and C 2519 libraries. All three libraries have tests to allow for the 2520 creating of the same messages that are in the example library 2521 followed by validating them. These are not compared against the 2522 example library. The Java and C# libraries have unit testing 2523 included. Not all of the MUST statements in the document have 2524 been implemented as part of the libraries. One such statement is 2525 the requirement that unique labels be present. 2527 * Licensing: Revised BSD License 2529 13.2. JavaScript Version 2531 * Implementation Location: https://github.com/erdtman/cose-js 2533 * Primary Maintainer: Samuel Erdtman 2535 * Languages: JavaScript 2537 * Cryptography: TBD 2539 * Coverage: Full Encrypt, Signature and MAC objects are supported. 2541 * Testing: Basic testing against the common example library. 2543 * Licensing: Apache License 2.0 2545 13.3. Python Version 2547 * Implementation Location: https://github.com/TimothyClaeys/COSE- 2548 PYTHON 2550 * Primary Maintainer: Timothy Claeys 2552 * Languages: Python 2554 * Cryptography: pyecdsak, crypto python libraries 2556 * Coverage: TBD 2558 * Testing: Basic testing plus running against the common example 2559 library. 2561 * Licensing: BSD 3-Clause License 2563 13.4. COSE Testing Library 2565 * Implementation Location: https://github.com/cose-wg/Examples 2567 * Primary Maintainer: Jim Schaad 2568 * Description: A set of tests for the COSE library is provided as 2569 part of the implementation effort. Both success and fail tests 2570 have been provided. All of the examples in this document are part 2571 of this example set. 2573 * Coverage: An attempt has been made to have test cases for every 2574 message type and algorithm in the document. Currently examples 2575 dealing with ECDH with Goldilocks are missing. 2577 * Licensing: Public Domain 2579 14. References 2581 14.1. Normative References 2583 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2584 Requirement Levels", BCP 14, RFC 2119, 2585 DOI 10.17487/RFC2119, March 1997, 2586 . 2588 [I-D.ietf-cbor-7049bis] 2589 Bormann, C. and P. Hoffman, "Concise Binary Object 2590 Representation (CBOR)", Work in Progress, Internet-Draft, 2591 draft-ietf-cbor-7049bis-16, 30 September 2020, 2592 . 2594 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2595 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 2596 May 2017, . 2598 [I-D.ietf-cose-rfc8152bis-algs] 2599 Schaad, J., "CBOR Object Signing and Encryption (COSE): 2600 Initial Algorithms", Work in Progress, Internet-Draft, 2601 draft-ietf-cose-rfc8152bis-algs-12, 24 September 2020, 2602 . 2605 14.2. Informative References 2607 [RFC8152] Schaad, J., "CBOR Object Signing and Encryption (COSE)", 2608 RFC 8152, DOI 10.17487/RFC8152, July 2017, 2609 . 2611 [RFC8610] Birkholz, H., Vigano, C., and C. Bormann, "Concise Data 2612 Definition Language (CDDL): A Notational Convention to 2613 Express Concise Binary Object Representation (CBOR) and 2614 JSON Data Structures", RFC 8610, DOI 10.17487/RFC8610, 2615 June 2019, . 2617 [RFC2633] Ramsdell, B., Ed., "S/MIME Version 3 Message 2618 Specification", RFC 2633, DOI 10.17487/RFC2633, June 1999, 2619 . 2621 [RFC4262] Santesson, S., "X.509 Certificate Extension for Secure/ 2622 Multipurpose Internet Mail Extensions (S/MIME) 2623 Capabilities", RFC 4262, DOI 10.17487/RFC4262, December 2624 2005, . 2626 [RFC4949] Shirey, R., "Internet Security Glossary, Version 2", 2627 FYI 36, RFC 4949, DOI 10.17487/RFC4949, August 2007, 2628 . 2630 [RFC5116] McGrew, D., "An Interface and Algorithms for Authenticated 2631 Encryption", RFC 5116, DOI 10.17487/RFC5116, January 2008, 2632 . 2634 [RFC5652] Housley, R., "Cryptographic Message Syntax (CMS)", STD 70, 2635 RFC 5652, DOI 10.17487/RFC5652, September 2009, 2636 . 2638 [RFC5751] Ramsdell, B. and S. Turner, "Secure/Multipurpose Internet 2639 Mail Extensions (S/MIME) Version 3.2 Message 2640 Specification", RFC 5751, DOI 10.17487/RFC5751, January 2641 2010, . 2643 [RFC5752] Turner, S. and J. Schaad, "Multiple Signatures in 2644 Cryptographic Message Syntax (CMS)", RFC 5752, 2645 DOI 10.17487/RFC5752, January 2010, 2646 . 2648 [RFC5990] Randall, J., Kaliski, B., Brainard, J., and S. Turner, 2649 "Use of the RSA-KEM Key Transport Algorithm in the 2650 Cryptographic Message Syntax (CMS)", RFC 5990, 2651 DOI 10.17487/RFC5990, September 2010, 2652 . 2654 [RFC6838] Freed, N., Klensin, J., and T. Hansen, "Media Type 2655 Specifications and Registration Procedures", BCP 13, 2656 RFC 6838, DOI 10.17487/RFC6838, January 2013, 2657 . 2659 [STD90] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 2660 Interchange Format", STD 90, RFC 8259, December 2017. 2662 2664 [BCP201] Housley, R., "Guidelines for Cryptographic Algorithm 2665 Agility and Selecting Mandatory-to-Implement Algorithms", 2666 BCP 201, RFC 7696, November 2015. 2668 2670 [RFC7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 2671 Application Protocol (CoAP)", RFC 7252, 2672 DOI 10.17487/RFC7252, June 2014, 2673 . 2675 [RFC7515] Jones, M., Bradley, J., and N. Sakimura, "JSON Web 2676 Signature (JWS)", RFC 7515, DOI 10.17487/RFC7515, May 2677 2015, . 2679 [RFC7516] Jones, M. and J. Hildebrand, "JSON Web Encryption (JWE)", 2680 RFC 7516, DOI 10.17487/RFC7516, May 2015, 2681 . 2683 [RFC7517] Jones, M., "JSON Web Key (JWK)", RFC 7517, 2684 DOI 10.17487/RFC7517, May 2015, 2685 . 2687 [RFC7518] Jones, M., "JSON Web Algorithms (JWA)", RFC 7518, 2688 DOI 10.17487/RFC7518, May 2015, 2689 . 2691 [RFC8032] Josefsson, S. and I. Liusvaara, "Edwards-Curve Digital 2692 Signature Algorithm (EdDSA)", RFC 8032, 2693 DOI 10.17487/RFC8032, January 2017, 2694 . 2696 [DSS] National Institute of Standards and Technology, "Digital 2697 Signature Standard (DSS)", DOI 10.6028/NIST.FIPS.186-4, 2698 FIPS PUB 186-4, July 2013, 2699 . 2702 [PVSig] Brown, D. and D. Johnson, "Formal Security Proofs for a 2703 Signature Scheme with Partial Message Recovery", 2704 DOI 10.1007/3-540-45353-9_11, LNCS Volume 2020, June 2000, 2705 . 2707 [W3C.WebCrypto] 2708 Watson, M., "Web Cryptography API", W3C Recommendation, 2709 January 2017, . 2711 [RFC8230] Jones, M., "Using RSA Algorithms with CBOR Object Signing 2712 and Encryption (COSE) Messages", RFC 8230, 2713 DOI 10.17487/RFC8230, September 2017, 2714 . 2716 [RFC7942] Sheffer, Y. and A. Farrel, "Improving Awareness of Running 2717 Code: The Implementation Status Section", BCP 205, 2718 RFC 7942, DOI 10.17487/RFC7942, July 2016, 2719 . 2721 [RFC3394] Schaad, J. and R. Housley, "Advanced Encryption Standard 2722 (AES) Key Wrap Algorithm", RFC 3394, DOI 10.17487/RFC3394, 2723 September 2002, . 2725 [I-D.ietf-cose-hash-algs] 2726 Schaad, J., "CBOR Object Signing and Encryption (COSE): 2727 Hash Algorithms", Work in Progress, Internet-Draft, draft- 2728 ietf-cose-hash-algs-09, 14 September 2020, 2729 . 2732 [I-D.ietf-core-groupcomm-bis] 2733 Dijk, E., Wang, C., and M. Tiloca, "Group Communication 2734 for the Constrained Application Protocol (CoAP)", Work in 2735 Progress, Internet-Draft, draft-ietf-core-groupcomm-bis- 2736 02, 2 November 2020, . 2739 [RFC8613] Selander, G., Mattsson, J., Palombini, F., and L. Seitz, 2740 "Object Security for Constrained RESTful Environments 2741 (OSCORE)", RFC 8613, DOI 10.17487/RFC8613, July 2019, 2742 . 2744 [I-D.irtf-cfrg-argon2] 2745 Biryukov, A., Dinu, D., Khovratovich, D., and S. 2746 Josefsson, "The memory-hard Argon2 password hash and 2747 proof-of-work function", Work in Progress, Internet-Draft, 2748 draft-irtf-cfrg-argon2-12, 8 September 2020, 2749 . 2751 [COAP.Formats] 2752 IANA, "CoAP Content-Formats", 2753 . 2756 [COSE.Algorithms] 2757 IANA, "COSE Algorithms", 2758 . 2761 [COSE.KeyParameters] 2762 IANA, "COSE Key Parameters", 2763 . 2766 [COSE.KeyTypes] 2767 IANA, "COSE Key Types", 2768 . 2771 [I-D.ietf-cose-countersign] 2772 Schaad, J., "CBOR Object Signing and Encryption (COSE): 2773 Countersignatures". 2775 Appendix A. Guidelines for External Data Authentication of Algorithms 2777 During development of COSE, the requirement that the algorithm 2778 identifier be located in the protected attributes was relaxed from a 2779 must to a should. There were two basic reasons that have been 2780 advanced to support this position. First, the resulting message will 2781 be smaller if the algorithm identifier is omitted from the most 2782 common messages in a CoAP environment. Second, there is a potential 2783 bug that will arise if full checking is not done correctly between 2784 the different places that an algorithm identifier could be placed 2785 (the message itself, an application statement, the key structure that 2786 the sender possesses, and the key structure the recipient possesses). 2788 This appendix lays out how such a change can be made and the details 2789 that an application needs to specify in order to use this option. 2790 Two different sets of details are specified: those needed to omit an 2791 algorithm identifier and those needed to use the variant on the 2792 countersignature attribute that contains no attributes about itself. 2794 Three sets of recommendations are laid out. The first set of 2795 recommendations applies to having an implicit algorithm identified 2796 for a single layer of a COSE object. The second set of 2797 recommendations applies to having multiple implicit algorithms 2798 identified for multiple layers of a COSE object. The third set of 2799 recommendations applies to having implicit algorithms for multiple 2800 COSE object constructs. 2802 The key words from [RFC2119] are deliberately not used here. This 2803 specification can provide recommendations, but it cannot enforce 2804 them. 2806 This set of recommendations applies to the case where an application 2807 is distributing a fixed algorithm along with the key information for 2808 use in a single COSE object. This normally applies to the smallest 2809 of the COSE objects, specifically COSE_Sign1, COSE_Mac0, and 2810 COSE_Encrypt0, but could apply to the other structures as well. 2812 The following items should be taken into account: 2814 * Applications need to list the set of COSE structures that implicit 2815 algorithms are to be used in. Applications need to require that 2816 the receipt of an explicit algorithm identifier in one of these 2817 structures will lead to the message being rejected. This 2818 requirement is stated so that there will never be a case where 2819 there is any ambiguity about the question of which algorithm 2820 should be used, the implicit or the explicit one. This applies 2821 even if the transported algorithm identifier is a protected 2822 attribute. This applies even if the transported algorithm is the 2823 same as the implicit algorithm. 2825 * Applications need to define the set of information that is to be 2826 considered to be part of a context when omitting algorithm 2827 identifiers. At a minimum, this would be the key identifier (if 2828 needed), the key, the algorithm, and the COSE structure it is used 2829 with. Applications should restrict the use of a single key to a 2830 single algorithm. As noted for some of the algorithms in 2831 [I-D.ietf-cose-rfc8152bis-algs], the use of the same key in 2832 different related algorithms can lead to leakage of information 2833 about the key, leakage about the data or the ability to perform 2834 forgeries. 2836 * In many cases, applications that make the algorithm identifier 2837 implicit will also want to make the context identifier implicit 2838 for the same reason. That is, omitting the context identifier 2839 will decrease the message size (potentially significantly 2840 depending on the length of the identifier). Applications that do 2841 this will need to describe the circumstances where the context 2842 identifier is to be omitted and how the context identifier is to 2843 be inferred in these cases. (An exhaustive search over all of the 2844 keys would normally not be considered to be acceptable.) An 2845 example of how this can be done is to tie the context to a 2846 transaction identifier. Both would be sent on the original 2847 message, but only the transaction identifier would need to be sent 2848 after that point as the context is tied into the transaction 2849 identifier. Another way would be to associate a context with a 2850 network address. All messages coming from a single network 2851 address can be assumed to be associated with a specific context. 2852 (In this case, the address would normally be distributed as part 2853 of the context.) 2855 * Applications cannot rely on key identifiers being unique unless 2856 they take significant efforts to ensure that they are computed in 2857 such a way as to create this guarantee. Even when an application 2858 does this, the uniqueness might be violated if the application is 2859 run in different contexts (i.e., with a different context 2860 provider) or if the system combines the security contexts from 2861 different applications together into a single store. 2863 * Applications should continue the practice of protecting the 2864 algorithm identifier. Since this is not done by placing it in the 2865 protected attributes field, applications should define an 2866 application-specific external data structure that includes this 2867 value. This external data field can be used as such for content 2868 encryption, MAC, and signature algorithms. It can be used in the 2869 SuppPrivInfo field for those algorithms that use a KDF to derive a 2870 key value. Applications may also want to protect other 2871 information that is part of the context structure as well. It 2872 should be noted that those fields, such as the key or a Base IV, 2873 are protected by virtue of being used in the cryptographic 2874 computation and do not need to be included in the external data 2875 field. 2877 The second case is having multiple implicit algorithm identifiers 2878 specified for a multiple layer COSE object. An example of how this 2879 would work is the encryption context that an application specifies, 2880 which contains a content encryption algorithm, a key wrap algorithm, 2881 a key identifier, and a shared secret. The sender omits sending the 2882 algorithm identifier for both the content layer and the recipient 2883 layer leaving only the key identifier. The receiver then uses the 2884 key identifier to get the implicit algorithm identifiers. 2886 The following additional items need to be taken into consideration: 2888 * Applications that want to support this will need to define a 2889 structure that allows for, and clearly identifies, both the COSE 2890 structure to be used with a given key and the structure and 2891 algorithm to be used for the secondary layer. The key for the 2892 secondary layer is computed as normal from the recipient layer. 2894 The third case is having multiple implicit algorithm identifiers, but 2895 targeted at potentially unrelated layers or different COSE objects. 2896 There are a number of different scenarios where this might be 2897 applicable. Some of these scenarios are: 2899 * Two contexts are distributed as a pair. Each of the contexts is 2900 for use with a COSE_Encrypt message. Each context will consist of 2901 distinct secret keys and IVs and potentially even different 2902 algorithms. One context is for sending messages from party A to 2903 party B, and the second context is for sending messages from party 2904 B to party A. This means that there is no chance for a reflection 2905 attack to occur as each party uses different secret keys to send 2906 its messages; a message that is reflected back to it would fail to 2907 decrypt. 2909 * Two contexts are distributed as a pair. The first context is used 2910 for encryption of the message, and the second context is used to 2911 place a countersignature on the message. The intention is that 2912 the second context can be distributed to other entities 2913 independently of the first context. This allows these entities to 2914 validate that the message came from an individual without being 2915 able to decrypt the message and see the content. 2917 * Two contexts are distributed as a pair. The first context 2918 contains a key for dealing with MACed messages, and the second 2919 context contains a different key for dealing with encrypted 2920 messages. This allows for a unified distribution of keys to 2921 participants for different types of messages that have different 2922 keys, but where the keys may be used in a coordinated manner. 2924 For these cases, the following additional items need to be 2925 considered: 2927 * Applications need to ensure that the multiple contexts stay 2928 associated. If one of the contexts is invalidated for any reason, 2929 all of the contexts associated with it should also be invalidated. 2931 Appendix B. Two Layers of Recipient Information 2933 All of the currently defined recipient algorithm classes only use two 2934 layers of the COSE structure. The first layer (COSE_Encrypt) is the 2935 message content, and the second layer (COSE_Recipint) is the content 2936 key encryption. However, if one uses a recipient algorithm such as 2937 the RSA Key Encapsulation Mechanism (RSA-KEM) (see Appendix A of RSA- 2938 KEM [RFC5990]), then it makes sense to have two layers of the 2939 COSE_Recipient structure. 2941 These layers would be: 2943 * Layer 0: The content encryption layer. This layer contains the 2944 payload of the message. 2946 * Layer 1: The encryption of the CEK by a KEK. 2948 * Layer 2: The encryption of a long random secret using an RSA key 2949 and a key derivation function to convert that secret into the KEK. 2951 This is an example of what a triple layer message would look like. 2952 The message has the following layers: 2954 * Layer 0: Has a content encrypted with AES-GCM using a 128-bit key. 2956 * Layer 1: Uses the AES Key Wrap algorithm with a 128-bit key. 2958 * Layer 2: Uses ECDH Ephemeral-Static direct to generate the layer 1 2959 key. 2961 In effect, this example is a decomposed version of using the 2962 ECDH-ES+A128KW algorithm. 2964 Size of binary file is 183 bytes 2965 96( 2966 [ / COSE_Encrypt / 2967 / protected h'a10101' / << { 2968 / alg / 1:1 / AES-GCM 128 / 2969 } >>, 2970 / unprotected / { 2971 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 2972 }, 2973 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e2852948658f0 2974 811139868826e89218a75715b', 2975 / recipients / [ 2976 [ / COSE_Recipient / 2977 / protected / h'', 2978 / unprotected / { 2979 / alg / 1:-3 / A128KW / 2980 }, 2981 / ciphertext / h'dbd43c4e9d719c27c6275c67d628d493f090593db82 2982 18f11', 2983 / recipients / [ 2984 [ / COSE_Recipient / 2985 / protected h'a1013818' / << { 2986 / alg / 1:-25 / ECDH-ES + HKDF-256 / 2987 } >> , 2988 / unprotected / { 2989 / ephemeral / -1:{ 2990 / kty / 1:2, 2991 / crv / -1:1, 2992 / x / -2:h'b2add44368ea6d641f9ca9af308b4079aeb519f11 2993 e9b8a55a600b21233e86e68', 2994 / y / -3:false 2995 }, 2996 / kid / 4:'meriadoc.brandybuck@buckland.example' 2997 }, 2998 / ciphertext / h'' 2999 ] 3000 ] 3001 ] 3002 ] 3003 ] 3004 ) 3006 Appendix C. Examples 3008 This appendix includes a set of examples that show the different 3009 features and message types that have been defined in this document. 3010 To make the examples easier to read, they are presented using the 3011 extended CBOR diagnostic notation (defined in [RFC8610]) rather than 3012 as a binary dump. 3014 A GitHub project has been created at that contains not only the examples presented in this 3016 document, but a more complete set of testing examples as well. Each 3017 example is found in a JSON file that contains the inputs used to 3018 create the example, some of the intermediate values that can be used 3019 in debugging the example and the output of the example presented both 3020 as a hex dump and in CBOR diagnostic notation format. Some of the 3021 examples at the site are designed failure testing cases; these are 3022 clearly marked as such in the JSON file. If errors in the examples 3023 in this document are found, the examples on GitHub will be updated, 3024 and a note to that effect will be placed in the JSON file. 3026 As noted, the examples are presented using the CBOR's diagnostic 3027 notation. A Ruby-based tool exists that can convert between the 3028 diagnostic notation and binary. This tool can be installed with the 3029 command line: 3031 gem install cbor-diag 3033 The diagnostic notation can be converted into binary files using the 3034 following command line: 3036 diag2cbor.rb < inputfile > outputfile 3038 The examples can be extracted from the XML version of this document 3039 via an XPath expression as all of the sourcecode is tagged with the 3040 attribute type='CBORdiag'. (Depending on the XPath evaluator one is 3041 using, it may be necessary to deal with > as an entity.) 3043 //sourcecode[@type='CDDL']/text() 3045 C.1. Examples of Signed Messages 3047 C.1.1. Single Signature 3049 This example uses the following: 3051 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3053 Size of binary file is 103 bytes 3054 98( 3055 [ 3056 / protected / h'', 3057 / unprotected / {}, 3058 / payload / 'This is the content.', 3059 / signatures / [ 3060 [ 3061 / protected h'a10126' / << { 3062 / alg / 1:-7 / ECDSA 256 / 3063 } >>, 3064 / unprotected / { 3065 / kid / 4:'11' 3066 }, 3067 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3068 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3069 98f53afd2fa0f30a' 3070 ] 3071 ] 3072 ] 3073 ) 3075 C.1.2. Multiple Signers 3077 This example uses the following: 3079 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3081 * Signature Algorithm: ECDSA w/ SHA-512, Curve P-521 3083 Size of binary file is 277 bytes 3084 98( 3085 [ 3086 / protected / h'', 3087 / unprotected / {}, 3088 / payload / 'This is the content.', 3089 / signatures / [ 3090 [ 3091 / protected h'a10126' / << { 3092 / alg / 1:-7 / ECDSA 256 / 3093 } >>, 3094 / unprotected / { 3095 / kid / 4:'11' 3096 }, 3097 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3098 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3099 98f53afd2fa0f30a' 3100 ], 3101 [ 3102 / protected h'a1013823' / << { 3103 / alg / 1:-36 / ECDSA 521 / 3104 } >> , 3105 / unprotected / { 3106 / kid / 4:'bilbo.baggins@hobbiton.example' 3107 }, 3108 / signature / h'00a2d28a7c2bdb1587877420f65adf7d0b9a06635dd1 3109 de64bb62974c863f0b160dd2163734034e6ac003b01e8705524c5c4ca479a952f024 3110 7ee8cb0b4fb7397ba08d009e0c8bf482270cc5771aa143966e5a469a09f613488030 3111 c5b07ec6d722e3835adb5b2d8c44e95ffb13877dd2582866883535de3bb03d01753f 3112 83ab87bb4f7a0297' 3113 ] 3114 ] 3115 ] 3116 ) 3118 C.1.3. Signature with Criticality 3120 This example uses the following: 3122 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3124 * There is a criticality marker on the "reserved" header parameter 3126 Size of binary file is 125 bytes 3127 98( 3128 [ 3129 / protected h'a2687265736572766564f40281687265736572766564' / 3130 << { 3131 "reserved":false, 3132 / crit / 2:[ 3133 "reserved" 3134 ] 3135 } >>, 3136 / unprotected / {}, 3137 / payload / 'This is the content.', 3138 / signatures / [ 3139 [ 3140 / protected h'a10126' / << { 3141 / alg / 1:-7 / ECDSA 256 / 3142 } >>, 3143 / unprotected / { 3144 / kid / 4:'11' 3145 }, 3146 / signature / h'3fc54702aa56e1b2cb20284294c9106a63f91bac658d 3147 69351210a031d8fc7c5ff3e4be39445b1a3e83e1510d1aca2f2e8a7c081c7645042b 3148 18aba9d1fad1bd9c' 3149 ] 3150 ] 3151 ] 3152 ) 3154 C.2. Single Signer Examples 3156 C.2.1. Single ECDSA Signature 3158 This example uses the following: 3160 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3162 Size of binary file is 98 bytes 3163 18( 3164 [ 3165 / protected h'a10126' / << { 3166 / alg / 1:-7 / ECDSA 256 / 3167 } >>, 3168 / unprotected / { 3169 / kid / 4:'11' 3170 }, 3171 / payload / 'This is the content.', 3172 / signature / h'8eb33e4ca31d1c465ab05aac34cc6b23d58fef5c083106c4 3173 d25a91aef0b0117e2af9a291aa32e14ab834dc56ed2a223444547e01f11d3b0916e5 3174 a4c345cacb36' 3175 ] 3176 ) 3178 C.3. Examples of Enveloped Messages 3180 C.3.1. Direct ECDH 3182 This example uses the following: 3184 * CEK: AES-GCM w/ 128-bit key 3186 * Recipient class: ECDH Ephemeral-Static, Curve P-256 3188 Size of binary file is 151 bytes 3189 96( 3190 [ 3191 / protected h'a10101' / << { 3192 / alg / 1:1 / AES-GCM 128 / 3193 } >>, 3194 / unprotected / { 3195 / iv / 5:h'c9cf4df2fe6c632bf7886413' 3196 }, 3197 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 3198 c52a357da7a644b8070a151b0', 3199 / recipients / [ 3200 [ 3201 / protected h'a1013818' / << { 3202 / alg / 1:-25 / ECDH-ES + HKDF-256 / 3203 } >>, 3204 / unprotected / { 3205 / ephemeral / -1:{ 3206 / kty / 1:2, 3207 / crv / -1:1, 3208 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 3209 bf054e1c7b4d91d6280', 3210 / y / -3:true 3211 }, 3212 / kid / 4:'meriadoc.brandybuck@buckland.example' 3213 }, 3214 / ciphertext / h'' 3215 ] 3216 ] 3217 ] 3218 ) 3220 C.3.2. Direct Plus Key Derivation 3222 This example uses the following: 3224 * CEK: AES-CCM w/ 128-bit key, truncate the tag to 64 bits 3226 * Recipient class: Use HKDF on a shared secret with the following 3227 implicit fields as part of the context. 3229 - salt: "aabbccddeeffgghh" 3231 - PartyU identity: "lighting-client" 3233 - PartyV identity: "lighting-server" 3235 - Supplementary Public Other: "Encryption Example 02" 3237 Size of binary file is 91 bytes 3239 96( 3240 [ 3241 / protected h'a1010a' / << { 3242 / alg / 1:10 / AES-CCM-16-64-128 / 3243 } >>, 3244 / unprotected / { 3245 / iv / 5:h'89f52f65a1c580933b5261a76c' 3246 }, 3247 / ciphertext / h'753548a19b1307084ca7b2056924ed95f2e3b17006dfe93 3248 1b687b847', 3249 / recipients / [ 3250 [ 3251 / protected h'a10129' / << { 3252 / alg / 1:-10 3253 } >>, 3254 / unprotected / { 3255 / salt / -20:'aabbccddeeffgghh', 3256 / kid / 4:'our-secret' 3257 }, 3258 / ciphertext / h'' 3259 ] 3260 ] 3261 ] 3262 ) 3264 C.3.3. Encrypted Content with External Data 3266 This example uses the following: 3268 * CEK: AES-GCM w/ 128-bit key 3270 * Recipient class: ECDH static-Static, Curve P-256 with AES Key Wrap 3272 * Externally Supplied AAD: h'0011bbcc22dd44ee55ff660077' 3274 Size of binary file is 173 bytes 3275 96( 3276 [ 3277 / protected h'a10101' / << { 3278 / alg / 1:1 / AES-GCM 128 / 3279 } >> , 3280 / unprotected / { 3281 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 3282 }, 3283 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e28529d8f5335 3284 e5f0165eee976b4a5f6c6f09d', 3285 / recipients / [ 3286 [ 3287 / protected / h'a101381f' / { 3288 \ alg \ 1:-32 \ ECHD-SS+A128KW \ 3289 } / , 3290 / unprotected / { 3291 / static kid / -3:'peregrin.took@tuckborough.example', 3292 / kid / 4:'meriadoc.brandybuck@buckland.example', 3293 / U nonce / -22:h'0101' 3294 }, 3295 / ciphertext / h'41e0d76f579dbd0d936a662d54d8582037de2e366fd 3296 e1c62' 3297 ] 3298 ] 3299 ] 3300 ) 3302 C.4. Examples of Encrypted Messages 3304 C.4.1. Simple Encrypted Message 3306 This example uses the following: 3308 * CEK: AES-CCM w/ 128-bit key and a 64-bit tag 3310 Size of binary file is 52 bytes 3311 16( 3312 [ 3313 / protected h'a1010a' / << { 3314 / alg / 1:10 / AES-CCM-16-64-128 / 3315 } >> , 3316 / unprotected / { 3317 / iv / 5:h'89f52f65a1c580933b5261a78c' 3318 }, 3319 / ciphertext / h'5974e1b99a3a4cc09a659aa2e9e7fff161d38ce71cb45ce 3320 460ffb569' 3321 ] 3322 ) 3324 C.4.2. Encrypted Message with a Partial IV 3326 This example uses the following: 3328 * CEK: AES-CCM w/ 128-bit key and a 64-bit tag 3330 * Prefix for IV is 89F52F65A1C580933B52 3332 Size of binary file is 41 bytes 3334 16( 3335 [ 3336 / protected h'a1010a' / << { 3337 / alg / 1:10 / AES-CCM-16-64-128 / 3338 } >> , 3339 / unprotected / { 3340 / partial iv / 6:h'61a7' 3341 }, 3342 / ciphertext / h'252a8911d465c125b6764739700f0141ed09192de139e05 3343 3bd09abca' 3344 ] 3345 ) 3347 C.5. Examples of MACed Messages 3349 C.5.1. Shared Secret Direct MAC 3351 This example uses the following: 3353 * MAC: AES-CMAC, 256-bit key, truncated to 64 bits 3355 * Recipient class: direct shared secret 3357 Size of binary file is 57 bytes 3358 97( 3359 [ 3360 / protected h'a1010f' / << { 3361 / alg / 1:15 / AES-CBC-MAC-256//64 / 3362 } >> , 3363 / unprotected / {}, 3364 / payload / 'This is the content.', 3365 / tag / h'9e1226ba1f81b848', 3366 / recipients / [ 3367 [ 3368 / protected / h'', 3369 / unprotected / { 3370 / alg / 1:-6 / direct /, 3371 / kid / 4:'our-secret' 3372 }, 3373 / ciphertext / h'' 3374 ] 3375 ] 3376 ] 3377 ) 3379 C.5.2. ECDH Direct MAC 3381 This example uses the following: 3383 * MAC: HMAC w/SHA-256, 256-bit key 3385 * Recipient class: ECDH key agreement, two static keys, HKDF w/ 3386 context structure 3388 Size of binary file is 214 bytes 3389 97( 3390 [ 3391 / protected h'a10105' / << { 3392 / alg / 1:5 / HMAC 256//256 / 3393 } >> , 3394 / unprotected / {}, 3395 / payload / 'This is the content.', 3396 / tag / h'81a03448acd3d305376eaa11fb3fe416a955be2cbe7ec96f012c99 3397 4bc3f16a41', 3398 / recipients / [ 3399 [ 3400 / protected h'a101381a' / << { 3401 / alg / 1:-27 / ECDH-SS + HKDF-256 / 3402 } >> , 3403 / unprotected / { 3404 / static kid / -3:'peregrin.took@tuckborough.example', 3405 / kid / 4:'meriadoc.brandybuck@buckland.example', 3406 / U nonce / -22:h'4d8553e7e74f3c6a3a9dd3ef286a8195cbf8a23d 3407 19558ccfec7d34b824f42d92bd06bd2c7f0271f0214e141fb779ae2856abf585a583 3408 68b017e7f2a9e5ce4db5' 3409 }, 3410 / ciphertext / h'' 3411 ] 3412 ] 3413 ] 3414 ) 3416 C.5.3. Wrapped MAC 3418 This example uses the following: 3420 * MAC: AES-MAC, 128-bit key, truncated to 64 bits 3422 * Recipient class: AES Key Wrap w/ a pre-shared 256-bit key 3424 Size of binary file is 109 bytes 3425 97( 3426 [ 3427 / protected h'a1010e' / << { 3428 / alg / 1:14 / AES-CBC-MAC-128//64 / 3429 } >> , 3430 / unprotected / {}, 3431 / payload / 'This is the content.', 3432 / tag / h'36f5afaf0bab5d43', 3433 / recipients / [ 3434 [ 3435 / protected / h'', 3436 / unprotected / { 3437 / alg / 1:-5 / A256KW /, 3438 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 3439 }, 3440 / ciphertext / h'711ab0dc2fc4585dce27effa6781c8093eba906f227 3441 b6eb0' 3442 ] 3443 ] 3444 ] 3445 ) 3447 C.5.4. Multi-Recipient MACed Message 3449 This example uses the following: 3451 * MAC: HMAC w/ SHA-256, 128-bit key 3453 * Recipient class: Uses three different methods 3455 1. ECDH Ephemeral-Static, Curve P-521, AES Key Wrap w/ 128-bit 3456 key 3458 2. AES Key Wrap w/ 256-bit key 3460 Size of binary file is 309 bytes 3461 97( 3462 [ 3463 / protected h'a10105' / << { 3464 / alg / 1:5 / HMAC 256//256 / 3465 } >> , 3466 / unprotected / {}, 3467 / payload / 'This is the content.', 3468 / tag / h'bf48235e809b5c42e995f2b7d5fa13620e7ed834e337f6aa43df16 3469 1e49e9323e', 3470 / recipients / [ 3471 [ 3472 / protected h'a101381c' / << { 3473 / alg / 1:-29 / ECHD-ES+A128KW / 3474 } >> , 3475 / unprotected / { 3476 / ephemeral / -1:{ 3477 / kty / 1:2, 3478 / crv / -1:3, 3479 / x / -2:h'0043b12669acac3fd27898ffba0bcd2e6c366d53bc4db 3480 71f909a759304acfb5e18cdc7ba0b13ff8c7636271a6924b1ac63c02688075b55ef2 3481 d613574e7dc242f79c3', 3482 / y / -3:true 3483 }, 3484 / kid / 4:'bilbo.baggins@hobbiton.example' 3485 }, 3486 / ciphertext / h'339bc4f79984cdc6b3e6ce5f315a4c7d2b0ac466fce 3487 a69e8c07dfbca5bb1f661bc5f8e0df9e3eff5' 3488 ], 3489 [ 3490 / protected / h'', 3491 / unprotected / { 3492 / alg / 1:-5 / A256KW /, 3493 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 3494 }, 3495 / ciphertext / h'0b2c7cfce04e98276342d6476a7723c090dfdd15f9a 3496 518e7736549e998370695e6d6a83b4ae507bb' 3497 ] 3498 ] 3499 ] 3500 ) 3502 C.6. Examples of MAC0 Messages 3504 C.6.1. Shared Secret Direct MAC 3506 This example uses the following: 3508 * MAC: AES-CMAC, 256-bit key, truncated to 64 bits 3509 * Recipient class: direct shared secret 3511 Size of binary file is 37 bytes 3513 17( 3514 [ 3515 / protected h'a1010f' / << { 3516 / alg / 1:15 / AES-CBC-MAC-256//64 / 3517 } >> , 3518 / unprotected / {}, 3519 / payload / 'This is the content.', 3520 / tag / h'726043745027214f' 3521 ] 3522 ) 3524 Note that this example uses the same inputs as Appendix C.5.1. 3526 C.7. COSE Keys 3528 C.7.1. Public Keys 3530 This is an example of a COSE Key Set. This example includes the 3531 public keys for all of the previous examples. 3533 In order the keys are: 3535 * An EC key with a kid of "meriadoc.brandybuck@buckland.example" 3537 * An EC key with a kid of "peregrin.took@tuckborough.example" 3539 * An EC key with a kid of "bilbo.baggins@hobbiton.example" 3541 * An EC key with a kid of "11" 3543 Size of binary file is 481 bytes 3545 [ 3546 { 3547 -1:1, 3548 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 3549 8551d', 3550 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 3551 4d19c', 3552 1:2, 3553 2:'meriadoc.brandybuck@buckland.example' 3554 }, 3555 { 3556 -1:1, 3557 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 3558 09eff', 3559 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 3560 c117e', 3561 1:2, 3562 2:'11' 3563 }, 3564 { 3565 -1:3, 3566 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 3567 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 3568 f42ad', 3569 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 3570 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 3571 d9475', 3572 1:2, 3573 2:'bilbo.baggins@hobbiton.example' 3574 }, 3575 { 3576 -1:1, 3577 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 3578 d6280', 3579 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 3580 822bb', 3581 1:2, 3582 2:'peregrin.took@tuckborough.example' 3583 } 3584 ] 3586 C.7.2. Private Keys 3588 This is an example of a COSE Key Set. This example includes the 3589 private keys for all of the previous examples. 3591 In order the keys are: 3593 * An EC key with a kid of "meriadoc.brandybuck@buckland.example" 3595 * A shared-secret key with a kid of "our-secret" 3597 * An EC key with a kid of "peregrin.took@tuckborough.example" 3599 * A shared-secret key with a kid of "018c0ae5-4d9b-471b- 3600 bfd6-eef314bc7037" 3602 * An EC key with a kid of "bilbo.baggins@hobbiton.example" 3604 * An EC key with a kid of "11" 3606 Size of binary file is 816 bytes 3608 [ 3609 { 3610 1:2, 3611 2:'meriadoc.brandybuck@buckland.example', 3612 -1:1, 3613 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 3614 8551d', 3615 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 3616 4d19c', 3617 -4:h'aff907c99f9ad3aae6c4cdf21122bce2bd68b5283e6907154ad911840fa 3618 208cf' 3619 }, 3620 { 3621 1:2, 3622 2:'11', 3623 -1:1, 3624 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 3625 09eff', 3626 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 3627 c117e', 3628 -4:h'57c92077664146e876760c9520d054aa93c3afb04e306705db609030850 3629 7b4d3' 3630 }, 3631 { 3632 1:2, 3633 2:'bilbo.baggins@hobbiton.example', 3634 -1:3, 3635 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 3636 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 3637 f42ad', 3638 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 3639 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 3640 d9475', 3641 -4:h'00085138ddabf5ca975f5860f91a08e91d6d5f9a76ad4018766a476680b 3642 55cd339e8ab6c72b5facdb2a2a50ac25bd086647dd3e2e6e99e84ca2c3609fdf177f 3643 eb26d' 3644 }, 3645 { 3646 1:4, 3647 2:'our-secret', 3648 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 3649 27188' 3650 }, 3651 { 3652 1:2, 3653 -1:1, 3654 2:'peregrin.took@tuckborough.example', 3655 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 3656 d6280', 3657 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 3658 822bb', 3659 -4:h'02d1f7e6f26c43d4868d87ceb2353161740aacf1f7163647984b522a848 3660 df1c3' 3661 }, 3662 { 3663 1:4, 3664 2:'our-secret2', 3665 -1:h'849b5786457c1491be3a76dcea6c4271' 3666 }, 3667 { 3668 1:4, 3669 2:'018c0ae5-4d9b-471b-bfd6-eef314bc7037', 3670 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 3671 27188' 3672 } 3673 ] 3675 Acknowledgments 3677 This document is a product of the COSE working group of the IETF. 3679 The following individuals are to blame for getting me started on this 3680 project in the first place: Richard Barnes, Matt Miller, and Martin 3681 Thomson. 3683 The initial version of the specification was based to some degree on 3684 the outputs of the JOSE and S/MIME working groups. 3686 The following individuals provided input into the final form of the 3687 document: Carsten Bormann, John Bradley, Brain Campbell, Michael B. 3688 Jones, Ilari Liusvaara, Francesca Palombini, Ludwig Seitz, and 3689 Göran Selander. 3691 Author's Address 3693 Jim Schaad 3694 August Cellars 3696 Email: ietf@augustcellars.com