idnits 2.17.1 draft-ietf-cose-rfc8152bis-struct-00.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.schaad-cose-RFC8152bis-algs]), which it shouldn't. Please replace those with straight textual mentions of the documents in question. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (January 21, 2019) is 1921 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: Non-RFC (?) normative reference: ref. 'DSS' -- Possible downref: Normative reference to a draft: ref. 'I-D.schaad-cose-rfc8152bis-algs' ** Obsolete normative reference: RFC 7049 (Obsoleted by RFC 8949) ** Downref: Normative reference to an Informational RFC: RFC 8032 == Outdated reference: A later version (-08) exists of draft-ietf-cbor-cddl-06 == Outdated reference: A later version (-16) exists of draft-ietf-core-object-security-15 -- Obsolete informational reference (is this intentional?): RFC 2633 (Obsoleted by RFC 3851) -- Obsolete informational reference (is this intentional?): RFC 5751 (Obsoleted by RFC 8551) -- Obsolete informational reference (is this intentional?): RFC 8152 (Obsoleted by RFC 9052, RFC 9053) Summary: 3 errors (**), 0 flaws (~~), 3 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) January 21, 2019 5 Intended status: Standards Track 6 Expires: July 25, 2019 8 CBOR Object Signing and Encryption (COSE) - Structures and Process 9 draft-ietf-cose-rfc8152bis-struct-00 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.schaad-cose-rfc8152bis-algs] obsoletes 23 RFC8152. 25 Contributing to this document 27 The source for this draft is being maintained in GitHub. Suggested 28 changes should be submitted as pull requests at . Instructions are on that page as well. 30 Editorial changes can be managed in GitHub, but any substantial 31 issues need to be discussed on the COSE mailing list. 33 Status of This Memo 35 This Internet-Draft is submitted in full conformance with the 36 provisions of BCP 78 and BCP 79. 38 Internet-Drafts are working documents of the Internet Engineering 39 Task Force (IETF). Note that other groups may also distribute 40 working documents as Internet-Drafts. The list of current Internet- 41 Drafts is at https://datatracker.ietf.org/drafts/current/. 43 Internet-Drafts are draft documents valid for a maximum of six months 44 and may be updated, replaced, or obsoleted by other documents at any 45 time. It is inappropriate to use Internet-Drafts as reference 46 material or to cite them other than as "work in progress." 48 This Internet-Draft will expire on July 25, 2019. 50 Copyright Notice 52 Copyright (c) 2019 IETF Trust and the persons identified as the 53 document authors. All rights reserved. 55 This document is subject to BCP 78 and the IETF Trust's Legal 56 Provisions Relating to IETF Documents 57 (https://trustee.ietf.org/license-info) in effect on the date of 58 publication of this document. Please review these documents 59 carefully, as they describe your rights and restrictions with respect 60 to this document. Code Components extracted from this document must 61 include Simplified BSD License text as described in Section 4.e of 62 the Trust Legal Provisions and are provided without warranty as 63 described in the Simplified BSD License. 65 Table of Contents 67 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 68 1.1. Design Changes from JOSE . . . . . . . . . . . . . . . . 5 69 1.2. Requirements Terminology . . . . . . . . . . . . . . . . 6 70 1.3. CBOR Grammar . . . . . . . . . . . . . . . . . . . . . . 6 71 1.4. CBOR-Related Terminology . . . . . . . . . . . . . . . . 7 72 1.5. Document Terminology . . . . . . . . . . . . . . . . . . 8 73 2. Basic COSE Structure . . . . . . . . . . . . . . . . . . . . 8 74 3. Header Parameters . . . . . . . . . . . . . . . . . . . . . . 10 75 3.1. Common COSE Headers Parameters . . . . . . . . . . . . . 12 76 4. Signing Objects . . . . . . . . . . . . . . . . . . . . . . . 16 77 4.1. Signing with One or More Signers . . . . . . . . . . . . 16 78 4.2. Signing with One Signer . . . . . . . . . . . . . . . . . 18 79 4.3. Externally Supplied Data . . . . . . . . . . . . . . . . 19 80 4.4. Signing and Verification Process . . . . . . . . . . . . 20 81 4.5. Computing Counter Signatures . . . . . . . . . . . . . . 21 82 5. Encryption Objects . . . . . . . . . . . . . . . . . . . . . 22 83 5.1. Enveloped COSE Structure . . . . . . . . . . . . . . . . 22 84 5.1.1. Content Key Distribution Methods . . . . . . . . . . 24 85 5.2. Single Recipient Encrypted . . . . . . . . . . . . . . . 24 86 5.3. How to Encrypt and Decrypt for AEAD Algorithms . . . . . 25 87 5.4. How to Encrypt and Decrypt for AE Algorithms . . . . . . 27 88 6. MAC Objects . . . . . . . . . . . . . . . . . . . . . . . . . 29 89 6.1. MACed Message with Recipients . . . . . . . . . . . . . . 29 90 6.2. MACed Messages with Implicit Key . . . . . . . . . . . . 30 91 6.3. How to Compute and Verify a MAC . . . . . . . . . . . . . 31 92 7. Key Objects . . . . . . . . . . . . . . . . . . . . . . . . . 32 93 7.1. COSE Key Common Parameters . . . . . . . . . . . . . . . 33 94 8. Signature Algorithms . . . . . . . . . . . . . . . . . . . . 36 95 9. Message Authentication Code (MAC) Algorithms . . . . . . . . 37 96 10. Content Encryption Algorithms . . . . . . . . . . . . . . . . 38 97 11. Key Derivation Functions (KDFs) . . . . . . . . . . . . . . . 38 98 12. Content Key Distribution Methods . . . . . . . . . . . . . . 39 99 12.1. Direct Encryption . . . . . . . . . . . . . . . . . . . 39 100 12.2. Key Wrap . . . . . . . . . . . . . . . . . . . . . . . . 40 101 12.3. Key Transport . . . . . . . . . . . . . . . . . . . . . 40 102 12.4. Direct Key Agreement . . . . . . . . . . . . . . . . . . 41 103 12.5. Key Agreement with Key Wrap . . . . . . . . . . . . . . 42 104 13. CBOR Encoder Restrictions . . . . . . . . . . . . . . . . . . 42 105 14. Application Profiling Considerations . . . . . . . . . . . . 43 106 15. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 44 107 15.1. CBOR Tag Assignment . . . . . . . . . . . . . . . . . . 44 108 15.2. COSE Header Parameters Registry . . . . . . . . . . . . 44 109 15.3. COSE Header Algorithm Parameters Registry . . . . . . . 44 110 15.4. COSE Key Common Parameters Registry . . . . . . . . . . 45 111 15.5. Media Type Registrations . . . . . . . . . . . . . . . . 45 112 15.5.1. COSE Security Message . . . . . . . . . . . . . . . 45 113 15.5.2. COSE Key Media Type . . . . . . . . . . . . . . . . 46 114 15.6. CoAP Content-Formats Registry . . . . . . . . . . . . . 48 115 15.7. Expert Review Instructions . . . . . . . . . . . . . . . 48 116 16. Security Considerations . . . . . . . . . . . . . . . . . . . 49 117 17. References . . . . . . . . . . . . . . . . . . . . . . . . . 51 118 17.1. Normative References . . . . . . . . . . . . . . . . . . 51 119 17.2. Informative References . . . . . . . . . . . . . . . . . 52 120 Appendix A. Guidelines for External Data Authentication of 121 Algorithms . . . . . . . . . . . . . . . . . . . . . 55 122 A.1. Algorithm Identification . . . . . . . . . . . . . . . . 55 123 A.2. Counter Signature without Headers . . . . . . . . . . . . 58 124 Appendix B. Two Layers of Recipient Information . . . . . . . . 59 125 Appendix C. Examples . . . . . . . . . . . . . . . . . . . . . . 60 126 C.1. Examples of Signed Messages . . . . . . . . . . . . . . . 61 127 C.1.1. Single Signature . . . . . . . . . . . . . . . . . . 61 128 C.1.2. Multiple Signers . . . . . . . . . . . . . . . . . . 62 129 C.1.3. Counter Signature . . . . . . . . . . . . . . . . . . 63 130 C.1.4. Signature with Criticality . . . . . . . . . . . . . 64 131 C.2. Single Signer Examples . . . . . . . . . . . . . . . . . 65 132 C.2.1. Single ECDSA Signature . . . . . . . . . . . . . . . 65 133 C.3. Examples of Enveloped Messages . . . . . . . . . . . . . 66 134 C.3.1. Direct ECDH . . . . . . . . . . . . . . . . . . . . . 66 135 C.3.2. Direct Plus Key Derivation . . . . . . . . . . . . . 67 136 C.3.3. Counter Signature on Encrypted Content . . . . . . . 68 137 C.3.4. Encrypted Content with External Data . . . . . . . . 70 138 C.4. Examples of Encrypted Messages . . . . . . . . . . . . . 70 139 C.4.1. Simple Encrypted Message . . . . . . . . . . . . . . 70 140 C.4.2. Encrypted Message with a Partial IV . . . . . . . . . 71 141 C.5. Examples of MACed Messages . . . . . . . . . . . . . . . 71 142 C.5.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 71 143 C.5.2. ECDH Direct MAC . . . . . . . . . . . . . . . . . . . 72 144 C.5.3. Wrapped MAC . . . . . . . . . . . . . . . . . . . . . 73 145 C.5.4. Multi-Recipient MACed Message . . . . . . . . . . . . 74 147 C.6. Examples of MAC0 Messages . . . . . . . . . . . . . . . . 75 148 C.6.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 75 149 C.7. COSE Keys . . . . . . . . . . . . . . . . . . . . . . . . 76 150 C.7.1. Public Keys . . . . . . . . . . . . . . . . . . . . . 76 151 C.7.2. Private Keys . . . . . . . . . . . . . . . . . . . . 77 152 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 79 153 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 80 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)" [RFC7049]. CBOR extended the data model of the JavaScript 161 Object Notation (JSON) [RFC8259] by allowing for binary data, among 162 other changes. CBOR has been adopted by several of the IETF working 163 groups dealing with the IoT world as their encoding of data 164 structures. CBOR was designed specifically to be both small in terms 165 of messages transport and implementation size and be a schema-free 166 decoder. A need exists to provide message security services for IoT, 167 and using CBOR as the message-encoding format makes sense. 169 The JOSE working group produced a set of documents [RFC7515] 170 [RFC7516] [RFC7517] [RFC7518] using JSON that specified how to 171 process encryption, signatures, and Message Authentication Code (MAC) 172 operations and how to encode keys using JSON. This document along 173 with [I-D.schaad-cose-rfc8152bis-algs] defines the CBOR Object 174 Signing and Encryption (COSE) standard, which does the same thing for 175 the CBOR encoding format. While there is a strong attempt to keep 176 the flavor of the original JSON Object Signing and Encryption (JOSE) 177 documents, two considerations are taken into account: 179 o CBOR has capabilities that are not present in JSON and are 180 appropriate to use. One example of this is the fact that CBOR has 181 a method of encoding binary directly without first converting it 182 into a base64-encoded string. 184 o COSE is not a direct copy of the JOSE specification. In the 185 process of creating COSE, decisions that were made for JOSE were 186 re-examined. In many cases, different results were decided on as 187 the criteria were not always the same. 189 This document contains: 191 o The description of the structure for the CBOR objects which are 192 transmitted over the wire. Two objects are defined for 193 encryption, signing and message authentication. One object is 194 defined for transporting keys and one for transporting groups of 195 keys. 197 o The procedures used to compute build the inputs to the 198 cryptographic functions required for each of the structures. 200 o A starting set of attributes that apply to the different security 201 objects. 203 This document does not contain the rules and procedures for using 204 specific cryptographic algorithms. Details on specific algorithms 205 can be found in [I-D.schaad-cose-rfc8152bis-algs] and [RFC8230]. 206 Details for additional algorithms are expected to be defined in 207 future documents. 209 One feature that is present in CMS [RFC5652] that is not present in 210 this standard is a digest structure. This omission is deliberate. 211 It is better for the structure to be defined in each document as 212 different protocols will want to include a different set of fields as 213 part of the structure. While an algorithm identifier and the digesst 214 value are going to be common to all applications, the two values may 215 not always be adjacent as the algorithm could be defined once with 216 multiple values. Applications may additionally want to defined 217 additional data fields as part of the stucture. A common structure 218 is going to include a URI or other pointer to where the data that is 219 being hashed is kept, allowing this to be application specific. 221 1.1. Design Changes from JOSE 223 o Define a single top message structure so that encrypted, signed, 224 and MACed messages can easily be identified and still have a 225 consistent view. 227 o Signed messages distinguish between the protected and unprotected 228 parameters that relate to the content from those that relate to 229 the signature. 231 o MACed messages are separated from signed messages. 233 o MACed messages have the ability to use the same set of recipient 234 algorithms as enveloped messages for obtaining the MAC 235 authentication key. 237 o Use binary encodings for binary data rather than base64url 238 encodings. 240 o Combine the authentication tag for encryption algorithms with the 241 ciphertext. 243 o The set of cryptographic algorithms has been expanded in some 244 directions and trimmed in others. 246 1.2. Requirements Terminology 248 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 249 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 250 "OPTIONAL" in this document are to be interpreted as described in BCP 251 14 [RFC2119] [RFC8174] when, and only when, they appear in all 252 capitals, as shown here. 254 1.3. CBOR Grammar 256 There was not a standard CBOR grammar available when COSE was 257 originally written. For that reason the CBOR structures defined here 258 are described in prose. Since that time CBOR Data Definition 259 Language (CDDL) [I-D.ietf-cbor-cddl] has been published as an RFC. 260 The CBOR grammar presented in this document is compatible with CDDL. 262 The document was developed by first working on the grammar and then 263 developing the prose to go with it. An artifact of this is that the 264 prose was written using the primitive type strings defined by CBOR 265 Data Definition Language (CDDL) [I-D.ietf-cbor-cddl]. In this 266 specification, the following primitive types are used: 268 any -- non-specific value that permits all CBOR values to be 269 placed here. 271 bool -- a boolean value (true: major type 7, value 21; false: 272 major type 7, value 20). 274 bstr -- byte string (major type 2). 276 int -- an unsigned integer or a negative integer. 278 nil -- a null value (major type 7, value 22). 280 nint -- a negative integer (major type 1). 282 tstr -- a UTF-8 text string (major type 3). 284 uint -- an unsigned integer (major type 0). 286 Two syntaxes from CDDL appear in this document as shorthand. These 287 are: 289 FOO / BAR -- indicates that either FOO or BAR can appear here. 291 [+ FOO] -- indicates that the type FOO appears one or more times 292 in an array. 294 As well as the prose description, a version of a CBOR grammar is 295 presented in CDDL. The CDDL grammar is informational; the prose 296 description is normative. 298 The collected CDDL can be extracted from the XML version of this 299 document via the following XPath expression below. (Depending on the 300 XPath evaluator one is using, it may be necessary to deal with > 301 as an entity.) 303 //artwork[@type='CDDL']/text() 305 CDDL expects the initial non-terminal symbol to be the first symbol 306 in the file. For this reason, the first fragment of CDDL is 307 presented here. 309 start = COSE_Messages / COSE_Key / COSE_KeySet / Internal_Types 311 ; This is defined to make the tool quieter: 312 Internal_Types = Sig_structure / Enc_structure / MAC_structure / 313 COSE_KDF_Context 315 The non-terminal Internal_Types is defined for dealing with the 316 automated validation tools used during the writing of this document. 317 It references those non-terminals that are used for security 318 computations but are not emitted for transport. 320 1.4. CBOR-Related Terminology 322 In JSON, maps are called objects and only have one kind of map key: a 323 string. In COSE, we use strings, negative integers, and unsigned 324 integers as map keys. The integers are used for compactness of 325 encoding and easy comparison. The inclusion of strings allows for an 326 additional range of short encoded values to be used as well. Since 327 the word "key" is mainly used in its other meaning, as a 328 cryptographic key, we use the term "label" for this usage as a map 329 key. 331 The presence of a label in a COSE map that is not a string or an 332 integer is an error. Applications can either fail processing or 333 process messages by ignoring incorrect labels; however, they MUST NOT 334 create messages with incorrect labels. 336 A CDDL grammar fragment defines the non-terminal 'label', as in the 337 previous paragraph, and 'values', which permits any value to be used. 339 label = int / tstr 340 values = any 342 1.5. Document Terminology 344 In this document, we use the following terminology: 346 Byte is a synonym for octet. 348 Constrained Application Protocol (CoAP) is a specialized web transfer 349 protocol for use in constrained systems. It is defined in [RFC7252]. 351 Authenticated Encryption (AE) [RFC5116] algorithms are those 352 encryption algorithms that provide an authentication check of the 353 contents algorithm with the encryption service. 355 Authenticated Encryption with Authenticated Data (AEAD) [RFC5116] 356 algorithms provide the same content authentication service as AE 357 algorithms, but they additionally provide for authentication of non- 358 encrypted data as well. 360 2. Basic COSE Structure 362 The COSE object structure is designed so that there can be a large 363 amount of common code when parsing and processing the different types 364 of security messages. All of the message structures are built on the 365 CBOR array type. The first three elements of the array always 366 contain the same information: 368 1. The set of protected header parameters wrapped in a bstr. 370 2. The set of unprotected header parameters as a map. 372 3. The content of the message. The content is either the plaintext 373 or the ciphertext as appropriate. The content may be detached 374 (i.e. transported separately from the COSE structure), but the 375 location is still used. The content is wrapped in a bstr when 376 present and is a nil value when detached. 378 Elements after this point are dependent on the specific message type. 380 COSE messages are built using the concept of layers to separate 381 different types of cryptographic concepts. As an example of how this 382 works, consider the COSE_Encrypt message (Section 5.1). This message 383 type is broken into two layers: the content layer and the recipient 384 layer. In the content layer, the plaintext is encrypted and 385 information about the encrypted message is placed. In the recipient 386 layer, the content encryption key (CEK) is encrypted and information 387 about how it is encrypted for each recipient is placed. A single 388 layer version of the encryption message COSE_Encrypt0 (Section 5.2) 389 is provided for cases where the CEK is pre-shared. 391 Identification of which type of message has been presented is done by 392 the following methods: 394 1. The specific message type is known from the context. This may be 395 defined by a marker in the containing structure or by 396 restrictions specified by the application protocol. 398 2. The message type is identified by a CBOR tag. Messages with a 399 CBOR tag are known in this specification as tagged messages, 400 while those without the CBOR tag are known as untagged messages. 401 This document defines a CBOR tag for each of the message 402 structures. These tags can be found in Table 1. 404 3. When a COSE object is carried in a media type of 'application/ 405 cose', the optional parameter 'cose-type' can be used to identify 406 the embedded object. The parameter is OPTIONAL if the tagged 407 version of the structure is used. The parameter is REQUIRED if 408 the untagged version of the structure is used. The value to use 409 with the parameter for each of the structures can be found in 410 Table 1. 412 4. When a COSE object is carried as a CoAP payload, the CoAP 413 Content-Format Option can be used to identify the message 414 content. The CoAP Content-Format values can be found in Table 2. 415 The CBOR tag for the message structure is not required as each 416 security message is uniquely identified. 418 +-------+---------------+---------------+---------------------------+ 419 | CBOR | cose-type | Data Item | Semantics | 420 | Tag | | | | 421 +-------+---------------+---------------+---------------------------+ 422 | 98 | cose-sign | COSE_Sign | COSE Signed Data Object | 423 | 18 | cose-sign1 | COSE_Sign1 | COSE Single Signer Data | 424 | | | | Object | 425 | 96 | cose-encrypt | COSE_Encrypt | COSE Encrypted Data | 426 | | | | Object | 427 | 16 | cose-encrypt0 | COSE_Encrypt0 | COSE Single Recipient | 428 | | | | Encrypted Data Object | 429 | 97 | cose-mac | COSE_Mac | COSE MACed Data Object | 430 | 17 | cose-mac0 | COSE_Mac0 | COSE Mac w/o Recipients | 431 | | | | Object | 432 +-------+---------------+---------------+---------------------------+ 434 Table 1: COSE Message Identification 436 +--------------------------------------+----------+-----+-----------+ 437 | Media Type | Encoding | ID | Reference | 438 +--------------------------------------+----------+-----+-----------+ 439 | application/cose; cose-type="cose- | | 98 | [RFC8152] | 440 | sign" | | | | 441 | application/cose; cose-type="cose- | | 18 | [RFC8152] | 442 | sign1" | | | | 443 | application/cose; cose-type="cose- | | 96 | [RFC8152] | 444 | encrypt" | | | | 445 | application/cose; cose-type="cose- | | 16 | [RFC8152] | 446 | encrypt0" | | | | 447 | application/cose; cose-type="cose- | | 97 | [RFC8152] | 448 | mac" | | | | 449 | application/cose; cose-type="cose- | | 17 | [RFC8152] | 450 | mac0" | | | | 451 | application/cose-key | | 101 | [RFC8152] | 452 | application/cose-key-set | | 102 | [RFC8152] | 453 +--------------------------------------+----------+-----+-----------+ 455 Table 2: CoAP Content-Formats for COSE 457 The following CDDL fragment identifies all of the top messages 458 defined in this document. Separate non-terminals are defined for the 459 tagged and the untagged versions of the messages. 461 COSE_Messages = COSE_Untagged_Message / COSE_Tagged_Message 463 COSE_Untagged_Message = COSE_Sign / COSE_Sign1 / 464 COSE_Encrypt / COSE_Encrypt0 / 465 COSE_Mac / COSE_Mac0 467 COSE_Tagged_Message = COSE_Sign_Tagged / COSE_Sign1_Tagged / 468 COSE_Encrypt_Tagged / COSE_Encrypt0_Tagged / 469 COSE_Mac_Tagged / COSE_Mac0_Tagged 471 3. Header Parameters 473 The structure of COSE has been designed to have two buckets of 474 information that are not considered to be part of the payload itself, 475 but are used for holding information about content, algorithms, keys, 476 or evaluation hints for the processing of the layer. These two 477 buckets are available for use in all of the structures except for 478 keys. While these buckets are present, they may not all be usable in 479 all instances. For example, while the protected bucket is defined as 480 part of the recipient structure, some of the algorithms used for 481 recipient structures do not provide for authenticated data. If this 482 is the case, the protected bucket is left empty. 484 Both buckets are implemented as CBOR maps. The map key is a 'label' 485 (Section 1.4). The value portion is dependent on the definition for 486 the label. Both maps use the same set of label/value pairs. The 487 integer and string values for labels have been divided into several 488 sections including a standard range, a private range, and a range 489 that is dependent on the algorithm selected. The defined labels can 490 be found in the "COSE Header Parameters" IANA registry 491 (Section 15.2). 493 Two buckets are provided for each layer: 495 protected: Contains parameters about the current layer that are 496 cryptographically protected. This bucket MUST be empty if it is 497 not going to be included in a cryptographic computation. This 498 bucket is encoded in the message as a binary object. This value 499 is obtained by CBOR encoding the protected map and wrapping it in 500 a bstr object. Senders SHOULD encode a zero-length map as a zero- 501 length byte string rather than as a zero-length map (encoded as 502 h'a0'). The zero-length binary encoding is preferred because it 503 is both shorter and the version used in the serialization 504 structures for cryptographic computation. After encoding the map, 505 the value is wrapped in the binary object. Recipients MUST accept 506 both a zero-length binary value and a zero-length map encoded in 507 the binary value. The wrapping allows for the encoding of the 508 protected map to be transported with a greater chance that it will 509 not be altered in transit. (Badly behaved intermediates could 510 decode and re-encode, but this will result in a failure to verify 511 unless the re-encoded byte string is identical to the decoded byte 512 string.) This avoids the problem of all parties needing to be 513 able to do a common canonical encoding. 515 unprotected: Contains parameters about the current layer that are 516 not cryptographically protected. 518 Only parameters that deal with the current layer are to be placed at 519 that layer. As an example of this, the parameter 'content type' 520 describes the content of the message being carried in the message. 521 As such, this parameter is placed only in the content layer and is 522 not placed in the recipient or signature layers. In principle, one 523 should be able to process any given layer without reference to any 524 other layer. With the exception of the COSE_Sign structure, the only 525 data that needs to cross layers is the cryptographic key. 527 The buckets are present in all of the security objects defined in 528 this document. The fields in order are the 'protected' bucket (as a 529 CBOR 'bstr' type) and then the 'unprotected' bucket (as a CBOR 'map' 530 type). The presence of both buckets is required. The parameters 531 that go into the buckets come from the IANA "COSE Header Parameters" 532 registry (Section 15.2). Some common parameters are defined in the 533 next section, but a number of parameters are defined throughout this 534 document. 536 Labels in each of the maps MUST be unique. When processing messages, 537 if a label appears multiple times, the message MUST be rejected as 538 malformed. Applications SHOULD verify that the same label does not 539 occur in both the protected and unprotected headers. If the message 540 is not rejected as malformed, attributes MUST be obtained from the 541 protected bucket before they are obtained from the unprotected 542 bucket. 544 The following CDDL fragment represents the two header buckets. A 545 group "Headers" is defined in CDDL that represents the two buckets in 546 which attributes are placed. This group is used to provide these two 547 fields consistently in all locations. A type is also defined that 548 represents the map of common headers. 550 Headers = ( 551 protected : empty_or_serialized_map, 552 unprotected : header_map 553 ) 555 header_map = { 556 Generic_Headers, 557 * label => values 558 } 560 empty_or_serialized_map = bstr .cbor header_map / bstr .size 0 562 3.1. Common COSE Headers Parameters 564 This section defines a set of common header parameters. A summary of 565 these parameters can be found in Table 3. This table should be 566 consulted to determine the value of label and the type of the value. 568 The set of header parameters defined in this section are: 570 alg: This parameter is used to indicate the algorithm used for the 571 security processing. This parameter MUST be authenticated where 572 the ability to do so exists. This support is provided by AEAD 573 algorithms or construction (COSE_Sign, COSE_Sign0, COSE_Mac, and 574 COSE_Mac0). This authentication can be done either by placing the 575 parameter in the protected header bucket or as part of the 576 externally supplied data. The value is taken from the "COSE 577 Algorithms" registry (see [COSE.Algorithms]). 579 crit: The parameter is used to indicate which protected header 580 labels an application that is processing a message is required to 581 understand. Parameters defined in this document do not need to be 582 included as they should be understood by all implementations. 583 When present, this parameter MUST be placed in the protected 584 header bucket. The array MUST have at least one value in it. 585 Not all labels need to be included in the 'crit' parameter. The 586 rules for deciding which header labels are placed in the array 587 are: 589 * Integer labels in the range of 0 to 8 SHOULD be omitted. 591 * Integer labels in the range -1 to -128 can be omitted as they 592 are algorithm dependent. If an application can correctly 593 process an algorithm, it can be assumed that it will correctly 594 process all of the common parameters associated with that 595 algorithm. Integer labels in the range -129 to -65536 SHOULD 596 be included as these would be less common parameters that might 597 not be generally supported. 599 * Labels for parameters required for an application MAY be 600 omitted. Applications should have a statement if the label can 601 be omitted. 603 The header parameter values indicated by 'crit' can be processed 604 by either the security library code or an application using a 605 security library; the only requirement is that the parameter is 606 processed. If the 'crit' value list includes a value for which 607 the parameter is not in the protected bucket, this is a fatal 608 error in processing the message. 610 content type: This parameter is used to indicate the content type of 611 the data in the payload or ciphertext fields. Integers are from 612 the "CoAP Content-Formats" IANA registry table [COAP.Formats]. 613 Text values following the syntax of "/" 614 where and are defined in Section 4.2 of 615 [RFC6838]. Leading and trailing whitespace is also omitted. 616 Textual content values along with parameters and subparameters can 617 be located using the IANA "Media Types" registry. Applications 618 SHOULD provide this parameter if the content structure is 619 potentially ambiguous. 621 kid: This parameter identifies one piece of data that can be used as 622 input to find the needed cryptographic key. The value of this 623 parameter can be matched against the 'kid' member in a COSE_Key 624 structure. Other methods of key distribution can define an 625 equivalent field to be matched. Applications MUST NOT assume that 626 'kid' values are unique. There may be more than one key with the 627 same 'kid' value, so all of the keys associated with this 'kid' 628 may need to be checked. The internal structure of 'kid' values is 629 not defined and cannot be relied on by applications. Key 630 identifier values are hints about which key to use. This is not a 631 security-critical field. For this reason, it can be placed in the 632 unprotected headers bucket. 634 IV: This parameter holds the Initialization Vector (IV) value. For 635 some symmetric encryption algorithms, this may be referred to as a 636 nonce. The IV can be placed in the unprotected header as 637 modifying the IV will cause the decryption to yield plaintext that 638 is readily detectable as garbled. 640 Partial IV: This parameter holds a part of the IV value. When using 641 the COSE_Encrypt0 structure, a portion of the IV can be part of 642 the context associated with the key. This field is used to carry 643 a value that causes the IV to be changed for each message. The IV 644 can be placed in the unprotected header as modifying the IV will 645 cause the decryption to yield plaintext that is readily detectable 646 as garbled. The 'Initialization Vector' and 'Partial 647 Initialization Vector' parameters MUST NOT both be present in the 648 same security layer. 650 The message IV is generated by the following steps: 652 1. Left-pad the Partial IV with zeros to the length of IV. 654 2. XOR the padded Partial IV with the context IV. 656 counter signature: This parameter holds one or more counter 657 signature values. Counter signatures provide a method of having a 658 second party sign some data. The counter signature parameter can 659 occur as an unprotected attribute in any of the following 660 structures: COSE_Sign1, COSE_Signature, COSE_Encrypt, 661 COSE_recipient, COSE_Encrypt0, COSE_Mac, and COSE_Mac0. These 662 structures all have the same beginning elements, so that a 663 consistent calculation of the counter signature can be computed. 664 Details on computing counter signatures are found in Section 4.5. 666 +-----------+-------+----------------+-------------+----------------+ 667 | Name | Label | Value Type | Value | Description | 668 | | | | Registry | | 669 +-----------+-------+----------------+-------------+----------------+ 670 | alg | 1 | int / tstr | COSE | Cryptographic | 671 | | | | Algorithms | algorithm to | 672 | | | | registry | use | 673 | crit | 2 | [+ label] | COSE Header | Critical | 674 | | | | Parameters | headers to be | 675 | | | | registry | understood | 676 | content | 3 | tstr / uint | CoAP | Content type | 677 | type | | | Content- | of the payload | 678 | | | | Formats or | | 679 | | | | Media Types | | 680 | | | | registries | | 681 | kid | 4 | bstr | | Key identifier | 682 | IV | 5 | bstr | | Full | 683 | | | | | Initialization | 684 | | | | | Vector | 685 | Partial | 6 | bstr | | Partial | 686 | IV | | | | Initialization | 687 | | | | | Vector | 688 | counter | 7 | COSE_Signature | | CBOR-encoded | 689 | signature | | / [+ | | signature | 690 | | | COSE_Signature | | structure | 691 | | | ] | | | 692 +-----------+-------+----------------+-------------+----------------+ 694 Table 3: Common Header Parameters 696 The CDDL fragment that represents the set of headers defined in this 697 section is given below. Each of the headers is tagged as optional 698 because they do not need to be in every map; headers required in 699 specific maps are discussed above. 701 Generic_Headers = ( 702 ? 1 => int / tstr, ; algorithm identifier 703 ? 2 => [+label], ; criticality 704 ? 3 => tstr / int, ; content type 705 ? 4 => bstr, ; key identifier 706 ? 5 => bstr, ; IV 707 ? 6 => bstr, ; Partial IV 708 ? 7 => COSE_Signature / [+COSE_Signature] ; Counter signature 709 ) 711 4. Signing Objects 713 COSE supports two different signature structures. COSE_Sign allows 714 for one or more signatures to be applied to the same content. 715 COSE_Sign1 is restricted to a single signer. The structures cannot 716 be converted between each other; as the signature computation 717 includes a parameter identifying which structure is being used, the 718 converted structure will fail signature validation. 720 4.1. Signing with One or More Signers 722 The COSE_Sign structure allows for one or more signatures to be 723 applied to a message payload. Parameters relating to the content and 724 parameters relating to the signature are carried along with the 725 signature itself. These parameters may be authenticated by the 726 signature, or just present. An example of a parameter about the 727 content is the content type. Examples of parameters about the 728 signature would be the algorithm and key used to create the signature 729 and counter signatures. 731 RFC 5652 indicates that: 733 When more than one signature is present, the successful validation 734 of one signature associated with a given signer is usually treated 735 as a successful signature by that signer. However, there are some 736 application environments where other rules are needed. An 737 application that employs a rule other than one valid signature for 738 each signer must specify those rules. Also, where simple matching 739 of the signer identifier is not sufficient to determine whether 740 the signatures were generated by the same signer, the application 741 specification must describe how to determine which signatures were 742 generated by the same signer. Support for different communities 743 of recipients is the primary reason that signers choose to include 744 more than one signature. 746 For example, the COSE_Sign structure might include signatures 747 generated with the Edwards-curve Digital Signature Algorithm (EdDSA) 748 [RFC8032] and with the Elliptic Curve Digital Signature Algorithm 749 (ECDSA) [DSS]. This allows recipients to verify the signature 750 associated with one algorithm or the other. More-detailed 751 information on multiple signature evaluations can be found in 752 [RFC5752]. 754 The signature structure can be encoded as either tagged or untagged 755 depending on the context it will be used in. A tagged COSE_Sign 756 structure is identified by the CBOR tag 98. The CDDL fragment that 757 represents this is: 759 COSE_Sign_Tagged = #6.98(COSE_Sign) 761 A COSE Signed Message is defined in two parts. The CBOR object that 762 carries the body and information about the body is called the 763 COSE_Sign structure. The CBOR object that carries the signature and 764 information about the signature is called the COSE_Signature 765 structure. Examples of COSE Signed Messages can be found in 766 Appendix C.1. 768 The COSE_Sign structure is a CBOR array. The fields of the array in 769 order are: 771 protected: This is as described in Section 3. 773 unprotected: This is as described in Section 3. 775 payload: This field contains the serialized content to be signed. 776 If the payload is not present in the message, the application is 777 required to supply the payload separately. The payload is wrapped 778 in a bstr to ensure that it is transported without changes. If 779 the payload is transported separately ("detached content"), then a 780 nil CBOR object is placed in this location, and it is the 781 responsibility of the application to ensure that it will be 782 transported without changes. 784 Note: When a signature with a message recovery algorithm is used 785 (Section 8), the maximum number of bytes that can be recovered is 786 the length of the payload. The size of the payload is reduced by 787 the number of bytes that will be recovered. If all of the bytes 788 of the payload are consumed, then the payload is encoded as a 789 zero-length binary string rather than as being absent. 791 signatures: This field is an array of signatures. Each signature is 792 represented as a COSE_Signature structure. 794 The CDDL fragment that represents the above text for COSE_Sign 795 follows. 797 COSE_Sign = [ 798 Headers, 799 payload : bstr / nil, 800 signatures : [+ COSE_Signature] 801 ] 803 The COSE_Signature structure is a CBOR array. The fields of the 804 array in order are: 806 protected: This is as described in Section 3. 808 unprotected: This is as described in Section 3. 810 signature: This field contains the computed signature value. The 811 type of the field is a bstr. Algorithms MUST specify padding if 812 the signature value is not a multiple of 8 bits. 814 The CDDL fragment that represents the above text for COSE_Signature 815 follows. 817 COSE_Signature = [ 818 Headers, 819 signature : bstr 820 ] 822 4.2. Signing with One Signer 824 The COSE_Sign1 signature structure is used when only one signature is 825 going to be placed on a message. The parameters dealing with the 826 content and the signature are placed in the same pair of buckets 827 rather than having the separation of COSE_Sign. 829 The structure can be encoded as either tagged or untagged depending 830 on the context it will be used in. A tagged COSE_Sign1 structure is 831 identified by the CBOR tag 18. The CDDL fragment that represents 832 this is: 834 COSE_Sign1_Tagged = #6.18(COSE_Sign1) 836 The CBOR object that carries the body, the signature, and the 837 information about the body and signature is called the COSE_Sign1 838 structure. Examples of COSE_Sign1 messages can be found in 839 Appendix C.2. 841 The COSE_Sign1 structure is a CBOR array. The fields of the array in 842 order are: 844 protected: This is as described in Section 3. 846 unprotected: This is as described in Section 3. 848 payload: This is as described in Section 4.1. 850 signature: This field contains the computed signature value. The 851 type of the field is a bstr. 853 The CDDL fragment that represents the above text for COSE_Sign1 854 follows. 856 COSE_Sign1 = [ 857 Headers, 858 payload : bstr / nil, 859 signature : bstr 860 ] 862 4.3. Externally Supplied Data 864 One of the features offered in the COSE document is the ability for 865 applications to provide additional data to be authenticated, but that 866 is not carried as part of the COSE object. The primary reason for 867 supporting this can be seen by looking at the CoAP message structure 868 [RFC7252], where the facility exists for options to be carried before 869 the payload. Examples of data that can be placed in this location 870 would be the CoAP code or CoAP options. If the data is in the header 871 section, then it is available for proxies to help in performing its 872 operations. For example, the Accept Option can be used by a proxy to 873 determine if an appropriate value is in the proxy's cache. But the 874 sender can cause a failure at the server if a proxy, or an attacker, 875 changes the set of accept values by including the field in the 876 application supplied data. 878 This document describes the process for using a byte array of 879 externally supplied authenticated data; the method of constructing 880 the byte array is a function of the application. Applications that 881 use this feature need to define how the externally supplied 882 authenticated data is to be constructed. Such a construction needs 883 to take into account the following issues: 885 o If multiple items are included, applications need to ensure that 886 the same byte string cannot produced if there are different 887 inputs. This could occur by appending the strings 'AB' and 'CDE' 888 or by appending the strings 'ABC' and 'DE'. This is usually 889 addressed by making fields a fixed width and/or encoding the 890 length of the field as part of the output. Using options from 891 CoAP [RFC7252] as an example, these fields use a TLV structure so 892 they can be concatenated without any problems. 894 o If multiple items are included, an order for the items needs to be 895 defined. Using options from CoAP as an example, an application 896 could state that the fields are to be ordered by the option 897 number. 899 o Applications need to ensure that the byte string is going to be 900 the same on both sides. Using options from CoAP might give a 901 problem if the same relative numbering is kept. An intermediate 902 node could insert or remove an option, changing how the relative 903 number is done. An application would need to specify that the 904 relative number must be re-encoded to be relative only to the 905 options that are in the external data. 907 4.4. Signing and Verification Process 909 In order to create a signature, a well-defined byte string is needed. 910 The Sig_struture is used to create the canonical form. This signing 911 and verification process takes in the body information (COSE_Sign or 912 COSE_Sign1), the signer information (COSE_Signature), and the 913 application data (external source). A Sig_structure is a CBOR array. 914 The fields of the Sig_struture in order are: 916 1. A text string identifying the context of the signature. The 917 context string is: 919 "Signature" for signatures using the COSE_Signature structure. 921 "Signature1" for signatures using the COSE_Sign1 structure. 923 "CounterSignature" for signatures used as counter signature 924 attributes. 926 2. The protected attributes from the body structure encoded in a 927 bstr type. If there are no protected attributes, a bstr of 928 length zero is used. 930 3. The protected attributes from the signer structure encoded in a 931 bstr type. If there are no protected attributes, a bstr of 932 length zero is used. This field is omitted for the COSE_Sign1 933 signature structure. 935 4. The protected attributes from the application encoded in a bstr 936 type. If this field is not supplied, it defaults to a zero- 937 length binary string. (See Section 4.3 for application guidance 938 on constructing this field.) 940 5. The payload to be signed encoded in a bstr type. The payload is 941 placed here independent of how it is transported. 943 The CDDL fragment that describes the above text is: 945 Sig_structure = [ 946 context : "Signature" / "Signature1" / "CounterSignature", 947 body_protected : empty_or_serialized_map, 948 ? sign_protected : empty_or_serialized_map, 949 external_aad : bstr, 950 payload : bstr 951 ] 952 How to compute a signature: 954 1. Create a Sig_structure and populate it with the appropriate 955 fields. 957 2. Create the value ToBeSigned by encoding the Sig_structure to a 958 byte string, using the encoding described in Section 13. 960 3. Call the signature creation algorithm passing in K (the key to 961 sign with), alg (the algorithm to sign with), and ToBeSigned (the 962 value to sign). 964 4. Place the resulting signature value in the 'signature' field of 965 the array. 967 The steps for verifying a signature are: 969 1. Create a Sig_structure object and populate it with the 970 appropriate fields. 972 2. Create the value ToBeSigned by encoding the Sig_structure to a 973 byte string, using the encoding described in Section 13. 975 3. Call the signature verification algorithm passing in K (the key 976 to verify with), alg (the algorithm used sign with), ToBeSigned 977 (the value to sign), and sig (the signature to be verified). 979 In addition to performing the signature verification, the application 980 performs the appropriate checks to ensure that the key is correctly 981 paired with the signing identity and that the signing identity is 982 authorized before performing actions. 984 4.5. Computing Counter Signatures 986 Counter signatures provide a method of associating a different 987 signature generated by different signers with some piece of content. 988 This is normally used to provide a signature on a signature allowing 989 for a proof that a signature existed at a given time (e.g., a 990 Timestamp). In this document, we allow for counter signatures to 991 exist in a greater number of environments. As an example, it is 992 possible to place a counter signature in the unprotected attributes 993 of a COSE_Encrypt object. This would allow for an intermediary to 994 either verify that the encrypted byte string has not been modified, 995 without being able to decrypt it, or assert that an encrypted byte 996 string either existed at a given time or passed through it in terms 997 of routing (e.g., a proxy signature). 999 An example of a counter signature on a signature can be found in 1000 Appendix C.1.3. An example of a counter signature in an encryption 1001 object can be found in Appendix C.3.3. 1003 The creation and validation of counter signatures over the different 1004 items relies on the fact that the objects have the same structure. 1005 The elements are a set of protected attributes, a set of unprotected 1006 attributes, and a body, in that order. This means that the 1007 Sig_structure can be used in a uniform manner to get the byte string 1008 for processing a signature. If the counter signature is going to be 1009 computed over a COSE_Encrypt structure, the body_protected and 1010 payload items can be mapped into the Sig_structure in the same manner 1011 as from the COSE_Sign structure. 1013 It should be noted that only a signature algorithm with appendix (see 1014 Section 8) can be used for counter signatures. This is because the 1015 body should be able to be processed without having to evaluate the 1016 counter signature, and this is not possible for signature schemes 1017 with message recovery. 1019 5. Encryption Objects 1021 COSE supports two different encryption structures. COSE_Encrypt0 is 1022 used when a recipient structure is not needed because the key to be 1023 used is known implicitly. COSE_Encrypt is used the rest of the time. 1024 This includes cases where there are multiple recipients or a 1025 recipient algorithm other than direct (i.e. pre-shared secret) is 1026 used. 1028 5.1. Enveloped COSE Structure 1030 The enveloped structure allows for one or more recipients of a 1031 message. There are provisions for parameters about the content and 1032 parameters about the recipient information to be carried in the 1033 message. The protected parameters associated with the content are 1034 authenticated by the content encryption algorithm. The protected 1035 parameters associated with the recipient are authenticated by the 1036 recipient algorithm (when the algorithm supports it). Examples of 1037 parameters about the content are the type of the content and the 1038 content encryption algorithm. Examples of parameters about the 1039 recipient are the recipient's key identifier and the recipient's 1040 encryption algorithm. 1042 The same techniques and nearly the same structure is used for 1043 encrypting both the plaintext and the keys. This is different from 1044 the approach used by both "Cryptographic Message Syntax (CMS)" 1045 [RFC5652] and "JSON Web Encryption (JWE)" [RFC7516] where different 1046 structures are used for the content layer and for the recipient 1047 layer. Two structures are defined: COSE_Encrypt to hold the 1048 encrypted content and COSE_recipient to hold the encrypted keys for 1049 recipients. Examples of encrypted messages can be found in 1050 Appendix C.3. 1052 The COSE_Encrypt structure can be encoded as either tagged or 1053 untagged depending on the context it will be used in. A tagged 1054 COSE_Encrypt structure is identified by the CBOR tag 96. The CDDL 1055 fragment that represents this is: 1057 COSE_Encrypt_Tagged = #6.96(COSE_Encrypt) 1059 The COSE_Encrypt structure is a CBOR array. The fields of the array 1060 in order are: 1062 protected: This is as described in Section 3. 1064 unprotected: This is as described in Section 3. 1066 ciphertext: This field contains the ciphertext encoded as a bstr. 1067 If the ciphertext is to be transported independently of the 1068 control information about the encryption process (i.e., detached 1069 content), then the field is encoded as a nil value. 1071 recipients: This field contains an array of recipient information 1072 structures. The type for the recipient information structure is a 1073 COSE_recipient. 1075 The CDDL fragment that corresponds to the above text is: 1077 COSE_Encrypt = [ 1078 Headers, 1079 ciphertext : bstr / nil, 1080 recipients : [+COSE_recipient] 1081 ] 1083 The COSE_recipient structure is a CBOR array. The fields of the 1084 array in order are: 1086 protected: This is as described in Section 3. 1088 unprotected: This is as described in Section 3. 1090 ciphertext: This field contains the encrypted key encoded as a bstr. 1091 All encoded keys are symmetric keys; the binary value of the key 1092 is the content. If there is not an encrypted key, then this field 1093 is encoded as a nil value. 1095 recipients: This field contains an array of recipient information 1096 structures. The type for the recipient information structure is a 1097 COSE_recipient (an example of this can be found in Appendix B). 1098 If there are no recipient information structures, this element is 1099 absent. 1101 The CDDL fragment that corresponds to the above text for 1102 COSE_recipient is: 1104 COSE_recipient = [ 1105 Headers, 1106 ciphertext : bstr / nil, 1107 ? recipients : [+COSE_recipient] 1108 ] 1110 5.1.1. Content Key Distribution Methods 1112 An encrypted message consists of an encrypted content and an 1113 encrypted CEK for one or more recipients. The CEK is encrypted for 1114 each recipient, using a key specific to that recipient. The details 1115 of this encryption depend on which class the recipient algorithm 1116 falls into. Specific details on each of the classes can be found in 1117 Section 12. A short summary of the five content key distribution 1118 methods is: 1120 direct: The CEK is the same as the identified previously distributed 1121 symmetric key or is derived from a previously distributed secret. 1122 No CEK is transported in the message. 1124 symmetric key-encryption keys (KEK): The CEK is encrypted using a 1125 previously distributed symmetric KEK. Also known as key wrap. 1127 key agreement: The recipient's public key and a sender's private key 1128 are used to generate a pairwise secret, a Key Derivation Function 1129 (KDF) is applied to derive a key, and then the CEK is either the 1130 derived key or encrypted by the derived key. 1132 key transport: The CEK is encrypted with the recipient's public key. 1133 No key transport algorithms are defined in this document. 1135 passwords: The CEK is encrypted in a KEK that is derived from a 1136 password. No password algorithms are defined in this document. 1138 5.2. Single Recipient Encrypted 1140 The COSE_Encrypt0 encrypted structure does not have the ability to 1141 specify recipients of the message. The structure assumes that the 1142 recipient of the object will already know the identity of the key to 1143 be used in order to decrypt the message. If a key needs to be 1144 identified to the recipient, the enveloped structure ought to be 1145 used. 1147 Examples of encrypted messages can be found in Appendix C.3. 1149 The COSE_Encrypt0 structure can be encoded as either tagged or 1150 untagged depending on the context it will be used in. A tagged 1151 COSE_Encrypt0 structure is identified by the CBOR tag 16. The CDDL 1152 fragment that represents this is: 1154 COSE_Encrypt0_Tagged = #6.16(COSE_Encrypt0) 1156 The COSE_Encrypt0 structure is a CBOR array. The fields of the array 1157 in order are: 1159 protected: This is as described in Section 3. 1161 unprotected: This is as described in Section 3. 1163 ciphertext: This is as described in Section 5.1. 1165 The CDDL fragment for COSE_Encrypt0 that corresponds to the above 1166 text is: 1168 COSE_Encrypt0 = [ 1169 Headers, 1170 ciphertext : bstr / nil, 1171 ] 1173 5.3. How to Encrypt and Decrypt for AEAD Algorithms 1175 The encryption algorithm for AEAD algorithms is fairly simple. The 1176 first step is to create a consistent byte string for the 1177 authenticated data structure. For this purpose, we use an 1178 Enc_structure. The Enc_structure is a CBOR array. The fields of the 1179 Enc_structure in order are: 1181 1. A text string identifying the context of the authenticated data 1182 structure. The context string is: 1184 "Encrypt0" for the content encryption of a COSE_Encrypt0 data 1185 structure. 1187 "Encrypt" for the first layer of a COSE_Encrypt data structure 1188 (i.e., for content encryption). 1190 "Enc_Recipient" for a recipient encoding to be placed in an 1191 COSE_Encrypt data structure. 1193 "Mac_Recipient" for a recipient encoding to be placed in a 1194 MACed message structure. 1196 "Rec_Recipient" for a recipient encoding to be placed in a 1197 recipient structure. 1199 2. The protected attributes from the body structure encoded in a 1200 bstr type. If there are no protected attributes, a bstr of 1201 length zero is used. 1203 3. The protected attributes from the application encoded in a bstr 1204 type. If this field is not supplied, it defaults to a zero- 1205 length bstr. (See Section 4.3 for application guidance on 1206 constructing this field.) 1208 The CDDL fragment that describes the above text is: 1210 Enc_structure = [ 1211 context : "Encrypt" / "Encrypt0" / "Enc_Recipient" / 1212 "Mac_Recipient" / "Rec_Recipient", 1213 protected : empty_or_serialized_map, 1214 external_aad : bstr 1215 ] 1217 How to encrypt a message: 1219 1. Create an Enc_structure and populate it with the appropriate 1220 fields. 1222 2. Encode the Enc_structure to a byte string (Additional 1223 Authenticated Data (AAD)), using the encoding described in 1224 Section 13. 1226 3. Determine the encryption key (K). This step is dependent on the 1227 class of recipient algorithm being used. For: 1229 No Recipients: The key to be used is determined by the algorithm 1230 and key at the current layer. Examples are key transport keys 1231 (Section 12.3), key wrap keys (Section 12.2), or pre-shared 1232 secrets. 1234 Direct Encryption and Direct Key Agreement: The key is 1235 determined by the key and algorithm in the recipient 1236 structure. The encryption algorithm and size of the key to be 1237 used are inputs into the KDF used for the recipient. (For 1238 direct, the KDF can be thought of as the identity operation.) 1239 Examples of these algorithms are found in Sections !!! DIRECT- 1240 KDF !!! and !!! ECDH !!! of 1241 [I-D.schaad-cose-rfc8152bis-algs]. 1243 Other: The key is randomly or pseudorandomly generated. 1245 4. Call the encryption algorithm with K (the encryption key), P (the 1246 plaintext), and AAD. Place the returned ciphertext into the 1247 'ciphertext' field of the structure. 1249 5. For recipients of the message, recursively perform the encryption 1250 algorithm for that recipient, using K (the encryption key) as the 1251 plaintext. 1253 How to decrypt a message: 1255 1. Create an Enc_structure and populate it with the appropriate 1256 fields. 1258 2. Encode the Enc_structure to a byte string (AAD), using the 1259 encoding described in Section 13. 1261 3. Determine the decryption key. This step is dependent on the 1262 class of recipient algorithm being used. For: 1264 No Recipients: The key to be used is determined by the algorithm 1265 and key at the current layer. Examples are key transport keys 1266 (Section 12.3), key wrap keys (Section 12.2), or pre-shared 1267 secrets. 1269 Direct Encryption and Direct Key Agreement: The key is 1270 determined by the key and algorithm in the recipient 1271 structure. The encryption algorithm and size of the key to be 1272 used are inputs into the KDF used for the recipient. (For 1273 direct, the KDF can be thought of as the identity operation.) 1275 Other: The key is determined by decoding and decrypting one of 1276 the recipient structures. 1278 4. Call the decryption algorithm with K (the decryption key to use), 1279 C (the ciphertext), and AAD. 1281 5.4. How to Encrypt and Decrypt for AE Algorithms 1283 How to encrypt a message: 1285 1. Verify that the 'protected' field is empty. 1287 2. Verify that there was no external additional authenticated data 1288 supplied for this operation. 1290 3. Determine the encryption key. This step is dependent on the 1291 class of recipient algorithm being used. For: 1293 No Recipients: The key to be used is determined by the algorithm 1294 and key at the current layer. Examples are key transport keys 1295 (Section 12.3), key wrap keys (Section 12.2), or pre-shared 1296 secrets. 1298 Direct Encryption and Direct Key Agreement: The key is 1299 determined by the key and algorithm in the recipient 1300 structure. The encryption algorithm and size of the key to be 1301 used are inputs into the KDF used for the recipient. (For 1302 direct, the KDF can be thought of as the identity operation.) 1303 Examples of these algorithms are found in Sections !!!DIRECT- 1304 KDF!!! and !!! ECDH !!! . 1306 Other: The key is randomly generated. 1308 4. Call the encryption algorithm with K (the encryption key to use) 1309 and P (the plaintext). Place the returned ciphertext into the 1310 'ciphertext' field of the structure. 1312 5. For recipients of the message, recursively perform the encryption 1313 algorithm for that recipient, using K (the encryption key) as the 1314 plaintext. 1316 How to decrypt a message: 1318 1. Verify that the 'protected' field is empty. 1320 2. Verify that there was no external additional authenticated data 1321 supplied for this operation. 1323 3. Determine the decryption key. This step is dependent on the 1324 class of recipient algorithm being used. For: 1326 No Recipients: The key to be used is determined by the algorithm 1327 and key at the current layer. Examples are key transport keys 1328 (Section 12.3), key wrap keys (Section 12.2), or pre-shared 1329 secrets. 1331 Direct Encryption and Direct Key Agreement: The key is 1332 determined by the key and algorithm in the recipient 1333 structure. The encryption algorithm and size of the key to be 1334 used are inputs into the KDF used for the recipient. (For 1335 direct, the KDF can be thought of as the identity operation.) 1336 Examples of these algorithms are found in Sections !!! DIRECT- 1337 KDF !!! and !!! ECDH !!! . 1339 Other: The key is determined by decoding and decrypting one of 1340 the recipient structures. 1342 4. Call the decryption algorithm with K (the decryption key to use) 1343 and C (the ciphertext). 1345 6. MAC Objects 1347 COSE supports two different MAC structures. COSE_MAC0 is used when a 1348 recipient structure is not needed because the key to be used is 1349 implicitly known. COSE_MAC is used for all other cases. These 1350 include a requirement for multiple recipients, the key being unknown, 1351 and a recipient algorithm of other than direct. 1353 In this section, we describe the structure and methods to be used 1354 when doing MAC authentication in COSE. This document allows for the 1355 use of all of the same classes of recipient algorithms as are allowed 1356 for encryption. 1358 When using MAC operations, there are two modes in which they can be 1359 used. The first is just a check that the content has not been 1360 changed since the MAC was computed. Any class of recipient algorithm 1361 can be used for this purpose. The second mode is to both check that 1362 the content has not been changed since the MAC was computed and to 1363 use the recipient algorithm to verify who sent it. The classes of 1364 recipient algorithms that support this are those that use a pre- 1365 shared secret or do static-static (SS) key agreement (without the key 1366 wrap step). In both of these cases, the entity that created and sent 1367 the message MAC can be validated. (This knowledge of the sender 1368 assumes that there are only two parties involved and that you did not 1369 send the message to yourself.) The origination property can be 1370 obtained with both of the MAC message structures. 1372 6.1. MACed Message with Recipients 1374 The multiple recipient MACed message uses two structures: the 1375 COSE_Mac structure defined in this section for carrying the body and 1376 the COSE_recipient structure (Section 5.1) to hold the key used for 1377 the MAC computation. Examples of MACed messages can be found in 1378 Appendix C.5. 1380 The MAC structure can be encoded as either tagged or untagged 1381 depending on the context it will be used in. A tagged COSE_Mac 1382 structure is identified by the CBOR tag 97. The CDDL fragment that 1383 represents this is: 1385 COSE_Mac_Tagged = #6.97(COSE_Mac) 1387 The COSE_Mac structure is a CBOR array. The fields of the array in 1388 order are: 1390 protected: This is as described in Section 3. 1392 unprotected: This is as described in Section 3. 1394 payload: This field contains the serialized content to be MACed. If 1395 the payload is not present in the message, the application is 1396 required to supply the payload separately. The payload is wrapped 1397 in a bstr to ensure that it is transported without changes. If 1398 the payload is transported separately (i.e., detached content), 1399 then a nil CBOR value is placed in this location, and it is the 1400 responsibility of the application to ensure that it will be 1401 transported without changes. 1403 tag: This field contains the MAC value. 1405 recipients: This is as described in Section 5.1. 1407 The CDDL fragment that represents the above text for COSE_Mac 1408 follows. 1410 COSE_Mac = [ 1411 Headers, 1412 payload : bstr / nil, 1413 tag : bstr, 1414 recipients :[+COSE_recipient] 1415 ] 1417 6.2. MACed Messages with Implicit Key 1419 In this section, we describe the structure and methods to be used 1420 when doing MAC authentication for those cases where the recipient is 1421 implicitly known. 1423 The MACed message uses the COSE_Mac0 structure defined in this 1424 section for carrying the body. Examples of MACed messages with an 1425 implicit key can be found in Appendix C.6. 1427 The MAC structure can be encoded as either tagged or untagged 1428 depending on the context it will be used in. A tagged COSE_Mac0 1429 structure is identified by the CBOR tag 17. The CDDL fragment that 1430 represents this is: 1432 COSE_Mac0_Tagged = #6.17(COSE_Mac0) 1434 The COSE_Mac0 structure is a CBOR array. The fields of the array in 1435 order are: 1437 protected: This is as described in Section 3. 1439 unprotected: This is as described in Section 3. 1441 payload: This is as described in Section 6.1. 1443 tag: This field contains the MAC value. 1445 The CDDL fragment that corresponds to the above text is: 1447 COSE_Mac0 = [ 1448 Headers, 1449 payload : bstr / nil, 1450 tag : bstr, 1451 ] 1453 6.3. How to Compute and Verify a MAC 1455 In order to get a consistent encoding of the data to be 1456 authenticated, the MAC_structure is used to have a canonical form. 1457 The MAC_structure is a CBOR array. The fields of the MAC_structure 1458 in order are: 1460 1. A text string that identifies the structure that is being 1461 encoded. This string is "MAC" for the COSE_Mac structure. This 1462 string is "MAC0" for the COSE_Mac0 structure. 1464 2. The protected attributes from the COSE_MAC structure. If there 1465 are no protected attributes, a zero-length bstr is used. 1467 3. The protected attributes from the application encoded as a bstr 1468 type. If this field is not supplied, it defaults to a zero- 1469 length binary string. (See Section 4.3 for application guidance 1470 on constructing this field.) 1472 4. The payload to be MACed encoded in a bstr type. The payload is 1473 placed here independent of how it is transported. 1475 The CDDL fragment that corresponds to the above text is: 1477 MAC_structure = [ 1478 context : "MAC" / "MAC0", 1479 protected : empty_or_serialized_map, 1480 external_aad : bstr, 1481 payload : bstr 1482 ] 1484 The steps to compute a MAC are: 1486 1. Create a MAC_structure and populate it with the appropriate 1487 fields. 1489 2. Create the value ToBeMaced by encoding the MAC_structure to a 1490 byte string, using the encoding described in Section 13. 1492 3. Call the MAC creation algorithm passing in K (the key to use), 1493 alg (the algorithm to MAC with), and ToBeMaced (the value to 1494 compute the MAC on). 1496 4. Place the resulting MAC in the 'tag' field of the COSE_Mac or 1497 COSE_Mac0 structure. 1499 5. For COSE_Mac structures, encrypt and encode the MAC key for each 1500 recipient of the message. 1502 The steps to verify a MAC are: 1504 1. Create a MAC_structure object and populate it with the 1505 appropriate fields. 1507 2. Create the value ToBeMaced by encoding the MAC_structure to a 1508 byte string, using the encoding described in Section 13. 1510 3. For COSE_Mac structures, obtain the cryptographic key from one of 1511 the recipients of the message. 1513 4. Call the MAC creation algorithm passing in K (the key to use), 1514 alg (the algorithm to MAC with), and ToBeMaced (the value to 1515 compute the MAC on). 1517 5. Compare the MAC value to the 'tag' field of the COSE_Mac or 1518 COSE_Mac0 structure. 1520 7. Key Objects 1522 A COSE Key structure is built on a CBOR map object. The set of 1523 common parameters that can appear in a COSE Key can be found in the 1524 IANA "COSE Key Common Parameters" registry (Section 15.4). 1526 Additional parameters defined for specific key types can be found in 1527 the IANA "COSE Key Type Parameters" registry ([COSE.KeyParameters]). 1529 A COSE Key Set uses a CBOR array object as its underlying type. The 1530 values of the array elements are COSE Keys. A COSE Key Set MUST have 1531 at least one element in the array. Examples of COSE Key Sets can be 1532 found in Appendix C.7. 1534 Each element in a COSE Key Set MUST be processed independently. If 1535 one element in a COSE Key Set is either malformed or uses a key that 1536 is not understood by an application, that key is ignored and the 1537 other keys are processed normally. 1539 The element "kty" is a required element in a COSE_Key map. 1541 The CDDL grammar describing COSE_Key and COSE_KeySet is: 1543 COSE_Key = { 1544 1 => tstr / int, ; kty 1545 ? 2 => bstr, ; kid 1546 ? 3 => tstr / int, ; alg 1547 ? 4 => [+ (tstr / int) ], ; key_ops 1548 ? 5 => bstr, ; Base IV 1549 * label => values 1550 } 1552 COSE_KeySet = [+COSE_Key] 1554 7.1. COSE Key Common Parameters 1556 This document defines a set of common parameters for a COSE Key 1557 object. Table 4 provides a summary of the parameters defined in this 1558 section. There are also parameters that are defined for specific key 1559 types. Key-type-specific parameters can be found in 1560 [I-D.schaad-cose-rfc8152bis-algs]. 1562 +---------+-------+----------------+------------+-------------------+ 1563 | Name | Label | CBOR Type | Value | Description | 1564 | | | | Registry | | 1565 +---------+-------+----------------+------------+-------------------+ 1566 | kty | 1 | tstr / int | COSE Key | Identification of | 1567 | | | | Types | the key type | 1568 | | | | | | 1569 | kid | 2 | bstr | | Key | 1570 | | | | | identification | 1571 | | | | | value -- match to | 1572 | | | | | kid in message | 1573 | | | | | | 1574 | alg | 3 | tstr / int | COSE | Key usage | 1575 | | | | Algorithms | restriction to | 1576 | | | | | this algorithm | 1577 | | | | | | 1578 | key_ops | 4 | [+ (tstr/int)] | | Restrict set of | 1579 | | | | | permissible | 1580 | | | | | operations | 1581 | | | | | | 1582 | Base IV | 5 | bstr | | Base IV to be | 1583 | | | | | xor-ed with | 1584 | | | | | Partial IVs | 1585 +---------+-------+----------------+------------+-------------------+ 1587 Table 4: Key Map Labels 1589 kty: This parameter is used to identify the family of keys for this 1590 structure and, thus, the set of key-type-specific parameters to be 1591 found. The set of values defined in this document can be found in 1592 [COSE.KeyTypes]. This parameter MUST be present in a key object. 1593 Implementations MUST verify that the key type is appropriate for 1594 the algorithm being processed. The key type MUST be included as 1595 part of the trust decision process. 1597 alg: This parameter is used to restrict the algorithm that is used 1598 with the key. If this parameter is present in the key structure, 1599 the application MUST verify that this algorithm matches the 1600 algorithm for which the key is being used. If the algorithms do 1601 not match, then this key object MUST NOT be used to perform the 1602 cryptographic operation. Note that the same key can be in a 1603 different key structure with a different or no algorithm 1604 specified; however, this is considered to be a poor security 1605 practice. 1607 kid: This parameter is used to give an identifier for a key. The 1608 identifier is not structured and can be anything from a user- 1609 provided string to a value computed on the public portion of the 1610 key. This field is intended for matching against a 'kid' 1611 parameter in a message in order to filter down the set of keys 1612 that need to be checked. 1614 key_ops: This parameter is defined to restrict the set of operations 1615 that a key is to be used for. The value of the field is an array 1616 of values from Table 5. Algorithms define the values of key ops 1617 that are permitted to appear and are required for specific 1618 operations. The set of values matches that in [RFC7517] and 1619 [W3C.WebCrypto]. 1621 Base IV: This parameter is defined to carry the base portion of an 1622 IV. It is designed to be used with the Partial IV header 1623 parameter defined in Section 3.1. This field provides the ability 1624 to associate a Partial IV with a key that is then modified on a 1625 per message basis with the Partial IV. 1627 Extreme care needs to be taken when using a Base IV in an 1628 application. Many encryption algorithms lose security if the same 1629 IV is used twice. 1631 If different keys are derived for each sender, using the same Base 1632 IV with Partial IVs starting at zero is likely to ensure that the 1633 IV would not be used twice for a single key. If different keys 1634 are derived for each sender, starting at the same Base IV is 1635 likely to satisfy this condition. If the same key is used for 1636 multiple senders, then the application needs to provide for a 1637 method of dividing the IV space up between the senders. This 1638 could be done by providing a different base point to start from or 1639 a different Partial IV to start with and restricting the number of 1640 messages to be sent before rekeying. 1642 +---------+-------+-------------------------------------------------+ 1643 | Name | Value | Description | 1644 +---------+-------+-------------------------------------------------+ 1645 | sign | 1 | The key is used to create signatures. Requires | 1646 | | | private key fields. | 1647 | verify | 2 | The key is used for verification of signatures. | 1648 | encrypt | 3 | The key is used for key transport encryption. | 1649 | decrypt | 4 | The key is used for key transport decryption. | 1650 | | | Requires private key fields. | 1651 | wrap | 5 | The key is used for key wrap encryption. | 1652 | key | | | 1653 | unwrap | 6 | The key is used for key wrap decryption. | 1654 | key | | Requires private key fields. | 1655 | derive | 7 | The key is used for deriving keys. Requires | 1656 | key | | private key fields. | 1657 | derive | 8 | The key is used for deriving bits not to be | 1658 | bits | | used as a key. Requires private key fields. | 1659 | MAC | 9 | The key is used for creating MACs. | 1660 | create | | | 1661 | MAC | 10 | The key is used for validating MACs. | 1662 | verify | | | 1663 +---------+-------+-------------------------------------------------+ 1665 Table 5: Key Operation Values 1667 8. Signature Algorithms 1669 There are two signature algorithm schemes. The first is signature 1670 with appendix. In this scheme, the message content is processed and 1671 a signature is produced; the signature is called the appendix. This 1672 is the scheme used by algorithms such as ECDSA and the RSA 1673 Probabilistic Signature Scheme (RSASSA-PSS). (In fact, the SSA in 1674 RSASSA-PSS stands for Signature Scheme with Appendix.) 1676 The signature functions for this scheme are: 1678 signature = Sign(message content, key) 1680 valid = Verification(message content, key, signature) 1682 The second scheme is signature with message recovery (an example of 1683 such an algorithm is [PVSig]). In this scheme, the message content 1684 is processed, but part of it is included in the signature. Moving 1685 bytes of the message content into the signature allows for smaller 1686 signatures; the signature size is still potentially large, but the 1687 message content has shrunk. This has implications for systems 1688 implementing these algorithms and for applications that use them. 1689 The first is that the message content is not fully available until 1690 after a signature has been validated. Until that point, the part of 1691 the message contained inside of the signature is unrecoverable. The 1692 second is that the security analysis of the strength of the signature 1693 is very much based on the structure of the message content. Messages 1694 that are highly predictable require additional randomness to be 1695 supplied as part of the signature process. In the worst case, it 1696 becomes the same as doing a signature with appendix. Finally, in the 1697 event that multiple signatures are applied to a message, all of the 1698 signature algorithms are going to be required to consume the same 1699 number of bytes of message content. This means that the mixing of 1700 the different schemes in a single message is not supported, and if a 1701 recovery signature scheme is used, then the same amount of content 1702 needs to be consumed by all of the signatures. 1704 The signature functions for this scheme are: 1706 signature, message sent = Sign(message content, key) 1708 valid, message content = Verification(message sent, key, signature) 1710 Signature algorithms are used with the COSE_Signature and COSE_Sign1 1711 structures. At this time, only signatures with appendixes are 1712 defined for use with COSE; however, considerable interest has been 1713 expressed in using a signature with message recovery algorithm due to 1714 the effective size reduction that is possible. Implementations will 1715 need to keep this in mind for later possible integration. 1717 9. Message Authentication Code (MAC) Algorithms 1719 Message Authentication Codes (MACs) provide data authentication and 1720 integrity protection. They provide either no or very limited data 1721 origination. A MAC, for example, cannot be used to prove the 1722 identity of the sender to a third party. 1724 MACs use the same scheme as signature with appendix algorithms. The 1725 message content is processed and an authentication code is produced. 1726 The authentication code is frequently called a tag. 1728 The MAC functions are: 1730 tag = MAC_Create(message content, key) 1732 valid = MAC_Verify(message content, key, tag) 1734 MAC algorithms can be based on either a block cipher algorithm (i.e., 1735 AES-MAC) or a hash algorithm (i.e., a Hash-based Message 1736 Authentication Code (HMAC)). This document defines a MAC algorithm 1737 using each of these constructions. 1739 MAC algorithms are used in the COSE_Mac and COSE_Mac0 structures. 1741 10. Content Encryption Algorithms 1743 Content encryption algorithms provide data confidentiality for 1744 potentially large blocks of data using a symmetric key. They provide 1745 integrity on the data that was encrypted; however, they provide 1746 either no or very limited data origination. (One cannot, for 1747 example, be used to prove the identity of the sender to a third 1748 party.) The ability to provide data origination is linked to how the 1749 CEK is obtained. 1751 COSE restricts the set of legal content encryption algorithms to 1752 those that support authentication both of the content and additional 1753 data. The encryption process will generate some type of 1754 authentication value, but that value may be either explicit or 1755 implicit in terms of the algorithm definition. For simplicity's 1756 sake, the authentication code will normally be defined as being 1757 appended to the ciphertext stream. The encryption functions are: 1759 ciphertext = Encrypt(message content, key, additional data) 1761 valid, message content = Decrypt(ciphertext, key, additional data) 1763 Most AEAD algorithms are logically defined as returning the message 1764 content only if the decryption is valid. Many but not all 1765 implementations will follow this convention. The message content 1766 MUST NOT be used if the decryption does not validate. 1768 These algorithms are used in COSE_Encrypt and COSE_Encrypt0. 1770 11. Key Derivation Functions (KDFs) 1772 KDFs are used to take some secret value and generate a different one. 1773 The secret value comes in three flavors: 1775 o Secrets that are uniformly random: This is the type of secret that 1776 is created by a good random number generator. 1778 o Secrets that are not uniformly random: This is type of secret that 1779 is created by operations like key agreement. 1781 o Secrets that are not random: This is the type of secret that 1782 people generate for things like passwords. 1784 General KDFs work well with the first type of secret, can do 1785 reasonably well with the second type of secret, and generally do 1786 poorly with the last type of secret. Functions like PBES2 [RFC8018] 1787 need to be used for non-random secrets. 1789 The same KDF can be set up to deal with the first two types of 1790 secrets in a different way. The KDF defined in !!! HDKF !!! (section 1791 XXXX of [I-D.schaad-cose-rfc8152bis-algs]) is such a function. This 1792 is reflected in the set of algorithms defined around the HMAC-based 1793 Extract-and-Expand Key Derivation Function (HKDF). 1795 When using KDFs, one component that is included is context 1796 information. Context information is used to allow for different 1797 keying information to be derived from the same secret. The use of 1798 context-based keying material is considered to be a good security 1799 practice. 1801 12. Content Key Distribution Methods 1803 Content key distribution methods (recipient algorithms) can be 1804 defined into a number of different classes. COSE has the ability to 1805 support many classes of recipient algorithms. In this section, a 1806 number of classes are listed. The names of the recipient algorithm 1807 classes used here are the same as those defined in [RFC7516]. Other 1808 specifications use different terms for the recipient algorithm 1809 classes or do not support some of the recipient algorithm classes. 1811 12.1. Direct Encryption 1813 The direct encryption class algorithms share a secret between the 1814 sender and the recipient that is used either directly or after 1815 manipulation as the CEK. When direct encryption mode is used, it 1816 MUST be the only mode used on the message. 1818 The COSE_Recipient structure for the recipient is organized as 1819 follows: 1821 o The 'protected' field MUST be a zero-length item unless it is used 1822 in the computation of the content key. 1824 o The 'alg' parameter MUST be present. 1826 o A parameter identifying the shared secret SHOULD be present. 1828 o The 'ciphertext' field MUST be a zero-length item. 1830 o The 'recipients' field MUST be absent. 1832 12.2. Key Wrap 1834 In key wrap mode, the CEK is randomly generated and that key is then 1835 encrypted by a shared secret between the sender and the recipient. 1836 All of the currently defined key wrap algorithms for COSE are AE 1837 algorithms. Key wrap mode is considered to be superior to direct 1838 encryption if the system has any capability for doing random key 1839 generation. This is because the shared key is used to wrap random 1840 data rather than data that has some degree of organization and may in 1841 fact be repeating the same content. The use of key wrap loses the 1842 weak data origination that is provided by the direct encryption 1843 algorithms. 1845 The COSE_Encrypt structure for the recipient is organized as follows: 1847 o The 'protected' field MUST be absent if the key wrap algorithm is 1848 an AE algorithm. 1850 o The 'recipients' field is normally absent, but can be used. 1851 Applications MUST deal with a recipient field being present that 1852 has an unsupported algorthms, not being able to decrypt that 1853 recipient is an acceptable way of dealing with it. Failing to 1854 process the message is not an acceptable way of dealing with it. 1856 o The plaintext to be encrypted is the key from next layer down 1857 (usually the content layer). 1859 o At a minimum, the 'unprotected' field MUST contain the 'alg' 1860 parameter and SHOULD contain a parameter identifying the shared 1861 secret. 1863 12.3. Key Transport 1865 Key transport mode is also called key encryption mode in some 1866 standards. Key transport mode differs from key wrap mode in that it 1867 uses an asymmetric encryption algorithm rather than a symmetric 1868 encryption algorithm to protect the key. This document does not 1869 define any key transport mode algorithms. 1871 When using a key transport algorithm, the COSE_Encrypt structure for 1872 the recipient is organized as follows: 1874 o The 'protected' field MUST be absent. 1876 o The plaintext to be encrypted is the key from the next layer down 1877 (usually the content layer). 1879 o At a minimum, the 'unprotected' field MUST contain the 'alg' 1880 parameter and SHOULD contain a parameter identifying the 1881 asymmetric key. 1883 12.4. Direct Key Agreement 1885 The 'direct key agreement' class of recipient algorithms uses a key 1886 agreement method to create a shared secret. A KDF is then applied to 1887 the shared secret to derive a key to be used in protecting the data. 1888 This key is normally used as a CEK or MAC key, but could be used for 1889 other purposes if more than two layers are in use (see Appendix B). 1891 The most commonly used key agreement algorithm is Diffie-Hellman, but 1892 other variants exist. Since COSE is designed for a store and forward 1893 environment rather than an online environment, many of the DH 1894 variants cannot be used as the receiver of the message cannot provide 1895 any dynamic key material. One side effect of this is that perfect 1896 forward secrecy (see [RFC4949]) is not achievable. A static key will 1897 always be used for the receiver of the COSE object. 1899 Two variants of DH that are supported are: 1901 Ephemeral-Static (ES) DH: where the sender of the message creates 1902 a one-time DH key and uses a static key for the recipient. The 1903 use of the ephemeral sender key means that no additional random 1904 input is needed as this is randomly generated for each message. 1906 Static-Static (SS) DH: where a static key is used for both the 1907 sender and the recipient. The use of static keys allows for the 1908 recipient to get a weak version of data origination for the 1909 message. When static-static key agreement is used, then some 1910 piece of unique data for the KDF is required to ensure that a 1911 different key is created for each message. 1913 When direct key agreement mode is used, there MUST be only one 1914 recipient in the message. This method creates the key directly, and 1915 that makes it difficult to mix with additional recipients. If 1916 multiple recipients are needed, then the version with key wrap needs 1917 to be used. 1919 The COSE_Encrypt structure for the recipient is organized as follows: 1921 o At a minimum, headers MUST contain the 'alg' parameter and SHOULD 1922 contain a parameter identifying the recipient's asymmetric key. 1924 o The headers SHOULD identify the sender's key for the static-static 1925 versions and MUST contain the sender's ephemeral key for the 1926 ephemeral-static versions. 1928 12.5. Key Agreement with Key Wrap 1930 Key Agreement with Key Wrap uses a randomly generated CEK. The CEK 1931 is then encrypted using a key wrap algorithm and a key derived from 1932 the shared secret computed by the key agreement algorithm. The 1933 function for this would be: 1935 encryptedKey = KeyWrap(KDF(DH-Shared, context), CEK) 1937 The COSE_Encrypt structure for the recipient is organized as follows: 1939 o The 'protected' field is fed into the KDF context structure. 1941 o The plaintext to be encrypted is the key from the next layer down 1942 (usually the content layer). 1944 o The 'alg' parameter MUST be present in the layer. 1946 o A parameter identifying the recipient's key SHOULD be present. A 1947 parameter identifying the sender's key SHOULD be present. 1949 13. CBOR Encoder Restrictions 1951 There has been an attempt to limit the number of places where the 1952 document needs to impose restrictions on how the CBOR Encoder needs 1953 to work. We have managed to narrow it down to the following 1954 restrictions: 1956 o The restriction applies to the encoding of the COSE_KDF_Context, 1957 the Sig_structure, the Enc_structure, and the MAC_structure. 1959 o The rules for "Canonical CBOR" (Section 3.9 of RFC 7049) MUST be 1960 used in these locations. The main rule that needs to be enforced 1961 is that all lengths in these structures MUST be encoded such that 1962 they are using definite lengths, and the minimum length encoding 1963 is used. 1965 o Applications MUST NOT generate messages with the same label used 1966 twice as a key in a single map. Applications MUST NOT parse and 1967 process messages with the same label used twice as a key in a 1968 single map. Applications can enforce the parse and process 1969 requirement by using parsers that will fail the parse step or by 1970 using parsers that will pass all keys to the application, and the 1971 application can perform the check for duplicate keys. 1973 14. Application Profiling Considerations 1975 This document is designed to provide a set of security services, but 1976 not impose algorithm implementation requirements for specific usage. 1977 The interoperability requirements are provided for how each of the 1978 individual services are used and how the algorithms are to be used 1979 for interoperability. The requirements about which algorithms and 1980 which services are needed are deferred to each application. 1982 An example of a profile can be found in 1983 [I-D.ietf-core-object-security] where a profiles was developed for 1984 carrying content in combination with CoAP headers. 1986 It is intended that a profile of this document be created that 1987 defines the interoperability requirements for that specific 1988 application. This section provides a set of guidelines and topics 1989 that need to be considered when profiling this document. 1991 o Applications need to determine the set of messages defined in this 1992 document that they will be using. The set of messages corresponds 1993 fairly directly to the set of security services that are needed 1994 and to the security levels needed. 1996 o Applications may define new header parameters for a specific 1997 purpose. Applications will often times select specific header 1998 parameters to use or not to use. For example, an application 1999 would normally state a preference for using either the IV or the 2000 Partial IV parameter. If the Partial IV parameter is specified, 2001 then the application also needs to define how the fixed portion of 2002 the IV is determined. 2004 o When applications use externally defined authenticated data, they 2005 need to define how that data is encoded. This document assumes 2006 that the data will be provided as a byte string. More information 2007 can be found in Section 4.3. 2009 o Applications need to determine the set of security algorithms that 2010 are to be used. When selecting the algorithms to be used as the 2011 mandatory-to-implement set, consideration should be given to 2012 choosing different types of algorithms when two are chosen for a 2013 specific purpose. An example of this would be choosing HMAC- 2014 SHA512 and AES-CMAC as different MAC algorithms; the construction 2015 is vastly different between these two algorithms. This means that 2016 a weakening of one algorithm would be unlikely to lead to a 2017 weakening of the other algorithms. Of course, these algorithms do 2018 not provide the same level of security and thus may not be 2019 comparable for the desired security functionality. 2021 o Applications may need to provide some type of negotiation or 2022 discovery method if multiple algorithms or message structures are 2023 permitted. The method can be as simple as requiring 2024 preconfiguration of the set of algorithms to providing a discovery 2025 method built into the protocol. S/MIME provided a number of 2026 different ways to approach the problem that applications could 2027 follow: 2029 * Advertising in the message (S/MIME capabilities) [RFC5751]. 2031 * Advertising in the certificate (capabilities extension) 2032 [RFC4262]. 2034 * Minimum requirements for the S/MIME, which have been updated 2035 over time [RFC2633] [RFC5751] (note that [RFC2633] has been 2036 obsoleted by [RFC5751]). 2038 15. IANA Considerations 2040 The registeries and registrations listed below were created during 2041 processing of RFC 8152 [RFC8152]. The only known action at this time 2042 is to update the references. 2044 15.1. CBOR Tag Assignment 2046 IANA assigned tags in the "CBOR Tags" registry as part of processing 2047 [RFC8152]. IANA is requested to update the references from [RFC8152] 2048 to this document. 2050 15.2. COSE Header Parameters Registry 2052 IANA created a registry titled "COSE Header Parameters" as part of 2053 processing [RFC8152]. The registry has been created to use the 2054 "Expert Review Required" registration procedure [RFC8126]. 2056 IANA is requested to update the reference for entries in the table 2057 from [RFC8152] to this document. This document does not update the 2058 expert review guidelines provided in [RFC8152]. 2060 15.3. COSE Header Algorithm Parameters Registry 2062 IANA created a registry titled "COSE Header Algorithm Parameters" as 2063 part of processing [RFC8152]. The registry has been created to use 2064 the "Expert Review Required" registration procedure [RFC8126]. 2066 IANA is requested to update the references from [RFC8152] to this 2067 document. This document does not update the expert review guidelines 2068 provided in [RFC8152]. 2070 15.4. COSE Key Common Parameters Registry 2072 IANA created a registry titled "COSE Key Common Parameters" as part 2073 of the processing of [RFC8152]. The registry has been created to use 2074 the "Expert Review Required" registration procedure [RFC8126]. 2076 IANA is requested to update the reference for entries in the table 2077 from [RFC8152] to this document. This document does not update the 2078 expert review guidelines provided in [RFC8152]. 2080 15.5. Media Type Registrations 2082 15.5.1. COSE Security Message 2084 This section registers the 'application/cose' media type in the 2085 "Media Types" registry. These media types are used to indicate that 2086 the content is a COSE message. 2088 Type name: application 2090 Subtype name: cose 2092 Required parameters: N/A 2094 Optional parameters: cose-type 2096 Encoding considerations: binary 2098 Security considerations: See the Security Considerations section 2099 of [[This Document]]. 2101 Interoperability considerations: N/A 2103 Published specification: RFC 8152 2105 Applications that use this media type: IoT applications sending 2106 security content over HTTP(S) transports. 2108 Fragment identifier considerations: N/A 2110 Additional information: 2112 * Deprecated alias names for this type: N/A 2114 * Magic number(s): N/A 2116 * File extension(s): cbor 2117 * Macintosh file type code(s): N/A 2119 Person & email address to contact for further information: 2120 iesg@ietf.org 2122 Intended usage: COMMON 2124 Restrictions on usage: N/A 2126 Author: Jim Schaad, ietf@augustcellars.com 2128 Change Controller: IESG 2130 Provisional registration? No 2132 15.5.2. COSE Key Media Type 2134 This section registers the 'application/cose-key' and 'application/ 2135 cose-key-set' media types in the "Media Types" registry. These media 2136 types are used to indicate, respectively, that content is a COSE_Key 2137 or COSE_KeySet object. 2139 The template for registering 'application/cose-key' is: 2141 Type name: application 2143 Subtype name: cose-key 2145 Required parameters: N/A 2147 Optional parameters: N/A 2149 Encoding considerations: binary 2151 Security considerations: See the Security Considerations section 2152 of [[This Document]]. 2154 Interoperability considerations: N/A 2156 Published specification: RFC 8152 2158 Applications that use this media type: Distribution of COSE based 2159 keys for IoT applications. 2161 Fragment identifier considerations: N/A 2163 Additional information: 2165 * Deprecated alias names for this type: N/A 2167 * Magic number(s): N/A 2169 * File extension(s): cbor 2171 * Macintosh file type code(s): N/A 2173 Person & email address to contact for further information: 2174 iesg@ietf.org 2176 Intended usage: COMMON 2178 Restrictions on usage: N/A 2180 Author: Jim Schaad, ietf@augustcellars.com 2182 Change Controller: IESG 2184 Provisional registration? No 2186 The template for registering 'application/cose-key-set' is: 2188 Type name: application 2190 Subtype name: cose-key-set 2192 Required parameters: N/A 2194 Optional parameters: N/A 2196 Encoding considerations: binary 2198 Security considerations: See the Security Considerations section 2199 of [[This Document]]. 2201 Interoperability considerations: N/A 2203 Published specification: RFC 8152 2205 Applications that use this media type: Distribution of COSE based 2206 keys for IoT applications. 2208 Fragment identifier considerations: N/A 2210 Additional information: 2212 * Deprecated alias names for this type: N/A 2213 * Magic number(s): N/A 2215 * File extension(s): cbor 2217 * Macintosh file type code(s): N/A 2219 Person & email address to contact for further information: 2220 iesg@ietf.org 2222 Intended usage: COMMON 2224 Restrictions on usage: N/A 2226 Author: Jim Schaad, ietf@augustcellars.com 2228 Change Controller: IESG 2230 Provisional registration? No 2232 15.6. CoAP Content-Formats Registry 2234 IANA added the following entries to the "CoAP Content-Formats" 2235 registry while processing [RFC8152]. IANA is requested to update the 2236 reference value from [RFC8152] to [[This Document]]. 2238 15.7. Expert Review Instructions 2240 All of the IANA registries established in this document are defined 2241 as expert review. This section gives some general guidelines for 2242 what the experts should be looking for, but they are being designated 2243 as experts for a reason, so they should be given substantial 2244 latitude. 2246 Expert reviewers should take into consideration the following points: 2248 o Point squatting should be discouraged. Reviewers are encouraged 2249 to get sufficient information for registration requests to ensure 2250 that the usage is not going to duplicate one that is already 2251 registered, and that the point is likely to be used in 2252 deployments. The zones tagged as private use are intended for 2253 testing purposes and closed environments; code points in other 2254 ranges should not be assigned for testing. 2256 o Specifications are required for the standards track range of point 2257 assignment. Specifications should exist for specification 2258 required ranges, but early assignment before a specification is 2259 available is considered to be permissible. Specifications are 2260 needed for the first-come, first-serve range if they are expected 2261 to be used outside of closed environments in an interoperable way. 2262 When specifications are not provided, the description provided 2263 needs to have sufficient information to identify what the point is 2264 being used for. 2266 o Experts should take into account the expected usage of fields when 2267 approving point assignment. The fact that there is a range for 2268 standards track documents does not mean that a standards track 2269 document cannot have points assigned outside of that range. The 2270 length of the encoded value should be weighed against how many 2271 code points of that length are left, the size of device it will be 2272 used on, and the number of code points left that encode to that 2273 size. 2275 o When algorithms are registered, vanity registrations should be 2276 discouraged. One way to do this is to require registrations to 2277 provide additional documentation on security analysis of the 2278 algorithm. Another thing that should be considered is requesting 2279 an opinion on the algorithm from the Crypto Forum Research Group 2280 (CFRG). Algorithms that do not meet the security requirements of 2281 the community and the messages structures should not be 2282 registered. 2284 16. Security Considerations 2286 There are a number of security considerations that need to be taken 2287 into account by implementers of this specification. The security 2288 considerations that are specific to an individual algorithm are 2289 placed next to the description of the algorithm. While some 2290 considerations have been highlighted here, additional considerations 2291 may be found in the documents listed in the references. 2293 Implementations need to protect the private key material for any 2294 individuals. There are some cases in this document that need to be 2295 highlighted on this issue. 2297 o Using the same key for two different algorithms can leak 2298 information about the key. It is therefore recommended that keys 2299 be restricted to a single algorithm. 2301 o Use of 'direct' as a recipient algorithm combined with a second 2302 recipient algorithm exposes the direct key to the second 2303 recipient. 2305 o Several of the algorithms in this document have limits on the 2306 number of times that a key can be used without leaking information 2307 about the key. 2309 The use of ECDH and direct plus KDF (with no key wrap) will not 2310 directly lead to the private key being leaked; the one way function 2311 of the KDF will prevent that. There is, however, a different issue 2312 that needs to be addressed. Having two recipients requires that the 2313 CEK be shared between two recipients. The second recipient therefore 2314 has a CEK that was derived from material that can be used for the 2315 weak proof of origin. The second recipient could create a message 2316 using the same CEK and send it to the first recipient; the first 2317 recipient would, for either static-static ECDH or direct plus KDF, 2318 make an assumption that the CEK could be used for proof of origin 2319 even though it is from the wrong entity. If the key wrap step is 2320 added, then no proof of origin is implied and this is not an issue. 2322 Although it has been mentioned before, the use of a single key for 2323 multiple algorithms has been demonstrated in some cases to leak 2324 information about a key, provide the opportunity for attackers to 2325 forge integrity tags, or gain information about encrypted content. 2326 Binding a key to a single algorithm prevents these problems. Key 2327 creators and key consumers are strongly encouraged not only to create 2328 new keys for each different algorithm, but to include that selection 2329 of algorithm in any distribution of key material and strictly enforce 2330 the matching of algorithms in the key structure to algorithms in the 2331 message structure. In addition to checking that algorithms are 2332 correct, the key form needs to be checked as well. Do not use an 2333 'EC2' key where an 'OKP' key is expected. 2335 Before using a key for transmission, or before acting on information 2336 received, a trust decision on a key needs to be made. Is the data or 2337 action something that the entity associated with the key has a right 2338 to see or a right to request? A number of factors are associated 2339 with this trust decision. Some of the ones that are highlighted here 2340 are: 2342 o What are the permissions associated with the key owner? 2344 o Is the cryptographic algorithm acceptable in the current context? 2346 o Have the restrictions associated with the key, such as algorithm 2347 or freshness, been checked and are they correct? 2349 o Is the request something that is reasonable, given the current 2350 state of the application? 2352 o Have any security considerations that are part of the message been 2353 enforced (as specified by the application or 'crit' parameter)? 2355 There are a large number of algorithms presented in this document 2356 that use nonce values. For all of the nonces defined in this 2357 document, there is some type of restriction on the nonce being a 2358 unique value either for a key or for some other conditions. In all 2359 of these cases, there is no known requirement on the nonce being both 2360 unique and unpredictable; under these circumstances, it's reasonable 2361 to use a counter for creation of the nonce. In cases where one wants 2362 the pattern of the nonce to be unpredictable as well as unique, one 2363 can use a key created for that purpose and encrypt the counter to 2364 produce the nonce value. 2366 One area that has been starting to get exposure is doing traffic 2367 analysis of encrypted messages based on the length of the message. 2368 This specification does not provide for a uniform method of providing 2369 padding as part of the message structure. An observer can 2370 distinguish between two different strings (for example, 'YES' and 2371 'NO') based on the length for all of the content encryption 2372 algorithms that are defined in this document. This means that it is 2373 up to the applications to document how content padding is to be done 2374 in order to prevent or discourage such analysis. (For example, the 2375 strings could be defined as 'YES' and 'NO '.) 2377 17. References 2379 17.1. Normative References 2381 [COAP.Formats] 2382 IANA, "CoAP Content-Formats", 2383 . 2386 [COSE.Algorithms] 2387 IANA, "COSE Algorithms", 2388 . 2391 [COSE.KeyParameters] 2392 IANA, "COSE Key Parameters", 2393 . 2396 [COSE.KeyTypes] 2397 IANA, "COSE Key Types", 2398 . 2401 [DSS] National Institute of Standards and Technology, "Digital 2402 Signature Standard (DSS)", FIPS PUB 186-4, 2403 DOI 10.6028/NIST.FIPS.186-4, July 2013, 2404 . 2407 [I-D.schaad-cose-rfc8152bis-algs] 2408 Schaad, J., "CBOR Algoritms for Object Signing and 2409 Encryption (COSE)", draft-schaad-cose-rfc8152bis-algs-01 2410 (work in progress), December 2018. 2412 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2413 Requirement Levels", BCP 14, RFC 2119, 2414 DOI 10.17487/RFC2119, March 1997, 2415 . 2417 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 2418 Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, 2419 October 2013, . 2421 [RFC8032] Josefsson, S. and I. Liusvaara, "Edwards-Curve Digital 2422 Signature Algorithm (EdDSA)", RFC 8032, 2423 DOI 10.17487/RFC8032, January 2017, 2424 . 2426 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2427 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 2428 May 2017, . 2430 17.2. Informative References 2432 [I-D.ietf-cbor-cddl] 2433 Birkholz, H., Vigano, C., and C. Bormann, "Concise data 2434 definition language (CDDL): a notational convention to 2435 express CBOR and JSON data structures", draft-ietf-cbor- 2436 cddl-06 (work in progress), November 2018. 2438 [I-D.ietf-core-object-security] 2439 Selander, G., Mattsson, J., Palombini, F., and L. Seitz, 2440 "Object Security for Constrained RESTful Environments 2441 (OSCORE)", draft-ietf-core-object-security-15 (work in 2442 progress), August 2018. 2444 [PVSig] Brown, D. and D. Johnson, "Formal Security Proofs for a 2445 Signature Scheme with Partial Message Recovery", 2446 DOI 10.1007/3-540-45353-9_11, LNCS Volume 2020, June 2000. 2448 [RFC2633] Ramsdell, B., Ed., "S/MIME Version 3 Message 2449 Specification", RFC 2633, DOI 10.17487/RFC2633, June 1999, 2450 . 2452 [RFC4262] Santesson, S., "X.509 Certificate Extension for Secure/ 2453 Multipurpose Internet Mail Extensions (S/MIME) 2454 Capabilities", RFC 4262, DOI 10.17487/RFC4262, December 2455 2005, . 2457 [RFC4949] Shirey, R., "Internet Security Glossary, Version 2", 2458 FYI 36, RFC 4949, DOI 10.17487/RFC4949, August 2007, 2459 . 2461 [RFC5116] McGrew, D., "An Interface and Algorithms for Authenticated 2462 Encryption", RFC 5116, DOI 10.17487/RFC5116, January 2008, 2463 . 2465 [RFC5652] Housley, R., "Cryptographic Message Syntax (CMS)", STD 70, 2466 RFC 5652, DOI 10.17487/RFC5652, September 2009, 2467 . 2469 [RFC5751] Ramsdell, B. and S. Turner, "Secure/Multipurpose Internet 2470 Mail Extensions (S/MIME) Version 3.2 Message 2471 Specification", RFC 5751, DOI 10.17487/RFC5751, January 2472 2010, . 2474 [RFC5752] Turner, S. and J. Schaad, "Multiple Signatures in 2475 Cryptographic Message Syntax (CMS)", RFC 5752, 2476 DOI 10.17487/RFC5752, January 2010, 2477 . 2479 [RFC5990] Randall, J., Kaliski, B., Brainard, J., and S. Turner, 2480 "Use of the RSA-KEM Key Transport Algorithm in the 2481 Cryptographic Message Syntax (CMS)", RFC 5990, 2482 DOI 10.17487/RFC5990, September 2010, 2483 . 2485 [RFC6838] Freed, N., Klensin, J., and T. Hansen, "Media Type 2486 Specifications and Registration Procedures", BCP 13, 2487 RFC 6838, DOI 10.17487/RFC6838, January 2013, 2488 . 2490 [RFC7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 2491 Application Protocol (CoAP)", RFC 7252, 2492 DOI 10.17487/RFC7252, June 2014, 2493 . 2495 [RFC7515] Jones, M., Bradley, J., and N. Sakimura, "JSON Web 2496 Signature (JWS)", RFC 7515, DOI 10.17487/RFC7515, May 2497 2015, . 2499 [RFC7516] Jones, M. and J. Hildebrand, "JSON Web Encryption (JWE)", 2500 RFC 7516, DOI 10.17487/RFC7516, May 2015, 2501 . 2503 [RFC7517] Jones, M., "JSON Web Key (JWK)", RFC 7517, 2504 DOI 10.17487/RFC7517, May 2015, 2505 . 2507 [RFC7518] Jones, M., "JSON Web Algorithms (JWA)", RFC 7518, 2508 DOI 10.17487/RFC7518, May 2015, 2509 . 2511 [RFC8018] Moriarty, K., Ed., Kaliski, B., and A. Rusch, "PKCS #5: 2512 Password-Based Cryptography Specification Version 2.1", 2513 RFC 8018, DOI 10.17487/RFC8018, January 2017, 2514 . 2516 [RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for 2517 Writing an IANA Considerations Section in RFCs", BCP 26, 2518 RFC 8126, DOI 10.17487/RFC8126, June 2017, 2519 . 2521 [RFC8152] Schaad, J., "CBOR Object Signing and Encryption (COSE)", 2522 RFC 8152, DOI 10.17487/RFC8152, July 2017, 2523 . 2525 [RFC8230] Jones, M., "Using RSA Algorithms with CBOR Object Signing 2526 and Encryption (COSE) Messages", RFC 8230, 2527 DOI 10.17487/RFC8230, September 2017, 2528 . 2530 [RFC8259] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 2531 Interchange Format", STD 90, RFC 8259, 2532 DOI 10.17487/RFC8259, December 2017, 2533 . 2535 [W3C.WebCrypto] 2536 Watson, M., "Web Cryptography API", W3C Recommendation, 2537 January 2017, . 2539 Appendix A. Guidelines for External Data Authentication of Algorithms 2541 A portion of the working group has expressed a strong desire to relax 2542 the rule that the algorithm identifier be required to appear in each 2543 level of a COSE object. There are two basic reasons that have been 2544 advanced to support this position. First, the resulting message will 2545 be smaller if the algorithm identifier is omitted from the most 2546 common messages in a CoAP environment. Second, there is a potential 2547 bug that will arise if full checking is not done correctly between 2548 the different places that an algorithm identifier could be placed 2549 (the message itself, an application statement, the key structure that 2550 the sender possesses, and the key structure the recipient possesses). 2552 This appendix lays out how such a change can be made and the details 2553 that an application needs to specify in order to use this option. 2554 Two different sets of details are specified: those needed to omit an 2555 algorithm identifier and those needed to use a variant on the counter 2556 signature attribute that contains no attributes about itself. 2558 A.1. Algorithm Identification 2560 In this section, three sets of recommendations are laid out. The 2561 first set of recommendations apply to having an implicit algorithm 2562 identified for a single layer of a COSE object. The second set of 2563 recommendations apply to having multiple implicit algorithms 2564 identified for multiple layers of a COSE object. The third set of 2565 recommendations apply to having implicit algorithms for multiple COSE 2566 object constructs. 2568 The key words from [RFC2119] are deliberately not used here. This 2569 specification can provide recommendations, but it cannot enforce 2570 them. 2572 This set of recommendations applies to the case where an application 2573 is distributing a fixed algorithm along with the key information for 2574 use in a single COSE object. This normally applies to the smallest 2575 of the COSE objects, specifically COSE_Sign1, COSE_Mac0, and 2576 COSE_Encrypt0, but could apply to the other structures as well. 2578 The following items should be taken into account: 2580 o Applications need to list the set of COSE structures that implicit 2581 algorithms are to be used in. Applications need to require that 2582 the receipt of an explicit algorithm identifier in one of these 2583 structures will lead to the message being rejected. This 2584 requirement is stated so that there will never be a case where 2585 there is any ambiguity about the question of which algorithm 2586 should be used, the implicit or the explicit one. This applies 2587 even if the transported algorithm identifier is a protected 2588 attribute. This applies even if the transported algorithm is the 2589 same as the implicit algorithm. 2591 o Applications need to define the set of information that is to be 2592 considered to be part of a context when omitting algorithm 2593 identifiers. At a minimum, this would be the key identifier (if 2594 needed), the key, the algorithm, and the COSE structure it is used 2595 with. Applications should restrict the use of a single key to a 2596 single algorithm. As noted for some of the algorithms in this 2597 document, the use of the same key in different related algorithms 2598 can lead to leakage of information about the key, leakage about 2599 the data or the ability to perform forgeries. 2601 o In many cases, applications that make the algorithm identifier 2602 implicit will also want to make the context identifier implicit 2603 for the same reason. That is, omitting the context identifier 2604 will decrease the message size (potentially significantly 2605 depending on the length of the identifier). Applications that do 2606 this will need to describe the circumstances where the context 2607 identifier is to be omitted and how the context identifier is to 2608 be inferred in these cases. (An exhaustive search over all of the 2609 keys would normally not be considered to be acceptable.) An 2610 example of how this can be done is to tie the context to a 2611 transaction identifier. Both would be sent on the original 2612 message, but only the transaction identifier would need to be sent 2613 after that point as the context is tied into the transaction 2614 identifier. Another way would be to associate a context with a 2615 network address. All messages coming from a single network 2616 address can be assumed to be associated with a specific context. 2617 (In this case, the address would normally be distributed as part 2618 of the context.) 2620 o Applications cannot rely on key identifiers being unique unless 2621 they take significant efforts to ensure that they are computed in 2622 such a way as to create this guarantee. Even when an application 2623 does this, the uniqueness might be violated if the application is 2624 run in different contexts (i.e., with a different context 2625 provider) or if the system combines the security contexts from 2626 different applications together into a single store. 2628 o Applications should continue the practice of protecting the 2629 algorithm identifier. Since this is not done by placing it in the 2630 protected attributes field, applications should define an 2631 application-specific external data structure that includes this 2632 value. This external data field can be used as such for content 2633 encryption, MAC, and signature algorithms. It can be used in the 2634 SuppPrivInfo field for those algorithms that use a KDF to derive a 2635 key value. Applications may also want to protect other 2636 information that is part of the context structure as well. It 2637 should be noted that those fields, such as the key or a Base IV, 2638 are protected by virtue of being used in the cryptographic 2639 computation and do not need to be included in the external data 2640 field. 2642 The second case is having multiple implicit algorithm identifiers 2643 specified for a multiple layer COSE object. An example of how this 2644 would work is the encryption context that an application specifies, 2645 which contains a content encryption algorithm, a key wrap algorithm, 2646 a key identifier, and a shared secret. The sender omits sending the 2647 algorithm identifier for both the content layer and the recipient 2648 layer leaving only the key identifier. The receiver then uses the 2649 key identifier to get the implicit algorithm identifiers. 2651 The following additional items need to be taken into consideration: 2653 o Applications that want to support this will need to define a 2654 structure that allows for, and clearly identifies, both the COSE 2655 structure to be used with a given key and the structure and 2656 algorithm to be used for the secondary layer. The key for the 2657 secondary layer is computed as normal from the recipient layer. 2659 The third case is having multiple implicit algorithm identifiers, but 2660 targeted at potentially unrelated layers or different COSE objects. 2661 There are a number of different scenarios where this might be 2662 applicable. Some of these scenarios are: 2664 o Two contexts are distributed as a pair. Each of the contexts is 2665 for use with a COSE_Encrypt message. Each context will consist of 2666 distinct secret keys and IVs and potentially even different 2667 algorithms. One context is for sending messages from party A to 2668 party B, and the second context is for sending messages from party 2669 B to party A. This means that there is no chance for a reflection 2670 attack to occur as each party uses different secret keys to send 2671 its messages; a message that is reflected back to it would fail to 2672 decrypt. 2674 o Two contexts are distributed as a pair. The first context is used 2675 for encryption of the message, and the second context is used to 2676 place a counter signature on the message. The intention is that 2677 the second context can be distributed to other entities 2678 independently of the first context. This allows these entities to 2679 validate that the message came from an individual without being 2680 able to decrypt the message and see the content. 2682 o Two contexts are distributed as a pair. The first context 2683 contains a key for dealing with MACed messages, and the second 2684 context contains a key for dealing with encrypted messages. This 2685 allows for a unified distribution of keys to participants for 2686 different types of messages that have different keys, but where 2687 the keys may be used in a coordinated manner. 2689 For these cases, the following additional items need to be 2690 considered: 2692 o Applications need to ensure that the multiple contexts stay 2693 associated. If one of the contexts is invalidated for any reason, 2694 all of the contexts associated with it should also be invalidated. 2696 A.2. Counter Signature without Headers 2698 There is a group of people who want to have a counter signature 2699 parameter that is directly tied to the value being signed, and thus 2700 the authenticated and unauthenticated buckets can be removed from the 2701 message being sent. The focus on this is an even smaller size, as 2702 all of the information on the process of creating the counter 2703 signature is implicit rather than being explicitly carried in the 2704 message. This includes not only the algorithm identifier as 2705 presented above, but also items such as the key identification, which 2706 is always external to the signature structure. This means that the 2707 entities that are doing the validation of the counter signature are 2708 required to infer which key is to be used from context rather than 2709 being explicit. One way of doing this would be to presume that all 2710 data coming from a specific port (or to a specific URL) is to be 2711 validated by a specific key. (Note that this does not require that 2712 the key identifier be part of the value signed as it does not serve a 2713 cryptographic purpose. If the key validates the counter signature, 2714 then it should be presumed that the entity associated with that key 2715 produced the signature.) 2717 When computing the signature for the bare counter signature header, 2718 the same Sig_structure defined in Section 4.4 is used. The 2719 sign_protected field is omitted, as there is no protected header 2720 field in this counter signature header. The value of 2721 "CounterSignature0" is placed in the context field of the 2722 Sig_stucture. 2724 +-------------------+-------+-------+-------+-----------------------+ 2725 | Name | Label | Value | Value | Description | 2726 | | | Type | | | 2727 +-------------------+-------+-------+-------+-----------------------+ 2728 | CounterSignature0 | 9 | bstr | | Counter signature | 2729 | | | | | with implied signer | 2730 | | | | | and headers | 2731 +-------------------+-------+-------+-------+-----------------------+ 2733 Table 6: Header Parameter for CounterSignature0 2735 Appendix B. Two Layers of Recipient Information 2737 All of the currently defined recipient algorithm classes only use two 2738 layers of the COSE_Encrypt structure. The first layer is the message 2739 content, and the second layer is the content key encryption. 2740 However, if one uses a recipient algorithm such as the RSA Key 2741 Encapsulation Mechanism (RSA-KEM) (see Appendix A of RSA-KEM 2742 [RFC5990]), then it makes sense to have three layers of the 2743 COSE_Encrypt structure. 2745 These layers would be: 2747 o Layer 0: The content encryption layer. This layer contains the 2748 payload of the message. 2750 o Layer 1: The encryption of the CEK by a KEK. 2752 o Layer 2: The encryption of a long random secret using an RSA key 2753 and a key derivation function to convert that secret into the KEK. 2755 This is an example of what a triple layer message would look like. 2756 The message has the following layers: 2758 o Layer 0: Has a content encrypted with AES-GCM using a 128-bit key. 2760 o Layer 1: Uses the AES Key Wrap algorithm with a 128-bit key. 2762 o Layer 2: Uses ECDH Ephemeral-Static direct to generate the layer 1 2763 key. 2765 In effect, this example is a decomposed version of using the 2766 ECDH-ES+A128KW algorithm. 2768 Size of binary file is 183 bytes 2769 96( 2770 [ 2771 / protected / h'a10101' / { 2772 \ alg \ 1:1 \ AES-GCM 128 \ 2773 } / , 2774 / unprotected / { 2775 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 2776 }, 2777 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e2852948658f0 2778 811139868826e89218a75715b', 2779 / recipients / [ 2780 [ 2781 / protected / h'', 2782 / unprotected / { 2783 / alg / 1:-3 / A128KW / 2784 }, 2785 / ciphertext / h'dbd43c4e9d719c27c6275c67d628d493f090593db82 2786 18f11', 2787 / recipients / [ 2788 [ 2789 / protected / h'a1013818' / { 2790 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 2791 } / , 2792 / unprotected / { 2793 / ephemeral / -1:{ 2794 / kty / 1:2, 2795 / crv / -1:1, 2796 / x / -2:h'b2add44368ea6d641f9ca9af308b4079aeb519f11 2797 e9b8a55a600b21233e86e68', 2798 / y / -3:false 2799 }, 2800 / kid / 4:'meriadoc.brandybuck@buckland.example' 2801 }, 2802 / ciphertext / h'' 2803 ] 2804 ] 2805 ] 2806 ] 2807 ] 2808 ) 2810 Appendix C. Examples 2812 This appendix includes a set of examples that show the different 2813 features and message types that have been defined in this document. 2814 To make the examples easier to read, they are presented using the 2815 extended CBOR diagnostic notation (defined in [I-D.ietf-cbor-cddl]) 2816 rather than as a binary dump. 2818 A GitHub project has been created at that contains not only the examples presented in this 2820 document, but a more complete set of testing examples as well. Each 2821 example is found in a JSON file that contains the inputs used to 2822 create the example, some of the intermediate values that can be used 2823 in debugging the example and the output of the example presented in 2824 both a hex and a CBOR diagnostic notation format. Some of the 2825 examples at the site are designed failure testing cases; these are 2826 clearly marked as such in the JSON file. If errors in the examples 2827 in this document are found, the examples on GitHub will be updated, 2828 and a note to that effect will be placed in the JSON file. 2830 As noted, the examples are presented using the CBOR's diagnostic 2831 notation. A Ruby-based tool exists that can convert between the 2832 diagnostic notation and binary. This tool can be installed with the 2833 command line: 2835 gem install cbor-diag 2837 The diagnostic notation can be converted into binary files using the 2838 following command line: 2840 diag2cbor.rb < inputfile > outputfile 2842 The examples can be extracted from the XML version of this document 2843 via an XPath expression as all of the artwork is tagged with the 2844 attribute type='CBORdiag'. (Depending on the XPath evaluator one is 2845 using, it may be necessary to deal with > as an entity.) 2847 //artwork[@type='CDDL']/text() 2849 C.1. Examples of Signed Messages 2851 C.1.1. Single Signature 2853 This example uses the following: 2855 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 2857 Size of binary file is 103 bytes 2858 98( 2859 [ 2860 / protected / h'', 2861 / unprotected / {}, 2862 / payload / 'This is the content.', 2863 / signatures / [ 2864 [ 2865 / protected / h'a10126' / { 2866 \ alg \ 1:-7 \ ECDSA 256 \ 2867 } / , 2868 / unprotected / { 2869 / kid / 4:'11' 2870 }, 2871 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 2872 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 2873 98f53afd2fa0f30a' 2874 ] 2875 ] 2876 ] 2877 ) 2879 C.1.2. Multiple Signers 2881 This example uses the following: 2883 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 2885 o Signature Algorithm: ECDSA w/ SHA-512, Curve P-521 2887 Size of binary file is 277 bytes 2888 98( 2889 [ 2890 / protected / h'', 2891 / unprotected / {}, 2892 / payload / 'This is the content.', 2893 / signatures / [ 2894 [ 2895 / protected / h'a10126' / { 2896 \ alg \ 1:-7 \ ECDSA 256 \ 2897 } / , 2898 / unprotected / { 2899 / kid / 4:'11' 2900 }, 2901 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 2902 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 2903 98f53afd2fa0f30a' 2904 ], 2905 [ 2906 / protected / h'a1013823' / { 2907 \ alg \ 1:-36 2908 } / , 2909 / unprotected / { 2910 / kid / 4:'bilbo.baggins@hobbiton.example' 2911 }, 2912 / signature / h'00a2d28a7c2bdb1587877420f65adf7d0b9a06635dd1 2913 de64bb62974c863f0b160dd2163734034e6ac003b01e8705524c5c4ca479a952f024 2914 7ee8cb0b4fb7397ba08d009e0c8bf482270cc5771aa143966e5a469a09f613488030 2915 c5b07ec6d722e3835adb5b2d8c44e95ffb13877dd2582866883535de3bb03d01753f 2916 83ab87bb4f7a0297' 2917 ] 2918 ] 2919 ] 2920 ) 2922 C.1.3. Counter Signature 2924 This example uses the following: 2926 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 2928 o The same parameters are used for both the signature and the 2929 counter signature. 2931 Size of binary file is 180 bytes 2932 98( 2933 [ 2934 / protected / h'', 2935 / unprotected / { 2936 / countersign / 7:[ 2937 / protected / h'a10126' / { 2938 \ alg \ 1:-7 \ ECDSA 256 \ 2939 } / , 2940 / unprotected / { 2941 / kid / 4:'11' 2942 }, 2943 / signature / h'5ac05e289d5d0e1b0a7f048a5d2b643813ded50bc9e4 2944 9220f4f7278f85f19d4a77d655c9d3b51e805a74b099e1e085aacd97fc29d72f887e 2945 8802bb6650cceb2c' 2946 ] 2947 }, 2948 / payload / 'This is the content.', 2949 / signatures / [ 2950 [ 2951 / protected / h'a10126' / { 2952 \ alg \ 1:-7 \ ECDSA 256 \ 2953 } / , 2954 / unprotected / { 2955 / kid / 4:'11' 2956 }, 2957 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 2958 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 2959 98f53afd2fa0f30a' 2960 ] 2961 ] 2962 ] 2963 ) 2965 C.1.4. Signature with Criticality 2967 This example uses the following: 2969 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 2971 o There is a criticality marker on the "reserved" header parameter 2973 Size of binary file is 125 bytes 2974 98( 2975 [ 2976 / protected / h'a2687265736572766564f40281687265736572766564' / 2977 { 2978 "reserved":false, 2979 \ crit \ 2:[ 2980 "reserved" 2981 ] 2982 } / , 2983 / unprotected / {}, 2984 / payload / 'This is the content.', 2985 / signatures / [ 2986 [ 2987 / protected / h'a10126' / { 2988 \ alg \ 1:-7 \ ECDSA 256 \ 2989 } / , 2990 / unprotected / { 2991 / kid / 4:'11' 2992 }, 2993 / signature / h'3fc54702aa56e1b2cb20284294c9106a63f91bac658d 2994 69351210a031d8fc7c5ff3e4be39445b1a3e83e1510d1aca2f2e8a7c081c7645042b 2995 18aba9d1fad1bd9c' 2996 ] 2997 ] 2998 ] 2999 ) 3001 C.2. Single Signer Examples 3003 C.2.1. Single ECDSA Signature 3005 This example uses the following: 3007 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3009 Size of binary file is 98 bytes 3010 18( 3011 [ 3012 / protected / h'a10126' / { 3013 \ alg \ 1:-7 \ ECDSA 256 \ 3014 } / , 3015 / unprotected / { 3016 / kid / 4:'11' 3017 }, 3018 / payload / 'This is the content.', 3019 / signature / h'8eb33e4ca31d1c465ab05aac34cc6b23d58fef5c083106c4 3020 d25a91aef0b0117e2af9a291aa32e14ab834dc56ed2a223444547e01f11d3b0916e5 3021 a4c345cacb36' 3022 ] 3023 ) 3025 C.3. Examples of Enveloped Messages 3027 C.3.1. Direct ECDH 3029 This example uses the following: 3031 o CEK: AES-GCM w/ 128-bit key 3033 o Recipient class: ECDH Ephemeral-Static, Curve P-256 3035 Size of binary file is 151 bytes 3036 96( 3037 [ 3038 / protected / h'a10101' / { 3039 \ alg \ 1:1 \ AES-GCM 128 \ 3040 } / , 3041 / unprotected / { 3042 / iv / 5:h'c9cf4df2fe6c632bf7886413' 3043 }, 3044 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 3045 c52a357da7a644b8070a151b0', 3046 / recipients / [ 3047 [ 3048 / protected / h'a1013818' / { 3049 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 3050 } / , 3051 / unprotected / { 3052 / ephemeral / -1:{ 3053 / kty / 1:2, 3054 / crv / -1:1, 3055 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 3056 bf054e1c7b4d91d6280', 3057 / y / -3:true 3058 }, 3059 / kid / 4:'meriadoc.brandybuck@buckland.example' 3060 }, 3061 / ciphertext / h'' 3062 ] 3063 ] 3064 ] 3065 ) 3067 C.3.2. Direct Plus Key Derivation 3069 This example uses the following: 3071 o CEK: AES-CCM w/ 128-bit key, truncate the tag to 64 bits 3073 o Recipient class: Use HKDF on a shared secret with the following 3074 implicit fields as part of the context. 3076 * salt: "aabbccddeeffgghh" 3078 * PartyU identity: "lighting-client" 3080 * PartyV identity: "lighting-server" 3082 * Supplementary Public Other: "Encryption Example 02" 3084 Size of binary file is 91 bytes 3086 96( 3087 [ 3088 / protected / h'a1010a' / { 3089 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3090 } / , 3091 / unprotected / { 3092 / iv / 5:h'89f52f65a1c580933b5261a76c' 3093 }, 3094 / ciphertext / h'753548a19b1307084ca7b2056924ed95f2e3b17006dfe93 3095 1b687b847', 3096 / recipients / [ 3097 [ 3098 / protected / h'a10129' / { 3099 \ alg \ 1:-10 3100 } / , 3101 / unprotected / { 3102 / salt / -20:'aabbccddeeffgghh', 3103 / kid / 4:'our-secret' 3104 }, 3105 / ciphertext / h'' 3106 ] 3107 ] 3108 ] 3109 ) 3111 C.3.3. Counter Signature on Encrypted Content 3113 This example uses the following: 3115 o CEK: AES-GCM w/ 128-bit key 3117 o Recipient class: ECDH Ephemeral-Static, Curve P-256 3119 Size of binary file is 326 bytes 3120 96( 3121 [ 3122 / protected / h'a10101' / { 3123 \ alg \ 1:1 \ AES-GCM 128 \ 3124 } / , 3125 / unprotected / { 3126 / iv / 5:h'c9cf4df2fe6c632bf7886413', 3127 / countersign / 7:[ 3128 / protected / h'a1013823' / { 3129 \ alg \ 1:-36 3130 } / , 3131 / unprotected / { 3132 / kid / 4:'bilbo.baggins@hobbiton.example' 3133 }, 3134 / signature / h'00929663c8789bb28177ae28467e66377da12302d7f9 3135 594d2999afa5dfa531294f8896f2b6cdf1740014f4c7f1a358e3a6cf57f4ed6fb02f 3136 cf8f7aa989f5dfd07f0700a3a7d8f3c604ba70fa9411bd10c2591b483e1d2c31de00 3137 3183e434d8fba18f17a4c7e3dfa003ac1cf3d30d44d2533c4989d3ac38c38b71481c 3138 c3430c9d65e7ddff' 3139 ] 3140 }, 3141 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 3142 c52a357da7a644b8070a151b0', 3143 / recipients / [ 3144 [ 3145 / protected / h'a1013818' / { 3146 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 3147 } / , 3148 / unprotected / { 3149 / ephemeral / -1:{ 3150 / kty / 1:2, 3151 / crv / -1:1, 3152 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 3153 bf054e1c7b4d91d6280', 3154 / y / -3:true 3155 }, 3156 / kid / 4:'meriadoc.brandybuck@buckland.example' 3157 }, 3158 / ciphertext / h'' 3159 ] 3160 ] 3161 ] 3162 ) 3164 C.3.4. Encrypted Content with External Data 3166 This example uses the following: 3168 o CEK: AES-GCM w/ 128-bit key 3170 o Recipient class: ECDH static-Static, Curve P-256 with AES Key Wrap 3172 o Externally Supplied AAD: h'0011bbcc22dd44ee55ff660077' 3174 Size of binary file is 173 bytes 3176 96( 3177 [ 3178 / protected / h'a10101' / { 3179 \ alg \ 1:1 \ AES-GCM 128 \ 3180 } / , 3181 / unprotected / { 3182 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 3183 }, 3184 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e28529d8f5335 3185 e5f0165eee976b4a5f6c6f09d', 3186 / recipients / [ 3187 [ 3188 / protected / h'a101381f' / { 3189 \ alg \ 1:-32 \ ECHD-SS+A128KW \ 3190 } / , 3191 / unprotected / { 3192 / static kid / -3:'peregrin.took@tuckborough.example', 3193 / kid / 4:'meriadoc.brandybuck@buckland.example', 3194 / U nonce / -22:h'0101' 3195 }, 3196 / ciphertext / h'41e0d76f579dbd0d936a662d54d8582037de2e366fd 3197 e1c62' 3198 ] 3199 ] 3200 ] 3201 ) 3203 C.4. Examples of Encrypted Messages 3205 C.4.1. Simple Encrypted Message 3207 This example uses the following: 3209 o CEK: AES-CCM w/ 128-bit key and a 64-bit tag 3211 Size of binary file is 52 bytes 3212 16( 3213 [ 3214 / protected / h'a1010a' / { 3215 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3216 } / , 3217 / unprotected / { 3218 / iv / 5:h'89f52f65a1c580933b5261a78c' 3219 }, 3220 / ciphertext / h'5974e1b99a3a4cc09a659aa2e9e7fff161d38ce71cb45ce 3221 460ffb569' 3222 ] 3223 ) 3225 C.4.2. Encrypted Message with a Partial IV 3227 This example uses the following: 3229 o CEK: AES-CCM w/ 128-bit key and a 64-bit tag 3231 o Prefix for IV is 89F52F65A1C580933B52 3233 Size of binary file is 41 bytes 3235 16( 3236 [ 3237 / protected / h'a1010a' / { 3238 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3239 } / , 3240 / unprotected / { 3241 / partial iv / 6:h'61a7' 3242 }, 3243 / ciphertext / h'252a8911d465c125b6764739700f0141ed09192de139e05 3244 3bd09abca' 3245 ] 3246 ) 3248 C.5. Examples of MACed Messages 3250 C.5.1. Shared Secret Direct MAC 3252 This example uses the following: 3254 o MAC: AES-CMAC, 256-bit key, truncated to 64 bits 3256 o Recipient class: direct shared secret 3258 Size of binary file is 57 bytes 3259 97( 3260 [ 3261 / protected / h'a1010f' / { 3262 \ alg \ 1:15 \ AES-CBC-MAC-256//64 \ 3263 } / , 3264 / unprotected / {}, 3265 / payload / 'This is the content.', 3266 / tag / h'9e1226ba1f81b848', 3267 / recipients / [ 3268 [ 3269 / protected / h'', 3270 / unprotected / { 3271 / alg / 1:-6 / direct /, 3272 / kid / 4:'our-secret' 3273 }, 3274 / ciphertext / h'' 3275 ] 3276 ] 3277 ] 3278 ) 3280 C.5.2. ECDH Direct MAC 3282 This example uses the following: 3284 o MAC: HMAC w/SHA-256, 256-bit key 3286 o Recipient class: ECDH key agreement, two static keys, HKDF w/ 3287 context structure 3289 Size of binary file is 214 bytes 3290 97( 3291 [ 3292 / protected / h'a10105' / { 3293 \ alg \ 1:5 \ HMAC 256//256 \ 3294 } / , 3295 / unprotected / {}, 3296 / payload / 'This is the content.', 3297 / tag / h'81a03448acd3d305376eaa11fb3fe416a955be2cbe7ec96f012c99 3298 4bc3f16a41', 3299 / recipients / [ 3300 [ 3301 / protected / h'a101381a' / { 3302 \ alg \ 1:-27 \ ECDH-SS + HKDF-256 \ 3303 } / , 3304 / unprotected / { 3305 / static kid / -3:'peregrin.took@tuckborough.example', 3306 / kid / 4:'meriadoc.brandybuck@buckland.example', 3307 / U nonce / -22:h'4d8553e7e74f3c6a3a9dd3ef286a8195cbf8a23d 3308 19558ccfec7d34b824f42d92bd06bd2c7f0271f0214e141fb779ae2856abf585a583 3309 68b017e7f2a9e5ce4db5' 3310 }, 3311 / ciphertext / h'' 3312 ] 3313 ] 3314 ] 3315 ) 3317 C.5.3. Wrapped MAC 3319 This example uses the following: 3321 o MAC: AES-MAC, 128-bit key, truncated to 64 bits 3323 o Recipient class: AES Key Wrap w/ a pre-shared 256-bit key 3325 Size of binary file is 109 bytes 3326 97( 3327 [ 3328 / protected / h'a1010e' / { 3329 \ alg \ 1:14 \ AES-CBC-MAC-128//64 \ 3330 } / , 3331 / unprotected / {}, 3332 / payload / 'This is the content.', 3333 / tag / h'36f5afaf0bab5d43', 3334 / recipients / [ 3335 [ 3336 / protected / h'', 3337 / unprotected / { 3338 / alg / 1:-5 / A256KW /, 3339 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 3340 }, 3341 / ciphertext / h'711ab0dc2fc4585dce27effa6781c8093eba906f227 3342 b6eb0' 3343 ] 3344 ] 3345 ] 3346 ) 3348 C.5.4. Multi-Recipient MACed Message 3350 This example uses the following: 3352 o MAC: HMAC w/ SHA-256, 128-bit key 3354 o Recipient class: Uses three different methods 3356 1. ECDH Ephemeral-Static, Curve P-521, AES Key Wrap w/ 128-bit 3357 key 3359 2. AES Key Wrap w/ 256-bit key 3361 Size of binary file is 309 bytes 3362 97( 3363 [ 3364 / protected / h'a10105' / { 3365 \ alg \ 1:5 \ HMAC 256//256 \ 3366 } / , 3367 / unprotected / {}, 3368 / payload / 'This is the content.', 3369 / tag / h'bf48235e809b5c42e995f2b7d5fa13620e7ed834e337f6aa43df16 3370 1e49e9323e', 3371 / recipients / [ 3372 [ 3373 / protected / h'a101381c' / { 3374 \ alg \ 1:-29 \ ECHD-ES+A128KW \ 3375 } / , 3376 / unprotected / { 3377 / ephemeral / -1:{ 3378 / kty / 1:2, 3379 / crv / -1:3, 3380 / x / -2:h'0043b12669acac3fd27898ffba0bcd2e6c366d53bc4db 3381 71f909a759304acfb5e18cdc7ba0b13ff8c7636271a6924b1ac63c02688075b55ef2 3382 d613574e7dc242f79c3', 3383 / y / -3:true 3384 }, 3385 / kid / 4:'bilbo.baggins@hobbiton.example' 3386 }, 3387 / ciphertext / h'339bc4f79984cdc6b3e6ce5f315a4c7d2b0ac466fce 3388 a69e8c07dfbca5bb1f661bc5f8e0df9e3eff5' 3389 ], 3390 [ 3391 / protected / h'', 3392 / unprotected / { 3393 / alg / 1:-5 / A256KW /, 3394 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 3395 }, 3396 / ciphertext / h'0b2c7cfce04e98276342d6476a7723c090dfdd15f9a 3397 518e7736549e998370695e6d6a83b4ae507bb' 3398 ] 3399 ] 3400 ] 3401 ) 3403 C.6. Examples of MAC0 Messages 3405 C.6.1. Shared Secret Direct MAC 3407 This example uses the following: 3409 o MAC: AES-CMAC, 256-bit key, truncated to 64 bits 3410 o Recipient class: direct shared secret 3412 Size of binary file is 37 bytes 3414 17( 3415 [ 3416 / protected / h'a1010f' / { 3417 \ alg \ 1:15 \ AES-CBC-MAC-256//64 \ 3418 } / , 3419 / unprotected / {}, 3420 / payload / 'This is the content.', 3421 / tag / h'726043745027214f' 3422 ] 3423 ) 3425 Note that this example uses the same inputs as Appendix C.5.1. 3427 C.7. COSE Keys 3429 C.7.1. Public Keys 3431 This is an example of a COSE Key Set. This example includes the 3432 public keys for all of the previous examples. 3434 In order the keys are: 3436 o An EC key with a kid of "meriadoc.brandybuck@buckland.example" 3438 o An EC key with a kid of "peregrin.took@tuckborough.example" 3440 o An EC key with a kid of "bilbo.baggins@hobbiton.example" 3442 o An EC key with a kid of "11" 3444 Size of binary file is 481 bytes 3446 [ 3447 { 3448 -1:1, 3449 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 3450 8551d', 3451 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 3452 4d19c', 3453 1:2, 3454 2:'meriadoc.brandybuck@buckland.example' 3455 }, 3456 { 3457 -1:1, 3458 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 3459 09eff', 3460 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 3461 c117e', 3462 1:2, 3463 2:'11' 3464 }, 3465 { 3466 -1:3, 3467 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 3468 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 3469 f42ad', 3470 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 3471 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 3472 d9475', 3473 1:2, 3474 2:'bilbo.baggins@hobbiton.example' 3475 }, 3476 { 3477 -1:1, 3478 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 3479 d6280', 3480 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 3481 822bb', 3482 1:2, 3483 2:'peregrin.took@tuckborough.example' 3484 } 3485 ] 3487 C.7.2. Private Keys 3489 This is an example of a COSE Key Set. This example includes the 3490 private keys for all of the previous examples. 3492 In order the keys are: 3494 o An EC key with a kid of "meriadoc.brandybuck@buckland.example" 3496 o A shared-secret key with a kid of "our-secret" 3498 o An EC key with a kid of "peregrin.took@tuckborough.example" 3500 o A shared-secret key with a kid of "018c0ae5-4d9b-471b- 3501 bfd6-eef314bc7037" 3503 o An EC key with a kid of "bilbo.baggins@hobbiton.example" 3505 o An EC key with a kid of "11" 3507 Size of binary file is 816 bytes 3509 [ 3510 { 3511 1:2, 3512 2:'meriadoc.brandybuck@buckland.example', 3513 -1:1, 3514 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 3515 8551d', 3516 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 3517 4d19c', 3518 -4:h'aff907c99f9ad3aae6c4cdf21122bce2bd68b5283e6907154ad911840fa 3519 208cf' 3520 }, 3521 { 3522 1:2, 3523 2:'11', 3524 -1:1, 3525 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 3526 09eff', 3527 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 3528 c117e', 3529 -4:h'57c92077664146e876760c9520d054aa93c3afb04e306705db609030850 3530 7b4d3' 3531 }, 3532 { 3533 1:2, 3534 2:'bilbo.baggins@hobbiton.example', 3535 -1:3, 3536 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 3537 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 3538 f42ad', 3539 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 3540 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 3541 d9475', 3542 -4:h'00085138ddabf5ca975f5860f91a08e91d6d5f9a76ad4018766a476680b 3543 55cd339e8ab6c72b5facdb2a2a50ac25bd086647dd3e2e6e99e84ca2c3609fdf177f 3544 eb26d' 3545 }, 3546 { 3547 1:4, 3548 2:'our-secret', 3549 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 3550 27188' 3551 }, 3552 { 3553 1:2, 3554 -1:1, 3555 2:'peregrin.took@tuckborough.example', 3556 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 3557 d6280', 3558 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 3559 822bb', 3560 -4:h'02d1f7e6f26c43d4868d87ceb2353161740aacf1f7163647984b522a848 3561 df1c3' 3562 }, 3563 { 3564 1:4, 3565 2:'our-secret2', 3566 -1:h'849b5786457c1491be3a76dcea6c4271' 3567 }, 3568 { 3569 1:4, 3570 2:'018c0ae5-4d9b-471b-bfd6-eef314bc7037', 3571 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 3572 27188' 3573 } 3574 ] 3576 Acknowledgments 3578 This document is a product of the COSE working group of the IETF. 3580 The following individuals are to blame for getting me started on this 3581 project in the first place: Richard Barnes, Matt Miller, and Martin 3582 Thomson. 3584 The initial version of the specification was based to some degree on 3585 the outputs of the JOSE and S/MIME working groups. 3587 The following individuals provided input into the final form of the 3588 document: Carsten Bormann, John Bradley, Brain Campbell, Michael B. 3590 Jones, Ilari Liusvaara, Francesca Palombini, Ludwig Seitz, and Goran 3591 Selander. 3593 Author's Address 3595 Jim Schaad 3596 August Cellars 3598 Email: ietf@augustcellars.com