idnits 2.17.1 draft-ietf-cose-rfc8152bis-struct-08.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 (9 March 2020) is 1480 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) ** Obsolete normative reference: RFC 7049 (Obsoleted by RFC 8949) -- Possible downref: Non-RFC (?) normative reference: ref. 'DSS' ** Downref: Normative reference to an Informational RFC: RFC 8032 == Outdated reference: A later version (-12) exists of draft-ietf-cose-rfc8152bis-algs-06 ** Downref: Normative reference to an Informational draft: draft-ietf-cose-rfc8152bis-algs (ref. 'I-D.ietf-cose-rfc8152bis-algs') -- Obsolete informational reference (is this intentional?): RFC 8152 (Obsoleted by RFC 9052, RFC 9053) -- Obsolete informational reference (is this intentional?): RFC 2633 (Obsoleted by RFC 3851) -- Obsolete informational reference (is this intentional?): RFC 5751 (Obsoleted by RFC 8551) Summary: 4 errors (**), 0 flaws (~~), 2 warnings (==), 5 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 COSE Working Group J. Schaad 3 Internet-Draft August Cellars 4 Obsoletes: 8152 (if approved) 9 March 2020 5 Intended status: Standards Track 6 Expires: 10 September 2020 8 CBOR Object Signing and Encryption (COSE): Structures and Process 9 draft-ietf-cose-rfc8152bis-struct-08 11 Abstract 13 Concise Binary Object Representation (CBOR) is a data format designed 14 for small code size and small message size. There is a need for the 15 ability to have basic security services defined for this data format. 16 This document defines the CBOR Object Signing and Encryption (COSE) 17 protocol. This specification describes how to create and process 18 signatures, message authentication codes, and encryption using CBOR 19 for serialization. This specification additionally describes how to 20 represent cryptographic keys using CBOR. 22 This document along with [I-D.ietf-cose-rfc8152bis-algs] obsoletes 23 RFC8152. 25 Contributing to this document 27 This note is to be removed before publishing as an RFC. 29 The source for this draft is being maintained in GitHub. Suggested 30 changes should be submitted as pull requests at https://github.com/ 31 cose-wg/cose-rfc8152bis. Instructions are on that page as well. 32 Editorial changes can be managed in GitHub, but any substantial 33 issues need to be discussed on the COSE mailing list. 35 Status of This Memo 37 This Internet-Draft is submitted in full conformance with the 38 provisions of BCP 78 and BCP 79. 40 Internet-Drafts are working documents of the Internet Engineering 41 Task Force (IETF). Note that other groups may also distribute 42 working documents as Internet-Drafts. The list of current Internet- 43 Drafts is at https://datatracker.ietf.org/drafts/current/. 45 Internet-Drafts are draft documents valid for a maximum of six months 46 and may be updated, replaced, or obsoleted by other documents at any 47 time. It is inappropriate to use Internet-Drafts as reference 48 material or to cite them other than as "work in progress." 49 This Internet-Draft will expire on 10 September 2020. 51 Copyright Notice 53 Copyright (c) 2020 IETF Trust and the persons identified as the 54 document authors. All rights reserved. 56 This document is subject to BCP 78 and the IETF Trust's Legal 57 Provisions Relating to IETF Documents (https://trustee.ietf.org/ 58 license-info) in effect on the date of publication of this document. 59 Please review these documents carefully, as they describe your rights 60 and restrictions with respect to this document. Code Components 61 extracted from this document must include Simplified BSD License text 62 as described in Section 4.e of the Trust Legal Provisions and are 63 provided without warranty as described in the Simplified BSD License. 65 Table of Contents 67 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 68 1.1. Requirements Terminology . . . . . . . . . . . . . . . . 5 69 1.2. Changes from RFC8152 . . . . . . . . . . . . . . . . . . 5 70 1.3. Design Changes from JOSE . . . . . . . . . . . . . . . . 6 71 1.4. CBOR Grammar . . . . . . . . . . . . . . . . . . . . . . 6 72 1.5. CBOR-Related Terminology . . . . . . . . . . . . . . . . 8 73 1.6. Document Terminology . . . . . . . . . . . . . . . . . . 8 74 2. Basic COSE Structure . . . . . . . . . . . . . . . . . . . . 9 75 3. Header Parameters . . . . . . . . . . . . . . . . . . . . . . 13 76 3.1. Common COSE Header Parameters . . . . . . . . . . . . . . 15 77 4. Signing Objects . . . . . . . . . . . . . . . . . . . . . . . 18 78 4.1. Signing with One or More Signers . . . . . . . . . . . . 18 79 4.2. Signing with One Signer . . . . . . . . . . . . . . . . . 20 80 4.3. Externally Supplied Data . . . . . . . . . . . . . . . . 21 81 4.4. Signing and Verification Process . . . . . . . . . . . . 22 82 5. Counter Signatures . . . . . . . . . . . . . . . . . . . . . 24 83 5.1. Full Countersignatures . . . . . . . . . . . . . . . . . 24 84 5.2. Abbreviated Countersignatures . . . . . . . . . . . . . . 25 85 6. Encryption Objects . . . . . . . . . . . . . . . . . . . . . 26 86 6.1. Enveloped COSE Structure . . . . . . . . . . . . . . . . 26 87 6.1.1. Content Key Distribution Methods . . . . . . . . . . 28 88 6.2. Single Recipient Encrypted . . . . . . . . . . . . . . . 28 89 6.3. How to Encrypt and Decrypt for AEAD Algorithms . . . . . 29 90 6.4. How to Encrypt and Decrypt for AE Algorithms . . . . . . 31 91 7. MAC Objects . . . . . . . . . . . . . . . . . . . . . . . . . 33 92 7.1. MACed Message with Recipients . . . . . . . . . . . . . . 33 93 7.2. MACed Messages with Implicit Key . . . . . . . . . . . . 34 94 7.3. How to Compute and Verify a MAC . . . . . . . . . . . . . 35 95 8. Key Objects . . . . . . . . . . . . . . . . . . . . . . . . . 36 96 8.1. COSE Key Common Parameters . . . . . . . . . . . . . . . 37 98 9. Taxonomy of Algorithms used by COSE . . . . . . . . . . . . . 39 99 9.1. Signature Algorithms . . . . . . . . . . . . . . . . . . 40 100 9.2. Message Authentication Code (MAC) Algorithms . . . . . . 41 101 9.3. Content Encryption Algorithms . . . . . . . . . . . . . . 41 102 9.4. Key Derivation Functions (KDFs) . . . . . . . . . . . . . 42 103 9.5. Content Key Distribution Methods . . . . . . . . . . . . 43 104 9.5.1. Direct Encryption . . . . . . . . . . . . . . . . . . 43 105 9.5.2. Key Wrap . . . . . . . . . . . . . . . . . . . . . . 43 106 9.5.3. Key Transport . . . . . . . . . . . . . . . . . . . . 44 107 9.5.4. Direct Key Agreement . . . . . . . . . . . . . . . . 44 108 9.5.5. Key Agreement with Key Wrap . . . . . . . . . . . . . 45 109 10. CBOR Encoding Restrictions . . . . . . . . . . . . . . . . . 46 110 11. Application Profiling Considerations . . . . . . . . . . . . 46 111 12. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 48 112 12.1. CBOR Tag Assignment . . . . . . . . . . . . . . . . . . 48 113 12.2. COSE Header Parameters Registry . . . . . . . . . . . . 48 114 12.3. COSE Header Algorithm Parameters Registry . . . . . . . 48 115 12.4. COSE Key Common Parameters Registry . . . . . . . . . . 48 116 12.5. Media Type Registrations . . . . . . . . . . . . . . . . 49 117 12.5.1. COSE Security Message . . . . . . . . . . . . . . . 49 118 12.5.2. COSE Key Media Type . . . . . . . . . . . . . . . . 50 119 12.6. CoAP Content-Formats Registry . . . . . . . . . . . . . 52 120 13. Security Considerations . . . . . . . . . . . . . . . . . . . 52 121 14. Implementation Status . . . . . . . . . . . . . . . . . . . . 54 122 14.1. Author's Versions . . . . . . . . . . . . . . . . . . . 54 123 14.2. JavaScript Version . . . . . . . . . . . . . . . . . . . 55 124 14.3. Python Version . . . . . . . . . . . . . . . . . . . . . 55 125 14.4. COSE Testing Library . . . . . . . . . . . . . . . . . . 56 126 15. References . . . . . . . . . . . . . . . . . . . . . . . . . 56 127 15.1. Normative References . . . . . . . . . . . . . . . . . . 56 128 15.2. Informative References . . . . . . . . . . . . . . . . . 57 129 Appendix A. Guidelines for External Data Authentication of 130 Algorithms . . . . . . . . . . . . . . . . . . . . . . . 60 131 Appendix B. Two Layers of Recipient Information . . . . . . . . 63 132 Appendix C. Examples . . . . . . . . . . . . . . . . . . . . . . 65 133 C.1. Examples of Signed Messages . . . . . . . . . . . . . . . 66 134 C.1.1. Single Signature . . . . . . . . . . . . . . . . . . 66 135 C.1.2. Multiple Signers . . . . . . . . . . . . . . . . . . 67 136 C.1.3. Counter Signature . . . . . . . . . . . . . . . . . . 68 137 C.1.4. Signature with Criticality . . . . . . . . . . . . . 69 138 C.2. Single Signer Examples . . . . . . . . . . . . . . . . . 70 139 C.2.1. Single ECDSA Signature . . . . . . . . . . . . . . . 70 140 C.3. Examples of Enveloped Messages . . . . . . . . . . . . . 71 141 C.3.1. Direct ECDH . . . . . . . . . . . . . . . . . . . . . 71 142 C.3.2. Direct Plus Key Derivation . . . . . . . . . . . . . 72 143 C.3.3. Counter Signature on Encrypted Content . . . . . . . 73 144 C.3.4. Encrypted Content with External Data . . . . . . . . 74 145 C.4. Examples of Encrypted Messages . . . . . . . . . . . . . 75 146 C.4.1. Simple Encrypted Message . . . . . . . . . . . . . . 75 147 C.4.2. Encrypted Message with a Partial IV . . . . . . . . . 76 148 C.5. Examples of MACed Messages . . . . . . . . . . . . . . . 76 149 C.5.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 76 150 C.5.2. ECDH Direct MAC . . . . . . . . . . . . . . . . . . . 77 151 C.5.3. Wrapped MAC . . . . . . . . . . . . . . . . . . . . . 78 152 C.5.4. Multi-Recipient MACed Message . . . . . . . . . . . . 79 153 C.6. Examples of MAC0 Messages . . . . . . . . . . . . . . . . 80 154 C.6.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 80 155 C.7. COSE Keys . . . . . . . . . . . . . . . . . . . . . . . . 81 156 C.7.1. Public Keys . . . . . . . . . . . . . . . . . . . . . 81 157 C.7.2. Private Keys . . . . . . . . . . . . . . . . . . . . 82 158 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 84 159 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 85 161 1. Introduction 163 There has been an increased focus on small, constrained devices that 164 make up the Internet of Things (IoT). One of the standards that has 165 come out of this process is "Concise Binary Object Representation 166 (CBOR)" [RFC7049]. CBOR extended the data model of the JavaScript 167 Object Notation (JSON) [RFC8259] by allowing for binary data, among 168 other changes. CBOR has been adopted by several of the IETF working 169 groups dealing with the IoT world as their encoding of data 170 structures. CBOR was designed specifically to be both small in terms 171 of messages transport and implementation size and be a schema-free 172 decoder. A need exists to provide message security services for IoT, 173 and using CBOR as the message-encoding format makes sense. 175 The JOSE working group produced a set of documents [RFC7515] 176 [RFC7516] [RFC7517] [RFC7518] using JSON that specified how to 177 process encryption, signatures, and Message Authentication Code (MAC) 178 operations and how to encode keys using JSON. This document along 179 with [I-D.ietf-cose-rfc8152bis-algs] defines the CBOR Object Signing 180 and Encryption (COSE) standard, which does the same thing for the 181 CBOR encoding format. While there is a strong attempt to keep the 182 flavor of the original JSON Object Signing and Encryption (JOSE) 183 documents, two considerations are taken into account: 185 * CBOR has capabilities that are not present in JSON and are 186 appropriate to use. One example of this is the fact that CBOR has 187 a method of encoding binary directly without first converting it 188 into a base64-encoded text string. 190 * COSE is not a direct copy of the JOSE specification. In the 191 process of creating COSE, decisions that were made for JOSE were 192 re-examined. In many cases, different results were decided on as 193 the criteria were not always the same. 195 This document contains: 197 * The description of the structure for the CBOR objects which are 198 transmitted over the wire. Two objects are defined for 199 encryption, signing and message authentication. One object is 200 defined for transporting keys and one for transporting groups of 201 keys. 203 * The procedures used to build the inputs to the cryptographic 204 functions required for each of the structures. 206 * A starting set of attributes that apply to the different security 207 objects. 209 This document does not contain the rules and procedures for using 210 specific cryptographic algorithms. Details on specific algorithms 211 can be found in [I-D.ietf-cose-rfc8152bis-algs] and [RFC8230]. 212 Details for additional algorithms are expected to be defined in 213 future documents. 215 One feature that is present in CMS [RFC5652] that is not present in 216 this standard is a digest structure. This omission is deliberate. 217 It is better for the structure to be defined in each document as 218 different protocols will want to include a different set of fields as 219 part of the structure. While an algorithm identifier and the digest 220 value are going to be common to all applications, the two values may 221 not always be adjacent as the algorithm could be defined once with 222 multiple values. Applications may additionally want to define 223 additional data fields as part of the structure. A common structure 224 is going to include a URI or other pointer to where the data that is 225 being hashed is kept, allowing this to be application specific. 227 1.1. Requirements Terminology 229 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 230 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 231 "OPTIONAL" in this document are to be interpreted as described in BCP 232 14 [RFC2119] [RFC8174] when, and only when, they appear in all 233 capitals, as shown here. 235 1.2. Changes from RFC8152 237 * Split the original document into this document and 238 [I-D.ietf-cose-rfc8152bis-algs]. 240 * Add some text describing why there is no digest structure defined 241 by COSE. 243 * Rearrange the text around counter signatures and define a CBOR Tag 244 for a standalone countersignature. 246 * Text clarifications and changes in terminology. 248 1.3. Design Changes from JOSE 250 * Define a single top message structure so that encrypted, signed, 251 and MACed messages can easily be identified and still have a 252 consistent view. 254 * Signed messages distinguish between the protected and unprotected 255 header parameters that relate to the content from those that 256 relate to the signature. 258 * MACed messages are separated from signed messages. 260 * MACed messages have the ability to use the same set of recipient 261 algorithms as enveloped messages for obtaining the MAC 262 authentication key. 264 * Use binary encodings for binary data rather than base64url 265 encodings. 267 * Combine the authentication tag for encryption algorithms with the 268 ciphertext. 270 * The set of cryptographic algorithms has been expanded in some 271 directions and trimmed in others. 273 1.4. CBOR Grammar 275 There was not a standard CBOR grammar available when COSE was 276 originally written. For that reason the CBOR data objects defined 277 here are described in prose. Since that time CBOR Data Definition 278 Language (CDDL) [RFC8610] has been published as an RFC. The CBOR 279 grammar presented in this document is compatible with CDDL. 281 The document was developed by first working on the grammar and then 282 developing the prose to go with it. An artifact of this is that the 283 prose was written using the primitive type strings defined by CBOR 284 Data Definition Language (CDDL) [RFC8610]. In this specification, 285 the following primitive types are used: 287 any -- non-specific value that permits all CBOR values to be 288 placed here. 290 bool -- a boolean value (true: major type 7, value 21; false: 291 major type 7, value 20). 293 bstr -- byte string (major type 2). 295 int -- an unsigned integer or a negative integer. 297 nil -- a null value (major type 7, value 22). 299 nint -- a negative integer (major type 1). 301 tstr -- a UTF-8 text string (major type 3). 303 uint -- an unsigned integer (major type 0). 305 Two syntaxes from CDDL appear in this document as shorthand. These 306 are: 308 FOO / BAR -- indicates that either FOO or BAR can appear here. 310 [+ FOO] -- indicates that the type FOO appears one or more times 311 in an array. 313 Two of the constraints defined by CDDL are also used in this 314 document. These are: 316 type1 .cbor type2 -- indicates that the contents of type1, usually 317 bstr, contains a value of type2. 319 type1 .size integer -- indicates that the contents of type1 is 320 integer bytes long 322 As well as the prose description, a version of a CBOR grammar is 323 presented in CDDL. The CDDL grammar is informational; the prose 324 description is normative. 326 The collected CDDL can be extracted from the XML version of this 327 document via the following XPath expression below. (Depending on the 328 XPath evaluator one is using, it may be necessary to deal with > 329 as an entity.) 331 //sourcecode[@type='CDDL']/text() 333 CDDL expects the initial non-terminal symbol to be the first symbol 334 in the file. For this reason, the first fragment of CDDL is 335 presented here. 337 start = COSE_Messages / COSE_Key / COSE_KeySet / Internal_Types 339 ; This is defined to make the tool quieter: 340 Internal_Types = Sig_structure / Enc_structure / MAC_structure 342 The non-terminal Internal_Types is defined for dealing with the 343 automated validation tools used during the writing of this document. 344 It references those non-terminals that are used for security 345 computations but are not emitted for transport. 347 1.5. CBOR-Related Terminology 349 In JSON, maps are called objects and only have one kind of map key: a 350 text string. In COSE, we use text strings, negative integers, and 351 unsigned integers as map keys. The integers are used for compactness 352 of encoding and easy comparison. The inclusion of text strings 353 allows for an additional range of short encoded values to be used as 354 well. Since the word "key" is mainly used in its other meaning, as a 355 cryptographic key, we use the term "label" for this usage as a map 356 key. 358 The presence of a label in a CBOR map that is not a text string or an 359 integer is an error. Applications can either fail processing or 360 process messages by ignoring incorrect labels; however, they MUST NOT 361 create messages with incorrect labels. 363 A CDDL grammar fragment defines the non-terminal 'label', as in the 364 previous paragraph, and 'values', which permits any value to be used. 366 label = int / tstr 367 values = any 369 1.6. Document Terminology 371 In this document, we use the following terminology: 373 Byte is a synonym for octet. 375 Constrained Application Protocol (CoAP) is a specialized web transfer 376 protocol for use in constrained systems. It is defined in [RFC7252]. 378 Authenticated Encryption (AE) [RFC5116] algorithms are those 379 encryption algorithms that provide an authentication check of the 380 contents algorithm with the encryption service. 382 Authenticated Encryption with Associated Data (AEAD) [RFC5116] 383 algorithms provide the same content authentication service as AE 384 algorithms, but they additionally provide for authentication of non- 385 encrypted data as well. 387 Context is used throughout the document to represent information that 388 is not part of the COSE message. Information which is part of the 389 context can come from several different sources including: Protocol 390 interactions, associated key structures and program configuration. 391 The context to use can be implicit, identified using the 'kid 392 context' header parameter defined in [RFC8613], or identified by a 393 protocol specific identifier. Context should generally be included 394 in the cryptographic configuration, for more details see Section 4.3. 396 The term 'byte string' is used for sequences of bytes, while the term 397 'text string' is used for sequences of characters. 399 2. Basic COSE Structure 401 The COSE object structure is designed so that there can be a large 402 amount of common code when parsing and processing the different types 403 of security messages. All of the message structures are built on the 404 CBOR array type. The first three elements of the array always 405 contain the same information: 407 1. The protected header parameters encoded and wrapped in a bstr. 409 2. The unprotected header parameters as a map. 411 3. The content of the message. The content is either the plaintext 412 or the ciphertext as appropriate. The content may be detached 413 (i.e. transported separately from the COSE structure), but the 414 location is still used. The content is wrapped in a bstr when 415 present and is a nil value when detached. 417 Elements after this point are dependent on the specific message type. 419 COSE messages are built using the concept of layers to separate 420 different types of cryptographic concepts. As an example of how this 421 works, consider the COSE_Encrypt message (Section 6.1). This message 422 type is broken into two layers: the content layer and the recipient 423 layer. In the content layer, the plaintext is encrypted and 424 information about the encrypted message is placed. In the recipient 425 layer, the content encryption key (CEK) is encrypted and information 426 about how it is encrypted for each recipient is placed. A single 427 layer version of the encryption message COSE_Encrypt0 (Section 6.2) 428 is provided for cases where the CEK is pre-shared. 430 Identification of which type of message has been presented is done by 431 the following methods: 433 1. The specific message type is known from the context. This may be 434 defined by a marker in the containing structure or by 435 restrictions specified by the application protocol. 437 2. The message type is identified by a CBOR tag. Messages with a 438 CBOR tag are known in this specification as tagged messages, 439 while those without the CBOR tag are known as untagged messages. 440 This document defines a CBOR tag for each of the message 441 structures. These tags can be found in Table 1. 443 3. When a COSE object is carried in a media type of 'application/ 444 cose', the optional parameter 'cose-type' can be used to identify 445 the embedded object. The parameter is OPTIONAL if the tagged 446 version of the structure is used. The parameter is REQUIRED if 447 the untagged version of the structure is used. The value to use 448 with the parameter for each of the structures can be found in 449 Table 1. 451 4. When a COSE object is carried as a CoAP payload, the CoAP 452 Content-Format Option can be used to identify the message 453 content. The CoAP Content-Format values can be found in Table 2. 454 The CBOR tag for the message structure is not required as each 455 security message is uniquely identified. 457 +------+------------------+-----------------------+-------------+ 458 | CBOR | cose-type | Data Item | Semantics | 459 | Tag | | | | 460 +======+==================+=======================+=============+ 461 | 98 | cose-sign | COSE_Sign | COSE Signed | 462 | | | | Data Object | 463 +------+------------------+-----------------------+-------------+ 464 | 18 | cose-sign1 | COSE_Sign1 | COSE Single | 465 | | | | Signer Data | 466 | | | | Object | 467 +------+------------------+-----------------------+-------------+ 468 | 96 | cose-encrypt | COSE_Encrypt | COSE | 469 | | | | Encrypted | 470 | | | | Data Object | 471 +------+------------------+-----------------------+-------------+ 472 | 16 | cose-encrypt0 | COSE_Encrypt0 | COSE Single | 473 | | | | Recipient | 474 | | | | Encrypted | 475 | | | | Data Object | 476 +------+------------------+-----------------------+-------------+ 477 | 97 | cose-mac | COSE_Mac | COSE MACed | 478 | | | | Data Object | 479 +------+------------------+-----------------------+-------------+ 480 | 17 | cose-mac0 | COSE_Mac0 | COSE Mac w/ | 481 | | | | o | 482 | | | | Recipients | 483 | | | | Object | 484 +------+------------------+-----------------------+-------------+ 485 | TBD0 | cose-countersign | COSE_Countersignature | COSE | 486 | | | | standalone | 487 | | | | counter | 488 | | | | signature | 489 +------+------------------+-----------------------+-------------+ 491 Table 1: COSE Message Identification 493 +---------------------------+----------+-----+------------+ 494 | Media Type | Encoding | ID | Reference | 495 +===========================+==========+=====+============+ 496 | application/cose; cose- | | 98 | [[THIS | 497 | type="cose-sign" | | | DOCUMENT]] | 498 +---------------------------+----------+-----+------------+ 499 | application/cose; cose- | | 18 | [[THIS | 500 | type="cose-sign1" | | | DOCUMENT]] | 501 +---------------------------+----------+-----+------------+ 502 | application/cose; cose- | | 96 | [[THIS | 503 | type="cose-encrypt" | | | DOCUMENT]] | 504 +---------------------------+----------+-----+------------+ 505 | application/cose; cose- | | 16 | [[THIS | 506 | type="cose-encrypt0" | | | DOCUMENT]] | 507 +---------------------------+----------+-----+------------+ 508 | application/cose; cose- | | 97 | [[THIS | 509 | type="cose-mac" | | | DOCUMENT]] | 510 +---------------------------+----------+-----+------------+ 511 | application/cose; cose- | | 17 | [[THIS | 512 | type="cose-mac0" | | | DOCUMENT]] | 513 +---------------------------+----------+-----+------------+ 514 | application/cose-key | | 101 | [[THIS | 515 | | | | DOCUMENT]] | 516 +---------------------------+----------+-----+------------+ 517 | application/cose-key-set | | 102 | [[THIS | 518 | | | | DOCUMENT]] | 519 +---------------------------+----------+-----+------------+ 521 Table 2: CoAP Content-Formats for COSE 523 The following CDDL fragment identifies all of the top messages 524 defined in this document. Separate non-terminals are defined for the 525 tagged and the untagged versions of the messages. 527 COSE_Messages = COSE_Untagged_Message / COSE_Tagged_Message 529 COSE_Untagged_Message = COSE_Sign / COSE_Sign1 / 530 COSE_Encrypt / COSE_Encrypt0 / 531 COSE_Mac / COSE_Mac0 / COSE_Countersignature 533 COSE_Tagged_Message = COSE_Sign_Tagged / COSE_Sign1_Tagged / 534 COSE_Encrypt_Tagged / COSE_Encrypt0_Tagged / 535 COSE_Mac_Tagged / COSE_Mac0_Tagged / COSE_Countersignature_Tagged 537 3. Header Parameters 539 The structure of COSE has been designed to have two buckets of 540 information that are not considered to be part of the payload itself, 541 but are used for holding information about content, algorithms, keys, 542 or evaluation hints for the processing of the layer. These two 543 buckets are available for use in all of the structures except for 544 keys. While these buckets are present, they may not all be usable in 545 all instances. For example, while the protected bucket is defined as 546 part of the recipient structure, some of the algorithms used for 547 recipient structures do not provide for authenticated data. If this 548 is the case, the protected bucket is left empty. 550 Both buckets are implemented as CBOR maps. The map key is a 'label' 551 (Section 1.5). The value portion is dependent on the definition for 552 the label. Both maps use the same set of label/value pairs. The 553 integer and text string values for labels have been divided into 554 several sections including a standard range, a private range, and a 555 range that is dependent on the algorithm selected. The defined 556 labels can be found in the "COSE Header Parameters" IANA registry 557 (Section 12.2). 559 The two buckets are: 561 protected: Contains parameters about the current layer that are 562 cryptographically protected. This bucket MUST be empty if it is 563 not going to be included in a cryptographic computation. This 564 bucket is encoded in the message as a binary object. This value 565 is obtained by CBOR encoding the protected map and wrapping it in 566 a bstr object. Senders SHOULD encode a zero-length map as a zero- 567 length byte string rather than as a zero-length map (encoded as 568 h'a0'). The zero-length binary encoding is preferred because it 569 is both shorter and the version used in the serialization 570 structures for cryptographic computation. After encoding the map, 571 the value is wrapped in the binary object. Recipients MUST accept 572 both a zero-length binary value and a zero-length map encoded in 573 the binary value. The wrapping allows for the encoding of the 574 protected map to be transported with a greater chance that it will 575 not be altered in transit. (Badly behaved intermediates could 576 decode and re-encode, but this will result in a failure to verify 577 unless the re-encoded byte string is identical to the decoded byte 578 string.) This avoids the problem of all parties needing to be 579 able to do a common canonical encoding. 581 unprotected: Contains parameters about the current layer that are 582 not cryptographically protected. 584 Only header parameters that deal with the current layer are to be 585 placed at that layer. As an example of this, the header parameter 586 'content type' describes the content of the message being carried in 587 the message. As such, this header parameter is placed only in the 588 content layer and is not placed in the recipient or signature layers. 589 In principle, one should be able to process any given layer without 590 reference to any other layer. With the exception of the COSE_Sign 591 structure, the only data that needs to cross layers is the 592 cryptographic key. 594 The buckets are present in all of the security objects defined in 595 this document. The fields in order are the 'protected' bucket (as a 596 CBOR 'bstr' type) and then the 'unprotected' bucket (as a CBOR 'map' 597 type). The presence of both buckets is required. The header 598 parameters that go into the buckets come from the IANA "COSE Header 599 Parameters" registry (Section 12.2). Some common header parameters 600 are defined in the next section. 602 Labels in each of the maps MUST be unique. When processing messages, 603 if a label appears multiple times, the message MUST be rejected as 604 malformed. Applications SHOULD verify that the same label does not 605 occur in both the protected and unprotected header parameters. If 606 the message is not rejected as malformed, attributes MUST be obtained 607 from the protected bucket before they are obtained from the 608 unprotected bucket. 610 The following CDDL fragment represents the two header parameter 611 buckets. A group "Headers" is defined in CDDL that represents the 612 two buckets in which attributes are placed. This group is used to 613 provide these two fields consistently in all locations. A type is 614 also defined that represents the map of common header parameters. 616 Headers = ( 617 protected : empty_or_serialized_map, 618 unprotected : header_map 619 ) 621 header_map = { 622 Generic_Headers, 623 * label => values 624 } 626 empty_or_serialized_map = bstr .cbor header_map / bstr .size 0 628 3.1. Common COSE Header Parameters 630 This section defines a set of common header parameters. A summary of 631 these header parameters can be found in Table 3. This table should 632 be consulted to determine the value of label and the type of the 633 value. 635 The set of header parameters defined in this section are: 637 alg: This header parameter is used to indicate the algorithm used 638 for the security processing. This header parameter MUST be 639 authenticated where the ability to do so exists. This support is 640 provided by AEAD algorithms or construction (COSE_Sign, 641 COSE_Sign1, COSE_Mac, and COSE_Mac0). This authentication can be 642 done either by placing the header parameter in the protected 643 header parameter bucket or as part of the externally supplied 644 data. The value is taken from the "COSE Algorithms" registry (see 645 [COSE.Algorithms]). 647 crit: This header parameter is used to indicate which protected 648 header parameters an application that is processing a message is 649 required to understand. Header parameters defined in this 650 document do not need to be included as they should be understood 651 by all implementations. When present, this the 'crit' header 652 parameter MUST be placed in the protected header parameter bucket. 653 The array MUST have at least one value in it. 655 Not all header parameter labels need to be included in the 'crit' 656 header parameter. The rules for deciding which header parameters 657 are placed in the array are: 659 * Integer labels in the range of 0 to 7 SHOULD be omitted. 661 * Integer labels in the range -1 to -128 can be omitted as they 662 are algorithm dependent. If an application can correctly 663 process an algorithm, it can be assumed that it will correctly 664 process all of the common header parameters associated with 665 that algorithm. Integer labels in the range -129 to -65536 666 SHOULD be included as these would be less common header 667 parameters that might not be generally supported. 669 * Labels for header parameters required for an application MAY be 670 omitted. Applications should have a statement if the label can 671 be omitted. 673 The header parameters indicated by 'crit' can be processed by 674 either the security library code or an application using a 675 security library; the only requirement is that the header 676 parameter is processed. If the 'crit' value list includes a label 677 for which the header parameter is not in the protected header 678 parameters bucket, this is a fatal error in processing the 679 message. 681 content type: This header parameter is used to indicate the content 682 type of the data in the payload or ciphertext fields. Integers 683 are from the "CoAP Content-Formats" IANA registry table 684 [COAP.Formats]. Text values following the syntax of "/" where and are 686 defined in Section 4.2 of [RFC6838]. Leading and trailing 687 whitespace is also omitted. Textual content values along with 688 parameters and subparameters can be located using the IANA "Media 689 Types" registry. Applications SHOULD provide this header 690 parameter if the content structure is potentially ambiguous. 692 kid: This header parameter identifies one piece of data that can be 693 used as input to find the needed cryptographic key. The value of 694 this header parameter can be matched against the 'kid' member in a 695 COSE_Key structure. Other methods of key distribution can define 696 an equivalent field to be matched. Applications MUST NOT assume 697 that 'kid' values are unique. There may be more than one key with 698 the same 'kid' value, so all of the keys associated with this 699 'kid' may need to be checked. The internal structure of 'kid' 700 values is not defined and cannot be relied on by applications. 701 Key identifier values are hints about which key to use. This is 702 not a security-critical field. For this reason, it can be placed 703 in the unprotected header parameters bucket. 705 IV: This header parameter holds the Initialization Vector (IV) 706 value. For some symmetric encryption algorithms, this may be 707 referred to as a nonce. The IV can be placed in the unprotected 708 bucket as modifying the IV will cause the decryption to yield 709 plaintext that is readily detectable as garbled. 711 Partial IV: This header parameter holds a part of the IV value. 712 When using the COSE_Encrypt0 structure, a portion of the IV can be 713 part of the context associated with the key (Context IV) while a 714 portion can be changed with each message (Partial IV). This field 715 is used to carry a value that causes the IV to be changed for each 716 message. The Partial IV can be placed in the unprotected bucket 717 as modifying the value will cause the decryption to yield 718 plaintext that is readily detectable as garbled. The 719 'Initialization Vector' and 'Partial Initialization Vector' header 720 parameters MUST NOT both be present in the same security layer. 722 The message IV is generated by the following steps: 724 1. Left-pad the Partial IV with zeros to the length of IV. 726 2. XOR the padded Partial IV with the context IV. 728 counter signature: This header parameter holds one or more counter 729 signature values. Counter signatures provide a method of having a 730 second party sign some data. The counter signature header 731 parameter can occur as an unprotected attribute in any of the 732 following structures: COSE_Sign1, COSE_Signature, COSE_Encrypt, 733 COSE_recipient, COSE_Encrypt0, COSE_Mac, and COSE_Mac0. These 734 structures all have the same beginning elements, so that a 735 consistent calculation of the counter signature can be computed. 736 Details on counter signatures are found in Section 5. 738 +---------+-----+----------------+-----------------+----------------+ 739 | Name |Label| Value Type | Value Registry | Description | 740 +=========+=====+================+=================+================+ 741 | alg | 1 | int / tstr | COSE Algorithms | Cryptographic | 742 | | | | registry |algorithm to use| 743 +---------+-----+----------------+-----------------+----------------+ 744 | crit | 2 | [+ label] | COSE Header |Critical header | 745 | | | | Parameters |parameters to be| 746 | | | | registry | understood | 747 +---------+-----+----------------+-----------------+----------------+ 748 | content | 3 | tstr / uint | CoAP Content- |Content type of | 749 | type | | |Formats or Media | the payload | 750 | | | |Types registries | | 751 +---------+-----+----------------+-----------------+----------------+ 752 | kid | 4 | bstr | | Key identifier | 753 +---------+-----+----------------+-----------------+----------------+ 754 | IV | 5 | bstr | | Full | 755 | | | | | Initialization | 756 | | | | | Vector | 757 +---------+-----+----------------+-----------------+----------------+ 758 | Partial | 6 | bstr | | Partial | 759 | IV | | | | Initialization | 760 | | | | | Vector | 761 +---------+-----+----------------+-----------------+----------------+ 762 | counter | 7 |COSE_Signature /| | CBOR-encoded | 763 |signature| | [+ | | signature | 764 | | |COSE_Signature ]| | structure | 765 +---------+-----+----------------+-----------------+----------------+ 767 Table 3: Common Header Parameters 769 The CDDL fragment that represents the set of header parameters 770 defined in this section is given below. Each of the header 771 parameters is tagged as optional because they do not need to be in 772 every map; header parameters required in specific maps are discussed 773 above. 775 Generic_Headers = ( 776 ? 1 => int / tstr, ; algorithm identifier 777 ? 2 => [+label], ; criticality 778 ? 3 => tstr / int, ; content type 779 ? 4 => bstr, ; key identifier 780 ? 5 => bstr, ; IV 781 ? 6 => bstr, ; Partial IV 782 ? 7 => COSE_Signature / [+COSE_Signature] ; Counter signature 783 ) 785 4. Signing Objects 787 COSE supports two different signature structures. COSE_Sign allows 788 for one or more signatures to be applied to the same content. 789 COSE_Sign1 is restricted to a single signer. The structures cannot 790 be converted between each other; as the signature computation 791 includes a parameter identifying which structure is being used, the 792 converted structure will fail signature validation. 794 4.1. Signing with One or More Signers 796 The COSE_Sign structure allows for one or more signatures to be 797 applied to a message payload. Header parameters relating to the 798 content and header parameters relating to the signature are carried 799 along with the signature itself. These header parameters may be 800 authenticated by the signature, or just present. An example of 801 header a parameter about the content is the content type. Examples 802 of a header parameters about the signature would be the algorithm and 803 key used to create the signature and counter signatures. 805 RFC 5652 indicates that: 807 | When more than one signature is present, the successful validation 808 | of one signature associated with a given signer is usually treated 809 | as a successful signature by that signer. However, there are some 810 | application environments where other rules are needed. An 811 | application that employs a rule other than one valid signature for 812 | each signer must specify those rules. Also, where simple matching 813 | of the signer identifier is not sufficient to determine whether 814 | the signatures were generated by the same signer, the application 815 | specification must describe how to determine which signatures were 816 | generated by the same signer. Support for different communities 817 | of recipients is the primary reason that signers choose to include 818 | more than one signature. 820 For example, the COSE_Sign structure might include signatures 821 generated with the Edwards-curve Digital Signature Algorithm (EdDSA) 822 [RFC8032] and with the Elliptic Curve Digital Signature Algorithm 823 (ECDSA) [DSS]. This allows recipients to verify the signature 824 associated with one algorithm or the other. More-detailed 825 information on multiple signature evaluations can be found in 826 [RFC5752]. 828 The signature structure can be encoded as either tagged or untagged 829 depending on the context it will be used in. A tagged COSE_Sign 830 structure is identified by the CBOR tag 98. The CDDL fragment that 831 represents this is: 833 COSE_Sign_Tagged = #6.98(COSE_Sign) 835 A COSE Signed Message is defined in two parts. The CBOR object that 836 carries the body and information about the body is called the 837 COSE_Sign structure. The CBOR object that carries the signature and 838 information about the signature is called the COSE_Signature 839 structure. Examples of COSE Signed Messages can be found in 840 Appendix C.1. 842 The COSE_Sign structure is a CBOR array. The fields of the array in 843 order are: 845 protected: This is as described in Section 3. 847 unprotected: This is as described in Section 3. 849 payload: This field contains the serialized content to be signed. 850 If the payload is not present in the message, the application is 851 required to supply the payload separately. The payload is wrapped 852 in a bstr to ensure that it is transported without changes. If 853 the payload is transported separately ("detached content"), then a 854 nil CBOR object is placed in this location, and it is the 855 responsibility of the application to ensure that it will be 856 transported without changes. 858 Note: When a signature with a message recovery algorithm is used 859 (Section 9.1), the maximum number of bytes that can be recovered 860 is the length of the payload. The size of the payload is reduced 861 by the number of bytes that will be recovered. If all of the 862 bytes of the payload are consumed, then the payload is encoded as 863 a zero-length byte string rather than as being absent. 865 signatures: This field is an array of signatures. Each signature is 866 represented as a COSE_Signature structure. 868 The CDDL fragment that represents the above text for COSE_Sign 869 follows. 871 COSE_Sign = [ 872 Headers, 873 payload : bstr / nil, 874 signatures : [+ COSE_Signature] 875 ] 877 The COSE_Signature structure is a CBOR array. The fields of the 878 array in order are: 880 protected: This is as described in Section 3. 882 unprotected: This is as described in Section 3. 884 signature: This field contains the computed signature value. The 885 type of the field is a bstr. Algorithms MUST specify padding if 886 the signature value is not a multiple of 8 bits. 888 The CDDL fragment that represents the above text for COSE_Signature 889 follows. 891 COSE_Signature = [ 892 Headers, 893 signature : bstr 894 ] 896 4.2. Signing with One Signer 898 The COSE_Sign1 signature structure is used when only one signature is 899 going to be placed on a message. The header parameters dealing with 900 the content and the signature are placed in the same pair of buckets 901 rather than having the separation of COSE_Sign. 903 The structure can be encoded as either tagged or untagged depending 904 on the context it will be used in. A tagged COSE_Sign1 structure is 905 identified by the CBOR tag 18. The CDDL fragment that represents 906 this is: 908 COSE_Sign1_Tagged = #6.18(COSE_Sign1) 910 The CBOR object that carries the body, the signature, and the 911 information about the body and signature is called the COSE_Sign1 912 structure. Examples of COSE_Sign1 messages can be found in 913 Appendix C.2. 915 The COSE_Sign1 structure is a CBOR array. The fields of the array in 916 order are: 918 protected: This is as described in Section 3. 920 unprotected: This is as described in Section 3. 922 payload: This is as described in Section 4.1. 924 signature: This field contains the computed signature value. The 925 type of the field is a bstr. 927 The CDDL fragment that represents the above text for COSE_Sign1 928 follows. 930 COSE_Sign1 = [ 931 Headers, 932 payload : bstr / nil, 933 signature : bstr 934 ] 936 4.3. Externally Supplied Data 938 One of the features offered in the COSE document is the ability for 939 applications to provide additional data to be authenticated, but that 940 is not carried as part of the COSE object. The primary reason for 941 supporting this can be seen by looking at the CoAP message structure 942 [RFC7252], where the facility exists for options to be carried before 943 the payload. Examples of data that can be placed in this location 944 would be the CoAP code or CoAP options. If the data is in the 945 headers of the CoAP message, then it is available for proxies to help 946 in performing its operations. For example, the Accept Option can be 947 used by a proxy to determine if an appropriate value is in the 948 proxy's cache. But the sender can cause a failure at the server if a 949 proxy, or an attacker, changes the set of accept values by including 950 the field in the application supplied data. 952 This document describes the process for using a byte array of 953 externally supplied authenticated data; the method of constructing 954 the byte array is a function of the application. Applications that 955 use this feature need to define how the externally supplied 956 authenticated data is to be constructed. Such a construction needs 957 to take into account the following issues: 959 * If multiple items are included, applications need to ensure that 960 the same byte string cannot produced if there are different 961 inputs. This would occur by appending the text strings 'AB' and 962 'CDE' or by appending the text strings 'ABC' and 'DE'. This is 963 usually addressed by making fields a fixed width and/or encoding 964 the length of the field as part of the output. Using options from 965 CoAP [RFC7252] as an example, these fields use a TLV structure so 966 they can be concatenated without any problems. 968 * If multiple items are included, an order for the items needs to be 969 defined. Using options from CoAP as an example, an application 970 could state that the fields are to be ordered by the option 971 number. 973 * Applications need to ensure that the byte string is going to be 974 the same on both sides. Using options from CoAP might give a 975 problem if the same relative numbering is kept. An intermediate 976 node could insert or remove an option, changing how the relative 977 number is done. An application would need to specify that the 978 relative number must be re-encoded to be relative only to the 979 options that are in the external data. 981 4.4. Signing and Verification Process 983 In order to create a signature, a well-defined byte string is needed. 984 The Sig_structure is used to create the canonical form. This signing 985 and verification process takes in the body information (COSE_Sign or 986 COSE_Sign1), the signer information (COSE_Signature), and the 987 application data (external source). A Sig_structure is a CBOR array. 988 The fields of the Sig_structure in order are: 990 1. A context text string identifying the context of the signature. 991 The context text string is: 993 "Signature" for signatures using the COSE_Signature structure. 995 "Signature1" for signatures using the COSE_Sign1 structure. 997 "CounterSignature" for signatures used as counter signature 998 attributes. 1000 "CounterSignature0" for signatures used as CounterSignature0 1001 attributes. 1003 2. The protected attributes from the body structure encoded in a 1004 bstr type. If there are no protected attributes, a bstr of 1005 length zero is used. 1007 3. The protected attributes from the signer structure encoded in a 1008 bstr type. If there are no protected attributes, a bstr of 1009 length zero is used. This field is omitted for the COSE_Sign1 1010 signature structure and CounterSignature0 attributes. 1012 4. The protected attributes from the application encoded in a bstr 1013 type. If this field is not supplied, it defaults to a zero- 1014 length byte string. (See Section 4.3 for application guidance on 1015 constructing this field.) 1017 5. The payload to be signed encoded in a bstr type. The payload is 1018 placed here independent of how it is transported. 1020 The CDDL fragment that describes the above text is: 1022 Sig_structure = [ 1023 context : "Signature" / "Signature1" / "CounterSignature" / 1024 "CounterSignature0", 1025 body_protected : empty_or_serialized_map, 1026 ? sign_protected : empty_or_serialized_map, 1027 external_aad : bstr, 1028 payload : bstr 1029 ] 1031 How to compute a signature: 1033 1. Create a Sig_structure and populate it with the appropriate 1034 fields. 1036 2. Create the value ToBeSigned by encoding the Sig_structure to a 1037 byte string, using the encoding described in Section 10. 1039 3. Call the signature creation algorithm passing in K (the key to 1040 sign with), alg (the algorithm to sign with), and ToBeSigned (the 1041 value to sign). 1043 4. Place the resulting signature value in the correct location. 1044 This is the 'signature' field of the COSE_Signature, COSE_Sign1 1045 or COSE_Countersignature structures. This is the value of the 1046 Countersignature0 attribute. 1048 The steps for verifying a signature are: 1050 1. Create a Sig_structure and populate it with the appropriate 1051 fields. 1053 2. Create the value ToBeSigned by encoding the Sig_structure to a 1054 byte string, using the encoding described in Section 10. 1056 3. Call the signature verification algorithm passing in K (the key 1057 to verify with), alg (the algorithm used sign with), ToBeSigned 1058 (the value to sign), and sig (the signature to be verified). 1060 In addition to performing the signature verification, the application 1061 performs the appropriate checks to ensure that the key is correctly 1062 paired with the signing identity and that the signing identity is 1063 authorized before performing actions. 1065 5. Counter Signatures 1067 COSE supports two different forms for counter signatures. Full 1068 countersignatures use the structure COSE_Countersign. This is same 1069 structure as COSE_Signature and thus it can have protected 1070 attributes, chained countersignatures and information about 1071 identifying the key. Abbreviated countersignatures use the structure 1072 COSE_Countersign1. This structure only contains the signature value 1073 and nothing else. The structures cannot be converted between each 1074 other; as the signature computation includes a parameter identifying 1075 which structure is being used, the converted structure will fail 1076 signature validation. 1078 COSE was designed for uniformity in how the data structures are 1079 specified. One result of this is that for COSE one can expand the 1080 concept of countersignatures beyond just the idea of signing a 1081 signature to being able to sign most of the structures without having 1082 to create a new signing layer. When creating a countersignature, one 1083 needs to be clear about the security properties that result. When 1084 done on a COSE_Signature, the normal countersignature semantics are 1085 preserved. That is the countersignature makes a statement about the 1086 existence of a signature and, when used as a timestamp, a time point 1087 at which the signature exists. When done on a COSE_Mac or a 1088 COSE_Mac0, one effectively upgrades the MAC operation to a signature 1089 operation. When done on a COSE_Encrypt or COSE_Encrypt0, the 1090 existence of the encrypted data is attested to. It should be noted 1091 that there is a big difference between attesting to the encrypted 1092 data as opposed to attesting to the unencrypted data. If the latter 1093 is what is desired, then one needs to apply a signature to the data 1094 and then encrypt that. It is always possible to construct cases 1095 where the decryption is successful, while providing completely 1096 different answers by using a different key. This situation is not 1097 detectable by a countersignature on the encrypted data. 1099 5.1. Full Countersignatures 1101 The COSE_Countersignature structure allows for the same set of 1102 capabilities of a COSE_Signature. This means that all of the 1103 capabilities of a signature are duplicated with this structure. 1104 Specifically, the countersigner does not need to be related to the 1105 producer of what is being counter signed as key and algorithm 1106 identification can be placed in the countersignature attributes. 1107 This also means that the countersignature can itself be 1108 countersigned. This is a feature required by protocols such as long- 1109 term archiving services. More information on how this is used can be 1110 found in the evidence record syntax described in [RFC4998]. 1112 The full countersignature structure can be encoded as either a tagged 1113 or untagged depending on the context it is used in. A tagged 1114 COSE_Countersign structure is identified by the CBOR tag TBD0. The 1115 CDDL fragment for full countersignatures is: 1117 COSE_CounterSignature_Tagged = #6.98(COSE_CounterSignature) 1118 COSE_CounterSignature = COSE_Signature 1120 The details of the fields of a countersignature can be found in 1121 Section 4.1. The process of creating and validating abbreviated 1122 countersignatures is defined in Section 4.4. 1124 An example of a counter signature on a signature can be found in 1125 Appendix C.1.3. An example of a counter signature in an encryption 1126 object can be found in Appendix C.3.3. 1128 It should be noted that only a signature algorithm with appendix (see 1129 Section 9.1) can be used for counter signatures. This is because the 1130 body should be able to be processed without having to evaluate the 1131 counter signature, and this is not possible for signature schemes 1132 with message recovery. 1134 5.2. Abbreviated Countersignatures 1136 Abbreviated countersignatures were designed primarily to deal with 1137 the problem of having group encrypted messaging, but still needing to 1138 know who originated the message. The objective was to keep the 1139 countersignature as small as possible while still providing the 1140 needed security. For abbreviated countersignatures, there is no 1141 provision for any protected attributes related to the signing 1142 operation. Instead, the parameters for computing or verifying the 1143 abbreviated countersignature are inferred from the same context used 1144 to describe the encryption, signature, or MAC processing. 1146 The byte string representing the signature value is placed in the 1147 CounterSignature0 attribute. This attribute is then encoded as an 1148 unprotected header parameter. The attribute is defined below. 1150 The process of creating and validating abbreviated countersignatures 1151 is defined in Section 4.4. 1153 +-------------------+-------+------------+-------+------------------+ 1154 | Name | Label | Value | Value | Description | 1155 | | | Type | | | 1156 +===================+=======+============+=======+==================+ 1157 | CounterSignature0 | 9 | bstr | | Abbreviated | 1158 | | | | | Countersignature | 1159 +-------------------+-------+------------+-------+------------------+ 1161 Table 4: Header Parameter for CounterSignature0 1163 6. Encryption Objects 1165 COSE supports two different encryption structures. COSE_Encrypt0 is 1166 used when a recipient structure is not needed because the key to be 1167 used is known implicitly. COSE_Encrypt is used the rest of the time. 1168 This includes cases where there are multiple recipients or a 1169 recipient algorithm other than direct (i.e. pre-shared secret) is 1170 used. 1172 6.1. Enveloped COSE Structure 1174 The enveloped structure allows for one or more recipients of a 1175 message. There are provisions for header parameters about the 1176 content and header parameters about the recipient information to be 1177 carried in the message. The protected header parameters associated 1178 with the content are authenticated by the content encryption 1179 algorithm. The protected header parameters associated with the 1180 recipient are authenticated by the recipient algorithm (when the 1181 algorithm supports it). Examples of header parameters about the 1182 content are the type of the content and the content encryption 1183 algorithm. Examples of header parameters about the recipient are the 1184 recipient's key identifier and the recipient's encryption algorithm. 1186 The same techniques and nearly the same structure is used for 1187 encrypting both the plaintext and the keys. This is different from 1188 the approach used by both "Cryptographic Message Syntax (CMS)" 1189 [RFC5652] and "JSON Web Encryption (JWE)" [RFC7516] where different 1190 structures are used for the content layer and for the recipient 1191 layer. Two structures are defined: COSE_Encrypt to hold the 1192 encrypted content and COSE_recipient to hold the encrypted keys for 1193 recipients. Examples of encrypted messages can be found in 1194 Appendix C.3. 1196 The COSE_Encrypt structure can be encoded as either tagged or 1197 untagged depending on the context it will be used in. A tagged 1198 COSE_Encrypt structure is identified by the CBOR tag 96. The CDDL 1199 fragment that represents this is: 1201 COSE_Encrypt_Tagged = #6.96(COSE_Encrypt) 1203 The COSE_Encrypt structure is a CBOR array. The fields of the array 1204 in order are: 1206 protected: This is as described in Section 3. 1208 unprotected: This is as described in Section 3. 1210 ciphertext: This field contains the ciphertext encoded as a bstr. 1211 If the ciphertext is to be transported independently of the 1212 control information about the encryption process (i.e., detached 1213 content), then the field is encoded as a nil value. 1215 recipients: This field contains an array of recipient information 1216 structures. The type for the recipient information structure is a 1217 COSE_recipient. 1219 The CDDL fragment that corresponds to the above text is: 1221 COSE_Encrypt = [ 1222 Headers, 1223 ciphertext : bstr / nil, 1224 recipients : [+COSE_recipient] 1225 ] 1227 The COSE_recipient structure is a CBOR array. The fields of the 1228 array in order are: 1230 protected: This is as described in Section 3. 1232 unprotected: This is as described in Section 3. 1234 ciphertext: This field contains the encrypted key encoded as a bstr. 1235 All encoded keys are symmetric keys; the binary value of the key 1236 is the content. If there is not an encrypted key, then this field 1237 is encoded as a nil value. 1239 recipients: This field contains an array of recipient information 1240 structures. The type for the recipient information structure is a 1241 COSE_recipient (an example of this can be found in Appendix B). 1242 If there are no recipient information structures, this element is 1243 absent. 1245 The CDDL fragment that corresponds to the above text for 1246 COSE_recipient is: 1248 COSE_recipient = [ 1249 Headers, 1250 ciphertext : bstr / nil, 1251 ? recipients : [+COSE_recipient] 1252 ] 1254 6.1.1. Content Key Distribution Methods 1256 An encrypted message consists of an encrypted content and an 1257 encrypted CEK for one or more recipients. The CEK is encrypted for 1258 each recipient, using a key specific to that recipient. The details 1259 of this encryption depend on which class the recipient algorithm 1260 falls into. Specific details on each of the classes can be found in 1261 Section 9.5. A short summary of the five content key distribution 1262 methods is: 1264 direct: The CEK is the same as the identified previously distributed 1265 symmetric key or is derived from a previously distributed secret. 1266 No CEK is transported in the message. 1268 symmetric key-encryption keys (KEK): The CEK is encrypted using a 1269 previously distributed symmetric KEK. Also known as key wrap. 1271 key agreement: The recipient's public key and a sender's private key 1272 are used to generate a pairwise secret, a Key Derivation Function 1273 (KDF) is applied to derive a key, and then the CEK is either the 1274 derived key or encrypted by the derived key. 1276 key transport: The CEK is encrypted with the recipient's public key. 1278 passwords: The CEK is encrypted in a KEK that is derived from a 1279 password. As of when this document was published, no password 1280 algorithms have been defined. 1282 6.2. Single Recipient Encrypted 1284 The COSE_Encrypt0 encrypted structure does not have the ability to 1285 specify recipients of the message. The structure assumes that the 1286 recipient of the object will already know the identity of the key to 1287 be used in order to decrypt the message. If a key needs to be 1288 identified to the recipient, the enveloped structure ought to be 1289 used. 1291 Examples of encrypted messages can be found in Appendix C.3. 1293 The COSE_Encrypt0 structure can be encoded as either tagged or 1294 untagged depending on the context it will be used in. A tagged 1295 COSE_Encrypt0 structure is identified by the CBOR tag 16. The CDDL 1296 fragment that represents this is: 1298 COSE_Encrypt0_Tagged = #6.16(COSE_Encrypt0) 1300 The COSE_Encrypt0 structure is a CBOR array. The fields of the array 1301 in order are: 1303 protected: This is as described in Section 3. 1305 unprotected: This is as described in Section 3. 1307 ciphertext: This is as described in Section 6.1. 1309 The CDDL fragment for COSE_Encrypt0 that corresponds to the above 1310 text is: 1312 COSE_Encrypt0 = [ 1313 Headers, 1314 ciphertext : bstr / nil, 1315 ] 1317 6.3. How to Encrypt and Decrypt for AEAD Algorithms 1319 The encryption algorithm for AEAD algorithms is fairly simple. The 1320 first step is to create a consistent byte string for the 1321 authenticated data structure. For this purpose, we use an 1322 Enc_structure. The Enc_structure is a CBOR array. The fields of the 1323 Enc_structure in order are: 1325 1. A context text string identifying the context of the 1326 authenticated data structure. The context text string is: 1328 "Encrypt0" for the content encryption of a COSE_Encrypt0 data 1329 structure. 1331 "Encrypt" for the first layer of a COSE_Encrypt data structure 1332 (i.e., for content encryption). 1334 "Enc_Recipient" for a recipient encoding to be placed in an 1335 COSE_Encrypt data structure. 1337 "Mac_Recipient" for a recipient encoding to be placed in a 1338 MACed message structure. 1340 "Rec_Recipient" for a recipient encoding to be placed in a 1341 recipient structure. 1343 2. The protected attributes from the body structure encoded in a 1344 bstr type. If there are no protected attributes, a bstr of 1345 length zero is used. 1347 3. The protected attributes from the application encoded in a bstr 1348 type. If this field is not supplied, it defaults to a zero- 1349 length bstr. (See Section 4.3 for application guidance on 1350 constructing this field.) 1352 The CDDL fragment that describes the above text is: 1354 Enc_structure = [ 1355 context : "Encrypt" / "Encrypt0" / "Enc_Recipient" / 1356 "Mac_Recipient" / "Rec_Recipient", 1357 protected : empty_or_serialized_map, 1358 external_aad : bstr 1359 ] 1361 How to encrypt a message: 1363 1. Create an Enc_structure and populate it with the appropriate 1364 fields. 1366 2. Encode the Enc_structure to a byte string (Additional 1367 Authenticated Data (AAD)), using the encoding described in 1368 Section 10. 1370 3. Determine the encryption key (K). This step is dependent on the 1371 class of recipient algorithm being used. For: 1373 No Recipients: The key to be used is determined by the algorithm 1374 and key at the current layer. Examples are key transport keys 1375 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1376 secrets. 1378 Direct Encryption and Direct Key Agreement: The key is 1379 determined by the key and algorithm in the recipient 1380 structure. The encryption algorithm and size of the key to be 1381 used are inputs into the KDF used for the recipient. (For 1382 direct, the KDF can be thought of as the identity operation.) 1383 Examples of these algorithms are found in Sections 6.1.2 and 1384 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1386 Other: The key is randomly or pseudo-randomly generated. 1388 4. Call the encryption algorithm with K (the encryption key), P (the 1389 plaintext), and AAD. Place the returned ciphertext into the 1390 'ciphertext' field of the structure. 1392 5. For recipients of the message, recursively perform the encryption 1393 algorithm for that recipient, using K (the encryption key) as the 1394 plaintext. 1396 How to decrypt a message: 1398 1. Create an Enc_structure and populate it with the appropriate 1399 fields. 1401 2. Encode the Enc_structure to a byte string (AAD), using the 1402 encoding described in Section 10. 1404 3. Determine the decryption key. This step is dependent on the 1405 class of recipient algorithm being used. For: 1407 No Recipients: The key to be used is determined by the algorithm 1408 and key at the current layer. Examples are key transport keys 1409 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1410 secrets. 1412 Direct Encryption and Direct Key Agreement: The key is 1413 determined by the key and algorithm in the recipient 1414 structure. The encryption algorithm and size of the key to be 1415 used are inputs into the KDF used for the recipient. (For 1416 direct, the KDF can be thought of as the identity operation.) 1418 Other: The key is determined by decoding and decrypting one of 1419 the recipient structures. 1421 4. Call the decryption algorithm with K (the decryption key to use), 1422 C (the ciphertext), and AAD. 1424 6.4. How to Encrypt and Decrypt for AE Algorithms 1426 How to encrypt a message: 1428 1. Verify that the 'protected' field is empty. 1430 2. Verify that there was no external additional authenticated data 1431 supplied for this operation. 1433 3. Determine the encryption key. This step is dependent on the 1434 class of recipient algorithm being used. For: 1436 No Recipients: The key to be used is determined by the algorithm 1437 and key at the current layer. Examples are key transport keys 1438 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1439 secrets. 1441 Direct Encryption and Direct Key Agreement: The key is 1442 determined by the key and algorithm in the recipient 1443 structure. The encryption algorithm and size of the key to be 1444 used are inputs into the KDF used for the recipient. (For 1445 direct, the KDF can be thought of as the identity operation.) 1446 Examples of these algorithms are found in Sections 6.1.2 and 1447 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1449 Other: The key is randomly generated. 1451 4. Call the encryption algorithm with K (the encryption key to use) 1452 and P (the plaintext). Place the returned ciphertext into the 1453 'ciphertext' field of the structure. 1455 5. For recipients of the message, recursively perform the encryption 1456 algorithm for that recipient, using K (the encryption key) as the 1457 plaintext. 1459 How to decrypt a message: 1461 1. Verify that the 'protected' field is empty. 1463 2. Verify that there was no external additional authenticated data 1464 supplied for this operation. 1466 3. Determine the decryption key. This step is dependent on the 1467 class of recipient algorithm being used. For: 1469 No Recipients: The key to be used is determined by the algorithm 1470 and key at the current layer. Examples are key transport keys 1471 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1472 secrets. 1474 Direct Encryption and Direct Key Agreement: The key is 1475 determined by the key and algorithm in the recipient 1476 structure. The encryption algorithm and size of the key to be 1477 used are inputs into the KDF used for the recipient. (For 1478 direct, the KDF can be thought of as the identity operation.) 1479 Examples of these algorithms are found in Sections 6.1.2 and 1480 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1482 Other: The key is determined by decoding and decrypting one of 1483 the recipient structures. 1485 4. Call the decryption algorithm with K (the decryption key to use) 1486 and C (the ciphertext). 1488 7. MAC Objects 1490 COSE supports two different MAC structures. COSE_MAC0 is used when a 1491 recipient structure is not needed because the key to be used is 1492 implicitly known. COSE_MAC is used for all other cases. These 1493 include a requirement for multiple recipients, the key being unknown, 1494 or a recipient algorithm of other than direct. 1496 In this section, we describe the structure and methods to be used 1497 when doing MAC authentication in COSE. This document allows for the 1498 use of all of the same classes of recipient algorithms as are allowed 1499 for encryption. 1501 When using MAC operations, there are two modes in which they can be 1502 used. The first is just a check that the content has not been 1503 changed since the MAC was computed. Any class of recipient algorithm 1504 can be used for this purpose. The second mode is to both check that 1505 the content has not been changed since the MAC was computed and to 1506 use the recipient algorithm to verify who sent it. The classes of 1507 recipient algorithms that support this are those that use a pre- 1508 shared secret or do static-static (SS) key agreement (without the key 1509 wrap step). In both of these cases, the entity that created and sent 1510 the message MAC can be validated. (This knowledge of the sender 1511 assumes that there are only two parties involved and that you did not 1512 send the message to yourself.) The origination property can be 1513 obtained with both of the MAC message structures. 1515 7.1. MACed Message with Recipients 1517 The multiple recipient MACed message uses two structures: the 1518 COSE_Mac structure defined in this section for carrying the body and 1519 the COSE_recipient structure (Section 6.1) to hold the key used for 1520 the MAC computation. Examples of MACed messages can be found in 1521 Appendix C.5. 1523 The MAC structure can be encoded as either tagged or untagged 1524 depending on the context it will be used in. A tagged COSE_Mac 1525 structure is identified by the CBOR tag 97. The CDDL fragment that 1526 represents this is: 1528 COSE_Mac_Tagged = #6.97(COSE_Mac) 1530 The COSE_Mac structure is a CBOR array. The fields of the array in 1531 order are: 1533 protected: This is as described in Section 3. 1535 unprotected: This is as described in Section 3. 1537 payload: This field contains the serialized content to be MACed. If 1538 the payload is not present in the message, the application is 1539 required to supply the payload separately. The payload is wrapped 1540 in a bstr to ensure that it is transported without changes. If 1541 the payload is transported separately (i.e., detached content), 1542 then a nil CBOR value is placed in this location, and it is the 1543 responsibility of the application to ensure that it will be 1544 transported without changes. 1546 tag: This field contains the MAC value. 1548 recipients: This is as described in Section 6.1. 1550 The CDDL fragment that represents the above text for COSE_Mac 1551 follows. 1553 COSE_Mac = [ 1554 Headers, 1555 payload : bstr / nil, 1556 tag : bstr, 1557 recipients :[+COSE_recipient] 1558 ] 1560 7.2. MACed Messages with Implicit Key 1562 In this section, we describe the structure and methods to be used 1563 when doing MAC authentication for those cases where the recipient is 1564 implicitly known. 1566 The MACed message uses the COSE_Mac0 structure defined in this 1567 section for carrying the body. Examples of MACed messages with an 1568 implicit key can be found in Appendix C.6. 1570 The MAC structure can be encoded as either tagged or untagged 1571 depending on the context it will be used in. A tagged COSE_Mac0 1572 structure is identified by the CBOR tag 17. The CDDL fragment that 1573 represents this is: 1575 COSE_Mac0_Tagged = #6.17(COSE_Mac0) 1577 The COSE_Mac0 structure is a CBOR array. The fields of the array in 1578 order are: 1580 protected: This is as described in Section 3. 1582 unprotected: This is as described in Section 3. 1584 payload: This is as described in Section 7.1. 1586 tag: This field contains the MAC value. 1588 The CDDL fragment that corresponds to the above text is: 1590 COSE_Mac0 = [ 1591 Headers, 1592 payload : bstr / nil, 1593 tag : bstr, 1594 ] 1596 7.3. How to Compute and Verify a MAC 1598 In order to get a consistent encoding of the data to be 1599 authenticated, the MAC_structure is used to have a canonical form. 1600 The MAC_structure is a CBOR array. The fields of the MAC_structure 1601 in order are: 1603 1. A context text string that identifies the structure that is being 1604 encoded. This context text string is "MAC" for the COSE_Mac 1605 structure. This context text string is "MAC0" for the COSE_Mac0 1606 structure. 1608 2. The protected attributes from the COSE_MAC structure. If there 1609 are no protected attributes, a zero-length bstr is used. 1611 3. The protected attributes from the application encoded as a bstr 1612 type. If this field is not supplied, it defaults to a zero- 1613 length byte string. (See Section 4.3 for application guidance on 1614 constructing this field.) 1616 4. The payload to be MACed encoded in a bstr type. The payload is 1617 placed here independent of how it is transported. 1619 The CDDL fragment that corresponds to the above text is: 1621 MAC_structure = [ 1622 context : "MAC" / "MAC0", 1623 protected : empty_or_serialized_map, 1624 external_aad : bstr, 1625 payload : bstr 1626 ] 1628 The steps to compute a MAC are: 1630 1. Create a MAC_structure and populate it with the appropriate 1631 fields. 1633 2. Create the value ToBeMaced by encoding the MAC_structure to a 1634 byte string, using the encoding described in Section 10. 1636 3. Call the MAC creation algorithm passing in K (the key to use), 1637 alg (the algorithm to MAC with), and ToBeMaced (the value to 1638 compute the MAC on). 1640 4. Place the resulting MAC in the 'tag' field of the COSE_Mac or 1641 COSE_Mac0 structure. 1643 5. For COSE_Mac structures, encrypt and encode the MAC key for each 1644 recipient of the message. 1646 The steps to verify a MAC are: 1648 1. Create a MAC_structure and populate it with the appropriate 1649 fields. 1651 2. Create the value ToBeMaced by encoding the MAC_structure to a 1652 byte string, using the encoding described in Section 10. 1654 3. For COSE_Mac structures, obtain the cryptographic key from one of 1655 the recipients of the message. 1657 4. Call the MAC creation algorithm passing in K (the key to use), 1658 alg (the algorithm to MAC with), and ToBeMaced (the value to 1659 compute the MAC on). 1661 5. Compare the MAC value to the 'tag' field of the COSE_Mac or 1662 COSE_Mac0 structure. 1664 8. Key Objects 1666 A COSE Key structure is built on a CBOR map. The set of common 1667 parameters that can appear in a COSE Key can be found in the IANA 1668 "COSE Key Common Parameters" registry (Section 12.4). Additional 1669 parameters defined for specific key types can be found in the IANA 1670 "COSE Key Type Parameters" registry ([COSE.KeyParameters]). 1672 A COSE Key Set uses a CBOR array object as its underlying type. The 1673 values of the array elements are COSE Keys. A COSE Key Set MUST have 1674 at least one element in the array. Examples of COSE Key Sets can be 1675 found in Appendix C.7. 1677 Each element in a COSE Key Set MUST be processed independently. If 1678 one element in a COSE Key Set is either malformed or uses a key that 1679 is not understood by an application, that key is ignored and the 1680 other keys are processed normally. 1682 The element "kty" is a required element in a COSE_Key map. 1684 The CDDL grammar describing COSE_Key and COSE_KeySet is: 1686 COSE_Key = { 1687 1 => tstr / int, ; kty 1688 ? 2 => bstr, ; kid 1689 ? 3 => tstr / int, ; alg 1690 ? 4 => [+ (tstr / int) ], ; key_ops 1691 ? 5 => bstr, ; Base IV 1692 * label => values 1693 } 1695 COSE_KeySet = [+COSE_Key] 1697 8.1. COSE Key Common Parameters 1699 This document defines a set of common parameters for a COSE Key 1700 object. Table 5 provides a summary of the parameters defined in this 1701 section. There are also parameters that are defined for specific key 1702 types. Key-type-specific parameters can be found in 1703 [I-D.ietf-cose-rfc8152bis-algs]. 1705 +---------+-------+--------+------------+--------------------+ 1706 | Name | Label | CBOR | Value | Description | 1707 | | | Type | Registry | | 1708 +=========+=======+========+============+====================+ 1709 | kty | 1 | tstr / | COSE Key | Identification of | 1710 | | | int | Types | the key type | 1711 +---------+-------+--------+------------+--------------------+ 1712 | kid | 2 | bstr | | Key identification | 1713 | | | | | value -- match to | 1714 | | | | | kid in message | 1715 +---------+-------+--------+------------+--------------------+ 1716 | alg | 3 | tstr / | COSE | Key usage | 1717 | | | int | Algorithms | restriction to | 1718 | | | | | this algorithm | 1719 +---------+-------+--------+------------+--------------------+ 1720 | key_ops | 4 | [+ | | Restrict set of | 1721 | | | (tstr/ | | permissible | 1722 | | | int)] | | operations | 1723 +---------+-------+--------+------------+--------------------+ 1724 | Base IV | 5 | bstr | | Base IV to be xor- | 1725 | | | | | ed with Partial | 1726 | | | | | IVs | 1727 +---------+-------+--------+------------+--------------------+ 1729 Table 5: Key Map Labels 1731 kty: This parameter is used to identify the family of keys for this 1732 structure and, thus, the set of key-type-specific parameters to be 1733 found. The set of values defined in this document can be found in 1734 [COSE.KeyTypes]. This parameter MUST be present in a key object. 1735 Implementations MUST verify that the key type is appropriate for 1736 the algorithm being processed. The key type MUST be included as 1737 part of the trust decision process. 1739 alg: This parameter is used to restrict the algorithm that is used 1740 with the key. If this parameter is present in the key structure, 1741 the application MUST verify that this algorithm matches the 1742 algorithm for which the key is being used. If the algorithms do 1743 not match, then this key object MUST NOT be used to perform the 1744 cryptographic operation. Note that the same key can be in a 1745 different key structure with a different or no algorithm 1746 specified; however, this is considered to be a poor security 1747 practice. 1749 kid: This parameter is used to give an identifier for a key. The 1750 identifier is not structured and can be anything from a user- 1751 provided byte string to a value computed on the public portion of 1752 the key. This field is intended for matching against a 'kid' 1753 parameter in a message in order to filter down the set of keys 1754 that need to be checked. 1756 key_ops: This parameter is defined to restrict the set of operations 1757 that a key is to be used for. The value of the field is an array 1758 of values from Table 6. Algorithms define the values of key ops 1759 that are permitted to appear and are required for specific 1760 operations. The set of values matches that in [RFC7517] and 1761 [W3C.WebCrypto]. 1763 Base IV: This parameter is defined to carry the base portion of an 1764 IV. It is designed to be used with the Partial IV header 1765 parameter defined in Section 3.1. This field provides the ability 1766 to associate a Partial IV with a key that is then modified on a 1767 per message basis with the Partial IV. 1769 Extreme care needs to be taken when using a Base IV in an 1770 application. Many encryption algorithms lose security if the same 1771 IV is used twice. 1773 If different keys are derived for each sender, using the same Base 1774 IV with Partial IVs starting at zero is likely to ensure that the 1775 IV would not be used twice for a single key. If different keys 1776 are derived for each sender, starting at the same Base IV is 1777 likely to satisfy this condition. If the same key is used for 1778 multiple senders, then the application needs to provide for a 1779 method of dividing the IV space up between the senders. This 1780 could be done by providing a different base point to start from or 1781 a different Partial IV to start with and restricting the number of 1782 messages to be sent before rekeying. 1784 +---------+-------+----------------------------------------------+ 1785 | Name | Value | Description | 1786 +=========+=======+==============================================+ 1787 | sign | 1 | The key is used to create signatures. | 1788 | | | Requires private key fields. | 1789 +---------+-------+----------------------------------------------+ 1790 | verify | 2 | The key is used for verification of | 1791 | | | signatures. | 1792 +---------+-------+----------------------------------------------+ 1793 | encrypt | 3 | The key is used for key transport | 1794 | | | encryption. | 1795 +---------+-------+----------------------------------------------+ 1796 | decrypt | 4 | The key is used for key transport | 1797 | | | decryption. Requires private key fields. | 1798 +---------+-------+----------------------------------------------+ 1799 | wrap | 5 | The key is used for key wrap encryption. | 1800 | key | | | 1801 +---------+-------+----------------------------------------------+ 1802 | unwrap | 6 | The key is used for key wrap decryption. | 1803 | key | | Requires private key fields. | 1804 +---------+-------+----------------------------------------------+ 1805 | derive | 7 | The key is used for deriving keys. Requires | 1806 | key | | private key fields. | 1807 +---------+-------+----------------------------------------------+ 1808 | derive | 8 | The key is used for deriving bits not to be | 1809 | bits | | used as a key. Requires private key fields. | 1810 +---------+-------+----------------------------------------------+ 1811 | MAC | 9 | The key is used for creating MACs. | 1812 | create | | | 1813 +---------+-------+----------------------------------------------+ 1814 | MAC | 10 | The key is used for validating MACs. | 1815 | verify | | | 1816 +---------+-------+----------------------------------------------+ 1818 Table 6: Key Operation Values 1820 9. Taxonomy of Algorithms used by COSE 1822 In this section, a taxonomy of the different algorithm types that can 1823 be used in COSE is laid out. This taxonomy should not be considered 1824 to be exhaustive as there are new algorithm structures that could be 1825 found or are not known to the author. 1827 9.1. Signature Algorithms 1829 Signature algorithms provide data origination and data integrity 1830 services. Data origination provides the ability to infer who 1831 originated the data based on who signed the data. Data integrity 1832 provides the ability to verify that the data has not been modified 1833 since it was signed. 1835 There are two signature algorithm schemes. The first is signature 1836 with appendix. In this scheme, the message content is processed and 1837 a signature is produced; the signature is called the appendix. This 1838 is the scheme used by algorithms such as ECDSA and the RSA 1839 Probabilistic Signature Scheme (RSASSA-PSS). (In fact, the SSA in 1840 RSASSA-PSS stands for Signature Scheme with Appendix.) 1842 The signature functions for this scheme are: 1844 signature = Sign(message content, key) 1846 valid = Verification(message content, key, signature) 1848 The second scheme is signature with message recovery (an example of 1849 such an algorithm is [PVSig]). In this scheme, the message content 1850 is processed, but part of it is included in the signature. Moving 1851 bytes of the message content into the signature allows for smaller 1852 signatures; the signature size is still potentially large, but the 1853 message content has shrunk. This has implications for systems 1854 implementing these algorithms and for applications that use them. 1855 The first is that the message content is not fully available until 1856 after a signature has been validated. Until that point, the part of 1857 the message contained inside of the signature is unrecoverable. The 1858 second is that the security analysis of the strength of the signature 1859 is very much based on the structure of the message content. Messages 1860 that are highly predictable require additional randomness to be 1861 supplied as part of the signature process. In the worst case, it 1862 becomes the same as doing a signature with appendix. Finally, in the 1863 event that multiple signatures are applied to a message, all of the 1864 signature algorithms are going to be required to consume the same 1865 number of bytes of message content. This means that the mixing of 1866 the different schemes in a single message is not supported, and if a 1867 recovery signature scheme is used, then the same amount of content 1868 needs to be consumed by all of the signatures. 1870 The signature functions for this scheme are: 1872 signature, message sent = Sign(message content, key) 1874 valid, message content = Verification(message sent, key, signature) 1875 Signature algorithms are used with the COSE_Signature and COSE_Sign1 1876 structures. At this time, only signatures with appendixes are 1877 defined for use with COSE; however, considerable interest has been 1878 expressed in using a signature with message recovery algorithm due to 1879 the effective size reduction that is possible. Implementations will 1880 need to keep this in mind for later possible integration. 1882 9.2. Message Authentication Code (MAC) Algorithms 1884 Message Authentication Codes (MACs) provide data authentication and 1885 integrity protection. They provide either no or very limited data 1886 origination. A MAC, for example, cannot be used to prove the 1887 identity of the sender to a third party. 1889 MACs use the same scheme as signature with appendix algorithms. The 1890 message content is processed and an authentication code is produced. 1891 The authentication code is frequently called a tag. 1893 The MAC functions are: 1895 tag = MAC_Create(message content, key) 1897 valid = MAC_Verify(message content, key, tag) 1899 MAC algorithms can be based on either a block cipher algorithm (i.e., 1900 AES-MAC) or a hash algorithm (i.e., a Hash-based Message 1901 Authentication Code (HMAC)). [I-D.ietf-cose-rfc8152bis-algs] defines 1902 a MAC algorithm using each of these constructions. 1904 MAC algorithms are used in the COSE_Mac and COSE_Mac0 structures. 1906 9.3. Content Encryption Algorithms 1908 Content encryption algorithms provide data confidentiality for 1909 potentially large blocks of data using a symmetric key. They provide 1910 integrity on the data that was encrypted; however, they provide 1911 either no or very limited data origination. (One cannot, for 1912 example, be used to prove the identity of the sender to a third 1913 party.) The ability to provide data origination is linked to how the 1914 CEK is obtained. 1916 COSE restricts the set of legal content encryption algorithms to 1917 those that support authentication both of the content and additional 1918 data. The encryption process will generate some type of 1919 authentication value, but that value may be either explicit or 1920 implicit in terms of the algorithm definition. For simplicity's 1921 sake, the authentication code will normally be defined as being 1922 appended to the ciphertext stream. The encryption functions are: 1924 ciphertext = Encrypt(message content, key, additional data) 1926 valid, message content = Decrypt(ciphertext, key, additional data) 1928 Most AEAD algorithms are logically defined as returning the message 1929 content only if the decryption is valid. Many but not all 1930 implementations will follow this convention. The message content 1931 MUST NOT be used if the decryption does not validate. 1933 These algorithms are used in COSE_Encrypt and COSE_Encrypt0. 1935 9.4. Key Derivation Functions (KDFs) 1937 KDFs are used to take some secret value and generate a different one. 1938 The secret value comes in three flavors: 1940 * Secrets that are uniformly random: This is the type of secret that 1941 is created by a good random number generator. 1943 * Secrets that are not uniformly random: This is type of secret that 1944 is created by operations like key agreement. 1946 * Secrets that are not random: This is the type of secret that 1947 people generate for things like passwords. 1949 General KDFs work well with the first type of secret, can do 1950 reasonably well with the second type of secret, and generally do 1951 poorly with the last type of secret. Functions like PBES2 [RFC8018] 1952 need to be used for non-random secrets. 1954 The same KDF can be set up to deal with the first two types of 1955 secrets in a different way. The KDF defined in section 5.1 of 1956 [I-D.ietf-cose-rfc8152bis-algs] is such a function. This is 1957 reflected in the set of algorithms defined around the HMAC-based 1958 Extract-and-Expand Key Derivation Function (HKDF). 1960 When using KDFs, one component that is included is context 1961 information. Context information is used to allow for different 1962 keying information to be derived from the same secret. The use of 1963 context-based keying material is considered to be a good security 1964 practice. 1966 9.5. Content Key Distribution Methods 1968 Content key distribution methods (recipient algorithms) can be 1969 defined into a number of different classes. COSE has the ability to 1970 support many classes of recipient algorithms. In this section, a 1971 number of classes are listed. The names of the recipient algorithm 1972 classes used here are the same as those defined in [RFC7516]. Other 1973 specifications use different terms for the recipient algorithm 1974 classes or do not support some of the recipient algorithm classes. 1976 9.5.1. Direct Encryption 1978 The direct encryption class algorithms share a secret between the 1979 sender and the recipient that is used either directly or after 1980 manipulation as the CEK. When direct encryption mode is used, it 1981 MUST be the only mode used on the message. 1983 The COSE_Recipient structure for the recipient is organized as 1984 follows: 1986 * The 'protected' field MUST be a zero-length item unless it is used 1987 in the computation of the content key. 1989 * The 'alg' header parameter MUST be present. 1991 * A header parameter identifying the shared secret SHOULD be 1992 present. 1994 * The 'ciphertext' field MUST be a zero-length item. 1996 * The 'recipients' field MUST be absent. 1998 9.5.2. Key Wrap 2000 In key wrap mode, the CEK is randomly generated and that key is then 2001 encrypted by a shared secret between the sender and the recipient. 2002 All of the currently defined key wrap algorithms for COSE are AE 2003 algorithms. Key wrap mode is considered to be superior to direct 2004 encryption if the system has any capability for doing random key 2005 generation. This is because the shared key is used to wrap random 2006 data rather than data that has some degree of organization and may in 2007 fact be repeating the same content. The use of key wrap loses the 2008 weak data origination that is provided by the direct encryption 2009 algorithms. 2011 The COSE_Encrypt structure for the recipient is organized as follows: 2013 * The 'protected' field MUST be absent if the key wrap algorithm is 2014 an AE algorithm. 2016 * The 'recipients' field is normally absent, but can be used. 2017 Applications MUST deal with a recipient field being present that 2018 has an unsupported algorithm, not being able to decrypt that 2019 recipient is an acceptable way of dealing with it. Failing to 2020 process the message is not an acceptable way of dealing with it. 2022 * The plaintext to be encrypted is the key from next layer down 2023 (usually the content layer). 2025 * At a minimum, the 'unprotected' field MUST contain the 'alg' 2026 header parameter and SHOULD contain a header parameter identifying 2027 the shared secret. 2029 9.5.3. Key Transport 2031 Key transport mode is also called key encryption mode in some 2032 standards. Key transport mode differs from key wrap mode in that it 2033 uses an asymmetric encryption algorithm rather than a symmetric 2034 encryption algorithm to protect the key. A set of key transport 2035 algorithms are defined in [RFC8230]. 2037 When using a key transport algorithm, the COSE_Encrypt structure for 2038 the recipient is organized as follows: 2040 * The 'protected' field MUST be absent. 2042 * The plaintext to be encrypted is the key from the next layer down 2043 (usually the content layer). 2045 * At a minimum, the 'unprotected' field MUST contain the 'alg' 2046 header parameter and SHOULD contain a parameter identifying the 2047 asymmetric key. 2049 9.5.4. Direct Key Agreement 2051 The 'direct key agreement' class of recipient algorithms uses a key 2052 agreement method to create a shared secret. A KDF is then applied to 2053 the shared secret to derive a key to be used in protecting the data. 2054 This key is normally used as a CEK or MAC key, but could be used for 2055 other purposes if more than two layers are in use (see Appendix B). 2057 The most commonly used key agreement algorithm is Diffie-Hellman, but 2058 other variants exist. Since COSE is designed for a store and forward 2059 environment rather than an online environment, many of the DH 2060 variants cannot be used as the receiver of the message cannot provide 2061 any dynamic key material. One side effect of this is that perfect 2062 forward secrecy (see [RFC4949]) is not achievable. A static key will 2063 always be used for the receiver of the COSE object. 2065 Two variants of DH that are supported are: 2067 Ephemeral-Static (ES) DH: where the sender of the message creates 2068 a one-time DH key and uses a static key for the recipient. The 2069 use of the ephemeral sender key means that no additional random 2070 input is needed as this is randomly generated for each message. 2072 Static-Static (SS) DH: where a static key is used for both the 2073 sender and the recipient. The use of static keys allows for the 2074 recipient to get a weak version of data origination for the 2075 message. When static-static key agreement is used, then some 2076 piece of unique data for the KDF is required to ensure that a 2077 different key is created for each message. 2079 When direct key agreement mode is used, there MUST be only one 2080 recipient in the message. This method creates the key directly, and 2081 that makes it difficult to mix with additional recipients. If 2082 multiple recipients are needed, then the version with key wrap needs 2083 to be used. 2085 The COSE_Encrypt structure for the recipient is organized as follows: 2087 * At a minimum, headers MUST contain the 'alg' header parameter and 2088 SHOULD contain a header parameter identifying the recipient's 2089 asymmetric key. 2091 * The headers SHOULD identify the sender's key for the static-static 2092 versions and MUST contain the sender's ephemeral key for the 2093 ephemeral-static versions. 2095 9.5.5. Key Agreement with Key Wrap 2097 Key Agreement with Key Wrap uses a randomly generated CEK. The CEK 2098 is then encrypted using a key wrap algorithm and a key derived from 2099 the shared secret computed by the key agreement algorithm. The 2100 function for this would be: 2102 encryptedKey = KeyWrap(KDF(DH-Shared, context), CEK) 2104 The COSE_Encrypt structure for the recipient is organized as follows: 2106 * The 'protected' field is fed into the KDF context structure. 2108 * The plaintext to be encrypted is the key from the next layer down 2109 (usually the content layer). 2111 * The 'alg' header parameter MUST be present in the layer. 2113 * A header parameter identifying the recipient's key SHOULD be 2114 present. A header parameter identifying the sender's key SHOULD 2115 be present. 2117 10. CBOR Encoding Restrictions 2119 There has been an attempt to limit the number of places where the 2120 document needs to impose restrictions on how the CBOR Encoder needs 2121 to work. We have managed to narrow it down to the following 2122 restrictions: 2124 * The restriction applies to the encoding of the Sig_structure, the 2125 Enc_structure, and the MAC_structure. 2127 * Encoding MUST be done using definite lengths and values MUST be 2128 the minimum possible length. This means that the integer 1 is 2129 encoded as "0x01" and not "0x1801". 2131 * Applications MUST NOT generate messages with the same label used 2132 twice as a key in a single map. Applications MUST NOT parse and 2133 process messages with the same label used twice as a key in a 2134 single map. Applications can enforce the parse and process 2135 requirement by using parsers that will fail the parse step or by 2136 using parsers that will pass all keys to the application, and the 2137 application can perform the check for duplicate keys. 2139 11. Application Profiling Considerations 2141 This document is designed to provide a set of security services, but 2142 not impose algorithm implementation requirements for specific usage. 2143 The interoperability requirements are provided for how each of the 2144 individual services are used and how the algorithms are to be used 2145 for interoperability. The requirements about which algorithms and 2146 which services are needed are deferred to each application. 2148 An example of a profile can be found in [RFC8613] where one was 2149 developed for carrying content in combination with CoAP headers. 2151 It is intended that a profile of this document be created that 2152 defines the interoperability requirements for that specific 2153 application. This section provides a set of guidelines and topics 2154 that need to be considered when profiling this document. 2156 * Applications need to determine the set of messages defined in this 2157 document that they will be using. The set of messages corresponds 2158 fairly directly to the set of security services that are needed 2159 and to the security levels needed. 2161 * Applications may define new header parameters for a specific 2162 purpose. Applications will often times select specific header 2163 parameters to use or not to use. For example, an application 2164 would normally state a preference for using either the IV or the 2165 Partial IV header parameter. If the Partial IV header parameter 2166 is specified, then the application also needs to define how the 2167 fixed portion of the IV is determined. 2169 * When applications use externally defined authenticated data, they 2170 need to define how that data is encoded. This document assumes 2171 that the data will be provided as a byte string. More information 2172 can be found in Section 4.3. 2174 * Applications need to determine the set of security algorithms that 2175 are to be used. When selecting the algorithms to be used as the 2176 mandatory-to-implement set, consideration should be given to 2177 choosing different types of algorithms when two are chosen for a 2178 specific purpose. An example of this would be choosing HMAC- 2179 SHA512 and AES-CMAC as different MAC algorithms; the construction 2180 is vastly different between these two algorithms. This means that 2181 a weakening of one algorithm would be unlikely to lead to a 2182 weakening of the other algorithms. Of course, these algorithms do 2183 not provide the same level of security and thus may not be 2184 comparable for the desired security functionality. 2186 * Applications may need to provide some type of negotiation or 2187 discovery method if multiple algorithms or message structures are 2188 permitted. The method can be as simple as requiring pre- 2189 configuration of the set of algorithms to providing a discovery 2190 method built into the protocol. S/MIME provided a number of 2191 different ways to approach the problem that applications could 2192 follow: 2194 - Advertising in the message (S/MIME capabilities) [RFC5751]. 2196 - Advertising in the certificate (capabilities extension) 2197 [RFC4262]. 2199 - Minimum requirements for the S/MIME, which have been updated 2200 over time [RFC2633] [RFC5751] (note that [RFC2633] has been 2201 obsoleted by [RFC5751]). 2203 12. IANA Considerations 2205 The registries and registrations listed below were created during 2206 processing of RFC 8152 [RFC8152]. The only known action at this time 2207 is to update the references. 2209 12.1. CBOR Tag Assignment 2211 IANA assigned tags in the "CBOR Tags" registry as part of processing 2212 [RFC8152]. IANA is requested to update the references from [RFC8152] 2213 to this document. 2215 IANA is requested to register a new tag for the CounterSignature 2216 type. 2218 * Tag: TBD0 2220 * Data Item: COSE_Signature 2222 * Semantics: COSE standalone counter signature 2224 * Reference: [[this document]] 2226 12.2. COSE Header Parameters Registry 2228 IANA created a registry titled "COSE Header Parameters" as part of 2229 processing [RFC8152]. The registry has been created to use the 2230 "Expert Review Required" registration procedure [RFC8126]. 2232 IANA is requested to update the reference for entries in the table 2233 from [RFC8152] to this document. This document does not update the 2234 expert review guidelines provided in [RFC8152]. 2236 12.3. COSE Header Algorithm Parameters Registry 2238 IANA created a registry titled "COSE Header Algorithm Parameters" as 2239 part of processing [RFC8152]. The registry has been created to use 2240 the "Expert Review Required" registration procedure [RFC8126]. 2242 IANA is requested to update the references from [RFC8152] to this 2243 document. This document does not update the expert review guidelines 2244 provided in [RFC8152]. 2246 12.4. COSE Key Common Parameters Registry 2248 IANA created a registry titled "COSE Key Common Parameters" as part 2249 of the processing of [RFC8152]. The registry has been created to use 2250 the "Expert Review Required" registration procedure [RFC8126]. 2252 IANA is requested to update the reference for entries in the table 2253 from [RFC8152] to this document. This document does not update the 2254 expert review guidelines provided in [RFC8152]. 2256 12.5. Media Type Registrations 2258 12.5.1. COSE Security Message 2260 This section registers the 'application/cose' media type in the 2261 "Media Types" registry. These media types are used to indicate that 2262 the content is a COSE message. 2264 Type name: application 2266 Subtype name: cose 2268 Required parameters: N/A 2270 Optional parameters: cose-type 2272 Encoding considerations: binary 2274 Security considerations: See the Security Considerations section 2275 of [[This Document]]. 2277 Interoperability considerations: N/A 2279 Published specification: [[this document]] 2281 Applications that use this media type: IoT applications sending 2282 security content over HTTP(S) transports. 2284 Fragment identifier considerations: N/A 2286 Additional information: 2288 - Deprecated alias names for this type: N/A 2290 - Magic number(s): N/A 2292 - File extension(s): cbor 2294 - Macintosh file type code(s): N/A 2296 Person & email address to contact for further information: 2297 iesg@ietf.org 2299 Intended usage: COMMON 2300 Restrictions on usage: N/A 2302 Author: Jim Schaad, ietf@augustcellars.com 2304 Change Controller: IESG 2306 Provisional registration? No 2308 12.5.2. COSE Key Media Type 2310 This section registers the 'application/cose-key' and 'application/ 2311 cose-key-set' media types in the "Media Types" registry. These media 2312 types are used to indicate, respectively, that content is a COSE_Key 2313 or COSE_KeySet object. 2315 The template for registering 'application/cose-key' is: 2317 Type name: application 2319 Subtype name: cose-key 2321 Required parameters: N/A 2323 Optional parameters: N/A 2325 Encoding considerations: binary 2327 Security considerations: See the Security Considerations section 2328 of [[This Document]]. 2330 Interoperability considerations: N/A 2332 Published specification: [[this document]] 2334 Applications that use this media type: Distribution of COSE based 2335 keys for IoT applications. 2337 Fragment identifier considerations: N/A 2339 Additional information: 2341 - Deprecated alias names for this type: N/A 2343 - Magic number(s): N/A 2345 - File extension(s): cbor 2347 - Macintosh file type code(s): N/A 2348 Person & email address to contact for further information: 2349 iesg@ietf.org 2351 Intended usage: COMMON 2353 Restrictions on usage: N/A 2355 Author: Jim Schaad, ietf@augustcellars.com 2357 Change Controller: IESG 2359 Provisional registration? No 2361 The template for registering 'application/cose-key-set' is: 2363 Type name: application 2365 Subtype name: cose-key-set 2367 Required parameters: N/A 2369 Optional parameters: N/A 2371 Encoding considerations: binary 2373 Security considerations: See the Security Considerations section 2374 of [[This Document]]. 2376 Interoperability considerations: N/A 2378 Published specification: [[this document]] 2380 Applications that use this media type: Distribution of COSE based 2381 keys for IoT applications. 2383 Fragment identifier considerations: N/A 2385 Additional information: 2387 - Deprecated alias names for this type: N/A 2389 - Magic number(s): N/A 2391 - File extension(s): cbor 2393 - Macintosh file type code(s): N/A 2394 Person & email address to contact for further information: 2395 iesg@ietf.org 2397 Intended usage: COMMON 2399 Restrictions on usage: N/A 2401 Author: Jim Schaad, ietf@augustcellars.com 2403 Change Controller: IESG 2405 Provisional registration? No 2407 12.6. CoAP Content-Formats Registry 2409 IANA added the following entries to the "CoAP Content-Formats" 2410 registry while processing [RFC8152]. IANA is requested to update the 2411 reference value from [RFC8152] to [[This Document]]. 2413 13. Security Considerations 2415 There are a number of security considerations that need to be taken 2416 into account by implementers of this specification. The security 2417 considerations that are specific to an individual algorithm are 2418 placed next to the description of the algorithm. While some 2419 considerations have been highlighted here, additional considerations 2420 may be found in the documents listed in the references. 2422 Implementations need to protect the private key material for any 2423 individuals. There are some cases that need to be highlighted on 2424 this issue. 2426 * Using the same key for two different algorithms can leak 2427 information about the key. It is therefore recommended that keys 2428 be restricted to a single algorithm. 2430 * Use of 'direct' as a recipient algorithm combined with a second 2431 recipient algorithm exposes the direct key to the second 2432 recipient. 2434 * Several of the algorithms in [I-D.ietf-cose-rfc8152bis-algs] have 2435 limits on the number of times that a key can be used without 2436 leaking information about the key. 2438 The use of ECDH and direct plus KDF (with no key wrap) will not 2439 directly lead to the private key being leaked; the one way function 2440 of the KDF will prevent that. There is, however, a different issue 2441 that needs to be addressed. Having two recipients requires that the 2442 CEK be shared between two recipients. The second recipient therefore 2443 has a CEK that was derived from material that can be used for the 2444 weak proof of origin. The second recipient could create a message 2445 using the same CEK and send it to the first recipient; the first 2446 recipient would, for either static-static ECDH or direct plus KDF, 2447 make an assumption that the CEK could be used for proof of origin 2448 even though it is from the wrong entity. If the key wrap step is 2449 added, then no proof of origin is implied and this is not an issue. 2451 Although it has been mentioned before, the use of a single key for 2452 multiple algorithms has been demonstrated in some cases to leak 2453 information about that key, provide the opportunity for attackers to 2454 forge integrity tags, or gain information about encrypted content. 2455 Binding a key to a single algorithm prevents these problems. Key 2456 creators and key consumers are strongly encouraged not only to create 2457 new keys for each different algorithm, but to include that selection 2458 of algorithm in any distribution of key material and strictly enforce 2459 the matching of algorithms in the key structure to algorithms in the 2460 message structure. In addition to checking that algorithms are 2461 correct, the key form needs to be checked as well. Do not use an 2462 'EC2' key where an 'OKP' key is expected. 2464 Before using a key for transmission, or before acting on information 2465 received, a trust decision on a key needs to be made. Is the data or 2466 action something that the entity associated with the key has a right 2467 to see or a right to request? A number of factors are associated 2468 with this trust decision. Some of the ones that are highlighted here 2469 are: 2471 * What are the permissions associated with the key owner? 2473 * Is the cryptographic algorithm acceptable in the current context? 2475 * Have the restrictions associated with the key, such as algorithm 2476 or freshness, been checked and are they correct? 2478 * Is the request something that is reasonable, given the current 2479 state of the application? 2481 * Have any security considerations that are part of the message been 2482 enforced (as specified by the application or 'crit' header 2483 parameter)? 2485 There are a large number of algorithms presented in 2486 [I-D.ietf-cose-rfc8152bis-algs] that use nonce values. Nonces 2487 generally have some type of restriction on their values. Generally a 2488 nonce needs to be a unique value either for a key or for some other 2489 conditions. In all of these cases, there is no known requirement on 2490 the nonce being both unique and unpredictable; under these 2491 circumstances, it's reasonable to use a counter for creation of the 2492 nonce. In cases where one wants the pattern of the nonce to be 2493 unpredictable as well as unique, one can use a key created for that 2494 purpose and encrypt the counter to produce the nonce value. 2496 One area that has been starting to get exposure is doing traffic 2497 analysis of encrypted messages based on the length of the message. 2498 This specification does not provide for a uniform method of providing 2499 padding as part of the message structure. An observer can 2500 distinguish between two different messages (for example, 'YES' and 2501 'NO') based on the length for all of the content encryption 2502 algorithms that are defined in [I-D.ietf-cose-rfc8152bis-algs] 2503 document. This means that it is up to the applications to document 2504 how content padding is to be done in order to prevent or discourage 2505 such analysis. (For example, the text strings could be defined as 2506 'YES' and 'NO '.) 2508 14. Implementation Status 2510 This section is to be removed before publishing as an RFC. 2512 This section records the status of known implementations of the 2513 protocol defined by this specification at the time of posting of this 2514 Internet-Draft, and is based on a proposal described in [RFC7942]. 2515 The description of implementations in this section is intended to 2516 assist the IETF in its decision processes in progressing drafts to 2517 RFCs. Please note that the listing of any individual implementation 2518 here does not imply endorsement by the IETF. Furthermore, no effort 2519 has been spent to verify the information presented here that was 2520 supplied by IETF contributors. This is not intended as, and must not 2521 be construed to be, a catalog of available implementations or their 2522 features. Readers are advised to note that other implementations may 2523 exist. 2525 According to [RFC7942], "this will allow reviewers and working groups 2526 to assign due consideration to documents that have the benefit of 2527 running code, which may serve as evidence of valuable experimentation 2528 and feedback that have made the implemented protocols more mature. 2529 It is up to the individual working groups to use this information as 2530 they see fit". 2532 14.1. Author's Versions 2534 There are three different implementations that have been created by 2535 the author of the document both to create the examples that are 2536 included in the document and to validate the structures and 2537 methodology used in the design of COSE. 2539 * Implementation Location: https://github.com/cose-wg 2541 * Primary Maintainer: Jim Schaad 2543 * Languages: There are three different languages that are currently 2544 supported: Java, C# and C. 2546 * Cryptography: The Java and C# libraries use Bouncy Castle to 2547 provide the required cryptography. The C version uses OPENSSL 2548 Version 1.0 for the cryptography. 2550 * Coverage: The C version currently does not have full countersign 2551 support. The other two versions do. They do have support to 2552 allow for implicit algorithm support as they allow for the 2553 application to set attributes that are not to be sent in the 2554 message. 2556 * Testing: All of the examples in the example library are generated 2557 by the C# library and then validated using the Java and C 2558 libraries. All three libraries have tests to allow for the 2559 creating of the same messages that are in the example library 2560 followed by validating them. These are not compared against the 2561 example library. The Java and C# libraries have unit testing 2562 included. Not all of the MUST statements in the document have 2563 been implemented as part of the libraries. One such statement is 2564 the requirement that unique labels be present. 2566 * Licensing: Revised BSD License 2568 14.2. JavaScript Version 2570 * Implementation Location: https://github.com/erdtman/cose-js 2572 * Primary Maintainer: Samuel Erdtman 2574 * Languages: JavaScript 2576 * Cryptography: TBD 2578 * Coverage: Full Encrypt, Signature and MAC objects are supported. 2580 * Testing: Basic testing against the common example library. 2582 * Licensing: Apache License 2.0 2584 14.3. Python Version 2585 * Implementation Location: https://github.com/TimothyClaeys/COSE- 2586 PYTHON 2588 * Primary Maintainer: Timothy Claeys 2590 * Languages: Python 2592 * Cryptography: pyecdsak, crypto python libraries 2594 * Coverage: TBD 2596 * Testing: Basic testing plus running against the common example 2597 library. 2599 * Licensing: BSD 3-Clause License 2601 14.4. COSE Testing Library 2603 * Implementation Location: https://github.com/cose-wg/Examples 2605 * Primary Maintainer: Jim Schaad 2607 * Description: A set of tests for the COSE library is provided as 2608 part of the implementation effort. Both success and fail tests 2609 have been provided. All of the examples in this document are part 2610 of this example set. 2612 * Coverage: An attempt has been made to have test cases for every 2613 message type and algorithm in the document. Currently examples 2614 dealing with counter signatures, and ECDH with Curve24459 and 2615 Goldilocks are missing. 2617 * Licensing: Public Domain 2619 15. References 2621 15.1. Normative References 2623 [COAP.Formats] 2624 IANA, "CoAP Content-Formats", 2625 . 2628 [COSE.Algorithms] 2629 IANA, "COSE Algorithms", 2630 . 2633 [COSE.KeyParameters] 2634 IANA, "COSE Key Parameters", 2635 . 2638 [COSE.KeyTypes] 2639 IANA, "COSE Key Types", 2640 . 2643 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2644 Requirement Levels", BCP 14, RFC 2119, 2645 DOI 10.17487/RFC2119, March 1997, 2646 . 2648 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 2649 Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, 2650 October 2013, . 2652 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2653 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 2654 May 2017, . 2656 [DSS] National Institute of Standards and Technology, "Digital 2657 Signature Standard (DSS)", DOI 10.6028/NIST.FIPS.186-4, 2658 FIPS PUB 186-4, July 2013, 2659 . 2662 [RFC8032] Josefsson, S. and I. Liusvaara, "Edwards-Curve Digital 2663 Signature Algorithm (EdDSA)", RFC 8032, 2664 DOI 10.17487/RFC8032, January 2017, 2665 . 2667 [I-D.ietf-cose-rfc8152bis-algs] 2668 Schaad, J., "CBOR Object Signing and Encryption (COSE): 2669 Initial Algorithms", Work in Progress, Internet-Draft, 2670 draft-ietf-cose-rfc8152bis-algs-06, 4 November 2019, 2671 . 2674 15.2. Informative References 2676 [RFC8152] Schaad, J., "CBOR Object Signing and Encryption (COSE)", 2677 RFC 8152, DOI 10.17487/RFC8152, July 2017, 2678 . 2680 [RFC8610] Birkholz, H., Vigano, C., and C. Bormann, "Concise Data 2681 Definition Language (CDDL): A Notational Convention to 2682 Express Concise Binary Object Representation (CBOR) and 2683 JSON Data Structures", RFC 8610, DOI 10.17487/RFC8610, 2684 June 2019, . 2686 [RFC8018] Moriarty, K., Ed., Kaliski, B., and A. Rusch, "PKCS #5: 2687 Password-Based Cryptography Specification Version 2.1", 2688 RFC 8018, DOI 10.17487/RFC8018, January 2017, 2689 . 2691 [RFC2633] Ramsdell, B., Ed., "S/MIME Version 3 Message 2692 Specification", RFC 2633, DOI 10.17487/RFC2633, June 1999, 2693 . 2695 [RFC4262] Santesson, S., "X.509 Certificate Extension for Secure/ 2696 Multipurpose Internet Mail Extensions (S/MIME) 2697 Capabilities", RFC 4262, DOI 10.17487/RFC4262, December 2698 2005, . 2700 [RFC4949] Shirey, R., "Internet Security Glossary, Version 2", 2701 FYI 36, RFC 4949, DOI 10.17487/RFC4949, August 2007, 2702 . 2704 [RFC5116] McGrew, D., "An Interface and Algorithms for Authenticated 2705 Encryption", RFC 5116, DOI 10.17487/RFC5116, January 2008, 2706 . 2708 [RFC5652] Housley, R., "Cryptographic Message Syntax (CMS)", STD 70, 2709 RFC 5652, DOI 10.17487/RFC5652, September 2009, 2710 . 2712 [RFC5751] Ramsdell, B. and S. Turner, "Secure/Multipurpose Internet 2713 Mail Extensions (S/MIME) Version 3.2 Message 2714 Specification", RFC 5751, DOI 10.17487/RFC5751, January 2715 2010, . 2717 [RFC5752] Turner, S. and J. Schaad, "Multiple Signatures in 2718 Cryptographic Message Syntax (CMS)", RFC 5752, 2719 DOI 10.17487/RFC5752, January 2010, 2720 . 2722 [RFC5990] Randall, J., Kaliski, B., Brainard, J., and S. Turner, 2723 "Use of the RSA-KEM Key Transport Algorithm in the 2724 Cryptographic Message Syntax (CMS)", RFC 5990, 2725 DOI 10.17487/RFC5990, September 2010, 2726 . 2728 [RFC6838] Freed, N., Klensin, J., and T. Hansen, "Media Type 2729 Specifications and Registration Procedures", BCP 13, 2730 RFC 6838, DOI 10.17487/RFC6838, January 2013, 2731 . 2733 [RFC8259] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 2734 Interchange Format", STD 90, RFC 8259, 2735 DOI 10.17487/RFC8259, December 2017, 2736 . 2738 [RFC7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 2739 Application Protocol (CoAP)", RFC 7252, 2740 DOI 10.17487/RFC7252, June 2014, 2741 . 2743 [RFC7515] Jones, M., Bradley, J., and N. Sakimura, "JSON Web 2744 Signature (JWS)", RFC 7515, DOI 10.17487/RFC7515, May 2745 2015, . 2747 [RFC7516] Jones, M. and J. Hildebrand, "JSON Web Encryption (JWE)", 2748 RFC 7516, DOI 10.17487/RFC7516, May 2015, 2749 . 2751 [RFC7517] Jones, M., "JSON Web Key (JWK)", RFC 7517, 2752 DOI 10.17487/RFC7517, May 2015, 2753 . 2755 [RFC7518] Jones, M., "JSON Web Algorithms (JWA)", RFC 7518, 2756 DOI 10.17487/RFC7518, May 2015, 2757 . 2759 [RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for 2760 Writing an IANA Considerations Section in RFCs", BCP 26, 2761 RFC 8126, DOI 10.17487/RFC8126, June 2017, 2762 . 2764 [PVSig] Brown, D. and D. Johnson, "Formal Security Proofs for a 2765 Signature Scheme with Partial Message Recovery", 2766 DOI 10.1007/3-540-45353-9_11, LNCS Volume 2020, June 2000, 2767 . 2769 [W3C.WebCrypto] 2770 Watson, M., "Web Cryptography API", W3C Recommendation, 2771 January 2017, . 2773 [RFC8613] Selander, G., Mattsson, J., Palombini, F., and L. Seitz, 2774 "Object Security for Constrained RESTful Environments 2775 (OSCORE)", RFC 8613, DOI 10.17487/RFC8613, July 2019, 2776 . 2778 [RFC8230] Jones, M., "Using RSA Algorithms with CBOR Object Signing 2779 and Encryption (COSE) Messages", RFC 8230, 2780 DOI 10.17487/RFC8230, September 2017, 2781 . 2783 [RFC7942] Sheffer, Y. and A. Farrel, "Improving Awareness of Running 2784 Code: The Implementation Status Section", BCP 205, 2785 RFC 7942, DOI 10.17487/RFC7942, July 2016, 2786 . 2788 [RFC4998] Gondrom, T., Brandner, R., and U. Pordesch, "Evidence 2789 Record Syntax (ERS)", RFC 4998, DOI 10.17487/RFC4998, 2790 August 2007, . 2792 Appendix A. Guidelines for External Data Authentication of Algorithms 2794 During development of COSE, the requirement that the algorithm 2795 identifier be located in the protected attributes was relaxed from a 2796 must to a should. There were two basic reasons that have been 2797 advanced to support this position. First, the resulting message will 2798 be smaller if the algorithm identifier is omitted from the most 2799 common messages in a CoAP environment. Second, there is a potential 2800 bug that will arise if full checking is not done correctly between 2801 the different places that an algorithm identifier could be placed 2802 (the message itself, an application statement, the key structure that 2803 the sender possesses, and the key structure the recipient possesses). 2805 This appendix lays out how such a change can be made and the details 2806 that an application needs to specify in order to use this option. 2807 Two different sets of details are specified: those needed to omit an 2808 algorithm identifier and those needed to use a variant on the counter 2809 signature attribute that contains no attributes about itself. 2811 Three sets of recommendations are laid out. The first set of 2812 recommendations apply to having an implicit algorithm identified for 2813 a single layer of a COSE object. The second set of recommendations 2814 apply to having multiple implicit algorithms identified for multiple 2815 layers of a COSE object. The third set of recommendations apply to 2816 having implicit algorithms for multiple COSE object constructs. 2818 The key words from [RFC2119] are deliberately not used here. This 2819 specification can provide recommendations, but it cannot enforce 2820 them. 2822 This set of recommendations applies to the case where an application 2823 is distributing a fixed algorithm along with the key information for 2824 use in a single COSE object. This normally applies to the smallest 2825 of the COSE objects, specifically COSE_Sign1, COSE_Mac0, and 2826 COSE_Encrypt0, but could apply to the other structures as well. 2828 The following items should be taken into account: 2830 * Applications need to list the set of COSE structures that implicit 2831 algorithms are to be used in. Applications need to require that 2832 the receipt of an explicit algorithm identifier in one of these 2833 structures will lead to the message being rejected. This 2834 requirement is stated so that there will never be a case where 2835 there is any ambiguity about the question of which algorithm 2836 should be used, the implicit or the explicit one. This applies 2837 even if the transported algorithm identifier is a protected 2838 attribute. This applies even if the transported algorithm is the 2839 same as the implicit algorithm. 2841 * Applications need to define the set of information that is to be 2842 considered to be part of a context when omitting algorithm 2843 identifiers. At a minimum, this would be the key identifier (if 2844 needed), the key, the algorithm, and the COSE structure it is used 2845 with. Applications should restrict the use of a single key to a 2846 single algorithm. As noted for some of the algorithms in 2847 [I-D.ietf-cose-rfc8152bis-algs], the use of the same key in 2848 different related algorithms can lead to leakage of information 2849 about the key, leakage about the data or the ability to perform 2850 forgeries. 2852 * In many cases, applications that make the algorithm identifier 2853 implicit will also want to make the context identifier implicit 2854 for the same reason. That is, omitting the context identifier 2855 will decrease the message size (potentially significantly 2856 depending on the length of the identifier). Applications that do 2857 this will need to describe the circumstances where the context 2858 identifier is to be omitted and how the context identifier is to 2859 be inferred in these cases. (An exhaustive search over all of the 2860 keys would normally not be considered to be acceptable.) An 2861 example of how this can be done is to tie the context to a 2862 transaction identifier. Both would be sent on the original 2863 message, but only the transaction identifier would need to be sent 2864 after that point as the context is tied into the transaction 2865 identifier. Another way would be to associate a context with a 2866 network address. All messages coming from a single network 2867 address can be assumed to be associated with a specific context. 2868 (In this case, the address would normally be distributed as part 2869 of the context.) 2871 * Applications cannot rely on key identifiers being unique unless 2872 they take significant efforts to ensure that they are computed in 2873 such a way as to create this guarantee. Even when an application 2874 does this, the uniqueness might be violated if the application is 2875 run in different contexts (i.e., with a different context 2876 provider) or if the system combines the security contexts from 2877 different applications together into a single store. 2879 * Applications should continue the practice of protecting the 2880 algorithm identifier. Since this is not done by placing it in the 2881 protected attributes field, applications should define an 2882 application-specific external data structure that includes this 2883 value. This external data field can be used as such for content 2884 encryption, MAC, and signature algorithms. It can be used in the 2885 SuppPrivInfo field for those algorithms that use a KDF to derive a 2886 key value. Applications may also want to protect other 2887 information that is part of the context structure as well. It 2888 should be noted that those fields, such as the key or a Base IV, 2889 are protected by virtue of being used in the cryptographic 2890 computation and do not need to be included in the external data 2891 field. 2893 The second case is having multiple implicit algorithm identifiers 2894 specified for a multiple layer COSE object. An example of how this 2895 would work is the encryption context that an application specifies, 2896 which contains a content encryption algorithm, a key wrap algorithm, 2897 a key identifier, and a shared secret. The sender omits sending the 2898 algorithm identifier for both the content layer and the recipient 2899 layer leaving only the key identifier. The receiver then uses the 2900 key identifier to get the implicit algorithm identifiers. 2902 The following additional items need to be taken into consideration: 2904 * Applications that want to support this will need to define a 2905 structure that allows for, and clearly identifies, both the COSE 2906 structure to be used with a given key and the structure and 2907 algorithm to be used for the secondary layer. The key for the 2908 secondary layer is computed as normal from the recipient layer. 2910 The third case is having multiple implicit algorithm identifiers, but 2911 targeted at potentially unrelated layers or different COSE objects. 2912 There are a number of different scenarios where this might be 2913 applicable. Some of these scenarios are: 2915 * Two contexts are distributed as a pair. Each of the contexts is 2916 for use with a COSE_Encrypt message. Each context will consist of 2917 distinct secret keys and IVs and potentially even different 2918 algorithms. One context is for sending messages from party A to 2919 party B, and the second context is for sending messages from party 2920 B to party A. This means that there is no chance for a reflection 2921 attack to occur as each party uses different secret keys to send 2922 its messages; a message that is reflected back to it would fail to 2923 decrypt. 2925 * Two contexts are distributed as a pair. The first context is used 2926 for encryption of the message, and the second context is used to 2927 place a counter signature on the message. The intention is that 2928 the second context can be distributed to other entities 2929 independently of the first context. This allows these entities to 2930 validate that the message came from an individual without being 2931 able to decrypt the message and see the content. 2933 * Two contexts are distributed as a pair. The first context 2934 contains a key for dealing with MACed messages, and the second 2935 context contains a different key for dealing with encrypted 2936 messages. This allows for a unified distribution of keys to 2937 participants for different types of messages that have different 2938 keys, but where the keys may be used in a coordinated manner. 2940 For these cases, the following additional items need to be 2941 considered: 2943 * Applications need to ensure that the multiple contexts stay 2944 associated. If one of the contexts is invalidated for any reason, 2945 all of the contexts associated with it should also be invalidated. 2947 Appendix B. Two Layers of Recipient Information 2949 All of the currently defined recipient algorithm classes only use two 2950 layers of the COSE_Encrypt structure. The first layer is the message 2951 content, and the second layer is the content key encryption. 2952 However, if one uses a recipient algorithm such as the RSA Key 2953 Encapsulation Mechanism (RSA-KEM) (see Appendix A of RSA-KEM 2954 [RFC5990]), then it makes sense to have three layers of the 2955 COSE_Encrypt structure. 2957 These layers would be: 2959 * Layer 0: The content encryption layer. This layer contains the 2960 payload of the message. 2962 * Layer 1: The encryption of the CEK by a KEK. 2964 * Layer 2: The encryption of a long random secret using an RSA key 2965 and a key derivation function to convert that secret into the KEK. 2967 This is an example of what a triple layer message would look like. 2968 The message has the following layers: 2970 * Layer 0: Has a content encrypted with AES-GCM using a 128-bit key. 2972 * Layer 1: Uses the AES Key Wrap algorithm with a 128-bit key. 2974 * Layer 2: Uses ECDH Ephemeral-Static direct to generate the layer 1 2975 key. 2977 In effect, this example is a decomposed version of using the 2978 ECDH-ES+A128KW algorithm. 2980 Size of binary file is 183 bytes 2981 96( 2982 [ 2983 / protected / h'a10101' / { 2984 \ alg \ 1:1 \ AES-GCM 128 \ 2985 } / , 2986 / unprotected / { 2987 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 2988 }, 2989 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e2852948658f0 2990 811139868826e89218a75715b', 2991 / recipients / [ 2992 [ 2993 / protected / h'', 2994 / unprotected / { 2995 / alg / 1:-3 / A128KW / 2996 }, 2997 / ciphertext / h'dbd43c4e9d719c27c6275c67d628d493f090593db82 2998 18f11', 2999 / recipients / [ 3000 [ 3001 / protected / h'a1013818' / { 3002 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 3003 } / , 3004 / unprotected / { 3005 / ephemeral / -1:{ 3006 / kty / 1:2, 3007 / crv / -1:1, 3008 / x / -2:h'b2add44368ea6d641f9ca9af308b4079aeb519f11 3009 e9b8a55a600b21233e86e68', 3010 / y / -3:false 3011 }, 3012 / kid / 4:'meriadoc.brandybuck@buckland.example' 3013 }, 3014 / ciphertext / h'' 3015 ] 3016 ] 3017 ] 3018 ] 3019 ] 3020 ) 3022 Appendix C. Examples 3024 This appendix includes a set of examples that show the different 3025 features and message types that have been defined in this document. 3026 To make the examples easier to read, they are presented using the 3027 extended CBOR diagnostic notation (defined in [RFC8610]) rather than 3028 as a binary dump. 3030 A GitHub project has been created at that contains not only the examples presented in this 3032 document, but a more complete set of testing examples as well. Each 3033 example is found in a JSON file that contains the inputs used to 3034 create the example, some of the intermediate values that can be used 3035 in debugging the example and the output of the example presented both 3036 as a hex dump and in CBOR diagnostic notation format. Some of the 3037 examples at the site are designed failure testing cases; these are 3038 clearly marked as such in the JSON file. If errors in the examples 3039 in this document are found, the examples on GitHub will be updated, 3040 and a note to that effect will be placed in the JSON file. 3042 As noted, the examples are presented using the CBOR's diagnostic 3043 notation. A Ruby-based tool exists that can convert between the 3044 diagnostic notation and binary. This tool can be installed with the 3045 command line: 3047 gem install cbor-diag 3049 The diagnostic notation can be converted into binary files using the 3050 following command line: 3052 diag2cbor.rb < inputfile > outputfile 3054 The examples can be extracted from the XML version of this document 3055 via an XPath expression as all of the sourcecode is tagged with the 3056 attribute type='CBORdiag'. (Depending on the XPath evaluator one is 3057 using, it may be necessary to deal with > as an entity.) 3059 //sourcecode[@type='CDDL']/text() 3061 C.1. Examples of Signed Messages 3063 C.1.1. Single Signature 3065 This example uses the following: 3067 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3069 Size of binary file is 103 bytes 3070 98( 3071 [ 3072 / protected / h'', 3073 / unprotected / {}, 3074 / payload / 'This is the content.', 3075 / signatures / [ 3076 [ 3077 / protected / h'a10126' / { 3078 \ alg \ 1:-7 \ ECDSA 256 \ 3079 } / , 3080 / unprotected / { 3081 / kid / 4:'11' 3082 }, 3083 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3084 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3085 98f53afd2fa0f30a' 3086 ] 3087 ] 3088 ] 3089 ) 3091 C.1.2. Multiple Signers 3093 This example uses the following: 3095 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3097 * Signature Algorithm: ECDSA w/ SHA-512, Curve P-521 3099 Size of binary file is 277 bytes 3100 98( 3101 [ 3102 / protected / h'', 3103 / unprotected / {}, 3104 / payload / 'This is the content.', 3105 / signatures / [ 3106 [ 3107 / protected / h'a10126' / { 3108 \ alg \ 1:-7 \ ECDSA 256 \ 3109 } / , 3110 / unprotected / { 3111 / kid / 4:'11' 3112 }, 3113 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3114 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3115 98f53afd2fa0f30a' 3116 ], 3117 [ 3118 / protected / h'a1013823' / { 3119 \ alg \ 1:-36 3120 } / , 3121 / unprotected / { 3122 / kid / 4:'bilbo.baggins@hobbiton.example' 3123 }, 3124 / signature / h'00a2d28a7c2bdb1587877420f65adf7d0b9a06635dd1 3125 de64bb62974c863f0b160dd2163734034e6ac003b01e8705524c5c4ca479a952f024 3126 7ee8cb0b4fb7397ba08d009e0c8bf482270cc5771aa143966e5a469a09f613488030 3127 c5b07ec6d722e3835adb5b2d8c44e95ffb13877dd2582866883535de3bb03d01753f 3128 83ab87bb4f7a0297' 3129 ] 3130 ] 3131 ] 3132 ) 3134 C.1.3. Counter Signature 3136 This example uses the following: 3138 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3140 * The same header parameters are used for both the signature and the 3141 counter signature. 3143 Size of binary file is 180 bytes 3144 98( 3145 [ 3146 / protected / h'', 3147 / unprotected / { 3148 / countersign / 7:[ 3149 / protected / h'a10126' / { 3150 \ alg \ 1:-7 \ ECDSA 256 \ 3151 } / , 3152 / unprotected / { 3153 / kid / 4:'11' 3154 }, 3155 / signature / h'5ac05e289d5d0e1b0a7f048a5d2b643813ded50bc9e4 3156 9220f4f7278f85f19d4a77d655c9d3b51e805a74b099e1e085aacd97fc29d72f887e 3157 8802bb6650cceb2c' 3158 ] 3159 }, 3160 / payload / 'This is the content.', 3161 / signatures / [ 3162 [ 3163 / protected / h'a10126' / { 3164 \ alg \ 1:-7 \ ECDSA 256 \ 3165 } / , 3166 / unprotected / { 3167 / kid / 4:'11' 3168 }, 3169 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3170 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3171 98f53afd2fa0f30a' 3172 ] 3173 ] 3174 ] 3175 ) 3177 C.1.4. Signature with Criticality 3179 This example uses the following: 3181 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3183 * There is a criticality marker on the "reserved" header parameter 3185 Size of binary file is 125 bytes 3186 98( 3187 [ 3188 / protected / h'a2687265736572766564f40281687265736572766564' / 3189 { 3190 "reserved":false, 3191 \ crit \ 2:[ 3192 "reserved" 3193 ] 3194 } / , 3195 / unprotected / {}, 3196 / payload / 'This is the content.', 3197 / signatures / [ 3198 [ 3199 / protected / h'a10126' / { 3200 \ alg \ 1:-7 \ ECDSA 256 \ 3201 } / , 3202 / unprotected / { 3203 / kid / 4:'11' 3204 }, 3205 / signature / h'3fc54702aa56e1b2cb20284294c9106a63f91bac658d 3206 69351210a031d8fc7c5ff3e4be39445b1a3e83e1510d1aca2f2e8a7c081c7645042b 3207 18aba9d1fad1bd9c' 3208 ] 3209 ] 3210 ] 3211 ) 3213 C.2. Single Signer Examples 3215 C.2.1. Single ECDSA Signature 3217 This example uses the following: 3219 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3221 Size of binary file is 98 bytes 3222 18( 3223 [ 3224 / protected / h'a10126' / { 3225 \ alg \ 1:-7 \ ECDSA 256 \ 3226 } / , 3227 / unprotected / { 3228 / kid / 4:'11' 3229 }, 3230 / payload / 'This is the content.', 3231 / signature / h'8eb33e4ca31d1c465ab05aac34cc6b23d58fef5c083106c4 3232 d25a91aef0b0117e2af9a291aa32e14ab834dc56ed2a223444547e01f11d3b0916e5 3233 a4c345cacb36' 3234 ] 3235 ) 3237 C.3. Examples of Enveloped Messages 3239 C.3.1. Direct ECDH 3241 This example uses the following: 3243 * CEK: AES-GCM w/ 128-bit key 3245 * Recipient class: ECDH Ephemeral-Static, Curve P-256 3247 Size of binary file is 151 bytes 3248 96( 3249 [ 3250 / protected / h'a10101' / { 3251 \ alg \ 1:1 \ AES-GCM 128 \ 3252 } / , 3253 / unprotected / { 3254 / iv / 5:h'c9cf4df2fe6c632bf7886413' 3255 }, 3256 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 3257 c52a357da7a644b8070a151b0', 3258 / recipients / [ 3259 [ 3260 / protected / h'a1013818' / { 3261 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 3262 } / , 3263 / unprotected / { 3264 / ephemeral / -1:{ 3265 / kty / 1:2, 3266 / crv / -1:1, 3267 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 3268 bf054e1c7b4d91d6280', 3269 / y / -3:true 3270 }, 3271 / kid / 4:'meriadoc.brandybuck@buckland.example' 3272 }, 3273 / ciphertext / h'' 3274 ] 3275 ] 3276 ] 3277 ) 3279 C.3.2. Direct Plus Key Derivation 3281 This example uses the following: 3283 * CEK: AES-CCM w/ 128-bit key, truncate the tag to 64 bits 3285 * Recipient class: Use HKDF on a shared secret with the following 3286 implicit fields as part of the context. 3288 - salt: "aabbccddeeffgghh" 3290 - PartyU identity: "lighting-client" 3292 - PartyV identity: "lighting-server" 3294 - Supplementary Public Other: "Encryption Example 02" 3296 Size of binary file is 91 bytes 3298 96( 3299 [ 3300 / protected / h'a1010a' / { 3301 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3302 } / , 3303 / unprotected / { 3304 / iv / 5:h'89f52f65a1c580933b5261a76c' 3305 }, 3306 / ciphertext / h'753548a19b1307084ca7b2056924ed95f2e3b17006dfe93 3307 1b687b847', 3308 / recipients / [ 3309 [ 3310 / protected / h'a10129' / { 3311 \ alg \ 1:-10 3312 } / , 3313 / unprotected / { 3314 / salt / -20:'aabbccddeeffgghh', 3315 / kid / 4:'our-secret' 3316 }, 3317 / ciphertext / h'' 3318 ] 3319 ] 3320 ] 3321 ) 3323 C.3.3. Counter Signature on Encrypted Content 3325 This example uses the following: 3327 * CEK: AES-GCM w/ 128-bit key 3329 * Recipient class: ECDH Ephemeral-Static, Curve P-256 3331 Size of binary file is 326 bytes 3332 96( 3333 [ 3334 / protected / h'a10101' / { 3335 \ alg \ 1:1 \ AES-GCM 128 \ 3336 } / , 3337 / unprotected / { 3338 / iv / 5:h'c9cf4df2fe6c632bf7886413', 3339 / countersign / 7:[ 3340 / protected / h'a1013823' / { 3341 \ alg \ 1:-36 3342 } / , 3343 / unprotected / { 3344 / kid / 4:'bilbo.baggins@hobbiton.example' 3345 }, 3346 / signature / h'00929663c8789bb28177ae28467e66377da12302d7f9 3347 594d2999afa5dfa531294f8896f2b6cdf1740014f4c7f1a358e3a6cf57f4ed6fb02f 3348 cf8f7aa989f5dfd07f0700a3a7d8f3c604ba70fa9411bd10c2591b483e1d2c31de00 3349 3183e434d8fba18f17a4c7e3dfa003ac1cf3d30d44d2533c4989d3ac38c38b71481c 3350 c3430c9d65e7ddff' 3351 ] 3352 }, 3353 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 3354 c52a357da7a644b8070a151b0', 3355 / recipients / [ 3356 [ 3357 / protected / h'a1013818' / { 3358 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 3359 } / , 3360 / unprotected / { 3361 / ephemeral / -1:{ 3362 / kty / 1:2, 3363 / crv / -1:1, 3364 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 3365 bf054e1c7b4d91d6280', 3366 / y / -3:true 3367 }, 3368 / kid / 4:'meriadoc.brandybuck@buckland.example' 3369 }, 3370 / ciphertext / h'' 3371 ] 3372 ] 3373 ] 3374 ) 3376 C.3.4. Encrypted Content with External Data 3378 This example uses the following: 3380 * CEK: AES-GCM w/ 128-bit key 3382 * Recipient class: ECDH static-Static, Curve P-256 with AES Key Wrap 3384 * Externally Supplied AAD: h'0011bbcc22dd44ee55ff660077' 3386 Size of binary file is 173 bytes 3388 96( 3389 [ 3390 / protected / h'a10101' / { 3391 \ alg \ 1:1 \ AES-GCM 128 \ 3392 } / , 3393 / unprotected / { 3394 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 3395 }, 3396 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e28529d8f5335 3397 e5f0165eee976b4a5f6c6f09d', 3398 / recipients / [ 3399 [ 3400 / protected / h'a101381f' / { 3401 \ alg \ 1:-32 \ ECHD-SS+A128KW \ 3402 } / , 3403 / unprotected / { 3404 / static kid / -3:'peregrin.took@tuckborough.example', 3405 / kid / 4:'meriadoc.brandybuck@buckland.example', 3406 / U nonce / -22:h'0101' 3407 }, 3408 / ciphertext / h'41e0d76f579dbd0d936a662d54d8582037de2e366fd 3409 e1c62' 3410 ] 3411 ] 3412 ] 3413 ) 3415 C.4. Examples of Encrypted Messages 3417 C.4.1. Simple Encrypted Message 3419 This example uses the following: 3421 * CEK: AES-CCM w/ 128-bit key and a 64-bit tag 3423 Size of binary file is 52 bytes 3424 16( 3425 [ 3426 / protected / h'a1010a' / { 3427 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3428 } / , 3429 / unprotected / { 3430 / iv / 5:h'89f52f65a1c580933b5261a78c' 3431 }, 3432 / ciphertext / h'5974e1b99a3a4cc09a659aa2e9e7fff161d38ce71cb45ce 3433 460ffb569' 3434 ] 3435 ) 3437 C.4.2. Encrypted Message with a Partial IV 3439 This example uses the following: 3441 * CEK: AES-CCM w/ 128-bit key and a 64-bit tag 3443 * Prefix for IV is 89F52F65A1C580933B52 3445 Size of binary file is 41 bytes 3447 16( 3448 [ 3449 / protected / h'a1010a' / { 3450 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3451 } / , 3452 / unprotected / { 3453 / partial iv / 6:h'61a7' 3454 }, 3455 / ciphertext / h'252a8911d465c125b6764739700f0141ed09192de139e05 3456 3bd09abca' 3457 ] 3458 ) 3460 C.5. Examples of MACed Messages 3462 C.5.1. Shared Secret Direct MAC 3464 This example uses the following: 3466 * MAC: AES-CMAC, 256-bit key, truncated to 64 bits 3468 * Recipient class: direct shared secret 3470 Size of binary file is 57 bytes 3471 97( 3472 [ 3473 / protected / h'a1010f' / { 3474 \ alg \ 1:15 \ AES-CBC-MAC-256//64 \ 3475 } / , 3476 / unprotected / {}, 3477 / payload / 'This is the content.', 3478 / tag / h'9e1226ba1f81b848', 3479 / recipients / [ 3480 [ 3481 / protected / h'', 3482 / unprotected / { 3483 / alg / 1:-6 / direct /, 3484 / kid / 4:'our-secret' 3485 }, 3486 / ciphertext / h'' 3487 ] 3488 ] 3489 ] 3490 ) 3492 C.5.2. ECDH Direct MAC 3494 This example uses the following: 3496 * MAC: HMAC w/SHA-256, 256-bit key 3498 * Recipient class: ECDH key agreement, two static keys, HKDF w/ 3499 context structure 3501 Size of binary file is 214 bytes 3502 97( 3503 [ 3504 / protected / h'a10105' / { 3505 \ alg \ 1:5 \ HMAC 256//256 \ 3506 } / , 3507 / unprotected / {}, 3508 / payload / 'This is the content.', 3509 / tag / h'81a03448acd3d305376eaa11fb3fe416a955be2cbe7ec96f012c99 3510 4bc3f16a41', 3511 / recipients / [ 3512 [ 3513 / protected / h'a101381a' / { 3514 \ alg \ 1:-27 \ ECDH-SS + HKDF-256 \ 3515 } / , 3516 / unprotected / { 3517 / static kid / -3:'peregrin.took@tuckborough.example', 3518 / kid / 4:'meriadoc.brandybuck@buckland.example', 3519 / U nonce / -22:h'4d8553e7e74f3c6a3a9dd3ef286a8195cbf8a23d 3520 19558ccfec7d34b824f42d92bd06bd2c7f0271f0214e141fb779ae2856abf585a583 3521 68b017e7f2a9e5ce4db5' 3522 }, 3523 / ciphertext / h'' 3524 ] 3525 ] 3526 ] 3527 ) 3529 C.5.3. Wrapped MAC 3531 This example uses the following: 3533 * MAC: AES-MAC, 128-bit key, truncated to 64 bits 3535 * Recipient class: AES Key Wrap w/ a pre-shared 256-bit key 3537 Size of binary file is 109 bytes 3538 97( 3539 [ 3540 / protected / h'a1010e' / { 3541 \ alg \ 1:14 \ AES-CBC-MAC-128//64 \ 3542 } / , 3543 / unprotected / {}, 3544 / payload / 'This is the content.', 3545 / tag / h'36f5afaf0bab5d43', 3546 / recipients / [ 3547 [ 3548 / protected / h'', 3549 / unprotected / { 3550 / alg / 1:-5 / A256KW /, 3551 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 3552 }, 3553 / ciphertext / h'711ab0dc2fc4585dce27effa6781c8093eba906f227 3554 b6eb0' 3555 ] 3556 ] 3557 ] 3558 ) 3560 C.5.4. Multi-Recipient MACed Message 3562 This example uses the following: 3564 * MAC: HMAC w/ SHA-256, 128-bit key 3566 * Recipient class: Uses three different methods 3568 1. ECDH Ephemeral-Static, Curve P-521, AES Key Wrap w/ 128-bit 3569 key 3571 2. AES Key Wrap w/ 256-bit key 3573 Size of binary file is 309 bytes 3574 97( 3575 [ 3576 / protected / h'a10105' / { 3577 \ alg \ 1:5 \ HMAC 256//256 \ 3578 } / , 3579 / unprotected / {}, 3580 / payload / 'This is the content.', 3581 / tag / h'bf48235e809b5c42e995f2b7d5fa13620e7ed834e337f6aa43df16 3582 1e49e9323e', 3583 / recipients / [ 3584 [ 3585 / protected / h'a101381c' / { 3586 \ alg \ 1:-29 \ ECHD-ES+A128KW \ 3587 } / , 3588 / unprotected / { 3589 / ephemeral / -1:{ 3590 / kty / 1:2, 3591 / crv / -1:3, 3592 / x / -2:h'0043b12669acac3fd27898ffba0bcd2e6c366d53bc4db 3593 71f909a759304acfb5e18cdc7ba0b13ff8c7636271a6924b1ac63c02688075b55ef2 3594 d613574e7dc242f79c3', 3595 / y / -3:true 3596 }, 3597 / kid / 4:'bilbo.baggins@hobbiton.example' 3598 }, 3599 / ciphertext / h'339bc4f79984cdc6b3e6ce5f315a4c7d2b0ac466fce 3600 a69e8c07dfbca5bb1f661bc5f8e0df9e3eff5' 3601 ], 3602 [ 3603 / protected / h'', 3604 / unprotected / { 3605 / alg / 1:-5 / A256KW /, 3606 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 3607 }, 3608 / ciphertext / h'0b2c7cfce04e98276342d6476a7723c090dfdd15f9a 3609 518e7736549e998370695e6d6a83b4ae507bb' 3610 ] 3611 ] 3612 ] 3613 ) 3615 C.6. Examples of MAC0 Messages 3617 C.6.1. Shared Secret Direct MAC 3619 This example uses the following: 3621 * MAC: AES-CMAC, 256-bit key, truncated to 64 bits 3622 * Recipient class: direct shared secret 3624 Size of binary file is 37 bytes 3626 17( 3627 [ 3628 / protected / h'a1010f' / { 3629 \ alg \ 1:15 \ AES-CBC-MAC-256//64 \ 3630 } / , 3631 / unprotected / {}, 3632 / payload / 'This is the content.', 3633 / tag / h'726043745027214f' 3634 ] 3635 ) 3637 Note that this example uses the same inputs as Appendix C.5.1. 3639 C.7. COSE Keys 3641 C.7.1. Public Keys 3643 This is an example of a COSE Key Set. This example includes the 3644 public keys for all of the previous examples. 3646 In order the keys are: 3648 * An EC key with a kid of "meriadoc.brandybuck@buckland.example" 3650 * An EC key with a kid of "peregrin.took@tuckborough.example" 3652 * An EC key with a kid of "bilbo.baggins@hobbiton.example" 3654 * An EC key with a kid of "11" 3656 Size of binary file is 481 bytes 3658 [ 3659 { 3660 -1:1, 3661 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 3662 8551d', 3663 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 3664 4d19c', 3665 1:2, 3666 2:'meriadoc.brandybuck@buckland.example' 3667 }, 3668 { 3669 -1:1, 3670 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 3671 09eff', 3672 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 3673 c117e', 3674 1:2, 3675 2:'11' 3676 }, 3677 { 3678 -1:3, 3679 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 3680 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 3681 f42ad', 3682 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 3683 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 3684 d9475', 3685 1:2, 3686 2:'bilbo.baggins@hobbiton.example' 3687 }, 3688 { 3689 -1:1, 3690 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 3691 d6280', 3692 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 3693 822bb', 3694 1:2, 3695 2:'peregrin.took@tuckborough.example' 3696 } 3697 ] 3699 C.7.2. Private Keys 3701 This is an example of a COSE Key Set. This example includes the 3702 private keys for all of the previous examples. 3704 In order the keys are: 3706 * An EC key with a kid of "meriadoc.brandybuck@buckland.example" 3708 * A shared-secret key with a kid of "our-secret" 3710 * An EC key with a kid of "peregrin.took@tuckborough.example" 3712 * A shared-secret key with a kid of "018c0ae5-4d9b-471b- 3713 bfd6-eef314bc7037" 3715 * An EC key with a kid of "bilbo.baggins@hobbiton.example" 3717 * An EC key with a kid of "11" 3719 Size of binary file is 816 bytes 3721 [ 3722 { 3723 1:2, 3724 2:'meriadoc.brandybuck@buckland.example', 3725 -1:1, 3726 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 3727 8551d', 3728 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 3729 4d19c', 3730 -4:h'aff907c99f9ad3aae6c4cdf21122bce2bd68b5283e6907154ad911840fa 3731 208cf' 3732 }, 3733 { 3734 1:2, 3735 2:'11', 3736 -1:1, 3737 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 3738 09eff', 3739 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 3740 c117e', 3741 -4:h'57c92077664146e876760c9520d054aa93c3afb04e306705db609030850 3742 7b4d3' 3743 }, 3744 { 3745 1:2, 3746 2:'bilbo.baggins@hobbiton.example', 3747 -1:3, 3748 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 3749 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 3750 f42ad', 3751 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 3752 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 3753 d9475', 3754 -4:h'00085138ddabf5ca975f5860f91a08e91d6d5f9a76ad4018766a476680b 3755 55cd339e8ab6c72b5facdb2a2a50ac25bd086647dd3e2e6e99e84ca2c3609fdf177f 3756 eb26d' 3757 }, 3758 { 3759 1:4, 3760 2:'our-secret', 3761 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 3762 27188' 3763 }, 3764 { 3765 1:2, 3766 -1:1, 3767 2:'peregrin.took@tuckborough.example', 3768 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 3769 d6280', 3770 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 3771 822bb', 3772 -4:h'02d1f7e6f26c43d4868d87ceb2353161740aacf1f7163647984b522a848 3773 df1c3' 3774 }, 3775 { 3776 1:4, 3777 2:'our-secret2', 3778 -1:h'849b5786457c1491be3a76dcea6c4271' 3779 }, 3780 { 3781 1:4, 3782 2:'018c0ae5-4d9b-471b-bfd6-eef314bc7037', 3783 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 3784 27188' 3785 } 3786 ] 3788 Acknowledgments 3790 This document is a product of the COSE working group of the IETF. 3792 The following individuals are to blame for getting me started on this 3793 project in the first place: Richard Barnes, Matt Miller, and Martin 3794 Thomson. 3796 The initial version of the specification was based to some degree on 3797 the outputs of the JOSE and S/MIME working groups. 3799 The following individuals provided input into the final form of the 3800 document: Carsten Bormann, John Bradley, Brain Campbell, Michael B. 3802 Jones, Ilari Liusvaara, Francesca Palombini, Ludwig Seitz, and Goran 3803 Selander. 3805 Author's Address 3807 Jim Schaad 3808 August Cellars 3810 Email: ietf@augustcellars.com