idnits 2.17.1 draft-ietf-cose-rfc8152bis-struct-02.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The abstract seems to contain references ([I-D.ietf-cose-RFC8152bis-algs]), which it shouldn't. Please replace those with straight textual mentions of the documents in question. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (March 11, 2019) is 1866 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' == Outdated reference: A later version (-12) exists of draft-ietf-cose-rfc8152bis-algs-01 ** Downref: Normative reference to an Informational draft: draft-ietf-cose-rfc8152bis-algs (ref. 'I-D.ietf-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-07 == 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: 4 errors (**), 0 flaws (~~), 4 warnings (==), 5 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 COSE Working Group J. Schaad 3 Internet-Draft August Cellars 4 Obsoletes: 8152 (if approved) March 11, 2019 5 Intended status: Standards Track 6 Expires: September 12, 2019 8 CBOR CBOR Object Signing and Encryption (COSE): Structures and Process 9 draft-ietf-cose-rfc8152bis-struct-02 11 Abstract 13 Concise Binary Object Representation (CBOR) is a data format designed 14 for small code size and small message size. There is a need for the 15 ability to have basic security services defined for this data format. 16 This document defines the CBOR Object Signing and Encryption (COSE) 17 protocol. This specification describes how to create and process 18 signatures, message authentication codes, and encryption using CBOR 19 for serialization. This specification additionally describes how to 20 represent cryptographic keys using CBOR. 22 This document along with [I-D.ietf-cose-rfc8152bis-algs] obsoletes 23 RFC8152. 25 Contributing to this document 27 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 September 12, 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. Changes from RFC8152 . . . . . . . . . . . . . . . . . . 6 70 1.3. Requirements Terminology . . . . . . . . . . . . . . . . 6 71 1.4. CBOR Grammar . . . . . . . . . . . . . . . . . . . . . . 6 72 1.5. CBOR-Related Terminology . . . . . . . . . . . . . . . . 7 73 1.6. Document Terminology . . . . . . . . . . . . . . . . . . 8 74 2. Basic COSE Structure . . . . . . . . . . . . . . . . . . . . 8 75 3. Header Parameters . . . . . . . . . . . . . . . . . . . . . . 11 76 3.1. Common COSE Headers Parameters . . . . . . . . . . . . . 13 77 4. Signing Objects . . . . . . . . . . . . . . . . . . . . . . . 17 78 4.1. Signing with One or More Signers . . . . . . . . . . . . 17 79 4.2. Signing with One Signer . . . . . . . . . . . . . . . . . 19 80 4.3. Externally Supplied Data . . . . . . . . . . . . . . . . 20 81 4.4. Signing and Verification Process . . . . . . . . . . . . 21 82 4.5. Computing Counter Signatures . . . . . . . . . . . . . . 22 83 5. Encryption Objects . . . . . . . . . . . . . . . . . . . . . 23 84 5.1. Enveloped COSE Structure . . . . . . . . . . . . . . . . 23 85 5.1.1. Content Key Distribution Methods . . . . . . . . . . 25 86 5.2. Single Recipient Encrypted . . . . . . . . . . . . . . . 25 87 5.3. How to Encrypt and Decrypt for AEAD Algorithms . . . . . 26 88 5.4. How to Encrypt and Decrypt for AE Algorithms . . . . . . 28 89 6. MAC Objects . . . . . . . . . . . . . . . . . . . . . . . . . 30 90 6.1. MACed Message with Recipients . . . . . . . . . . . . . . 30 91 6.2. MACed Messages with Implicit Key . . . . . . . . . . . . 31 92 6.3. How to Compute and Verify a MAC . . . . . . . . . . . . . 32 93 7. Key Objects . . . . . . . . . . . . . . . . . . . . . . . . . 33 94 7.1. COSE Key Common Parameters . . . . . . . . . . . . . . . 34 95 8. Signature Algorithms . . . . . . . . . . . . . . . . . . . . 37 96 9. Message Authentication Code (MAC) Algorithms . . . . . . . . 38 97 10. Content Encryption Algorithms . . . . . . . . . . . . . . . . 39 98 11. Key Derivation Functions (KDFs) . . . . . . . . . . . . . . . 39 99 12. Content Key Distribution Methods . . . . . . . . . . . . . . 40 100 12.1. Direct Encryption . . . . . . . . . . . . . . . . . . . 40 101 12.2. Key Wrap . . . . . . . . . . . . . . . . . . . . . . . . 41 102 12.3. Key Transport . . . . . . . . . . . . . . . . . . . . . 41 103 12.4. Direct Key Agreement . . . . . . . . . . . . . . . . . . 42 104 12.5. Key Agreement with Key Wrap . . . . . . . . . . . . . . 43 105 13. CBOR Encoder Restrictions . . . . . . . . . . . . . . . . . . 43 106 14. Application Profiling Considerations . . . . . . . . . . . . 44 107 15. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 45 108 15.1. CBOR Tag Assignment . . . . . . . . . . . . . . . . . . 45 109 15.2. COSE Header Parameters Registry . . . . . . . . . . . . 45 110 15.3. COSE Header Algorithm Parameters Registry . . . . . . . 45 111 15.4. COSE Key Common Parameters Registry . . . . . . . . . . 46 112 15.5. Media Type Registrations . . . . . . . . . . . . . . . . 46 113 15.5.1. COSE Security Message . . . . . . . . . . . . . . . 46 114 15.5.2. COSE Key Media Type . . . . . . . . . . . . . . . . 47 115 15.6. CoAP Content-Formats Registry . . . . . . . . . . . . . 49 116 15.7. Expert Review Instructions . . . . . . . . . . . . . . . 49 117 16. Security Considerations . . . . . . . . . . . . . . . . . . . 50 118 17. Implementation Status . . . . . . . . . . . . . . . . . . . . 52 119 17.1. Author's Versions . . . . . . . . . . . . . . . . . . . 52 120 17.2. Java Script Version . . . . . . . . . . . . . . . . . . 53 121 17.3. Python Version . . . . . . . . . . . . . . . . . . . . . 54 122 17.4. COSE Testing Library . . . . . . . . . . . . . . . . . . 54 123 18. References . . . . . . . . . . . . . . . . . . . . . . . . . 54 124 18.1. Normative References . . . . . . . . . . . . . . . . . . 54 125 18.2. Informative References . . . . . . . . . . . . . . . . . 56 126 Appendix A. Guidelines for External Data Authentication of 127 Algorithms . . . . . . . . . . . . . . . . . . . . . 58 128 A.1. Algorithm Identification . . . . . . . . . . . . . . . . 58 129 A.2. Counter Signature without Headers . . . . . . . . . . . . 61 130 Appendix B. Two Layers of Recipient Information . . . . . . . . 62 131 Appendix C. Examples . . . . . . . . . . . . . . . . . . . . . . 64 132 C.1. Examples of Signed Messages . . . . . . . . . . . . . . . 65 133 C.1.1. Single Signature . . . . . . . . . . . . . . . . . . 65 134 C.1.2. Multiple Signers . . . . . . . . . . . . . . . . . . 66 135 C.1.3. Counter Signature . . . . . . . . . . . . . . . . . . 67 136 C.1.4. Signature with Criticality . . . . . . . . . . . . . 68 137 C.2. Single Signer Examples . . . . . . . . . . . . . . . . . 69 138 C.2.1. Single ECDSA Signature . . . . . . . . . . . . . . . 69 139 C.3. Examples of Enveloped Messages . . . . . . . . . . . . . 70 140 C.3.1. Direct ECDH . . . . . . . . . . . . . . . . . . . . . 70 141 C.3.2. Direct Plus Key Derivation . . . . . . . . . . . . . 71 142 C.3.3. Counter Signature on Encrypted Content . . . . . . . 72 143 C.3.4. Encrypted Content with External Data . . . . . . . . 74 144 C.4. Examples of Encrypted Messages . . . . . . . . . . . . . 74 145 C.4.1. Simple Encrypted Message . . . . . . . . . . . . . . 74 146 C.4.2. Encrypted Message with a Partial IV . . . . . . . . . 75 147 C.5. Examples of MACed Messages . . . . . . . . . . . . . . . 75 148 C.5.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 75 149 C.5.2. ECDH Direct MAC . . . . . . . . . . . . . . . . . . . 76 150 C.5.3. Wrapped MAC . . . . . . . . . . . . . . . . . . . . . 77 151 C.5.4. Multi-Recipient MACed Message . . . . . . . . . . . . 78 152 C.6. Examples of MAC0 Messages . . . . . . . . . . . . . . . . 79 153 C.6.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 79 154 C.7. COSE Keys . . . . . . . . . . . . . . . . . . . . . . . . 80 155 C.7.1. Public Keys . . . . . . . . . . . . . . . . . . . . . 80 156 C.7.2. Private Keys . . . . . . . . . . . . . . . . . . . . 81 157 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 83 158 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 84 160 1. Introduction 162 There has been an increased focus on small, constrained devices that 163 make up the Internet of Things (IoT). One of the standards that has 164 come out of this process is "Concise Binary Object Representation 165 (CBOR)" [RFC7049]. CBOR extended the data model of the JavaScript 166 Object Notation (JSON) [RFC8259] by allowing for binary data, among 167 other changes. CBOR has been adopted by several of the IETF working 168 groups dealing with the IoT world as their encoding of data 169 structures. CBOR was designed specifically to be both small in terms 170 of messages transport and implementation size and be a schema-free 171 decoder. A need exists to provide message security services for IoT, 172 and using CBOR as the message-encoding format makes sense. 174 The JOSE working group produced a set of documents [RFC7515] 175 [RFC7516] [RFC7517] [RFC7518] using JSON that specified how to 176 process encryption, signatures, and Message Authentication Code (MAC) 177 operations and how to encode keys using JSON. This document along 178 with [I-D.ietf-cose-rfc8152bis-algs] defines the CBOR Object Signing 179 and Encryption (COSE) standard, which does the same thing for the 180 CBOR encoding format. While there is a strong attempt to keep the 181 flavor of the original JSON Object Signing and Encryption (JOSE) 182 documents, two considerations are taken into account: 184 o CBOR has capabilities that are not present in JSON and are 185 appropriate to use. One example of this is the fact that CBOR has 186 a method of encoding binary directly without first converting it 187 into a base64-encoded string. 189 o COSE is not a direct copy of the JOSE specification. In the 190 process of creating COSE, decisions that were made for JOSE were 191 re-examined. In many cases, different results were decided on as 192 the criteria were not always the same. 194 This document contains: 196 o The description of the structure for the CBOR objects which are 197 transmitted over the wire. Two objects are defined for 198 encryption, signing and message authentication. One object is 199 defined for transporting keys and one for transporting groups of 200 keys. 202 o The procedures used to compute build the inputs to the 203 cryptographic functions required for each of the structures. 205 o A starting set of attributes that apply to the different security 206 objects. 208 This document does not contain the rules and procedures for using 209 specific cryptographic algorithms. Details on specific algorithms 210 can be found in [I-D.ietf-cose-rfc8152bis-algs] and [RFC8230]. 211 Details for additional algorithms are expected to be defined in 212 future documents. 214 One feature that is present in CMS [RFC5652] that is not present in 215 this standard is a digest structure. This omission is deliberate. 216 It is better for the structure to be defined in each document as 217 different protocols will want to include a different set of fields as 218 part of the structure. While an algorithm identifier and the digesst 219 value are going to be common to all applications, the two values may 220 not always be adjacent as the algorithm could be defined once with 221 multiple values. Applications may additionally want to defined 222 additional data fields as part of the stucture. A common structure 223 is going to include a URI or other pointer to where the data that is 224 being hashed is kept, allowing this to be application specific. 226 1.1. Design Changes from JOSE 228 o Define a single top message structure so that encrypted, signed, 229 and MACed messages can easily be identified and still have a 230 consistent view. 232 o Signed messages distinguish between the protected and unprotected 233 parameters that relate to the content from those that relate to 234 the signature. 236 o MACed messages are separated from signed messages. 238 o MACed messages have the ability to use the same set of recipient 239 algorithms as enveloped messages for obtaining the MAC 240 authentication key. 242 o Use binary encodings for binary data rather than base64url 243 encodings. 245 o Combine the authentication tag for encryption algorithms with the 246 ciphertext. 248 o The set of cryptographic algorithms has been expanded in some 249 directions and trimmed in others. 251 1.2. Changes from RFC8152 253 o Split the orignal document into this document and 254 [I-D.ietf-cose-rfc8152bis-algs]. 256 o Add some text describing why there is no digest structure defined 257 by COSE. 259 1.3. Requirements Terminology 261 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 262 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 263 "OPTIONAL" in this document are to be interpreted as described in BCP 264 14 [RFC2119] [RFC8174] when, and only when, they appear in all 265 capitals, as shown here. 267 1.4. CBOR Grammar 269 There was not a standard CBOR grammar available when COSE was 270 originally written. For that reason the CBOR structures defined here 271 are described in prose. Since that time CBOR Data Definition 272 Language (CDDL) [I-D.ietf-cbor-cddl] has been published as an RFC. 273 The CBOR grammar presented in this document is compatible with CDDL. 275 The document was developed by first working on the grammar and then 276 developing the prose to go with it. An artifact of this is that the 277 prose was written using the primitive type strings defined by CBOR 278 Data Definition Language (CDDL) [I-D.ietf-cbor-cddl]. In this 279 specification, the following primitive types are used: 281 any -- non-specific value that permits all CBOR values to be 282 placed here. 284 bool -- a boolean value (true: major type 7, value 21; false: 285 major type 7, value 20). 287 bstr -- byte string (major type 2). 289 int -- an unsigned integer or a negative integer. 291 nil -- a null value (major type 7, value 22). 293 nint -- a negative integer (major type 1). 295 tstr -- a UTF-8 text string (major type 3). 297 uint -- an unsigned integer (major type 0). 299 Two syntaxes from CDDL appear in this document as shorthand. These 300 are: 302 FOO / BAR -- indicates that either FOO or BAR can appear here. 304 [+ FOO] -- indicates that the type FOO appears one or more times 305 in an array. 307 As well as the prose description, a version of a CBOR grammar is 308 presented in CDDL. The CDDL grammar is informational; the prose 309 description is normative. 311 The collected CDDL can be extracted from the XML version of this 312 document via the following XPath expression below. (Depending on the 313 XPath evaluator one is using, it may be necessary to deal with > 314 as an entity.) 316 //artwork[@type='CDDL']/text() 318 CDDL expects the initial non-terminal symbol to be the first symbol 319 in the file. For this reason, the first fragment of CDDL is 320 presented here. 322 start = COSE_Messages / COSE_Key / COSE_KeySet / Internal_Types 324 ; This is defined to make the tool quieter: 325 Internal_Types = Sig_structure / Enc_structure / MAC_structure / 326 COSE_KDF_Context 328 The non-terminal Internal_Types is defined for dealing with the 329 automated validation tools used during the writing of this document. 330 It references those non-terminals that are used for security 331 computations but are not emitted for transport. 333 1.5. CBOR-Related Terminology 335 In JSON, maps are called objects and only have one kind of map key: a 336 string. In COSE, we use strings, negative integers, and unsigned 337 integers as map keys. The integers are used for compactness of 338 encoding and easy comparison. The inclusion of strings allows for an 339 additional range of short encoded values to be used as well. Since 340 the word "key" is mainly used in its other meaning, as a 341 cryptographic key, we use the term "label" for this usage as a map 342 key. 344 The presence of a label in a COSE map that is not a string or an 345 integer is an error. Applications can either fail processing or 346 process messages by ignoring incorrect labels; however, they MUST NOT 347 create messages with incorrect labels. 349 A CDDL grammar fragment defines the non-terminal 'label', as in the 350 previous paragraph, and 'values', which permits any value to be used. 352 label = int / tstr 353 values = any 355 1.6. Document Terminology 357 In this document, we use the following terminology: 359 Byte is a synonym for octet. 361 Constrained Application Protocol (CoAP) is a specialized web transfer 362 protocol for use in constrained systems. It is defined in [RFC7252]. 364 Authenticated Encryption (AE) [RFC5116] algorithms are those 365 encryption algorithms that provide an authentication check of the 366 contents algorithm with the encryption service. 368 Authenticated Encryption with Authenticated Data (AEAD) [RFC5116] 369 algorithms provide the same content authentication service as AE 370 algorithms, but they additionally provide for authentication of non- 371 encrypted data as well. 373 2. Basic COSE Structure 375 The COSE object structure is designed so that there can be a large 376 amount of common code when parsing and processing the different types 377 of security messages. All of the message structures are built on the 378 CBOR array type. The first three elements of the array always 379 contain the same information: 381 1. The set of protected header parameters wrapped in a bstr. 383 2. The set of unprotected header parameters as a map. 385 3. The content of the message. The content is either the plaintext 386 or the ciphertext as appropriate. The content may be detached 387 (i.e. transported separately from the COSE structure), but the 388 location is still used. The content is wrapped in a bstr when 389 present and is a nil value when detached. 391 Elements after this point are dependent on the specific message type. 393 COSE messages are built using the concept of layers to separate 394 different types of cryptographic concepts. As an example of how this 395 works, consider the COSE_Encrypt message (Section 5.1). This message 396 type is broken into two layers: the content layer and the recipient 397 layer. In the content layer, the plaintext is encrypted and 398 information about the encrypted message is placed. In the recipient 399 layer, the content encryption key (CEK) is encrypted and information 400 about how it is encrypted for each recipient is placed. A single 401 layer version of the encryption message COSE_Encrypt0 (Section 5.2) 402 is provided for cases where the CEK is pre-shared. 404 Identification of which type of message has been presented is done by 405 the following methods: 407 1. The specific message type is known from the context. This may be 408 defined by a marker in the containing structure or by 409 restrictions specified by the application protocol. 411 2. The message type is identified by a CBOR tag. Messages with a 412 CBOR tag are known in this specification as tagged messages, 413 while those without the CBOR tag are known as untagged messages. 414 This document defines a CBOR tag for each of the message 415 structures. These tags can be found in Table 1. 417 3. When a COSE object is carried in a media type of 'application/ 418 cose', the optional parameter 'cose-type' can be used to identify 419 the embedded object. The parameter is OPTIONAL if the tagged 420 version of the structure is used. The parameter is REQUIRED if 421 the untagged version of the structure is used. The value to use 422 with the parameter for each of the structures can be found in 423 Table 1. 425 4. When a COSE object is carried as a CoAP payload, the CoAP 426 Content-Format Option can be used to identify the message 427 content. The CoAP Content-Format values can be found in Table 2. 428 The CBOR tag for the message structure is not required as each 429 security message is uniquely identified. 431 +-------+---------------+---------------+---------------------------+ 432 | CBOR | cose-type | Data Item | Semantics | 433 | Tag | | | | 434 +-------+---------------+---------------+---------------------------+ 435 | 98 | cose-sign | COSE_Sign | COSE Signed Data Object | 436 | 18 | cose-sign1 | COSE_Sign1 | COSE Single Signer Data | 437 | | | | Object | 438 | 96 | cose-encrypt | COSE_Encrypt | COSE Encrypted Data | 439 | | | | Object | 440 | 16 | cose-encrypt0 | COSE_Encrypt0 | COSE Single Recipient | 441 | | | | Encrypted Data Object | 442 | 97 | cose-mac | COSE_Mac | COSE MACed Data Object | 443 | 17 | cose-mac0 | COSE_Mac0 | COSE Mac w/o Recipients | 444 | | | | Object | 445 +-------+---------------+---------------+---------------------------+ 447 Table 1: COSE Message Identification 449 +--------------------------------------+----------+-----+-----------+ 450 | Media Type | Encoding | ID | Reference | 451 +--------------------------------------+----------+-----+-----------+ 452 | application/cose; cose-type="cose- | | 98 | [RFC8152] | 453 | sign" | | | | 454 | application/cose; cose-type="cose- | | 18 | [RFC8152] | 455 | sign1" | | | | 456 | application/cose; cose-type="cose- | | 96 | [RFC8152] | 457 | encrypt" | | | | 458 | application/cose; cose-type="cose- | | 16 | [RFC8152] | 459 | encrypt0" | | | | 460 | application/cose; cose-type="cose- | | 97 | [RFC8152] | 461 | mac" | | | | 462 | application/cose; cose-type="cose- | | 17 | [RFC8152] | 463 | mac0" | | | | 464 | application/cose-key | | 101 | [RFC8152] | 465 | application/cose-key-set | | 102 | [RFC8152] | 466 +--------------------------------------+----------+-----+-----------+ 468 Table 2: CoAP Content-Formats for COSE 470 The following CDDL fragment identifies all of the top messages 471 defined in this document. Separate non-terminals are defined for the 472 tagged and the untagged versions of the messages. 474 COSE_Messages = COSE_Untagged_Message / COSE_Tagged_Message 476 COSE_Untagged_Message = COSE_Sign / COSE_Sign1 / 477 COSE_Encrypt / COSE_Encrypt0 / 478 COSE_Mac / COSE_Mac0 480 COSE_Tagged_Message = COSE_Sign_Tagged / COSE_Sign1_Tagged / 481 COSE_Encrypt_Tagged / COSE_Encrypt0_Tagged / 482 COSE_Mac_Tagged / COSE_Mac0_Tagged 484 3. Header Parameters 486 The structure of COSE has been designed to have two buckets of 487 information that are not considered to be part of the payload itself, 488 but are used for holding information about content, algorithms, keys, 489 or evaluation hints for the processing of the layer. These two 490 buckets are available for use in all of the structures except for 491 keys. While these buckets are present, they may not all be usable in 492 all instances. For example, while the protected bucket is defined as 493 part of the recipient structure, some of the algorithms used for 494 recipient structures do not provide for authenticated data. If this 495 is the case, the protected bucket is left empty. 497 Both buckets are implemented as CBOR maps. The map key is a 'label' 498 (Section 1.5). The value portion is dependent on the definition for 499 the label. Both maps use the same set of label/value pairs. The 500 integer and string values for labels have been divided into several 501 sections including a standard range, a private range, and a range 502 that is dependent on the algorithm selected. The defined labels can 503 be found in the "COSE Header Parameters" IANA registry 504 (Section 15.2). 506 Two buckets are provided for each layer: 508 protected: Contains parameters about the current layer that are 509 cryptographically protected. This bucket MUST be empty if it is 510 not going to be included in a cryptographic computation. This 511 bucket is encoded in the message as a binary object. This value 512 is obtained by CBOR encoding the protected map and wrapping it in 513 a bstr object. Senders SHOULD encode a zero-length map as a zero- 514 length byte string rather than as a zero-length map (encoded as 515 h'a0'). The zero-length binary encoding is preferred because it 516 is both shorter and the version used in the serialization 517 structures for cryptographic computation. After encoding the map, 518 the value is wrapped in the binary object. Recipients MUST accept 519 both a zero-length binary value and a zero-length map encoded in 520 the binary value. The wrapping allows for the encoding of the 521 protected map to be transported with a greater chance that it will 522 not be altered in transit. (Badly behaved intermediates could 523 decode and re-encode, but this will result in a failure to verify 524 unless the re-encoded byte string is identical to the decoded byte 525 string.) This avoids the problem of all parties needing to be 526 able to do a common canonical encoding. 528 unprotected: Contains parameters about the current layer that are 529 not cryptographically protected. 531 Only parameters that deal with the current layer are to be placed at 532 that layer. As an example of this, the parameter 'content type' 533 describes the content of the message being carried in the message. 534 As such, this parameter is placed only in the content layer and is 535 not placed in the recipient or signature layers. In principle, one 536 should be able to process any given layer without reference to any 537 other layer. With the exception of the COSE_Sign structure, the only 538 data that needs to cross layers is the cryptographic key. 540 The buckets are present in all of the security objects defined in 541 this document. The fields in order are the 'protected' bucket (as a 542 CBOR 'bstr' type) and then the 'unprotected' bucket (as a CBOR 'map' 543 type). The presence of both buckets is required. The parameters 544 that go into the buckets come from the IANA "COSE Header Parameters" 545 registry (Section 15.2). Some common parameters are defined in the 546 next section, but a number of parameters are defined throughout this 547 document. 549 Labels in each of the maps MUST be unique. When processing messages, 550 if a label appears multiple times, the message MUST be rejected as 551 malformed. Applications SHOULD verify that the same label does not 552 occur in both the protected and unprotected headers. If the message 553 is not rejected as malformed, attributes MUST be obtained from the 554 protected bucket before they are obtained from the unprotected 555 bucket. 557 The following CDDL fragment represents the two header buckets. A 558 group "Headers" is defined in CDDL that represents the two buckets in 559 which attributes are placed. This group is used to provide these two 560 fields consistently in all locations. A type is also defined that 561 represents the map of common headers. 563 Headers = ( 564 protected : empty_or_serialized_map, 565 unprotected : header_map 566 ) 568 header_map = { 569 Generic_Headers, 570 * label => values 571 } 573 empty_or_serialized_map = bstr .cbor header_map / bstr .size 0 575 3.1. Common COSE Headers Parameters 577 This section defines a set of common header parameters. A summary of 578 these parameters can be found in Table 3. This table should be 579 consulted to determine the value of label and the type of the value. 581 The set of header parameters defined in this section are: 583 alg: This parameter is used to indicate the algorithm used for the 584 security processing. This parameter MUST be authenticated where 585 the ability to do so exists. This support is provided by AEAD 586 algorithms or construction (COSE_Sign, COSE_Sign1, COSE_Mac, and 587 COSE_Mac0). This authentication can be done either by placing the 588 parameter in the protected header bucket or as part of the 589 externally supplied data. The value is taken from the "COSE 590 Algorithms" registry (see [COSE.Algorithms]). 592 crit: The parameter is used to indicate which protected header 593 labels an application that is processing a message is required to 594 understand. Parameters defined in this document do not need to be 595 included as they should be understood by all implementations. 596 When present, this parameter MUST be placed in the protected 597 header bucket. The array MUST have at least one value in it. 598 Not all labels need to be included in the 'crit' parameter. The 599 rules for deciding which header labels are placed in the array 600 are: 602 * Integer labels in the range of 0 to 8 SHOULD be omitted. 604 * Integer labels in the range -1 to -128 can be omitted as they 605 are algorithm dependent. If an application can correctly 606 process an algorithm, it can be assumed that it will correctly 607 process all of the common parameters associated with that 608 algorithm. Integer labels in the range -129 to -65536 SHOULD 609 be included as these would be less common parameters that might 610 not be generally supported. 612 * Labels for parameters required for an application MAY be 613 omitted. Applications should have a statement if the label can 614 be omitted. 616 The header parameter values indicated by 'crit' can be processed 617 by either the security library code or an application using a 618 security library; the only requirement is that the parameter is 619 processed. If the 'crit' value list includes a value for which 620 the parameter is not in the protected bucket, this is a fatal 621 error in processing the message. 623 content type: This parameter is used to indicate the content type of 624 the data in the payload or ciphertext fields. Integers are from 625 the "CoAP Content-Formats" IANA registry table [COAP.Formats]. 626 Text values following the syntax of "/" 627 where and are defined in Section 4.2 of 628 [RFC6838]. Leading and trailing whitespace is also omitted. 629 Textual content values along with parameters and subparameters can 630 be located using the IANA "Media Types" registry. Applications 631 SHOULD provide this parameter if the content structure is 632 potentially ambiguous. 634 kid: This parameter identifies one piece of data that can be used as 635 input to find the needed cryptographic key. The value of this 636 parameter can be matched against the 'kid' member in a COSE_Key 637 structure. Other methods of key distribution can define an 638 equivalent field to be matched. Applications MUST NOT assume that 639 'kid' values are unique. There may be more than one key with the 640 same 'kid' value, so all of the keys associated with this 'kid' 641 may need to be checked. The internal structure of 'kid' values is 642 not defined and cannot be relied on by applications. Key 643 identifier values are hints about which key to use. This is not a 644 security-critical field. For this reason, it can be placed in the 645 unprotected headers bucket. 647 IV: This parameter holds the Initialization Vector (IV) value. For 648 some symmetric encryption algorithms, this may be referred to as a 649 nonce. The IV can be placed in the unprotected header as 650 modifying the IV will cause the decryption to yield plaintext that 651 is readily detectable as garbled. 653 Partial IV: This parameter holds a part of the IV value. When using 654 the COSE_Encrypt0 structure, a portion of the IV can be part of 655 the context associated with the key. This field is used to carry 656 a value that causes the IV to be changed for each message. The IV 657 can be placed in the unprotected header as modifying the IV will 658 cause the decryption to yield plaintext that is readily detectable 659 as garbled. The 'Initialization Vector' and 'Partial 660 Initialization Vector' parameters MUST NOT both be present in the 661 same security layer. 663 The message IV is generated by the following steps: 665 1. Left-pad the Partial IV with zeros to the length of IV. 667 2. XOR the padded Partial IV with the context IV. 669 counter signature: This parameter holds one or more counter 670 signature values. Counter signatures provide a method of having a 671 second party sign some data. The counter signature parameter can 672 occur as an unprotected attribute in any of the following 673 structures: COSE_Sign1, COSE_Signature, COSE_Encrypt, 674 COSE_recipient, COSE_Encrypt0, COSE_Mac, and COSE_Mac0. These 675 structures all have the same beginning elements, so that a 676 consistent calculation of the counter signature can be computed. 677 Details on computing counter signatures are found in Section 4.5. 679 +-----------+-------+----------------+-------------+----------------+ 680 | Name | Label | Value Type | Value | Description | 681 | | | | Registry | | 682 +-----------+-------+----------------+-------------+----------------+ 683 | alg | 1 | int / tstr | COSE | Cryptographic | 684 | | | | Algorithms | algorithm to | 685 | | | | registry | use | 686 | crit | 2 | [+ label] | COSE Header | Critical | 687 | | | | Parameters | headers to be | 688 | | | | registry | understood | 689 | content | 3 | tstr / uint | CoAP | Content type | 690 | type | | | Content- | of the payload | 691 | | | | Formats or | | 692 | | | | Media Types | | 693 | | | | registries | | 694 | kid | 4 | bstr | | Key identifier | 695 | IV | 5 | bstr | | Full | 696 | | | | | Initialization | 697 | | | | | Vector | 698 | Partial | 6 | bstr | | Partial | 699 | IV | | | | Initialization | 700 | | | | | Vector | 701 | counter | 7 | COSE_Signature | | CBOR-encoded | 702 | signature | | / [+ | | signature | 703 | | | COSE_Signature | | structure | 704 | | | ] | | | 705 +-----------+-------+----------------+-------------+----------------+ 707 Table 3: Common Header Parameters 709 The CDDL fragment that represents the set of headers defined in this 710 section is given below. Each of the headers is tagged as optional 711 because they do not need to be in every map; headers required in 712 specific maps are discussed above. 714 Generic_Headers = ( 715 ? 1 => int / tstr, ; algorithm identifier 716 ? 2 => [+label], ; criticality 717 ? 3 => tstr / int, ; content type 718 ? 4 => bstr, ; key identifier 719 ? 5 => bstr, ; IV 720 ? 6 => bstr, ; Partial IV 721 ? 7 => COSE_Signature / [+COSE_Signature] ; Counter signature 722 ) 724 4. Signing Objects 726 COSE supports two different signature structures. COSE_Sign allows 727 for one or more signatures to be applied to the same content. 728 COSE_Sign1 is restricted to a single signer. The structures cannot 729 be converted between each other; as the signature computation 730 includes a parameter identifying which structure is being used, the 731 converted structure will fail signature validation. 733 4.1. Signing with One or More Signers 735 The COSE_Sign structure allows for one or more signatures to be 736 applied to a message payload. Parameters relating to the content and 737 parameters relating to the signature are carried along with the 738 signature itself. These parameters may be authenticated by the 739 signature, or just present. An example of a parameter about the 740 content is the content type. Examples of parameters about the 741 signature would be the algorithm and key used to create the signature 742 and counter signatures. 744 RFC 5652 indicates that: 746 When more than one signature is present, the successful validation 747 of one signature associated with a given signer is usually treated 748 as a successful signature by that signer. However, there are some 749 application environments where other rules are needed. An 750 application that employs a rule other than one valid signature for 751 each signer must specify those rules. Also, where simple matching 752 of the signer identifier is not sufficient to determine whether 753 the signatures were generated by the same signer, the application 754 specification must describe how to determine which signatures were 755 generated by the same signer. Support for different communities 756 of recipients is the primary reason that signers choose to include 757 more than one signature. 759 For example, the COSE_Sign structure might include signatures 760 generated with the Edwards-curve Digital Signature Algorithm (EdDSA) 761 [RFC8032] and with the Elliptic Curve Digital Signature Algorithm 762 (ECDSA) [DSS]. This allows recipients to verify the signature 763 associated with one algorithm or the other. More-detailed 764 information on multiple signature evaluations can be found in 765 [RFC5752]. 767 The signature structure can be encoded as either tagged or untagged 768 depending on the context it will be used in. A tagged COSE_Sign 769 structure is identified by the CBOR tag 98. The CDDL fragment that 770 represents this is: 772 COSE_Sign_Tagged = #6.98(COSE_Sign) 774 A COSE Signed Message is defined in two parts. The CBOR object that 775 carries the body and information about the body is called the 776 COSE_Sign structure. The CBOR object that carries the signature and 777 information about the signature is called the COSE_Signature 778 structure. Examples of COSE Signed Messages can be found in 779 Appendix C.1. 781 The COSE_Sign structure is a CBOR array. The fields of the array in 782 order are: 784 protected: This is as described in Section 3. 786 unprotected: This is as described in Section 3. 788 payload: This field contains the serialized content to be signed. 789 If the payload is not present in the message, the application is 790 required to supply the payload separately. The payload is wrapped 791 in a bstr to ensure that it is transported without changes. If 792 the payload is transported separately ("detached content"), then a 793 nil CBOR object is placed in this location, and it is the 794 responsibility of the application to ensure that it will be 795 transported without changes. 797 Note: When a signature with a message recovery algorithm is used 798 (Section 8), the maximum number of bytes that can be recovered is 799 the length of the payload. The size of the payload is reduced by 800 the number of bytes that will be recovered. If all of the bytes 801 of the payload are consumed, then the payload is encoded as a 802 zero-length binary string rather than as being absent. 804 signatures: This field is an array of signatures. Each signature is 805 represented as a COSE_Signature structure. 807 The CDDL fragment that represents the above text for COSE_Sign 808 follows. 810 COSE_Sign = [ 811 Headers, 812 payload : bstr / nil, 813 signatures : [+ COSE_Signature] 814 ] 816 The COSE_Signature structure is a CBOR array. The fields of the 817 array in order are: 819 protected: This is as described in Section 3. 821 unprotected: This is as described in Section 3. 823 signature: This field contains the computed signature value. The 824 type of the field is a bstr. Algorithms MUST specify padding if 825 the signature value is not a multiple of 8 bits. 827 The CDDL fragment that represents the above text for COSE_Signature 828 follows. 830 COSE_Signature = [ 831 Headers, 832 signature : bstr 833 ] 835 4.2. Signing with One Signer 837 The COSE_Sign1 signature structure is used when only one signature is 838 going to be placed on a message. The parameters dealing with the 839 content and the signature are placed in the same pair of buckets 840 rather than having the separation of COSE_Sign. 842 The structure can be encoded as either tagged or untagged depending 843 on the context it will be used in. A tagged COSE_Sign1 structure is 844 identified by the CBOR tag 18. The CDDL fragment that represents 845 this is: 847 COSE_Sign1_Tagged = #6.18(COSE_Sign1) 849 The CBOR object that carries the body, the signature, and the 850 information about the body and signature is called the COSE_Sign1 851 structure. Examples of COSE_Sign1 messages can be found in 852 Appendix C.2. 854 The COSE_Sign1 structure is a CBOR array. The fields of the array in 855 order are: 857 protected: This is as described in Section 3. 859 unprotected: This is as described in Section 3. 861 payload: This is as described in Section 4.1. 863 signature: This field contains the computed signature value. The 864 type of the field is a bstr. 866 The CDDL fragment that represents the above text for COSE_Sign1 867 follows. 869 COSE_Sign1 = [ 870 Headers, 871 payload : bstr / nil, 872 signature : bstr 873 ] 875 4.3. Externally Supplied Data 877 One of the features offered in the COSE document is the ability for 878 applications to provide additional data to be authenticated, but that 879 is not carried as part of the COSE object. The primary reason for 880 supporting this can be seen by looking at the CoAP message structure 881 [RFC7252], where the facility exists for options to be carried before 882 the payload. Examples of data that can be placed in this location 883 would be the CoAP code or CoAP options. If the data is in the header 884 section, then it is available for proxies to help in performing its 885 operations. For example, the Accept Option can be used by a proxy to 886 determine if an appropriate value is in the proxy's cache. But the 887 sender can cause a failure at the server if a proxy, or an attacker, 888 changes the set of accept values by including the field in the 889 application supplied data. 891 This document describes the process for using a byte array of 892 externally supplied authenticated data; the method of constructing 893 the byte array is a function of the application. Applications that 894 use this feature need to define how the externally supplied 895 authenticated data is to be constructed. Such a construction needs 896 to take into account the following issues: 898 o If multiple items are included, applications need to ensure that 899 the same byte string cannot produced if there are different 900 inputs. This would occur by appending the strings 'AB' and 'CDE' 901 or by appending the strings 'ABC' and 'DE'. This is usually 902 addressed by making fields a fixed width and/or encoding the 903 length of the field as part of the output. Using options from 904 CoAP [RFC7252] as an example, these fields use a TLV structure so 905 they can be concatenated without any problems. 907 o If multiple items are included, an order for the items needs to be 908 defined. Using options from CoAP as an example, an application 909 could state that the fields are to be ordered by the option 910 number. 912 o Applications need to ensure that the byte string is going to be 913 the same on both sides. Using options from CoAP might give a 914 problem if the same relative numbering is kept. An intermediate 915 node could insert or remove an option, changing how the relative 916 number is done. An application would need to specify that the 917 relative number must be re-encoded to be relative only to the 918 options that are in the external data. 920 4.4. Signing and Verification Process 922 In order to create a signature, a well-defined byte string is needed. 923 The Sig_structure is used to create the canonical form. This signing 924 and verification process takes in the body information (COSE_Sign or 925 COSE_Sign1), the signer information (COSE_Signature), and the 926 application data (external source). A Sig_structure is a CBOR array. 927 The fields of the Sig_structure in order are: 929 1. A text string identifying the context of the signature. The 930 context string is: 932 "Signature" for signatures using the COSE_Signature structure. 934 "Signature1" for signatures using the COSE_Sign1 structure. 936 "CounterSignature" for signatures used as counter signature 937 attributes. 939 2. The protected attributes from the body structure encoded in a 940 bstr type. If there are no protected attributes, a bstr of 941 length zero is used. 943 3. The protected attributes from the signer structure encoded in a 944 bstr type. If there are no protected attributes, a bstr of 945 length zero is used. This field is omitted for the COSE_Sign1 946 signature structure. 948 4. The protected attributes from the application encoded in a bstr 949 type. If this field is not supplied, it defaults to a zero- 950 length binary string. (See Section 4.3 for application guidance 951 on constructing this field.) 953 5. The payload to be signed encoded in a bstr type. The payload is 954 placed here independent of how it is transported. 956 The CDDL fragment that describes the above text is: 958 Sig_structure = [ 959 context : "Signature" / "Signature1" / "CounterSignature", 960 body_protected : empty_or_serialized_map, 961 ? sign_protected : empty_or_serialized_map, 962 external_aad : bstr, 963 payload : bstr 964 ] 965 How to compute a signature: 967 1. Create a Sig_structure and populate it with the appropriate 968 fields. 970 2. Create the value ToBeSigned by encoding the Sig_structure to a 971 byte string, using the encoding described in Section 13. 973 3. Call the signature creation algorithm passing in K (the key to 974 sign with), alg (the algorithm to sign with), and ToBeSigned (the 975 value to sign). 977 4. Place the resulting signature value in the 'signature' field of 978 the array. 980 The steps for verifying a signature are: 982 1. Create a Sig_structure object and populate it with the 983 appropriate fields. 985 2. Create the value ToBeSigned by encoding the Sig_structure to a 986 byte string, using the encoding described in Section 13. 988 3. Call the signature verification algorithm passing in K (the key 989 to verify with), alg (the algorithm used sign with), ToBeSigned 990 (the value to sign), and sig (the signature to be verified). 992 In addition to performing the signature verification, the application 993 performs the appropriate checks to ensure that the key is correctly 994 paired with the signing identity and that the signing identity is 995 authorized before performing actions. 997 4.5. Computing Counter Signatures 999 Counter signatures provide a method of associating a different 1000 signature generated by different signers with some piece of content. 1001 This is normally used to provide a signature on a signature allowing 1002 for a proof that a signature existed at a given time (e.g., a 1003 Timestamp). In this document, we allow for counter signatures to 1004 exist in a greater number of environments. As an example, it is 1005 possible to place a counter signature in the unprotected attributes 1006 of a COSE_Encrypt object. This would allow for an intermediary to 1007 either verify that the encrypted byte string has not been modified, 1008 without being able to decrypt it, or assert that an encrypted byte 1009 string either existed at a given time or passed through it in terms 1010 of routing (e.g., a proxy signature). 1012 An example of a counter signature on a signature can be found in 1013 Appendix C.1.3. An example of a counter signature in an encryption 1014 object can be found in Appendix C.3.3. 1016 The creation and validation of counter signatures over the different 1017 items relies on the fact that the objects have the same structure. 1018 The elements are a set of protected attributes, a set of unprotected 1019 attributes, and a body, in that order. This means that the 1020 Sig_structure can be used in a uniform manner to get the byte string 1021 for processing a signature. If the counter signature is going to be 1022 computed over a COSE_Encrypt structure, the body_protected and 1023 payload items can be mapped into the Sig_structure in the same manner 1024 as from the COSE_Sign structure. 1026 It should be noted that only a signature algorithm with appendix (see 1027 Section 8) can be used for counter signatures. This is because the 1028 body should be able to be processed without having to evaluate the 1029 counter signature, and this is not possible for signature schemes 1030 with message recovery. 1032 5. Encryption Objects 1034 COSE supports two different encryption structures. COSE_Encrypt0 is 1035 used when a recipient structure is not needed because the key to be 1036 used is known implicitly. COSE_Encrypt is used the rest of the time. 1037 This includes cases where there are multiple recipients or a 1038 recipient algorithm other than direct (i.e. pre-shared secret) is 1039 used. 1041 5.1. Enveloped COSE Structure 1043 The enveloped structure allows for one or more recipients of a 1044 message. There are provisions for parameters about the content and 1045 parameters about the recipient information to be carried in the 1046 message. The protected parameters associated with the content are 1047 authenticated by the content encryption algorithm. The protected 1048 parameters associated with the recipient are authenticated by the 1049 recipient algorithm (when the algorithm supports it). Examples of 1050 parameters about the content are the type of the content and the 1051 content encryption algorithm. Examples of parameters about the 1052 recipient are the recipient's key identifier and the recipient's 1053 encryption algorithm. 1055 The same techniques and nearly the same structure is used for 1056 encrypting both the plaintext and the keys. This is different from 1057 the approach used by both "Cryptographic Message Syntax (CMS)" 1058 [RFC5652] and "JSON Web Encryption (JWE)" [RFC7516] where different 1059 structures are used for the content layer and for the recipient 1060 layer. Two structures are defined: COSE_Encrypt to hold the 1061 encrypted content and COSE_recipient to hold the encrypted keys for 1062 recipients. Examples of encrypted messages can be found in 1063 Appendix C.3. 1065 The COSE_Encrypt structure can be encoded as either tagged or 1066 untagged depending on the context it will be used in. A tagged 1067 COSE_Encrypt structure is identified by the CBOR tag 96. The CDDL 1068 fragment that represents this is: 1070 COSE_Encrypt_Tagged = #6.96(COSE_Encrypt) 1072 The COSE_Encrypt structure is a CBOR array. The fields of the array 1073 in order are: 1075 protected: This is as described in Section 3. 1077 unprotected: This is as described in Section 3. 1079 ciphertext: This field contains the ciphertext encoded as a bstr. 1080 If the ciphertext is to be transported independently of the 1081 control information about the encryption process (i.e., detached 1082 content), then the field is encoded as a nil value. 1084 recipients: This field contains an array of recipient information 1085 structures. The type for the recipient information structure is a 1086 COSE_recipient. 1088 The CDDL fragment that corresponds to the above text is: 1090 COSE_Encrypt = [ 1091 Headers, 1092 ciphertext : bstr / nil, 1093 recipients : [+COSE_recipient] 1094 ] 1096 The COSE_recipient structure is a CBOR array. The fields of the 1097 array in order are: 1099 protected: This is as described in Section 3. 1101 unprotected: This is as described in Section 3. 1103 ciphertext: This field contains the encrypted key encoded as a bstr. 1104 All encoded keys are symmetric keys; the binary value of the key 1105 is the content. If there is not an encrypted key, then this field 1106 is encoded as a nil value. 1108 recipients: This field contains an array of recipient information 1109 structures. The type for the recipient information structure is a 1110 COSE_recipient (an example of this can be found in Appendix B). 1111 If there are no recipient information structures, this element is 1112 absent. 1114 The CDDL fragment that corresponds to the above text for 1115 COSE_recipient is: 1117 COSE_recipient = [ 1118 Headers, 1119 ciphertext : bstr / nil, 1120 ? recipients : [+COSE_recipient] 1121 ] 1123 5.1.1. Content Key Distribution Methods 1125 An encrypted message consists of an encrypted content and an 1126 encrypted CEK for one or more recipients. The CEK is encrypted for 1127 each recipient, using a key specific to that recipient. The details 1128 of this encryption depend on which class the recipient algorithm 1129 falls into. Specific details on each of the classes can be found in 1130 Section 12. A short summary of the five content key distribution 1131 methods is: 1133 direct: The CEK is the same as the identified previously distributed 1134 symmetric key or is derived from a previously distributed secret. 1135 No CEK is transported in the message. 1137 symmetric key-encryption keys (KEK): The CEK is encrypted using a 1138 previously distributed symmetric KEK. Also known as key wrap. 1140 key agreement: The recipient's public key and a sender's private key 1141 are used to generate a pairwise secret, a Key Derivation Function 1142 (KDF) is applied to derive a key, and then the CEK is either the 1143 derived key or encrypted by the derived key. 1145 key transport: The CEK is encrypted with the recipient's public key. 1146 No key transport algorithms are defined in this document. 1148 passwords: The CEK is encrypted in a KEK that is derived from a 1149 password. No password algorithms are defined in this document. 1151 5.2. Single Recipient Encrypted 1153 The COSE_Encrypt0 encrypted structure does not have the ability to 1154 specify recipients of the message. The structure assumes that the 1155 recipient of the object will already know the identity of the key to 1156 be used in order to decrypt the message. If a key needs to be 1157 identified to the recipient, the enveloped structure ought to be 1158 used. 1160 Examples of encrypted messages can be found in Appendix C.3. 1162 The COSE_Encrypt0 structure can be encoded as either tagged or 1163 untagged depending on the context it will be used in. A tagged 1164 COSE_Encrypt0 structure is identified by the CBOR tag 16. The CDDL 1165 fragment that represents this is: 1167 COSE_Encrypt0_Tagged = #6.16(COSE_Encrypt0) 1169 The COSE_Encrypt0 structure is a CBOR array. The fields of the array 1170 in order are: 1172 protected: This is as described in Section 3. 1174 unprotected: This is as described in Section 3. 1176 ciphertext: This is as described in Section 5.1. 1178 The CDDL fragment for COSE_Encrypt0 that corresponds to the above 1179 text is: 1181 COSE_Encrypt0 = [ 1182 Headers, 1183 ciphertext : bstr / nil, 1184 ] 1186 5.3. How to Encrypt and Decrypt for AEAD Algorithms 1188 The encryption algorithm for AEAD algorithms is fairly simple. The 1189 first step is to create a consistent byte string for the 1190 authenticated data structure. For this purpose, we use an 1191 Enc_structure. The Enc_structure is a CBOR array. The fields of the 1192 Enc_structure in order are: 1194 1. A text string identifying the context of the authenticated data 1195 structure. The context string is: 1197 "Encrypt0" for the content encryption of a COSE_Encrypt0 data 1198 structure. 1200 "Encrypt" for the first layer of a COSE_Encrypt data structure 1201 (i.e., for content encryption). 1203 "Enc_Recipient" for a recipient encoding to be placed in an 1204 COSE_Encrypt data structure. 1206 "Mac_Recipient" for a recipient encoding to be placed in a 1207 MACed message structure. 1209 "Rec_Recipient" for a recipient encoding to be placed in a 1210 recipient structure. 1212 2. The protected attributes from the body structure encoded in a 1213 bstr type. If there are no protected attributes, a bstr of 1214 length zero is used. 1216 3. The protected attributes from the application encoded in a bstr 1217 type. If this field is not supplied, it defaults to a zero- 1218 length bstr. (See Section 4.3 for application guidance on 1219 constructing this field.) 1221 The CDDL fragment that describes the above text is: 1223 Enc_structure = [ 1224 context : "Encrypt" / "Encrypt0" / "Enc_Recipient" / 1225 "Mac_Recipient" / "Rec_Recipient", 1226 protected : empty_or_serialized_map, 1227 external_aad : bstr 1228 ] 1230 How to encrypt a message: 1232 1. Create an Enc_structure and populate it with the appropriate 1233 fields. 1235 2. Encode the Enc_structure to a byte string (Additional 1236 Authenticated Data (AAD)), using the encoding described in 1237 Section 13. 1239 3. Determine the encryption key (K). This step is dependent on the 1240 class of recipient algorithm being used. For: 1242 No Recipients: The key to be used is determined by the algorithm 1243 and key at the current layer. Examples are key transport keys 1244 (Section 12.3), key wrap keys (Section 12.2), or pre-shared 1245 secrets. 1247 Direct Encryption and Direct Key Agreement: The key is 1248 determined by the key and algorithm in the recipient 1249 structure. The encryption algorithm and size of the key to be 1250 used are inputs into the KDF used for the recipient. (For 1251 direct, the KDF can be thought of as the identity operation.) 1252 Examples of these algorithms are found in Sections !!! DIRECT- 1253 KDF !!! and !!! ECDH !!! of [I-D.ietf-cose-rfc8152bis-algs]. 1255 Other: The key is randomly or pseudorandomly generated. 1257 4. Call the encryption algorithm with K (the encryption key), P (the 1258 plaintext), and AAD. Place the returned ciphertext into the 1259 'ciphertext' field of the structure. 1261 5. For recipients of the message, recursively perform the encryption 1262 algorithm for that recipient, using K (the encryption key) as the 1263 plaintext. 1265 How to decrypt a message: 1267 1. Create an Enc_structure and populate it with the appropriate 1268 fields. 1270 2. Encode the Enc_structure to a byte string (AAD), using the 1271 encoding described in Section 13. 1273 3. Determine the decryption key. This step is dependent on the 1274 class of recipient algorithm being used. For: 1276 No Recipients: The key to be used is determined by the algorithm 1277 and key at the current layer. Examples are key transport keys 1278 (Section 12.3), key wrap keys (Section 12.2), or pre-shared 1279 secrets. 1281 Direct Encryption and Direct Key Agreement: The key is 1282 determined by the key and algorithm in the recipient 1283 structure. The encryption algorithm and size of the key to be 1284 used are inputs into the KDF used for the recipient. (For 1285 direct, the KDF can be thought of as the identity operation.) 1287 Other: The key is determined by decoding and decrypting one of 1288 the recipient structures. 1290 4. Call the decryption algorithm with K (the decryption key to use), 1291 C (the ciphertext), and AAD. 1293 5.4. How to Encrypt and Decrypt for AE Algorithms 1295 How to encrypt a message: 1297 1. Verify that the 'protected' field is empty. 1299 2. Verify that there was no external additional authenticated data 1300 supplied for this operation. 1302 3. Determine the encryption key. This step is dependent on the 1303 class of recipient algorithm being used. For: 1305 No Recipients: The key to be used is determined by the algorithm 1306 and key at the current layer. Examples are key transport keys 1307 (Section 12.3), key wrap keys (Section 12.2), or pre-shared 1308 secrets. 1310 Direct Encryption and Direct Key Agreement: The key is 1311 determined by the key and algorithm in the recipient 1312 structure. The encryption algorithm and size of the key to be 1313 used are inputs into the KDF used for the recipient. (For 1314 direct, the KDF can be thought of as the identity operation.) 1315 Examples of these algorithms are found in Sections !!!DIRECT- 1316 KDF!!! and !!! ECDH !!! . 1318 Other: The key is randomly generated. 1320 4. Call the encryption algorithm with K (the encryption key to use) 1321 and P (the plaintext). Place the returned ciphertext into the 1322 'ciphertext' field of the structure. 1324 5. For recipients of the message, recursively perform the encryption 1325 algorithm for that recipient, using K (the encryption key) as the 1326 plaintext. 1328 How to decrypt a message: 1330 1. Verify that the 'protected' field is empty. 1332 2. Verify that there was no external additional authenticated data 1333 supplied for this operation. 1335 3. Determine the decryption key. This step is dependent on the 1336 class of recipient algorithm being used. For: 1338 No Recipients: The key to be used is determined by the algorithm 1339 and key at the current layer. Examples are key transport keys 1340 (Section 12.3), key wrap keys (Section 12.2), or pre-shared 1341 secrets. 1343 Direct Encryption and Direct Key Agreement: The key is 1344 determined by the key and algorithm in the recipient 1345 structure. The encryption algorithm and size of the key to be 1346 used are inputs into the KDF used for the recipient. (For 1347 direct, the KDF can be thought of as the identity operation.) 1348 Examples of these algorithms are found in Sections !!! DIRECT- 1349 KDF !!! and !!! ECDH !!! . 1351 Other: The key is determined by decoding and decrypting one of 1352 the recipient structures. 1354 4. Call the decryption algorithm with K (the decryption key to use) 1355 and C (the ciphertext). 1357 6. MAC Objects 1359 COSE supports two different MAC structures. COSE_MAC0 is used when a 1360 recipient structure is not needed because the key to be used is 1361 implicitly known. COSE_MAC is used for all other cases. These 1362 include a requirement for multiple recipients, the key being unknown, 1363 and a recipient algorithm of other than direct. 1365 In this section, we describe the structure and methods to be used 1366 when doing MAC authentication in COSE. This document allows for the 1367 use of all of the same classes of recipient algorithms as are allowed 1368 for encryption. 1370 When using MAC operations, there are two modes in which they can be 1371 used. The first is just a check that the content has not been 1372 changed since the MAC was computed. Any class of recipient algorithm 1373 can be used for this purpose. The second mode is to both check that 1374 the content has not been changed since the MAC was computed and to 1375 use the recipient algorithm to verify who sent it. The classes of 1376 recipient algorithms that support this are those that use a pre- 1377 shared secret or do static-static (SS) key agreement (without the key 1378 wrap step). In both of these cases, the entity that created and sent 1379 the message MAC can be validated. (This knowledge of the sender 1380 assumes that there are only two parties involved and that you did not 1381 send the message to yourself.) The origination property can be 1382 obtained with both of the MAC message structures. 1384 6.1. MACed Message with Recipients 1386 The multiple recipient MACed message uses two structures: the 1387 COSE_Mac structure defined in this section for carrying the body and 1388 the COSE_recipient structure (Section 5.1) to hold the key used for 1389 the MAC computation. Examples of MACed messages can be found in 1390 Appendix C.5. 1392 The MAC structure can be encoded as either tagged or untagged 1393 depending on the context it will be used in. A tagged COSE_Mac 1394 structure is identified by the CBOR tag 97. The CDDL fragment that 1395 represents this is: 1397 COSE_Mac_Tagged = #6.97(COSE_Mac) 1399 The COSE_Mac structure is a CBOR array. The fields of the array in 1400 order are: 1402 protected: This is as described in Section 3. 1404 unprotected: This is as described in Section 3. 1406 payload: This field contains the serialized content to be MACed. If 1407 the payload is not present in the message, the application is 1408 required to supply the payload separately. The payload is wrapped 1409 in a bstr to ensure that it is transported without changes. If 1410 the payload is transported separately (i.e., detached content), 1411 then a nil CBOR value is placed in this location, and it is the 1412 responsibility of the application to ensure that it will be 1413 transported without changes. 1415 tag: This field contains the MAC value. 1417 recipients: This is as described in Section 5.1. 1419 The CDDL fragment that represents the above text for COSE_Mac 1420 follows. 1422 COSE_Mac = [ 1423 Headers, 1424 payload : bstr / nil, 1425 tag : bstr, 1426 recipients :[+COSE_recipient] 1427 ] 1429 6.2. MACed Messages with Implicit Key 1431 In this section, we describe the structure and methods to be used 1432 when doing MAC authentication for those cases where the recipient is 1433 implicitly known. 1435 The MACed message uses the COSE_Mac0 structure defined in this 1436 section for carrying the body. Examples of MACed messages with an 1437 implicit key can be found in Appendix C.6. 1439 The MAC structure can be encoded as either tagged or untagged 1440 depending on the context it will be used in. A tagged COSE_Mac0 1441 structure is identified by the CBOR tag 17. The CDDL fragment that 1442 represents this is: 1444 COSE_Mac0_Tagged = #6.17(COSE_Mac0) 1446 The COSE_Mac0 structure is a CBOR array. The fields of the array in 1447 order are: 1449 protected: This is as described in Section 3. 1451 unprotected: This is as described in Section 3. 1453 payload: This is as described in Section 6.1. 1455 tag: This field contains the MAC value. 1457 The CDDL fragment that corresponds to the above text is: 1459 COSE_Mac0 = [ 1460 Headers, 1461 payload : bstr / nil, 1462 tag : bstr, 1463 ] 1465 6.3. How to Compute and Verify a MAC 1467 In order to get a consistent encoding of the data to be 1468 authenticated, the MAC_structure is used to have a canonical form. 1469 The MAC_structure is a CBOR array. The fields of the MAC_structure 1470 in order are: 1472 1. A text string that identifies the structure that is being 1473 encoded. This string is "MAC" for the COSE_Mac structure. This 1474 string is "MAC0" for the COSE_Mac0 structure. 1476 2. The protected attributes from the COSE_MAC structure. If there 1477 are no protected attributes, a zero-length bstr is used. 1479 3. The protected attributes from the application encoded as a bstr 1480 type. If this field is not supplied, it defaults to a zero- 1481 length binary string. (See Section 4.3 for application guidance 1482 on constructing this field.) 1484 4. The payload to be MACed encoded in a bstr type. The payload is 1485 placed here independent of how it is transported. 1487 The CDDL fragment that corresponds to the above text is: 1489 MAC_structure = [ 1490 context : "MAC" / "MAC0", 1491 protected : empty_or_serialized_map, 1492 external_aad : bstr, 1493 payload : bstr 1494 ] 1496 The steps to compute a MAC are: 1498 1. Create a MAC_structure and populate it with the appropriate 1499 fields. 1501 2. Create the value ToBeMaced by encoding the MAC_structure to a 1502 byte string, using the encoding described in Section 13. 1504 3. Call the MAC creation algorithm passing in K (the key to use), 1505 alg (the algorithm to MAC with), and ToBeMaced (the value to 1506 compute the MAC on). 1508 4. Place the resulting MAC in the 'tag' field of the COSE_Mac or 1509 COSE_Mac0 structure. 1511 5. For COSE_Mac structures, encrypt and encode the MAC key for each 1512 recipient of the message. 1514 The steps to verify a MAC are: 1516 1. Create a MAC_structure object and populate it with the 1517 appropriate fields. 1519 2. Create the value ToBeMaced by encoding the MAC_structure to a 1520 byte string, using the encoding described in Section 13. 1522 3. For COSE_Mac structures, obtain the cryptographic key from one of 1523 the recipients of the message. 1525 4. Call the MAC creation algorithm passing in K (the key to use), 1526 alg (the algorithm to MAC with), and ToBeMaced (the value to 1527 compute the MAC on). 1529 5. Compare the MAC value to the 'tag' field of the COSE_Mac or 1530 COSE_Mac0 structure. 1532 7. Key Objects 1534 A COSE Key structure is built on a CBOR map object. The set of 1535 common parameters that can appear in a COSE Key can be found in the 1536 IANA "COSE Key Common Parameters" registry (Section 15.4). 1538 Additional parameters defined for specific key types can be found in 1539 the IANA "COSE Key Type Parameters" registry ([COSE.KeyParameters]). 1541 A COSE Key Set uses a CBOR array object as its underlying type. The 1542 values of the array elements are COSE Keys. A COSE Key Set MUST have 1543 at least one element in the array. Examples of COSE Key Sets can be 1544 found in Appendix C.7. 1546 Each element in a COSE Key Set MUST be processed independently. If 1547 one element in a COSE Key Set is either malformed or uses a key that 1548 is not understood by an application, that key is ignored and the 1549 other keys are processed normally. 1551 The element "kty" is a required element in a COSE_Key map. 1553 The CDDL grammar describing COSE_Key and COSE_KeySet is: 1555 COSE_Key = { 1556 1 => tstr / int, ; kty 1557 ? 2 => bstr, ; kid 1558 ? 3 => tstr / int, ; alg 1559 ? 4 => [+ (tstr / int) ], ; key_ops 1560 ? 5 => bstr, ; Base IV 1561 * label => values 1562 } 1564 COSE_KeySet = [+COSE_Key] 1566 7.1. COSE Key Common Parameters 1568 This document defines a set of common parameters for a COSE Key 1569 object. Table 4 provides a summary of the parameters defined in this 1570 section. There are also parameters that are defined for specific key 1571 types. Key-type-specific parameters can be found in 1572 [I-D.ietf-cose-rfc8152bis-algs]. 1574 +---------+-------+----------------+------------+-------------------+ 1575 | Name | Label | CBOR Type | Value | Description | 1576 | | | | Registry | | 1577 +---------+-------+----------------+------------+-------------------+ 1578 | kty | 1 | tstr / int | COSE Key | Identification of | 1579 | | | | Types | the key type | 1580 | | | | | | 1581 | kid | 2 | bstr | | Key | 1582 | | | | | identification | 1583 | | | | | value -- match to | 1584 | | | | | kid in message | 1585 | | | | | | 1586 | alg | 3 | tstr / int | COSE | Key usage | 1587 | | | | Algorithms | restriction to | 1588 | | | | | this algorithm | 1589 | | | | | | 1590 | key_ops | 4 | [+ (tstr/int)] | | Restrict set of | 1591 | | | | | permissible | 1592 | | | | | operations | 1593 | | | | | | 1594 | Base IV | 5 | bstr | | Base IV to be | 1595 | | | | | xor-ed with | 1596 | | | | | Partial IVs | 1597 +---------+-------+----------------+------------+-------------------+ 1599 Table 4: Key Map Labels 1601 kty: This parameter is used to identify the family of keys for this 1602 structure and, thus, the set of key-type-specific parameters to be 1603 found. The set of values defined in this document can be found in 1604 [COSE.KeyTypes]. This parameter MUST be present in a key object. 1605 Implementations MUST verify that the key type is appropriate for 1606 the algorithm being processed. The key type MUST be included as 1607 part of the trust decision process. 1609 alg: This parameter is used to restrict the algorithm that is used 1610 with the key. If this parameter is present in the key structure, 1611 the application MUST verify that this algorithm matches the 1612 algorithm for which the key is being used. If the algorithms do 1613 not match, then this key object MUST NOT be used to perform the 1614 cryptographic operation. Note that the same key can be in a 1615 different key structure with a different or no algorithm 1616 specified; however, this is considered to be a poor security 1617 practice. 1619 kid: This parameter is used to give an identifier for a key. The 1620 identifier is not structured and can be anything from a user- 1621 provided string to a value computed on the public portion of the 1622 key. This field is intended for matching against a 'kid' 1623 parameter in a message in order to filter down the set of keys 1624 that need to be checked. 1626 key_ops: This parameter is defined to restrict the set of operations 1627 that a key is to be used for. The value of the field is an array 1628 of values from Table 5. Algorithms define the values of key ops 1629 that are permitted to appear and are required for specific 1630 operations. The set of values matches that in [RFC7517] and 1631 [W3C.WebCrypto]. 1633 Base IV: This parameter is defined to carry the base portion of an 1634 IV. It is designed to be used with the Partial IV header 1635 parameter defined in Section 3.1. This field provides the ability 1636 to associate a Partial IV with a key that is then modified on a 1637 per message basis with the Partial IV. 1639 Extreme care needs to be taken when using a Base IV in an 1640 application. Many encryption algorithms lose security if the same 1641 IV is used twice. 1643 If different keys are derived for each sender, using the same Base 1644 IV with Partial IVs starting at zero is likely to ensure that the 1645 IV would not be used twice for a single key. If different keys 1646 are derived for each sender, starting at the same Base IV is 1647 likely to satisfy this condition. If the same key is used for 1648 multiple senders, then the application needs to provide for a 1649 method of dividing the IV space up between the senders. This 1650 could be done by providing a different base point to start from or 1651 a different Partial IV to start with and restricting the number of 1652 messages to be sent before rekeying. 1654 +---------+-------+-------------------------------------------------+ 1655 | Name | Value | Description | 1656 +---------+-------+-------------------------------------------------+ 1657 | sign | 1 | The key is used to create signatures. Requires | 1658 | | | private key fields. | 1659 | verify | 2 | The key is used for verification of signatures. | 1660 | encrypt | 3 | The key is used for key transport encryption. | 1661 | decrypt | 4 | The key is used for key transport decryption. | 1662 | | | Requires private key fields. | 1663 | wrap | 5 | The key is used for key wrap encryption. | 1664 | key | | | 1665 | unwrap | 6 | The key is used for key wrap decryption. | 1666 | key | | Requires private key fields. | 1667 | derive | 7 | The key is used for deriving keys. Requires | 1668 | key | | private key fields. | 1669 | derive | 8 | The key is used for deriving bits not to be | 1670 | bits | | used as a key. Requires private key fields. | 1671 | MAC | 9 | The key is used for creating MACs. | 1672 | create | | | 1673 | MAC | 10 | The key is used for validating MACs. | 1674 | verify | | | 1675 +---------+-------+-------------------------------------------------+ 1677 Table 5: Key Operation Values 1679 8. Signature Algorithms 1681 There are two signature algorithm schemes. The first is signature 1682 with appendix. In this scheme, the message content is processed and 1683 a signature is produced; the signature is called the appendix. This 1684 is the scheme used by algorithms such as ECDSA and the RSA 1685 Probabilistic Signature Scheme (RSASSA-PSS). (In fact, the SSA in 1686 RSASSA-PSS stands for Signature Scheme with Appendix.) 1688 The signature functions for this scheme are: 1690 signature = Sign(message content, key) 1692 valid = Verification(message content, key, signature) 1694 The second scheme is signature with message recovery (an example of 1695 such an algorithm is [PVSig]). In this scheme, the message content 1696 is processed, but part of it is included in the signature. Moving 1697 bytes of the message content into the signature allows for smaller 1698 signatures; the signature size is still potentially large, but the 1699 message content has shrunk. This has implications for systems 1700 implementing these algorithms and for applications that use them. 1701 The first is that the message content is not fully available until 1702 after a signature has been validated. Until that point, the part of 1703 the message contained inside of the signature is unrecoverable. The 1704 second is that the security analysis of the strength of the signature 1705 is very much based on the structure of the message content. Messages 1706 that are highly predictable require additional randomness to be 1707 supplied as part of the signature process. In the worst case, it 1708 becomes the same as doing a signature with appendix. Finally, in the 1709 event that multiple signatures are applied to a message, all of the 1710 signature algorithms are going to be required to consume the same 1711 number of bytes of message content. This means that the mixing of 1712 the different schemes in a single message is not supported, and if a 1713 recovery signature scheme is used, then the same amount of content 1714 needs to be consumed by all of the signatures. 1716 The signature functions for this scheme are: 1718 signature, message sent = Sign(message content, key) 1720 valid, message content = Verification(message sent, key, signature) 1722 Signature algorithms are used with the COSE_Signature and COSE_Sign1 1723 structures. At this time, only signatures with appendixes are 1724 defined for use with COSE; however, considerable interest has been 1725 expressed in using a signature with message recovery algorithm due to 1726 the effective size reduction that is possible. Implementations will 1727 need to keep this in mind for later possible integration. 1729 9. Message Authentication Code (MAC) Algorithms 1731 Message Authentication Codes (MACs) provide data authentication and 1732 integrity protection. They provide either no or very limited data 1733 origination. A MAC, for example, cannot be used to prove the 1734 identity of the sender to a third party. 1736 MACs use the same scheme as signature with appendix algorithms. The 1737 message content is processed and an authentication code is produced. 1738 The authentication code is frequently called a tag. 1740 The MAC functions are: 1742 tag = MAC_Create(message content, key) 1744 valid = MAC_Verify(message content, key, tag) 1746 MAC algorithms can be based on either a block cipher algorithm (i.e., 1747 AES-MAC) or a hash algorithm (i.e., a Hash-based Message 1748 Authentication Code (HMAC)). This document defines a MAC algorithm 1749 using each of these constructions. 1751 MAC algorithms are used in the COSE_Mac and COSE_Mac0 structures. 1753 10. Content Encryption Algorithms 1755 Content encryption algorithms provide data confidentiality for 1756 potentially large blocks of data using a symmetric key. They provide 1757 integrity on the data that was encrypted; however, they provide 1758 either no or very limited data origination. (One cannot, for 1759 example, be used to prove the identity of the sender to a third 1760 party.) The ability to provide data origination is linked to how the 1761 CEK is obtained. 1763 COSE restricts the set of legal content encryption algorithms to 1764 those that support authentication both of the content and additional 1765 data. The encryption process will generate some type of 1766 authentication value, but that value may be either explicit or 1767 implicit in terms of the algorithm definition. For simplicity's 1768 sake, the authentication code will normally be defined as being 1769 appended to the ciphertext stream. The encryption functions are: 1771 ciphertext = Encrypt(message content, key, additional data) 1773 valid, message content = Decrypt(ciphertext, key, additional data) 1775 Most AEAD algorithms are logically defined as returning the message 1776 content only if the decryption is valid. Many but not all 1777 implementations will follow this convention. The message content 1778 MUST NOT be used if the decryption does not validate. 1780 These algorithms are used in COSE_Encrypt and COSE_Encrypt0. 1782 11. Key Derivation Functions (KDFs) 1784 KDFs are used to take some secret value and generate a different one. 1785 The secret value comes in three flavors: 1787 o Secrets that are uniformly random: This is the type of secret that 1788 is created by a good random number generator. 1790 o Secrets that are not uniformly random: This is type of secret that 1791 is created by operations like key agreement. 1793 o Secrets that are not random: This is the type of secret that 1794 people generate for things like passwords. 1796 General KDFs work well with the first type of secret, can do 1797 reasonably well with the second type of secret, and generally do 1798 poorly with the last type of secret. Functions like PBES2 [RFC8018] 1799 need to be used for non-random secrets. 1801 The same KDF can be set up to deal with the first two types of 1802 secrets in a different way. The KDF defined in !!! HDKF !!! (section 1803 XXXX of [I-D.ietf-cose-rfc8152bis-algs]) is such a function. This is 1804 reflected in the set of algorithms defined around the HMAC-based 1805 Extract-and-Expand Key Derivation Function (HKDF). 1807 When using KDFs, one component that is included is context 1808 information. Context information is used to allow for different 1809 keying information to be derived from the same secret. The use of 1810 context-based keying material is considered to be a good security 1811 practice. 1813 12. Content Key Distribution Methods 1815 Content key distribution methods (recipient algorithms) can be 1816 defined into a number of different classes. COSE has the ability to 1817 support many classes of recipient algorithms. In this section, a 1818 number of classes are listed. The names of the recipient algorithm 1819 classes used here are the same as those defined in [RFC7516]. Other 1820 specifications use different terms for the recipient algorithm 1821 classes or do not support some of the recipient algorithm classes. 1823 12.1. Direct Encryption 1825 The direct encryption class algorithms share a secret between the 1826 sender and the recipient that is used either directly or after 1827 manipulation as the CEK. When direct encryption mode is used, it 1828 MUST be the only mode used on the message. 1830 The COSE_Recipient structure for the recipient is organized as 1831 follows: 1833 o The 'protected' field MUST be a zero-length item unless it is used 1834 in the computation of the content key. 1836 o The 'alg' parameter MUST be present. 1838 o A parameter identifying the shared secret SHOULD be present. 1840 o The 'ciphertext' field MUST be a zero-length item. 1842 o The 'recipients' field MUST be absent. 1844 12.2. Key Wrap 1846 In key wrap mode, the CEK is randomly generated and that key is then 1847 encrypted by a shared secret between the sender and the recipient. 1848 All of the currently defined key wrap algorithms for COSE are AE 1849 algorithms. Key wrap mode is considered to be superior to direct 1850 encryption if the system has any capability for doing random key 1851 generation. This is because the shared key is used to wrap random 1852 data rather than data that has some degree of organization and may in 1853 fact be repeating the same content. The use of key wrap loses the 1854 weak data origination that is provided by the direct encryption 1855 algorithms. 1857 The COSE_Encrypt structure for the recipient is organized as follows: 1859 o The 'protected' field MUST be absent if the key wrap algorithm is 1860 an AE algorithm. 1862 o The 'recipients' field is normally absent, but can be used. 1863 Applications MUST deal with a recipient field being present that 1864 has an unsupported algorthms, not being able to decrypt that 1865 recipient is an acceptable way of dealing with it. Failing to 1866 process the message is not an acceptable way of dealing with it. 1868 o The plaintext to be encrypted is the key from next layer down 1869 (usually the content layer). 1871 o At a minimum, the 'unprotected' field MUST contain the 'alg' 1872 parameter and SHOULD contain a parameter identifying the shared 1873 secret. 1875 12.3. Key Transport 1877 Key transport mode is also called key encryption mode in some 1878 standards. Key transport mode differs from key wrap mode in that it 1879 uses an asymmetric encryption algorithm rather than a symmetric 1880 encryption algorithm to protect the key. A set of key transport 1881 algorithms are defined in [RFC8230]. 1883 When using a key transport algorithm, the COSE_Encrypt structure for 1884 the recipient is organized as follows: 1886 o The 'protected' field MUST be absent. 1888 o The plaintext to be encrypted is the key from the next layer down 1889 (usually the content layer). 1891 o At a minimum, the 'unprotected' field MUST contain the 'alg' 1892 parameter and SHOULD contain a parameter identifying the 1893 asymmetric key. 1895 12.4. Direct Key Agreement 1897 The 'direct key agreement' class of recipient algorithms uses a key 1898 agreement method to create a shared secret. A KDF is then applied to 1899 the shared secret to derive a key to be used in protecting the data. 1900 This key is normally used as a CEK or MAC key, but could be used for 1901 other purposes if more than two layers are in use (see Appendix B). 1903 The most commonly used key agreement algorithm is Diffie-Hellman, but 1904 other variants exist. Since COSE is designed for a store and forward 1905 environment rather than an online environment, many of the DH 1906 variants cannot be used as the receiver of the message cannot provide 1907 any dynamic key material. One side effect of this is that perfect 1908 forward secrecy (see [RFC4949]) is not achievable. A static key will 1909 always be used for the receiver of the COSE object. 1911 Two variants of DH that are supported are: 1913 Ephemeral-Static (ES) DH: where the sender of the message creates 1914 a one-time DH key and uses a static key for the recipient. The 1915 use of the ephemeral sender key means that no additional random 1916 input is needed as this is randomly generated for each message. 1918 Static-Static (SS) DH: where a static key is used for both the 1919 sender and the recipient. The use of static keys allows for the 1920 recipient to get a weak version of data origination for the 1921 message. When static-static key agreement is used, then some 1922 piece of unique data for the KDF is required to ensure that a 1923 different key is created for each message. 1925 When direct key agreement mode is used, there MUST be only one 1926 recipient in the message. This method creates the key directly, and 1927 that makes it difficult to mix with additional recipients. If 1928 multiple recipients are needed, then the version with key wrap needs 1929 to be used. 1931 The COSE_Encrypt structure for the recipient is organized as follows: 1933 o At a minimum, headers MUST contain the 'alg' parameter and SHOULD 1934 contain a parameter identifying the recipient's asymmetric key. 1936 o The headers SHOULD identify the sender's key for the static-static 1937 versions and MUST contain the sender's ephemeral key for the 1938 ephemeral-static versions. 1940 12.5. Key Agreement with Key Wrap 1942 Key Agreement with Key Wrap uses a randomly generated CEK. The CEK 1943 is then encrypted using a key wrap algorithm and a key derived from 1944 the shared secret computed by the key agreement algorithm. The 1945 function for this would be: 1947 encryptedKey = KeyWrap(KDF(DH-Shared, context), CEK) 1949 The COSE_Encrypt structure for the recipient is organized as follows: 1951 o The 'protected' field is fed into the KDF context structure. 1953 o The plaintext to be encrypted is the key from the next layer down 1954 (usually the content layer). 1956 o The 'alg' parameter MUST be present in the layer. 1958 o A parameter identifying the recipient's key SHOULD be present. A 1959 parameter identifying the sender's key SHOULD be present. 1961 13. CBOR Encoder Restrictions 1963 There has been an attempt to limit the number of places where the 1964 document needs to impose restrictions on how the CBOR Encoder needs 1965 to work. We have managed to narrow it down to the following 1966 restrictions: 1968 o The restriction applies to the encoding of the COSE_KDF_Context, 1969 the Sig_structure, the Enc_structure, and the MAC_structure. 1971 o The rules for "Canonical CBOR" (Section 3.9 of RFC 7049) MUST be 1972 used in these locations. The main rule that needs to be enforced 1973 is that all lengths in these structures MUST be encoded such that 1974 they are using definite lengths, and the minimum length encoding 1975 is used. 1977 o Applications MUST NOT generate messages with the same label used 1978 twice as a key in a single map. Applications MUST NOT parse and 1979 process messages with the same label used twice as a key in a 1980 single map. Applications can enforce the parse and process 1981 requirement by using parsers that will fail the parse step or by 1982 using parsers that will pass all keys to the application, and the 1983 application can perform the check for duplicate keys. 1985 14. Application Profiling Considerations 1987 This document is designed to provide a set of security services, but 1988 not impose algorithm implementation requirements for specific usage. 1989 The interoperability requirements are provided for how each of the 1990 individual services are used and how the algorithms are to be used 1991 for interoperability. The requirements about which algorithms and 1992 which services are needed are deferred to each application. 1994 An example of a profile can be found in 1995 [I-D.ietf-core-object-security] where a profiles was developed for 1996 carrying content in combination with CoAP headers. 1998 It is intended that a profile of this document be created that 1999 defines the interoperability requirements for that specific 2000 application. This section provides a set of guidelines and topics 2001 that need to be considered when profiling this document. 2003 o Applications need to determine the set of messages defined in this 2004 document that they will be using. The set of messages corresponds 2005 fairly directly to the set of security services that are needed 2006 and to the security levels needed. 2008 o Applications may define new header parameters for a specific 2009 purpose. Applications will often times select specific header 2010 parameters to use or not to use. For example, an application 2011 would normally state a preference for using either the IV or the 2012 Partial IV parameter. If the Partial IV parameter is specified, 2013 then the application also needs to define how the fixed portion of 2014 the IV is determined. 2016 o When applications use externally defined authenticated data, they 2017 need to define how that data is encoded. This document assumes 2018 that the data will be provided as a byte string. More information 2019 can be found in Section 4.3. 2021 o Applications need to determine the set of security algorithms that 2022 are to be used. When selecting the algorithms to be used as the 2023 mandatory-to-implement set, consideration should be given to 2024 choosing different types of algorithms when two are chosen for a 2025 specific purpose. An example of this would be choosing HMAC- 2026 SHA512 and AES-CMAC as different MAC algorithms; the construction 2027 is vastly different between these two algorithms. This means that 2028 a weakening of one algorithm would be unlikely to lead to a 2029 weakening of the other algorithms. Of course, these algorithms do 2030 not provide the same level of security and thus may not be 2031 comparable for the desired security functionality. 2033 o Applications may need to provide some type of negotiation or 2034 discovery method if multiple algorithms or message structures are 2035 permitted. The method can be as simple as requiring 2036 preconfiguration of the set of algorithms to providing a discovery 2037 method built into the protocol. S/MIME provided a number of 2038 different ways to approach the problem that applications could 2039 follow: 2041 * Advertising in the message (S/MIME capabilities) [RFC5751]. 2043 * Advertising in the certificate (capabilities extension) 2044 [RFC4262]. 2046 * Minimum requirements for the S/MIME, which have been updated 2047 over time [RFC2633] [RFC5751] (note that [RFC2633] has been 2048 obsoleted by [RFC5751]). 2050 15. IANA Considerations 2052 The registeries and registrations listed below were created during 2053 processing of RFC 8152 [RFC8152]. The only known action at this time 2054 is to update the references. 2056 15.1. CBOR Tag Assignment 2058 IANA assigned tags in the "CBOR Tags" registry as part of processing 2059 [RFC8152]. IANA is requested to update the references from [RFC8152] 2060 to this document. 2062 15.2. COSE Header Parameters Registry 2064 IANA created a registry titled "COSE Header Parameters" as part of 2065 processing [RFC8152]. The registry has been created to use the 2066 "Expert Review Required" registration procedure [RFC8126]. 2068 IANA is requested to update the reference for entries in the table 2069 from [RFC8152] to this document. This document does not update the 2070 expert review guidelines provided in [RFC8152]. 2072 15.3. COSE Header Algorithm Parameters Registry 2074 IANA created a registry titled "COSE Header Algorithm Parameters" as 2075 part of processing [RFC8152]. The registry has been created to use 2076 the "Expert Review Required" registration procedure [RFC8126]. 2078 IANA is requested to update the references from [RFC8152] to this 2079 document. This document does not update the expert review guidelines 2080 provided in [RFC8152]. 2082 15.4. COSE Key Common Parameters Registry 2084 IANA created a registry titled "COSE Key Common Parameters" as part 2085 of the processing of [RFC8152]. The registry has been created to use 2086 the "Expert Review Required" registration procedure [RFC8126]. 2088 IANA is requested to update the reference for entries in the table 2089 from [RFC8152] to this document. This document does not update the 2090 expert review guidelines provided in [RFC8152]. 2092 15.5. Media Type Registrations 2094 15.5.1. COSE Security Message 2096 This section registers the 'application/cose' media type in the 2097 "Media Types" registry. These media types are used to indicate that 2098 the content is a COSE message. 2100 Type name: application 2102 Subtype name: cose 2104 Required parameters: N/A 2106 Optional parameters: cose-type 2108 Encoding considerations: binary 2110 Security considerations: See the Security Considerations section 2111 of [[This Document]]. 2113 Interoperability considerations: N/A 2115 Published specification: RFC 8152 2117 Applications that use this media type: IoT applications sending 2118 security content over HTTP(S) transports. 2120 Fragment identifier considerations: N/A 2122 Additional information: 2124 * Deprecated alias names for this type: N/A 2126 * Magic number(s): N/A 2128 * File extension(s): cbor 2129 * Macintosh file type code(s): N/A 2131 Person & email address to contact for further information: 2132 iesg@ietf.org 2134 Intended usage: COMMON 2136 Restrictions on usage: N/A 2138 Author: Jim Schaad, ietf@augustcellars.com 2140 Change Controller: IESG 2142 Provisional registration? No 2144 15.5.2. COSE Key Media Type 2146 This section registers the 'application/cose-key' and 'application/ 2147 cose-key-set' media types in the "Media Types" registry. These media 2148 types are used to indicate, respectively, that content is a COSE_Key 2149 or COSE_KeySet object. 2151 The template for registering 'application/cose-key' is: 2153 Type name: application 2155 Subtype name: cose-key 2157 Required parameters: N/A 2159 Optional parameters: N/A 2161 Encoding considerations: binary 2163 Security considerations: See the Security Considerations section 2164 of [[This Document]]. 2166 Interoperability considerations: N/A 2168 Published specification: RFC 8152 2170 Applications that use this media type: Distribution of COSE based 2171 keys for IoT applications. 2173 Fragment identifier considerations: N/A 2175 Additional information: 2177 * Deprecated alias names for this type: N/A 2179 * Magic number(s): N/A 2181 * File extension(s): cbor 2183 * Macintosh file type code(s): N/A 2185 Person & email address to contact for further information: 2186 iesg@ietf.org 2188 Intended usage: COMMON 2190 Restrictions on usage: N/A 2192 Author: Jim Schaad, ietf@augustcellars.com 2194 Change Controller: IESG 2196 Provisional registration? No 2198 The template for registering 'application/cose-key-set' is: 2200 Type name: application 2202 Subtype name: cose-key-set 2204 Required parameters: N/A 2206 Optional parameters: N/A 2208 Encoding considerations: binary 2210 Security considerations: See the Security Considerations section 2211 of [[This Document]]. 2213 Interoperability considerations: N/A 2215 Published specification: RFC 8152 2217 Applications that use this media type: Distribution of COSE based 2218 keys for IoT applications. 2220 Fragment identifier considerations: N/A 2222 Additional information: 2224 * Deprecated alias names for this type: N/A 2225 * Magic number(s): N/A 2227 * File extension(s): cbor 2229 * Macintosh file type code(s): N/A 2231 Person & email address to contact for further information: 2232 iesg@ietf.org 2234 Intended usage: COMMON 2236 Restrictions on usage: N/A 2238 Author: Jim Schaad, ietf@augustcellars.com 2240 Change Controller: IESG 2242 Provisional registration? No 2244 15.6. CoAP Content-Formats Registry 2246 IANA added the following entries to the "CoAP Content-Formats" 2247 registry while processing [RFC8152]. IANA is requested to update the 2248 reference value from [RFC8152] to [[This Document]]. 2250 15.7. Expert Review Instructions 2252 All of the IANA registries established in this document are defined 2253 as expert review. This section gives some general guidelines for 2254 what the experts should be looking for, but they are being designated 2255 as experts for a reason, so they should be given substantial 2256 latitude. 2258 Expert reviewers should take into consideration the following points: 2260 o Point squatting should be discouraged. Reviewers are encouraged 2261 to get sufficient information for registration requests to ensure 2262 that the usage is not going to duplicate one that is already 2263 registered, and that the point is likely to be used in 2264 deployments. The zones tagged as private use are intended for 2265 testing purposes and closed environments; code points in other 2266 ranges should not be assigned for testing. 2268 o Specifications are required for the standards track range of point 2269 assignment. Specifications should exist for specification 2270 required ranges, but early assignment before a specification is 2271 available is considered to be permissible. Specifications are 2272 needed for the first-come, first-serve range if they are expected 2273 to be used outside of closed environments in an interoperable way. 2274 When specifications are not provided, the description provided 2275 needs to have sufficient information to identify what the point is 2276 being used for. 2278 o Experts should take into account the expected usage of fields when 2279 approving point assignment. The fact that there is a range for 2280 standards track documents does not mean that a standards track 2281 document cannot have points assigned outside of that range. The 2282 length of the encoded value should be weighed against how many 2283 code points of that length are left, the size of device it will be 2284 used on, and the number of code points left that encode to that 2285 size. 2287 o When algorithms are registered, vanity registrations should be 2288 discouraged. One way to do this is to require registrations to 2289 provide additional documentation on security analysis of the 2290 algorithm. Another thing that should be considered is requesting 2291 an opinion on the algorithm from the Crypto Forum Research Group 2292 (CFRG). Algorithms that do not meet the security requirements of 2293 the community and the messages structures should not be 2294 registered. 2296 16. Security Considerations 2298 There are a number of security considerations that need to be taken 2299 into account by implementers of this specification. The security 2300 considerations that are specific to an individual algorithm are 2301 placed next to the description of the algorithm. While some 2302 considerations have been highlighted here, additional considerations 2303 may be found in the documents listed in the references. 2305 Implementations need to protect the private key material for any 2306 individuals. There are some cases in this document that need to be 2307 highlighted on this issue. 2309 o Using the same key for two different algorithms can leak 2310 information about the key. It is therefore recommended that keys 2311 be restricted to a single algorithm. 2313 o Use of 'direct' as a recipient algorithm combined with a second 2314 recipient algorithm exposes the direct key to the second 2315 recipient. 2317 o Several of the algorithms in this document have limits on the 2318 number of times that a key can be used without leaking information 2319 about the key. 2321 The use of ECDH and direct plus KDF (with no key wrap) will not 2322 directly lead to the private key being leaked; the one way function 2323 of the KDF will prevent that. There is, however, a different issue 2324 that needs to be addressed. Having two recipients requires that the 2325 CEK be shared between two recipients. The second recipient therefore 2326 has a CEK that was derived from material that can be used for the 2327 weak proof of origin. The second recipient could create a message 2328 using the same CEK and send it to the first recipient; the first 2329 recipient would, for either static-static ECDH or direct plus KDF, 2330 make an assumption that the CEK could be used for proof of origin 2331 even though it is from the wrong entity. If the key wrap step is 2332 added, then no proof of origin is implied and this is not an issue. 2334 Although it has been mentioned before, the use of a single key for 2335 multiple algorithms has been demonstrated in some cases to leak 2336 information about a key, provide the opportunity for attackers to 2337 forge integrity tags, or gain information about encrypted content. 2338 Binding a key to a single algorithm prevents these problems. Key 2339 creators and key consumers are strongly encouraged not only to create 2340 new keys for each different algorithm, but to include that selection 2341 of algorithm in any distribution of key material and strictly enforce 2342 the matching of algorithms in the key structure to algorithms in the 2343 message structure. In addition to checking that algorithms are 2344 correct, the key form needs to be checked as well. Do not use an 2345 'EC2' key where an 'OKP' key is expected. 2347 Before using a key for transmission, or before acting on information 2348 received, a trust decision on a key needs to be made. Is the data or 2349 action something that the entity associated with the key has a right 2350 to see or a right to request? A number of factors are associated 2351 with this trust decision. Some of the ones that are highlighted here 2352 are: 2354 o What are the permissions associated with the key owner? 2356 o Is the cryptographic algorithm acceptable in the current context? 2358 o Have the restrictions associated with the key, such as algorithm 2359 or freshness, been checked and are they correct? 2361 o Is the request something that is reasonable, given the current 2362 state of the application? 2364 o Have any security considerations that are part of the message been 2365 enforced (as specified by the application or 'crit' parameter)? 2367 There are a large number of algorithms presented in this document 2368 that use nonce values. For all of the nonces defined in this 2369 document, there is some type of restriction on the nonce being a 2370 unique value either for a key or for some other conditions. In all 2371 of these cases, there is no known requirement on the nonce being both 2372 unique and unpredictable; under these circumstances, it's reasonable 2373 to use a counter for creation of the nonce. In cases where one wants 2374 the pattern of the nonce to be unpredictable as well as unique, one 2375 can use a key created for that purpose and encrypt the counter to 2376 produce the nonce value. 2378 One area that has been starting to get exposure is doing traffic 2379 analysis of encrypted messages based on the length of the message. 2380 This specification does not provide for a uniform method of providing 2381 padding as part of the message structure. An observer can 2382 distinguish between two different strings (for example, 'YES' and 2383 'NO') based on the length for all of the content encryption 2384 algorithms that are defined in this document. This means that it is 2385 up to the applications to document how content padding is to be done 2386 in order to prevent or discourage such analysis. (For example, the 2387 strings could be defined as 'YES' and 'NO '.) 2389 17. Implementation Status 2391 This section records the status of known implementations of the 2392 protocol defined by this specification at the time of posting of this 2393 Internet-Draft, and is based on a proposal described in [RFC7942]. 2394 The description of implementations in this section is intended to 2395 assist the IETF in its decision processes in progressing drafts to 2396 RFCs. Please note that the listing of any individual implementation 2397 here does not imply endorsement by the IETF. Furthermore, no effort 2398 has been spent to verify the information presented here that was 2399 supplied by IETF contributors. This is not intended as, and must not 2400 be construed to be, a catalog of available implementations or their 2401 features. Readers are advised to note that other implementations may 2402 exist. 2404 According to [RFC7942], "this will allow reviewers and working groups 2405 to assign due consideration to documents that have the benefit of 2406 running code, which may serve as evidence of valuable experimentation 2407 and feedback that have made the implemented protocols more mature. 2408 It is up to the individual working groups to use this information as 2409 they see fit". 2411 17.1. Author's Versions 2413 There are three different implementations that have been created by 2414 the author of the document both to create the examples that are 2415 included in the document and to validate the structures and 2416 methodology used in the design of COSE. 2418 Implementation Location: https://github.com/cose-wg 2420 Primary Maintainer: Jim Schaad 2422 Languages: There are three different languages that are currently 2423 supported: Java, C# and C. 2425 Cryptography: The Java and C# libraries use Bouncy Castle to 2426 provide the required cryptography. The C version uses OPENSSL 2427 Version 1.0 for the cryptography. 2429 Coverage: The C version currently does not have full countersign 2430 support. THe other two versions do. They do have support to 2431 allow for implicit algorithm support as they allow for the 2432 application to set attributes that are not to be sent in the 2433 message. 2435 Testing: All of the examples in the example library are generated 2436 by the C# library and then validated using the Java and C 2437 libraries. All three libraries have tests to allow for the 2438 creating of the same messages that are in the example library 2439 followed by validating them. These are not compared against the 2440 example library. The Java and C# libraries have unit testing 2441 included. Not all of the MUST statements in the document have 2442 been implemented as part of the libraries. One such statement is 2443 the requirement that unique labels be present. 2445 Licensing: Revised BSD License 2447 17.2. Java Script Version 2449 Implementation Location: https://github.com/erdtman/cose-js 2451 Primary Maintainer: Samuel Erdtman 2453 Languages: JavaScript 2455 Cryptography: TBD 2457 Coverage: Full Encrypt, Signature and MAC objects are supported. 2459 Testing: Basic testing against the common example library. 2461 Licensing: Apache License 2.0 2463 17.3. Python Version 2465 Implementation Location: https://github.com/TimothyClaeys/COSE- 2466 PYTHON 2468 Primary Maintainer: Timothy Claeys 2470 Languages: Python 2472 Cryptography: pyecdsak, crypto python libraries 2474 Coverage: TBD 2476 Testing: Basic testing plus running against the common example 2477 library. 2479 Licensing: BSD 3-Clause License 2481 17.4. COSE Testing Library 2483 Implementation Location: https://github.com/cose-wg/Examples 2485 Primary Maintainer: Jim Schaad 2487 Description: A set of tests for the COSE library is provided as 2488 part of the implementation effort. Both success and fail tests 2489 have been provided. All of the examples in this document are part 2490 of this example set. 2492 Coverage: An attempt has been made to have test cases for every 2493 message type and algorithm in the document. Currently examples 2494 dealing with counter signatures, and ECDH with Curve24459 and 2495 Goldilocks are missing. 2497 Licensing: Public Domain 2499 18. References 2501 18.1. Normative References 2503 [COAP.Formats] 2504 IANA, "CoAP Content-Formats", 2505 . 2508 [COSE.Algorithms] 2509 IANA, "COSE Algorithms", 2510 . 2513 [COSE.KeyParameters] 2514 IANA, "COSE Key Parameters", 2515 . 2518 [COSE.KeyTypes] 2519 IANA, "COSE Key Types", 2520 . 2523 [DSS] National Institute of Standards and Technology, "Digital 2524 Signature Standard (DSS)", FIPS PUB 186-4, 2525 DOI 10.6028/NIST.FIPS.186-4, July 2013, 2526 . 2529 [I-D.ietf-cose-rfc8152bis-algs] 2530 Schaad, J., "CBOR Algorithms for Object Signing and 2531 Encryption (COSE)", draft-ietf-cose-rfc8152bis-algs-01 2532 (work in progress), February 2019. 2534 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2535 Requirement Levels", BCP 14, RFC 2119, 2536 DOI 10.17487/RFC2119, March 1997, 2537 . 2539 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 2540 Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, 2541 October 2013, . 2543 [RFC8032] Josefsson, S. and I. Liusvaara, "Edwards-Curve Digital 2544 Signature Algorithm (EdDSA)", RFC 8032, 2545 DOI 10.17487/RFC8032, January 2017, 2546 . 2548 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2549 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 2550 May 2017, . 2552 18.2. Informative References 2554 [I-D.ietf-cbor-cddl] 2555 Birkholz, H., Vigano, C., and C. Bormann, "Concise data 2556 definition language (CDDL): a notational convention to 2557 express CBOR and JSON data structures", draft-ietf-cbor- 2558 cddl-07 (work in progress), February 2019. 2560 [I-D.ietf-core-object-security] 2561 Selander, G., Mattsson, J., Palombini, F., and L. Seitz, 2562 "Object Security for Constrained RESTful Environments 2563 (OSCORE)", draft-ietf-core-object-security-15 (work in 2564 progress), August 2018. 2566 [PVSig] Brown, D. and D. Johnson, "Formal Security Proofs for a 2567 Signature Scheme with Partial Message Recovery", 2568 DOI 10.1007/3-540-45353-9_11, LNCS Volume 2020, June 2000. 2570 [RFC2633] Ramsdell, B., Ed., "S/MIME Version 3 Message 2571 Specification", RFC 2633, DOI 10.17487/RFC2633, June 1999, 2572 . 2574 [RFC4262] Santesson, S., "X.509 Certificate Extension for Secure/ 2575 Multipurpose Internet Mail Extensions (S/MIME) 2576 Capabilities", RFC 4262, DOI 10.17487/RFC4262, December 2577 2005, . 2579 [RFC4949] Shirey, R., "Internet Security Glossary, Version 2", 2580 FYI 36, RFC 4949, DOI 10.17487/RFC4949, August 2007, 2581 . 2583 [RFC5116] McGrew, D., "An Interface and Algorithms for Authenticated 2584 Encryption", RFC 5116, DOI 10.17487/RFC5116, January 2008, 2585 . 2587 [RFC5652] Housley, R., "Cryptographic Message Syntax (CMS)", STD 70, 2588 RFC 5652, DOI 10.17487/RFC5652, September 2009, 2589 . 2591 [RFC5751] Ramsdell, B. and S. Turner, "Secure/Multipurpose Internet 2592 Mail Extensions (S/MIME) Version 3.2 Message 2593 Specification", RFC 5751, DOI 10.17487/RFC5751, January 2594 2010, . 2596 [RFC5752] Turner, S. and J. Schaad, "Multiple Signatures in 2597 Cryptographic Message Syntax (CMS)", RFC 5752, 2598 DOI 10.17487/RFC5752, January 2010, 2599 . 2601 [RFC5990] Randall, J., Kaliski, B., Brainard, J., and S. Turner, 2602 "Use of the RSA-KEM Key Transport Algorithm in the 2603 Cryptographic Message Syntax (CMS)", RFC 5990, 2604 DOI 10.17487/RFC5990, September 2010, 2605 . 2607 [RFC6838] Freed, N., Klensin, J., and T. Hansen, "Media Type 2608 Specifications and Registration Procedures", BCP 13, 2609 RFC 6838, DOI 10.17487/RFC6838, January 2013, 2610 . 2612 [RFC7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 2613 Application Protocol (CoAP)", RFC 7252, 2614 DOI 10.17487/RFC7252, June 2014, 2615 . 2617 [RFC7515] Jones, M., Bradley, J., and N. Sakimura, "JSON Web 2618 Signature (JWS)", RFC 7515, DOI 10.17487/RFC7515, May 2619 2015, . 2621 [RFC7516] Jones, M. and J. Hildebrand, "JSON Web Encryption (JWE)", 2622 RFC 7516, DOI 10.17487/RFC7516, May 2015, 2623 . 2625 [RFC7517] Jones, M., "JSON Web Key (JWK)", RFC 7517, 2626 DOI 10.17487/RFC7517, May 2015, 2627 . 2629 [RFC7518] Jones, M., "JSON Web Algorithms (JWA)", RFC 7518, 2630 DOI 10.17487/RFC7518, May 2015, 2631 . 2633 [RFC7942] Sheffer, Y. and A. Farrel, "Improving Awareness of Running 2634 Code: The Implementation Status Section", BCP 205, 2635 RFC 7942, DOI 10.17487/RFC7942, July 2016, 2636 . 2638 [RFC8018] Moriarty, K., Ed., Kaliski, B., and A. Rusch, "PKCS #5: 2639 Password-Based Cryptography Specification Version 2.1", 2640 RFC 8018, DOI 10.17487/RFC8018, January 2017, 2641 . 2643 [RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for 2644 Writing an IANA Considerations Section in RFCs", BCP 26, 2645 RFC 8126, DOI 10.17487/RFC8126, June 2017, 2646 . 2648 [RFC8152] Schaad, J., "CBOR Object Signing and Encryption (COSE)", 2649 RFC 8152, DOI 10.17487/RFC8152, July 2017, 2650 . 2652 [RFC8230] Jones, M., "Using RSA Algorithms with CBOR Object Signing 2653 and Encryption (COSE) Messages", RFC 8230, 2654 DOI 10.17487/RFC8230, September 2017, 2655 . 2657 [RFC8259] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 2658 Interchange Format", STD 90, RFC 8259, 2659 DOI 10.17487/RFC8259, December 2017, 2660 . 2662 [W3C.WebCrypto] 2663 Watson, M., "Web Cryptography API", W3C Recommendation, 2664 January 2017, . 2666 Appendix A. Guidelines for External Data Authentication of Algorithms 2668 A portion of the working group has expressed a strong desire to relax 2669 the rule that the algorithm identifier be required to appear in each 2670 level of a COSE object. There are two basic reasons that have been 2671 advanced to support this position. First, the resulting message will 2672 be smaller if the algorithm identifier is omitted from the most 2673 common messages in a CoAP environment. Second, there is a potential 2674 bug that will arise if full checking is not done correctly between 2675 the different places that an algorithm identifier could be placed 2676 (the message itself, an application statement, the key structure that 2677 the sender possesses, and the key structure the recipient possesses). 2679 This appendix lays out how such a change can be made and the details 2680 that an application needs to specify in order to use this option. 2681 Two different sets of details are specified: those needed to omit an 2682 algorithm identifier and those needed to use a variant on the counter 2683 signature attribute that contains no attributes about itself. 2685 A.1. Algorithm Identification 2687 In this section, three sets of recommendations are laid out. The 2688 first set of recommendations apply to having an implicit algorithm 2689 identified for a single layer of a COSE object. The second set of 2690 recommendations apply to having multiple implicit algorithms 2691 identified for multiple layers of a COSE object. The third set of 2692 recommendations apply to having implicit algorithms for multiple COSE 2693 object constructs. 2695 The key words from [RFC2119] are deliberately not used here. This 2696 specification can provide recommendations, but it cannot enforce 2697 them. 2699 This set of recommendations applies to the case where an application 2700 is distributing a fixed algorithm along with the key information for 2701 use in a single COSE object. This normally applies to the smallest 2702 of the COSE objects, specifically COSE_Sign1, COSE_Mac0, and 2703 COSE_Encrypt0, but could apply to the other structures as well. 2705 The following items should be taken into account: 2707 o Applications need to list the set of COSE structures that implicit 2708 algorithms are to be used in. Applications need to require that 2709 the receipt of an explicit algorithm identifier in one of these 2710 structures will lead to the message being rejected. This 2711 requirement is stated so that there will never be a case where 2712 there is any ambiguity about the question of which algorithm 2713 should be used, the implicit or the explicit one. This applies 2714 even if the transported algorithm identifier is a protected 2715 attribute. This applies even if the transported algorithm is the 2716 same as the implicit algorithm. 2718 o Applications need to define the set of information that is to be 2719 considered to be part of a context when omitting algorithm 2720 identifiers. At a minimum, this would be the key identifier (if 2721 needed), the key, the algorithm, and the COSE structure it is used 2722 with. Applications should restrict the use of a single key to a 2723 single algorithm. As noted for some of the algorithms in this 2724 document, the use of the same key in different related algorithms 2725 can lead to leakage of information about the key, leakage about 2726 the data or the ability to perform forgeries. 2728 o In many cases, applications that make the algorithm identifier 2729 implicit will also want to make the context identifier implicit 2730 for the same reason. That is, omitting the context identifier 2731 will decrease the message size (potentially significantly 2732 depending on the length of the identifier). Applications that do 2733 this will need to describe the circumstances where the context 2734 identifier is to be omitted and how the context identifier is to 2735 be inferred in these cases. (An exhaustive search over all of the 2736 keys would normally not be considered to be acceptable.) An 2737 example of how this can be done is to tie the context to a 2738 transaction identifier. Both would be sent on the original 2739 message, but only the transaction identifier would need to be sent 2740 after that point as the context is tied into the transaction 2741 identifier. Another way would be to associate a context with a 2742 network address. All messages coming from a single network 2743 address can be assumed to be associated with a specific context. 2744 (In this case, the address would normally be distributed as part 2745 of the context.) 2747 o Applications cannot rely on key identifiers being unique unless 2748 they take significant efforts to ensure that they are computed in 2749 such a way as to create this guarantee. Even when an application 2750 does this, the uniqueness might be violated if the application is 2751 run in different contexts (i.e., with a different context 2752 provider) or if the system combines the security contexts from 2753 different applications together into a single store. 2755 o Applications should continue the practice of protecting the 2756 algorithm identifier. Since this is not done by placing it in the 2757 protected attributes field, applications should define an 2758 application-specific external data structure that includes this 2759 value. This external data field can be used as such for content 2760 encryption, MAC, and signature algorithms. It can be used in the 2761 SuppPrivInfo field for those algorithms that use a KDF to derive a 2762 key value. Applications may also want to protect other 2763 information that is part of the context structure as well. It 2764 should be noted that those fields, such as the key or a Base IV, 2765 are protected by virtue of being used in the cryptographic 2766 computation and do not need to be included in the external data 2767 field. 2769 The second case is having multiple implicit algorithm identifiers 2770 specified for a multiple layer COSE object. An example of how this 2771 would work is the encryption context that an application specifies, 2772 which contains a content encryption algorithm, a key wrap algorithm, 2773 a key identifier, and a shared secret. The sender omits sending the 2774 algorithm identifier for both the content layer and the recipient 2775 layer leaving only the key identifier. The receiver then uses the 2776 key identifier to get the implicit algorithm identifiers. 2778 The following additional items need to be taken into consideration: 2780 o Applications that want to support this will need to define a 2781 structure that allows for, and clearly identifies, both the COSE 2782 structure to be used with a given key and the structure and 2783 algorithm to be used for the secondary layer. The key for the 2784 secondary layer is computed as normal from the recipient layer. 2786 The third case is having multiple implicit algorithm identifiers, but 2787 targeted at potentially unrelated layers or different COSE objects. 2788 There are a number of different scenarios where this might be 2789 applicable. Some of these scenarios are: 2791 o Two contexts are distributed as a pair. Each of the contexts is 2792 for use with a COSE_Encrypt message. Each context will consist of 2793 distinct secret keys and IVs and potentially even different 2794 algorithms. One context is for sending messages from party A to 2795 party B, and the second context is for sending messages from party 2796 B to party A. This means that there is no chance for a reflection 2797 attack to occur as each party uses different secret keys to send 2798 its messages; a message that is reflected back to it would fail to 2799 decrypt. 2801 o Two contexts are distributed as a pair. The first context is used 2802 for encryption of the message, and the second context is used to 2803 place a counter signature on the message. The intention is that 2804 the second context can be distributed to other entities 2805 independently of the first context. This allows these entities to 2806 validate that the message came from an individual without being 2807 able to decrypt the message and see the content. 2809 o Two contexts are distributed as a pair. The first context 2810 contains a key for dealing with MACed messages, and the second 2811 context contains a key for dealing with encrypted messages. This 2812 allows for a unified distribution of keys to participants for 2813 different types of messages that have different keys, but where 2814 the keys may be used in a coordinated manner. 2816 For these cases, the following additional items need to be 2817 considered: 2819 o Applications need to ensure that the multiple contexts stay 2820 associated. If one of the contexts is invalidated for any reason, 2821 all of the contexts associated with it should also be invalidated. 2823 A.2. Counter Signature without Headers 2825 There is a group of people who want to have a counter signature 2826 parameter that is directly tied to the value being signed, and thus 2827 the authenticated and unauthenticated buckets can be removed from the 2828 message being sent. The focus on this is an even smaller size, as 2829 all of the information on the process of creating the counter 2830 signature is implicit rather than being explicitly carried in the 2831 message. This includes not only the algorithm identifier as 2832 presented above, but also items such as the key identification, which 2833 is always external to the signature structure. This means that the 2834 entities that are doing the validation of the counter signature are 2835 required to infer which key is to be used from context rather than 2836 being explicit. One way of doing this would be to presume that all 2837 data coming from a specific port (or to a specific URL) is to be 2838 validated by a specific key. (Note that this does not require that 2839 the key identifier be part of the value signed as it does not serve a 2840 cryptographic purpose. If the key validates the counter signature, 2841 then it should be presumed that the entity associated with that key 2842 produced the signature.) 2844 When computing the signature for the bare counter signature header, 2845 the same Sig_structure defined in Section 4.4 is used. The 2846 sign_protected field is omitted, as there is no protected header 2847 field in this counter signature header. The value of 2848 "CounterSignature0" is placed in the context field of the 2849 Sig_stucture. 2851 +-------------------+-------+-------+-------+-----------------------+ 2852 | Name | Label | Value | Value | Description | 2853 | | | Type | | | 2854 +-------------------+-------+-------+-------+-----------------------+ 2855 | CounterSignature0 | 9 | bstr | | Counter signature | 2856 | | | | | with implied signer | 2857 | | | | | and headers | 2858 +-------------------+-------+-------+-------+-----------------------+ 2860 Table 6: Header Parameter for CounterSignature0 2862 Appendix B. Two Layers of Recipient Information 2864 All of the currently defined recipient algorithm classes only use two 2865 layers of the COSE_Encrypt structure. The first layer is the message 2866 content, and the second layer is the content key encryption. 2867 However, if one uses a recipient algorithm such as the RSA Key 2868 Encapsulation Mechanism (RSA-KEM) (see Appendix A of RSA-KEM 2869 [RFC5990]), then it makes sense to have three layers of the 2870 COSE_Encrypt structure. 2872 These layers would be: 2874 o Layer 0: The content encryption layer. This layer contains the 2875 payload of the message. 2877 o Layer 1: The encryption of the CEK by a KEK. 2879 o Layer 2: The encryption of a long random secret using an RSA key 2880 and a key derivation function to convert that secret into the KEK. 2882 This is an example of what a triple layer message would look like. 2883 The message has the following layers: 2885 o Layer 0: Has a content encrypted with AES-GCM using a 128-bit key. 2887 o Layer 1: Uses the AES Key Wrap algorithm with a 128-bit key. 2889 o Layer 2: Uses ECDH Ephemeral-Static direct to generate the layer 1 2890 key. 2892 In effect, this example is a decomposed version of using the 2893 ECDH-ES+A128KW algorithm. 2895 Size of binary file is 183 bytes 2896 96( 2897 [ 2898 / protected / h'a10101' / { 2899 \ alg \ 1:1 \ AES-GCM 128 \ 2900 } / , 2901 / unprotected / { 2902 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 2903 }, 2904 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e2852948658f0 2905 811139868826e89218a75715b', 2906 / recipients / [ 2907 [ 2908 / protected / h'', 2909 / unprotected / { 2910 / alg / 1:-3 / A128KW / 2911 }, 2912 / ciphertext / h'dbd43c4e9d719c27c6275c67d628d493f090593db82 2913 18f11', 2914 / recipients / [ 2915 [ 2916 / protected / h'a1013818' / { 2917 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 2918 } / , 2919 / unprotected / { 2920 / ephemeral / -1:{ 2921 / kty / 1:2, 2922 / crv / -1:1, 2923 / x / -2:h'b2add44368ea6d641f9ca9af308b4079aeb519f11 2924 e9b8a55a600b21233e86e68', 2925 / y / -3:false 2926 }, 2927 / kid / 4:'meriadoc.brandybuck@buckland.example' 2928 }, 2929 / ciphertext / h'' 2930 ] 2931 ] 2932 ] 2933 ] 2934 ] 2935 ) 2937 Appendix C. Examples 2939 This appendix includes a set of examples that show the different 2940 features and message types that have been defined in this document. 2941 To make the examples easier to read, they are presented using the 2942 extended CBOR diagnostic notation (defined in [I-D.ietf-cbor-cddl]) 2943 rather than as a binary dump. 2945 A GitHub project has been created at that contains not only the examples presented in this 2947 document, but a more complete set of testing examples as well. Each 2948 example is found in a JSON file that contains the inputs used to 2949 create the example, some of the intermediate values that can be used 2950 in debugging the example and the output of the example presented in 2951 both a hex and a CBOR diagnostic notation format. Some of the 2952 examples at the site are designed failure testing cases; these are 2953 clearly marked as such in the JSON file. If errors in the examples 2954 in this document are found, the examples on GitHub will be updated, 2955 and a note to that effect will be placed in the JSON file. 2957 As noted, the examples are presented using the CBOR's diagnostic 2958 notation. A Ruby-based tool exists that can convert between the 2959 diagnostic notation and binary. This tool can be installed with the 2960 command line: 2962 gem install cbor-diag 2964 The diagnostic notation can be converted into binary files using the 2965 following command line: 2967 diag2cbor.rb < inputfile > outputfile 2969 The examples can be extracted from the XML version of this document 2970 via an XPath expression as all of the artwork is tagged with the 2971 attribute type='CBORdiag'. (Depending on the XPath evaluator one is 2972 using, it may be necessary to deal with > as an entity.) 2974 //artwork[@type='CDDL']/text() 2976 C.1. Examples of Signed Messages 2978 C.1.1. Single Signature 2980 This example uses the following: 2982 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 2984 Size of binary file is 103 bytes 2985 98( 2986 [ 2987 / protected / h'', 2988 / unprotected / {}, 2989 / payload / 'This is the content.', 2990 / signatures / [ 2991 [ 2992 / protected / h'a10126' / { 2993 \ alg \ 1:-7 \ ECDSA 256 \ 2994 } / , 2995 / unprotected / { 2996 / kid / 4:'11' 2997 }, 2998 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 2999 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3000 98f53afd2fa0f30a' 3001 ] 3002 ] 3003 ] 3004 ) 3006 C.1.2. Multiple Signers 3008 This example uses the following: 3010 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3012 o Signature Algorithm: ECDSA w/ SHA-512, Curve P-521 3014 Size of binary file is 277 bytes 3015 98( 3016 [ 3017 / protected / h'', 3018 / unprotected / {}, 3019 / payload / 'This is the content.', 3020 / signatures / [ 3021 [ 3022 / protected / h'a10126' / { 3023 \ alg \ 1:-7 \ ECDSA 256 \ 3024 } / , 3025 / unprotected / { 3026 / kid / 4:'11' 3027 }, 3028 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3029 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3030 98f53afd2fa0f30a' 3031 ], 3032 [ 3033 / protected / h'a1013823' / { 3034 \ alg \ 1:-36 3035 } / , 3036 / unprotected / { 3037 / kid / 4:'bilbo.baggins@hobbiton.example' 3038 }, 3039 / signature / h'00a2d28a7c2bdb1587877420f65adf7d0b9a06635dd1 3040 de64bb62974c863f0b160dd2163734034e6ac003b01e8705524c5c4ca479a952f024 3041 7ee8cb0b4fb7397ba08d009e0c8bf482270cc5771aa143966e5a469a09f613488030 3042 c5b07ec6d722e3835adb5b2d8c44e95ffb13877dd2582866883535de3bb03d01753f 3043 83ab87bb4f7a0297' 3044 ] 3045 ] 3046 ] 3047 ) 3049 C.1.3. Counter Signature 3051 This example uses the following: 3053 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3055 o The same parameters are used for both the signature and the 3056 counter signature. 3058 Size of binary file is 180 bytes 3059 98( 3060 [ 3061 / protected / h'', 3062 / unprotected / { 3063 / countersign / 7:[ 3064 / protected / h'a10126' / { 3065 \ alg \ 1:-7 \ ECDSA 256 \ 3066 } / , 3067 / unprotected / { 3068 / kid / 4:'11' 3069 }, 3070 / signature / h'5ac05e289d5d0e1b0a7f048a5d2b643813ded50bc9e4 3071 9220f4f7278f85f19d4a77d655c9d3b51e805a74b099e1e085aacd97fc29d72f887e 3072 8802bb6650cceb2c' 3073 ] 3074 }, 3075 / payload / 'This is the content.', 3076 / signatures / [ 3077 [ 3078 / protected / h'a10126' / { 3079 \ alg \ 1:-7 \ ECDSA 256 \ 3080 } / , 3081 / unprotected / { 3082 / kid / 4:'11' 3083 }, 3084 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3085 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3086 98f53afd2fa0f30a' 3087 ] 3088 ] 3089 ] 3090 ) 3092 C.1.4. Signature with Criticality 3094 This example uses the following: 3096 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3098 o There is a criticality marker on the "reserved" header parameter 3100 Size of binary file is 125 bytes 3101 98( 3102 [ 3103 / protected / h'a2687265736572766564f40281687265736572766564' / 3104 { 3105 "reserved":false, 3106 \ crit \ 2:[ 3107 "reserved" 3108 ] 3109 } / , 3110 / unprotected / {}, 3111 / payload / 'This is the content.', 3112 / signatures / [ 3113 [ 3114 / protected / h'a10126' / { 3115 \ alg \ 1:-7 \ ECDSA 256 \ 3116 } / , 3117 / unprotected / { 3118 / kid / 4:'11' 3119 }, 3120 / signature / h'3fc54702aa56e1b2cb20284294c9106a63f91bac658d 3121 69351210a031d8fc7c5ff3e4be39445b1a3e83e1510d1aca2f2e8a7c081c7645042b 3122 18aba9d1fad1bd9c' 3123 ] 3124 ] 3125 ] 3126 ) 3128 C.2. Single Signer Examples 3130 C.2.1. Single ECDSA Signature 3132 This example uses the following: 3134 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3136 Size of binary file is 98 bytes 3137 18( 3138 [ 3139 / protected / h'a10126' / { 3140 \ alg \ 1:-7 \ ECDSA 256 \ 3141 } / , 3142 / unprotected / { 3143 / kid / 4:'11' 3144 }, 3145 / payload / 'This is the content.', 3146 / signature / h'8eb33e4ca31d1c465ab05aac34cc6b23d58fef5c083106c4 3147 d25a91aef0b0117e2af9a291aa32e14ab834dc56ed2a223444547e01f11d3b0916e5 3148 a4c345cacb36' 3149 ] 3150 ) 3152 C.3. Examples of Enveloped Messages 3154 C.3.1. Direct ECDH 3156 This example uses the following: 3158 o CEK: AES-GCM w/ 128-bit key 3160 o Recipient class: ECDH Ephemeral-Static, Curve P-256 3162 Size of binary file is 151 bytes 3163 96( 3164 [ 3165 / protected / h'a10101' / { 3166 \ alg \ 1:1 \ AES-GCM 128 \ 3167 } / , 3168 / unprotected / { 3169 / iv / 5:h'c9cf4df2fe6c632bf7886413' 3170 }, 3171 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 3172 c52a357da7a644b8070a151b0', 3173 / recipients / [ 3174 [ 3175 / protected / h'a1013818' / { 3176 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 3177 } / , 3178 / unprotected / { 3179 / ephemeral / -1:{ 3180 / kty / 1:2, 3181 / crv / -1:1, 3182 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 3183 bf054e1c7b4d91d6280', 3184 / y / -3:true 3185 }, 3186 / kid / 4:'meriadoc.brandybuck@buckland.example' 3187 }, 3188 / ciphertext / h'' 3189 ] 3190 ] 3191 ] 3192 ) 3194 C.3.2. Direct Plus Key Derivation 3196 This example uses the following: 3198 o CEK: AES-CCM w/ 128-bit key, truncate the tag to 64 bits 3200 o Recipient class: Use HKDF on a shared secret with the following 3201 implicit fields as part of the context. 3203 * salt: "aabbccddeeffgghh" 3205 * PartyU identity: "lighting-client" 3207 * PartyV identity: "lighting-server" 3209 * Supplementary Public Other: "Encryption Example 02" 3211 Size of binary file is 91 bytes 3213 96( 3214 [ 3215 / protected / h'a1010a' / { 3216 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3217 } / , 3218 / unprotected / { 3219 / iv / 5:h'89f52f65a1c580933b5261a76c' 3220 }, 3221 / ciphertext / h'753548a19b1307084ca7b2056924ed95f2e3b17006dfe93 3222 1b687b847', 3223 / recipients / [ 3224 [ 3225 / protected / h'a10129' / { 3226 \ alg \ 1:-10 3227 } / , 3228 / unprotected / { 3229 / salt / -20:'aabbccddeeffgghh', 3230 / kid / 4:'our-secret' 3231 }, 3232 / ciphertext / h'' 3233 ] 3234 ] 3235 ] 3236 ) 3238 C.3.3. Counter Signature on Encrypted Content 3240 This example uses the following: 3242 o CEK: AES-GCM w/ 128-bit key 3244 o Recipient class: ECDH Ephemeral-Static, Curve P-256 3246 Size of binary file is 326 bytes 3247 96( 3248 [ 3249 / protected / h'a10101' / { 3250 \ alg \ 1:1 \ AES-GCM 128 \ 3251 } / , 3252 / unprotected / { 3253 / iv / 5:h'c9cf4df2fe6c632bf7886413', 3254 / countersign / 7:[ 3255 / protected / h'a1013823' / { 3256 \ alg \ 1:-36 3257 } / , 3258 / unprotected / { 3259 / kid / 4:'bilbo.baggins@hobbiton.example' 3260 }, 3261 / signature / h'00929663c8789bb28177ae28467e66377da12302d7f9 3262 594d2999afa5dfa531294f8896f2b6cdf1740014f4c7f1a358e3a6cf57f4ed6fb02f 3263 cf8f7aa989f5dfd07f0700a3a7d8f3c604ba70fa9411bd10c2591b483e1d2c31de00 3264 3183e434d8fba18f17a4c7e3dfa003ac1cf3d30d44d2533c4989d3ac38c38b71481c 3265 c3430c9d65e7ddff' 3266 ] 3267 }, 3268 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 3269 c52a357da7a644b8070a151b0', 3270 / recipients / [ 3271 [ 3272 / protected / h'a1013818' / { 3273 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 3274 } / , 3275 / unprotected / { 3276 / ephemeral / -1:{ 3277 / kty / 1:2, 3278 / crv / -1:1, 3279 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 3280 bf054e1c7b4d91d6280', 3281 / y / -3:true 3282 }, 3283 / kid / 4:'meriadoc.brandybuck@buckland.example' 3284 }, 3285 / ciphertext / h'' 3286 ] 3287 ] 3288 ] 3289 ) 3291 C.3.4. Encrypted Content with External Data 3293 This example uses the following: 3295 o CEK: AES-GCM w/ 128-bit key 3297 o Recipient class: ECDH static-Static, Curve P-256 with AES Key Wrap 3299 o Externally Supplied AAD: h'0011bbcc22dd44ee55ff660077' 3301 Size of binary file is 173 bytes 3303 96( 3304 [ 3305 / protected / h'a10101' / { 3306 \ alg \ 1:1 \ AES-GCM 128 \ 3307 } / , 3308 / unprotected / { 3309 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 3310 }, 3311 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e28529d8f5335 3312 e5f0165eee976b4a5f6c6f09d', 3313 / recipients / [ 3314 [ 3315 / protected / h'a101381f' / { 3316 \ alg \ 1:-32 \ ECHD-SS+A128KW \ 3317 } / , 3318 / unprotected / { 3319 / static kid / -3:'peregrin.took@tuckborough.example', 3320 / kid / 4:'meriadoc.brandybuck@buckland.example', 3321 / U nonce / -22:h'0101' 3322 }, 3323 / ciphertext / h'41e0d76f579dbd0d936a662d54d8582037de2e366fd 3324 e1c62' 3325 ] 3326 ] 3327 ] 3328 ) 3330 C.4. Examples of Encrypted Messages 3332 C.4.1. Simple Encrypted Message 3334 This example uses the following: 3336 o CEK: AES-CCM w/ 128-bit key and a 64-bit tag 3338 Size of binary file is 52 bytes 3339 16( 3340 [ 3341 / protected / h'a1010a' / { 3342 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3343 } / , 3344 / unprotected / { 3345 / iv / 5:h'89f52f65a1c580933b5261a78c' 3346 }, 3347 / ciphertext / h'5974e1b99a3a4cc09a659aa2e9e7fff161d38ce71cb45ce 3348 460ffb569' 3349 ] 3350 ) 3352 C.4.2. Encrypted Message with a Partial IV 3354 This example uses the following: 3356 o CEK: AES-CCM w/ 128-bit key and a 64-bit tag 3358 o Prefix for IV is 89F52F65A1C580933B52 3360 Size of binary file is 41 bytes 3362 16( 3363 [ 3364 / protected / h'a1010a' / { 3365 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3366 } / , 3367 / unprotected / { 3368 / partial iv / 6:h'61a7' 3369 }, 3370 / ciphertext / h'252a8911d465c125b6764739700f0141ed09192de139e05 3371 3bd09abca' 3372 ] 3373 ) 3375 C.5. Examples of MACed Messages 3377 C.5.1. Shared Secret Direct MAC 3379 This example uses the following: 3381 o MAC: AES-CMAC, 256-bit key, truncated to 64 bits 3383 o Recipient class: direct shared secret 3385 Size of binary file is 57 bytes 3386 97( 3387 [ 3388 / protected / h'a1010f' / { 3389 \ alg \ 1:15 \ AES-CBC-MAC-256//64 \ 3390 } / , 3391 / unprotected / {}, 3392 / payload / 'This is the content.', 3393 / tag / h'9e1226ba1f81b848', 3394 / recipients / [ 3395 [ 3396 / protected / h'', 3397 / unprotected / { 3398 / alg / 1:-6 / direct /, 3399 / kid / 4:'our-secret' 3400 }, 3401 / ciphertext / h'' 3402 ] 3403 ] 3404 ] 3405 ) 3407 C.5.2. ECDH Direct MAC 3409 This example uses the following: 3411 o MAC: HMAC w/SHA-256, 256-bit key 3413 o Recipient class: ECDH key agreement, two static keys, HKDF w/ 3414 context structure 3416 Size of binary file is 214 bytes 3417 97( 3418 [ 3419 / protected / h'a10105' / { 3420 \ alg \ 1:5 \ HMAC 256//256 \ 3421 } / , 3422 / unprotected / {}, 3423 / payload / 'This is the content.', 3424 / tag / h'81a03448acd3d305376eaa11fb3fe416a955be2cbe7ec96f012c99 3425 4bc3f16a41', 3426 / recipients / [ 3427 [ 3428 / protected / h'a101381a' / { 3429 \ alg \ 1:-27 \ ECDH-SS + HKDF-256 \ 3430 } / , 3431 / unprotected / { 3432 / static kid / -3:'peregrin.took@tuckborough.example', 3433 / kid / 4:'meriadoc.brandybuck@buckland.example', 3434 / U nonce / -22:h'4d8553e7e74f3c6a3a9dd3ef286a8195cbf8a23d 3435 19558ccfec7d34b824f42d92bd06bd2c7f0271f0214e141fb779ae2856abf585a583 3436 68b017e7f2a9e5ce4db5' 3437 }, 3438 / ciphertext / h'' 3439 ] 3440 ] 3441 ] 3442 ) 3444 C.5.3. Wrapped MAC 3446 This example uses the following: 3448 o MAC: AES-MAC, 128-bit key, truncated to 64 bits 3450 o Recipient class: AES Key Wrap w/ a pre-shared 256-bit key 3452 Size of binary file is 109 bytes 3453 97( 3454 [ 3455 / protected / h'a1010e' / { 3456 \ alg \ 1:14 \ AES-CBC-MAC-128//64 \ 3457 } / , 3458 / unprotected / {}, 3459 / payload / 'This is the content.', 3460 / tag / h'36f5afaf0bab5d43', 3461 / recipients / [ 3462 [ 3463 / protected / h'', 3464 / unprotected / { 3465 / alg / 1:-5 / A256KW /, 3466 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 3467 }, 3468 / ciphertext / h'711ab0dc2fc4585dce27effa6781c8093eba906f227 3469 b6eb0' 3470 ] 3471 ] 3472 ] 3473 ) 3475 C.5.4. Multi-Recipient MACed Message 3477 This example uses the following: 3479 o MAC: HMAC w/ SHA-256, 128-bit key 3481 o Recipient class: Uses three different methods 3483 1. ECDH Ephemeral-Static, Curve P-521, AES Key Wrap w/ 128-bit 3484 key 3486 2. AES Key Wrap w/ 256-bit key 3488 Size of binary file is 309 bytes 3489 97( 3490 [ 3491 / protected / h'a10105' / { 3492 \ alg \ 1:5 \ HMAC 256//256 \ 3493 } / , 3494 / unprotected / {}, 3495 / payload / 'This is the content.', 3496 / tag / h'bf48235e809b5c42e995f2b7d5fa13620e7ed834e337f6aa43df16 3497 1e49e9323e', 3498 / recipients / [ 3499 [ 3500 / protected / h'a101381c' / { 3501 \ alg \ 1:-29 \ ECHD-ES+A128KW \ 3502 } / , 3503 / unprotected / { 3504 / ephemeral / -1:{ 3505 / kty / 1:2, 3506 / crv / -1:3, 3507 / x / -2:h'0043b12669acac3fd27898ffba0bcd2e6c366d53bc4db 3508 71f909a759304acfb5e18cdc7ba0b13ff8c7636271a6924b1ac63c02688075b55ef2 3509 d613574e7dc242f79c3', 3510 / y / -3:true 3511 }, 3512 / kid / 4:'bilbo.baggins@hobbiton.example' 3513 }, 3514 / ciphertext / h'339bc4f79984cdc6b3e6ce5f315a4c7d2b0ac466fce 3515 a69e8c07dfbca5bb1f661bc5f8e0df9e3eff5' 3516 ], 3517 [ 3518 / protected / h'', 3519 / unprotected / { 3520 / alg / 1:-5 / A256KW /, 3521 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 3522 }, 3523 / ciphertext / h'0b2c7cfce04e98276342d6476a7723c090dfdd15f9a 3524 518e7736549e998370695e6d6a83b4ae507bb' 3525 ] 3526 ] 3527 ] 3528 ) 3530 C.6. Examples of MAC0 Messages 3532 C.6.1. Shared Secret Direct MAC 3534 This example uses the following: 3536 o MAC: AES-CMAC, 256-bit key, truncated to 64 bits 3537 o Recipient class: direct shared secret 3539 Size of binary file is 37 bytes 3541 17( 3542 [ 3543 / protected / h'a1010f' / { 3544 \ alg \ 1:15 \ AES-CBC-MAC-256//64 \ 3545 } / , 3546 / unprotected / {}, 3547 / payload / 'This is the content.', 3548 / tag / h'726043745027214f' 3549 ] 3550 ) 3552 Note that this example uses the same inputs as Appendix C.5.1. 3554 C.7. COSE Keys 3556 C.7.1. Public Keys 3558 This is an example of a COSE Key Set. This example includes the 3559 public keys for all of the previous examples. 3561 In order the keys are: 3563 o An EC key with a kid of "meriadoc.brandybuck@buckland.example" 3565 o An EC key with a kid of "peregrin.took@tuckborough.example" 3567 o An EC key with a kid of "bilbo.baggins@hobbiton.example" 3569 o An EC key with a kid of "11" 3571 Size of binary file is 481 bytes 3573 [ 3574 { 3575 -1:1, 3576 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 3577 8551d', 3578 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 3579 4d19c', 3580 1:2, 3581 2:'meriadoc.brandybuck@buckland.example' 3582 }, 3583 { 3584 -1:1, 3585 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 3586 09eff', 3587 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 3588 c117e', 3589 1:2, 3590 2:'11' 3591 }, 3592 { 3593 -1:3, 3594 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 3595 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 3596 f42ad', 3597 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 3598 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 3599 d9475', 3600 1:2, 3601 2:'bilbo.baggins@hobbiton.example' 3602 }, 3603 { 3604 -1:1, 3605 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 3606 d6280', 3607 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 3608 822bb', 3609 1:2, 3610 2:'peregrin.took@tuckborough.example' 3611 } 3612 ] 3614 C.7.2. Private Keys 3616 This is an example of a COSE Key Set. This example includes the 3617 private keys for all of the previous examples. 3619 In order the keys are: 3621 o An EC key with a kid of "meriadoc.brandybuck@buckland.example" 3623 o A shared-secret key with a kid of "our-secret" 3625 o An EC key with a kid of "peregrin.took@tuckborough.example" 3627 o A shared-secret key with a kid of "018c0ae5-4d9b-471b- 3628 bfd6-eef314bc7037" 3630 o An EC key with a kid of "bilbo.baggins@hobbiton.example" 3632 o An EC key with a kid of "11" 3634 Size of binary file is 816 bytes 3636 [ 3637 { 3638 1:2, 3639 2:'meriadoc.brandybuck@buckland.example', 3640 -1:1, 3641 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 3642 8551d', 3643 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 3644 4d19c', 3645 -4:h'aff907c99f9ad3aae6c4cdf21122bce2bd68b5283e6907154ad911840fa 3646 208cf' 3647 }, 3648 { 3649 1:2, 3650 2:'11', 3651 -1:1, 3652 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 3653 09eff', 3654 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 3655 c117e', 3656 -4:h'57c92077664146e876760c9520d054aa93c3afb04e306705db609030850 3657 7b4d3' 3658 }, 3659 { 3660 1:2, 3661 2:'bilbo.baggins@hobbiton.example', 3662 -1:3, 3663 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 3664 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 3665 f42ad', 3666 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 3667 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 3668 d9475', 3669 -4:h'00085138ddabf5ca975f5860f91a08e91d6d5f9a76ad4018766a476680b 3670 55cd339e8ab6c72b5facdb2a2a50ac25bd086647dd3e2e6e99e84ca2c3609fdf177f 3671 eb26d' 3672 }, 3673 { 3674 1:4, 3675 2:'our-secret', 3676 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 3677 27188' 3678 }, 3679 { 3680 1:2, 3681 -1:1, 3682 2:'peregrin.took@tuckborough.example', 3683 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 3684 d6280', 3685 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 3686 822bb', 3687 -4:h'02d1f7e6f26c43d4868d87ceb2353161740aacf1f7163647984b522a848 3688 df1c3' 3689 }, 3690 { 3691 1:4, 3692 2:'our-secret2', 3693 -1:h'849b5786457c1491be3a76dcea6c4271' 3694 }, 3695 { 3696 1:4, 3697 2:'018c0ae5-4d9b-471b-bfd6-eef314bc7037', 3698 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 3699 27188' 3700 } 3701 ] 3703 Acknowledgments 3705 This document is a product of the COSE working group of the IETF. 3707 The following individuals are to blame for getting me started on this 3708 project in the first place: Richard Barnes, Matt Miller, and Martin 3709 Thomson. 3711 The initial version of the specification was based to some degree on 3712 the outputs of the JOSE and S/MIME working groups. 3714 The following individuals provided input into the final form of the 3715 document: Carsten Bormann, John Bradley, Brain Campbell, Michael B. 3717 Jones, Ilari Liusvaara, Francesca Palombini, Ludwig Seitz, and Goran 3718 Selander. 3720 Author's Address 3722 Jim Schaad 3723 August Cellars 3725 Email: ietf@augustcellars.com