idnits 2.17.1 draft-ietf-cose-rfc8152bis-struct-09.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 (14 May 2020) is 1442 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-07 ** 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) 14 May 2020 5 Intended status: Standards Track 6 Expires: 15 November 2020 8 CBOR Object Signing and Encryption (COSE): Structures and Process 9 draft-ietf-cose-rfc8152bis-struct-09 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 15 November 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 Counter Signatures . . . . . . . . . . . . . . . . . 25 84 5.2. Abbreviated Counter Signatures . . . . . . . . . . . . . 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 . . . . . . . . . . . . . . . 29 89 6.3. How to Encrypt and Decrypt for AEAD Algorithms . . . . . 29 90 6.4. How to Encrypt and Decrypt for AE Algorithms . . . . . . 32 91 7. MAC Objects . . . . . . . . . . . . . . . . . . . . . . . . . 33 92 7.1. MACed Message with Recipients . . . . . . . . . . . . . . 34 93 7.2. MACed Messages with Implicit Key . . . . . . . . . . . . 35 94 7.3. How to Compute and Verify a MAC . . . . . . . . . . . . . 35 95 8. Key Objects . . . . . . . . . . . . . . . . . . . . . . . . . 37 96 8.1. COSE Key Common Parameters . . . . . . . . . . . . . . . 37 98 9. Taxonomy of Algorithms used by COSE . . . . . . . . . . . . . 40 99 9.1. Signature Algorithms . . . . . . . . . . . . . . . . . . 41 100 9.2. Message Authentication Code (MAC) Algorithms . . . . . . 42 101 9.3. Content Encryption Algorithms . . . . . . . . . . . . . . 42 102 9.4. Key Derivation Functions (KDFs) . . . . . . . . . . . . . 43 103 9.5. Content Key Distribution Methods . . . . . . . . . . . . 44 104 9.5.1. Direct Encryption . . . . . . . . . . . . . . . . . . 44 105 9.5.2. Key Wrap . . . . . . . . . . . . . . . . . . . . . . 44 106 9.5.3. Key Transport . . . . . . . . . . . . . . . . . . . . 45 107 9.5.4. Direct Key Agreement . . . . . . . . . . . . . . . . 45 108 9.5.5. Key Agreement with Key Wrap . . . . . . . . . . . . . 46 109 10. CBOR Encoding Restrictions . . . . . . . . . . . . . . . . . 47 110 11. Application Profiling Considerations . . . . . . . . . . . . 47 111 12. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 49 112 12.1. CBOR Tag Assignment . . . . . . . . . . . . . . . . . . 49 113 12.2. COSE Header Parameters Registry . . . . . . . . . . . . 49 114 12.3. COSE Header Algorithm Parameters Registry . . . . . . . 49 115 12.4. COSE Key Common Parameters Registry . . . . . . . . . . 49 116 12.5. Media Type Registrations . . . . . . . . . . . . . . . . 50 117 12.5.1. COSE Security Message . . . . . . . . . . . . . . . 50 118 12.5.2. COSE Key Media Type . . . . . . . . . . . . . . . . 51 119 12.6. CoAP Content-Formats Registry . . . . . . . . . . . . . 53 120 13. Security Considerations . . . . . . . . . . . . . . . . . . . 53 121 14. Implementation Status . . . . . . . . . . . . . . . . . . . . 55 122 14.1. Author's Versions . . . . . . . . . . . . . . . . . . . 55 123 14.2. JavaScript Version . . . . . . . . . . . . . . . . . . . 56 124 14.3. Python Version . . . . . . . . . . . . . . . . . . . . . 56 125 14.4. COSE Testing Library . . . . . . . . . . . . . . . . . . 57 126 15. References . . . . . . . . . . . . . . . . . . . . . . . . . 57 127 15.1. Normative References . . . . . . . . . . . . . . . . . . 57 128 15.2. Informative References . . . . . . . . . . . . . . . . . 58 129 Appendix A. Guidelines for External Data Authentication of 130 Algorithms . . . . . . . . . . . . . . . . . . . . . . . 61 131 Appendix B. Two Layers of Recipient Information . . . . . . . . 64 132 Appendix C. Examples . . . . . . . . . . . . . . . . . . . . . . 66 133 C.1. Examples of Signed Messages . . . . . . . . . . . . . . . 67 134 C.1.1. Single Signature . . . . . . . . . . . . . . . . . . 67 135 C.1.2. Multiple Signers . . . . . . . . . . . . . . . . . . 68 136 C.1.3. Counter Signature . . . . . . . . . . . . . . . . . . 69 137 C.1.4. Signature with Criticality . . . . . . . . . . . . . 70 138 C.2. Single Signer Examples . . . . . . . . . . . . . . . . . 71 139 C.2.1. Single ECDSA Signature . . . . . . . . . . . . . . . 71 140 C.3. Examples of Enveloped Messages . . . . . . . . . . . . . 72 141 C.3.1. Direct ECDH . . . . . . . . . . . . . . . . . . . . . 72 142 C.3.2. Direct Plus Key Derivation . . . . . . . . . . . . . 73 143 C.3.3. Counter Signature on Encrypted Content . . . . . . . 74 144 C.3.4. Encrypted Content with External Data . . . . . . . . 75 145 C.4. Examples of Encrypted Messages . . . . . . . . . . . . . 76 146 C.4.1. Simple Encrypted Message . . . . . . . . . . . . . . 76 147 C.4.2. Encrypted Message with a Partial IV . . . . . . . . . 77 148 C.5. Examples of MACed Messages . . . . . . . . . . . . . . . 77 149 C.5.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 77 150 C.5.2. ECDH Direct MAC . . . . . . . . . . . . . . . . . . . 78 151 C.5.3. Wrapped MAC . . . . . . . . . . . . . . . . . . . . . 79 152 C.5.4. Multi-Recipient MACed Message . . . . . . . . . . . . 80 153 C.6. Examples of MAC0 Messages . . . . . . . . . . . . . . . . 81 154 C.6.1. Shared Secret Direct MAC . . . . . . . . . . . . . . 81 155 C.7. COSE Keys . . . . . . . . . . . . . . . . . . . . . . . . 82 156 C.7.1. Public Keys . . . . . . . . . . . . . . . . . . . . . 82 157 C.7.2. Private Keys . . . . . . . . . . . . . . . . . . . . 83 158 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 85 159 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 86 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 both to be small in terms 171 of messages transported 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] that specified how to process 177 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 counter signature. 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, rather than base64url encodings, to encode 265 binary data. 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 in a CBOR map of a label 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 byte string 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 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 be 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 zero-length 1005 byte string is used. 1007 3. The protected attributes from the signer structure encoded in a 1008 bstr type. If there are no protected attributes, a zero-length 1009 byte string 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 counter signatures use the structure COSE_Countersign. This is same 1069 structure as COSE_Signature and thus it can have protected 1070 attributes, chained counter signatures and information about 1071 identifying the key. Abbreviated counter signatures use the 1072 structure COSE_Countersign1. This structure only contains the 1073 signature value and nothing else. The structures cannot be converted 1074 between each other; as the signature computation includes a parameter 1075 identifying which structure is being used, the converted structure 1076 will fail 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 counter signatures 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 counter signature, 1083 one needs to be clear about the security properties that result. 1084 When done on a COSE_Signature, the normal counter signature semantics 1085 are preserved. That is the counter signature makes a statement about 1086 the existence of a signature and, when used as a timestamp, a time 1087 point 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 use of two different keys will appear to result in a 1096 successful decryption (the tag check success), but which produce two 1097 completely different plaintexts. This situation is not detectable by 1098 a counter signature on the encrypted data. 1100 5.1. Full Counter Signatures 1102 The COSE_Countersignature structure allows for the same set of 1103 capabilities of a COSE_Signature. This means that all of the 1104 capabilities of a signature are duplicated with this structure. 1105 Specifically, the counter signer does not need to be related to the 1106 producer of what is being counter signed as key and algorithm 1107 identification can be placed in the counter signature attributes. 1108 This also means that the counter signature can itself be counter 1109 signed. This is a feature required by protocols such as long-term 1110 archiving services. More information on how this is used can be 1111 found in the evidence record syntax described in [RFC4998]. 1113 The full counter signature structure can be encoded as either tagged 1114 or untagged depending on the context it is used in. A tagged 1115 COSE_Countersign structure is identified by the CBOR tag TBD0. The 1116 CDDL fragment for full counter signatures is: 1118 COSE_CounterSignature_Tagged = #6.98(COSE_CounterSignature) 1119 COSE_CounterSignature = COSE_Signature 1121 The details of the fields of a counter signature can be found in 1122 Section 4.1. The process of creating and validating abbreviated 1123 counter signatures is defined in Section 4.4. 1125 An example of a counter signature on a signature can be found in 1126 Appendix C.1.3. An example of a counter signature in an encryption 1127 object can be found in Appendix C.3.3. 1129 It should be noted that only a signature algorithm with appendix (see 1130 Section 9.1) can be used for counter signatures. This is because the 1131 body should be able to be processed without having to evaluate the 1132 counter signature, and this is not possible for signature schemes 1133 with message recovery. 1135 5.2. Abbreviated Counter Signatures 1137 Abbreviated counter signatures were designed primarily to deal with 1138 the problem of having encrypted group messaging, but still needing to 1139 know who originated the message. The objective was to keep the 1140 counter signature as small as possible while still providing the 1141 needed security. For abbreviated counter signatures, there is no 1142 provision for any protected attributes related to the signing 1143 operation. Instead, the parameters for computing or verifying the 1144 abbreviated counter signature are inferred from the same context used 1145 to describe the encryption, signature, or MAC processing. 1147 The byte string representing the signature value is placed in the 1148 CounterSignature0 attribute. This attribute is then encoded as an 1149 unprotected header parameter. The attribute is defined below. 1151 The process of creating and validating abbreviated counter signatures 1152 is defined in Section 4.4. 1154 +-------------------+-------+-------+-------+-------------------+ 1155 | Name | Label | Value | Value | Description | 1156 | | | Type | | | 1157 +===================+=======+=======+=======+===================+ 1158 | CounterSignature0 | 9 | bstr | | Abbreviated | 1159 | | | | | Counter Signature | 1160 +-------------------+-------+-------+-------+-------------------+ 1162 Table 4: Header Parameter for CounterSignature0 1164 6. Encryption Objects 1166 COSE supports two different encryption structures. COSE_Encrypt0 is 1167 used when a recipient structure is not needed because the key to be 1168 used is known implicitly. COSE_Encrypt is used the rest of the time. 1169 This includes cases where there are multiple recipients or a 1170 recipient algorithm other than direct (i.e. pre-shared secret) is 1171 used. 1173 6.1. Enveloped COSE Structure 1175 The enveloped structure allows for one or more recipients of a 1176 message. There are provisions for header parameters about the 1177 content and header parameters about the recipient information to be 1178 carried in the message. The protected header parameters associated 1179 with the content are authenticated by the content encryption 1180 algorithm. The protected header parameters associated with the 1181 recipient are authenticated by the recipient algorithm (when the 1182 algorithm supports it). Examples of header parameters about the 1183 content are the type of the content and the content encryption 1184 algorithm. Examples of header parameters about the recipient are the 1185 recipient's key identifier and the recipient's encryption algorithm. 1187 The same techniques and nearly the same structure are used for 1188 encrypting both the plaintext and the keys. This is different from 1189 the approach used by both "Cryptographic Message Syntax (CMS)" 1190 [RFC5652] and "JSON Web Encryption (JWE)" [RFC7516] where different 1191 structures are used for the content layer and for the recipient 1192 layer. Two structures are defined: COSE_Encrypt to hold the 1193 encrypted content and COSE_recipient to hold the encrypted keys for 1194 recipients. Examples of encrypted messages can be found in 1195 Appendix C.3. 1197 The COSE_Encrypt structure can be encoded as either tagged or 1198 untagged depending on the context it will be used in. A tagged 1199 COSE_Encrypt structure is identified by the CBOR tag 96. The CDDL 1200 fragment that represents this is: 1202 COSE_Encrypt_Tagged = #6.96(COSE_Encrypt) 1204 The COSE_Encrypt structure is a CBOR array. The fields of the array 1205 in order are: 1207 protected: This is as described in Section 3. 1209 unprotected: This is as described in Section 3. 1211 ciphertext: This field contains the ciphertext encoded as a bstr. 1212 If the ciphertext is to be transported independently of the 1213 control information about the encryption process (i.e., detached 1214 content), then the field is encoded as a nil value. 1216 recipients: This field contains an array of recipient information 1217 structures. The type for the recipient information structure is a 1218 COSE_recipient. 1220 The CDDL fragment that corresponds to the above text is: 1222 COSE_Encrypt = [ 1223 Headers, 1224 ciphertext : bstr / nil, 1225 recipients : [+COSE_recipient] 1226 ] 1228 The COSE_recipient structure is a CBOR array. The fields of the 1229 array in order are: 1231 protected: This is as described in Section 3. 1233 unprotected: This is as described in Section 3. 1235 ciphertext: This field contains the encrypted key encoded as a bstr. 1236 All encoded keys are symmetric keys; the binary value of the key 1237 is the content. If there is not an encrypted key, then this field 1238 is encoded as a nil value. 1240 recipients: This field contains an array of recipient information 1241 structures. The type for the recipient information structure is a 1242 COSE_recipient (an example of this can be found in Appendix B). 1243 If there are no recipient information structures, this element is 1244 absent. 1246 The CDDL fragment that corresponds to the above text for 1247 COSE_recipient is: 1249 COSE_recipient = [ 1250 Headers, 1251 ciphertext : bstr / nil, 1252 ? recipients : [+COSE_recipient] 1253 ] 1255 6.1.1. Content Key Distribution Methods 1257 An encrypted message consists of an encrypted content and an 1258 encrypted CEK for one or more recipients. The CEK is encrypted for 1259 each recipient, using a key specific to that recipient. The details 1260 of this encryption depend on which class the recipient algorithm 1261 falls into. Specific details on each of the classes can be found in 1262 Section 9.5. A short summary of the five content key distribution 1263 methods is: 1265 direct: The CEK is the same as the identified previously distributed 1266 symmetric key or is derived from a previously distributed secret. 1267 No CEK is transported in the message. 1269 symmetric key-encryption keys (KEK): The CEK is encrypted using a 1270 previously distributed symmetric KEK. Also known as key wrap. 1272 key agreement: The recipient's public key and a sender's private key 1273 are used to generate a pairwise secret, a Key Derivation Function 1274 (KDF) is applied to derive a key, and then the CEK is either the 1275 derived key or encrypted by the derived key. 1277 key transport: The CEK is encrypted with the recipient's public key. 1279 passwords: The CEK is encrypted in a KEK that is derived from a 1280 password. As of when this document was published, no password 1281 algorithms have been defined. 1283 6.2. Single Recipient Encrypted 1285 The COSE_Encrypt0 encrypted structure does not have the ability to 1286 specify recipients of the message. The structure assumes that the 1287 recipient of the object will already know the identity of the key to 1288 be used in order to decrypt the message. If a key needs to be 1289 identified to the recipient, the enveloped structure ought to be 1290 used. 1292 Examples of encrypted messages can be found in Appendix C.3. 1294 The COSE_Encrypt0 structure can be encoded as either tagged or 1295 untagged depending on the context it will be used in. A tagged 1296 COSE_Encrypt0 structure is identified by the CBOR tag 16. The CDDL 1297 fragment that represents this is: 1299 COSE_Encrypt0_Tagged = #6.16(COSE_Encrypt0) 1301 The COSE_Encrypt0 structure is a CBOR array. The fields of the array 1302 in order are: 1304 protected: This is as described in Section 3. 1306 unprotected: This is as described in Section 3. 1308 ciphertext: This is as described in Section 6.1. 1310 The CDDL fragment for COSE_Encrypt0 that corresponds to the above 1311 text is: 1313 COSE_Encrypt0 = [ 1314 Headers, 1315 ciphertext : bstr / nil, 1316 ] 1318 6.3. How to Encrypt and Decrypt for AEAD Algorithms 1320 The encryption algorithm for AEAD algorithms is fairly simple. The 1321 first step is to create a consistent byte string for the 1322 authenticated data structure. For this purpose, we use an 1323 Enc_structure. The Enc_structure is a CBOR array. The fields of the 1324 Enc_structure in order are: 1326 1. A context text string identifying the context of the 1327 authenticated data structure. The context text string is: 1329 "Encrypt0" for the content encryption of a COSE_Encrypt0 data 1330 structure. 1332 "Encrypt" for the first layer of a COSE_Encrypt data structure 1333 (i.e., for content encryption). 1335 "Enc_Recipient" for a recipient encoding to be placed in an 1336 COSE_Encrypt data structure. 1338 "Mac_Recipient" for a recipient encoding to be placed in a 1339 MACed message structure. 1341 "Rec_Recipient" for a recipient encoding to be placed in a 1342 recipient structure. 1344 2. The protected attributes from the body structure encoded in a 1345 bstr type. If there are no protected attributes, a zero-length 1346 byte string is used. 1348 3. The protected attributes from the application encoded in a bstr 1349 type. If this field is not supplied, it defaults to a zero- 1350 length byte string. (See Section 4.3 for application guidance on 1351 constructing this field.) 1353 The CDDL fragment that describes the above text is: 1355 Enc_structure = [ 1356 context : "Encrypt" / "Encrypt0" / "Enc_Recipient" / 1357 "Mac_Recipient" / "Rec_Recipient", 1358 protected : empty_or_serialized_map, 1359 external_aad : bstr 1360 ] 1362 How to encrypt a message: 1364 1. Create an Enc_structure and populate it with the appropriate 1365 fields. 1367 2. Encode the Enc_structure to a byte string (Additional 1368 Authenticated Data (AAD)), using the encoding described in 1369 Section 10. 1371 3. Determine the encryption key (K). This step is dependent on the 1372 class of recipient algorithm being used. For: 1374 No Recipients: The key to be used is determined by the algorithm 1375 and key at the current layer. Examples are key transport keys 1376 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1377 secrets. 1379 Direct Encryption and Direct Key Agreement: The key is 1380 determined by the key and algorithm in the recipient 1381 structure. The encryption algorithm and size of the key to be 1382 used are inputs into the KDF used for the recipient. (For 1383 direct, the KDF can be thought of as the identity operation.) 1384 Examples of these algorithms are found in Sections 6.1.2 and 1385 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1387 Other: The key is randomly or pseudo-randomly generated. 1389 4. Call the encryption algorithm with K (the encryption key), P (the 1390 plaintext), and AAD. Place the returned ciphertext into the 1391 'ciphertext' field of the structure. 1393 5. For recipients of the message, recursively perform the encryption 1394 algorithm for that recipient, using K (the encryption key) as the 1395 plaintext. 1397 How to decrypt a message: 1399 1. Create an Enc_structure and populate it with the appropriate 1400 fields. 1402 2. Encode the Enc_structure to a byte string (AAD), using the 1403 encoding described in Section 10. 1405 3. Determine the decryption key. This step is dependent on the 1406 class of recipient algorithm being used. For: 1408 No Recipients: The key to be used is determined by the algorithm 1409 and key at the current layer. Examples are key transport keys 1410 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1411 secrets. 1413 Direct Encryption and Direct Key Agreement: The key is 1414 determined by the key and algorithm in the recipient 1415 structure. The encryption algorithm and size of the key to be 1416 used are inputs into the KDF used for the recipient. (For 1417 direct, the KDF can be thought of as the identity operation.) 1419 Other: The key is determined by decoding and decrypting one of 1420 the recipient structures. 1422 4. Call the decryption algorithm with K (the decryption key to use), 1423 C (the ciphertext), and AAD. 1425 6.4. How to Encrypt and Decrypt for AE Algorithms 1427 How to encrypt a message: 1429 1. Verify that the 'protected' field is empty. 1431 2. Verify that there was no external additional authenticated data 1432 supplied for this operation. 1434 3. Determine the encryption key. This step is dependent on the 1435 class of recipient algorithm being used. For: 1437 No Recipients: The key to be used is determined by the algorithm 1438 and key at the current layer. Examples are key transport keys 1439 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1440 secrets. 1442 Direct Encryption and Direct Key Agreement: The key is 1443 determined by the key and algorithm in the recipient 1444 structure. The encryption algorithm and size of the key to be 1445 used are inputs into the KDF used for the recipient. (For 1446 direct, the KDF can be thought of as the identity operation.) 1447 Examples of these algorithms are found in Sections 6.1.2 and 1448 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1450 Other: The key is randomly generated. 1452 4. Call the encryption algorithm with K (the encryption key to use) 1453 and P (the plaintext). Place the returned ciphertext into the 1454 'ciphertext' field of the structure. 1456 5. For recipients of the message, recursively perform the encryption 1457 algorithm for that recipient, using K (the encryption key) as the 1458 plaintext. 1460 How to decrypt a message: 1462 1. Verify that the 'protected' field is empty. 1464 2. Verify that there was no external additional authenticated data 1465 supplied for this operation. 1467 3. Determine the decryption key. This step is dependent on the 1468 class of recipient algorithm being used. For: 1470 No Recipients: The key to be used is determined by the algorithm 1471 and key at the current layer. Examples are key transport keys 1472 (Section 9.5.3), key wrap keys (Section 9.5.2), or pre-shared 1473 secrets. 1475 Direct Encryption and Direct Key Agreement: The key is 1476 determined by the key and algorithm in the recipient 1477 structure. The encryption algorithm and size of the key to be 1478 used are inputs into the KDF used for the recipient. (For 1479 direct, the KDF can be thought of as the identity operation.) 1480 Examples of these algorithms are found in Sections 6.1.2 and 1481 6.3 of [I-D.ietf-cose-rfc8152bis-algs]. 1483 Other: The key is determined by decoding and decrypting one of 1484 the recipient structures. 1486 4. Call the decryption algorithm with K (the decryption key to use) 1487 and C (the ciphertext). 1489 7. MAC Objects 1491 COSE supports two different MAC structures. COSE_MAC0 is used when a 1492 recipient structure is not needed because the key to be used is 1493 implicitly known. COSE_MAC is used for all other cases. These 1494 include a requirement for multiple recipients, the key being unknown, 1495 or a recipient algorithm of other than direct. 1497 In this section, we describe the structure and methods to be used 1498 when doing MAC authentication in COSE. This document allows for the 1499 use of all of the same classes of recipient algorithms as are allowed 1500 for encryption. 1502 When using MAC operations, there are two modes in which they can be 1503 used. The first is just a check that the content has not been 1504 changed since the MAC was computed. Any class of recipient algorithm 1505 can be used for this purpose. The second mode is to both check that 1506 the content has not been changed since the MAC was computed and to 1507 use the recipient algorithm to verify who sent it. The classes of 1508 recipient algorithms that support this are those that use a pre- 1509 shared secret or do static-static (SS) key agreement (without the key 1510 wrap step). In both of these cases, the entity that created and sent 1511 the message MAC can be validated. (This knowledge of the sender 1512 assumes that there are only two parties involved and that you did not 1513 send the message to yourself.) The origination property can be 1514 obtained with both of the MAC message structures. 1516 7.1. MACed Message with Recipients 1518 The multiple recipient MACed message uses two structures: the 1519 COSE_Mac structure defined in this section for carrying the body and 1520 the COSE_recipient structure (Section 6.1) to hold the key used for 1521 the MAC computation. Examples of MACed messages can be found in 1522 Appendix C.5. 1524 The MAC structure can be encoded as either tagged or untagged 1525 depending on the context it will be used in. A tagged COSE_Mac 1526 structure is identified by the CBOR tag 97. The CDDL fragment that 1527 represents this is: 1529 COSE_Mac_Tagged = #6.97(COSE_Mac) 1531 The COSE_Mac structure is a CBOR array. The fields of the array in 1532 order are: 1534 protected: This is as described in Section 3. 1536 unprotected: This is as described in Section 3. 1538 payload: This field contains the serialized content to be MACed. If 1539 the payload is not present in the message, the application is 1540 required to supply the payload separately. The payload is wrapped 1541 in a bstr to ensure that it is transported without changes. If 1542 the payload is transported separately (i.e., detached content), 1543 then a nil CBOR value is placed in this location, and it is the 1544 responsibility of the application to ensure that it will be 1545 transported without changes. 1547 tag: This field contains the MAC value. 1549 recipients: This is as described in Section 6.1. 1551 The CDDL fragment that represents the above text for COSE_Mac 1552 follows. 1554 COSE_Mac = [ 1555 Headers, 1556 payload : bstr / nil, 1557 tag : bstr, 1558 recipients :[+COSE_recipient] 1559 ] 1561 7.2. MACed Messages with Implicit Key 1563 In this section, we describe the structure and methods to be used 1564 when doing MAC authentication for those cases where the recipient is 1565 implicitly known. 1567 The MACed message uses the COSE_Mac0 structure defined in this 1568 section for carrying the body. Examples of MACed messages with an 1569 implicit key can be found in Appendix C.6. 1571 The MAC structure can be encoded as either tagged or untagged 1572 depending on the context it will be used in. A tagged COSE_Mac0 1573 structure is identified by the CBOR tag 17. The CDDL fragment that 1574 represents this is: 1576 COSE_Mac0_Tagged = #6.17(COSE_Mac0) 1578 The COSE_Mac0 structure is a CBOR array. The fields of the array in 1579 order are: 1581 protected: This is as described in Section 3. 1583 unprotected: This is as described in Section 3. 1585 payload: This is as described in Section 7.1. 1587 tag: This field contains the MAC value. 1589 The CDDL fragment that corresponds to the above text is: 1591 COSE_Mac0 = [ 1592 Headers, 1593 payload : bstr / nil, 1594 tag : bstr, 1595 ] 1597 7.3. How to Compute and Verify a MAC 1599 In order to get a consistent encoding of the data to be 1600 authenticated, the MAC_structure is used to have a canonical form. 1601 The MAC_structure is a CBOR array. The fields of the MAC_structure 1602 in order are: 1604 1. A context text string that identifies the structure that is being 1605 encoded. This context text string is "MAC" for the COSE_Mac 1606 structure. This context text string is "MAC0" for the COSE_Mac0 1607 structure. 1609 2. The protected attributes from the COSE_MAC structure. If there 1610 are no protected attributes, a zero-length bstr is used. 1612 3. The protected attributes from the application encoded as a bstr 1613 type. If this field is not supplied, it defaults to a zero- 1614 length byte string. (See Section 4.3 for application guidance on 1615 constructing this field.) 1617 4. The payload to be MACed encoded in a bstr type. The payload is 1618 placed here independent of how it is transported. 1620 The CDDL fragment that corresponds to the above text is: 1622 MAC_structure = [ 1623 context : "MAC" / "MAC0", 1624 protected : empty_or_serialized_map, 1625 external_aad : bstr, 1626 payload : bstr 1627 ] 1629 The steps to compute a MAC are: 1631 1. Create a MAC_structure and populate it with the appropriate 1632 fields. 1634 2. Create the value ToBeMaced by encoding the MAC_structure to a 1635 byte string, using the encoding described in Section 10. 1637 3. Call the MAC creation algorithm passing in K (the key to use), 1638 alg (the algorithm to MAC with), and ToBeMaced (the value to 1639 compute the MAC on). 1641 4. Place the resulting MAC in the 'tag' field of the COSE_Mac or 1642 COSE_Mac0 structure. 1644 5. For COSE_Mac structures, encrypt and encode the MAC key for each 1645 recipient of the message. 1647 The steps to verify a MAC are: 1649 1. Create a MAC_structure and populate it with the appropriate 1650 fields. 1652 2. Create the value ToBeMaced by encoding the MAC_structure to a 1653 byte string, using the encoding described in Section 10. 1655 3. For COSE_Mac structures, obtain the cryptographic key from one of 1656 the recipients of the message. 1658 4. Call the MAC creation algorithm passing in K (the key to use), 1659 alg (the algorithm to MAC with), and ToBeMaced (the value to 1660 compute the MAC on). 1662 5. Compare the MAC value to the 'tag' field of the COSE_Mac or 1663 COSE_Mac0 structure. 1665 8. Key Objects 1667 A COSE Key structure is built on a CBOR map. The set of common 1668 parameters that can appear in a COSE Key can be found in the IANA 1669 "COSE Key Common Parameters" registry (Section 12.4). Additional 1670 parameters defined for specific key types can be found in the IANA 1671 "COSE Key Type Parameters" registry ([COSE.KeyParameters]). 1673 A COSE Key Set uses a CBOR array object as its underlying type. The 1674 values of the array elements are COSE Keys. A COSE Key Set MUST have 1675 at least one element in the array. Examples of COSE Key Sets can be 1676 found in Appendix C.7. 1678 Each element in a COSE Key Set MUST be processed independently. If 1679 one element in a COSE Key Set is either malformed or uses a key that 1680 is not understood by an application, that key is ignored and the 1681 other keys are processed normally. 1683 The element "kty" is a required element in a COSE_Key map. 1685 The CDDL grammar describing COSE_Key and COSE_KeySet is: 1687 COSE_Key = { 1688 1 => tstr / int, ; kty 1689 ? 2 => bstr, ; kid 1690 ? 3 => tstr / int, ; alg 1691 ? 4 => [+ (tstr / int) ], ; key_ops 1692 ? 5 => bstr, ; Base IV 1693 * label => values 1694 } 1696 COSE_KeySet = [+COSE_Key] 1698 8.1. COSE Key Common Parameters 1700 This document defines a set of common parameters for a COSE Key 1701 object. Table 5 provides a summary of the parameters defined in this 1702 section. There are also parameters that are defined for specific key 1703 types. Key-type-specific parameters can be found in 1704 [I-D.ietf-cose-rfc8152bis-algs]. 1706 +---------+-------+--------+------------+--------------------+ 1707 | Name | Label | CBOR | Value | Description | 1708 | | | Type | Registry | | 1709 +=========+=======+========+============+====================+ 1710 | kty | 1 | tstr / | COSE Key | Identification of | 1711 | | | int | Types | the key type | 1712 +---------+-------+--------+------------+--------------------+ 1713 | kid | 2 | bstr | | Key identification | 1714 | | | | | value -- match to | 1715 | | | | | kid in message | 1716 +---------+-------+--------+------------+--------------------+ 1717 | alg | 3 | tstr / | COSE | Key usage | 1718 | | | int | Algorithms | restriction to | 1719 | | | | | this algorithm | 1720 +---------+-------+--------+------------+--------------------+ 1721 | key_ops | 4 | [+ | | Restrict set of | 1722 | | | (tstr/ | | permissible | 1723 | | | int)] | | operations | 1724 +---------+-------+--------+------------+--------------------+ 1725 | Base IV | 5 | bstr | | Base IV to be xor- | 1726 | | | | | ed with Partial | 1727 | | | | | IVs | 1728 +---------+-------+--------+------------+--------------------+ 1730 Table 5: Key Map Labels 1732 kty: This parameter is used to identify the family of keys for this 1733 structure and, thus, the set of key-type-specific parameters to be 1734 found. The set of values defined in this document can be found in 1735 [COSE.KeyTypes]. This parameter MUST be present in a key object. 1736 Implementations MUST verify that the key type is appropriate for 1737 the algorithm being processed. The key type MUST be included as 1738 part of the trust decision process. 1740 alg: This parameter is used to restrict the algorithm that is used 1741 with the key. If this parameter is present in the key structure, 1742 the application MUST verify that this algorithm matches the 1743 algorithm for which the key is being used. If the algorithms do 1744 not match, then this key object MUST NOT be used to perform the 1745 cryptographic operation. Note that the same key can be in a 1746 different key structure with a different or no algorithm 1747 specified; however, this is considered to be a poor security 1748 practice. 1750 kid: This parameter is used to give an identifier for a key. The 1751 identifier is not structured and can be anything from a user- 1752 provided byte string to a value computed on the public portion of 1753 the key. This field is intended for matching against a 'kid' 1754 parameter in a message in order to filter down the set of keys 1755 that need to be checked. 1757 key_ops: This parameter is defined to restrict the set of operations 1758 that a key is to be used for. The value of the field is an array 1759 of values from Table 6. Algorithms define the values of key ops 1760 that are permitted to appear and are required for specific 1761 operations. The set of values matches that in [RFC7517] and 1762 [W3C.WebCrypto]. 1764 Base IV: This parameter is defined to carry the base portion of an 1765 IV. It is designed to be used with the Partial IV header 1766 parameter defined in Section 3.1. This field provides the ability 1767 to associate a Partial IV with a key that is then modified on a 1768 per message basis with the Partial IV. 1770 Extreme care needs to be taken when using a Base IV in an 1771 application. Many encryption algorithms lose security if the same 1772 IV is used twice. 1774 If different keys are derived for each sender, using the same Base 1775 IV with Partial IVs starting at zero is likely to ensure that the 1776 IV would not be used twice for a single key. If different keys 1777 are derived for each sender, starting at the same Base IV is 1778 likely to satisfy this condition. If the same key is used for 1779 multiple senders, then the application needs to provide for a 1780 method of dividing the IV space up between the senders. This 1781 could be done by providing a different base point to start from or 1782 a different Partial IV to start with and restricting the number of 1783 messages to be sent before rekeying. 1785 +---------+-------+----------------------------------------------+ 1786 | Name | Value | Description | 1787 +=========+=======+==============================================+ 1788 | sign | 1 | The key is used to create signatures. | 1789 | | | Requires private key fields. | 1790 +---------+-------+----------------------------------------------+ 1791 | verify | 2 | The key is used for verification of | 1792 | | | signatures. | 1793 +---------+-------+----------------------------------------------+ 1794 | encrypt | 3 | The key is used for key transport | 1795 | | | encryption. | 1796 +---------+-------+----------------------------------------------+ 1797 | decrypt | 4 | The key is used for key transport | 1798 | | | decryption. Requires private key fields. | 1799 +---------+-------+----------------------------------------------+ 1800 | wrap | 5 | The key is used for key wrap encryption. | 1801 | key | | | 1802 +---------+-------+----------------------------------------------+ 1803 | unwrap | 6 | The key is used for key wrap decryption. | 1804 | key | | Requires private key fields. | 1805 +---------+-------+----------------------------------------------+ 1806 | derive | 7 | The key is used for deriving keys. Requires | 1807 | key | | private key fields. | 1808 +---------+-------+----------------------------------------------+ 1809 | derive | 8 | The key is used for deriving bits not to be | 1810 | bits | | used as a key. Requires private key fields. | 1811 +---------+-------+----------------------------------------------+ 1812 | MAC | 9 | The key is used for creating MACs. | 1813 | create | | | 1814 +---------+-------+----------------------------------------------+ 1815 | MAC | 10 | The key is used for validating MACs. | 1816 | verify | | | 1817 +---------+-------+----------------------------------------------+ 1819 Table 6: Key Operation Values 1821 9. Taxonomy of Algorithms used by COSE 1823 In this section, a taxonomy of the different algorithm types that can 1824 be used in COSE is laid out. This taxonomy should not be considered 1825 to be exhaustive. New algorithms will be created which will not fit 1826 into this taxonomy. If this occurs, then new documents addressing 1827 this new algorithms are going to be needed. 1829 9.1. Signature Algorithms 1831 Signature algorithms provide data origination and data integrity 1832 services. Data origination provides the ability to infer who 1833 originated the data based on who signed the data. Data integrity 1834 provides the ability to verify that the data has not been modified 1835 since it was signed. 1837 There are two signature algorithm schemes. The first is signature 1838 with appendix. In this scheme, the message content is processed and 1839 a signature is produced; the signature is called the appendix. This 1840 is the scheme used by algorithms such as ECDSA and the RSA 1841 Probabilistic Signature Scheme (RSASSA-PSS). (In fact, the SSA in 1842 RSASSA-PSS stands for Signature Scheme with Appendix.) 1844 The signature functions for this scheme are: 1846 signature = Sign(message content, key) 1848 valid = Verification(message content, key, signature) 1850 The second scheme is signature with message recovery (an example of 1851 such an algorithm is [PVSig]). In this scheme, the message content 1852 is processed, but part of it is included in the signature. Moving 1853 bytes of the message content into the signature allows for smaller 1854 signatures; the signature size is still potentially large, but the 1855 message content has shrunk. This has implications for systems 1856 implementing these algorithms and for applications that use them. 1857 The first is that the message content is not fully available until 1858 after a signature has been validated. Until that point, the part of 1859 the message contained inside of the signature is unrecoverable. The 1860 second is that the security analysis of the strength of the signature 1861 is very much based on the structure of the message content. Messages 1862 that are highly predictable require additional randomness to be 1863 supplied as part of the signature process. In the worst case, it 1864 becomes the same as doing a signature with appendix. Finally, in the 1865 event that multiple signatures are applied to a message, all of the 1866 signature algorithms are going to be required to consume the same 1867 number of bytes of message content. This means that the mixing of 1868 the different schemes in a single message is not supported, and if a 1869 recovery signature scheme is used, then the same amount of content 1870 needs to be consumed by all of the signatures. 1872 The signature functions for this scheme are: 1874 signature, message sent = Sign(message content, key) 1876 valid, message content = Verification(message sent, key, signature) 1877 Signature algorithms are used with the COSE_Signature and COSE_Sign1 1878 structures. At this time, only signatures with appendixes are 1879 defined for use with COSE; however, considerable interest has been 1880 expressed in using a signature with message recovery algorithm due to 1881 the effective size reduction that is possible. Implementations will 1882 need to keep this in mind for later possible integration. 1884 9.2. Message Authentication Code (MAC) Algorithms 1886 Message Authentication Codes (MACs) provide data authentication and 1887 integrity protection. They provide either no or very limited data 1888 origination. A MAC, for example, cannot be used to prove the 1889 identity of the sender to a third party. 1891 MACs use the same scheme as signature with appendix algorithms. The 1892 message content is processed and an authentication code is produced. 1893 The authentication code is frequently called a tag. 1895 The MAC functions are: 1897 tag = MAC_Create(message content, key) 1899 valid = MAC_Verify(message content, key, tag) 1901 MAC algorithms can be based on either a block cipher algorithm (i.e., 1902 AES-MAC) or a hash algorithm (i.e., a Hash-based Message 1903 Authentication Code (HMAC)). [I-D.ietf-cose-rfc8152bis-algs] defines 1904 a MAC algorithm using each of these constructions. 1906 MAC algorithms are used in the COSE_Mac and COSE_Mac0 structures. 1908 9.3. Content Encryption Algorithms 1910 Content encryption algorithms provide data confidentiality for 1911 potentially large blocks of data using a symmetric key. They provide 1912 integrity on the data that was encrypted; however, they provide 1913 either no or very limited data origination. (One cannot, for 1914 example, be used to prove the identity of the sender to a third 1915 party.) The ability to provide data origination is linked to how the 1916 CEK is obtained. 1918 COSE restricts the set of legal content encryption algorithms to 1919 those that support authentication both of the content and additional 1920 data. The encryption process will generate some type of 1921 authentication value, but that value may be either explicit or 1922 implicit in terms of the algorithm definition. For simplicity's 1923 sake, the authentication code will normally be defined as being 1924 appended to the ciphertext stream. The encryption functions are: 1926 ciphertext = Encrypt(message content, key, additional data) 1928 valid, message content = Decrypt(ciphertext, key, additional data) 1930 Most AEAD algorithms are logically defined as returning the message 1931 content only if the decryption is valid. Many but not all 1932 implementations will follow this convention. The message content 1933 MUST NOT be used if the decryption does not validate. 1935 These algorithms are used in COSE_Encrypt and COSE_Encrypt0. 1937 9.4. Key Derivation Functions (KDFs) 1939 KDFs are used to take some secret value and generate a different one. 1940 The secret value comes in three flavors: 1942 * Secrets that are uniformly random: This is the type of secret that 1943 is created by a good random number generator. 1945 * Secrets that are not uniformly random: This is type of secret that 1946 is created by operations like key agreement. 1948 * Secrets that are not random: This is the type of secret that 1949 people generate for things like passwords. 1951 General KDFs work well with the first type of secret, can do 1952 reasonably well with the second type of secret, and generally do 1953 poorly with the last type of secret. Functions like PBES2 [RFC8018] 1954 need to be used for non-random secrets. 1956 The same KDF can be set up to deal with the first two types of 1957 secrets in a different way. The KDF defined in section 5.1 of 1958 [I-D.ietf-cose-rfc8152bis-algs] is such a function. This is 1959 reflected in the set of algorithms defined around the HMAC-based 1960 Extract-and-Expand Key Derivation Function (HKDF). 1962 When using KDFs, one component that is included is context 1963 information. Context information is used to allow for different 1964 keying information to be derived from the same secret. The use of 1965 context-based keying material is considered to be a good security 1966 practice. 1968 9.5. Content Key Distribution Methods 1970 Content key distribution methods (recipient algorithms) can be 1971 defined into a number of different classes. COSE has the ability to 1972 support many classes of recipient algorithms. In this section, a 1973 number of classes are listed. The names of the recipient algorithm 1974 classes used here are the same as those defined in [RFC7516]. Other 1975 specifications use different terms for the recipient algorithm 1976 classes or do not support some of the recipient algorithm classes. 1978 9.5.1. Direct Encryption 1980 The direct encryption class algorithms share a secret between the 1981 sender and the recipient that is used either directly or after 1982 manipulation as the CEK. When direct encryption mode is used, it 1983 MUST be the only mode used on the message. 1985 The COSE_Recipient structure for the recipient is organized as 1986 follows: 1988 * The 'protected' field MUST be a zero-length byte string unless it 1989 is used in the computation of the content key. 1991 * The 'alg' header parameter MUST be present. 1993 * A header parameter identifying the shared secret SHOULD be 1994 present. 1996 * The 'ciphertext' field MUST be a zero-length byte string. 1998 * The 'recipients' field MUST be absent. 2000 9.5.2. Key Wrap 2002 In key wrap mode, the CEK is randomly generated and that key is then 2003 encrypted by a shared secret between the sender and the recipient. 2004 All of the currently defined key wrap algorithms for COSE are AE 2005 algorithms. Key wrap mode is considered to be superior to direct 2006 encryption if the system has any capability for doing random key 2007 generation. This is because the shared key is used to wrap random 2008 data rather than data that has some degree of organization and may in 2009 fact be repeating the same content. The use of key wrap loses the 2010 weak data origination that is provided by the direct encryption 2011 algorithms. 2013 The COSE_Encrypt structure for the recipient is organized as follows: 2015 * The 'protected' field MUST be absent if the key wrap algorithm is 2016 an AE algorithm. 2018 * The 'recipients' field is normally absent, but can be used. 2019 Applications MUST deal with a recipient field being present that 2020 has an unsupported algorithm, not being able to decrypt that 2021 recipient is an acceptable way of dealing with it. Failing to 2022 process the message is not an acceptable way of dealing with it. 2024 * The plaintext to be encrypted is the key from next layer down 2025 (usually the content layer). 2027 * At a minimum, the 'unprotected' field MUST contain the 'alg' 2028 header parameter and SHOULD contain a header parameter identifying 2029 the shared secret. 2031 9.5.3. Key Transport 2033 Key transport mode is also called key encryption mode in some 2034 standards. Key transport mode differs from key wrap mode in that it 2035 uses an asymmetric encryption algorithm rather than a symmetric 2036 encryption algorithm to protect the key. A set of key transport 2037 algorithms are defined in [RFC8230]. 2039 When using a key transport algorithm, the COSE_Encrypt structure for 2040 the recipient is organized as follows: 2042 * The 'protected' field MUST be absent. 2044 * The plaintext to be encrypted is the key from the next layer down 2045 (usually the content layer). 2047 * At a minimum, the 'unprotected' field MUST contain the 'alg' 2048 header parameter and SHOULD contain a parameter identifying the 2049 asymmetric key. 2051 9.5.4. Direct Key Agreement 2053 The 'direct key agreement' class of recipient algorithms uses a key 2054 agreement method to create a shared secret. A KDF is then applied to 2055 the shared secret to derive a key to be used in protecting the data. 2056 This key is normally used as a CEK or MAC key, but could be used for 2057 other purposes if more than two layers are in use (see Appendix B). 2059 The most commonly used key agreement algorithm is Diffie-Hellman, but 2060 other variants exist. Since COSE is designed for a store and forward 2061 environment rather than an online environment, many of the DH 2062 variants cannot be used as the receiver of the message cannot provide 2063 any dynamic key material. One side effect of this is that perfect 2064 forward secrecy (see [RFC4949]) is not achievable. A static key will 2065 always be used for the receiver of the COSE object. 2067 Two variants of DH that are supported are: 2069 Ephemeral-Static (ES) DH: where the sender of the message creates 2070 a one-time DH key and uses a static key for the recipient. The 2071 use of the ephemeral sender key means that no additional random 2072 input is needed as this is randomly generated for each message. 2074 Static-Static (SS) DH: where a static key is used for both the 2075 sender and the recipient. The use of static keys allows for the 2076 recipient to get a weak version of data origination for the 2077 message. When static-static key agreement is used, then some 2078 piece of unique data for the KDF is required to ensure that a 2079 different key is created for each message. 2081 When direct key agreement mode is used, there MUST be only one 2082 recipient in the message. This method creates the key directly, and 2083 that makes it difficult to mix with additional recipients. If 2084 multiple recipients are needed, then the version with key wrap needs 2085 to be used. 2087 The COSE_Encrypt structure for the recipient is organized as follows: 2089 * At a minimum, headers MUST contain the 'alg' header parameter and 2090 SHOULD contain a header parameter identifying the recipient's 2091 asymmetric key. 2093 * The headers SHOULD identify the sender's key for the static-static 2094 versions and MUST contain the sender's ephemeral key for the 2095 ephemeral-static versions. 2097 9.5.5. Key Agreement with Key Wrap 2099 Key Agreement with Key Wrap uses a randomly generated CEK. The CEK 2100 is then encrypted using a key wrap algorithm and a key derived from 2101 the shared secret computed by the key agreement algorithm. The 2102 function for this would be: 2104 encryptedKey = KeyWrap(KDF(DH-Shared, context), CEK) 2106 The COSE_Encrypt structure for the recipient is organized as follows: 2108 * The 'protected' field is fed into the KDF context structure. 2110 * The plaintext to be encrypted is the key from the next layer down 2111 (usually the content layer). 2113 * The 'alg' header parameter MUST be present in the layer. 2115 * A header parameter identifying the recipient's key SHOULD be 2116 present. A header parameter identifying the sender's key SHOULD 2117 be present. 2119 10. CBOR Encoding Restrictions 2121 The document limits the restrictions it imposes on the CBOR Encoder 2122 needs to work. We have managed to narrow it down to the following 2123 restrictions: 2125 * The restriction applies to the encoding of the Sig_structure, the 2126 Enc_structure, and the MAC_structure. 2128 * Encoding MUST be done using definite lengths and values MUST be 2129 the minimum possible length. This means that the integer 1 is 2130 encoded as "0x01" and not "0x1801". 2132 * Applications MUST NOT generate messages with the same label used 2133 twice as a key in a single map. Applications MUST NOT parse and 2134 process messages with the same label used twice as a key in a 2135 single map. Applications can enforce the parse and process 2136 requirement by using parsers that will fail the parse step or by 2137 using parsers that will pass all keys to the application, and the 2138 application can perform the check for duplicate keys. 2140 11. Application Profiling Considerations 2142 This document is designed to provide a set of security services, but 2143 not impose algorithm implementation requirements for specific usage. 2144 The interoperability requirements are provided for how each of the 2145 individual services are used and how the algorithms are to be used 2146 for interoperability. The requirements about which algorithms and 2147 which services are needed are deferred to each application. 2149 An example of a profile can be found in [RFC8613] where one was 2150 developed for carrying content in combination with CoAP headers. 2152 It is intended that a profile of this document be created that 2153 defines the interoperability requirements for that specific 2154 application. This section provides a set of guidelines and topics 2155 that need to be considered when profiling this document. 2157 * Applications need to determine the set of messages defined in this 2158 document that they will be using. The set of messages corresponds 2159 fairly directly to the set of security services that are needed 2160 and to the security levels needed. 2162 * Applications may define new header parameters for a specific 2163 purpose. Applications will often times select specific header 2164 parameters to use or not to use. For example, an application 2165 would normally state a preference for using either the IV or the 2166 Partial IV header parameter. If the Partial IV header parameter 2167 is specified, then the application also needs to define how the 2168 fixed portion of the IV is determined. 2170 * When applications use externally defined authenticated data, they 2171 need to define how that data is encoded. This document assumes 2172 that the data will be provided as a byte string. More information 2173 can be found in Section 4.3. 2175 * Applications need to determine the set of security algorithms that 2176 are to be used. When selecting the algorithms to be used as the 2177 mandatory-to-implement set, consideration should be given to 2178 choosing different types of algorithms when two are chosen for a 2179 specific purpose. An example of this would be choosing HMAC- 2180 SHA512 and AES-CMAC as different MAC algorithms; the construction 2181 is vastly different between these two algorithms. This means that 2182 a weakening of one algorithm would be unlikely to lead to a 2183 weakening of the other algorithms. Of course, these algorithms do 2184 not provide the same level of security and thus may not be 2185 comparable for the desired security functionality. 2187 * Applications may need to provide some type of negotiation or 2188 discovery method if multiple algorithms or message structures are 2189 permitted. The method can be as simple as requiring pre- 2190 configuration of the set of algorithms to providing a discovery 2191 method built into the protocol. S/MIME provided a number of 2192 different ways to approach the problem that applications could 2193 follow: 2195 - Advertising in the message (S/MIME capabilities) [RFC5751]. 2197 - Advertising in the certificate (capabilities extension) 2198 [RFC4262]. 2200 - Minimum requirements for the S/MIME, which have been updated 2201 over time [RFC2633] [RFC5751] (note that [RFC2633] has been 2202 obsoleted by [RFC5751]). 2204 12. IANA Considerations 2206 The registries and registrations listed below were created during 2207 processing of RFC 8152 [RFC8152]. The only known action at this time 2208 is to update the references. 2210 12.1. CBOR Tag Assignment 2212 IANA assigned tags in the "CBOR Tags" registry as part of processing 2213 [RFC8152]. IANA is requested to update the references from [RFC8152] 2214 to this document. 2216 IANA is requested to register a new tag for the CounterSignature 2217 type. 2219 * Tag: TBD0 2221 * Data Item: COSE_Signature 2223 * Semantics: COSE standalone counter signature 2225 * Reference: [[this document]] 2227 12.2. COSE Header Parameters Registry 2229 IANA created a registry titled "COSE Header Parameters" as part of 2230 processing [RFC8152]. The registry has been created to use the 2231 "Expert Review Required" registration procedure [RFC8126]. 2233 IANA is requested to update the reference for entries in the table 2234 from [RFC8152] to this document. This document does not update the 2235 expert review guidelines provided in [RFC8152]. 2237 12.3. COSE Header Algorithm Parameters Registry 2239 IANA created a registry titled "COSE Header Algorithm Parameters" as 2240 part of processing [RFC8152]. The registry has been created to use 2241 the "Expert Review Required" registration procedure [RFC8126]. 2243 IANA is requested to update the references from [RFC8152] to this 2244 document. This document does not update the expert review guidelines 2245 provided in [RFC8152]. 2247 12.4. COSE Key Common Parameters Registry 2249 IANA created a registry titled "COSE Key Common Parameters" as part 2250 of the processing of [RFC8152]. The registry has been created to use 2251 the "Expert Review Required" registration procedure [RFC8126]. 2253 IANA is requested to update the reference for entries in the table 2254 from [RFC8152] to this document. This document does not update the 2255 expert review guidelines provided in [RFC8152]. 2257 12.5. Media Type Registrations 2259 12.5.1. COSE Security Message 2261 This section registers the 'application/cose' media type in the 2262 "Media Types" registry. These media types are used to indicate that 2263 the content is a COSE message. 2265 Type name: application 2267 Subtype name: cose 2269 Required parameters: N/A 2271 Optional parameters: cose-type 2273 Encoding considerations: binary 2275 Security considerations: See the Security Considerations section 2276 of [[This Document]]. 2278 Interoperability considerations: N/A 2280 Published specification: [[this document]] 2282 Applications that use this media type: IoT applications sending 2283 security content over HTTP(S) transports. 2285 Fragment identifier considerations: N/A 2287 Additional information: 2289 - Deprecated alias names for this type: N/A 2291 - Magic number(s): N/A 2293 - File extension(s): cbor 2295 - Macintosh file type code(s): N/A 2297 Person & email address to contact for further information: 2298 iesg@ietf.org 2300 Intended usage: COMMON 2301 Restrictions on usage: N/A 2303 Author: Jim Schaad, ietf@augustcellars.com 2305 Change Controller: IESG 2307 Provisional registration? No 2309 12.5.2. COSE Key Media Type 2311 This section registers the 'application/cose-key' and 'application/ 2312 cose-key-set' media types in the "Media Types" registry. These media 2313 types are used to indicate, respectively, that content is a COSE_Key 2314 or COSE_KeySet object. 2316 The template for registering 'application/cose-key' is: 2318 Type name: application 2320 Subtype name: cose-key 2322 Required parameters: N/A 2324 Optional parameters: N/A 2326 Encoding considerations: binary 2328 Security considerations: See the Security Considerations section 2329 of [[This Document]]. 2331 Interoperability considerations: N/A 2333 Published specification: [[this document]] 2335 Applications that use this media type: Distribution of COSE based 2336 keys for IoT applications. 2338 Fragment identifier considerations: N/A 2340 Additional information: 2342 - Deprecated alias names for this type: N/A 2344 - Magic number(s): N/A 2346 - File extension(s): cbor 2348 - Macintosh file type code(s): N/A 2349 Person & email address to contact for further information: 2350 iesg@ietf.org 2352 Intended usage: COMMON 2354 Restrictions on usage: N/A 2356 Author: Jim Schaad, ietf@augustcellars.com 2358 Change Controller: IESG 2360 Provisional registration? No 2362 The template for registering 'application/cose-key-set' is: 2364 Type name: application 2366 Subtype name: cose-key-set 2368 Required parameters: N/A 2370 Optional parameters: N/A 2372 Encoding considerations: binary 2374 Security considerations: See the Security Considerations section 2375 of [[This Document]]. 2377 Interoperability considerations: N/A 2379 Published specification: [[this document]] 2381 Applications that use this media type: Distribution of COSE based 2382 keys for IoT applications. 2384 Fragment identifier considerations: N/A 2386 Additional information: 2388 - Deprecated alias names for this type: N/A 2390 - Magic number(s): N/A 2392 - File extension(s): cbor 2394 - Macintosh file type code(s): N/A 2395 Person & email address to contact for further information: 2396 iesg@ietf.org 2398 Intended usage: COMMON 2400 Restrictions on usage: N/A 2402 Author: Jim Schaad, ietf@augustcellars.com 2404 Change Controller: IESG 2406 Provisional registration? No 2408 12.6. CoAP Content-Formats Registry 2410 IANA added the following entries to the "CoAP Content-Formats" 2411 registry while processing [RFC8152]. IANA is requested to update the 2412 reference value from [RFC8152] to [[This Document]]. 2414 13. Security Considerations 2416 There are a number of security considerations that need to be taken 2417 into account by implementers of this specification. The security 2418 considerations that are specific to an individual algorithm are 2419 placed next to the description of the algorithm. While some 2420 considerations have been highlighted here, additional considerations 2421 may be found in the documents listed in the references. 2423 Implementations need to protect the private key material for any 2424 individuals. There are some cases that need to be highlighted on 2425 this issue. 2427 * Using the same key for two different algorithms can leak 2428 information about the key. It is therefore recommended that keys 2429 be restricted to a single algorithm. 2431 * Use of 'direct' as a recipient algorithm combined with a second 2432 recipient algorithm exposes the direct key to the second 2433 recipient. 2435 * Several of the algorithms in [I-D.ietf-cose-rfc8152bis-algs] have 2436 limits on the number of times that a key can be used without 2437 leaking information about the key. 2439 The use of ECDH and direct plus KDF (with no key wrap) will not 2440 directly lead to the private key being leaked; the one way function 2441 of the KDF will prevent that. There is, however, a different issue 2442 that needs to be addressed. Having two recipients requires that the 2443 CEK be shared between two recipients. The second recipient therefore 2444 has a CEK that was derived from material that can be used for the 2445 weak proof of origin. The second recipient could create a message 2446 using the same CEK and send it to the first recipient; the first 2447 recipient would, for either static-static ECDH or direct plus KDF, 2448 make an assumption that the CEK could be used for proof of origin 2449 even though it is from the wrong entity. If the key wrap step is 2450 added, then no proof of origin is implied and this is not an issue. 2452 Although it has been mentioned before, the use of a single key for 2453 multiple algorithms has been demonstrated in some cases to leak 2454 information about that key, provide the opportunity for attackers to 2455 forge integrity tags, or gain information about encrypted content. 2456 Binding a key to a single algorithm prevents these problems. Key 2457 creators and key consumers are strongly encouraged not only to create 2458 new keys for each different algorithm, but to include that selection 2459 of algorithm in any distribution of key material and strictly enforce 2460 the matching of algorithms in the key structure to algorithms in the 2461 message structure. In addition to checking that algorithms are 2462 correct, the key form needs to be checked as well. Do not use an 2463 'EC2' key where an 'OKP' key is expected. 2465 Before using a key for transmission, or before acting on information 2466 received, a trust decision on a key needs to be made. Is the data or 2467 action something that the entity associated with the key has a right 2468 to see or a right to request? A number of factors are associated 2469 with this trust decision. Some of the ones that are highlighted here 2470 are: 2472 * What are the permissions associated with the key owner? 2474 * Is the cryptographic algorithm acceptable in the current context? 2476 * Have the restrictions associated with the key, such as algorithm 2477 or freshness, been checked and are they correct? 2479 * Is the request something that is reasonable, given the current 2480 state of the application? 2482 * Have any security considerations that are part of the message been 2483 enforced (as specified by the application or 'crit' header 2484 parameter)? 2486 There are a large number of algorithms presented in 2487 [I-D.ietf-cose-rfc8152bis-algs] that use nonce values. Nonces 2488 generally have some type of restriction on their values. Generally a 2489 nonce needs to be a unique value either for a key or for some other 2490 conditions. In all of these cases, there is no known requirement on 2491 the nonce being both unique and unpredictable; under these 2492 circumstances, it's reasonable to use a counter for creation of the 2493 nonce. In cases where one wants the pattern of the nonce to be 2494 unpredictable as well as unique, one can use a key created for that 2495 purpose and encrypt the counter to produce the nonce value. 2497 One area that has been starting to get exposure is doing traffic 2498 analysis of encrypted messages based on the length of the message. 2499 This specification does not provide for a uniform method of providing 2500 padding as part of the message structure. An observer can 2501 distinguish between two different messages (for example, 'YES' and 2502 'NO') based on the length for all of the content encryption 2503 algorithms that are defined in [I-D.ietf-cose-rfc8152bis-algs] 2504 document. This means that it is up to the applications to document 2505 how content padding is to be done in order to prevent or discourage 2506 such analysis. (For example, the text strings could be defined as 2507 'YES' and 'NO '.) 2509 14. Implementation Status 2511 This section is to be removed before publishing as an RFC. 2513 This section records the status of known implementations of the 2514 protocol defined by this specification at the time of posting of this 2515 Internet-Draft, and is based on a proposal described in [RFC7942]. 2516 The description of implementations in this section is intended to 2517 assist the IETF in its decision processes in progressing drafts to 2518 RFCs. Please note that the listing of any individual implementation 2519 here does not imply endorsement by the IETF. Furthermore, no effort 2520 has been spent to verify the information presented here that was 2521 supplied by IETF contributors. This is not intended as, and must not 2522 be construed to be, a catalog of available implementations or their 2523 features. Readers are advised to note that other implementations may 2524 exist. 2526 According to [RFC7942], "this will allow reviewers and working groups 2527 to assign due consideration to documents that have the benefit of 2528 running code, which may serve as evidence of valuable experimentation 2529 and feedback that have made the implemented protocols more mature. 2530 It is up to the individual working groups to use this information as 2531 they see fit". 2533 14.1. Author's Versions 2535 There are three different implementations that have been created by 2536 the author of the document both to create the examples that are 2537 included in the document and to validate the structures and 2538 methodology used in the design of COSE. 2540 * Implementation Location: https://github.com/cose-wg 2542 * Primary Maintainer: Jim Schaad 2544 * Languages: There are three different languages that are currently 2545 supported: Java, C# and C. 2547 * Cryptography: The Java and C# libraries use Bouncy Castle to 2548 provide the required cryptography. The C version uses OPENSSL 2549 Version 1.0 for the cryptography. 2551 * Coverage: The C version currently does not have full counter sign 2552 support. The other two versions do. They do have support to 2553 allow for implicit algorithm support as they allow for the 2554 application to set attributes that are not to be sent in the 2555 message. 2557 * Testing: All of the examples in the example library are generated 2558 by the C# library and then validated using the Java and C 2559 libraries. All three libraries have tests to allow for the 2560 creating of the same messages that are in the example library 2561 followed by validating them. These are not compared against the 2562 example library. The Java and C# libraries have unit testing 2563 included. Not all of the MUST statements in the document have 2564 been implemented as part of the libraries. One such statement is 2565 the requirement that unique labels be present. 2567 * Licensing: Revised BSD License 2569 14.2. JavaScript Version 2571 * Implementation Location: https://github.com/erdtman/cose-js 2573 * Primary Maintainer: Samuel Erdtman 2575 * Languages: JavaScript 2577 * Cryptography: TBD 2579 * Coverage: Full Encrypt, Signature and MAC objects are supported. 2581 * Testing: Basic testing against the common example library. 2583 * Licensing: Apache License 2.0 2585 14.3. Python Version 2586 * Implementation Location: https://github.com/TimothyClaeys/COSE- 2587 PYTHON 2589 * Primary Maintainer: Timothy Claeys 2591 * Languages: Python 2593 * Cryptography: pyecdsak, crypto python libraries 2595 * Coverage: TBD 2597 * Testing: Basic testing plus running against the common example 2598 library. 2600 * Licensing: BSD 3-Clause License 2602 14.4. COSE Testing Library 2604 * Implementation Location: https://github.com/cose-wg/Examples 2606 * Primary Maintainer: Jim Schaad 2608 * Description: A set of tests for the COSE library is provided as 2609 part of the implementation effort. Both success and fail tests 2610 have been provided. All of the examples in this document are part 2611 of this example set. 2613 * Coverage: An attempt has been made to have test cases for every 2614 message type and algorithm in the document. Currently examples 2615 dealing with counter signatures, and ECDH with Curve24459 and 2616 Goldilocks are missing. 2618 * Licensing: Public Domain 2620 15. References 2622 15.1. Normative References 2624 [COAP.Formats] 2625 IANA, "CoAP Content-Formats", 2626 . 2629 [COSE.Algorithms] 2630 IANA, "COSE Algorithms", 2631 . 2634 [COSE.KeyParameters] 2635 IANA, "COSE Key Parameters", 2636 . 2639 [COSE.KeyTypes] 2640 IANA, "COSE Key Types", 2641 . 2644 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2645 Requirement Levels", BCP 14, RFC 2119, 2646 DOI 10.17487/RFC2119, March 1997, 2647 . 2649 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 2650 Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, 2651 October 2013, . 2653 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2654 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 2655 May 2017, . 2657 [DSS] National Institute of Standards and Technology, "Digital 2658 Signature Standard (DSS)", DOI 10.6028/NIST.FIPS.186-4, 2659 FIPS PUB 186-4, July 2013, 2660 . 2663 [RFC8032] Josefsson, S. and I. Liusvaara, "Edwards-Curve Digital 2664 Signature Algorithm (EdDSA)", RFC 8032, 2665 DOI 10.17487/RFC8032, January 2017, 2666 . 2668 [I-D.ietf-cose-rfc8152bis-algs] 2669 Schaad, J., "CBOR Object Signing and Encryption (COSE): 2670 Initial Algorithms", Work in Progress, Internet-Draft, 2671 draft-ietf-cose-rfc8152bis-algs-07, 9 March 2020, 2672 . 2675 15.2. Informative References 2677 [RFC8152] Schaad, J., "CBOR Object Signing and Encryption (COSE)", 2678 RFC 8152, DOI 10.17487/RFC8152, July 2017, 2679 . 2681 [RFC8610] Birkholz, H., Vigano, C., and C. Bormann, "Concise Data 2682 Definition Language (CDDL): A Notational Convention to 2683 Express Concise Binary Object Representation (CBOR) and 2684 JSON Data Structures", RFC 8610, DOI 10.17487/RFC8610, 2685 June 2019, . 2687 [RFC8018] Moriarty, K., Ed., Kaliski, B., and A. Rusch, "PKCS #5: 2688 Password-Based Cryptography Specification Version 2.1", 2689 RFC 8018, DOI 10.17487/RFC8018, January 2017, 2690 . 2692 [RFC2633] Ramsdell, B., Ed., "S/MIME Version 3 Message 2693 Specification", RFC 2633, DOI 10.17487/RFC2633, June 1999, 2694 . 2696 [RFC4262] Santesson, S., "X.509 Certificate Extension for Secure/ 2697 Multipurpose Internet Mail Extensions (S/MIME) 2698 Capabilities", RFC 4262, DOI 10.17487/RFC4262, December 2699 2005, . 2701 [RFC4949] Shirey, R., "Internet Security Glossary, Version 2", 2702 FYI 36, RFC 4949, DOI 10.17487/RFC4949, August 2007, 2703 . 2705 [RFC5116] McGrew, D., "An Interface and Algorithms for Authenticated 2706 Encryption", RFC 5116, DOI 10.17487/RFC5116, January 2008, 2707 . 2709 [RFC5652] Housley, R., "Cryptographic Message Syntax (CMS)", STD 70, 2710 RFC 5652, DOI 10.17487/RFC5652, September 2009, 2711 . 2713 [RFC5751] Ramsdell, B. and S. Turner, "Secure/Multipurpose Internet 2714 Mail Extensions (S/MIME) Version 3.2 Message 2715 Specification", RFC 5751, DOI 10.17487/RFC5751, January 2716 2010, . 2718 [RFC5752] Turner, S. and J. Schaad, "Multiple Signatures in 2719 Cryptographic Message Syntax (CMS)", RFC 5752, 2720 DOI 10.17487/RFC5752, January 2010, 2721 . 2723 [RFC5990] Randall, J., Kaliski, B., Brainard, J., and S. Turner, 2724 "Use of the RSA-KEM Key Transport Algorithm in the 2725 Cryptographic Message Syntax (CMS)", RFC 5990, 2726 DOI 10.17487/RFC5990, September 2010, 2727 . 2729 [RFC6838] Freed, N., Klensin, J., and T. Hansen, "Media Type 2730 Specifications and Registration Procedures", BCP 13, 2731 RFC 6838, DOI 10.17487/RFC6838, January 2013, 2732 . 2734 [RFC8259] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 2735 Interchange Format", STD 90, RFC 8259, 2736 DOI 10.17487/RFC8259, December 2017, 2737 . 2739 [RFC7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 2740 Application Protocol (CoAP)", RFC 7252, 2741 DOI 10.17487/RFC7252, June 2014, 2742 . 2744 [RFC7515] Jones, M., Bradley, J., and N. Sakimura, "JSON Web 2745 Signature (JWS)", RFC 7515, DOI 10.17487/RFC7515, May 2746 2015, . 2748 [RFC7516] Jones, M. and J. Hildebrand, "JSON Web Encryption (JWE)", 2749 RFC 7516, DOI 10.17487/RFC7516, May 2015, 2750 . 2752 [RFC7517] Jones, M., "JSON Web Key (JWK)", RFC 7517, 2753 DOI 10.17487/RFC7517, May 2015, 2754 . 2756 [RFC7518] Jones, M., "JSON Web Algorithms (JWA)", RFC 7518, 2757 DOI 10.17487/RFC7518, May 2015, 2758 . 2760 [RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for 2761 Writing an IANA Considerations Section in RFCs", BCP 26, 2762 RFC 8126, DOI 10.17487/RFC8126, June 2017, 2763 . 2765 [PVSig] Brown, D. and D. Johnson, "Formal Security Proofs for a 2766 Signature Scheme with Partial Message Recovery", 2767 DOI 10.1007/3-540-45353-9_11, LNCS Volume 2020, June 2000, 2768 . 2770 [W3C.WebCrypto] 2771 Watson, M., "Web Cryptography API", W3C Recommendation, 2772 January 2017, . 2774 [RFC8613] Selander, G., Mattsson, J., Palombini, F., and L. Seitz, 2775 "Object Security for Constrained RESTful Environments 2776 (OSCORE)", RFC 8613, DOI 10.17487/RFC8613, July 2019, 2777 . 2779 [RFC8230] Jones, M., "Using RSA Algorithms with CBOR Object Signing 2780 and Encryption (COSE) Messages", RFC 8230, 2781 DOI 10.17487/RFC8230, September 2017, 2782 . 2784 [RFC7942] Sheffer, Y. and A. Farrel, "Improving Awareness of Running 2785 Code: The Implementation Status Section", BCP 205, 2786 RFC 7942, DOI 10.17487/RFC7942, July 2016, 2787 . 2789 [RFC4998] Gondrom, T., Brandner, R., and U. Pordesch, "Evidence 2790 Record Syntax (ERS)", RFC 4998, DOI 10.17487/RFC4998, 2791 August 2007, . 2793 Appendix A. Guidelines for External Data Authentication of Algorithms 2795 During development of COSE, the requirement that the algorithm 2796 identifier be located in the protected attributes was relaxed from a 2797 must to a should. There were two basic reasons that have been 2798 advanced to support this position. First, the resulting message will 2799 be smaller if the algorithm identifier is omitted from the most 2800 common messages in a CoAP environment. Second, there is a potential 2801 bug that will arise if full checking is not done correctly between 2802 the different places that an algorithm identifier could be placed 2803 (the message itself, an application statement, the key structure that 2804 the sender possesses, and the key structure the recipient possesses). 2806 This appendix lays out how such a change can be made and the details 2807 that an application needs to specify in order to use this option. 2808 Two different sets of details are specified: those needed to omit an 2809 algorithm identifier and those needed to use a variant on the counter 2810 signature attribute that contains no attributes about itself. 2812 Three sets of recommendations are laid out. The first set of 2813 recommendations applies to having an implicit algorithm identified 2814 for a single layer of a COSE object. The second set of 2815 recommendations applies to having multiple implicit algorithms 2816 identified for multiple layers of a COSE object. The third set of 2817 recommendations applies to having implicit algorithms for multiple 2818 COSE object constructs. 2820 The key words from [RFC2119] are deliberately not used here. This 2821 specification can provide recommendations, but it cannot enforce 2822 them. 2824 This set of recommendations applies to the case where an application 2825 is distributing a fixed algorithm along with the key information for 2826 use in a single COSE object. This normally applies to the smallest 2827 of the COSE objects, specifically COSE_Sign1, COSE_Mac0, and 2828 COSE_Encrypt0, but could apply to the other structures as well. 2830 The following items should be taken into account: 2832 * Applications need to list the set of COSE structures that implicit 2833 algorithms are to be used in. Applications need to require that 2834 the receipt of an explicit algorithm identifier in one of these 2835 structures will lead to the message being rejected. This 2836 requirement is stated so that there will never be a case where 2837 there is any ambiguity about the question of which algorithm 2838 should be used, the implicit or the explicit one. This applies 2839 even if the transported algorithm identifier is a protected 2840 attribute. This applies even if the transported algorithm is the 2841 same as the implicit algorithm. 2843 * Applications need to define the set of information that is to be 2844 considered to be part of a context when omitting algorithm 2845 identifiers. At a minimum, this would be the key identifier (if 2846 needed), the key, the algorithm, and the COSE structure it is used 2847 with. Applications should restrict the use of a single key to a 2848 single algorithm. As noted for some of the algorithms in 2849 [I-D.ietf-cose-rfc8152bis-algs], the use of the same key in 2850 different related algorithms can lead to leakage of information 2851 about the key, leakage about the data or the ability to perform 2852 forgeries. 2854 * In many cases, applications that make the algorithm identifier 2855 implicit will also want to make the context identifier implicit 2856 for the same reason. That is, omitting the context identifier 2857 will decrease the message size (potentially significantly 2858 depending on the length of the identifier). Applications that do 2859 this will need to describe the circumstances where the context 2860 identifier is to be omitted and how the context identifier is to 2861 be inferred in these cases. (An exhaustive search over all of the 2862 keys would normally not be considered to be acceptable.) An 2863 example of how this can be done is to tie the context to a 2864 transaction identifier. Both would be sent on the original 2865 message, but only the transaction identifier would need to be sent 2866 after that point as the context is tied into the transaction 2867 identifier. Another way would be to associate a context with a 2868 network address. All messages coming from a single network 2869 address can be assumed to be associated with a specific context. 2870 (In this case, the address would normally be distributed as part 2871 of the context.) 2873 * Applications cannot rely on key identifiers being unique unless 2874 they take significant efforts to ensure that they are computed in 2875 such a way as to create this guarantee. Even when an application 2876 does this, the uniqueness might be violated if the application is 2877 run in different contexts (i.e., with a different context 2878 provider) or if the system combines the security contexts from 2879 different applications together into a single store. 2881 * Applications should continue the practice of protecting the 2882 algorithm identifier. Since this is not done by placing it in the 2883 protected attributes field, applications should define an 2884 application-specific external data structure that includes this 2885 value. This external data field can be used as such for content 2886 encryption, MAC, and signature algorithms. It can be used in the 2887 SuppPrivInfo field for those algorithms that use a KDF to derive a 2888 key value. Applications may also want to protect other 2889 information that is part of the context structure as well. It 2890 should be noted that those fields, such as the key or a Base IV, 2891 are protected by virtue of being used in the cryptographic 2892 computation and do not need to be included in the external data 2893 field. 2895 The second case is having multiple implicit algorithm identifiers 2896 specified for a multiple layer COSE object. An example of how this 2897 would work is the encryption context that an application specifies, 2898 which contains a content encryption algorithm, a key wrap algorithm, 2899 a key identifier, and a shared secret. The sender omits sending the 2900 algorithm identifier for both the content layer and the recipient 2901 layer leaving only the key identifier. The receiver then uses the 2902 key identifier to get the implicit algorithm identifiers. 2904 The following additional items need to be taken into consideration: 2906 * Applications that want to support this will need to define a 2907 structure that allows for, and clearly identifies, both the COSE 2908 structure to be used with a given key and the structure and 2909 algorithm to be used for the secondary layer. The key for the 2910 secondary layer is computed as normal from the recipient layer. 2912 The third case is having multiple implicit algorithm identifiers, but 2913 targeted at potentially unrelated layers or different COSE objects. 2914 There are a number of different scenarios where this might be 2915 applicable. Some of these scenarios are: 2917 * Two contexts are distributed as a pair. Each of the contexts is 2918 for use with a COSE_Encrypt message. Each context will consist of 2919 distinct secret keys and IVs and potentially even different 2920 algorithms. One context is for sending messages from party A to 2921 party B, and the second context is for sending messages from party 2922 B to party A. This means that there is no chance for a reflection 2923 attack to occur as each party uses different secret keys to send 2924 its messages; a message that is reflected back to it would fail to 2925 decrypt. 2927 * Two contexts are distributed as a pair. The first context is used 2928 for encryption of the message, and the second context is used to 2929 place a counter signature on the message. The intention is that 2930 the second context can be distributed to other entities 2931 independently of the first context. This allows these entities to 2932 validate that the message came from an individual without being 2933 able to decrypt the message and see the content. 2935 * Two contexts are distributed as a pair. The first context 2936 contains a key for dealing with MACed messages, and the second 2937 context contains a different key for dealing with encrypted 2938 messages. This allows for a unified distribution of keys to 2939 participants for different types of messages that have different 2940 keys, but where the keys may be used in a coordinated manner. 2942 For these cases, the following additional items need to be 2943 considered: 2945 * Applications need to ensure that the multiple contexts stay 2946 associated. If one of the contexts is invalidated for any reason, 2947 all of the contexts associated with it should also be invalidated. 2949 Appendix B. Two Layers of Recipient Information 2951 All of the currently defined recipient algorithm classes only use two 2952 layers of the COSE_Encrypt structure. The first layer is the message 2953 content, and the second layer is the content key encryption. 2954 However, if one uses a recipient algorithm such as the RSA Key 2955 Encapsulation Mechanism (RSA-KEM) (see Appendix A of RSA-KEM 2956 [RFC5990]), then it makes sense to have three layers of the 2957 COSE_Encrypt structure. 2959 These layers would be: 2961 * Layer 0: The content encryption layer. This layer contains the 2962 payload of the message. 2964 * Layer 1: The encryption of the CEK by a KEK. 2966 * Layer 2: The encryption of a long random secret using an RSA key 2967 and a key derivation function to convert that secret into the KEK. 2969 This is an example of what a triple layer message would look like. 2970 The message has the following layers: 2972 * Layer 0: Has a content encrypted with AES-GCM using a 128-bit key. 2974 * Layer 1: Uses the AES Key Wrap algorithm with a 128-bit key. 2976 * Layer 2: Uses ECDH Ephemeral-Static direct to generate the layer 1 2977 key. 2979 In effect, this example is a decomposed version of using the 2980 ECDH-ES+A128KW algorithm. 2982 Size of binary file is 183 bytes 2983 96( 2984 [ 2985 / protected / h'a10101' / { 2986 \ alg \ 1:1 \ AES-GCM 128 \ 2987 } / , 2988 / unprotected / { 2989 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 2990 }, 2991 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e2852948658f0 2992 811139868826e89218a75715b', 2993 / recipients / [ 2994 [ 2995 / protected / h'', 2996 / unprotected / { 2997 / alg / 1:-3 / A128KW / 2998 }, 2999 / ciphertext / h'dbd43c4e9d719c27c6275c67d628d493f090593db82 3000 18f11', 3001 / recipients / [ 3002 [ 3003 / protected / h'a1013818' / { 3004 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 3005 } / , 3006 / unprotected / { 3007 / ephemeral / -1:{ 3008 / kty / 1:2, 3009 / crv / -1:1, 3010 / x / -2:h'b2add44368ea6d641f9ca9af308b4079aeb519f11 3011 e9b8a55a600b21233e86e68', 3012 / y / -3:false 3013 }, 3014 / kid / 4:'meriadoc.brandybuck@buckland.example' 3015 }, 3016 / ciphertext / h'' 3017 ] 3018 ] 3019 ] 3020 ] 3021 ] 3022 ) 3024 Appendix C. Examples 3026 This appendix includes a set of examples that show the different 3027 features and message types that have been defined in this document. 3028 To make the examples easier to read, they are presented using the 3029 extended CBOR diagnostic notation (defined in [RFC8610]) rather than 3030 as a binary dump. 3032 A GitHub project has been created at that contains not only the examples presented in this 3034 document, but a more complete set of testing examples as well. Each 3035 example is found in a JSON file that contains the inputs used to 3036 create the example, some of the intermediate values that can be used 3037 in debugging the example and the output of the example presented both 3038 as a hex dump and in CBOR diagnostic notation format. Some of the 3039 examples at the site are designed failure testing cases; these are 3040 clearly marked as such in the JSON file. If errors in the examples 3041 in this document are found, the examples on GitHub will be updated, 3042 and a note to that effect will be placed in the JSON file. 3044 As noted, the examples are presented using the CBOR's diagnostic 3045 notation. A Ruby-based tool exists that can convert between the 3046 diagnostic notation and binary. This tool can be installed with the 3047 command line: 3049 gem install cbor-diag 3051 The diagnostic notation can be converted into binary files using the 3052 following command line: 3054 diag2cbor.rb < inputfile > outputfile 3056 The examples can be extracted from the XML version of this document 3057 via an XPath expression as all of the sourcecode is tagged with the 3058 attribute type='CBORdiag'. (Depending on the XPath evaluator one is 3059 using, it may be necessary to deal with > as an entity.) 3061 //sourcecode[@type='CDDL']/text() 3063 C.1. Examples of Signed Messages 3065 C.1.1. Single Signature 3067 This example uses the following: 3069 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3071 Size of binary file is 103 bytes 3072 98( 3073 [ 3074 / protected / h'', 3075 / unprotected / {}, 3076 / payload / 'This is the content.', 3077 / signatures / [ 3078 [ 3079 / protected / h'a10126' / { 3080 \ alg \ 1:-7 \ ECDSA 256 \ 3081 } / , 3082 / unprotected / { 3083 / kid / 4:'11' 3084 }, 3085 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3086 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3087 98f53afd2fa0f30a' 3088 ] 3089 ] 3090 ] 3091 ) 3093 C.1.2. Multiple Signers 3095 This example uses the following: 3097 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3099 * Signature Algorithm: ECDSA w/ SHA-512, Curve P-521 3101 Size of binary file is 277 bytes 3102 98( 3103 [ 3104 / protected / h'', 3105 / unprotected / {}, 3106 / payload / 'This is the content.', 3107 / signatures / [ 3108 [ 3109 / protected / h'a10126' / { 3110 \ alg \ 1:-7 \ ECDSA 256 \ 3111 } / , 3112 / unprotected / { 3113 / kid / 4:'11' 3114 }, 3115 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3116 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3117 98f53afd2fa0f30a' 3118 ], 3119 [ 3120 / protected / h'a1013823' / { 3121 \ alg \ 1:-36 3122 } / , 3123 / unprotected / { 3124 / kid / 4:'bilbo.baggins@hobbiton.example' 3125 }, 3126 / signature / h'00a2d28a7c2bdb1587877420f65adf7d0b9a06635dd1 3127 de64bb62974c863f0b160dd2163734034e6ac003b01e8705524c5c4ca479a952f024 3128 7ee8cb0b4fb7397ba08d009e0c8bf482270cc5771aa143966e5a469a09f613488030 3129 c5b07ec6d722e3835adb5b2d8c44e95ffb13877dd2582866883535de3bb03d01753f 3130 83ab87bb4f7a0297' 3131 ] 3132 ] 3133 ] 3134 ) 3136 C.1.3. Counter Signature 3138 This example uses the following: 3140 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3142 * The same header parameters are used for both the signature and the 3143 counter signature. 3145 Size of binary file is 180 bytes 3146 98( 3147 [ 3148 / protected / h'', 3149 / unprotected / { 3150 / countersign / 7:[ 3151 / protected / h'a10126' / { 3152 \ alg \ 1:-7 \ ECDSA 256 \ 3153 } / , 3154 / unprotected / { 3155 / kid / 4:'11' 3156 }, 3157 / signature / h'5ac05e289d5d0e1b0a7f048a5d2b643813ded50bc9e4 3158 9220f4f7278f85f19d4a77d655c9d3b51e805a74b099e1e085aacd97fc29d72f887e 3159 8802bb6650cceb2c' 3160 ] 3161 }, 3162 / payload / 'This is the content.', 3163 / signatures / [ 3164 [ 3165 / protected / h'a10126' / { 3166 \ alg \ 1:-7 \ ECDSA 256 \ 3167 } / , 3168 / unprotected / { 3169 / kid / 4:'11' 3170 }, 3171 / signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb 3172 5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b 3173 98f53afd2fa0f30a' 3174 ] 3175 ] 3176 ] 3177 ) 3179 C.1.4. Signature with Criticality 3181 This example uses the following: 3183 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3185 * There is a criticality marker on the "reserved" header parameter 3187 Size of binary file is 125 bytes 3188 98( 3189 [ 3190 / protected / h'a2687265736572766564f40281687265736572766564' / 3191 { 3192 "reserved":false, 3193 \ crit \ 2:[ 3194 "reserved" 3195 ] 3196 } / , 3197 / unprotected / {}, 3198 / payload / 'This is the content.', 3199 / signatures / [ 3200 [ 3201 / protected / h'a10126' / { 3202 \ alg \ 1:-7 \ ECDSA 256 \ 3203 } / , 3204 / unprotected / { 3205 / kid / 4:'11' 3206 }, 3207 / signature / h'3fc54702aa56e1b2cb20284294c9106a63f91bac658d 3208 69351210a031d8fc7c5ff3e4be39445b1a3e83e1510d1aca2f2e8a7c081c7645042b 3209 18aba9d1fad1bd9c' 3210 ] 3211 ] 3212 ] 3213 ) 3215 C.2. Single Signer Examples 3217 C.2.1. Single ECDSA Signature 3219 This example uses the following: 3221 * Signature Algorithm: ECDSA w/ SHA-256, Curve P-256 3223 Size of binary file is 98 bytes 3224 18( 3225 [ 3226 / protected / h'a10126' / { 3227 \ alg \ 1:-7 \ ECDSA 256 \ 3228 } / , 3229 / unprotected / { 3230 / kid / 4:'11' 3231 }, 3232 / payload / 'This is the content.', 3233 / signature / h'8eb33e4ca31d1c465ab05aac34cc6b23d58fef5c083106c4 3234 d25a91aef0b0117e2af9a291aa32e14ab834dc56ed2a223444547e01f11d3b0916e5 3235 a4c345cacb36' 3236 ] 3237 ) 3239 C.3. Examples of Enveloped Messages 3241 C.3.1. Direct ECDH 3243 This example uses the following: 3245 * CEK: AES-GCM w/ 128-bit key 3247 * Recipient class: ECDH Ephemeral-Static, Curve P-256 3249 Size of binary file is 151 bytes 3250 96( 3251 [ 3252 / protected / h'a10101' / { 3253 \ alg \ 1:1 \ AES-GCM 128 \ 3254 } / , 3255 / unprotected / { 3256 / iv / 5:h'c9cf4df2fe6c632bf7886413' 3257 }, 3258 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 3259 c52a357da7a644b8070a151b0', 3260 / recipients / [ 3261 [ 3262 / protected / h'a1013818' / { 3263 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 3264 } / , 3265 / unprotected / { 3266 / ephemeral / -1:{ 3267 / kty / 1:2, 3268 / crv / -1:1, 3269 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 3270 bf054e1c7b4d91d6280', 3271 / y / -3:true 3272 }, 3273 / kid / 4:'meriadoc.brandybuck@buckland.example' 3274 }, 3275 / ciphertext / h'' 3276 ] 3277 ] 3278 ] 3279 ) 3281 C.3.2. Direct Plus Key Derivation 3283 This example uses the following: 3285 * CEK: AES-CCM w/ 128-bit key, truncate the tag to 64 bits 3287 * Recipient class: Use HKDF on a shared secret with the following 3288 implicit fields as part of the context. 3290 - salt: "aabbccddeeffgghh" 3292 - PartyU identity: "lighting-client" 3294 - PartyV identity: "lighting-server" 3296 - Supplementary Public Other: "Encryption Example 02" 3298 Size of binary file is 91 bytes 3300 96( 3301 [ 3302 / protected / h'a1010a' / { 3303 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3304 } / , 3305 / unprotected / { 3306 / iv / 5:h'89f52f65a1c580933b5261a76c' 3307 }, 3308 / ciphertext / h'753548a19b1307084ca7b2056924ed95f2e3b17006dfe93 3309 1b687b847', 3310 / recipients / [ 3311 [ 3312 / protected / h'a10129' / { 3313 \ alg \ 1:-10 3314 } / , 3315 / unprotected / { 3316 / salt / -20:'aabbccddeeffgghh', 3317 / kid / 4:'our-secret' 3318 }, 3319 / ciphertext / h'' 3320 ] 3321 ] 3322 ] 3323 ) 3325 C.3.3. Counter Signature on Encrypted Content 3327 This example uses the following: 3329 * CEK: AES-GCM w/ 128-bit key 3331 * Recipient class: ECDH Ephemeral-Static, Curve P-256 3333 Size of binary file is 326 bytes 3334 96( 3335 [ 3336 / protected / h'a10101' / { 3337 \ alg \ 1:1 \ AES-GCM 128 \ 3338 } / , 3339 / unprotected / { 3340 / iv / 5:h'c9cf4df2fe6c632bf7886413', 3341 / countersign / 7:[ 3342 / protected / h'a1013823' / { 3343 \ alg \ 1:-36 3344 } / , 3345 / unprotected / { 3346 / kid / 4:'bilbo.baggins@hobbiton.example' 3347 }, 3348 / signature / h'00929663c8789bb28177ae28467e66377da12302d7f9 3349 594d2999afa5dfa531294f8896f2b6cdf1740014f4c7f1a358e3a6cf57f4ed6fb02f 3350 cf8f7aa989f5dfd07f0700a3a7d8f3c604ba70fa9411bd10c2591b483e1d2c31de00 3351 3183e434d8fba18f17a4c7e3dfa003ac1cf3d30d44d2533c4989d3ac38c38b71481c 3352 c3430c9d65e7ddff' 3353 ] 3354 }, 3355 / ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0 3356 c52a357da7a644b8070a151b0', 3357 / recipients / [ 3358 [ 3359 / protected / h'a1013818' / { 3360 \ alg \ 1:-25 \ ECDH-ES + HKDF-256 \ 3361 } / , 3362 / unprotected / { 3363 / ephemeral / -1:{ 3364 / kty / 1:2, 3365 / crv / -1:1, 3366 / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf 3367 bf054e1c7b4d91d6280', 3368 / y / -3:true 3369 }, 3370 / kid / 4:'meriadoc.brandybuck@buckland.example' 3371 }, 3372 / ciphertext / h'' 3373 ] 3374 ] 3375 ] 3376 ) 3378 C.3.4. Encrypted Content with External Data 3380 This example uses the following: 3382 * CEK: AES-GCM w/ 128-bit key 3384 * Recipient class: ECDH static-Static, Curve P-256 with AES Key Wrap 3386 * Externally Supplied AAD: h'0011bbcc22dd44ee55ff660077' 3388 Size of binary file is 173 bytes 3390 96( 3391 [ 3392 / protected / h'a10101' / { 3393 \ alg \ 1:1 \ AES-GCM 128 \ 3394 } / , 3395 / unprotected / { 3396 / iv / 5:h'02d1f7e6f26c43d4868d87ce' 3397 }, 3398 / ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e28529d8f5335 3399 e5f0165eee976b4a5f6c6f09d', 3400 / recipients / [ 3401 [ 3402 / protected / h'a101381f' / { 3403 \ alg \ 1:-32 \ ECHD-SS+A128KW \ 3404 } / , 3405 / unprotected / { 3406 / static kid / -3:'peregrin.took@tuckborough.example', 3407 / kid / 4:'meriadoc.brandybuck@buckland.example', 3408 / U nonce / -22:h'0101' 3409 }, 3410 / ciphertext / h'41e0d76f579dbd0d936a662d54d8582037de2e366fd 3411 e1c62' 3412 ] 3413 ] 3414 ] 3415 ) 3417 C.4. Examples of Encrypted Messages 3419 C.4.1. Simple Encrypted Message 3421 This example uses the following: 3423 * CEK: AES-CCM w/ 128-bit key and a 64-bit tag 3425 Size of binary file is 52 bytes 3426 16( 3427 [ 3428 / protected / h'a1010a' / { 3429 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3430 } / , 3431 / unprotected / { 3432 / iv / 5:h'89f52f65a1c580933b5261a78c' 3433 }, 3434 / ciphertext / h'5974e1b99a3a4cc09a659aa2e9e7fff161d38ce71cb45ce 3435 460ffb569' 3436 ] 3437 ) 3439 C.4.2. Encrypted Message with a Partial IV 3441 This example uses the following: 3443 * CEK: AES-CCM w/ 128-bit key and a 64-bit tag 3445 * Prefix for IV is 89F52F65A1C580933B52 3447 Size of binary file is 41 bytes 3449 16( 3450 [ 3451 / protected / h'a1010a' / { 3452 \ alg \ 1:10 \ AES-CCM-16-64-128 \ 3453 } / , 3454 / unprotected / { 3455 / partial iv / 6:h'61a7' 3456 }, 3457 / ciphertext / h'252a8911d465c125b6764739700f0141ed09192de139e05 3458 3bd09abca' 3459 ] 3460 ) 3462 C.5. Examples of MACed Messages 3464 C.5.1. Shared Secret Direct MAC 3466 This example uses the following: 3468 * MAC: AES-CMAC, 256-bit key, truncated to 64 bits 3470 * Recipient class: direct shared secret 3472 Size of binary file is 57 bytes 3473 97( 3474 [ 3475 / protected / h'a1010f' / { 3476 \ alg \ 1:15 \ AES-CBC-MAC-256//64 \ 3477 } / , 3478 / unprotected / {}, 3479 / payload / 'This is the content.', 3480 / tag / h'9e1226ba1f81b848', 3481 / recipients / [ 3482 [ 3483 / protected / h'', 3484 / unprotected / { 3485 / alg / 1:-6 / direct /, 3486 / kid / 4:'our-secret' 3487 }, 3488 / ciphertext / h'' 3489 ] 3490 ] 3491 ] 3492 ) 3494 C.5.2. ECDH Direct MAC 3496 This example uses the following: 3498 * MAC: HMAC w/SHA-256, 256-bit key 3500 * Recipient class: ECDH key agreement, two static keys, HKDF w/ 3501 context structure 3503 Size of binary file is 214 bytes 3504 97( 3505 [ 3506 / protected / h'a10105' / { 3507 \ alg \ 1:5 \ HMAC 256//256 \ 3508 } / , 3509 / unprotected / {}, 3510 / payload / 'This is the content.', 3511 / tag / h'81a03448acd3d305376eaa11fb3fe416a955be2cbe7ec96f012c99 3512 4bc3f16a41', 3513 / recipients / [ 3514 [ 3515 / protected / h'a101381a' / { 3516 \ alg \ 1:-27 \ ECDH-SS + HKDF-256 \ 3517 } / , 3518 / unprotected / { 3519 / static kid / -3:'peregrin.took@tuckborough.example', 3520 / kid / 4:'meriadoc.brandybuck@buckland.example', 3521 / U nonce / -22:h'4d8553e7e74f3c6a3a9dd3ef286a8195cbf8a23d 3522 19558ccfec7d34b824f42d92bd06bd2c7f0271f0214e141fb779ae2856abf585a583 3523 68b017e7f2a9e5ce4db5' 3524 }, 3525 / ciphertext / h'' 3526 ] 3527 ] 3528 ] 3529 ) 3531 C.5.3. Wrapped MAC 3533 This example uses the following: 3535 * MAC: AES-MAC, 128-bit key, truncated to 64 bits 3537 * Recipient class: AES Key Wrap w/ a pre-shared 256-bit key 3539 Size of binary file is 109 bytes 3540 97( 3541 [ 3542 / protected / h'a1010e' / { 3543 \ alg \ 1:14 \ AES-CBC-MAC-128//64 \ 3544 } / , 3545 / unprotected / {}, 3546 / payload / 'This is the content.', 3547 / tag / h'36f5afaf0bab5d43', 3548 / recipients / [ 3549 [ 3550 / protected / h'', 3551 / unprotected / { 3552 / alg / 1:-5 / A256KW /, 3553 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 3554 }, 3555 / ciphertext / h'711ab0dc2fc4585dce27effa6781c8093eba906f227 3556 b6eb0' 3557 ] 3558 ] 3559 ] 3560 ) 3562 C.5.4. Multi-Recipient MACed Message 3564 This example uses the following: 3566 * MAC: HMAC w/ SHA-256, 128-bit key 3568 * Recipient class: Uses three different methods 3570 1. ECDH Ephemeral-Static, Curve P-521, AES Key Wrap w/ 128-bit 3571 key 3573 2. AES Key Wrap w/ 256-bit key 3575 Size of binary file is 309 bytes 3576 97( 3577 [ 3578 / protected / h'a10105' / { 3579 \ alg \ 1:5 \ HMAC 256//256 \ 3580 } / , 3581 / unprotected / {}, 3582 / payload / 'This is the content.', 3583 / tag / h'bf48235e809b5c42e995f2b7d5fa13620e7ed834e337f6aa43df16 3584 1e49e9323e', 3585 / recipients / [ 3586 [ 3587 / protected / h'a101381c' / { 3588 \ alg \ 1:-29 \ ECHD-ES+A128KW \ 3589 } / , 3590 / unprotected / { 3591 / ephemeral / -1:{ 3592 / kty / 1:2, 3593 / crv / -1:3, 3594 / x / -2:h'0043b12669acac3fd27898ffba0bcd2e6c366d53bc4db 3595 71f909a759304acfb5e18cdc7ba0b13ff8c7636271a6924b1ac63c02688075b55ef2 3596 d613574e7dc242f79c3', 3597 / y / -3:true 3598 }, 3599 / kid / 4:'bilbo.baggins@hobbiton.example' 3600 }, 3601 / ciphertext / h'339bc4f79984cdc6b3e6ce5f315a4c7d2b0ac466fce 3602 a69e8c07dfbca5bb1f661bc5f8e0df9e3eff5' 3603 ], 3604 [ 3605 / protected / h'', 3606 / unprotected / { 3607 / alg / 1:-5 / A256KW /, 3608 / kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037' 3609 }, 3610 / ciphertext / h'0b2c7cfce04e98276342d6476a7723c090dfdd15f9a 3611 518e7736549e998370695e6d6a83b4ae507bb' 3612 ] 3613 ] 3614 ] 3615 ) 3617 C.6. Examples of MAC0 Messages 3619 C.6.1. Shared Secret Direct MAC 3621 This example uses the following: 3623 * MAC: AES-CMAC, 256-bit key, truncated to 64 bits 3624 * Recipient class: direct shared secret 3626 Size of binary file is 37 bytes 3628 17( 3629 [ 3630 / protected / h'a1010f' / { 3631 \ alg \ 1:15 \ AES-CBC-MAC-256//64 \ 3632 } / , 3633 / unprotected / {}, 3634 / payload / 'This is the content.', 3635 / tag / h'726043745027214f' 3636 ] 3637 ) 3639 Note that this example uses the same inputs as Appendix C.5.1. 3641 C.7. COSE Keys 3643 C.7.1. Public Keys 3645 This is an example of a COSE Key Set. This example includes the 3646 public keys for all of the previous examples. 3648 In order the keys are: 3650 * An EC key with a kid of "meriadoc.brandybuck@buckland.example" 3652 * An EC key with a kid of "peregrin.took@tuckborough.example" 3654 * An EC key with a kid of "bilbo.baggins@hobbiton.example" 3656 * An EC key with a kid of "11" 3658 Size of binary file is 481 bytes 3660 [ 3661 { 3662 -1:1, 3663 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 3664 8551d', 3665 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 3666 4d19c', 3667 1:2, 3668 2:'meriadoc.brandybuck@buckland.example' 3669 }, 3670 { 3671 -1:1, 3672 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 3673 09eff', 3674 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 3675 c117e', 3676 1:2, 3677 2:'11' 3678 }, 3679 { 3680 -1:3, 3681 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 3682 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 3683 f42ad', 3684 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 3685 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 3686 d9475', 3687 1:2, 3688 2:'bilbo.baggins@hobbiton.example' 3689 }, 3690 { 3691 -1:1, 3692 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 3693 d6280', 3694 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 3695 822bb', 3696 1:2, 3697 2:'peregrin.took@tuckborough.example' 3698 } 3699 ] 3701 C.7.2. Private Keys 3703 This is an example of a COSE Key Set. This example includes the 3704 private keys for all of the previous examples. 3706 In order the keys are: 3708 * An EC key with a kid of "meriadoc.brandybuck@buckland.example" 3710 * A shared-secret key with a kid of "our-secret" 3712 * An EC key with a kid of "peregrin.took@tuckborough.example" 3714 * A shared-secret key with a kid of "018c0ae5-4d9b-471b- 3715 bfd6-eef314bc7037" 3717 * An EC key with a kid of "bilbo.baggins@hobbiton.example" 3719 * An EC key with a kid of "11" 3721 Size of binary file is 816 bytes 3723 [ 3724 { 3725 1:2, 3726 2:'meriadoc.brandybuck@buckland.example', 3727 -1:1, 3728 -2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0 3729 8551d', 3730 -3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008 3731 4d19c', 3732 -4:h'aff907c99f9ad3aae6c4cdf21122bce2bd68b5283e6907154ad911840fa 3733 208cf' 3734 }, 3735 { 3736 1:2, 3737 2:'11', 3738 -1:1, 3739 -2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a 3740 09eff', 3741 -3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf 3742 c117e', 3743 -4:h'57c92077664146e876760c9520d054aa93c3afb04e306705db609030850 3744 7b4d3' 3745 }, 3746 { 3747 1:2, 3748 2:'bilbo.baggins@hobbiton.example', 3749 -1:3, 3750 -2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de 3751 7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8 3752 f42ad', 3753 -3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e 3754 60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1 3755 d9475', 3756 -4:h'00085138ddabf5ca975f5860f91a08e91d6d5f9a76ad4018766a476680b 3757 55cd339e8ab6c72b5facdb2a2a50ac25bd086647dd3e2e6e99e84ca2c3609fdf177f 3758 eb26d' 3759 }, 3760 { 3761 1:4, 3762 2:'our-secret', 3763 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 3764 27188' 3765 }, 3766 { 3767 1:2, 3768 -1:1, 3769 2:'peregrin.took@tuckborough.example', 3770 -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91 3771 d6280', 3772 -3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf 3773 822bb', 3774 -4:h'02d1f7e6f26c43d4868d87ceb2353161740aacf1f7163647984b522a848 3775 df1c3' 3776 }, 3777 { 3778 1:4, 3779 2:'our-secret2', 3780 -1:h'849b5786457c1491be3a76dcea6c4271' 3781 }, 3782 { 3783 1:4, 3784 2:'018c0ae5-4d9b-471b-bfd6-eef314bc7037', 3785 -1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4 3786 27188' 3787 } 3788 ] 3790 Acknowledgments 3792 This document is a product of the COSE working group of the IETF. 3794 The following individuals are to blame for getting me started on this 3795 project in the first place: Richard Barnes, Matt Miller, and Martin 3796 Thomson. 3798 The initial version of the specification was based to some degree on 3799 the outputs of the JOSE and S/MIME working groups. 3801 The following individuals provided input into the final form of the 3802 document: Carsten Bormann, John Bradley, Brain Campbell, Michael B. 3803 Jones, Ilari Liusvaara, Francesca Palombini, Ludwig Seitz, and Goran 3804 Selander. 3806 Author's Address 3808 Jim Schaad 3809 August Cellars 3811 Email: ietf@augustcellars.com