forked from jstedfast/MimeKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rfc2311.txt
2075 lines (1216 loc) · 69.2 KB
/
rfc2311.txt
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
863
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
Network Working Group S. Dusse
Request for Comments: 2311 RSA Data Security
Category: Informational P. Hoffman
Internet Mail Consortium
B. Ramsdell
Worldtalk
L. Lundblade
Qualcomm
L. Repka
Netscape
March 1998
S/MIME Version 2 Message Specification
Status of this Memo
This memo provides information for the Internet community. It does
not specify an Internet standard of any kind. Distribution of this
memo is unlimited.
Copyright Notice
Copyright (C) The Internet Society (1998). All Rights Reserved.
1. Introduction
S/MIME (Secure/Multipurpose Internet Mail Extensions) provides a
consistent way to send and receive secure MIME data. Based on the
popular Internet MIME standard, S/MIME provides the following
cryptographic security services for electronic messaging
applications: authentication, message integrity and non-repudiation
of origin (using digital signatures) and privacy and data security
(using encryption).
S/MIME can be used by traditional mail user agents (MUAs) to add
cryptographic security services to mail that is sent, and to
interpret cryptographic security services in mail that is received.
However, S/MIME is not restricted to mail; it can be used with any
transport mechanism that transports MIME data, such as HTTP. As such,
S/MIME takes advantage of the object-based features of MIME and
allows secure messages to be exchanged in mixed-transport systems.
Further, S/MIME can be used in automated message transfer agents that
use cryptographic security services that do not require any human
intervention, such as the signing of software-generated documents and
the encryption of FAX messages sent over the Internet.
Dusse, et. al. Informational [Page 1]
RFC 2311 S/MIME Version 2 Message Specification March 1998
Please note: The information in this document is historical material
being published for the public record. It is not an IETF standard.
The use of the word "standard" in this document indicates a standard
for adopters of S/MIME version 2, not an IETF standard.
1.1 Specification Overview
This document describes a protocol for adding cryptographic signature
and encryption services to MIME data. The MIME standard [MIME-SPEC]
provides a general structure for the content type of Internet
messages and allows extensions for new content type applications.
This memo defines how to create a MIME body part that has been
cryptographically enhanced according to PKCS #7 [PKCS-7]. This memo
also defines the application/pkcs7-mime MIME type that can be used to
transport those body parts. This memo also defines how to create
certification requests that conform to PKCS #10 [PKCS-10], and the
application/pkcs10 MIME type for transporting those requests.
This memo also discusses how to use the multipart/signed MIME type
defined in [MIME-SECURE] to transport S/MIME signed messages. This
memo also defines the application/pkcs7-signature MIME type, which is
also used to transport S/MIME signed messages. This specification is
compatible with PKCS #7 in that it uses the data types defined by
PKCS #7.
In order to create S/MIME messages, an agent has to follow
specifications in this memo, as well as some of the specifications
listed in the following documents:
- "PKCS #1: RSA Encryption", [PKCS-1]
- "PKCS #7: Cryptographic Message Syntax", [PKCS-7]
- "PKCS #10: Certification Request Syntax", [PKCS-10]
Throughout this memo, there are requirements and recommendations made
for how receiving agents handle incoming messages. There are separate
requirements and recommendations for how sending agents create
outgoing messages. In general, the best strategy is to "be liberal in
what you receive and conservative in what you send". Most of the
requirements are placed on the handling of incoming messages while
the recommendations are mostly on the creation of outgoing messages.
The separation for requirements on receiving agents and sending
agents also derives from the likelihood that there will be S/MIME
systems that involve software other than traditional Internet mail
clients. S/MIME can be used with any system that transports MIME
Dusse, et. al. Informational [Page 2]
RFC 2311 S/MIME Version 2 Message Specification March 1998
data. An automated process that sends an encrypted message might not
be able to receive an encrypted message at all, for example. Thus,
the requirements and recommendations for the two types of agents are
listed separately when appropriate.
1.2 Terminology
Throughout this memo, the terms MUST, MUST NOT, SHOULD, and SHOULD
NOT are used in capital letters. This conforms to the definitions in
[MUSTSHOULD]. [MUSTSHOULD] defines the use of these key words to
help make the intent of standards track documents as clear as
possible. The same key words are used in this document to help
implementors achieve interoperability.
1.3 Definitions
For the purposes of this memo, the following definitions apply.
ASN.1: Abstract Syntax Notation One, as defined in CCITT X.208.
BER: Basic Encoding Rules for ASN.1, as defined in CCITT X.209.
Certificate: A type that binds an entity's distinguished name to a
public key with a digital signature.
DER: Distinguished Encoding Rules for ASN.1, as defined in CCITT
X.509.
7-bit data: Text data with lines less than 998 characters long, where
none of the characters have the 8th bit set, and there are no NULL
characters. <CR> and <LF> occur only as part of a <CR><LF> end of
line delimiter.
8-bit data: Text data with lines less than 998 characters, and where
none of the characters are NULL characters. <CR> and <LF> occur only
as part of a <CR><LF> end of line delimiter.
Binary data: Arbitrary data.
Transfer Encoding: A reversible transformation made on data so 8-bit
or binary data may be sent via a channel that only transmits 7-bit
data.
1.4 Compatibility with Prior Practice of S/MIME
Appendix C contains important information about how S/MIME agents
following this specification should act in order to have the greatest
interoperability with earlier implementations of S/MIME.
Dusse, et. al. Informational [Page 3]
RFC 2311 S/MIME Version 2 Message Specification March 1998
2. PKCS #7 Options
The PKCS #7 message format allows for a wide variety of options in
content and algorithm support. This section puts forth a number of
support requirements and recommendations in order to achieve a base
level of interoperability among all S/MIME implementations.
2.1 DigestAlgorithmIdentifier
Receiving agents MUST support SHA-1 [SHA1] and MD5 [MD5].
Sending agents SHOULD use SHA-1.
2.2 DigestEncryptionAlgorithmIdentifier
Receiving agents MUST support rsaEncryption, defined in [PKCS-1].
Receiving agents MUST support verification of signatures using RSA
public key sizes from 512 bits to 1024 bits.
Sending agents MUST support rsaEncryption. Outgoing messages are
signed with a user's private key. The size of the private key is
determined during key generation.
2.3 KeyEncryptionAlgorithmIdentifier
Receiving agents MUST support rsaEncryption. Incoming encrypted
messages contain symmetric keys which are to be decrypted with a
user's private key. The size of the private key is determined during
key generation.
Sending agents MUST support rsaEncryption. Sending agents MUST
support encryption of symmetric keys with RSA public keys at key
sizes from 512 bits to 1024 bits.
2.4 General Syntax
The PKCS #7 defines six distinct content types: "data", "signedData",
"envelopedData", "signedAndEnvelopedData", "digestedData", and
"encryptedData". Receiving agents MUST support the "data",
"signedData" and "envelopedData" content types. Sending agents may or
may not send out any of the content types, depending on the services
that the agent supports.
2.4.1 Data Content Type
Sending agents MUST use the "data" content type as the content within
other content types to indicate the message content which has had
security services applied to it.
Dusse, et. al. Informational [Page 4]
RFC 2311 S/MIME Version 2 Message Specification March 1998
2.4.2 SignedData Content Type
Sending agents MUST use the signedData content type to apply a
digital signature to a message or, in a degenerate case where there
is no signature information, to convey certificates.
2.4.3 EnvelopedData Content Type
This content type is used to apply privacy protection to a message. A
sender needs to have access to a public key for each intended message
recipient to use this service. This content type does not provide
authentication.
2.5 Attribute SignerInfo Type
The SignerInfo type allows the inclusion of unauthenticated and
authenticated attributes to be included along with a signature.
Receiving agents MUST be able to handle zero or one instance of each
of the signed attributes described in this section.
Sending agents SHOULD be able to generate one instance of each of the
signed attributes described in this section, and SHOULD include these
attributes in each signed message sent.
Additional attributes and values for these attributes may be defined
in the future. Receiving agents SHOULD handle attributes or values
that it does not recognize in a graceful manner.
2.5.1 Signing-Time Attribute
The signing-time attribute is used to convey the time that a message
was signed. Until there are trusted timestamping services, the time
of signing will most likely be created by a message originator and
therefore is only as trustworthy as the originator.
Sending agents MUST encode signing time through the year 2049 as
UTCTime; signing times in 2050 or later MUST be encoded as
GeneralizedTime. Agents MUST interpret the year field (YY) as
follows: if YY is greater than or equal to 50, the year is
interpreted as 19YY; if YY is less than 50, the year is interpreted
as 20YY.
2.5.2 S/MIME Capabilities Attribute
The S/MIME capabilities attribute includes signature algorithms (such
as "md5WithRSAEncryption"), symmetric algorithms (such as "DES-CBC"),
and key encipherment algorithms (such as "rsaEncryption"). It also
Dusse, et. al. Informational [Page 5]
RFC 2311 S/MIME Version 2 Message Specification March 1998
includes a non-algorithm capability which is the preference for
signedData. SMIMECapabilities was designed to be flexible and
extensible so that, in the future, a means of identifying other
capabilities and preferences such as certificates can be added in a
way that will not cause current clients to break.
The semantics of the S/MIME capabilites attribute specify a partial
list as to what the client announcing the SMIMECapabilites can
support. A client does not have to list every capability it supports,
and probably should not list all its capabilities so that the
capabilities list doesn't get too long. In an SMIMECapabilities
encoding, the OIDs are listed in order of their preference, but
SHOULD be logically separated along the lines of their categories
(signature algorithms, symmetric algorithms, key encipherment
algorithms, etc.)
The structure of SMIMECapabilities was designed to facilitate simple
table lookups and binary comparisons in order to determine matches.
For instance, the DER-encoding for the SMIMECapability for DES EDE3
CBC MUST be identically encoded regardless of the implementation.
In the case of symmetric algorithms, the associated parameters for
the OID MUST specify all of the parameters necessary to differentiate
between two instances of the same algorithm. For instance, the number
of rounds and block size for RC5 must be specified in addition to the
key length.
There is a list of OIDs (the registered SMIMECapability list) that is
centrally maintained and is separate from this memo. The list of OIDs
is maintained by the Internet Mail Consortium at
<http://www.imc.org/ietf-smime/oids.html>.
The OIDs that correspond to algorithms SHOULD use the same OID as the
actual algorithm, except in the case where the algorithm usage is
ambiguous from the OID. For instance, in an earlier memo,
rsaEncryption was ambiguous because it could refer to either a
signature algorithm or a key encipherment algorithm. In the event
that an OID is ambiguous, it needs to be arbitrated by the maintainer
of the registered S/MIME capabilities list as to which type of
algorithm will use the OID, and a new OID MUST be allocated under the
smimeCapabilities OID to satisfy the other use of the OID.
The registered S/MIME capabilities list specifies the parameters for
OIDs that need them, most notably key lengths in the case of
variable-length symmetric ciphers. In the event that there are no
differentiating parameters for a particular OID, the parameters MUST
be omitted, and MUST NOT be encoded as NULL.
Dusse, et. al. Informational [Page 6]
RFC 2311 S/MIME Version 2 Message Specification March 1998
Additional values for SMIMECapability may be defined in the future.
Receiving agents MUST handle a SMIMECapabilities object that has
values that it does not recognize in a graceful manner.
2.6 ContentEncryptionAlgorithmIdentifier
Receiving agents MUST support decryption using the RC2 [RC2] or a
compatible algorithm at a key size of 40 bits, hereinafter called
"RC2/40". Receiving agents SHOULD support decryption using DES EDE3
CBC, hereinafter called "tripleDES" [3DES] [DES].
Sending agents SHOULD support encryption with RC2/40 and tripleDES.
2.6.1 Deciding Which Encryption Method To Use
When a sending agent creates an encrypted message, it has to decide
which type of encryption to use. The decision process involves using
information garnered from the capabilities lists included in messages
received from the recipient, as well as out-of-band information such
as private agreements, user preferences, legal restrictions, and so
on.
Section 2.5 defines a method by which a sending agent can optionally
announce, among other things, its decrypting capabilities in its
order of preference. The following method for processing and
remembering the encryption capabilities attribute in incoming signed
messages SHOULD be used.
- If the receiving agent has not yet created a list of capabilities
for the sender's public key, then, after verifying the signature
on the incoming message and checking the timestamp, the receiving
agent SHOULD create a new list containing at least the signing
time and the symmetric capabilities.
- If such a list already exists, the receiving agent SHOULD verify
that the signing time in the incoming message is greater than the
signing time stored in the list and that the signature is valid.
If so, the receiving agent SHOULD update both the signing time and
capabilities in the list. Values of the signing time that lie far
in the future (that is, a greater discrepancy than any reasonable
clock skew), or a capabilitie lists in messages whose signature
could not be verified, MUST NOT be accepted.
The list of capabilities SHOULD be stored for future use in creating
messages.
Before sending a message, the sending agent MUST decide whether it is
willing to use weak encryption for the particular data in the
Dusse, et. al. Informational [Page 7]
RFC 2311 S/MIME Version 2 Message Specification March 1998
message. If the sending agent decides that weak encryption is
unacceptable for this data, then the sending agent MUST NOT use a
weak algorithm such as RC2/40. The decision to use or not use weak
encryption overrides any other decision in this section about which
encryption algorithm to use.
Sections 2.6.2.1 through 2.6.2.4 describe the decisions a sending
agent SHOULD use in deciding which type of encryption should be
applied to a message. These rules are ordered, so the sending agent
SHOULD make its decision in the order given.
2.6.2.1 Rule 1: Known Capabilities
If the sending agent has received a set of capabilities from the
recipient for the message the agent is about to encrypt, then the
sending agent SHOULD use that information by selecting the first
capability in the list (that is, the capability most preferred by the
intended recipient) for which the sending agent knows how to encrypt.
The sending agent SHOULD use one of the capabilities in the list if
the agent reasonably expects the recipient to be able to decrypt the
message.
2.6.2.2 Rule 2: Unknown Capabilities, Known Use of Encryption
If:
- the sending agent has no knowledge of the encryption capabilities
of the recipient,
- and the sending agent has received at least one message from the
recipient,
- and the last encrypted message received from the recipient had a
trusted signature on it,
then the outgoing message SHOULD use the same encryption algorithm as
was used on the last signed and encrypted message received from the
recipient.
2.6.2.3 Rule 3: Unknown Capabilities, Risk of Failed Decryption
If:
- the sending agent has no knowledge of the encryption capabilities
of the recipient,
- and the sending agent is willing to risk that the recipient may
not be able to decrypt the message,
then the sending agent SHOULD use tripleDES.
Dusse, et. al. Informational [Page 8]
RFC 2311 S/MIME Version 2 Message Specification March 1998
2.6.2.4 Rule 4: Unknown Capabilities, No Risk of Failed Decryption
If:
- the sending agent has no knowledge of the encryption capabilities
of the recipient,
- and the sending agent is not willing to risk that the recipient
may not be able to decrypt the message,
then the sending agent MUST use RC2/40.
2.6.3 Choosing Weak Encryption
Like all algorithms that use 40 bit keys, RC2/40 is considered by
many to be weak encryption. A sending agent that is controlled by a
human SHOULD allow a human sender to determine the risks of sending
data using RC2/40 or a similarly weak encryption algorithm before
sending the data, and possibly allow the human to use a stronger
encryption method such as tripleDES.
2.6.4 Multiple Recipients
If a sending agent is composing an encrypted message to a group of
recipients where the encryption capabilities of some of the
recipients do not overlap, the sending agent is forced to send more
than one message. It should be noted that if the sending agent
chooses to send a message encrypted with a strong algorithm, and then
send the same message encrypted with a weak algorithm, someone
watching the communications channel can decipher the contents of the
strongly-encrypted message simply by decrypting the weakly-encrypted
message.
3. Creating S/MIME Messages
This section describes the S/MIME message formats and how they are
created. S/MIME messages are a combination of MIME bodies and PKCS
objects. Several MIME types as well as several PKCS objects are used.
The data to be secured is always a canonical MIME entity. The MIME
entity and other data, such as certificates and algorithm
identifiers, are given to PKCS processing facilities which produces a
PKCS object. The PKCS object is then finally wrapped in MIME.
S/MIME provides one format for enveloped-only data, several formats
for signed-only data, and several formats for signed and enveloped
data. Several formats are required to accommodate several
environments, in particular for signed messages. The criteria for
choosing among these formats are also described.
The reader of this section is expected to understand MIME as
described in [MIME-SPEC] and [MIME-SECURE].
Dusse, et. al. Informational [Page 9]
RFC 2311 S/MIME Version 2 Message Specification March 1998
3.1 Preparing the MIME Entity for Signing or Enveloping
S/MIME is used to secure MIME entities. A MIME entity may be a sub-
part, sub-parts of a message, or the whole message with all its sub-
parts. A MIME entity that is the whole message includes only the MIME
headers and MIME body, and does not include the RFC-822 headers. Note
that S/MIME can also be used to secure MIME entities used in
applications other than Internet mail.
The MIME entity that is secured and described in this section can be
thought of as the "inside" MIME entity. That is, it is the
"innermost" object in what is possibly a larger MIME message.
Processing "outside" MIME entities into PKCS #7 objects is described
in Section 3.2, 3.4 and elsewhere.
The procedure for preparing a MIME entity is given in [MIME-SPEC].
The same procedure is used here with some additional restrictions
when signing. Description of the procedures from [MIME-SPEC] are
repeated here, but the reader should refer to that document for the
exact procedure. This section also describes additional requirements.
A single procedure is used for creating MIME entities that are to be
signed, enveloped, or both signed and enveloped. Some additional
steps are recommended to defend against known corruptions that can
occur during mail transport that are of particular importance for
clear-signing using the multipart/signed format. It is recommended
that these additional steps be performed on enveloped messages, or
signed and enveloped messages in order that the message can be
forwarded to any environment without modification.
These steps are descriptive rather than prescriptive. The implementor
is free to use any procedure as long as the result is the same.
Step 1. The MIME entity is prepared according to the local
conventions
Step 2. The leaf parts of the MIME entity are converted to
canonical form
Step 3. Appropriate transfer encoding is applied to the leaves of
the MIME entity
When an S/MIME message is received, the security services on the
message are removed, and the result is the MIME entity. That MIME
entity is typically passed to a MIME-capable user agent where, it is
further decoded and presented to the user or receiving application.
Dusse, et. al. Informational [Page 10]
RFC 2311 S/MIME Version 2 Message Specification March 1998
3.1.1 Canonicalization
Each MIME entity MUST be converted to a canonical form that is
uniquely and unambiguously representable in the environment where the
signature is created and the environment where the signature will be
verified. MIME entities MUST be canonicalized for enveloping as well
as signing.
The exact details of canonicalization depend on the actual MIME type
and subtype of an entity, and are not described here. Instead, the
standard for the particular MIME type should be consulted. For
example, canonicalization of type text/plain is different from
canonicalization of audio/basic. Other than text types, most types
have only one representation regardless of computing platform or
environment which can be considered their canonical representation.
In general, canonicalization will be performed by the sending agent
rather than the S/MIME implementation.
The most common and important canonicalization is for text, which is
often represented differently in different environments. MIME
entities of major type "text" must have both their line endings and
character set canonicalized. The line ending must be the pair of
characters <CR><LF>, and the charset should be a registered charset
[CHARSETS]. The details of the canonicalization are specified in
[MIME-SPEC]. The chosen charset SHOULD be named in the charset
parameter so that the receiving agent can unambiguously determine the
charset used.
Note that some charsets such as ISO-2022 have multiple
representations for the same characters. When preparing such text for
signing, the canonical representation specified for the charset MUST
be used.
3.1.2 Transfer Encoding
When generating any of the secured MIME entities below, except the
signing using the multipart/signed format, no transfer encoding at
all is required. S/MIME implementations MUST be able to deal with
binary MIME objects. If no Content-Transfer-Encoding header is
present, the transfer encoding should be considered 7BIT.
S/MIME implementations SHOULD however use transfer encoding described
in section 3.1.3 for all MIME entities they secure. The reason for
securing only 7-bit MIME entities, even for enveloped data that are
not exposed to the transport, is that it allows the MIME entity to be
handled in any environment without changing it. For example, a
trusted gateway might remove the envelope, but not the signature, of
a message, and then forward the signed message on to the end
Dusse, et. al. Informational [Page 11]
RFC 2311 S/MIME Version 2 Message Specification March 1998
recipient so that they can verify the signatures directly. If the
transport internal to the site is not 8-bit clean, such as on a
wide-area network with a single mail gateway, verifying the signature
will not be possible unless the original MIME entity was only 7-bit
data.
3.1.3 Transfer Encoding for Signing Using multipart/signed
If a multipart/signed entity is EVER to be transmitted over the
standard Internet SMTP infrastructure or other transport that is
constrained to 7-bit text, it MUST have transfer encoding applied so
that it is represented as 7-bit text. MIME entities that are 7-bit
data already need no transfer encoding. Entities such as 8-bit text
and binary data can be encoded with quoted-printable or base-64
transfer encoding.
The primary reason for the 7-bit requirement is that the Internet
mail transport infrastructure cannot guarantee transport of 8-bit or
binary data. Even though many segments of the transport
infrastructure now handle 8-bit and even binary data, it is sometimes
not possible to know whether the transport path is 8-bit clear. If a
mail message with 8-bit data were to encounter a message transfer
agent that can not transmit 8-bit or binary data, the agent has three
options, none of which are acceptable for a clear-signed message:
- The agent could change the transfer encoding; this would
invalidate the signature.
- The agent could transmit the data anyway, which would most likely
result in the 8th bit being corrupted; this too would invalidate
the signature.
- The agent could return the message to the sender.
[MIME-SECURE] prohibits an agent from changing the transfer encoding
of the first part of a multipart/signed message. If a compliant agent
that can not transmit 8-bit or binary data encounters a
multipart/signed message with 8-bit or binary data in the first part,
it would have to return the message to the sender as undeliverable.
3.1.4 Sample Canonical MIME Entity
This example shows a multipart/mixed message with full transfer
encoding. This message contains a text part and an attachment. The
sample message text includes characters that are not US-ASCII and
thus must be transfer encoded. Though not shown here, the end of each
line is <CR><LF>. The line ending of the MIME headers, the text, and
transfer encoded parts, all must be <CR><LF>.
Note that this example is not of an S/MIME message.
Dusse, et. al. Informational [Page 12]
RFC 2311 S/MIME Version 2 Message Specification March 1998
Content-Type: multipart/mixed; boundary=bar
--bar
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
=A1Hola Michael!
How do you like the new S/MIME specification?
I agree. It's generally a good idea to encode lines that begin with
From=20because some mail transport agents will insert a greater-
than (>) sign, thus invalidating the signature.
Also, in some cases it might be desirable to encode any =20
trailing whitespace that occurs on lines in order to ensure =20
that the message signature is not invalidated when passing =20
a gateway that modifies such whitespace (like BITNET). =20
--bar
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
iQCVAwUBMJrRF2N9oWBghPDJAQE9UQQAtl7LuRVndBjrk4EqYBIb3h5QXIX/LC//
jJV5bNvkZIGPIcEmI5iFd9boEgvpirHtIREEqLQRkYNoBActFBZmh9GC3C041WGq
uMbrbxc nIs1TIKlA08rVi9ig/2Yh7LFrK5Ein57U/W72vgSxLhe/zhdfolT9Brn
HOxEa44b EI=
--bar--
3.2 The application/pkcs7-mime Type
The application/pkcs7-mime type is used to carry PKCS #7 objects of
several types including envelopedData and signedData. The details of
constructing these entities is described in subsequent sections. This
section describes the general characteristics of the
application/pkcs7-mime type.
This MIME type always carries a single PKCS #7 object. The PKCS #7
object must always be BER encoding of the ASN.1 syntax describing the
object. The contentInfo field of the carried PKCS #7 object always
contains a MIME entity that is prepared as described in section 3.1.
The contentInfo field must never be empty.
Since PKCS #7 objects are binary data, in most cases base-64 transfer
encoding is appropriate, in particular when used with SMTP transport.
The transfer encoding used depends on the transport through which the
object is to be sent, and is not a characteristic of the MIME type.
Dusse, et. al. Informational [Page 13]
RFC 2311 S/MIME Version 2 Message Specification March 1998
Note that this discussion refers to the transfer encoding of the PKCS
#7 object or "outside" MIME entity. It is completely distinct from,
and unrelated to, the transfer encoding of the MIME entity secured by
the PKCS #7 object, the "inside" object, which is described in
section 3.1.
Because there are several types of application/pkcs7-mime objects, a
sending agent SHOULD do as much as possible to help a receiving agent
know about the contents of the object without forcing the receiving
agent to decode the ASN.1 for the object. The MIME headers of all
application/pkcs7-mime objects SHOULD include the optional "smime-
type" parameter, as described in the following sections.
3.2.1 The name and filename Parameters
For the application/pkcs7-mime, sending agents SHOULD emit the
optional "name" parameter to the Content-Type field for compatibility
with older systems. Sending agents SHOULD also emit the optional
Content-Disposition field [CONTDISP] with the "filename" parameter.
If a sending agent emits the above parameters, the value of the
parameters SHOULD be a file name with the appropriate extension:
MIME Type File Extension
application/pkcs7-mime .p7m
(signedData, envelopedData)
application/pkcs7-mime .p7c
(degenerate signedData
"certs-only" message)
application/pkcs7-signature .p7s
application/pkcs10 .p10
In addition, the file name SHOULD be limited to eight characters
followed by a three letter extension. The eight character filename
base can be any distinct name; the use of the filename base "smime"
SHOULD be used to indicate that the MIME entity is associated with
S/MIME.
Including a file name serves two purposes. It facilitates easier use
of S/MIME objects as files on disk. It also can convey type
information across gateways. When a MIME entity of type
application/pkcs7-mime (for example) arrives at a gateway that has no
special knowledge of S/MIME, it will default the entity's MIME type
to application/octet-stream and treat it as a generic attachment,
thus losing the type information. However, the suggested filename for
Dusse, et. al. Informational [Page 14]
RFC 2311 S/MIME Version 2 Message Specification March 1998
an attachment is often carried across a gateway. This often allows
the receiving systems to determine the appropriate application to
hand the attachment off to, in this case a stand-alone S/MIME
processing application. Note that this mechanism is provided as a
convenience for implementations in certain environments. A proper
S/MIME implementation MUST use the MIME types and MUST NOT rely on
the file extensions.
3.3 Creating an Enveloped-only Message
This section describes the format for enveloping a MIME entity
without signing it.
Step 1. The MIME entity to be enveloped is prepared according to
section 3.1.
Step 2. The MIME entity and other required data is processed into a
PKCS #7 object of type envelopedData.
Step 3. The PKCS #7 object is inserted into an application/pkcs7-
mime MIME entity.
The smime-type parameter for enveloped-only messages is "enveloped-
data". The file extension for this type of message is ".p7m".
A sample message would be:
Content-Type: application/pkcs7-mime; smime-type=enveloped-data;
name=smime.p7m
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=smime.p7m
rfvbnj756tbBghyHhHUujhJhjH77n8HHGT9HG4VQpfyF467GhIGfHfYT6
7n8HHGghyHhHUujhJh4VQpfyF467GhIGfHfYGTrfvbnjT6jH7756tbB9H
f8HHGTrfvhJhjH776tbB9HG4VQbnj7567GhIGfHfYT6ghyHhHUujpfyF4
0GhIGfHfQbnj756YT64V
3.4 Creating a Signed-only Message
There are two formats for signed messages defined for S/MIME:
application/pkcs7-mime and SignedData, and multipart/signed. In
general, the multipart/signed form is preferred for sending, and
receiving agents SHOULD be able to handle both.
3.4.1 Choosing a Format for Signed-only Messages
There are no hard-and-fast rules when a particular signed-only format
should be chosen because it depends on the capabilities of all the
Dusse, et. al. Informational [Page 15]
RFC 2311 S/MIME Version 2 Message Specification March 1998
receivers and the relative importance of receivers with S/MIME
facilities being able to verify the signature versus the importance
of receivers without S/MIME software being able to view the message.
Messages signed using the multipart/signed format can always be
viewed by the receiver whether they have S/MIME software or not. They
can also be viewed whether they are using a MIME-native user agent or
they have messages translated by a gateway. In this context, "be
viewed" means the ability to process the message essentially as if it
were not a signed message, including any other MIME structure the
message might have.
Messages signed using the signedData format cannot be viewed by a
recipient unless they have S/MIME facilities. However, if they have
S/MIME facilities, these messages can always be verified if they were
not changed in transit.
3.4.2 Signing Using application/pkcs7-mime and SignedData
This signing format uses the application/pkcs7-mime MIME type. The
steps to create this format are:
Step 1. The MIME entity is prepared according to section 3.1
Step 2. The MIME entity and other required data is processed into a
PKCS #7 object of type signedData
Step 3. The PKCS #7 object is inserted into an
application/pkcs7-mime MIME entity
The smime-type parameter for messages using application/pkcs7-mime
and SignedData is "signed-data". The file extension for this type of
message is ".p7m".
A sample message would be:
Content-Type: application/pkcs7-mime; smime-type=signed-data;
name=smime.p7m
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=smime.p7m
567GhIGfHfYT6ghyHhHUujpfyF4f8HHGTrfvhJhjH776tbB9HG4VQbnj7
77n8HHGT9HG4VQpfyF467GhIGfHfYT6rfvbnj756tbBghyHhHUujhJhjH
HUujhJh4VQpfyF467GhIGfHfYGTrfvbnjT6jH7756tbB9H7n8HHGghyHh
6YT64V0GhIGfHfQbnj75
Dusse, et. al. Informational [Page 16]
RFC 2311 S/MIME Version 2 Message Specification March 1998
3.4.3 Signing Using the multipart/signed Format
This format is a clear-signing format. Recipients without any S/MIME
or PKCS processing facilities are able to view the message. It makes
use of the multipart/signed MIME type described in [MIME-SECURE]. The
multipart/signed MIME type has two parts. The first part contains the
MIME entity that is to be signed; the second part contains the
signature, which is a PKCS #7 detached signature.
3.4.3.1 The application/pkcs7-signature MIME Type
This MIME type always contains a single PKCS #7 object of type
signedData. The contentInfo field of the PKCS #7 object must be
empty. The signerInfos field contains the signatures for the MIME
entity. The details of the registered type are given in Appendix D.
The file extension for signed-only messages using application/pkcs7-
signature is ".p7s".
3.4.3.2 Creating a multipart/signed Message
Step 1. The MIME entity to be signed is prepared according to
section 3.1, taking special care for clear-signing.
Step 2. The MIME entity is presented to PKCS #7 processing in order
to obtain an object of type signedData with an empty
contentInfo field.
Step 3. The MIME entity is inserted into the first part of a
multipart/signed message with no processing other than that
described in section 3.1.
Step 4. Transfer encoding is applied to the detached signature and
it is inserted into a MIME entity of type
application/pkcs7-signature
Step 5. The MIME entity of the application/pkcs7-signature is
inserted into the second part of the multipart/signed
entity
The multipart/signed Content type has two required parameters: the
protocol parameter and the micalg parameter.
The protocol parameter MUST be "application/pkcs7-signature". Note
that quotation marks are required around the protocol parameter
because MIME requires that the "/" character in the parameter value
MUST be quoted.
Dusse, et. al. Informational [Page 17]
RFC 2311 S/MIME Version 2 Message Specification March 1998
The micalg parameter allows for one-pass processing when the
signature is being verified. The value of the micalg parameter is
dependent on the message digest algorithm used in the calculation of
the Message Integrity Check. The value of the micalg parameter SHOULD
be one of the following:
Algorithm used Value
-------------- ---------
MD5 md5
SHA-1 sha1
any other unknown
(Historical note: some early implementations of S/MIME emitted and
expected "rsa-md5" and "rsa-sha1" for the micalg parameter.)
Receiving agents SHOULD be able to recover gracefully from a micalg
parameter value that they do not recognize.
3.4.3.3 Sample multipart/signed Message
Content-Type: multipart/signed;
protocol="application/pkcs7-signature";
micalg=sha1; boundary=boundary42
--boundary42
Content-Type: text/plain
This is a clear-signed message.
--boundary42
Content-Type: application/pkcs7-signature; name=smime.p7s
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=smime.p7s
ghyHhHUujhJhjH77n8HHGTrfvbnj756tbB9HG4VQpfyF467GhIGfHfYT6
4VQpfyF467GhIGfHfYT6jH77n8HHGghyHhHUujhJh756tbB9HGTrfvbnj
n8HHGTrfvhJhjH776tbB9HG4VQbnj7567GhIGfHfYT6ghyHhHUujpfyF4
7GhIGfHfYT64VQbnj756
--boundary42--
3.5 Signing and Encrypting