-
Notifications
You must be signed in to change notification settings - Fork 4
/
draft-ietf-cose-rfc8152bis-struct.xml
2911 lines (2810 loc) · 169 KB
/
draft-ietf-cose-rfc8152bis-struct.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version='1.0' encoding='utf-8'?>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
<!DOCTYPE rfc SYSTEM "rfc2629-xhtml.ent" [
<!ENTITY RFC8152 SYSTEM "https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8152.xml">
<!ENTITY HkdfSection "5.1">
<!ENTITY SectionDirectKdf "6.1.2">
<!ENTITY SectionECDH "6.3">
]>
<!-- <!ENTITY cose-alg SYSTEM "http://xml.resource.org/public/rfc/bibxml3/reference.I-D.schaad-cose-rfc8152bis-algs.xml"> -->
<!-- RFC EDITOR
Issue has been raised about countersign vs counter sign.
The dictionaries seem to favor a single word, but when you did RFC 8152 you left it as a double word.
I have switched to the single word version except for tables 3 and 4 where it causes the text file to have long lines.
-->
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc toc="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc comments="yes"?>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902" docName="draft-ietf-cose-rfc8152bis-struct-13" category="std" obsoletes="8152" updates="" submissionType="IETF" xml:lang="en" version="3" consensus="true">
<!-- xml2rfc v2v3 conversion 2.24.0 -->
<front>
<title abbrev="COSE Structure">
CBOR Object Signing and Encryption (COSE): Structures and Process</title>
<seriesInfo name="Internet-Draft" value="draft-ietf-cose-rfc8152bis-struct-12"/>
<author initials="J." surname="Schaad" fullname="Jim Schaad">
<organization>August Cellars</organization>
<address>
<email>[email protected]</email>
</address>
</author>
<date/>
<area>Security</area>
<workgroup>COSE Working Group</workgroup>
<abstract>
<t>Concise Binary Object Representation (CBOR) is a data format designed for small code size and small message size. There is a need for the ability to have basic security services defined for this data format. This document defines the CBOR Object Signing and Encryption (COSE) protocol. This specification describes how to create and process signatures, message authentication codes, and encryption using CBOR for serialization. This specification additionally describes how to represent cryptographic keys using CBOR. </t>
<t>
This document along with <xref target="I-D.ietf-cose-rfc8152bis-algs"/> obsoletes RFC8152.
</t>
</abstract>
<note removeInRFC="true">
<name>Contributing to this document</name>
<!-- RFC EDITOR - Please remove this note before publishing -->
<t>
The source for this draft is being maintained in GitHub.
Suggested changes should be submitted as pull requests at <eref target="https://github.com/cose-wg/cose-rfc8152bis"/>.
Instructions are on that page as well.
Editorial changes can be managed in GitHub, but any substantial issues need to be discussed on the COSE mailing list.
</t>
</note>
</front>
<middle>
<section anchor="introduction">
<name>Introduction</name>
<t>There has been an increased focus on small, constrained devices that make up the Internet of Things (IoT). One of the standards that has come out of this process is "Concise Binary Object Representation (CBOR)" <xref target="I-D.ietf-cbor-7049bis"/>. CBOR extended the data model of the JavaScript Object Notation (JSON) <xref target="STD90"/> by allowing for binary data, among other changes. CBOR has been adopted by several of the IETF working groups dealing with the IoT world as their encoding of data structures. CBOR was designed specifically both to be small in terms of messages transported and implementation size and to be a schema-free decoder. A need exists to provide message security services for IoT, and using CBOR as the message-encoding format makes sense. </t>
<t>The JOSE working group produced a set of documents <xref target="RFC7515"/> <xref target="RFC7516"/> <xref target="RFC7517"/> <xref target="RFC7518"/> that specified how to process encryption, signatures, and Message Authentication Code (MAC) operations and how to encode keys using JSON. This document defines the CBOR Object Signing and Encryption (COSE) standard, which does the same thing for the CBOR encoding format. This document is combined with <xref target="I-D.ietf-cose-rfc8152bis-algs"/> which provides an initial set of algorithms. While there is a strong attempt to keep the flavor of the original JSON Object Signing and Encryption (JOSE) documents, two considerations are taken into account: </t>
<ul>
<li>CBOR has capabilities that are not present in JSON and are appropriate to use. One example of this is the fact that CBOR has a method of encoding binary directly without first converting it into a base64-encoded text string. </li>
<li>COSE is not a direct copy of the JOSE specification. In the process of creating COSE, decisions that were made for JOSE were re-examined. In many cases, different results were decided on as the criteria were not always the same. </li>
</ul>
<t>
This document contains:
</t>
<ul>
<li>
The description of the structure for the CBOR objects which are transmitted over the wire.
Two objects are defined for each of encryption, signing and message authentication.
One object is defined for transporting keys and one for transporting groups of keys.
</li>
<li>
The procedures used to build the inputs to the cryptographic functions required for each of the structures.
</li>
<li>
A set of attributes that apply to the different security objects.
</li>
</ul>
<t>
This document does not contain the rules and procedures for using specific cryptographic algorithms.
Details on specific algorithms can be found in <xref target="I-D.ietf-cose-rfc8152bis-algs"/> and <xref target="RFC8230"/>.
Details for additional algorithms are expected to be defined in future documents.
</t>
<t>
COSE was initially designed as part of a solution to provide security to Constrained RESTful Environments (CoRE), and this is done using <xref target="RFC8613"/> and <xref target="I-D.ietf-core-groupcomm-bis"/>.
However, COSE is not restricted to just these cases and can be used in any place where one would consider either JOSE or CMS <xref target="RFC5652"/> for the purpose of providing security services.
COSE, like JOSE and CMS, is only for use in store and forward or offline protocols.
The use of COSE in online protocols needing encryption, require that an online key establishment process be done before sending objects back and forth.
Any application which uses COSE for security services first needs to determine what security services are required and then select the appropriate COSE structures and cryptographic algorithms based on those needs.
<xref target="app-considerations"/> provides additional information on what applications need to specify when using COSE.
</t>
<t>
One feature that is present in CMS that is not present in this standard is a digest structure.
This omission is deliberate.
It is better for the structure to be defined in each protocol as different protocols will want to include a different set of fields as part of the structure.
While an algorithm identifier and the digest value are going to be common to all applications, the two values may not always be adjacent as the algorithm could be defined once with multiple values.
Applications may additionally want to define additional data fields as part of the structure.
One such application-specific element would be to include a URI or other pointer to where the data that is being hashed can be obtained.
<xref target="I-D.ietf-cose-hash-algs"/> contains one such possible structure along with defining a set of digest algorithms.
</t>
<t>
During the process of advancing COSE to Internet Standard, it was noticed the description of the security properties of countersignatures was incorrect for the COSE_Sign1 structure.
Since the security properties that were described, those of a true countersignature, were those that the working group desired, the decision was made to remove all of the countersignature text from this document and create a new document <xref target="I-D.ietf-cose-countersign"/> to both deprecate the old countersignature algorithm and header parameters and to define a new algorithm and header parameters with the desired security properties.
</t>
<section anchor="requirements-terminology">
<name>Requirements Terminology</name>
<t>
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only when, they appear in all capitals, as shown here.
</t>
</section>
<section>
<name>Changes from RFC8152</name>
<ul>
<li> Split the original document into this document and <xref target="I-D.ietf-cose-rfc8152bis-algs"/>.</li>
<li>Add some text describing why there is no digest structure defined by COSE.</li>
<li>Text clarifications and changes in terminology.</li>
<li>
All of the details relating to countersignatures have been removed and placed in <xref target="I-D.ietf-cose-countersign"/>.
</li>
</ul>
</section>
<section anchor="design-changes-from-jose">
<name>Design Changes from JOSE</name>
<ul>
<li>Define a single overall message structure so that encrypted, signed, and MACed messages can easily be identified and still have a consistent view. </li>
<li>Signed messages distinguish between the protected and unprotected header parameters that relate to the content and those that relate to the signature. </li>
<li>MACed messages are separated from signed messages. </li>
<li>MACed messages have the ability to use the same set of recipient algorithms as enveloped messages for obtaining the MAC authentication key. </li>
<li>Use binary encodings, rather than base64url encodings, to encode binary data. </li>
<li>Combine the authentication tag for encryption algorithms with the ciphertext. </li>
<li>The set of cryptographic algorithms has been expanded in some directions and trimmed in others. </li>
</ul>
</section>
<section anchor="cbor-grammar">
<name>CBOR Grammar</name>
<t>
There was not a standard CBOR grammar available when COSE was originally written.
For that reason the CBOR data objects defined here are described in prose.
Since that time CBOR Data Definition Language (CDDL) <xref target="RFC8610"/> has been published as an RFC.
The CBOR grammar presented in this document is compatible with CDDL.
</t>
<t>
The document was developed by first working on the grammar and then developing the prose to go with it.
An artifact of this is that the prose was written using the primitive type strings defined by CBOR Data Definition Language (CDDL) <xref target="RFC8610"/>.
In this specification, the following primitive types are used:
</t>
<ul empty="true">
<li>any -- non-specific value that permits all CBOR values to be placed here.</li>
<li>bool -- a boolean value (true: major type 7, value 21; false: major type 7, value 20).</li>
<li>bstr -- byte string (major type 2).</li>
<li>int -- an unsigned integer or a negative integer.</li>
<li>nil -- a null value (major type 7, value 22).</li>
<li>nint -- a negative integer (major type 1).</li>
<li>tstr -- a UTF-8 text string (major type 3).</li>
<li>uint -- an unsigned integer (major type 0).</li>
</ul>
<t>Two syntaxes from CDDL appear in this document as shorthand. These are:
</t>
<ul empty="true">
<li>FOO / BAR -- indicates that either FOO or BAR can appear here.</li>
<li>[+ FOO] -- indicates that the type FOO appears one or more times in an array.</li>
<li>* FOO -- indicates that the type FOO appears zero or more times.</li>
</ul>
<t>
Two of the constraints defined by CDDL are also used in this document. These are:
</t>
<ul empty="true">
<li>type1 .cbor type2 -- indicates that the contents of type1, usually bstr, contains a value of type2.</li>
<li>type1 .size integer -- indicates that the contents of type1 is integer bytes long</li>
</ul>
<t>
As well as the prose description, a version of a CBOR grammar is presented in CDDL.
The CDDL grammar is informational; the prose description is normative.
</t>
<t>The collected CDDL can be extracted from the XML version of this document via the following XPath expression below. (Depending on the XPath evaluator one is using, it may be necessary to deal with &gt; as an entity.) </t>
<sourcecode type="XPATH"><![CDATA[
//sourcecode[@type='CDDL']/text()
]]></sourcecode>
<t>CDDL expects the initial non-terminal symbol to be the first symbol in the file. For this reason, the first fragment of CDDL is presented here. </t>
<sourcecode type="CDDL"><![CDATA[
start = COSE_Messages / COSE_Key / COSE_KeySet / Internal_Types
; This is defined to make the tool quieter:
Internal_Types = Sig_structure / Enc_structure / MAC_structure
]]></sourcecode>
<t>The non-terminal Internal_Types is defined for dealing with the automated validation tools used during the writing of this document. It references those non-terminals that are used for security computations but are not emitted for transport. </t>
</section>
<section anchor="label">
<name>CBOR-Related Terminology</name>
<t>In JSON, maps are called objects and only have one kind of map key: a text string. In COSE, we use text strings, negative integers, and unsigned integers as map keys. The integers are used for compactness of encoding and easy comparison. The inclusion of text strings allows for an additional range of short encoded values to be used as well. Since the word "key" is mainly used in its other meaning, as a cryptographic key, we use the term "label" for this usage as a map key. </t>
<t>
The presence a label that is neither a text string or an integer, in a CBOR map, is an error.
Applications can either fail processing or process messages by ignoring incorrect labels; however, they <bcp14>MUST NOT</bcp14> create messages with incorrect labels.
</t>
<t>A CDDL grammar fragment defines the non-terminal 'label', as in the previous paragraph, and 'values', which permits any value to be used. </t>
<sourcecode type="CDDL"><![CDATA[
label = int / tstr
values = any
]]></sourcecode>
</section>
<section>
<name>Document Terminology</name>
<t>In this document, we use the following terminology: </t>
<t>Byte is a synonym for octet.</t>
<t>
Constrained Application Protocol (CoAP) is a specialized web transfer protocol for use in constrained systems. It is defined in <xref target="RFC7252"/>.
</t>
<t>
Authenticated Encryption (AE) <xref target="RFC5116"/> algorithms are encryption algorithms that provide an authentication check of the contents with the encryption service.
An example of an AE algorithm used in COSE is AES Key Wrap <xref target="RFC3394"/>.
These algorithms are used for key encryption algorithms, but AEAD algorithms would be preferred.
</t>
<t>
Authenticated Encryption with Associated Data (AEAD) <xref target="RFC5116"/> algorithms provide the same authentication service of the content as AE algorithms do.
They also allow for associated data to be included in the authentication service, but which is not part of the encrypted body.
An example of an AEAD algorithm used in COSE is AES-GCM <xref target="RFC5116"/>.
These algorithms are used for content encryption and can be used for key encryption as well.
</t>
<t>
Context is used throughout the document to represent information that is not part of the COSE message.
Information which is part of the context can come from several different sources including:
Protocol interactions, associated key structures, and program configuration.
The context to use can be implicit, identified using the 'kid context' header parameter defined in <xref target="RFC8613"/>, or identified by a protocol-specific identifier.
Context should generally be included in the cryptographic construction; for more details see <xref target="Extern_AAD"/>.
</t>
<t>The term 'byte string' is used for sequences of bytes, while the term 'text string' is used for sequences of characters.</t>
</section>
</section>
<section anchor="the-cosemsg-structure">
<name>Basic COSE Structure</name>
<t>
The COSE object structure is designed so that there can be a large amount of common code when parsing and processing the different types of security messages.
All of the message structures are built on the CBOR array type.
The first three elements of the array always contain the same information:
</t>
<ol type="1">
<li>The protected header parameters, encoded and wrapped in a bstr.</li>
<li>The unprotected header parameters as a map.</li>
<li>
The content of the message.
The content is either the plaintext or the ciphertext as appropriate.
The content may be detached (i.e. transported separately from the COSE structure), but the location is still used.
The content is wrapped in a bstr when present and is a nil value when detached.
</li>
</ol>
<t>
Elements after this point are dependent on the specific message type.
</t>
<t>COSE messages are built using the concept of layers to separate different types of cryptographic concepts. As an example of how this works, consider the COSE_Encrypt message (<xref target="EnvelopedData"/>). This message type is broken into two layers: the content layer and the recipient layer. The content layer contains the encrypted plaintext and information about the encrypted message. The recipient layer contains the encrypted content encryption key (CEK) and information about how it is encrypted for each recipient. A single layer version of the encryption message COSE_Encrypt0 (<xref target="EnvelopedData0"/>) is provided for cases where the CEK is pre-shared.</t>
<t>Identification of which type of message has been presented is done by the following methods:
</t>
<ol type="1">
<li>The specific message type is known from the context. This may be defined by a marker in the containing structure or by restrictions specified by the application protocol. </li>
<li>The message type is identified by a CBOR tag. Messages with a CBOR tag are known in this specification as tagged messages, while those without the CBOR tag are known as untagged messages. This document defines a CBOR tag for each of the message structures. These tags can be found in <xref target="CBOR-Tags"/>. </li>
<li>
When a COSE object is carried in a media type of 'application/cose', the optional parameter 'cose-type' can be used to identify the embedded object.
The parameter is OPTIONAL if the tagged version of the structure is used.
The parameter is <bcp14>REQUIRED</bcp14> if the untagged version of the structure is used.
The value to use with the parameter for each of the structures can be found in <xref target="CBOR-Tags"/>.
</li>
<li>When a COSE object is carried as a CoAP payload, the CoAP Content-Format Option can be used to identify the message content. The CoAP Content-Format values can be found in <xref target="CoAP_content_type"/>. The CBOR tag for the message structure is not required as each security message is uniquely identified. </li>
</ol>
<!--Table 1 -->
<table anchor="CBOR-Tags" align="center">
<name>COSE Message Identification</name>
<thead>
<tr>
<th>CBOR Tag</th>
<th>cose-type</th>
<th>Data Item</th>
<th>Semantics</th>
</tr>
</thead>
<tbody>
<tr>
<td>98</td>
<td>cose-sign</td>
<td>COSE_Sign</td>
<td>COSE Signed Data Object</td>
</tr>
<tr>
<td>18</td>
<td>cose-sign1</td>
<td>COSE_Sign1</td>
<td>COSE Single Signer Data Object</td>
</tr>
<tr>
<td>96</td>
<td>cose-encrypt</td>
<td>COSE_Encrypt</td>
<td>COSE Encrypted Data Object</td>
</tr>
<tr>
<td>16</td>
<td>cose-encrypt0</td>
<td>COSE_Encrypt0</td>
<td>COSE Single Recipient Encrypted Data Object</td>
</tr>
<tr>
<td>97</td>
<td>cose-mac</td>
<td>COSE_Mac</td>
<td>COSE MACed Data Object</td>
</tr>
<tr>
<td>17</td>
<td>cose-mac0</td>
<td>COSE_Mac0</td>
<td>COSE Mac w/o Recipients Object</td>
</tr>
</tbody>
</table>
<table anchor="CoAP_content_type" align="center">
<name>CoAP Content-Formats for COSE</name>
<thead>
<tr>
<th>Media Type</th>
<th>Encoding</th>
<th>ID</th>
<th>Reference</th>
</tr>
</thead>
<tbody>
<tr>
<td>application/cose; cose-type="cose-sign"</td>
<td/>
<td>98</td>
<td>[[THIS DOCUMENT]]</td>
</tr>
<tr>
<td>application/cose; cose-type="cose-sign1"</td>
<td/>
<td>18</td>
<td>[[THIS DOCUMENT]]</td>
</tr>
<tr>
<td>application/cose; cose-type="cose-encrypt"</td>
<td/>
<td>96</td>
<td>[[THIS DOCUMENT]]</td>
</tr>
<tr>
<td>application/cose; cose-type="cose-encrypt0"</td>
<td/>
<td>16</td>
<td>[[THIS DOCUMENT]]</td>
</tr>
<tr>
<td>application/cose; cose-type="cose-mac"</td>
<td/>
<td>97</td>
<td>[[THIS DOCUMENT]]</td>
</tr>
<tr>
<td>application/cose; cose-type="cose-mac0"</td>
<td/>
<td>17</td>
<td>[[THIS DOCUMENT]]</td>
</tr>
<tr>
<td>application/cose-key</td>
<td/>
<td>101</td>
<td>[[THIS DOCUMENT]]</td>
</tr>
<tr>
<td>application/cose-key-set</td>
<td/>
<td>102</td>
<td>[[THIS DOCUMENT]]</td>
</tr>
</tbody>
</table>
<t>The following CDDL fragment identifies all of the top messages defined in this document. Separate non-terminals are defined for the tagged and the untagged versions of the messages. </t>
<sourcecode type="CDDL"><![CDATA[
COSE_Messages = COSE_Untagged_Message / COSE_Tagged_Message
COSE_Untagged_Message = COSE_Sign / COSE_Sign1 /
COSE_Encrypt / COSE_Encrypt0 /
COSE_Mac / COSE_Mac0
COSE_Tagged_Message = COSE_Sign_Tagged / COSE_Sign1_Tagged /
COSE_Encrypt_Tagged / COSE_Encrypt0_Tagged /
COSE_Mac_Tagged / COSE_Mac0_Tagged
]]></sourcecode>
</section>
<section anchor="header-parameters">
<name>Header Parameters</name>
<t>The structure of COSE has been designed to have two buckets of information that are not considered to be part of the payload itself, but are used for holding information about content, algorithms, keys, or evaluation hints for the processing of the layer. These two buckets are available for use in all of the structures except for keys. While these buckets are present, they may not always be usable in all instances. For example, while the protected bucket is defined as part of the recipient structure, some of the algorithms used for recipient structures do not provide for authenticated data. If this is the case, the protected bucket is left empty. </t>
<t>Both buckets are implemented as CBOR maps. The map key is a 'label' (<xref target="label"/>). The value portion is dependent on the definition for the label. Both maps use the same set of label/value pairs. The integer and text string values for labels have been divided into several sections including a standard range, a private range, and a range that is dependent on the algorithm selected. The defined labels can be found in the "COSE Header Parameters" IANA registry (<xref target="cose-header-key-table"/>). </t>
<t>
The two buckets are:
</t>
<dl newline="false">
<dt>protected:</dt>
<dd>
<t>
Contains parameters about the current layer that are cryptographically protected.
This bucket <bcp14>MUST</bcp14> be empty if it is not going to be included in a cryptographic computation.
This bucket is encoded in the message as a binary object.
This value is obtained by CBOR encoding the protected map and wrapping it in a bstr object.
Senders <bcp14>SHOULD</bcp14> encode a zero-length map as a zero-length byte string rather than as a zero-length map (encoded as h'a0').
The zero-length binary encoding is preferred because it is both shorter and the version used in the serialization structures for cryptographic computation.
Recipients <bcp14>MUST</bcp14> accept both a zero-length byte string and a zero-length map encoded in a byte string.
</t>
<t>
Wrapping the encoding with a byte string allows for the protected map to be transported with a greater chance that it will not be altered accidentally in transit.
(Badly behaved intermediates could decode and re-encode, but this will result in a failure to verify unless the re-encoded byte string is identical to the decoded byte string.)
This avoids the problem of all parties needing to be able to do a common canonical encoding of the map for input to cyprtographic operations.
</t>
</dd>
<dt>unprotected:</dt>
<dd>Contains parameters about the current layer that are not cryptographically protected. </dd>
</dl>
<t>
Only header parameters that deal with the current layer are to be placed at that layer. As an example of this, the header parameter 'content type' describes the content of the message being carried in the message. As such, this header parameter is placed only in the content layer and is not placed in the recipient or signature layers. In principle, one should be able to process any given layer without reference to any other layer. With the exception of the COSE_Sign structure, the only data that needs to cross layers is the cryptographic key.
</t>
<t>
The buckets are present in all of the security objects defined in this document. The fields in order are the 'protected' bucket (as a CBOR 'bstr' type) and then the 'unprotected' bucket (as a CBOR 'map' type). The presence of both buckets is required. The header parameters that go into the buckets come from the IANA "COSE Header Parameters" registry (<xref target="cose-header-key-table"/>).
Some header parameters are defined in the next section.
</t>
<t>Labels in each of the maps <bcp14>MUST</bcp14> be unique. When processing messages, if a label appears multiple times, the message <bcp14>MUST</bcp14> be rejected as malformed. Applications <bcp14>SHOULD</bcp14> verify that the same label does not occur in both the protected and unprotected header parameters. If the message is not rejected as malformed, attributes <bcp14>MUST</bcp14> be obtained from the protected bucket, and only if not found are attributes obtained from the unprotected bucket. </t>
<t>The following CDDL fragment represents the two header parameter buckets. A group "Headers" is defined in CDDL that represents the two buckets in which attributes are placed. This group is used to provide these two fields consistently in all locations. A type is also defined that represents the map of common header parameters. </t>
<sourcecode type="CDDL"><![CDATA[
Headers = (
protected : empty_or_serialized_map,
unprotected : header_map
)
header_map = {
Generic_Headers,
* label => values
}
empty_or_serialized_map = bstr .cbor header_map / bstr .size 0
]]></sourcecode>
<section anchor="cose-headers">
<name>Common COSE Header Parameters</name>
<t>This section defines a set of common header parameters. A summary of these header parameters can be found in <xref target="Header-Table"/>. This table should be consulted to determine the value of label and the type of the value. </t>
<t>The set of header parameters defined in this section are: </t>
<dl newline="false">
<dt>alg:</dt>
<dd> This header parameter is used to indicate the algorithm used for the security processing. This header parameter <bcp14>MUST</bcp14> be authenticated where the ability to do so exists. This support is provided by AEAD algorithms or construction (e.g. COSE_Sign and COSE_Mac0). This authentication can be done either by placing the header parameter in the protected header parameter bucket or as part of the externally supplied data <xref target="Extern_AAD"/>). The value is taken from the "COSE Algorithms" registry (see <xref target="COSE.Algorithms"/>). </dd>
<dt>crit:</dt>
<dd>
<t>
This header parameter is used to indicate which protected header parameters an application that is processing a message is required to understand.
Header parameters defined in this document do not need to be included as they should be understood by all implementations.
When present, this the 'crit' header parameter <bcp14>MUST</bcp14> be placed in the protected header parameter bucket.
The array <bcp14>MUST</bcp14> have at least one value in it.
</t>
<t>
Not all header parameter labels need to be included in the 'crit' header parameter.
The rules for deciding which header parameters are placed in the array are:
</t>
<ul>
<li>Integer labels in the range of 0 to 7 <bcp14>SHOULD</bcp14> be omitted.</li>
<li>
Integer labels in the range -1 to -128 can be omitted.
Algorithms can assign labels in this range where the ability to process the content of the label is considered to be core to implementing the algorithm.
Algorithms can assign labels outside of this range where the ability to process the content of the label is not considered to be core, but needs to be understood to correctly process this instance.
Integer labels in the range -129 to -65536 <bcp14>SHOULD</bcp14> be included as these would be less common header parameters that might not be generally supported.
</li>
<li>Labels for header parameters required for an application MAY be omitted. Applications should have a statement if the label can be omitted. </li>
</ul>
<t>
The header parameters indicated by 'crit' can be processed by either the security library code or an application using a security library; the only requirement is that the header parameter is processed. If the 'crit' value list includes a label for which the header parameter is not in the protected header parameters bucket, this is a fatal error in processing the message.
</t>
</dd>
<dt>content type:</dt>
<dd>This header parameter is used to indicate the content type of the data in the payload or ciphertext fields. Integers are from the "CoAP Content-Formats" IANA registry table <xref target="COAP.Formats"/>. Text values following the syntax of "<type-name>/<subtype-name>" where <type-name> and <subtype-name> are defined in Section 4.2 of <xref target="RFC6838"/>. Leading and trailing whitespace is also omitted. Textual content values along with parameters and subparameters can be located using the IANA "Media Types" registry. Applications <bcp14>SHOULD</bcp14> provide this header parameter if the content structure is potentially ambiguous. </dd>
<dt>kid:</dt>
<dd>This header parameter identifies one piece of data that can be used as input to find the needed cryptographic key. The value of this header parameter can be matched against the 'kid' member in a COSE_Key structure. Other methods of key distribution can define an equivalent field to be matched. Applications <bcp14>MUST NOT</bcp14> assume that 'kid' values are unique. There may be more than one key with the same 'kid' value, so all of the keys associated with this 'kid' may need to be checked. The internal structure of 'kid' values is not defined and cannot be relied on by applications. Key identifier values are hints about which key to use. This is not a security-critical field. For this reason, it can be placed in the unprotected header parameters bucket. </dd>
<dt>IV:</dt>
<dd>This header parameter holds the Initialization Vector (IV) value. For some symmetric encryption algorithms, this may be referred to as a nonce. The IV can be placed in the unprotected bucket as modifying the IV will cause the decryption to yield plaintext that is readily detectable as garbled. </dd>
<dt>Partial IV:</dt>
<dd>
<t>
This header parameter holds a part of the IV value.
When using the COSE_Encrypt0 structure, a portion of the IV can be part of the context associated with the key (Context IV) while a portion can be changed with each message (Partial IV).
This field is used to carry a value that causes the IV to be changed for each message.
The Partial IV can be placed in the unprotected bucket as modifying the value will cause the decryption to yield plaintext that is readily detectable as garbled.
The 'Initialization Vector' and 'Partial Initialization Vector' header parameters <bcp14>MUST NOT</bcp14> both be present in the same security layer.
</t>
<t>
The message IV is generated by the following steps:
</t>
<ol type="1">
<li>Left-pad the Partial IV with zeros to the length of IV (determined by the algorithm).</li>
<li>XOR the padded Partial IV with the context IV.</li>
</ol>
</dd>
</dl>
<table anchor="Header-Table" align="center">
<name>Common Header Parameters</name>
<thead>
<tr>
<th>Name</th>
<th>Label</th>
<th>Value Type</th>
<th>Value Registry</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>alg</td>
<td>1</td>
<td>int / tstr</td>
<td>COSE Algorithms registry</td>
<td>Cryptographic algorithm to use</td>
</tr>
<tr>
<td>crit</td>
<td>2</td>
<td>[+ label]</td>
<td>COSE Header Parameters registry</td>
<td>Critical header parameters to be understood</td>
</tr>
<tr>
<td>content type</td>
<td>3</td>
<td>tstr / uint</td>
<td>CoAP Content-Formats or Media Types registries</td>
<td>Content type of the payload</td>
</tr>
<tr>
<td>kid</td>
<td>4</td>
<td>bstr</td>
<td/>
<td>Key identifier</td>
</tr>
<tr>
<td>IV</td>
<td>5</td>
<td>bstr</td>
<td/>
<td>Full Initialization Vector</td>
</tr>
<tr>
<td>Partial IV</td>
<td>6</td>
<td>bstr</td>
<td/>
<td>Partial Initialization Vector</td>
</tr>
</tbody>
</table>
<t>The CDDL fragment that represents the set of header parameters defined in this section is given below. Each of the header parameters is tagged as optional because they do not need to be in every map; header parameters required in specific maps are discussed above. </t>
<sourcecode type="CDDL"><![CDATA[
Generic_Headers = (
? 1 => int / tstr, ; algorithm identifier
? 2 => [+label], ; criticality
? 3 => tstr / int, ; content type
? 4 => bstr, ; key identifier
? 5 => bstr, ; IV
? 6 => bstr ; Partial IV
)
]]></sourcecode>
</section>
</section>
<section anchor="signing-structure">
<name>Signing Objects</name>
<t>COSE supports two different signature structures. COSE_Sign allows for one or more signatures to be applied to the same content. COSE_Sign1 is restricted to a single signer. The structures cannot be converted between each other; as the signature computation includes a parameter identifying which structure is being used, the converted structure will fail signature validation. </t>
<section anchor="full-signature">
<name>Signing with One or More Signers</name>
<t>The COSE_Sign structure allows for one or more signatures to be applied to a message payload. Header parameters relating to the content and header parameters relating to the signature are carried along with the signature itself. These header parameters may be authenticated by the signature, or just present. An example of a header parameter about the content is the content type header parameter. An example of a header parameter about the signature would be the algorithm and key used to create the signature.</t>
<t>RFC 5652 indicates that:
</t>
<blockquote>
When more than one signature is present, the successful validation of one signature associated with a given signer is usually treated as a successful signature by that signer. However, there are some application environments where other rules are needed. An application that employs a rule other than one valid signature for each signer must specify those rules. Also, where simple matching of the signer identifier is not sufficient to determine whether the signatures were generated by the same signer, the application specification must describe how to determine which signatures were generated by the same signer. Support for different communities of recipients is the primary reason that signers choose to include more than one signature.
</blockquote>
<t>
For example, the COSE_Sign structure might include signatures generated with the Edwards-curve Digital Signature Algorithm (EdDSA) <xref target="RFC8032"/> and with the Elliptic Curve Digital Signature Algorithm (ECDSA) <xref target="DSS"/>. This allows recipients to verify the signature associated with one algorithm or the other. More-detailed information on multiple signature evaluations can be found in <xref target="RFC5752"/>. </t>
<t>The signature structure can be encoded as either tagged or untagged depending on the context it will be used in. A tagged COSE_Sign structure is identified by the CBOR tag 98. The CDDL fragment that represents this is: </t>
<sourcecode type="CDDL"><![CDATA[
COSE_Sign_Tagged = #6.98(COSE_Sign)
]]></sourcecode>
<t>A COSE Signed Message is defined in two parts. The CBOR object that carries the body and information about the body is called the COSE_Sign structure. The CBOR object that carries the signature and information about the signature is called the COSE_Signature structure. Examples of COSE Signed Messages can be found in <xref target="SignedExamples"/>. </t>
<!-- Ben is complaining about the above, I think it is ok. Here is our email exchange:
> > > > A COSE Signed Message is defined in two parts. The CBOR object that
> > > > carries the body and information about the body is called the
> > > > COSE_Sign structure. The CBOR object that carries the
> > > > signature and
> > > >
> > > > (COSE_Sign also carries the signature parts?) [JLS] No - they are
> > > > carried in COSE_Signature
> > >
> > > I thought the COSE_Sign structure contained one or more
> > > COSE_Signature structures.
> >
> > Yes it does. I think of the "signature" as the byte string as being different
> from the COSE_Signature structure. This is referring to the first.
>
> Okay ... but even in this sense the "signature" is *indirectly* contained in
> COSE_Sign, and I at least did not get the sense from this text that we intended
> the "directly carries" sense of the term. Maybe we should leave a note to ask
> the RFC Editor for help; I'm failing to come up with a good wording right now.
>
-->
<t>The COSE_Sign structure is a CBOR array. The fields of the array in order are:
</t>
<dl newline="false">
<dt>protected:</dt>
<dd>This is as described in <xref target="header-parameters"/>. </dd>
<dt>unprotected:</dt>
<dd>This is as described in <xref target="header-parameters"/>. </dd>
<dt>payload:</dt>
<dd>
<t>
This field contains the serialized content to be signed.
If the payload is not present in the message, the application is required to supply the payload separately.
The payload is wrapped in a bstr to ensure that it is transported without changes.
If the payload is transported separately ("detached content"), then a nil CBOR object is placed in this location, and it is the responsibility of the application to ensure that it will be transported without changes.
</t>
<t>
Note: When a signature with a message recovery algorithm is used (<xref target="SigAlgs"/>), the maximum number of bytes that can be recovered is the length of the original payload.
The size of the encoded payload is reduced by the number of bytes that will be recovered.
If all of the bytes of the original payload are consumed, then the transmitted payload is encoded as a zero-length byte string rather than as being absent.
</t>
</dd>
<dt>signatures:</dt>
<dd>This field is an array of signatures. Each signature is represented as a COSE_Signature structure. </dd>
</dl>
<t>The CDDL fragment that represents the above text for COSE_Sign follows. </t>
<sourcecode type="CDDL"><![CDATA[
COSE_Sign = [
Headers,
payload : bstr / nil,
signatures : [+ COSE_Signature]
]
]]></sourcecode>
<t>The COSE_Signature structure is a CBOR array. The fields of the array in order are:
</t>
<dl newline="false">
<dt>protected:</dt>
<dd>This is as described in <xref target="header-parameters"/>. </dd>
<dt>unprotected:</dt>
<dd>This is as described in <xref target="header-parameters"/>. </dd>
<dt>signature:</dt>
<dd>This field contains the computed signature value. The type of the field is a bstr. Algorithms <bcp14>MUST</bcp14> specify padding if the signature value is not a multiple of 8 bits. </dd>
</dl>
<t>The CDDL fragment that represents the above text for COSE_Signature follows. </t>
<sourcecode type="CDDL"><![CDATA[
COSE_Signature = [
Headers,
signature : bstr
]
]]></sourcecode>
</section>
<section>
<name>Signing with One Signer</name>
<t>The COSE_Sign1 signature structure is used when only one signature is going to be placed on a message. The header parameters dealing with the content and the signature are placed in the same pair of buckets rather than having the separation of COSE_Sign. </t>
<t>The structure can be encoded as either tagged or untagged depending on the context it will be used in. A tagged COSE_Sign1 structure is identified by the CBOR tag 18. The CDDL fragment that represents this is: </t>
<sourcecode type="CDDL"><![CDATA[
COSE_Sign1_Tagged = #6.18(COSE_Sign1)
]]></sourcecode>
<t>The CBOR object that carries the body, the signature, and the information about the body and signature is called the COSE_Sign1 structure. Examples of COSE_Sign1 messages can be found in <xref target="Sign1_Examples"/>. </t>
<t>The COSE_Sign1 structure is a CBOR array. The fields of the array in order are:
</t>
<dl newline="false">
<dt>protected:</dt>
<dd>This is as described in <xref target="header-parameters"/>. </dd>
<dt>unprotected:</dt>
<dd>This is as described in <xref target="header-parameters"/>. </dd>
<dt>payload:</dt>
<dd>This is as described in <xref target="full-signature"/>. </dd>
<dt>signature:</dt>
<dd>This field contains the computed signature value. The type of the field is a bstr. </dd>
</dl>
<t>The CDDL fragment that represents the above text for COSE_Sign1 follows. </t>
<sourcecode type="CDDL"><![CDATA[
COSE_Sign1 = [
Headers,
payload : bstr / nil,
signature : bstr
]
]]></sourcecode>
</section>
<section anchor="Extern_AAD">
<name>Externally Supplied Data</name>
<t>
One of the features offered in the COSE document is the ability for applications to provide additional data to be authenticated, but that is not carried as part of the COSE object.
The primary reason for supporting this can be seen by looking at the CoAP message structure <xref target="RFC7252"/>, where the facility exists for options to be carried before the payload.
Examples of data that can be placed in this location would be the CoAP code or CoAP options.
If the data is in the headers of the CoAP message, then it is available for proxies to help in performing its operations.
For example, the Accept Option can be used by a proxy to determine if an appropriate value is in the proxy's cache.
But the sender can cause a failure at the server if a proxy, or an attacker, changes the set of accept values by including the field in the externally supplied data.
</t>
<t>
This document describes the process for using a byte array of externally supplied authenticated data; the method of constructing the byte array is a function of the application.
Applications that use this feature need to define how the externally supplied authenticated data is to be constructed. Such a construction needs to take into account the following issues:
</t>
<ul>
<li>
If multiple items are included, applications need to ensure that the same byte string cannot be produced if there are different inputs.
This would occur by concatenating the text strings 'AB' and 'CDE' or by concatenating the text strings 'ABC' and 'DE'.
This is usually addressed by making fields a fixed width and/or encoding the length of the field as part of the output.
Using options from CoAP <xref target="RFC7252"/> as an example, these fields use a TLV structure so they can be concatenated without any problems.
</li>
<li>If multiple items are included, an order for the items needs to be defined. Using options from CoAP as an example, an application could state that the fields are to be ordered by the option number. </li>
<li>
Applications need to ensure that the byte string is going to be the same on both sides.
Using options from CoAP might give a problem if the same relative numbering is kept.
An intermediate node could insert or remove an option, changing how the relative number is done.
An application would need to specify that the relative number must be re-encoded to be relative only to the options that are in the external data.
</li>
</ul>
</section>
<section anchor="Sig_structure">
<name>Signing and Verification Process</name>
<t>
In order to create a signature, a well-defined byte string is needed.
The Sig_structure is used to create the canonical form.
This signing and verification process takes in the body information (COSE_Sign or COSE_Sign1), the signer information (COSE_Signature), and the application data (external source).
A Sig_structure is a CBOR array.
The fields of the Sig_structure in order are:
</t>
<ol type="1">
<li>
<t>
A context text string identifying the context of the signature. The context text string is:
</t>
<ul empty="true">
<li>"Signature" for signatures using the COSE_Signature structure.</li>
<li>"Signature1" for signatures using the COSE_Sign1 structure.</li>
</ul>
</li>
<li>The protected attributes from the body structure encoded in a bstr type. If there are no protected attributes, a zero-length byte string is used. </li>
<li>The protected attributes from the signer structure encoded in a bstr type. If there are no protected attributes, a zero-length byte string is used. This field is omitted for the COSE_Sign1 signature structure. </li>
<li>The externally supplied data from the application encoded in a bstr type. If this field is not supplied, it defaults to a zero-length byte string. (See <xref target="Extern_AAD"/> for application guidance on constructing this field.) </li>
<li>The payload to be signed encoded in a bstr type. The payload is placed here independent of how it is transported. </li>
</ol>
<t>The CDDL fragment that describes the above text is: </t>
<sourcecode type="CDDL"><![CDATA[
Sig_structure = [
context : "Signature" / "Signature1",
body_protected : empty_or_serialized_map,
? sign_protected : empty_or_serialized_map,
external_aad : bstr,
payload : bstr
]
]]></sourcecode>
<t>How to compute a signature:
</t>
<ol type="1">
<li>Create a Sig_structure and populate it with the appropriate fields. </li>
<li>Create the value ToBeSigned by encoding the Sig_structure to a byte string, using the encoding described in <xref target="CBOR-Canonical"/>. </li>
<li>Call the signature creation algorithm passing in K (the key to sign with), alg (the algorithm to sign with), and ToBeSigned (the value to sign). </li>
<!--
" 4. Place the resulting signature value in the 'signature' field of
the array."
Although it is clear from the context, one might whish to specify which
array to avoid confusion.
[JLS] It is a bit problematical to say which array it is going into because this is one of three different arrays. However, it would go into a non-array for CounterSignature0. Hmmmmmm.
Need to think about how to adjust the text to deal with all of the different ways to put the signature someplace.
-->
<li>
Place the resulting signature value in the correct location.
This is the 'signature' field of the COSE_Signature or COSE_Sign1 structure.
</li>
</ol>
<t>The steps for verifying a signature are:
</t>
<ol type="1">
<li>Create a Sig_structure and populate it with the appropriate fields. </li>
<li>Create the value ToBeSigned by encoding the Sig_structure to a byte string, using the encoding described in <xref target="CBOR-Canonical"/>. </li>
<li>Call the signature verification algorithm passing in K (the key to verify with), alg (the algorithm used sign with), ToBeSigned (the value to sign), and sig (the signature to be verified). </li>
</ol>
<t>
In addition to performing the signature verification, the application performs the appropriate checks to ensure that the key is correctly paired with the signing identity and that the signing identity is authorized before performing actions.
</t>
</section>
</section>
<section anchor="encryption-object">
<name>Encryption Objects</name>
<t>
COSE supports two different encryption structures.
COSE_Encrypt0 is used when a recipient structure is not needed because the key to be used is known implicitly.
COSE_Encrypt is used the rest of the time.
This includes cases where there are multiple recipients or a recipient algorithm other than direct (i.e. pre-shared secret) is used.
</t>
<section anchor="EnvelopedData">
<name>Enveloped COSE Structure</name>
<t>The enveloped structure allows for one or more recipients of a message. There are provisions for header parameters about the content and header parameters about the recipient information to be carried in the message. The protected header parameters associated with the content are authenticated by the content encryption algorithm. The protected header parameters associated with the recipient are authenticated by the recipient algorithm (when the algorithm supports it). Examples of header parameters about the content are the type of the content and the content encryption algorithm. Examples of header parameters about the recipient are the recipient's key identifier and the recipient's encryption algorithm. </t>
<t>
The same techniques and nearly the same structure are used for encrypting both the plaintext and the keys.
This is different from the approach used by both "Cryptographic Message Syntax (CMS)" <xref target="RFC5652"/> and "JSON Web Encryption (JWE)" <xref target="RFC7516"/> where different structures are used for the content layer and for the recipient layer.
Two structures are defined: COSE_Encrypt to hold the encrypted content and COSE_recipient to hold the encrypted keys for recipients.
Examples of encrypted messages can be found in <xref target="EnvelopedExamples"/>.
</t>
<t>The COSE_Encrypt structure can be encoded as either tagged or untagged depending on the context it will be used in. A tagged COSE_Encrypt structure is identified by the CBOR tag 96. The CDDL fragment that represents this is: </t>
<sourcecode type="CDDL"><![CDATA[
COSE_Encrypt_Tagged = #6.96(COSE_Encrypt)
]]></sourcecode>
<t>The COSE_Encrypt structure is a CBOR array. The fields of the array in order are:
</t>
<dl newline="false">
<dt>protected:</dt>
<dd>This is as described in <xref target="header-parameters"/>. </dd>
<dt>unprotected:</dt>
<dd>This is as described in <xref target="header-parameters"/>. </dd>
<dt>ciphertext:</dt>
<dd>This field contains the ciphertext encoded as a bstr. If the ciphertext is to be transported independently of the control information about the encryption process (i.e., detached content), then the field is encoded as a nil value. </dd>
<dt>recipients:</dt>
<dd>This field contains an array of recipient information structures. The type for the recipient information structure is a COSE_recipient. </dd>
</dl>
<t>The CDDL fragment that corresponds to the above text is: </t>
<sourcecode type="CDDL"><![CDATA[
COSE_Encrypt = [
Headers,
ciphertext : bstr / nil,
recipients : [+COSE_recipient]
]
]]></sourcecode>
<t>The COSE_recipient structure is a CBOR array. The fields of the array in order are:
</t>
<dl newline="false">
<dt>protected:</dt>
<dd>This is as described in <xref target="header-parameters"/>. </dd>
<dt>unprotected:</dt>
<dd>This is as described in <xref target="header-parameters"/>. </dd>
<dt>ciphertext:</dt>
<dd>This field contains the encrypted key encoded as a bstr. All encoded keys are symmetric keys; the binary value of the key is the content. If there is not an encrypted key, then this field is encoded as a nil value. </dd>
<dt>recipients:</dt>
<dd>This field contains an array of recipient information structures. The type for the recipient information structure is a COSE_recipient (an example of this can be found in <xref target="three-layer"/>). If there are no recipient information structures, this element is absent. </dd>
</dl>
<t>The CDDL fragment that corresponds to the above text for COSE_recipient is: </t>
<sourcecode type="CDDL"><![CDATA[
COSE_recipient = [
Headers,
ciphertext : bstr / nil,
? recipients : [+COSE_recipient]
]
]]></sourcecode>
<section anchor="key-management-methods">
<name>Content Key Distribution Methods</name>
<t>
An encrypted message consists of an encrypted content and an encrypted CEK for one or more recipients.
The CEK is encrypted for each recipient, using a key specific to that recipient.
The details of this encryption depend on which class the recipient algorithm falls into.
Specific details on each of the classes can be found in <xref target="key-management-algs"/>.
A short summary of the five content key distribution methods is:
</t>
<dl newline="false">
<dt>direct:</dt>
<dd>
The CEK is the same as the identified previously distributed symmetric key or is derived from a previously distributed secret.
No CEK is transported in the message.
</dd>
<dt>symmetric key-encryption keys (KEK):</dt>
<dd>
The CEK is encrypted using a previously distributed symmetric KEK.
Also known as key wrap.
</dd>
<dt>key agreement:</dt>
<dd>
The recipient's public key and a sender's private key are used to generate a pairwise secret, a Key Derivation Function (KDF) is applied to derive a key, and then the CEK is either the derived key or encrypted by the derived key.
</dd>
<dt>key transport:</dt>
<dd>
The CEK is encrypted with the recipient's public key.
</dd>
<dt>passwords:</dt>
<dd>
The CEK is encrypted in a KEK that is derived from a password.
As of when this document was published, no password algorithms have been defined.
</dd>
</dl>
</section>
</section>
<section anchor="EnvelopedData0">
<name>Single Recipient Encrypted</name>
<t>The COSE_Encrypt0 encrypted structure does not have the ability to specify recipients of the message. The structure assumes that the recipient of the object will already know the identity of the key to be used in order to decrypt the message. If a key needs to be identified to the recipient, the enveloped structure ought to be used. </t>
<t>Examples of encrypted messages can be found in <xref target="EnvelopedExamples"/>. </t>
<t>The COSE_Encrypt0 structure can be encoded as either tagged or untagged depending on the context it will be used in. A tagged COSE_Encrypt0 structure is identified by the CBOR tag 16. The CDDL fragment that represents this is: </t>
<sourcecode type="CDDL"><![CDATA[
COSE_Encrypt0_Tagged = #6.16(COSE_Encrypt0)
]]></sourcecode>
<t>The COSE_Encrypt0 structure is a CBOR array. The fields of the array in order are:
</t>
<dl newline="false">
<dt>protected:</dt>
<dd>This is as described in <xref target="header-parameters"/>.</dd>
<dt>unprotected:</dt>
<dd>This is as described in <xref target="header-parameters"/>.</dd>
<dt>ciphertext:</dt>
<dd>This is as described in <xref target="EnvelopedData"/>.</dd>
</dl>
<t>The CDDL fragment for COSE_Encrypt0 that corresponds to the above text is: </t>
<sourcecode type="CDDL"><![CDATA[
COSE_Encrypt0 = [
Headers,
ciphertext : bstr / nil,
]
]]></sourcecode>
</section>
<section anchor="encryption-algorithm-for-aead-algorithms">
<name>How to Encrypt and Decrypt for AEAD Algorithms</name>
<t>The encryption algorithm for AEAD algorithms is fairly simple. The first step is to create a consistent byte string for the authenticated data structure. For this purpose, we use an Enc_structure. The Enc_structure is a CBOR array. The fields of the Enc_structure in order are:
</t>
<ol type="1">
<li>
<t>A context text string identifying the context of the authenticated data structure. The context text string is:
</t>
<ul empty="true">
<li>"Encrypt0" for the content encryption of a COSE_Encrypt0 data structure.</li>
<li>"Encrypt" for the first layer of a COSE_Encrypt data structure (i.e., for content encryption).</li>
<li>"Enc_Recipient" for a recipient encoding to be placed in an COSE_Encrypt data structure.</li>
<li>"Mac_Recipient" for a recipient encoding to be placed in a MACed message structure.</li>
<li>"Rec_Recipient" for a recipient encoding to be placed in a recipient structure.</li>
</ul>
</li>
<li>The protected attributes from the body structure encoded in a bstr type. If there are no protected attributes, a zero-length byte string is used. </li>
<li>The externally supplied data from the application encoded in a bstr type. If this field is not supplied, it defaults to a zero-length byte string. (See <xref target="Extern_AAD"/> for application guidance on constructing this field.) </li>
</ol>
<t>The CDDL fragment that describes the above text is: </t>
<sourcecode type="CDDL"><![CDATA[
Enc_structure = [
context : "Encrypt" / "Encrypt0" / "Enc_Recipient" /
"Mac_Recipient" / "Rec_Recipient",
protected : empty_or_serialized_map,
external_aad : bstr
]
]]></sourcecode>
<t>How to encrypt a message:
</t>
<ol type="1">
<li>Create an Enc_structure and populate it with the appropriate fields. </li>
<li>Encode the Enc_structure to a byte string (Additional Authenticated Data (AAD)), using the encoding described in <xref target="CBOR-Canonical"/>. </li>
<li>
<t>Determine the encryption key (K). This step is dependent on the class of recipient algorithm being used. For:
</t>
<dl newline="false">
<dt>No Recipients:</dt>
<dd>The key to be used is determined by the algorithm and key at the current layer. Examples are key transport keys (<xref target="KeyTransport"/>), key wrap keys (<xref target="key_wrap_algs"/>), or pre-shared secrets. </dd>
<dt>Direct Encryption and Direct Key Agreement:</dt>
<dd>
The key is determined by the key and algorithm in the recipient structure.
The encryption algorithm and size of the key to be used are inputs into the KDF used for the recipient.
(For direct, the KDF can be thought of as the identity operation.)
Examples of these algorithms are found in Sections 6.1.2 and 6.3 of <xref target="I-D.ietf-cose-rfc8152bis-algs"/>.
</dd>
<dt>Other:</dt>
<dd>The key is randomly or pseudo-randomly generated. </dd>