idnits 2.17.1 draft-ietf-cose-rfc8152bis-struct-04.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 (August 17, 2019) is 1712 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-03 ** 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 -- 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 (~~), 2 warnings (==), 5 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 COSE Working Group J. Schaad 3 Internet-Draft August Cellars 4 Obsoletes: 8152 (if approved) August 17, 2019 5 Intended status: Standards Track 6 Expires: February 18, 2020 8 CBOR Object Signing and Encryption (COSE): Structures and Process 9 draft-ietf-cose-rfc8152bis-struct-04 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 February 18, 2020. 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 . . . . . . . . . . . . . . . . 8 73 1.6. Document Terminology . . . . . . . . . . . . . . . . . . 8 74 2. Basic COSE Structure . . . . . . . . . . . . . . . . . . . . 9 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 5. Counter Signatures . . . . . . . . . . . . . . . . . . . . . 22 83 5.1. Full Countersignatures . . . . . . . . . . . . . . . . . 23 84 5.2. Abbreviated Countersignatures . . . . . . . . . . . . . . 24 85 6. Encryption Objects . . . . . . . . . . . . . . . . . . . . . 25 86 6.1. Enveloped COSE Structure . . . . . . . . . . . . . . . . 25 87 6.1.1. Content Key Distribution Methods . . . . . . . . . . 27 88 6.2. Single Recipient Encrypted . . . . . . . . . . . . . . . 27 89 6.3. How to Encrypt and Decrypt for AEAD Algorithms . . . . . 28 90 6.4. How to Encrypt and Decrypt for AE Algorithms . . . . . . 30 91 7. MAC Objects . . . . . . . . . . . . . . . . . . . . . . . . . 31 92 7.1. MACed Message with Recipients . . . . . . . . . . . . . . 32 93 7.2. MACed Messages with Implicit Key . . . . . . . . . . . . 33 94 7.3. How to Compute and Verify a MAC . . . . . . . . . . . . . 34 95 8. Key Objects . . . . . . . . . . . . . . . . . . . . . . . . . 35 96 8.1. COSE Key Common Parameters . . . . . . . . . . . . . . . 36 97 9. Taxonomy of Algorithms used by COSE . . . . . . . . . . . . . 38 98 9.1. Signature Algorithms . . . . . . . . . . . . . . . . . . 38 99 9.2. Message Authentication Code (MAC) Algorithms . . . . . . 39 100 9.3. Content Encryption Algorithms . . . . . . . . . . . . . . 40 101 9.4. Key Derivation Functions (KDFs) . . . . . . . . . . . . . 41 102 9.5. Content Key Distribution Methods . . . . . . . . . . . . 41 103 9.5.1. Direct Encryption . . . . . . . . . . . . . . . . . . 41 104 9.5.2. Key Wrap . . . . . . . . . . . . . . . . . . . . . . 42 105 9.5.3. Key Transport . . . . . . . . . . . . . . . . . . . . 43 106 9.5.4. Direct Key Agreement . . . . . . . . . . . . . . . . 43 107 9.5.5. Key Agreement with Key Wrap . . . . . . . . . . . . . 44 108 10. CBOR Encoding Restrictions . . . . . . . . . . . . . . . . . 44 109 11. Application Profiling Considerations . . . . . . . . . . . . 45 110 12. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 46 111 12.1. CBOR Tag Assignment . . . . . . . . . . . . . . . . . . 46 112 12.2. COSE Header Parameters Registry . . . . . . . . . . . . 47 113 12.3. COSE Header Algorithm Parameters Registry . . . . . . . 47 114 12.4. COSE Key Common Parameters Registry . . . . . . . . . . 47 115 12.5. Media Type Registrations . . . . . . . . . . . . . . . . 47 116 12.5.1. COSE Security Message . . . . . . . . . . . . . . . 47 117 12.5.2. COSE Key Media Type . . . . . . . . . . . . . . . . 48 118 12.6. CoAP Content-Formats Registry . . . . . . . . . . . . . 50 119 13. Security Considerations . . . . . . . . . . . . . . . . . . . 51 120 14. Implementation Status . . . . . . . . . . . . . . . . . . . . 53 121 14.1. Author's Versions . . . . . . . . . . . . . . . . . . . 53 122 14.2. JavaScript Version . . . . . . . . . . . . . . . . . . . 54 123 14.3. Python Version . . . . . . . . . . . . . . . . . . . . . 54 124 14.4. COSE Testing Library . . . . . . . . . . . . . . . . . . 55 125 15. References . . . . . . . . . . . . . . . . . . . . . . . . . 55 126 15.1. Normative References . . . . . . . . . . . . . . . . . . 55 127 15.2. Informative References . . . . . . . . . . . . . . . . . 56 128 Appendix A. Guidelines for External Data Authentication of 129 Algorithms . . . . . . . . . . . . . . . . . . . . . 59 130 Appendix B. Two Layers of Recipient Information . . . . . . . . 62 131 Appendix C. Examples . . . . . . . . . . . . . . . . . . . . . . 63 132 C.1. Examples of Signed Messages . . . . . . . . . . . . . . . 64 133 C.1.1. Single Signature . . . . . . . . . . . . . . . . . . 64 134 C.1.2. Multiple Signers . . . . . . . . . . . . . . . . . . 65 135 C.1.3. Counter Signature . . . . . . . . . . . . . . . . . . 66 136 C.1.4. Signature with Criticality . . . . . . . . . . . . . 67 137 C.2. Single Signer Examples . . . . . . . . . . . . . . . . . 68 138 C.2.1. Single ECDSA Signature . . . . . . . . . . . . . . . 68 139 C.3. Examples of Enveloped Messages . . . . . . . . . . . . . 69 140 C.3.1. Direct ECDH . . . . . . . . . . . . . . . . . . . . . 69 141 C.3.2. Direct Plus Key Derivation . . . . . . . . . . . . . 70 142 C.3.3. Counter Signature on Encrypted Content . . . . . . . 71 143 C.3.4. Encrypted Content with External Data . . . . . . . . 73 144 C.4. Examples of Encrypted Messages . . . . . . . . . . . . . 73 145 C.4.1. Simple Encrypted Message . . . . . . . . . . . . . . 73 146 C.4.2. Encrypted Message with a Partial IV . . . . . . . . . 74 147 C.5. Examples of MACed Messages . . . . . . . . . . . . . . . 74 148 C.5.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 74 149 C.5.2. ECDH Direct MAC . . . . . . . . . . . . . . . . . . . 75 150 C.5.3. Wrapped MAC . . . . . . . . . . . . . . . . . . . . . 76 151 C.5.4. Multi-Recipient MACed Message . . . . . . . . . . . . 77 152 C.6. Examples of MAC0 Messages . . . . . . . . . . . . . . . . 78 153 C.6.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 78 154 C.7. COSE Keys . . . . . . . . . . . . . . . . . . . . . . . . 79 155 C.7.1. Public Keys . . . . . . . . . . . . . . . . . . . . . 79 156 C.7.2. Private Keys . . . . . . . . . . . . . . . . . . . . 80 157 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 82 158 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 83 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 build the inputs to the cryptographic 203 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 define 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 o Rearrange the text around counter signatures and define a CBOR Tag 260 for a standalone countersignature. 262 1.3. Requirements Terminology 264 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 265 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 266 "OPTIONAL" in this document are to be interpreted as described in BCP 267 14 [RFC2119] [RFC8174] when, and only when, they appear in all 268 capitals, as shown here. 270 1.4. CBOR Grammar 272 There was not a standard CBOR grammar available when COSE was 273 originally written. For that reason the CBOR structures defined here 274 are described in prose. Since that time CBOR Data Definition 275 Language (CDDL) [RFC8610] has been published as an RFC. The CBOR 276 grammar presented in this document is compatible with CDDL. 278 The document was developed by first working on the grammar and then 279 developing the prose to go with it. An artifact of this is that the 280 prose was written using the primitive type strings defined by CBOR 281 Data Definition Language (CDDL) [RFC8610]. In this specification, 282 the following primitive types are used: 284 any -- non-specific value that permits all CBOR values to be 285 placed here. 287 bool -- a boolean value (true: major type 7, value 21; false: 288 major type 7, value 20). 290 bstr -- byte string (major type 2). 292 int -- an unsigned integer or a negative integer. 294 nil -- a null value (major type 7, value 22). 296 nint -- a negative integer (major type 1). 298 tstr -- a UTF-8 text string (major type 3). 300 uint -- an unsigned integer (major type 0). 302 Two syntaxes from CDDL appear in this document as shorthand. These 303 are: 305 FOO / BAR -- indicates that either FOO or BAR can appear here. 307 [+ FOO] -- indicates that the type FOO appears one or more times 308 in an array. 310 Two of the constraints defined by CDDL are also used in this 311 document. These are: 313 type1 .cbor type2 -- indicates that the contents of type1, usually 314 bstr, contains a value of type2. 316 type1 .size integer -- indicates that the contents of type1 is 317 integer bytes long 319 As well as the prose description, a version of a CBOR grammar is 320 presented in CDDL. The CDDL grammar is informational; the prose 321 description is normative. 323 The collected CDDL can be extracted from the XML version of this 324 document via the following XPath expression below. (Depending on the 325 XPath evaluator one is using, it may be necessary to deal with > 326 as an entity.) 328 //artwork[@type='CDDL']/text() 330 CDDL expects the initial non-terminal symbol to be the first symbol 331 in the file. For this reason, the first fragment of CDDL is 332 presented here. 334 start = COSE_Messages / COSE_Key / COSE_KeySet / Internal_Types 336 ; This is defined to make the tool quieter: 337 Internal_Types = Sig_structure / Enc_structure / MAC_structure 338 The non-terminal Internal_Types is defined for dealing with the 339 automated validation tools used during the writing of this document. 340 It references those non-terminals that are used for security 341 computations but are not emitted for transport. 343 1.5. CBOR-Related Terminology 345 In JSON, maps are called objects and only have one kind of map key: a 346 string. In COSE, we use strings, negative integers, and unsigned 347 integers as map keys. The integers are used for compactness of 348 encoding and easy comparison. The inclusion of strings allows for an 349 additional range of short encoded values to be used as well. Since 350 the word "key" is mainly used in its other meaning, as a 351 cryptographic key, we use the term "label" for this usage as a map 352 key. 354 The presence of a label in a COSE map that is not a string or an 355 integer is an error. Applications can either fail processing or 356 process messages by ignoring incorrect labels; however, they MUST NOT 357 create messages with incorrect labels. 359 A CDDL grammar fragment defines the non-terminal 'label', as in the 360 previous paragraph, and 'values', which permits any value to be used. 362 label = int / tstr 363 values = any 365 1.6. Document Terminology 367 In this document, we use the following terminology: 369 Byte is a synonym for octet. 371 Constrained Application Protocol (CoAP) is a specialized web transfer 372 protocol for use in constrained systems. It is defined in [RFC7252]. 374 Authenticated Encryption (AE) [RFC5116] algorithms are those 375 encryption algorithms that provide an authentication check of the 376 contents algorithm with the encryption service. 378 Authenticated Encryption with Associated Data (AEAD) [RFC5116] 379 algorithms provide the same content authentication service as AE 380 algorithms, but they additionally provide for authentication of non- 381 encrypted data as well. 383 Context is used throughout the document to represent information that 384 is not part of the COSE message. Information which is part of the 385 context can come from several different sources including: Protocol 386 interactions, associated key structures and program configuration. 387 The context to use can be implicit, identified using the 'kid 388 context' header field defined in [RFC8613], or identified by a 389 protocol specific identifier. Context should generally be included 390 in the cryptographic configuration, for more details see Section 4.3. 392 2. Basic COSE Structure 394 The COSE object structure is designed so that there can be a large 395 amount of common code when parsing and processing the different types 396 of security messages. All of the message structures are built on the 397 CBOR array type. The first three elements of the array always 398 contain the same information: 400 1. The set of protected header parameters wrapped in a bstr. 402 2. The set of unprotected header parameters as a map. 404 3. The content of the message. The content is either the plaintext 405 or the ciphertext as appropriate. The content may be detached 406 (i.e. transported separately from the COSE structure), but the 407 location is still used. The content is wrapped in a bstr when 408 present and is a nil value when detached. 410 Elements after this point are dependent on the specific message type. 412 COSE messages are built using the concept of layers to separate 413 different types of cryptographic concepts. As an example of how this 414 works, consider the COSE_Encrypt message (Section 6.1). This message 415 type is broken into two layers: the content layer and the recipient 416 layer. In the content layer, the plaintext is encrypted and 417 information about the encrypted message is placed. In the recipient 418 layer, the content encryption key (CEK) is encrypted and information 419 about how it is encrypted for each recipient is placed. A single 420 layer version of the encryption message COSE_Encrypt0 (Section 6.2) 421 is provided for cases where the CEK is pre-shared. 423 Identification of which type of message has been presented is done by 424 the following methods: 426 1. The specific message type is known from the context. This may be 427 defined by a marker in the containing structure or by 428 restrictions specified by the application protocol. 430 2. The message type is identified by a CBOR tag. Messages with a 431 CBOR tag are known in this specification as tagged messages, 432 while those without the CBOR tag are known as untagged messages. 434 This document defines a CBOR tag for each of the message 435 structures. These tags can be found in Table 1. 437 3. When a COSE object is carried in a media type of 'application/ 438 cose', the optional parameter 'cose-type' can be used to identify 439 the embedded object. The parameter is OPTIONAL if the tagged 440 version of the structure is used. The parameter is REQUIRED if 441 the untagged version of the structure is used. The value to use 442 with the parameter for each of the structures can be found in 443 Table 1. 445 4. When a COSE object is carried as a CoAP payload, the CoAP 446 Content-Format Option can be used to identify the message 447 content. The CoAP Content-Format values can be found in Table 2. 448 The CBOR tag for the message structure is not required as each 449 security message is uniquely identified. 451 +------+------------------+-----------------------+-----------------+ 452 | CBOR | cose-type | Data Item | Semantics | 453 | Tag | | | | 454 +------+------------------+-----------------------+-----------------+ 455 | 98 | cose-sign | COSE_Sign | COSE Signed | 456 | | | | Data Object | 457 | 18 | cose-sign1 | COSE_Sign1 | COSE Single | 458 | | | | Signer Data | 459 | | | | Object | 460 | 96 | cose-encrypt | COSE_Encrypt | COSE Encrypted | 461 | | | | Data Object | 462 | 16 | cose-encrypt0 | COSE_Encrypt0 | COSE Single | 463 | | | | Recipient | 464 | | | | Encrypted Data | 465 | | | | Object | 466 | 97 | cose-mac | COSE_Mac | COSE MACed Data | 467 | | | | Object | 468 | 17 | cose-mac0 | COSE_Mac0 | COSE Mac w/o | 469 | | | | Recipients | 470 | | | | Object | 471 | TBD0 | cose-countersign | COSE_Countersignature | COSE standalone | 472 | | | | counter | 473 | | | | signature | 474 +------+------------------+-----------------------+-----------------+ 476 Table 1: COSE Message Identification 478 +----------------------------------+----------+-----+---------------+ 479 | Media Type | Encoding | ID | Reference | 480 +----------------------------------+----------+-----+---------------+ 481 | application/cose; cose-type | | 98 | [[THIS | 482 | ="cose-sign" | | | DOCUMENT]] | 483 | application/cose; cose-type | | 18 | [[THIS | 484 | ="cose-sign1" | | | DOCUMENT]] | 485 | application/cose; cose-type | | 96 | [[THIS | 486 | ="cose-encrypt" | | | DOCUMENT]] | 487 | application/cose; cose-type | | 16 | [[THIS | 488 | ="cose-encrypt0" | | | DOCUMENT]] | 489 | application/cose; cose-type | | 97 | [[THIS | 490 | ="cose-mac" | | | DOCUMENT]] | 491 | application/cose; cose-type | | 17 | [[THIS | 492 | ="cose-mac0" | | | DOCUMENT]] | 493 | application/cose-key | | 101 | [[THIS | 494 | | | | DOCUMENT]] | 495 | application/cose-key-set | | 102 | [[THIS | 496 | | | | DOCUMENT]] | 497 +----------------------------------+----------+-----+---------------+ 499 Table 2: CoAP Content-Formats for COSE 501 The following CDDL fragment identifies all of the top messages 502 defined in this document. Separate non-terminals are defined for the 503 tagged and the untagged versions of the messages. 505 COSE_Messages = COSE_Untagged_Message / COSE_Tagged_Message 507 COSE_Untagged_Message = COSE_Sign / COSE_Sign1 / 508 COSE_Encrypt / COSE_Encrypt0 / 509 COSE_Mac / COSE_Mac0 / COSE_Countersignature 511 COSE_Tagged_Message = COSE_Sign_Tagged / COSE_Sign1_Tagged / 512 COSE_Encrypt_Tagged / COSE_Encrypt0_Tagged / 513 COSE_Mac_Tagged / COSE_Mac0_Tagged / COSE_Countersignature_Tagged 515 3. Header Parameters 517 The structure of COSE has been designed to have two buckets of 518 information that are not considered to be part of the payload itself, 519 but are used for holding information about content, algorithms, keys, 520 or evaluation hints for the processing of the layer. These two 521 buckets are available for use in all of the structures except for 522 keys. While these buckets are present, they may not all be usable in 523 all instances. For example, while the protected bucket is defined as 524 part of the recipient structure, some of the algorithms used for 525 recipient structures do not provide for authenticated data. If this 526 is the case, the protected bucket is left empty. 528 Both buckets are implemented as CBOR maps. The map key is a 'label' 529 (Section 1.5). The value portion is dependent on the definition for 530 the label. Both maps use the same set of label/value pairs. The 531 integer and string values for labels have been divided into several 532 sections including a standard range, a private range, and a range 533 that is dependent on the algorithm selected. The defined labels can 534 be found in the "COSE Header Parameters" IANA registry 535 (Section 12.2). 537 The two buckets are: 539 protected: Contains parameters about the current layer that are 540 cryptographically protected. This bucket MUST be empty if it is 541 not going to be included in a cryptographic computation. This 542 bucket is encoded in the message as a binary object. This value 543 is obtained by CBOR encoding the protected map and wrapping it in 544 a bstr object. Senders SHOULD encode a zero-length map as a zero- 545 length byte string rather than as a zero-length map (encoded as 546 h'a0'). The zero-length binary encoding is preferred because it 547 is both shorter and the version used in the serialization 548 structures for cryptographic computation. After encoding the map, 549 the value is wrapped in the binary object. Recipients MUST accept 550 both a zero-length binary value and a zero-length map encoded in 551 the binary value. The wrapping allows for the encoding of the 552 protected map to be transported with a greater chance that it will 553 not be altered in transit. (Badly behaved intermediates could 554 decode and re-encode, but this will result in a failure to verify 555 unless the re-encoded byte string is identical to the decoded byte 556 string.) This avoids the problem of all parties needing to be 557 able to do a common canonical encoding. 559 unprotected: Contains parameters about the current layer that are 560 not cryptographically protected. 562 Only parameters that deal with the current layer are to be placed at 563 that layer. As an example of this, the parameter 'content type' 564 describes the content of the message being carried in the message. 565 As such, this parameter is placed only in the content layer and is 566 not placed in the recipient or signature layers. In principle, one 567 should be able to process any given layer without reference to any 568 other layer. With the exception of the COSE_Sign structure, the only 569 data that needs to cross layers is the cryptographic key. 571 The buckets are present in all of the security objects defined in 572 this document. The fields in order are the 'protected' bucket (as a 573 CBOR 'bstr' type) and then the 'unprotected' bucket (as a CBOR 'map' 574 type). The presence of both buckets is required. The parameters 575 that go into the buckets come from the IANA "COSE Header Parameters" 576 registry (Section 12.2). Some common parameters are defined in the 577 next section. 579 Labels in each of the maps MUST be unique. When processing messages, 580 if a label appears multiple times, the message MUST be rejected as 581 malformed. Applications SHOULD verify that the same label does not 582 occur in both the protected and unprotected headers. If the message 583 is not rejected as malformed, attributes MUST be obtained from the 584 protected bucket before they are obtained from the unprotected 585 bucket. 587 The following CDDL fragment represents the two header buckets. A 588 group "Headers" is defined in CDDL that represents the two buckets in 589 which attributes are placed. This group is used to provide these two 590 fields consistently in all locations. A type is also defined that 591 represents the map of common headers. 593 Headers = ( 594 protected : empty_or_serialized_map, 595 unprotected : header_map 596 ) 598 header_map = { 599 Generic_Headers, 600 * label => values 601 } 603 empty_or_serialized_map = bstr .cbor header_map / bstr .size 0 605 3.1. Common COSE Headers Parameters 607 This section defines a set of common header parameters. A summary of 608 these parameters can be found in Table 3. This table should be 609 consulted to determine the value of label and the type of the value. 611 The set of header parameters defined in this section are: 613 alg: This parameter is used to indicate the algorithm used for the 614 security processing. This parameter MUST be authenticated where 615 the ability to do so exists. This support is provided by AEAD 616 algorithms or construction (COSE_Sign, COSE_Sign1, COSE_Mac, and 617 COSE_Mac0). This authentication can be done either by placing the 618 parameter in the protected header bucket or as part of the 619 externally supplied data. The value is taken from the "COSE 620 Algorithms" registry (see [COSE.Algorithms]). 622 crit: The parameter is used to indicate which protected header 623 labels an application that is processing a message is required to 624 understand. Parameters defined in this document do not need to be 625 included as they should be understood by all implementations. 626 When present, this parameter MUST be placed in the protected 627 header bucket. The array MUST have at least one value in it. 628 Not all labels need to be included in the 'crit' parameter. The 629 rules for deciding which header labels are placed in the array 630 are: 632 * Integer labels in the range of 0 to 7 SHOULD be omitted. 634 * Integer labels in the range -1 to -128 can be omitted as they 635 are algorithm dependent. If an application can correctly 636 process an algorithm, it can be assumed that it will correctly 637 process all of the common parameters associated with that 638 algorithm. Integer labels in the range -129 to -65536 SHOULD 639 be included as these would be less common parameters that might 640 not be generally supported. 642 * Labels for parameters required for an application MAY be 643 omitted. Applications should have a statement if the label can 644 be omitted. 646 The header parameter values indicated by 'crit' can be processed 647 by either the security library code or an application using a 648 security library; the only requirement is that the parameter is 649 processed. If the 'crit' value list includes a value for which 650 the parameter is not in the protected bucket, this is a fatal 651 error in processing the message. 653 content type: This parameter is used to indicate the content type of 654 the data in the payload or ciphertext fields. Integers are from 655 the "CoAP Content-Formats" IANA registry table [COAP.Formats]. 656 Text values following the syntax of "/" 657 where and are defined in Section 4.2 of 658 [RFC6838]. Leading and trailing whitespace is also omitted. 659 Textual content values along with parameters and subparameters can 660 be located using the IANA "Media Types" registry. Applications 661 SHOULD provide this parameter if the content structure is 662 potentially ambiguous. 664 kid: This parameter identifies one piece of data that can be used as 665 input to find the needed cryptographic key. The value of this 666 parameter can be matched against the 'kid' member in a COSE_Key 667 structure. Other methods of key distribution can define an 668 equivalent field to be matched. Applications MUST NOT assume that 669 'kid' values are unique. There may be more than one key with the 670 same 'kid' value, so all of the keys associated with this 'kid' 671 may need to be checked. The internal structure of 'kid' values is 672 not defined and cannot be relied on by applications. Key 673 identifier values are hints about which key to use. This is not a 674 security-critical field. For this reason, it can be placed in the 675 unprotected headers bucket. 677 IV: This parameter holds the Initialization Vector (IV) value. For 678 some symmetric encryption algorithms, this may be referred to as a 679 nonce. The IV can be placed in the unprotected header as 680 modifying the IV will cause the decryption to yield plaintext that 681 is readily detectable as garbled. 683 Partial IV: This parameter holds a part of the IV value. When using 684 the COSE_Encrypt0 structure, a portion of the IV can be part of 685 the context associated with the key (Context IV) while a portion 686 can be changed with each message (Parital IV). This field is used 687 to carry a value that causes the IV to be changed for each 688 message. The Parital IV can be placed in the unprotected header 689 as modifying the value will cause the decryption to yield 690 plaintext that is readily detectable as garbled. The 691 'Initialization Vector' and 'Partial Initialization Vector' 692 parameters MUST NOT both be present in the same security layer. 694 The message IV is generated by the following steps: 696 1. Left-pad the Partial IV with zeros to the length of IV. 698 2. XOR the padded Partial IV with the context IV. 700 counter signature: This parameter holds one or more counter 701 signature values. Counter signatures provide a method of having a 702 second party sign some data. The counter signature parameter can 703 occur as an unprotected attribute in any of the following 704 structures: COSE_Sign1, COSE_Signature, COSE_Encrypt, 705 COSE_recipient, COSE_Encrypt0, COSE_Mac, and COSE_Mac0. These 706 structures all have the same beginning elements, so that a 707 consistent calculation of the counter signature can be computed. 708 Details on counter signatures are found in Section 5. 710 +-----------+-------+----------------+-------------+----------------+ 711 | Name | Label | Value Type | Value | Description | 712 | | | | Registry | | 713 +-----------+-------+----------------+-------------+----------------+ 714 | alg | 1 | int / tstr | COSE | Cryptographic | 715 | | | | Algorithms | algorithm to | 716 | | | | registry | use | 717 | crit | 2 | [+ label] | COSE Header | Critical | 718 | | | | Parameters | headers to be | 719 | | | | registry | understood | 720 | content | 3 | tstr / uint | CoAP | Content type | 721 | type | | | Content- | of the payload | 722 | | | | Formats or | | 723 | | | | Media Types | | 724 | | | | registries | | 725 | kid | 4 | bstr | | Key identifier | 726 | IV | 5 | bstr | | Full | 727 | | | | | Initialization | 728 | | | | | Vector | 729 | Partial | 6 | bstr | | Partial | 730 | IV | | | | Initialization | 731 | | | | | Vector | 732 | counter | 7 | COSE_Signature | | CBOR-encoded | 733 | signature | | / [+ | | signature | 734 | | | COSE_Signature | | structure | 735 | | | ] | | | 736 +-----------+-------+----------------+-------------+----------------+ 738 Table 3: Common Header Parameters 740 The CDDL fragment that represents the set of headers defined in this 741 section is given below. Each of the headers is tagged as optional 742 because they do not need to be in every map; headers required in 743 specific maps are discussed above. 745 Generic_Headers = ( 746 ? 1 => int / tstr, ; algorithm identifier 747 ? 2 => [+label], ; criticality 748 ? 3 => tstr / int, ; content type 749 ? 4 => bstr, ; key identifier 750 ? 5 => bstr, ; IV 751 ? 6 => bstr, ; Partial IV 752 ? 7 => COSE_Signature / [+COSE_Signature] ; Counter signature 753 ) 755 4. Signing Objects 757 COSE supports two different signature structures. COSE_Sign allows 758 for one or more signatures to be applied to the same content. 759 COSE_Sign1 is restricted to a single signer. The structures cannot 760 be converted between each other; as the signature computation 761 includes a parameter identifying which structure is being used, the 762 converted structure will fail signature validation. 764 4.1. Signing with One or More Signers 766 The COSE_Sign structure allows for one or more signatures to be 767 applied to a message payload. Parameters relating to the content and 768 parameters relating to the signature are carried along with the 769 signature itself. These parameters may be authenticated by the 770 signature, or just present. An example of a parameter about the 771 content is the content type. Examples of parameters about the 772 signature would be the algorithm and key used to create the signature 773 and counter signatures. 775 RFC 5652 indicates that: 777 When more than one signature is present, the successful validation 778 of one signature associated with a given signer is usually treated 779 as a successful signature by that signer. However, there are some 780 application environments where other rules are needed. An 781 application that employs a rule other than one valid signature for 782 each signer must specify those rules. Also, where simple matching 783 of the signer identifier is not sufficient to determine whether 784 the signatures were generated by the same signer, the application 785 specification must describe how to determine which signatures were 786 generated by the same signer. Support for different communities 787 of recipients is the primary reason that signers choose to include 788 more than one signature. 790 For example, the COSE_Sign structure might include signatures 791 generated with the Edwards-curve Digital Signature Algorithm (EdDSA) 792 [RFC8032] and with the Elliptic Curve Digital Signature Algorithm 793 (ECDSA) [DSS]. This allows recipients to verify the signature 794 associated with one algorithm or the other. More-detailed 795 information on multiple signature evaluations can be found in 796 [RFC5752]. 798 The signature structure can be encoded as either tagged or untagged 799 depending on the context it will be used in. A tagged COSE_Sign 800 structure is identified by the CBOR tag 98. The CDDL fragment that 801 represents this is: 803 COSE_Sign_Tagged = #6.98(COSE_Sign) 805 A COSE Signed Message is defined in two parts. The CBOR object that 806 carries the body and information about the body is called the 807 COSE_Sign structure. The CBOR object that carries the signature and 808 information about the signature is called the COSE_Signature 809 structure. Examples of COSE Signed Messages can be found in 810 Appendix C.1. 812 The COSE_Sign structure is a CBOR array. The fields of the array in 813 order are: 815 protected: This is as described in Section 3. 817 unprotected: This is as described in Section 3. 819 payload: This field contains the serialized content to be signed. 820 If the payload is not present in the message, the application is 821 required to supply the payload separately. The payload is wrapped 822 in a bstr to ensure that it is transported without changes. If 823 the payload is transported separately ("detached content"), then a 824 nil CBOR object is placed in this location, and it is the 825 responsibility of the application to ensure that it will be 826 transported without changes. 828 Note: When a signature with a message recovery algorithm is used 829 (Section 9.1), the maximum number of bytes that can be recovered 830 is the length of the payload. The size of the payload is reduced 831 by the number of bytes that will be recovered. If all of the 832 bytes of the payload are consumed, then the payload is encoded as 833 a zero-length binary string rather than as being absent. 835 signatures: This field is an array of signatures. Each signature is 836 represented as a COSE_Signature structure. 838 The CDDL fragment that represents the above text for COSE_Sign 839 follows. 841 COSE_Sign = [ 842 Headers, 843 payload : bstr / nil, 844 signatures : [+ COSE_Signature] 845 ] 847 The COSE_Signature structure is a CBOR array. The fields of the 848 array in order are: 850 protected: This is as described in Section 3. 852 unprotected: This is as described in Section 3. 854 signature: This field contains the computed signature value. The 855 type of the field is a bstr. Algorithms MUST specify padding if 856 the signature value is not a multiple of 8 bits. 858 The CDDL fragment that represents the above text for COSE_Signature 859 follows. 861 COSE_Signature = [ 862 Headers, 863 signature : bstr 864 ] 866 4.2. Signing with One Signer 868 The COSE_Sign1 signature structure is used when only one signature is 869 going to be placed on a message. The parameters dealing with the 870 content and the signature are placed in the same pair of buckets 871 rather than having the separation of COSE_Sign. 873 The structure can be encoded as either tagged or untagged depending 874 on the context it will be used in. A tagged COSE_Sign1 structure is 875 identified by the CBOR tag 18. The CDDL fragment that represents 876 this is: 878 COSE_Sign1_Tagged = #6.18(COSE_Sign1) 880 The CBOR object that carries the body, the signature, and the 881 information about the body and signature is called the COSE_Sign1 882 structure. Examples of COSE_Sign1 messages can be found in 883 Appendix C.2. 885 The COSE_Sign1 structure is a CBOR array. The fields of the array in 886 order are: 888 protected: This is as described in Section 3. 890 unprotected: This is as described in Section 3. 892 payload: This is as described in Section 4.1. 894 signature: This field contains the computed signature value. The 895 type of the field is a bstr. 897 The CDDL fragment that represents the above text for COSE_Sign1 898 follows. 900 COSE_Sign1 = [ 901 Headers, 902 payload : bstr / nil, 903 signature : bstr 904 ] 906 4.3. Externally Supplied Data 908 One of the features offered in the COSE document is the ability for 909 applications to provide additional data to be authenticated, but that 910 is not carried as part of the COSE object. The primary reason for 911 supporting this can be seen by looking at the CoAP message structure 912 [RFC7252], where the facility exists for options to be carried before 913 the payload. Examples of data that can be placed in this location 914 would be the CoAP code or CoAP options. If the data is in the header 915 section, then it is available for proxies to help in performing its 916 operations. For example, the Accept Option can be used by a proxy to 917 determine if an appropriate value is in the proxy's cache. But the 918 sender can cause a failure at the server if a proxy, or an attacker, 919 changes the set of accept values by including the field in the 920 application supplied data. 922 This document describes the process for using a byte array of 923 externally supplied authenticated data; the method of constructing 924 the byte array is a function of the application. Applications that 925 use this feature need to define how the externally supplied 926 authenticated data is to be constructed. Such a construction needs 927 to take into account the following issues: 929 o If multiple items are included, applications need to ensure that 930 the same byte string cannot produced if there are different 931 inputs. This would occur by appending the strings 'AB' and 'CDE' 932 or by appending the strings 'ABC' and 'DE'. This is usually 933 addressed by making fields a fixed width and/or encoding the 934 length of the field as part of the output. Using options from 935 CoAP [RFC7252] as an example, these fields use a TLV structure so 936 they can be concatenated without any problems. 938 o If multiple items are included, an order for the items needs to be 939 defined. Using options from CoAP as an example, an application 940 could state that the fields are to be ordered by the option 941 number. 943 o Applications need to ensure that the byte string is going to be 944 the same on both sides. Using options from CoAP might give a 945 problem if the same relative numbering is kept. An intermediate 946 node could insert or remove an option, changing how the relative 947 number is done. An application would need to specify that the 948 relative number must be re-encoded to be relative only to the 949 options that are in the external data. 951 4.4. Signing and Verification Process 953 In order to create a signature, a well-defined byte string is needed. 954 The Sig_structure is used to create the canonical form. This signing 955 and verification process takes in the body information (COSE_Sign or 956 COSE_Sign1), the signer information (COSE_Signature), and the 957 application data (external source). A Sig_structure is a CBOR array. 958 The fields of the Sig_structure in order are: 960 1. A text string identifying the context of the signature. The 961 context string is: 963 "Signature" for signatures using the COSE_Signature structure. 965 "Signature1" for signatures using the COSE_Sign1 structure. 967 "CounterSignature" for signatures used as counter signature 968 attributes. 970 "CounterSignature0" for signatures used as CounterSignature0 971 attributes. 973 2. The protected attributes from the body structure encoded in a 974 bstr type. If there are no protected attributes, a bstr of 975 length zero is used. 977 3. The protected attributes from the signer structure encoded in a 978 bstr type. If there are no protected attributes, a bstr of 979 length zero is used. This field is omitted for the COSE_Sign1 980 signature structure and CounterSignature0 attributes. 982 4. The protected attributes from the application encoded in a bstr 983 type. If this field is not supplied, it defaults to a zero- 984 length binary string. (See Section 4.3 for application guidance 985 on constructing this field.) 987 5. The payload to be signed encoded in a bstr type. The payload is 988 placed here independent of how it is transported. 990 The CDDL fragment that describes the above text is: 992 Sig_structure = [ 993 context : "Signature" / "Signature1" / "CounterSignature" / 994 "CounterSignature0", 995 body_protected : empty_or_serialized_map, 996 ? sign_protected : empty_or_serialized_map, 997 external_aad : bstr, 998 payload : bstr 999 ] 1001 How to compute a signature: 1003 1. Create a Sig_structure and populate it with the appropriate 1004 fields. 1006 2. Create the value ToBeSigned by encoding the Sig_structure to a 1007 byte string, using the encoding described in Section 10. 1009 3. Call the signature creation algorithm passing in K (the key to 1010 sign with), alg (the algorithm to sign with), and ToBeSigned (the 1011 value to sign). 1013 4. Place the resulting signature value in the correct location. 1014 This is the 'signature' field of the COSE_Signature, COSE_Sign1 1015 or COSE_Countersignature structures. This is the value of the 1016 Countersignature0 attribute. 1018 The steps for verifying a signature are: 1020 1. Create a Sig_structure object and populate it with the 1021 appropriate fields. 1023 2. Create the value ToBeSigned by encoding the Sig_structure to a 1024 byte string, using the encoding described in Section 10. 1026 3. Call the signature verification algorithm passing in K (the key 1027 to verify with), alg (the algorithm used sign with), ToBeSigned 1028 (the value to sign), and sig (the signature to be verified). 1030 In addition to performing the signature verification, the application 1031 performs the appropriate checks to ensure that the key is correctly 1032 paired with the signing identity and that the signing identity is 1033 authorized before performing actions. 1035 5. Counter Signatures 1037 COSE supports two different forms for counter signatures. Full 1038 countersignatures use the structure COSE_Countersign. This is same 1039 structure as COSE_Signature and thus it can have protected 1040 attributes, chained countersignatures and information about 1041 identifying the key. Abbreviated countersignatures use the structure 1042 COSE_Countersign1. This structure only contains the signature value 1043 and nothing else. The structures cannot be converted between each 1044 other; as the signature computation includes a parameter identifying 1045 which structure is being used, the converted structure will fail 1046 signature validation. 1048 COSE was designed for uniformity in how the data strutures are 1049 specified. One result of this is that for COSE one can expand the 1050 concept of countersignatures beyond just the idea of signing a 1051 signature to being able to sign most of the structures without having 1052 to create a new signing layer. When creating a countersignature, one 1053 needs to be clear about the security properties that result. When 1054 done on a COSE_Signature, the normal countersignature semantics are 1055 preserved. That is the countersignature makes a statement about the 1056 existence of a signature and, when used as a timestamp, a time point 1057 at which the signature exists. When done on a COSE_Mac or a 1058 COSE_Mac0, one effectively upgrades the MAC operation to a sginature 1059 operation. When done on a COSE_Encrypt or COSE_Encrypt0, the 1060 existence of the encrypted data is attested to. It should be noted 1061 that there is a big difference between attesting to the encrypted 1062 data as opposed to attesting to the unencrypted data. If the latter 1063 is what is desired, then one needs to apply a signature to the data 1064 and then encrypt that. It is always possible to construct cases 1065 where the decryption is successful, while providing completely 1066 different answers by using a different key. This situation is not 1067 detectable by a countersignature on the encrypted data. 1069 5.1. Full Countersignatures 1071 The COSE_Countersignature structure allows for the same set of 1072 capabilities of a COSE_Signature. This means that all of the 1073 capabilities of a signature are duplicated with this structure. 1074 Specifically, the countersigner does not need to be related to the 1075 producer of what is being counter signed as key and algorithm 1076 identification can be placed in the countersignature attributes. 1077 This also means that the countersignature can itself be 1078 countersigned. This is a feature required by protocols such as long- 1079 term archiving services. More information on how this is used can be 1080 found in the evidence record syntax described in [RFC4998]. 1082 The full countersignature structure can be encoded as either a tagged 1083 or untagged depending on the context it is used in. A tagged 1084 COSE_Countersign structure is identified by the CBOR tag TBD0. The 1085 CDDL fragment for full countersignatures is: 1087 COSE_CounterSignature_Tagged = #6.98(COSE_CounterSignature) 1088 COSE_CounterSignature = COSE_Signature 1090 The details of the fields of a countersignature can be found in 1091 Section 4.1. The process of creating and validating abbreviated 1092 countersignatures is defined in Section 4.4. 1094 An example of a counter signature on a signature can be found in 1095 Appendix C.1.3. An example of a counter signature in an encryption 1096 object can be found in Appendix C.3.3. 1098 It should be noted that only a signature algorithm with appendix (see 1099 Section 9.1) can be used for counter signatures. This is because the 1100 body should be able to be processed without having to evaluate the 1101 counter signature, and this is not possible for signature schemes 1102 with message recovery. 1104 5.2. Abbreviated Countersignatures 1106 Abbreviated countersignatures were designed primarily to deal with 1107 the problem of having group encrypted messaging, but still needing to 1108 know who originated the message. The objective was to keep the 1109 countersignature as small as possible while still providing the 1110 needed security. For abbreviated countersignatures, there is no 1111 provision for any protected attributes related to the signing 1112 operation. Instead, the parameters for computing or verifying the 1113 abbreviated countersignature are inferred from the same context used 1114 to describe the encryption, signature, or MAC processing. 1116 The byte string representing the signature value is placed in the 1117 CounterSignature0 attribute. This attribute is then encoded as an 1118 unprotected header. The attribute is defined below. 1120 The process of creating and validating abbreviated countersignatures 1121 is defined in Section 4.4. 1123 +-------------------+-------+---------+-------+---------------------+ 1124 | Name | Label | Value | Value | Description | 1125 | | | Type | | | 1126 +-------------------+-------+---------+-------+---------------------+ 1127 | CounterSignature0 | 9 | bstr | | Abbreviated | 1128 | | | | | Countersignature | 1129 +-------------------+-------+---------+-------+---------------------+ 1131 Table 4: Header Parameter for CounterSignature0 1133 6. Encryption Objects 1135 COSE supports two different encryption structures. COSE_Encrypt0 is 1136 used when a recipient structure is not needed because the key to be 1137 used is known implicitly. COSE_Encrypt is used the rest of the time. 1138 This includes cases where there are multiple recipients or a 1139 recipient algorithm other than direct (i.e. pre-shared secret) is 1140 used. 1142 6.1. Enveloped COSE Structure 1144 The enveloped structure allows for one or more recipients of a 1145 message. There are provisions for parameters about the content and 1146 parameters about the recipient information to be carried in the 1147 message. The protected parameters associated with the content are 1148 authenticated by the content encryption algorithm. The protected 1149 parameters associated with the recipient are authenticated by the 1150 recipient algorithm (when the algorithm supports it). Examples of 1151 parameters about the content are the type of the content and the 1152 content encryption algorithm. Examples of parameters about the 1153 recipient are the recipient's key identifier and the recipient's 1154 encryption algorithm. 1156 The same techniques and nearly the same structure is used for 1157 encrypting both the plaintext and the keys. This is different from 1158 the approach used by both "Cryptographic Message Syntax (CMS)" 1159 [RFC5652] and "JSON Web Encryption (JWE)" [RFC7516] where different 1160 structures are used for the content layer and for the recipient 1161 layer. Two structures are defined: COSE_Encrypt to hold the 1162 encrypted content and COSE_recipient to hold the encrypted keys for 1163 recipients. Examples of encrypted messages can be found in 1164 Appendix C.3. 1166 The COSE_Encrypt structure can be encoded as either tagged or 1167 untagged depending on the context it will be used in. A tagged 1168 COSE_Encrypt structure is identified by the CBOR tag 96. The CDDL 1169 fragment that represents this is: 1171 COSE_Encrypt_Tagged = #6.96(COSE_Encrypt) 1173 The COSE_Encrypt structure is a CBOR array. The fields of the array 1174 in order are: 1176 protected: This is as described in Section 3. 1178 unprotected: This is as described in Section 3. 1180 ciphertext: This field contains the ciphertext encoded as a bstr. 1181 If the ciphertext is to be transported independently of the 1182 control information about the encryption process (i.e., detached 1183 content), then the field is encoded as a nil value. 1185 recipients: This field contains an array of recipient information 1186 structures. The type for the recipient information structure is a 1187 COSE_recipient. 1189 The CDDL fragment that corresponds to the above text is: 1191 COSE_Encrypt = [ 1192 Headers, 1193 ciphertext : bstr / nil, 1194 recipients : [+COSE_recipient] 1195 ] 1197 The COSE_recipient structure is a CBOR array. The fields of the 1198 array in order are: 1200 protected: This is as described in Section 3. 1202 unprotected: This is as described in Section 3. 1204 ciphertext: This field contains the encrypted key encoded as a bstr. 1205 All encoded keys are symmetric keys; the binary value of the key 1206 is the content. If there is not an encrypted key, then this field 1207 is encoded as a nil value. 1209 recipients: This field contains an array of recipient information 1210 structures. The type for the recipient information structure is a 1211 COSE_recipient (an example of this can be found in Appendix B). 1212 If there are no recipient information structures, this element is 1213 absent. 1215 The CDDL fragment that corresponds to the above text for 1216 COSE_recipient is: 1218 COSE_recipient = [ 1219 Headers, 1220 ciphertext : bstr / nil, 1221 ? recipients : [+COSE_recipient] 1222 ] 1224 6.1.1. Content Key Distribution Methods 1226 An encrypted message consists of an encrypted content and an 1227 encrypted CEK for one or more recipients. The CEK is encrypted for 1228 each recipient, using a key specific to that recipient. The details 1229 of this encryption depend on which class the recipient algorithm 1230 falls into. Specific details on each of the classes can be found in 1231 Section 9.5. A short summary of the five content key distribution 1232 methods is: 1234 direct: The CEK is the same as the identified previously distributed 1235 symmetric key or is derived from a previously distributed secret. 1236 No CEK is transported in the message. 1238 symmetric key-encryption keys (KEK): The CEK is encrypted using a 1239 previously distributed symmetric KEK. Also known as key wrap. 1241 key agreement: The recipient's public key and a sender's private key 1242 are used to generate a pairwise secret, a Key Derivation Function 1243 (KDF) is applied to derive a key, and then the CEK is either the 1244 derived key or encrypted by the derived key. 1246 key transport: The CEK is encrypted with the recipient's public key. 1248 passwords: The CEK is encrypted in a KEK that is derived from a 1249 password. As of when this document was published, no password 1250 algorithms have been defined. 1252 6.2. Single Recipient Encrypted 1254 The COSE_Encrypt0 encrypted structure does not have the ability to 1255 specify recipients of the message. The structure assumes that the 1256 recipient of the object will already know the identity of the key to 1257 be used in order to decrypt the message. If a key needs to be 1258 identified to the recipient, the enveloped structure ought to be 1259 used. 1261 Examples of encrypted messages can be found in Appendix C.3. 1263 The COSE_Encrypt0 structure can be encoded as either tagged or 1264 untagged depending on the context it will be used in. A tagged 1265 COSE_Encrypt0 structure is identified by the CBOR tag 16. The CDDL 1266 fragment that represents this is: 1268 COSE_Encrypt0_Tagged = #6.16(COSE_Encrypt0) 1270 The COSE_Encrypt0 structure is a CBOR array. The fields of the array 1271 in order are: 1273 protected: This is as described in Section 3. 1275 unprotected: This is as described in Section 3. 1277 ciphertext: This is as described in Section 6.1. 1279 The CDDL fragment for COSE_Encrypt0 that corresponds to the above 1280 text is: 1282 COSE_Encrypt0 = [ 1283 Headers, 1284 ciphertext : bstr / nil, 1285 ] 1287 6.3. How to Encrypt and Decrypt for AEAD Algorithms 1289 The encryption algorithm for AEAD algorithms is fairly simple. The 1290 first step is to create a consistent byte string for the 1291 authenticated data structure. For this purpose, we use an 1292 Enc_structure. The Enc_structure is a CBOR array. The fields of the 1293 Enc_structure in order are: 1295 1. A text string identifying the context of the authenticated data 1296 structure. The context string is: 1298 "Encrypt0" for the content encryption of a COSE_Encrypt0 data 1299 structure. 1301 "Encrypt" for the first layer of a COSE_Encrypt data structure 1302 (i.e., for content encryption). 1304 "Enc_Recipient" for a recipient encoding to be placed in an 1305 COSE_Encrypt data structure. 1307 "Mac_Recipient" for a recipient encoding to be placed in a 1308 MACed message structure. 1310 "Rec_Recipient" for a recipient encoding to be placed in a 1311 recipient structure. 1313 2. The protected attributes from the body structure encoded in a 1314 bstr type. If there are no protected attributes, a bstr of 1315 length zero is used. 1317 3. The protected attributes from the application encoded in a bstr 1318 type. If this field is not supplied, it defaults to a zero- 1319 length bstr. (See Section 4.3 for application guidance on 1320 constructing this field.) 1322 The CDDL fragment that describes the above text is: 1324 Enc_structure = [ 1325 context : "Encrypt" / "Encrypt0" / "Enc_Recipient" / 1326 "Mac_Recipient" / "Rec_Recipient", 1327 protected : empty_or_serialized_map, 1328 external_aad : bstr 1329 ] 1331 How to encrypt a message: 1333 1. Create an Enc_structure and populate it with the appropriate 1334 fields. 1336 2. Encode the Enc_structure to a byte string (Additional 1337 Authenticated Data (AAD)), using the encoding described in 1338 Section 10. 1340 3. Determine the encryption key (K). This step is dependent on the 1341 class of recipient algorithm being used. For: 1343 No Recipients: The key to be used is determined by the algorithm 1344 and key at the current layer. Examples are key transport keys 1345 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1346 secrets. 1348 Direct Encryption and Direct Key Agreement: The key is 1349 determined by the key and algorithm in the recipient 1350 structure. The encryption algorithm and size of the key to be 1351 used are inputs into the KDF used for the recipient. (For 1352 direct, the KDF can be thought of as the identity operation.) 1353 Examples of these algorithms are found in Sections 6.1.2 and 1354 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1356 Other: The key is randomly or pseudorandomly generated. 1358 4. Call the encryption algorithm with K (the encryption key), P (the 1359 plaintext), and AAD. Place the returned ciphertext into the 1360 'ciphertext' field of the structure. 1362 5. For recipients of the message, recursively perform the encryption 1363 algorithm for that recipient, using K (the encryption key) as the 1364 plaintext. 1366 How to decrypt a message: 1368 1. Create an Enc_structure and populate it with the appropriate 1369 fields. 1371 2. Encode the Enc_structure to a byte string (AAD), using the 1372 encoding described in Section 10. 1374 3. Determine the decryption key. This step is dependent on the 1375 class of recipient algorithm being used. For: 1377 No Recipients: The key to be used is determined by the algorithm 1378 and key at the current layer. Examples are key transport keys 1379 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1380 secrets. 1382 Direct Encryption and Direct Key Agreement: The key is 1383 determined by the key and algorithm in the recipient 1384 structure. The encryption algorithm and size of the key to be 1385 used are inputs into the KDF used for the recipient. (For 1386 direct, the KDF can be thought of as the identity operation.) 1388 Other: The key is determined by decoding and decrypting one of 1389 the recipient structures. 1391 4. Call the decryption algorithm with K (the decryption key to use), 1392 C (the ciphertext), and AAD. 1394 6.4. How to Encrypt and Decrypt for AE Algorithms 1396 How to encrypt a message: 1398 1. Verify that the 'protected' field is empty. 1400 2. Verify that there was no external additional authenticated data 1401 supplied for this operation. 1403 3. Determine the encryption key. This step is dependent on the 1404 class of recipient algorithm being used. For: 1406 No Recipients: The key to be used is determined by the algorithm 1407 and key at the current layer. Examples are key transport keys 1408 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1409 secrets. 1411 Direct Encryption and Direct Key Agreement: The key is 1412 determined by the key and algorithm in the recipient 1413 structure. The encryption algorithm and size of the key to be 1414 used are inputs into the KDF used for the recipient. (For 1415 direct, the KDF can be thought of as the identity operation.) 1416 Examples of these algorithms are found in Sections 6.1.2 and 1417 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1419 Other: The key is randomly generated. 1421 4. Call the encryption algorithm with K (the encryption key to use) 1422 and P (the plaintext). Place the returned ciphertext into the 1423 'ciphertext' field of the structure. 1425 5. For recipients of the message, recursively perform the encryption 1426 algorithm for that recipient, using K (the encryption key) as the 1427 plaintext. 1429 How to decrypt a message: 1431 1. Verify that the 'protected' field is empty. 1433 2. Verify that there was no external additional authenticated data 1434 supplied for this operation. 1436 3. Determine the decryption key. This step is dependent on the 1437 class of recipient algorithm being used. For: 1439 No Recipients: The key to be used is determined by the algorithm 1440 and key at the current layer. Examples are key transport keys 1441 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1442 secrets. 1444 Direct Encryption and Direct Key Agreement: The key is 1445 determined by the key and algorithm in the recipient 1446 structure. The encryption algorithm and size of the key to be 1447 used are inputs into the KDF used for the recipient. (For 1448 direct, the KDF can be thought of as the identity operation.) 1449 Examples of these algorithms are found in Sections 6.1.2 and 1450 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1452 Other: The key is determined by decoding and decrypting one of 1453 the recipient structures. 1455 4. Call the decryption algorithm with K (the decryption key to use) 1456 and C (the ciphertext). 1458 7. MAC Objects 1460 COSE supports two different MAC structures. COSE_MAC0 is used when a 1461 recipient structure is not needed because the key to be used is 1462 implicitly known. COSE_MAC is used for all other cases. These 1463 include a requirement for multiple recipients, the key being unknown, 1464 and a recipient algorithm of other than direct. 1466 In this section, we describe the structure and methods to be used 1467 when doing MAC authentication in COSE. This document allows for the 1468 use of all of the same classes of recipient algorithms as are allowed 1469 for encryption. 1471 When using MAC operations, there are two modes in which they can be 1472 used. The first is just a check that the content has not been 1473 changed since the MAC was computed. Any class of recipient algorithm 1474 can be used for this purpose. The second mode is to both check that 1475 the content has not been changed since the MAC was computed and to 1476 use the recipient algorithm to verify who sent it. The classes of 1477 recipient algorithms that support this are those that use a pre- 1478 shared secret or do static-static (SS) key agreement (without the key 1479 wrap step). In both of these cases, the entity that created and sent 1480 the message MAC can be validated. (This knowledge of the sender 1481 assumes that there are only two parties involved and that you did not 1482 send the message to yourself.) The origination property can be 1483 obtained with both of the MAC message structures. 1485 7.1. MACed Message with Recipients 1487 The multiple recipient MACed message uses two structures: the 1488 COSE_Mac structure defined in this section for carrying the body and 1489 the COSE_recipient structure (Section 6.1) to hold the key used for 1490 the MAC computation. Examples of MACed messages can be found in 1491 Appendix C.5. 1493 The MAC structure can be encoded as either tagged or untagged 1494 depending on the context it will be used in. A tagged COSE_Mac 1495 structure is identified by the CBOR tag 97. The CDDL fragment that 1496 represents this is: 1498 COSE_Mac_Tagged = #6.97(COSE_Mac) 1500 The COSE_Mac structure is a CBOR array. The fields of the array in 1501 order are: 1503 protected: This is as described in Section 3. 1505 unprotected: This is as described in Section 3. 1507 payload: This field contains the serialized content to be MACed. If 1508 the payload is not present in the message, the application is 1509 required to supply the payload separately. The payload is wrapped 1510 in a bstr to ensure that it is transported without changes. If 1511 the payload is transported separately (i.e., detached content), 1512 then a nil CBOR value is placed in this location, and it is the 1513 responsibility of the application to ensure that it will be 1514 transported without changes. 1516 tag: This field contains the MAC value. 1518 recipients: This is as described in Section 6.1. 1520 The CDDL fragment that represents the above text for COSE_Mac 1521 follows. 1523 COSE_Mac = [ 1524 Headers, 1525 payload : bstr / nil, 1526 tag : bstr, 1527 recipients :[+COSE_recipient] 1528 ] 1530 7.2. MACed Messages with Implicit Key 1532 In this section, we describe the structure and methods to be used 1533 when doing MAC authentication for those cases where the recipient is 1534 implicitly known. 1536 The MACed message uses the COSE_Mac0 structure defined in this 1537 section for carrying the body. Examples of MACed messages with an 1538 implicit key can be found in Appendix C.6. 1540 The MAC structure can be encoded as either tagged or untagged 1541 depending on the context it will be used in. A tagged COSE_Mac0 1542 structure is identified by the CBOR tag 17. The CDDL fragment that 1543 represents this is: 1545 COSE_Mac0_Tagged = #6.17(COSE_Mac0) 1547 The COSE_Mac0 structure is a CBOR array. The fields of the array in 1548 order are: 1550 protected: This is as described in Section 3. 1552 unprotected: This is as described in Section 3. 1554 payload: This is as described in Section 7.1. 1556 tag: This field contains the MAC value. 1558 The CDDL fragment that corresponds to the above text is: 1560 COSE_Mac0 = [ 1561 Headers, 1562 payload : bstr / nil, 1563 tag : bstr, 1564 ] 1566 7.3. How to Compute and Verify a MAC 1568 In order to get a consistent encoding of the data to be 1569 authenticated, the MAC_structure is used to have a canonical form. 1570 The MAC_structure is a CBOR array. The fields of the MAC_structure 1571 in order are: 1573 1. A text string that identifies the structure that is being 1574 encoded. This string is "MAC" for the COSE_Mac structure. This 1575 string is "MAC0" for the COSE_Mac0 structure. 1577 2. The protected attributes from the COSE_MAC structure. If there 1578 are no protected attributes, a zero-length bstr is used. 1580 3. The protected attributes from the application encoded as a bstr 1581 type. If this field is not supplied, it defaults to a zero- 1582 length binary string. (See Section 4.3 for application guidance 1583 on constructing this field.) 1585 4. The payload to be MACed encoded in a bstr type. The payload is 1586 placed here independent of how it is transported. 1588 The CDDL fragment that corresponds to the above text is: 1590 MAC_structure = [ 1591 context : "MAC" / "MAC0", 1592 protected : empty_or_serialized_map, 1593 external_aad : bstr, 1594 payload : bstr 1595 ] 1597 The steps to compute a MAC are: 1599 1. Create a MAC_structure and populate it with the appropriate 1600 fields. 1602 2. Create the value ToBeMaced by encoding the MAC_structure to a 1603 byte string, using the encoding described in Section 10. 1605 3. Call the MAC creation algorithm passing in K (the key to use), 1606 alg (the algorithm to MAC with), and ToBeMaced (the value to 1607 compute the MAC on). 1609 4. Place the resulting MAC in the 'tag' field of the COSE_Mac or 1610 COSE_Mac0 structure. 1612 5. For COSE_Mac structures, encrypt and encode the MAC key for each 1613 recipient of the message. 1615 The steps to verify a MAC are: 1617 1. Create a MAC_structure object and populate it with the 1618 appropriate fields. 1620 2. Create the value ToBeMaced by encoding the MAC_structure to a 1621 byte string, using the encoding described in Section 10. 1623 3. For COSE_Mac structures, obtain the cryptographic key from one of 1624 the recipients of the message. 1626 4. Call the MAC creation algorithm passing in K (the key to use), 1627 alg (the algorithm to MAC with), and ToBeMaced (the value to 1628 compute the MAC on). 1630 5. Compare the MAC value to the 'tag' field of the COSE_Mac or 1631 COSE_Mac0 structure. 1633 8. Key Objects 1635 A COSE Key structure is built on a CBOR map object. The set of 1636 common parameters that can appear in a COSE Key can be found in the 1637 IANA "COSE Key Common Parameters" registry (Section 12.4). 1638 Additional parameters defined for specific key types can be found in 1639 the IANA "COSE Key Type Parameters" registry ([COSE.KeyParameters]). 1641 A COSE Key Set uses a CBOR array object as its underlying type. The 1642 values of the array elements are COSE Keys. A COSE Key Set MUST have 1643 at least one element in the array. Examples of COSE Key Sets can be 1644 found in Appendix C.7. 1646 Each element in a COSE Key Set MUST be processed independently. If 1647 one element in a COSE Key Set is either malformed or uses a key that 1648 is not understood by an application, that key is ignored and the 1649 other keys are processed normally. 1651 The element "kty" is a required element in a COSE_Key map. 1653 The CDDL grammar describing COSE_Key and COSE_KeySet is: 1655 COSE_Key = { 1656 1 => tstr / int, ; kty 1657 ? 2 => bstr, ; kid 1658 ? 3 => tstr / int, ; alg 1659 ? 4 => [+ (tstr / int) ], ; key_ops 1660 ? 5 => bstr, ; Base IV 1661 * label => values 1662 } 1664 COSE_KeySet = [+COSE_Key] 1666 8.1. COSE Key Common Parameters 1668 This document defines a set of common parameters for a COSE Key 1669 object. Table 5 provides a summary of the parameters defined in this 1670 section. There are also parameters that are defined for specific key 1671 types. Key-type-specific parameters can be found in 1672 [I-D.ietf-cose-rfc8152bis-algs]. 1674 +---------+-------+----------------+------------+-------------------+ 1675 | Name | Label | CBOR Type | Value | Description | 1676 | | | | Registry | | 1677 +---------+-------+----------------+------------+-------------------+ 1678 | kty | 1 | tstr / int | COSE Key | Identification of | 1679 | | | | Types | the key type | 1680 | | | | | | 1681 | kid | 2 | bstr | | Key | 1682 | | | | | identification | 1683 | | | | | value -- match to | 1684 | | | | | kid in message | 1685 | | | | | | 1686 | alg | 3 | tstr / int | COSE | Key usage | 1687 | | | | Algorithms | restriction to | 1688 | | | | | this algorithm | 1689 | | | | | | 1690 | key_ops | 4 | [+ (tstr/int)] | | Restrict set of | 1691 | | | | | permissible | 1692 | | | | | operations | 1693 | | | | | | 1694 | Base IV | 5 | bstr | | Base IV to be | 1695 | | | | | xor-ed with | 1696 | | | | | Partial IVs | 1697 +---------+-------+----------------+------------+-------------------+ 1699 Table 5: Key Map Labels 1701 kty: This parameter is used to identify the family of keys for this 1702 structure and, thus, the set of key-type-specific parameters to be 1703 found. The set of values defined in this document can be found in 1704 [COSE.KeyTypes]. This parameter MUST be present in a key object. 1705 Implementations MUST verify that the key type is appropriate for 1706 the algorithm being processed. The key type MUST be included as 1707 part of the trust decision process. 1709 alg: This parameter is used to restrict the algorithm that is used 1710 with the key. If this parameter is present in the key structure, 1711 the application MUST verify that this algorithm matches the 1712 algorithm for which the key is being used. If the algorithms do 1713 not match, then this key object MUST NOT be used to perform the 1714 cryptographic operation. Note that the same key can be in a 1715 different key structure with a different or no algorithm 1716 specified; however, this is considered to be a poor security 1717 practice. 1719 kid: This parameter is used to give an identifier for a key. The 1720 identifier is not structured and can be anything from a user- 1721 provided string to a value computed on the public portion of the 1722 key. This field is intended for matching against a 'kid' 1723 parameter in a message in order to filter down the set of keys 1724 that need to be checked. 1726 key_ops: This parameter is defined to restrict the set of operations 1727 that a key is to be used for. The value of the field is an array 1728 of values from Table 6. Algorithms define the values of key ops 1729 that are permitted to appear and are required for specific 1730 operations. The set of values matches that in [RFC7517] and 1731 [W3C.WebCrypto]. 1733 Base IV: This parameter is defined to carry the base portion of an 1734 IV. It is designed to be used with the Partial IV header 1735 parameter defined in Section 3.1. This field provides the ability 1736 to associate a Partial IV with a key that is then modified on a 1737 per message basis with the Partial IV. 1739 Extreme care needs to be taken when using a Base IV in an 1740 application. Many encryption algorithms lose security if the same 1741 IV is used twice. 1743 If different keys are derived for each sender, using the same Base 1744 IV with Partial IVs starting at zero is likely to ensure that the 1745 IV would not be used twice for a single key. If different keys 1746 are derived for each sender, starting at the same Base IV is 1747 likely to satisfy this condition. If the same key is used for 1748 multiple senders, then the application needs to provide for a 1749 method of dividing the IV space up between the senders. This 1750 could be done by providing a different base point to start from or 1751 a different Partial IV to start with and restricting the number of 1752 messages to be sent before rekeying. 1754 +---------+-------+-------------------------------------------------+ 1755 | Name | Value | Description | 1756 +---------+-------+-------------------------------------------------+ 1757 | sign | 1 | The key is used to create signatures. Requires | 1758 | | | private key fields. | 1759 | verify | 2 | The key is used for verification of signatures. | 1760 | encrypt | 3 | The key is used for key transport encryption. | 1761 | decrypt | 4 | The key is used for key transport decryption. | 1762 | | | Requires private key fields. | 1763 | wrap | 5 | The key is used for key wrap encryption. | 1764 | key | | | 1765 | unwrap | 6 | The key is used for key wrap decryption. | 1766 | key | | Requires private key fields. | 1767 | derive | 7 | The key is used for deriving keys. Requires | 1768 | key | | private key fields. | 1769 | derive | 8 | The key is used for deriving bits not to be | 1770 | bits | | used as a key. Requires private key fields. | 1771 | MAC | 9 | The key is used for creating MACs. | 1772 | create | | | 1773 | MAC | 10 | The key is used for validating MACs. | 1774 | verify | | | 1775 +---------+-------+-------------------------------------------------+ 1777 Table 6: Key Operation Values 1779 9. Taxonomy of Algorithms used by COSE 1781 In this section, a taxonomy of the different algorithm types that can 1782 be used in COSE is laid out. This taxonomy should not be considered 1783 to be exhaustive as there are new algorithm structures that could be 1784 found or are not known to the author. 1786 9.1. Signature Algorithms 1788 There are two signature algorithm schemes. The first is signature 1789 with appendix. In this scheme, the message content is processed and 1790 a signature is produced; the signature is called the appendix. This 1791 is the scheme used by algorithms such as ECDSA and the RSA 1792 Probabilistic Signature Scheme (RSASSA-PSS). (In fact, the SSA in 1793 RSASSA-PSS stands for Signature Scheme with Appendix.) 1795 The signature functions for this scheme are: 1797 signature = Sign(message content, key) 1799 valid = Verification(message content, key, signature) 1801 The second scheme is signature with message recovery (an example of 1802 such an algorithm is [PVSig]). In this scheme, the message content 1803 is processed, but part of it is included in the signature. Moving 1804 bytes of the message content into the signature allows for smaller 1805 signatures; the signature size is still potentially large, but the 1806 message content has shrunk. This has implications for systems 1807 implementing these algorithms and for applications that use them. 1808 The first is that the message content is not fully available until 1809 after a signature has been validated. Until that point, the part of 1810 the message contained inside of the signature is unrecoverable. The 1811 second is that the security analysis of the strength of the signature 1812 is very much based on the structure of the message content. Messages 1813 that are highly predictable require additional randomness to be 1814 supplied as part of the signature process. In the worst case, it 1815 becomes the same as doing a signature with appendix. Finally, in the 1816 event that multiple signatures are applied to a message, all of the 1817 signature algorithms are going to be required to consume the same 1818 number of bytes of message content. This means that the mixing of 1819 the different schemes in a single message is not supported, and if a 1820 recovery signature scheme is used, then the same amount of content 1821 needs to be consumed by all of the signatures. 1823 The signature functions for this scheme are: 1825 signature, message sent = Sign(message content, key) 1827 valid, message content = Verification(message sent, key, signature) 1829 Signature algorithms are used with the COSE_Signature and COSE_Sign1 1830 structures. At this time, only signatures with appendixes are 1831 defined for use with COSE; however, considerable interest has been 1832 expressed in using a signature with message recovery algorithm due to 1833 the effective size reduction that is possible. Implementations will 1834 need to keep this in mind for later possible integration. 1836 9.2. Message Authentication Code (MAC) Algorithms 1838 Message Authentication Codes (MACs) provide data authentication and 1839 integrity protection. They provide either no or very limited data 1840 origination. A MAC, for example, cannot be used to prove the 1841 identity of the sender to a third party. 1843 MACs use the same scheme as signature with appendix algorithms. The 1844 message content is processed and an authentication code is produced. 1845 The authentication code is frequently called a tag. 1847 The MAC functions are: 1849 tag = MAC_Create(message content, key) 1851 valid = MAC_Verify(message content, key, tag) 1853 MAC algorithms can be based on either a block cipher algorithm (i.e., 1854 AES-MAC) or a hash algorithm (i.e., a Hash-based Message 1855 Authentication Code (HMAC)). [I-D.ietf-cose-rfc8152bis-algs] defines 1856 a MAC algorithm using each of these constructions. 1858 MAC algorithms are used in the COSE_Mac and COSE_Mac0 structures. 1860 9.3. Content Encryption Algorithms 1862 Content encryption algorithms provide data confidentiality for 1863 potentially large blocks of data using a symmetric key. They provide 1864 integrity on the data that was encrypted; however, they provide 1865 either no or very limited data origination. (One cannot, for 1866 example, be used to prove the identity of the sender to a third 1867 party.) The ability to provide data origination is linked to how the 1868 CEK is obtained. 1870 COSE restricts the set of legal content encryption algorithms to 1871 those that support authentication both of the content and additional 1872 data. The encryption process will generate some type of 1873 authentication value, but that value may be either explicit or 1874 implicit in terms of the algorithm definition. For simplicity's 1875 sake, the authentication code will normally be defined as being 1876 appended to the ciphertext stream. The encryption functions are: 1878 ciphertext = Encrypt(message content, key, additional data) 1880 valid, message content = Decrypt(ciphertext, key, additional data) 1882 Most AEAD algorithms are logically defined as returning the message 1883 content only if the decryption is valid. Many but not all 1884 implementations will follow this convention. The message content 1885 MUST NOT be used if the decryption does not validate. 1887 These algorithms are used in COSE_Encrypt and COSE_Encrypt0. 1889 9.4. Key Derivation Functions (KDFs) 1891 KDFs are used to take some secret value and generate a different one. 1892 The secret value comes in three flavors: 1894 o Secrets that are uniformly random: This is the type of secret that 1895 is created by a good random number generator. 1897 o Secrets that are not uniformly random: This is type of secret that 1898 is created by operations like key agreement. 1900 o Secrets that are not random: This is the type of secret that 1901 people generate for things like passwords. 1903 General KDFs work well with the first type of secret, can do 1904 reasonably well with the second type of secret, and generally do 1905 poorly with the last type of secret. Functions like PBES2 [RFC8018] 1906 need to be used for non-random secrets. 1908 The same KDF can be set up to deal with the first two types of 1909 secrets in a different way. The KDF defined in section 5.1 of 1910 [I-D.ietf-cose-rfc8152bis-algs] is such a function. This is 1911 reflected in the set of algorithms defined around the HMAC-based 1912 Extract-and-Expand Key Derivation Function (HKDF). 1914 When using KDFs, one component that is included is context 1915 information. Context information is used to allow for different 1916 keying information to be derived from the same secret. The use of 1917 context-based keying material is considered to be a good security 1918 practice. 1920 9.5. Content Key Distribution Methods 1922 Content key distribution methods (recipient algorithms) can be 1923 defined into a number of different classes. COSE has the ability to 1924 support many classes of recipient algorithms. In this section, a 1925 number of classes are listed. The names of the recipient algorithm 1926 classes used here are the same as those defined in [RFC7516]. Other 1927 specifications use different terms for the recipient algorithm 1928 classes or do not support some of the recipient algorithm classes. 1930 9.5.1. Direct Encryption 1932 The direct encryption class algorithms share a secret between the 1933 sender and the recipient that is used either directly or after 1934 manipulation as the CEK. When direct encryption mode is used, it 1935 MUST be the only mode used on the message. 1937 The COSE_Recipient structure for the recipient is organized as 1938 follows: 1940 o The 'protected' field MUST be a zero-length item unless it is used 1941 in the computation of the content key. 1943 o The 'alg' parameter MUST be present. 1945 o A parameter identifying the shared secret SHOULD be present. 1947 o The 'ciphertext' field MUST be a zero-length item. 1949 o The 'recipients' field MUST be absent. 1951 9.5.2. Key Wrap 1953 In key wrap mode, the CEK is randomly generated and that key is then 1954 encrypted by a shared secret between the sender and the recipient. 1955 All of the currently defined key wrap algorithms for COSE are AE 1956 algorithms. Key wrap mode is considered to be superior to direct 1957 encryption if the system has any capability for doing random key 1958 generation. This is because the shared key is used to wrap random 1959 data rather than data that has some degree of organization and may in 1960 fact be repeating the same content. The use of key wrap loses the 1961 weak data origination that is provided by the direct encryption 1962 algorithms. 1964 The COSE_Encrypt structure for the recipient is organized as follows: 1966 o The 'protected' field MUST be absent if the key wrap algorithm is 1967 an AE algorithm. 1969 o The 'recipients' field is normally absent, but can be used. 1970 Applications MUST deal with a recipient field being present that 1971 has an unsupported algorthms, not being able to decrypt that 1972 recipient is an acceptable way of dealing with it. Failing to 1973 process the message is not an acceptable way of dealing with it. 1975 o The plaintext to be encrypted is the key from next layer down 1976 (usually the content layer). 1978 o At a minimum, the 'unprotected' field MUST contain the 'alg' 1979 parameter and SHOULD contain a parameter identifying the shared 1980 secret. 1982 9.5.3. Key Transport 1984 Key transport mode is also called key encryption mode in some 1985 standards. Key transport mode differs from key wrap mode in that it 1986 uses an asymmetric encryption algorithm rather than a symmetric 1987 encryption algorithm to protect the key. A set of key transport 1988 algorithms are defined in [RFC8230]. 1990 When using a key transport algorithm, the COSE_Encrypt structure for 1991 the recipient is organized as follows: 1993 o The 'protected' field MUST be absent. 1995 o The plaintext to be encrypted is the key from the next layer down 1996 (usually the content layer). 1998 o At a minimum, the 'unprotected' field MUST contain the 'alg' 1999 parameter and SHOULD contain a parameter identifying the 2000 asymmetric key. 2002 9.5.4. Direct Key Agreement 2004 The 'direct key agreement' class of recipient algorithms uses a key 2005 agreement method to create a shared secret. A KDF is then applied to 2006 the shared secret to derive a key to be used in protecting the data. 2007 This key is normally used as a CEK or MAC key, but could be used for 2008 other purposes if more than two layers are in use (see Appendix B). 2010 The most commonly used key agreement algorithm is Diffie-Hellman, but 2011 other variants exist. Since COSE is designed for a store and forward 2012 environment rather than an online environment, many of the DH 2013 variants cannot be used as the receiver of the message cannot provide 2014 any dynamic key material. One side effect of this is that perfect 2015 forward secrecy (see [RFC4949]) is not achievable. A static key will 2016 always be used for the receiver of the COSE object. 2018 Two variants of DH that are supported are: 2020 Ephemeral-Static (ES) DH: where the sender of the message creates 2021 a one-time DH key and uses a static key for the recipient. The 2022 use of the ephemeral sender key means that no additional random 2023 input is needed as this is randomly generated for each message. 2025 Static-Static (SS) DH: where a static key is used for both the 2026 sender and the recipient. The use of static keys allows for the 2027 recipient to get a weak version of data origination for the 2028 message. When static-static key agreement is used, then some 2029 piece of unique data for the KDF is required to ensure that a 2030 different key is created for each message. 2032 When direct key agreement mode is used, there MUST be only one 2033 recipient in the message. This method creates the key directly, and 2034 that makes it difficult to mix with additional recipients. If 2035 multiple recipients are needed, then the version with key wrap needs 2036 to be used. 2038 The COSE_Encrypt structure for the recipient is organized as follows: 2040 o At a minimum, headers MUST contain the 'alg' parameter and SHOULD 2041 contain a parameter identifying the recipient's asymmetric key. 2043 o The headers SHOULD identify the sender's key for the static-static 2044 versions and MUST contain the sender's ephemeral key for the 2045 ephemeral-static versions. 2047 9.5.5. Key Agreement with Key Wrap 2049 Key Agreement with Key Wrap uses a randomly generated CEK. The CEK 2050 is then encrypted using a key wrap algorithm and a key derived from 2051 the shared secret computed by the key agreement algorithm. The 2052 function for this would be: 2054 encryptedKey = KeyWrap(KDF(DH-Shared, context), CEK) 2056 The COSE_Encrypt structure for the recipient is organized as follows: 2058 o The 'protected' field is fed into the KDF context structure. 2060 o The plaintext to be encrypted is the key from the next layer down 2061 (usually the content layer). 2063 o The 'alg' parameter MUST be present in the layer. 2065 o A parameter identifying the recipient's key SHOULD be present. A 2066 parameter identifying the sender's key SHOULD be present. 2068 10. CBOR Encoding Restrictions 2070 There has been an attempt to limit the number of places where the 2071 document needs to impose restrictions on how the CBOR Encoder needs 2072 to work. We have managed to narrow it down to the following 2073 restrictions: 2075 o The restriction applies to the encoding of the Sig_structure, the 2076 Enc_structure, and the MAC_structure. 2078 o Encoding MUST be done using definite lengths and values MUST be 2079 the minimum possible length. This means that the integer 1 is 2080 encoded as "0x01" and not "0x1801". 2082 o Applications MUST NOT generate messages with the same label used 2083 twice as a key in a single map. Applications MUST NOT parse and 2084 process messages with the same label used twice as a key in a 2085 single map. Applications can enforce the parse and process 2086 requirement by using parsers that will fail the parse step or by 2087 using parsers that will pass all keys to the application, and the 2088 application can perform the check for duplicate keys. 2090 11. Application Profiling Considerations 2092 This document is designed to provide a set of security services, but 2093 not impose algorithm implementation requirements for specific usage. 2094 The interoperability requirements are provided for how each of the 2095 individual services are used and how the algorithms are to be used 2096 for interoperability. The requirements about which algorithms and 2097 which services are needed are deferred to each application. 2099 An example of a profile can be found in [RFC8613] where one was 2100 developed for carrying content in combination with CoAP headers. 2102 It is intended that a profile of this document be created that 2103 defines the interoperability requirements for that specific 2104 application. This section provides a set of guidelines and topics 2105 that need to be considered when profiling this document. 2107 o Applications need to determine the set of messages defined in this 2108 document that they will be using. The set of messages corresponds 2109 fairly directly to the set of security services that are needed 2110 and to the security levels needed. 2112 o Applications may define new header parameters for a specific 2113 purpose. Applications will often times select specific header 2114 parameters to use or not to use. For example, an application 2115 would normally state a preference for using either the IV or the 2116 Partial IV parameter. If the Partial IV parameter is specified, 2117 then the application also needs to define how the fixed portion of 2118 the IV is determined. 2120 o When applications use externally defined authenticated data, they 2121 need to define how that data is encoded. This document assumes 2122 that the data will be provided as a byte string. More information 2123 can be found in Section 4.3. 2125 o Applications need to determine the set of security algorithms that 2126 are to be used. When selecting the algorithms to be used as the 2127 mandatory-to-implement set, consideration should be given to 2128 choosing different types of algorithms when two are chosen for a 2129 specific purpose. An example of this would be choosing HMAC- 2130 SHA512 and AES-CMAC as different MAC algorithms; the construction 2131 is vastly different between these two algorithms. This means that 2132 a weakening of one algorithm would be unlikely to lead to a 2133 weakening of the other algorithms. Of course, these algorithms do 2134 not provide the same level of security and thus may not be 2135 comparable for the desired security functionality. 2137 o Applications may need to provide some type of negotiation or 2138 discovery method if multiple algorithms or message structures are 2139 permitted. The method can be as simple as requiring 2140 preconfiguration of the set of algorithms to providing a discovery 2141 method built into the protocol. S/MIME provided a number of 2142 different ways to approach the problem that applications could 2143 follow: 2145 * Advertising in the message (S/MIME capabilities) [RFC5751]. 2147 * Advertising in the certificate (capabilities extension) 2148 [RFC4262]. 2150 * Minimum requirements for the S/MIME, which have been updated 2151 over time [RFC2633] [RFC5751] (note that [RFC2633] has been 2152 obsoleted by [RFC5751]). 2154 12. IANA Considerations 2156 The registeries and registrations listed below were created during 2157 processing of RFC 8152 [RFC8152]. The only known action at this time 2158 is to update the references. 2160 12.1. CBOR Tag Assignment 2162 IANA assigned tags in the "CBOR Tags" registry as part of processing 2163 [RFC8152]. IANA is requested to update the references from [RFC8152] 2164 to this document. 2166 IANA is requested to register a new tag for the CounterSignature 2167 type. 2169 Tag: TBD0 2171 Data Item: COSE_Signature 2172 Semantics: COSE standalone counter signature 2174 Reference: [[this document]] 2176 12.2. COSE Header Parameters Registry 2178 IANA created a registry titled "COSE Header Parameters" as part of 2179 processing [RFC8152]. The registry has been created to use the 2180 "Expert Review Required" registration procedure [RFC8126]. 2182 IANA is requested to update the reference for entries in the table 2183 from [RFC8152] to this document. This document does not update the 2184 expert review guidelines provided in [RFC8152]. 2186 12.3. COSE Header Algorithm Parameters Registry 2188 IANA created a registry titled "COSE Header Algorithm Parameters" as 2189 part of processing [RFC8152]. The registry has been created to use 2190 the "Expert Review Required" registration procedure [RFC8126]. 2192 IANA is requested to update the references from [RFC8152] to this 2193 document. This document does not update the expert review guidelines 2194 provided in [RFC8152]. 2196 12.4. COSE Key Common Parameters Registry 2198 IANA created a registry titled "COSE Key Common Parameters" as part 2199 of the processing of [RFC8152]. The registry has been created to use 2200 the "Expert Review Required" registration procedure [RFC8126]. 2202 IANA is requested to update the reference for entries in the table 2203 from [RFC8152] to this document. This document does not update the 2204 expert review guidelines provided in [RFC8152]. 2206 12.5. Media Type Registrations 2208 12.5.1. COSE Security Message 2210 This section registers the 'application/cose' media type in the 2211 "Media Types" registry. These media types are used to indicate that 2212 the content is a COSE message. 2214 Type name: application 2216 Subtype name: cose 2218 Required parameters: N/A 2219 Optional parameters: cose-type 2221 Encoding considerations: binary 2223 Security considerations: See the Security Considerations section 2224 of [[This Document]]. 2226 Interoperability considerations: N/A 2228 Published specification: [[this document]] 2230 Applications that use this media type: IoT applications sending 2231 security content over HTTP(S) transports. 2233 Fragment identifier considerations: N/A 2235 Additional information: 2237 * Deprecated alias names for this type: N/A 2239 * Magic number(s): N/A 2241 * File extension(s): cbor 2243 * Macintosh file type code(s): N/A 2245 Person & email address to contact for further information: 2246 iesg@ietf.org 2248 Intended usage: COMMON 2250 Restrictions on usage: N/A 2252 Author: Jim Schaad, ietf@augustcellars.com 2254 Change Controller: IESG 2256 Provisional registration? No 2258 12.5.2. COSE Key Media Type 2260 This section registers the 'application/cose-key' and 'application/ 2261 cose-key-set' media types in the "Media Types" registry. These media 2262 types are used to indicate, respectively, that content is a COSE_Key 2263 or COSE_KeySet object. 2265 The template for registering 'application/cose-key' is: 2267 Type name: application 2269 Subtype name: cose-key 2271 Required parameters: N/A 2273 Optional parameters: N/A 2275 Encoding considerations: binary 2277 Security considerations: See the Security Considerations section 2278 of [[This Document]]. 2280 Interoperability considerations: N/A 2282 Published specification: [[this document]] 2284 Applications that use this media type: Distribution of COSE based 2285 keys for IoT applications. 2287 Fragment identifier considerations: N/A 2289 Additional information: 2291 * Deprecated alias names for this type: N/A 2293 * Magic number(s): N/A 2295 * File extension(s): cbor 2297 * Macintosh file type code(s): N/A 2299 Person & email address to contact for further information: 2300 iesg@ietf.org 2302 Intended usage: COMMON 2304 Restrictions on usage: N/A 2306 Author: Jim Schaad, ietf@augustcellars.com 2308 Change Controller: IESG 2310 Provisional registration? No 2312 The template for registering 'application/cose-key-set' is: 2314 Type name: application 2315 Subtype name: cose-key-set 2317 Required parameters: N/A 2319 Optional parameters: N/A 2321 Encoding considerations: binary 2323 Security considerations: See the Security Considerations section 2324 of [[This Document]]. 2326 Interoperability considerations: N/A 2328 Published specification: [[this document]] 2330 Applications that use this media type: Distribution of COSE based 2331 keys for IoT applications. 2333 Fragment identifier considerations: N/A 2335 Additional information: 2337 * Deprecated alias names for this type: N/A 2339 * Magic number(s): N/A 2341 * File extension(s): cbor 2343 * Macintosh file type code(s): N/A 2345 Person & email address to contact for further information: 2346 iesg@ietf.org 2348 Intended usage: COMMON 2350 Restrictions on usage: N/A 2352 Author: Jim Schaad, ietf@augustcellars.com 2354 Change Controller: IESG 2356 Provisional registration? No 2358 12.6. CoAP Content-Formats Registry 2360 IANA added the following entries to the "CoAP Content-Formats" 2361 registry while processing [RFC8152]. IANA is requested to update the 2362 reference value from [RFC8152] to [[This Document]]. 2364 13. Security Considerations 2366 There are a number of security considerations that need to be taken 2367 into account by implementers of this specification. The security 2368 considerations that are specific to an individual algorithm are 2369 placed next to the description of the algorithm. While some 2370 considerations have been highlighted here, additional considerations 2371 may be found in the documents listed in the references. 2373 Implementations need to protect the private key material for any 2374 individuals. There are some cases that need to be highlighted on 2375 this issue. 2377 o Using the same key for two different algorithms can leak 2378 information about the key. It is therefore recommended that keys 2379 be restricted to a single algorithm. 2381 o Use of 'direct' as a recipient algorithm combined with a second 2382 recipient algorithm exposes the direct key to the second 2383 recipient. 2385 o Several of the algorithms in [I-D.ietf-cose-rfc8152bis-algs] have 2386 limits on the number of times that a key can be used without 2387 leaking information about the key. 2389 The use of ECDH and direct plus KDF (with no key wrap) will not 2390 directly lead to the private key being leaked; the one way function 2391 of the KDF will prevent that. There is, however, a different issue 2392 that needs to be addressed. Having two recipients requires that the 2393 CEK be shared between two recipients. The second recipient therefore 2394 has a CEK that was derived from material that can be used for the 2395 weak proof of origin. The second recipient could create a message 2396 using the same CEK and send it to the first recipient; the first 2397 recipient would, for either static-static ECDH or direct plus KDF, 2398 make an assumption that the CEK could be used for proof of origin 2399 even though it is from the wrong entity. If the key wrap step is 2400 added, then no proof of origin is implied and this is not an issue. 2402 Although it has been mentioned before, the use of a single key for 2403 multiple algorithms has been demonstrated in some cases to leak 2404 information about a key, provide the opportunity for attackers to 2405 forge integrity tags, or gain information about encrypted content. 2406 Binding a key to a single algorithm prevents these problems. Key 2407 creators and key consumers are strongly encouraged not only to create 2408 new keys for each different algorithm, but to include that selection 2409 of algorithm in any distribution of key material and strictly enforce 2410 the matching of algorithms in the key structure to algorithms in the 2411 message structure. In addition to checking that algorithms are 2412 correct, the key form needs to be checked as well. Do not use an 2413 'EC2' key where an 'OKP' key is expected. 2415 Before using a key for transmission, or before acting on information 2416 received, a trust decision on a key needs to be made. Is the data or 2417 action something that the entity associated with the key has a right 2418 to see or a right to request? A number of factors are associated 2419 with this trust decision. Some of the ones that are highlighted here 2420 are: 2422 o What are the permissions associated with the key owner? 2424 o Is the cryptographic algorithm acceptable in the current context? 2426 o Have the restrictions associated with the key, such as algorithm 2427 or freshness, been checked and are they correct? 2429 o Is the request something that is reasonable, given the current 2430 state of the application? 2432 o Have any security considerations that are part of the message been 2433 enforced (as specified by the application or 'crit' parameter)? 2435 There are a large number of algorithms presented in 2436 [I-D.ietf-cose-rfc8152bis-algs] that use nonce values. Nonces 2437 generally have some type of restriction on their values. Generally a 2438 nonce needs to be a unique value either for a key or for some other 2439 conditions. In all of these cases, there is no known requirement on 2440 the nonce being both unique and unpredictable; under these 2441 circumstances, it's reasonable to use a counter for creation of the 2442 nonce. In cases where one wants the pattern of the nonce to be 2443 unpredictable as well as unique, one can use a key created for that 2444 purpose and encrypt the counter to produce the nonce value. 2446 One area that has been starting to get exposure is doing traffic 2447 analysis of encrypted messages based on the length of the message. 2448 This specification does not provide for a uniform method of providing 2449 padding as part of the message structure. An observer can 2450 distinguish between two different strings (for example, 'YES' and 2451 'NO') based on the length for all of the content encryption 2452 algorithms that are defined in [I-D.ietf-cose-rfc8152bis-algs] 2453 document. This means that it is up to the applications to document 2454 how content padding is to be done in order to prevent or discourage 2455 such analysis. (For example, the strings could be defined as 'YES' 2456 and 'NO '.) 2458 14. Implementation Status 2460 This section records the status of known implementations of the 2461 protocol defined by this specification at the time of posting of this 2462 Internet-Draft, and is based on a proposal described in [RFC7942]. 2463 The description of implementations in this section is intended to 2464 assist the IETF in its decision processes in progressing drafts to 2465 RFCs. Please note that the listing of any individual implementation 2466 here does not imply endorsement by the IETF. Furthermore, no effort 2467 has been spent to verify the information presented here that was 2468 supplied by IETF contributors. This is not intended as, and must not 2469 be construed to be, a catalog of available implementations or their 2470 features. Readers are advised to note that other implementations may 2471 exist. 2473 According to [RFC7942], "this will allow reviewers and working groups 2474 to assign due consideration to documents that have the benefit of 2475 running code, which may serve as evidence of valuable experimentation 2476 and feedback that have made the implemented protocols more mature. 2477 It is up to the individual working groups to use this information as 2478 they see fit". 2480 14.1. Author's Versions 2482 There are three different implementations that have been created by 2483 the author of the document both to create the examples that are 2484 included in the document and to validate the structures and 2485 methodology used in the design of COSE. 2487 Implementation Location: https://github.com/cose-wg 2489 Primary Maintainer: Jim Schaad 2491 Languages: There are three different languages that are currently 2492 supported: Java, C# and C. 2494 Cryptography: The Java and C# libraries use Bouncy Castle to 2495 provide the required cryptography. The C version uses OPENSSL 2496 Version 1.0 for the cryptography. 2498 Coverage: The C version currently does not have full countersign 2499 support. The other two versions do. They do have support to 2500 allow for implicit algorithm support as they allow for the 2501 application to set attributes that are not to be sent in the 2502 message. 2504 Testing: All of the examples in the example library are generated 2505 by the C# library and then validated using the Java and C 2506 libraries. All three libraries have tests to allow for the 2507 creating of the same messages that are in the example library 2508 followed by validating them. These are not compared against the 2509 example library. The Java and C# libraries have unit testing 2510 included. Not all of the MUST statements in the document have 2511 been implemented as part of the libraries. One such statement is 2512 the requirement that unique labels be present. 2514 Licensing: Revised BSD License 2516 14.2. JavaScript Version 2518 Implementation Location: https://github.com/erdtman/cose-js 2520 Primary Maintainer: Samuel Erdtman 2522 Languages: JavaScript 2524 Cryptography: TBD 2526 Coverage: Full Encrypt, Signature and MAC objects are supported. 2528 Testing: Basic testing against the common example library. 2530 Licensing: Apache License 2.0 2532 14.3. Python Version 2534 Implementation Location: https://github.com/TimothyClaeys/COSE- 2535 PYTHON 2537 Primary Maintainer: Timothy Claeys 2539 Languages: Python 2541 Cryptography: pyecdsak, crypto python libraries 2543 Coverage: TBD 2545 Testing: Basic testing plus running against the common example 2546 library. 2548 Licensing: BSD 3-Clause License 2550 14.4. COSE Testing Library 2552 Implementation Location: https://github.com/cose-wg/Examples 2554 Primary Maintainer: Jim Schaad 2556 Description: A set of tests for the COSE library is provided as 2557 part of the implementation effort. Both success and fail tests 2558 have been provided. All of the examples in this document are part 2559 of this example set. 2561 Coverage: An attempt has been made to have test cases for every 2562 message type and algorithm in the document. Currently examples 2563 dealing with counter signatures, and ECDH with Curve24459 and 2564 Goldilocks are missing. 2566 Licensing: Public Domain 2568 15. References 2570 15.1. Normative References 2572 [COAP.Formats] 2573 IANA, "CoAP Content-Formats", 2574 . 2577 [COSE.Algorithms] 2578 IANA, "COSE Algorithms", 2579 . 2582 [COSE.KeyParameters] 2583 IANA, "COSE Key Parameters", 2584 . 2587 [COSE.KeyTypes] 2588 IANA, "COSE Key Types", 2589 . 2592 [DSS] National Institute of Standards and Technology, "Digital 2593 Signature Standard (DSS)", FIPS PUB 186-4, 2594 DOI 10.6028/NIST.FIPS.186-4, July 2013, 2595 . 2598 [I-D.ietf-cose-rfc8152bis-algs] 2599 Schaad, J., "CBOR Object Signing and Encryption (COSE): 2600 Initial Algorithms", draft-ietf-cose-rfc8152bis-algs-03 2601 (work in progress), June 2019. 2603 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2604 Requirement Levels", BCP 14, RFC 2119, 2605 DOI 10.17487/RFC2119, March 1997, 2606 . 2608 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 2609 Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, 2610 October 2013, . 2612 [RFC8032] Josefsson, S. and I. Liusvaara, "Edwards-Curve Digital 2613 Signature Algorithm (EdDSA)", RFC 8032, 2614 DOI 10.17487/RFC8032, January 2017, 2615 . 2617 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2618 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 2619 May 2017, . 2621 15.2. Informative References 2623 [PVSig] Brown, D. and D. Johnson, "Formal Security Proofs for a 2624 Signature Scheme with Partial Message Recovery", 2625 DOI 10.1007/3-540-45353-9_11, LNCS Volume 2020, June 2000. 2627 [RFC2633] Ramsdell, B., Ed., "S/MIME Version 3 Message 2628 Specification", RFC 2633, DOI 10.17487/RFC2633, June 1999, 2629 . 2631 [RFC4262] Santesson, S., "X.509 Certificate Extension for Secure/ 2632 Multipurpose Internet Mail Extensions (S/MIME) 2633 Capabilities", RFC 4262, DOI 10.17487/RFC4262, December 2634 2005, . 2636 [RFC4949] Shirey, R., "Internet Security Glossary, Version 2", 2637 FYI 36, RFC 4949, DOI 10.17487/RFC4949, August 2007, 2638 . 2640 [RFC4998] Gondrom, T., Brandner, R., and U. Pordesch, "Evidence 2641 Record Syntax (ERS)", RFC 4998, DOI 10.17487/RFC4998, 2642 August 2007, . 2644 [RFC5116] McGrew, D., "An Interface and Algorithms for Authenticated 2645 Encryption", RFC 5116, DOI 10.17487/RFC5116, January 2008, 2646 . 2648 [RFC5652] Housley, R., "Cryptographic Message Syntax (CMS)", STD 70, 2649 RFC 5652, DOI 10.17487/RFC5652, September 2009, 2650 . 2652 [RFC5751] Ramsdell, B. and S. Turner, "Secure/Multipurpose Internet 2653 Mail Extensions (S/MIME) Version 3.2 Message 2654 Specification", RFC 5751, DOI 10.17487/RFC5751, January 2655 2010, . 2657 [RFC5752] Turner, S. and J. Schaad, "Multiple Signatures in 2658 Cryptographic Message Syntax (CMS)", RFC 5752, 2659 DOI 10.17487/RFC5752, January 2010, 2660 . 2662 [RFC5990] Randall, J., Kaliski, B., Brainard, J., and S. Turner, 2663 "Use of the RSA-KEM Key Transport Algorithm in the 2664 Cryptographic Message Syntax (CMS)", RFC 5990, 2665 DOI 10.17487/RFC5990, September 2010, 2666 . 2668 [RFC6838] Freed, N., Klensin, J., and T. Hansen, "Media Type 2669 Specifications and Registration Procedures", BCP 13, 2670 RFC 6838, DOI 10.17487/RFC6838, January 2013, 2671 . 2673 [RFC7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 2674 Application Protocol (CoAP)", RFC 7252, 2675 DOI 10.17487/RFC7252, June 2014, 2676 . 2678 [RFC7515] Jones, M., Bradley, J., and N. Sakimura, "JSON Web 2679 Signature (JWS)", RFC 7515, DOI 10.17487/RFC7515, May 2680 2015, . 2682 [RFC7516] Jones, M. and J. Hildebrand, "JSON Web Encryption (JWE)", 2683 RFC 7516, DOI 10.17487/RFC7516, May 2015, 2684 . 2686 [RFC7517] Jones, M., "JSON Web Key (JWK)", RFC 7517, 2687 DOI 10.17487/RFC7517, May 2015, 2688 . 2690 [RFC7518] Jones, M., "JSON Web Algorithms (JWA)", RFC 7518, 2691 DOI 10.17487/RFC7518, May 2015, 2692 . 2694 [RFC7942] Sheffer, Y. and A. Farrel, "Improving Awareness of Running 2695 Code: The Implementation Status Section", BCP 205, 2696 RFC 7942, DOI 10.17487/RFC7942, July 2016, 2697 . 2699 [RFC8018] Moriarty, K., Ed., Kaliski, B., and A. Rusch, "PKCS #5: 2700 Password-Based Cryptography Specification Version 2.1", 2701 RFC 8018, DOI 10.17487/RFC8018, January 2017, 2702 . 2704 [RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for 2705 Writing an IANA Considerations Section in RFCs", BCP 26, 2706 RFC 8126, DOI 10.17487/RFC8126, June 2017, 2707 . 2709 [RFC8152] Schaad, J., "CBOR Object Signing and Encryption (COSE)", 2710 RFC 8152, DOI 10.17487/RFC8152, July 2017, 2711 . 2713 [RFC8230] Jones, M., "Using RSA Algorithms with CBOR Object Signing 2714 and Encryption (COSE) Messages", RFC 8230, 2715 DOI 10.17487/RFC8230, September 2017, 2716 . 2718 [RFC8259] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 2719 Interchange Format", STD 90, RFC 8259, 2720 DOI 10.17487/RFC8259, December 2017, 2721 . 2723 [RFC8610] Birkholz, H., Vigano, C., and C. Bormann, "Concise Data 2724 Definition Language (CDDL): A Notational Convention to 2725 Express Concise Binary Object Representation (CBOR) and 2726 JSON Data Structures", RFC 8610, DOI 10.17487/RFC8610, 2727 June 2019, . 2729 [RFC8613] Selander, G., Mattsson, J., Palombini, F., and L. Seitz, 2730 "Object Security for Constrained RESTful Environments 2731 (OSCORE)", RFC 8613, DOI 10.17487/RFC8613, July 2019, 2732 . 2734 [W3C.WebCrypto] 2735 Watson, M., "Web Cryptography API", W3C Recommendation, 2736 January 2017, . 2738 Appendix A. Guidelines for External Data Authentication of Algorithms 2740 During development of COSE, the requirement that the algorithm 2741 identifier be located in the protected attributes was relaxed from a 2742 must to a should. There were two basic reasons that have been 2743 advanced to support this position. First, the resulting message will 2744 be smaller if the algorithm identifier is omitted from the most 2745 common messages in a CoAP environment. Second, there is a potential 2746 bug that will arise if full checking is not done correctly between 2747 the different places that an algorithm identifier could be placed 2748 (the message itself, an application statement, the key structure that 2749 the sender possesses, and the key structure the recipient possesses). 2751 This appendix lays out how such a change can be made and the details 2752 that an application needs to specify in order to use this option. 2753 Two different sets of details are specified: those needed to omit an 2754 algorithm identifier and those needed to use a variant on the counter 2755 signature attribute that contains no attributes about itself. 2757 Three sets of recommendations are laid out. The first set of 2758 recommendations apply to having an implicit algorithm identified for 2759 a single layer of a COSE object. The second set of recommendations 2760 apply to having multiple implicit algorithms identified for multiple 2761 layers of a COSE object. The third set of recommendations apply to 2762 having implicit algorithms for multiple COSE object constructs. 2764 The key words from [RFC2119] are deliberately not used here. This 2765 specification can provide recommendations, but it cannot enforce 2766 them. 2768 This set of recommendations applies to the case where an application 2769 is distributing a fixed algorithm along with the key information for 2770 use in a single COSE object. This normally applies to the smallest 2771 of the COSE objects, specifically COSE_Sign1, COSE_Mac0, and 2772 COSE_Encrypt0, but could apply to the other structures as well. 2774 The following items should be taken into account: 2776 o Applications need to list the set of COSE structures that implicit 2777 algorithms are to be used in. Applications need to require that 2778 the receipt of an explicit algorithm identifier in one of these 2779 structures will lead to the message being rejected. This 2780 requirement is stated so that there will never be a case where 2781 there is any ambiguity about the question of which algorithm 2782 should be used, the implicit or the explicit one. This applies 2783 even if the transported algorithm identifier is a protected 2784 attribute. This applies even if the transported algorithm is the 2785 same as the implicit algorithm. 2787 o Applications need to define the set of information that is to be 2788 considered to be part of a context when omitting algorithm 2789 identifiers. At a minimum, this would be the key identifier (if 2790 needed), the key, the algorithm, and the COSE structure it is used 2791 with. Applications should restrict the use of a single key to a 2792 single algorithm. As noted for some of the algorithms in 2793 [I-D.ietf-cose-rfc8152bis-algs], the use of the same key in 2794 different related algorithms can lead to leakage of information 2795 about the key, leakage about the data or the ability to perform 2796 forgeries. 2798 o In many cases, applications that make the algorithm identifier 2799 implicit will also want to make the context identifier implicit 2800 for the same reason. That is, omitting the context identifier 2801 will decrease the message size (potentially significantly 2802 depending on the length of the identifier). Applications that do 2803 this will need to describe the circumstances where the context 2804 identifier is to be omitted and how the context identifier is to 2805 be inferred in these cases. (An exhaustive search over all of the 2806 keys would normally not be considered to be acceptable.) An 2807 example of how this can be done is to tie the context to a 2808 transaction identifier. Both would be sent on the original 2809 message, but only the transaction identifier would need to be sent 2810 after that point as the context is tied into the transaction 2811 identifier. Another way would be to associate a context with a 2812 network address. All messages coming from a single network 2813 address can be assumed to be associated with a specific context. 2814 (In this case, the address would normally be distributed as part 2815 of the context.) 2817 o Applications cannot rely on key identifiers being unique unless 2818 they take significant efforts to ensure that they are computed in 2819 such a way as to create this guarantee. Even when an application 2820 does this, the uniqueness might be violated if the application is 2821 run in different contexts (i.e., with a different context 2822 provider) or if the system combines the security contexts from 2823 different applications together into a single store. 2825 o Applications should continue the practice of protecting the 2826 algorithm identifier. Since this is not done by placing it in the 2827 protected attributes field, applications should define an 2828 application-specific external data structure that includes this 2829 value. This external data field can be used as such for content 2830 encryption, MAC, and signature algorithms. It can be used in the 2831 SuppPrivInfo field for those algorithms that use a KDF to derive a 2832 key value. Applications may also want to protect other 2833 information that is part of the context structure as well. It 2834 should be noted that those fields, such as the key or a Base IV, 2835 are protected by virtue of being used in the cryptographic 2836 computation and do not need to be included in the external data 2837 field. 2839 The second case is having multiple implicit algorithm identifiers 2840 specified for a multiple layer COSE object. An example of how this 2841 would work is the encryption context that an application specifies, 2842 which contains a content encryption algorithm, a key wrap algorithm, 2843 a key identifier, and a shared secret. The sender omits sending the 2844 algorithm identifier for both the content layer and the recipient 2845 layer leaving only the key identifier. The receiver then uses the 2846 key identifier to get the implicit algorithm identifiers. 2848 The following additional items need to be taken into consideration: 2850 o Applications that want to support this will need to define a 2851 structure that allows for, and clearly identifies, both the COSE 2852 structure to be used with a given key and the structure and 2853 algorithm to be used for the secondary layer. The key for the 2854 secondary layer is computed as normal from the recipient layer. 2856 The third case is having multiple implicit algorithm identifiers, but 2857 targeted at potentially unrelated layers or different COSE objects. 2858 There are a number of different scenarios where this might be 2859 applicable. Some of these scenarios are: 2861 o Two contexts are distributed as a pair. Each of the contexts is 2862 for use with a COSE_Encrypt message. Each context will consist of 2863 distinct secret keys and IVs and potentially even different 2864 algorithms. One context is for sending messages from party A to 2865 party B, and the second context is for sending messages from party 2866 B to party A. This means that there is no chance for a reflection 2867 attack to occur as each party uses different secret keys to send 2868 its messages; a message that is reflected back to it would fail to 2869 decrypt. 2871 o Two contexts are distributed as a pair. The first context is used 2872 for encryption of the message, and the second context is used to 2873 place a counter signature on the message. The intention is that 2874 the second context can be distributed to other entities 2875 independently of the first context. This allows these entities to 2876 validate that the message came from an individual without being 2877 able to decrypt the message and see the content. 2879 o Two contexts are distributed as a pair. The first context 2880 contains a key for dealing with MACed messages, and the second 2881 context contains a key for dealing with encrypted messages. This 2882 allows for a unified distribution of keys to participants for 2883 different types of messages that have different keys, but where 2884 the keys may be used in a coordinated manner. 2886 For these cases, the following additional items need to be 2887 considered: 2889 o Applications need to ensure that the multiple contexts stay 2890 associated. If one of the contexts is invalidated for any reason, 2891 all of the contexts associated with it should also be invalidated. 2893 Appendix B. Two Layers of Recipient Information 2895 All of the currently defined recipient algorithm classes only use two 2896 layers of the COSE_Encrypt structure. The first layer is the message 2897 content, and the second layer is the content key encryption. 2898 However, if one uses a recipient algorithm such as the RSA Key 2899 Encapsulation Mechanism (RSA-KEM) (see Appendix A of RSA-KEM 2900 [RFC5990]), then it makes sense to have three layers of the 2901 COSE_Encrypt structure. 2903 These layers would be: 2905 o Layer 0: The content encryption layer. This layer contains the 2906 payload of the message. 2908 o Layer 1: The encryption of the CEK by a KEK. 2910 o Layer 2: The encryption of a long random secret using an RSA key 2911 and a key derivation function to convert that secret into the KEK. 2913 This is an example of what a triple layer message would look like. 2914 The message has the following layers: 2916 o Layer 0: Has a content encrypted with AES-GCM using a 128-bit key. 2918 o Layer 1: Uses the AES Key Wrap algorithm with a 128-bit key. 2920 o Layer 2: Uses ECDH Ephemeral-Static direct to generate the layer 1 2921 key. 2923 In effect, this example is a decomposed version of using the 2924 ECDH-ES+A128KW algorithm. 2926 Size of binary file is 183 bytes 2927 96( 2928 [ 2929 / protected / h'a10101' / { 2930 \ alg \ 1:1 \ AES-GCM 128 \ 2931 } / , 2932 / unprotected / { 2933 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 2934 }, 2935 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e2852948658f0 2936 811139868826e89218a75715b', 2937 / recipients / [ 2938 [ 2939 / protected / h'', 2940 / unprotected / { 2941 / alg / 1:-3 / A128KW / 2942 }, 2943 / ciphertext / h'dbd43c4e9d719c27c6275c67d628d493f090593db82 2944 18f11', 2945 / recipients / [ 2946 [ 2947 / protected / h'a1013818' / { 2948 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 2949 } / , 2950 / unprotected / { 2951 / ephemeral / -1:{ 2952 / kty / 1:2, 2953 / crv / -1:1, 2954 / x / -2:h'b2add44368ea6d641f9ca9af308b4079aeb519f11 2955 e9b8a55a600b21233e86e68', 2956 / y / -3:false 2957 }, 2958 / kid / 4:'meriadoc.brandybuck@buckland.example' 2959 }, 2960 / ciphertext / h'' 2961 ] 2962 ] 2963 ] 2964 ] 2965 ] 2966 ) 2968 Appendix C. Examples 2970 This appendix includes a set of examples that show the different 2971 features and message types that have been defined in this document. 2972 To make the examples easier to read, they are presented using the 2973 extended CBOR diagnostic notation (defined in [RFC8610]) rather than 2974 as a binary dump. 2976 A GitHub project has been created at that contains not only the examples presented in this 2978 document, but a more complete set of testing examples as well. Each 2979 example is found in a JSON file that contains the inputs used to 2980 create the example, some of the intermediate values that can be used 2981 in debugging the example and the output of the example presented in 2982 both a hex and a CBOR diagnostic notation format. Some of the 2983 examples at the site are designed failure testing cases; these are 2984 clearly marked as such in the JSON file. If errors in the examples 2985 in this document are found, the examples on GitHub will be updated, 2986 and a note to that effect will be placed in the JSON file. 2988 As noted, the examples are presented using the CBOR's diagnostic 2989 notation. A Ruby-based tool exists that can convert between the 2990 diagnostic notation and binary. This tool can be installed with the 2991 command line: 2993 gem install cbor-diag 2995 The diagnostic notation can be converted into binary files using the 2996 following command line: 2998 diag2cbor.rb < inputfile > outputfile 3000 The examples can be extracted from the XML version of this document 3001 via an XPath expression as all of the artwork is tagged with the 3002 attribute type='CBORdiag'. (Depending on the XPath evaluator one is 3003 using, it may be necessary to deal with > as an entity.) 3005 //artwork[@type='CDDL']/text() 3007 C.1. Examples of Signed Messages 3009 C.1.1. Single Signature 3011 This example uses the following: 3013 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3015 Size of binary file is 103 bytes 3016 98( 3017 [ 3018 / protected / h'', 3019 / unprotected / {}, 3020 / payload / 'This is the content.', 3021 / signatures / [ 3022 [ 3023 / protected / h'a10126' / { 3024 \ alg \ 1:-7 \ ECDSA 256 \ 3025 } / , 3026 / unprotected / { 3027 / kid / 4:'11' 3028 }, 3029 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3030 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3031 98f53afd2fa0f30a' 3032 ] 3033 ] 3034 ] 3035 ) 3037 C.1.2. Multiple Signers 3039 This example uses the following: 3041 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3043 o Signature Algorithm: ECDSA w/ SHA-512, Curve P-521 3045 Size of binary file is 277 bytes 3046 98( 3047 [ 3048 / protected / h'', 3049 / unprotected / {}, 3050 / payload / 'This is the content.', 3051 / signatures / [ 3052 [ 3053 / protected / h'a10126' / { 3054 \ alg \ 1:-7 \ ECDSA 256 \ 3055 } / , 3056 / unprotected / { 3057 / kid / 4:'11' 3058 }, 3059 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3060 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3061 98f53afd2fa0f30a' 3062 ], 3063 [ 3064 / protected / h'a1013823' / { 3065 \ alg \ 1:-36 3066 } / , 3067 / unprotected / { 3068 / kid / 4:'bilbo.baggins@hobbiton.example' 3069 }, 3070 / signature / h'00a2d28a7c2bdb1587877420f65adf7d0b9a06635dd1 3071 de64bb62974c863f0b160dd2163734034e6ac003b01e8705524c5c4ca479a952f024 3072 7ee8cb0b4fb7397ba08d009e0c8bf482270cc5771aa143966e5a469a09f613488030 3073 c5b07ec6d722e3835adb5b2d8c44e95ffb13877dd2582866883535de3bb03d01753f 3074 83ab87bb4f7a0297' 3075 ] 3076 ] 3077 ] 3078 ) 3080 C.1.3. Counter Signature 3082 This example uses the following: 3084 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3086 o The same parameters are used for both the signature and the 3087 counter signature. 3089 Size of binary file is 180 bytes 3090 98( 3091 [ 3092 / protected / h'', 3093 / unprotected / { 3094 / countersign / 7:[ 3095 / protected / h'a10126' / { 3096 \ alg \ 1:-7 \ ECDSA 256 \ 3097 } / , 3098 / unprotected / { 3099 / kid / 4:'11' 3100 }, 3101 / signature / h'5ac05e289d5d0e1b0a7f048a5d2b643813ded50bc9e4 3102 9220f4f7278f85f19d4a77d655c9d3b51e805a74b099e1e085aacd97fc29d72f887e 3103 8802bb6650cceb2c' 3104 ] 3105 }, 3106 / payload / 'This is the content.', 3107 / signatures / [ 3108 [ 3109 / protected / h'a10126' / { 3110 \ alg \ 1:-7 \ ECDSA 256 \ 3111 } / , 3112 / unprotected / { 3113 / kid / 4:'11' 3114 }, 3115 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3116 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3117 98f53afd2fa0f30a' 3118 ] 3119 ] 3120 ] 3121 ) 3123 C.1.4. Signature with Criticality 3125 This example uses the following: 3127 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3129 o There is a criticality marker on the "reserved" header parameter 3131 Size of binary file is 125 bytes 3132 98( 3133 [ 3134 / protected / h'a2687265736572766564f40281687265736572766564' / 3135 { 3136 "reserved":false, 3137 \ crit \ 2:[ 3138 "reserved" 3139 ] 3140 } / , 3141 / unprotected / {}, 3142 / payload / 'This is the content.', 3143 / signatures / [ 3144 [ 3145 / protected / h'a10126' / { 3146 \ alg \ 1:-7 \ ECDSA 256 \ 3147 } / , 3148 / unprotected / { 3149 / kid / 4:'11' 3150 }, 3151 / signature / h'3fc54702aa56e1b2cb20284294c9106a63f91bac658d 3152 69351210a031d8fc7c5ff3e4be39445b1a3e83e1510d1aca2f2e8a7c081c7645042b 3153 18aba9d1fad1bd9c' 3154 ] 3155 ] 3156 ] 3157 ) 3159 C.2. Single Signer Examples 3161 C.2.1. Single ECDSA Signature 3163 This example uses the following: 3165 o Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3167 Size of binary file is 98 bytes 3168 18( 3169 [ 3170 / protected / h'a10126' / { 3171 \ alg \ 1:-7 \ ECDSA 256 \ 3172 } / , 3173 / unprotected / { 3174 / kid / 4:'11' 3175 }, 3176 / payload / 'This is the content.', 3177 / signature / h'8eb33e4ca31d1c465ab05aac34cc6b23d58fef5c083106c4 3178 d25a91aef0b0117e2af9a291aa32e14ab834dc56ed2a223444547e01f11d3b0916e5 3179 a4c345cacb36' 3180 ] 3181 ) 3183 C.3. Examples of Enveloped Messages 3185 C.3.1. Direct ECDH 3187 This example uses the following: 3189 o CEK: AES-GCM w/ 128-bit key 3191 o Recipient class: ECDH Ephemeral-Static, Curve P-256 3193 Size of binary file is 151 bytes 3194 96( 3195 [ 3196 / protected / h'a10101' / { 3197 \ alg \ 1:1 \ AES-GCM 128 \ 3198 } / , 3199 / unprotected / { 3200 / iv / 5:h'c9cf4df2fe6c632bf7886413' 3201 }, 3202 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 3203 c52a357da7a644b8070a151b0', 3204 / recipients / [ 3205 [ 3206 / protected / h'a1013818' / { 3207 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 3208 } / , 3209 / unprotected / { 3210 / ephemeral / -1:{ 3211 / kty / 1:2, 3212 / crv / -1:1, 3213 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 3214 bf054e1c7b4d91d6280', 3215 / y / -3:true 3216 }, 3217 / kid / 4:'meriadoc.brandybuck@buckland.example' 3218 }, 3219 / ciphertext / h'' 3220 ] 3221 ] 3222 ] 3223 ) 3225 C.3.2. Direct Plus Key Derivation 3227 This example uses the following: 3229 o CEK: AES-CCM w/ 128-bit key, truncate the tag to 64 bits 3231 o Recipient class: Use HKDF on a shared secret with the following 3232 implicit fields as part of the context. 3234 * salt: "aabbccddeeffgghh" 3236 * PartyU identity: "lighting-client" 3238 * PartyV identity: "lighting-server" 3240 * Supplementary Public Other: "Encryption Example 02" 3242 Size of binary file is 91 bytes 3244 96( 3245 [ 3246 / protected / h'a1010a' / { 3247 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3248 } / , 3249 / unprotected / { 3250 / iv / 5:h'89f52f65a1c580933b5261a76c' 3251 }, 3252 / ciphertext / h'753548a19b1307084ca7b2056924ed95f2e3b17006dfe93 3253 1b687b847', 3254 / recipients / [ 3255 [ 3256 / protected / h'a10129' / { 3257 \ alg \ 1:-10 3258 } / , 3259 / unprotected / { 3260 / salt / -20:'aabbccddeeffgghh', 3261 / kid / 4:'our-secret' 3262 }, 3263 / ciphertext / h'' 3264 ] 3265 ] 3266 ] 3267 ) 3269 C.3.3. Counter Signature on Encrypted Content 3271 This example uses the following: 3273 o CEK: AES-GCM w/ 128-bit key 3275 o Recipient class: ECDH Ephemeral-Static, Curve P-256 3277 Size of binary file is 326 bytes 3278 96( 3279 [ 3280 / protected / h'a10101' / { 3281 \ alg \ 1:1 \ AES-GCM 128 \ 3282 } / , 3283 / unprotected / { 3284 / iv / 5:h'c9cf4df2fe6c632bf7886413', 3285 / countersign / 7:[ 3286 / protected / h'a1013823' / { 3287 \ alg \ 1:-36 3288 } / , 3289 / unprotected / { 3290 / kid / 4:'bilbo.baggins@hobbiton.example' 3291 }, 3292 / signature / h'00929663c8789bb28177ae28467e66377da12302d7f9 3293 594d2999afa5dfa531294f8896f2b6cdf1740014f4c7f1a358e3a6cf57f4ed6fb02f 3294 cf8f7aa989f5dfd07f0700a3a7d8f3c604ba70fa9411bd10c2591b483e1d2c31de00 3295 3183e434d8fba18f17a4c7e3dfa003ac1cf3d30d44d2533c4989d3ac38c38b71481c 3296 c3430c9d65e7ddff' 3297 ] 3298 }, 3299 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 3300 c52a357da7a644b8070a151b0', 3301 / recipients / [ 3302 [ 3303 / protected / h'a1013818' / { 3304 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 3305 } / , 3306 / unprotected / { 3307 / ephemeral / -1:{ 3308 / kty / 1:2, 3309 / crv / -1:1, 3310 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 3311 bf054e1c7b4d91d6280', 3312 / y / -3:true 3313 }, 3314 / kid / 4:'meriadoc.brandybuck@buckland.example' 3315 }, 3316 / ciphertext / h'' 3317 ] 3318 ] 3319 ] 3320 ) 3322 C.3.4. Encrypted Content with External Data 3324 This example uses the following: 3326 o CEK: AES-GCM w/ 128-bit key 3328 o Recipient class: ECDH static-Static, Curve P-256 with AES Key Wrap 3330 o Externally Supplied AAD: h'0011bbcc22dd44ee55ff660077' 3332 Size of binary file is 173 bytes 3334 96( 3335 [ 3336 / protected / h'a10101' / { 3337 \ alg \ 1:1 \ AES-GCM 128 \ 3338 } / , 3339 / unprotected / { 3340 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 3341 }, 3342 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e28529d8f5335 3343 e5f0165eee976b4a5f6c6f09d', 3344 / recipients / [ 3345 [ 3346 / protected / h'a101381f' / { 3347 \ alg \ 1:-32 \ ECHD-SS+A128KW \ 3348 } / , 3349 / unprotected / { 3350 / static kid / -3:'peregrin.took@tuckborough.example', 3351 / kid / 4:'meriadoc.brandybuck@buckland.example', 3352 / U nonce / -22:h'0101' 3353 }, 3354 / ciphertext / h'41e0d76f579dbd0d936a662d54d8582037de2e366fd 3355 e1c62' 3356 ] 3357 ] 3358 ] 3359 ) 3361 C.4. Examples of Encrypted Messages 3363 C.4.1. Simple Encrypted Message 3365 This example uses the following: 3367 o CEK: AES-CCM w/ 128-bit key and a 64-bit tag 3369 Size of binary file is 52 bytes 3370 16( 3371 [ 3372 / protected / h'a1010a' / { 3373 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3374 } / , 3375 / unprotected / { 3376 / iv / 5:h'89f52f65a1c580933b5261a78c' 3377 }, 3378 / ciphertext / h'5974e1b99a3a4cc09a659aa2e9e7fff161d38ce71cb45ce 3379 460ffb569' 3380 ] 3381 ) 3383 C.4.2. Encrypted Message with a Partial IV 3385 This example uses the following: 3387 o CEK: AES-CCM w/ 128-bit key and a 64-bit tag 3389 o Prefix for IV is 89F52F65A1C580933B52 3391 Size of binary file is 41 bytes 3393 16( 3394 [ 3395 / protected / h'a1010a' / { 3396 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3397 } / , 3398 / unprotected / { 3399 / partial iv / 6:h'61a7' 3400 }, 3401 / ciphertext / h'252a8911d465c125b6764739700f0141ed09192de139e05 3402 3bd09abca' 3403 ] 3404 ) 3406 C.5. Examples of MACed Messages 3408 C.5.1. Shared Secret Direct MAC 3410 This example uses the following: 3412 o MAC: AES-CMAC, 256-bit key, truncated to 64 bits 3414 o Recipient class: direct shared secret 3416 Size of binary file is 57 bytes 3417 97( 3418 [ 3419 / protected / h'a1010f' / { 3420 \ alg \ 1:15 \ AES-CBC-MAC-256//64 \ 3421 } / , 3422 / unprotected / {}, 3423 / payload / 'This is the content.', 3424 / tag / h'9e1226ba1f81b848', 3425 / recipients / [ 3426 [ 3427 / protected / h'', 3428 / unprotected / { 3429 / alg / 1:-6 / direct /, 3430 / kid / 4:'our-secret' 3431 }, 3432 / ciphertext / h'' 3433 ] 3434 ] 3435 ] 3436 ) 3438 C.5.2. ECDH Direct MAC 3440 This example uses the following: 3442 o MAC: HMAC w/SHA-256, 256-bit key 3444 o Recipient class: ECDH key agreement, two static keys, HKDF w/ 3445 context structure 3447 Size of binary file is 214 bytes 3448 97( 3449 [ 3450 / protected / h'a10105' / { 3451 \ alg \ 1:5 \ HMAC 256//256 \ 3452 } / , 3453 / unprotected / {}, 3454 / payload / 'This is the content.', 3455 / tag / h'81a03448acd3d305376eaa11fb3fe416a955be2cbe7ec96f012c99 3456 4bc3f16a41', 3457 / recipients / [ 3458 [ 3459 / protected / h'a101381a' / { 3460 \ alg \ 1:-27 \ ECDH-SS + HKDF-256 \ 3461 } / , 3462 / unprotected / { 3463 / static kid / -3:'peregrin.took@tuckborough.example', 3464 / kid / 4:'meriadoc.brandybuck@buckland.example', 3465 / U nonce / -22:h'4d8553e7e74f3c6a3a9dd3ef286a8195cbf8a23d 3466 19558ccfec7d34b824f42d92bd06bd2c7f0271f0214e141fb779ae2856abf585a583 3467 68b017e7f2a9e5ce4db5' 3468 }, 3469 / ciphertext / h'' 3470 ] 3471 ] 3472 ] 3473 ) 3475 C.5.3. Wrapped MAC 3477 This example uses the following: 3479 o MAC: AES-MAC, 128-bit key, truncated to 64 bits 3481 o Recipient class: AES Key Wrap w/ a pre-shared 256-bit key 3483 Size of binary file is 109 bytes 3484 97( 3485 [ 3486 / protected / h'a1010e' / { 3487 \ alg \ 1:14 \ AES-CBC-MAC-128//64 \ 3488 } / , 3489 / unprotected / {}, 3490 / payload / 'This is the content.', 3491 / tag / h'36f5afaf0bab5d43', 3492 / recipients / [ 3493 [ 3494 / protected / h'', 3495 / unprotected / { 3496 / alg / 1:-5 / A256KW /, 3497 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 3498 }, 3499 / ciphertext / h'711ab0dc2fc4585dce27effa6781c8093eba906f227 3500 b6eb0' 3501 ] 3502 ] 3503 ] 3504 ) 3506 C.5.4. Multi-Recipient MACed Message 3508 This example uses the following: 3510 o MAC: HMAC w/ SHA-256, 128-bit key 3512 o Recipient class: Uses three different methods 3514 1. ECDH Ephemeral-Static, Curve P-521, AES Key Wrap w/ 128-bit 3515 key 3517 2. AES Key Wrap w/ 256-bit key 3519 Size of binary file is 309 bytes 3520 97( 3521 [ 3522 / protected / h'a10105' / { 3523 \ alg \ 1:5 \ HMAC 256//256 \ 3524 } / , 3525 / unprotected / {}, 3526 / payload / 'This is the content.', 3527 / tag / h'bf48235e809b5c42e995f2b7d5fa13620e7ed834e337f6aa43df16 3528 1e49e9323e', 3529 / recipients / [ 3530 [ 3531 / protected / h'a101381c' / { 3532 \ alg \ 1:-29 \ ECHD-ES+A128KW \ 3533 } / , 3534 / unprotected / { 3535 / ephemeral / -1:{ 3536 / kty / 1:2, 3537 / crv / -1:3, 3538 / x / -2:h'0043b12669acac3fd27898ffba0bcd2e6c366d53bc4db 3539 71f909a759304acfb5e18cdc7ba0b13ff8c7636271a6924b1ac63c02688075b55ef2 3540 d613574e7dc242f79c3', 3541 / y / -3:true 3542 }, 3543 / kid / 4:'bilbo.baggins@hobbiton.example' 3544 }, 3545 / ciphertext / h'339bc4f79984cdc6b3e6ce5f315a4c7d2b0ac466fce 3546 a69e8c07dfbca5bb1f661bc5f8e0df9e3eff5' 3547 ], 3548 [ 3549 / protected / h'', 3550 / unprotected / { 3551 / alg / 1:-5 / A256KW /, 3552 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 3553 }, 3554 / ciphertext / h'0b2c7cfce04e98276342d6476a7723c090dfdd15f9a 3555 518e7736549e998370695e6d6a83b4ae507bb' 3556 ] 3557 ] 3558 ] 3559 ) 3561 C.6. Examples of MAC0 Messages 3563 C.6.1. Shared Secret Direct MAC 3565 This example uses the following: 3567 o MAC: AES-CMAC, 256-bit key, truncated to 64 bits 3568 o Recipient class: direct shared secret 3570 Size of binary file is 37 bytes 3572 17( 3573 [ 3574 / protected / h'a1010f' / { 3575 \ alg \ 1:15 \ AES-CBC-MAC-256//64 \ 3576 } / , 3577 / unprotected / {}, 3578 / payload / 'This is the content.', 3579 / tag / h'726043745027214f' 3580 ] 3581 ) 3583 Note that this example uses the same inputs as Appendix C.5.1. 3585 C.7. COSE Keys 3587 C.7.1. Public Keys 3589 This is an example of a COSE Key Set. This example includes the 3590 public keys for all of the previous examples. 3592 In order the keys are: 3594 o An EC key with a kid of "meriadoc.brandybuck@buckland.example" 3596 o An EC key with a kid of "peregrin.took@tuckborough.example" 3598 o An EC key with a kid of "bilbo.baggins@hobbiton.example" 3600 o An EC key with a kid of "11" 3602 Size of binary file is 481 bytes 3604 [ 3605 { 3606 -1:1, 3607 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 3608 8551d', 3609 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 3610 4d19c', 3611 1:2, 3612 2:'meriadoc.brandybuck@buckland.example' 3613 }, 3614 { 3615 -1:1, 3616 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 3617 09eff', 3618 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 3619 c117e', 3620 1:2, 3621 2:'11' 3622 }, 3623 { 3624 -1:3, 3625 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 3626 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 3627 f42ad', 3628 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 3629 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 3630 d9475', 3631 1:2, 3632 2:'bilbo.baggins@hobbiton.example' 3633 }, 3634 { 3635 -1:1, 3636 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 3637 d6280', 3638 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 3639 822bb', 3640 1:2, 3641 2:'peregrin.took@tuckborough.example' 3642 } 3643 ] 3645 C.7.2. Private Keys 3647 This is an example of a COSE Key Set. This example includes the 3648 private keys for all of the previous examples. 3650 In order the keys are: 3652 o An EC key with a kid of "meriadoc.brandybuck@buckland.example" 3654 o A shared-secret key with a kid of "our-secret" 3656 o An EC key with a kid of "peregrin.took@tuckborough.example" 3658 o A shared-secret key with a kid of "018c0ae5-4d9b-471b- 3659 bfd6-eef314bc7037" 3661 o An EC key with a kid of "bilbo.baggins@hobbiton.example" 3663 o An EC key with a kid of "11" 3665 Size of binary file is 816 bytes 3667 [ 3668 { 3669 1:2, 3670 2:'meriadoc.brandybuck@buckland.example', 3671 -1:1, 3672 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 3673 8551d', 3674 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 3675 4d19c', 3676 -4:h'aff907c99f9ad3aae6c4cdf21122bce2bd68b5283e6907154ad911840fa 3677 208cf' 3678 }, 3679 { 3680 1:2, 3681 2:'11', 3682 -1:1, 3683 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 3684 09eff', 3685 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 3686 c117e', 3687 -4:h'57c92077664146e876760c9520d054aa93c3afb04e306705db609030850 3688 7b4d3' 3689 }, 3690 { 3691 1:2, 3692 2:'bilbo.baggins@hobbiton.example', 3693 -1:3, 3694 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 3695 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 3696 f42ad', 3697 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 3698 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 3699 d9475', 3700 -4:h'00085138ddabf5ca975f5860f91a08e91d6d5f9a76ad4018766a476680b 3701 55cd339e8ab6c72b5facdb2a2a50ac25bd086647dd3e2e6e99e84ca2c3609fdf177f 3702 eb26d' 3703 }, 3704 { 3705 1:4, 3706 2:'our-secret', 3707 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 3708 27188' 3709 }, 3710 { 3711 1:2, 3712 -1:1, 3713 2:'peregrin.took@tuckborough.example', 3714 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 3715 d6280', 3716 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 3717 822bb', 3718 -4:h'02d1f7e6f26c43d4868d87ceb2353161740aacf1f7163647984b522a848 3719 df1c3' 3720 }, 3721 { 3722 1:4, 3723 2:'our-secret2', 3724 -1:h'849b5786457c1491be3a76dcea6c4271' 3725 }, 3726 { 3727 1:4, 3728 2:'018c0ae5-4d9b-471b-bfd6-eef314bc7037', 3729 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 3730 27188' 3731 } 3732 ] 3734 Acknowledgments 3736 This document is a product of the COSE working group of the IETF. 3738 The following individuals are to blame for getting me started on this 3739 project in the first place: Richard Barnes, Matt Miller, and Martin 3740 Thomson. 3742 The initial version of the specification was based to some degree on 3743 the outputs of the JOSE and S/MIME working groups. 3745 The following individuals provided input into the final form of the 3746 document: Carsten Bormann, John Bradley, Brain Campbell, Michael B. 3748 Jones, Ilari Liusvaara, Francesca Palombini, Ludwig Seitz, and Goran 3749 Selander. 3751 Author's Address 3753 Jim Schaad 3754 August Cellars 3756 Email: ietf@augustcellars.com