RFC 2630
Cryptographic Message Syntax
Cryptographic Message Syntax ๐
Okay bestie, this is RFC 2630 ๐, and it's all about the Cryptographic Message Syntax, or CMS for short. Here's the title block tea โ:
- Author: R. Housley, from SPYRUS
- Stream: Network Working Group
- Category: Standards Track ๐ฆ
- Date: June 1999 ๐ธ
- Obsoletes / Updates: the title block doesn't list either one ๐
Status of this Memo ๐
This is an Internet standards track protocol for the Internet community, and it's literally asking for discussion and suggestions for improvements ๐ . For the standardization state and status of this protocol, check the current edition of the "Internet Official Protocol Standards" (STD 1). Distribution of this memo is unlimited โจ.
Copyright Notice ยฉ๏ธ
Copyright (C) The Internet Society (1999). All Rights Reserved. ๐
Abstract ๐ธ
So this doc describes CMS, and CMS is the thing you use to digitally sign, digest, authenticate, or encrypt arbitrary messages ๐ฅ.
CMS is derived from PKCS #7 version 1.5, as specified in RFC 2315 [PKCS#7]. Backward compatibility is preserved wherever possible ๐ซถ. Changes were necessary, though, to accommodate attribute certificate transfer and key agreement techniques for key management โญ.
Table of Contents ๐ง
1 Introduction ................................................. 4
2 General Overview ............................................. 4
3 General Syntax ............................................... 5
4 Data Content Type ............................................ 5
5 Signed-data Content Type ..................................... 6
5.1 SignedData Type ......................................... 7
5.2 EncapsulatedContentInfo Type ............................ 8
5.3 SignerInfo Type ......................................... 9
5.4 Message Digest Calculation Process ...................... 11
5.5 Message Signature Generation Process .................... 12
5.6 Message Signature Verification Process .................. 12
6 Enveloped-data Content Type .................................. 12
6.1 EnvelopedData Type ...................................... 14
6.2 RecipientInfo Type ...................................... 15
6.2.1 KeyTransRecipientInfo Type ....................... 16
6.2.2 KeyAgreeRecipientInfo Type ....................... 17
6.2.3 KEKRecipientInfo Type ............................ 19
6.3 Content-encryption Process .............................. 20
6.4 Key-encryption Process .................................. 20
7 Digested-data Content Type ................................... 21
8 Encrypted-data Content Type .................................. 22
9 Authenticated-data Content Type .............................. 23
9.1 AuthenticatedData Type .................................. 23
9.2 MAC Generation .......................................... 25
9.3 MAC Verification ........................................ 26
10 Useful Types ................................................. 27
10.1 Algorithm Identifier Types ............................. 27
10.1.1 DigestAlgorithmIdentifier ...................... 27
10.1.2 SignatureAlgorithmIdentifier ................... 27
10.1.3 KeyEncryptionAlgorithmIdentifier ............... 28
10.1.4 ContentEncryptionAlgorithmIdentifier ........... 28
10.1.5 MessageAuthenticationCodeAlgorithm ............. 28
10.2 Other Useful Types ..................................... 28
10.2.1 CertificateRevocationLists ..................... 28
10.2.2 CertificateChoices ............................. 29
10.2.3 CertificateSet ................................. 29
10.2.4 IssuerAndSerialNumber .......................... 30
10.2.5 CMSVersion ..................................... 30
10.2.6 UserKeyingMaterial ............................. 30
10.2.7 OtherKeyAttribute .............................. 30
11 Useful Attributes ............................................ 31
11.1 Content Type ........................................... 31
11.2 Message Digest ......................................... 32
11.3 Signing Time ........................................... 32
11.4 Countersignature ....................................... 34
12 Supported Algorithms ......................................... 35
12.1 Digest Algorithms ...................................... 35
12.1.1 SHA-1 .......................................... 35
12.1.2 MD5 ............................................ 35
12.2 Signature Algorithms ................................... 36
12.2.1 DSA ............................................ 36
12.2.2 RSA ............................................ 36
12.3 Key Management Algorithms .............................. 36
12.3.1 Key Agreement Algorithms ....................... 36
12.3.1.1 X9.42 Ephemeral-Static Diffie-Hellman. 37
12.3.2 Key Transport Algorithms ....................... 38
12.3.2.1 RSA .................................. 39
12.3.3 Symmetric Key-Encryption Key Algorithms ........ 39
12.3.3.1 Triple-DES Key Wrap .................. 40
12.3.3.2 RC2 Key Wrap ......................... 41
12.4 Content Encryption Algorithms ........................... 41
12.4.1 Triple-DES CBC .................................. 42
12.4.2 RC2 CBC ......................................... 42
12.5 Message Authentication Code Algorithms .................. 42
12.5.1 HMAC with SHA-1 ................................. 43
12.6 Triple-DES and RC2 Key Wrap Algorithms .................. 43
12.6.1 Key Checksum .................................... 44
12.6.2 Triple-DES Key Wrap ............................. 44
12.6.3 Triple-DES Key Unwrap ........................... 44
12.6.4 RC2 Key Wrap .................................... 45
12.6.5 RC2 Key Unwrap .................................. 46
Appendix A: ASN.1 Module ........................................ 47
References ....................................................... 55
Security Considerations .......................................... 56
Acknowledgments .................................................. 58
Author's Address ................................................. 59
Full Copyright Statement ......................................... 60
1. Introduction โจ
This document describes CMS, and it's used to digitally sign, digest, authenticate, or encrypt arbitrary messages ๐.
CMS is an encapsulation syntax for data protection ๐. It supports digital signatures, message authentication codes, and encryption. The syntax allows multiple encapsulation, so one envelope can be nested inside another, which is so iconic ๐ญ. Likewise, one party can digitally sign some data that was already encapsulated. It also lets you sign arbitrary attributes, like signing time, along with the message content. And it provides for other attributes, such as countersignatures, to be associated with a signature ๐.
CMS can support a bunch of architectures for certificate-based key management, like the one defined by the PKIX working group ๐ง.
CMS values are generated using ASN.1 [X.208-88], using BER-encoding [X.209-88]. Values are typically represented as octet strings. Lots of systems can transmit arbitrary octet strings reliably, but it's well known that many electronic-mail systems can't ๐. This document doesn't address mechanisms for encoding octet strings for reliable transmission in those environments ๐.
2. General Overview ๐
CMS is general enough to support many different content types ๐. This document defines one protection content, ContentInfo. ContentInfo encapsulates a single identified content type, and that identified type may provide further encapsulation. This document defines six content types: data, signed-data, enveloped-data, digested-data, encrypted-data, and authenticated-data. Additional content types can be defined outside this document ๐.
An implementation that conforms to this specification must implement the protection content, ContentInfo, and must implement the data, signed-data, and enveloped-data content types. The other content types may be implemented if desired ๐ซถ.
As a general design philosophy, each content type permits single-pass processing using indefinite-length Basic Encoding Rules (BER) encoding. Single-pass operation is especially helpful if content is large, stored on tapes, or "piped" from another process ๐ฆ. It has one significant drawback, though: it's difficult to perform encode operations using the Distinguished Encoding Rules (DER) [X.509-88] encoding in a single pass, since the lengths of the various components may not be known in advance ๐ฅฒ.
However, signed attributes within the signed-data content type and authenticated attributes within the authenticated-data content type require DER encoding. Signed attributes and authenticated attributes must be transmitted in DER form to ensure that recipients can verify a content that contains one or more unrecognized attributes ๐ฅ. Signed attributes and authenticated attributes are the only CMS data types that require DER encoding โจ.
3. General Syntax ๐ซถ
CMS associates a content type identifier with a content ๐. The syntax shall have ASN.1 type ContentInfo:
ContentInfo ::= SEQUENCE {
contentType ContentType,
content [0] EXPLICIT ANY DEFINED BY contentType }
ContentType ::= OBJECT IDENTIFIER
Here's what the fields of ContentInfo mean ๐:
contentType indicates the type of the associated content. It is
an object identifier; it is a unique string of integers assigned
by an authority that defines the content type.
content is the associated content. The type of content can be
determined uniquely by contentType. Content types for data,
signed-data, enveloped-data, digested-data, encrypted-data, and
authenticated-data are defined in this document. If additional
content types are defined in other documents, the ASN.1 type
defined should not be a CHOICE type.
4. Data Content Type ๐ธ
The data content type gets its own object identifier, and here it is ๐ง:
id-data OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs7(7) 1 }
The data content type is meant for arbitrary octet strings, like ASCII text files. The interpretation is left up to the application ๐. Those strings don't need any internal structure, though they could have their own ASN.1 definition or other structure ๐.
The data content type is generally encapsulated in the signed-data, enveloped-data, digested-data, encrypted-data, or authenticated-data content type ๐.
5. Signed-data Content Type โจ
okay bestie, the signed-data content type is literally giving "hold my content, I'm about to get signed" ๐ It's any type of content plus zero or more signature values. Any number of signers can sign in parallel, and they can sign any type of content ๐ซถ
The typical use is one signer's digital signature on data content ๐ The other typical use is passing around certificates and certificate revocation lists (CRLs) ๐ธ
Here's how signed-data gets built, step by step:
- For each signer, a message digest (aka hash value) is computed on the content with that signer's own message-digest algorithm. If the signer is signing anything other than the content, the message digest of the content and that other information get digested together with the signer's message digest algorithm (see Section 5.4), and the result becomes the "message digest." ๐ง
- For each signer, the message digest is digitally signed using the signer's private key.
- For each signer, the signature value and other signer-specific information get collected into a SignerInfo value, as defined in Section 5.3. Certificates and CRLs for each signer, and those not corresponding to any signer, get collected in this step too.
- The message digest algorithms for all the signers and the SignerInfo values for all the signers get collected together with the content into a SignedData value, as defined in Section 5.1.
On the recipient side, they independently compute the message digest ๐ That digest and the signer's public key are used to verify the signature value. The signer's public key is referenced either by an issuer distinguished name plus an issuer-specific serial number, or by a subject key identifier that uniquely identifies the certificate containing the public key. The signer's certificate may be included in the SignedData certificates field.
This section is split into six parts. The first covers the top-level type SignedData, the second covers EncapsulatedContentInfo, and the third covers the per-signer type SignerInfo. The fourth, fifth, and sixth parts cover the message digest calculation, signature generation, and signature verification processes, in that order ๐
5.1. SignedData Type
The following object identifier identifies the signed-data content type:
id-signedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs7(7) 2 }
The signed-data content type shall have ASN.1 type SignedData:
SignedData ::= SEQUENCE {
version CMSVersion,
digestAlgorithms DigestAlgorithmIdentifiers,
encapContentInfo EncapsulatedContentInfo,
certificates [0] IMPLICIT CertificateSet OPTIONAL,
crls [1] IMPLICIT CertificateRevocationLists OPTIONAL,
signerInfos SignerInfos }
DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier
SignerInfos ::= SET OF SignerInfo
The fields of type SignedData have the following meanings:
versionis the syntax version number. If no attribute certificates are present in the certificates field, the encapsulated content type is id-data, and all of the elements of SignerInfos are version 1, then the value of version shall be 1. Alternatively, if attribute certificates are present, the encapsulated content type is other than id-data, or any of the elements of SignerInfos are version 3, then the value of version shall be 3. ๐digestAlgorithmsis a collection of message digest algorithm identifiers. There may be any number of elements in the collection, including zero. Each element identifies the message digest algorithm, along with any associated parameters, used by one or more signers. The collection is meant to list the message digest algorithms used by all of the signers, in any order, so that signature verification can be done in one pass. The message digesting process is described in Section 5.4.encapContentInfois the signed content, made up of a content type identifier and the content itself. Details of the EncapsulatedContentInfo type are discussed in section 5.2.certificatesis a collection of certificates. The set of certificates should be enough to contain chains from a recognized "root" or "top-level certification authority" to all of the signers in the signerInfos field. There may be more certificates than necessary, and there may be certificates enough to contain chains from two or more independent top-level certification authorities. There may also be fewer certificates than necessary, if it is expected that recipients have an alternate means of getting the necessary certificates (e.g., from a previous set of certificates). As discussed above, if attribute certificates are present, then the value of version shall be 3. ๐ธcrlsis a collection of certificate revocation lists (CRLs). The set is meant to contain information enough to determine whether or not the certificates in the certificates field are valid, but that correspondence is not necessary. There may be more CRLs than necessary, and there may also be fewer CRLs than necessary.signerInfosis a collection of per-signer information. There may be any number of elements in the collection, including zero. The details of the SignerInfo type are discussed in section 5.3. ๐ง
5.2. EncapsulatedContentInfo Type
The content is represented in the type EncapsulatedContentInfo:
EncapsulatedContentInfo ::= SEQUENCE {
eContentType ContentType,
eContent [0] EXPLICIT OCTET STRING OPTIONAL }
ContentType ::= OBJECT IDENTIFIER
The fields of type EncapsulatedContentInfo have the following meanings:
eContentTypeis an object identifier that uniquely specifies the content type.eContentis the content itself, carried as an octet string. The eContent need not be DER encoded. ๐ฆ
The optional omission of the eContent within the EncapsulatedContentInfo field makes it possible to build "external signatures." ๐ซฃ With external signatures, the content being signed is absent from the EncapsulatedContentInfo value included in the signed-data content type. If the eContent value within EncapsulatedContentInfo is absent, then the signatureValue is calculated and the eContentType is assigned as though the eContent value was present.
In the degenerate case where there are no signers, the EncapsulatedContentInfo value being "signed" doesn't matter. In this case, the content type within the EncapsulatedContentInfo value being "signed" should be id-data (as defined in section 4), and the content field of the EncapsulatedContentInfo value should be omitted. ๐
5.3. SignerInfo Type
Per-signer information is represented in the type SignerInfo:
SignerInfo ::= SEQUENCE {
version CMSVersion,
sid SignerIdentifier,
digestAlgorithm DigestAlgorithmIdentifier,
signedAttrs [0] IMPLICIT SignedAttributes OPTIONAL,
signatureAlgorithm SignatureAlgorithmIdentifier,
signature SignatureValue,
unsignedAttrs [1] IMPLICIT UnsignedAttributes OPTIONAL }
SignerIdentifier ::= CHOICE {
issuerAndSerialNumber IssuerAndSerialNumber,
subjectKeyIdentifier [0] SubjectKeyIdentifier }
SignedAttributes ::= SET SIZE (1..MAX) OF Attribute
UnsignedAttributes ::= SET SIZE (1..MAX) OF Attribute
Attribute ::= SEQUENCE {
attrType OBJECT IDENTIFIER,
attrValues SET OF AttributeValue }
AttributeValue ::= ANY
SignatureValue ::= OCTET STRING
The fields of type SignerInfo have the following meanings:
versionis the syntax version number. If the SignerIdentifier is the CHOICE issuerAndSerialNumber, then the version shall be 1. If the SignerIdentifier is subjectKeyIdentifier, then the version shall be 3. ๐sidspecifies the signer's certificate (and therefore the signer's public key). The recipient needs the signer's public key to verify the signature. SignerIdentifier gives two options for specifying the signer's public key. The issuerAndSerialNumber option identifies the signer's certificate by the issuer's distinguished name and the certificate serial number. The subjectKeyIdentifier option identifies the signer's certificate by the X.509 subjectKeyIdentifier extension value. ๐digestAlgorithmidentifies the message digest algorithm, and any associated parameters, used by the signer. The message digest is computed on either the content being signed, or on the content together with the signed attributes, using the process described in section 5.4. The message digest algorithm should be among those listed in the digestAlgorithms field of the associated SignerData.signedAttributesis a collection of attributes that are signed. The field is optional, but it must be present if the content type of the EncapsulatedContentInfo value being signed is not id-data. Each SignedAttribute in the SET must be DER encoded. Useful attribute types, such as signing time, are defined in Section 11. If the field is present, it must contain, at a minimum, the following two attributes:- A content-type attribute having as its value the content type of the EncapsulatedContentInfo value being signed. Section 11.1 defines the content-type attribute. The content-type attribute is not required when used as part of a countersignature unsigned attribute as defined in section 11.4.
- A message-digest attribute, having as its value the message digest of the content. Section 11.2 defines the message-digest attribute. ๐
signatureAlgorithmidentifies the signature algorithm, and any associated parameters, used by the signer to generate the digital signature.signatureis the result of digital signature generation, using the message digest and the signer's private key. โจunsignedAttributesis a collection of attributes that are not signed. The field is optional. Useful attribute types, such as countersignatures, are defined in Section 11.
The fields of type SignedAttribute and UnsignedAttribute have the following meanings:
attrTypeindicates the type of attribute. It is an object identifier.attrValuesis a set of values that make up the attribute. The type of each value in the set can be determined uniquely by attrType. ๐
5.4. Message Digest Calculation Process
Okay so the digest step hashes either the content itself, or the content plus the signed attributes ๐งฎ๐. Either way, the starting input is the value of the encapsulated content being signed, which is the encapContentInfo eContent OCTET STRING. Only the octets that make up the value of that eContent OCTET STRING go into the digest algorithm. The tag and length octets are left out โจ.
What comes out depends on whether signedAttributes is there. If the field is absent, the result is just the digest of the content, as described above. If the field is present, the result is the digest of the complete DER encoding of the SignedAttributes value in that field ๐. Since SignedAttributes must contain the content type and content message digest attributes when present, those values get pulled in indirectly too ๐ . The content type attribute isn't required when it's used as part of a countersignature unsigned attribute, as defined in section 11.4 ๐ธ.
Now the tricky bit, bestie ๐. The signedAttributes field gets encoded a second time just for the digest calculation. The IMPLICIT [0] tag is NOT used for that DER encoding. Instead, an EXPLICIT SET OF tag is used. So the DER encoding of the SET OF tag (not the IMPLICIT [0] tag) goes into the digest calculation, along with the length and content octets of the SignedAttributes value ๐ง.
When signedAttributes is absent, only the octets making up the value of the signedData encapContentInfo eContent OCTET STRING go into the digest calculation, like the contents of a file ๐. This is lowkey amazing because the length of the content doesn't have to be known before signature generation starts ๐ฆ.
The tag and length octets of the encapContentInfo eContent OCTET STRING aren't in the digest, but they're still protected, just in other ways ๐ซถ. The length octets are protected by the nature of the digest algorithm, since it's computationally infeasible to find any two distinct messages, of any length, that have the same message digest ๐ฅ.
5.5. Message Signature Generation Process
The inputs to signature generation are the result of the digest calculation and the signer's private key ๐โจ. The details depend on the signature algorithm being used. The object identifier, along with any parameters, that names that signature algorithm is carried in the signatureAlgorithm field. The signature value the signer makes is encoded as an OCTET STRING and carried in the signature field ๐.
5.6. Message Signature Verification Process
For verification, the inputs are the result of the digest calculation and the signer's public key ๐. The recipient can get the right public key for the signer any way they want, but the preferred method is a certificate from the SignedData certificates field ๐. Picking and validating the signer's public key may be based on certification path validation (see [PROFILE]) plus other outside context, but that's beyond the scope of this document ๐. The details of verification depend on the signature algorithm too ๐ง.
The recipient may not rely on any message digest values the originator computed ๐. If the signedData signerInfo includes signedAttributes, then the content message digest must be calculated as described in section 5.4 ๐ . For the signature to be valid, the digest value the recipient calculates must match the messageDigest attribute value included in the signedAttributes of the signedData signerInfo ๐. No match, no slay ๐.
6. Enveloped-data Content Type โจ
The enveloped-data content type is basically a secret box ๐ฆ๐. It holds encrypted content of any type, plus encrypted content-encryption keys for one or more recipients ๐. The encrypted content together with one encrypted content-encryption key for a particular recipient is that recipient's "digital envelope" ๐. Any type of content can be enveloped for any number of recipients, using any of the three key management techniques for each recipient ๐ฆ.
The typical use is a few recipients' digital envelopes wrapped around content of the data or signed-data content types ๐ธ.
Enveloped-data gets built in these steps:
- A content-encryption key for a particular content-encryption algorithm is generated at random ๐ฒ.
- The content-encryption key is encrypted for each recipient. The details depend on the key management algorithm used, but three general techniques are supported ๐ง:
- key transport: the content-encryption key is encrypted in the recipient's public key.
- key agreement: the recipient's public key and the sender's private key are used to generate a pairwise symmetric key, then the content-encryption key is encrypted in the pairwise symmetric key.
- symmetric key-encryption keys: the content-encryption key is encrypted in a previously distributed symmetric key-encryption key.
- For each recipient, the encrypted content-encryption key and other recipient-specific information get collected into a RecipientInfo value, defined in Section 6.2 ๐.
- The content is encrypted with the content-encryption key. Content encryption may require that the content be padded to a multiple of some block size; see Section 6.3 ๐ซง.
- The RecipientInfo values for all the recipients get collected together with the encrypted content to form an EnvelopedData value, as defined in Section 6.1 ๐.
A recipient opens the digital envelope by decrypting one of the encrypted content-encryption keys, then decrypting the encrypted content with the recovered content-encryption key ๐โจ.
This section is divided into four parts. The first part describes the top-level type EnvelopedData. The second part describes the per-recipient information type RecipientInfo. The third and fourth parts describe the content-encryption and key-encryption processes ๐ง.
6.1. EnvelopedData Type
The following object identifier identifies the enveloped-data content type ๐ท๏ธ:
id-envelopedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs7(7) 3 }
The enveloped-data content type shall have ASN.1 type EnvelopedData ๐ :
EnvelopedData ::= SEQUENCE {
version CMSVersion,
originatorInfo [0] IMPLICIT OriginatorInfo OPTIONAL,
recipientInfos RecipientInfos,
encryptedContentInfo EncryptedContentInfo,
unprotectedAttrs [1] IMPLICIT UnprotectedAttributes OPTIONAL }
OriginatorInfo ::= SEQUENCE {
certs [0] IMPLICIT CertificateSet OPTIONAL,
crls [1] IMPLICIT CertificateRevocationLists OPTIONAL }
RecipientInfos ::= SET OF RecipientInfo
EncryptedContentInfo ::= SEQUENCE {
contentType ContentType,
contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier,
encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL }
EncryptedContent ::= OCTET STRING
UnprotectedAttributes ::= SET SIZE (1..MAX) OF Attribute
The fields of type EnvelopedData mean the following ๐งฉ:
- version is the syntax version number. If originatorInfo is present, then version shall be 2. If any of the RecipientInfo structures included have a version other than 0, then the version shall be 2. If unprotectedAttrs is present, then version shall be 2. If originatorInfo is absent, all of the RecipientInfo structures are version 0, and unprotectedAttrs is absent, then version shall be 0.
- originatorInfo optionally provides information about the originator. It is present only if required by the key management algorithm. It may contain certificates and CRLs ๐:
- certs is a collection of certificates. certs may contain originator certificates associated with several different key management algorithms. certs may also contain attribute certificates associated with the originator. The certificates contained in certs are intended to be sufficient to make chains from a recognized "root" or "top-level certification authority" to all recipients. However, certs may contain more certificates than necessary, and there may be certificates sufficient to make chains from two or more independent top-level certification authorities. Alternatively, certs may contain fewer certificates than necessary, if it is expected that recipients have an alternate means of obtaining necessary certificates (e.g., from a previous set of certificates).
- crls is a collection of CRLs. It is intended that the set contain information sufficient to determine whether or not the certificates in the certs field are valid, but such correspondence is not necessary. There may be more CRLs than necessary, and there may also be fewer CRLs than necessary.
- recipientInfos is a collection of per-recipient information. There must be at least one element in the collection ๐ฌ.
- encryptedContentInfo is the encrypted content information ๐.
- unprotectedAttrs is a collection of attributes that are not encrypted. The field is optional. Useful attribute types are defined in Section 11 ๐.
The fields of type EncryptedContentInfo mean the following ๐ฌ:
- contentType indicates the type of content.
- contentEncryptionAlgorithm identifies the content-encryption algorithm, and any associated parameters, used to encrypt the content. The content-encryption process is described in Section 6.3. The same content-encryption algorithm and content-encryption key is used for all recipients ๐ซถ.
- encryptedContent is the result of encrypting the content. The field is optional, and if the field is not present, its intended value must be supplied by other means ๐.
The recipientInfos field comes before the encryptedContentInfo field so that an EnvelopedData value may be processed in a single pass ๐โโ๏ธโจ.
6.2. RecipientInfo Type
Per-recipient information is represented in the type RecipientInfo ๐. RecipientInfo has a different format for each of the three key management techniques supported: key transport, key agreement, and previously distributed symmetric key-encryption keys ๐๏ธ. Any of the three techniques can be used for each recipient of the same encrypted content ๐. In all cases, the content-encryption key is transferred to one or more recipients in encrypted form ๐.
RecipientInfo ::= CHOICE {
ktri KeyTransRecipientInfo,
kari [1] KeyAgreeRecipientInfo,
kekri [2] KEKRecipientInfo }
EncryptedKey ::= OCTET STRING
6.2.1. KeyTransRecipientInfo Type ๐
okay bestie, so per-recipient info that uses key transport lives in a type called KeyTransRecipientInfo ๐ฆ. Each one carries the content-encryption key to exactly one recipient ๐
KeyTransRecipientInfo ::= SEQUENCE {
version CMSVersion, -- always set to 0 or 2
rid RecipientIdentifier,
keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
encryptedKey EncryptedKey }
RecipientIdentifier ::= CHOICE {
issuerAndSerialNumber IssuerAndSerialNumber,
subjectKeyIdentifier [0] SubjectKeyIdentifier }
Here's what each field does ๐
versionis the syntax version number. If the RecipientIdentifier is the CHOICEissuerAndSerialNumber, then the version shall be 0. If the RecipientIdentifier issubjectKeyIdentifier, then the version shall be 2.ridnames the recipient's certificate or key that the sender used to protect the content-encryption key ๐. The RecipientIdentifier gives two options for pointing at that certificate, and therefore at the recipient's public key. The recipient's certificate must contain a key transport public key, and the content-encryption key gets encrypted with the recipient's public key. TheissuerAndSerialNumberoption finds the certificate using the issuer's distinguished name and the certificate serial number. ThesubjectKeyIdentifieroption finds it using the X.509 subjectKeyIdentifier extension value ๐ฆkeyEncryptionAlgorithmidentifies the key-encryption algorithm, plus any associated parameters, used to encrypt the content-encryption key for the recipient. The key-encryption process is described in Section 6.4 ๐encryptedKeyis the result of encrypting the content-encryption key for the recipient ๐
6.2.2. KeyAgreeRecipientInfo Type ๐ค
Recipient info that uses key agreement is represented by KeyAgreeRecipientInfo. Each instance transfers the content-encryption key to one or more recipients who use the same key agreement algorithm and domain parameters for that algorithm โจ
KeyAgreeRecipientInfo ::= SEQUENCE {
version CMSVersion, -- always set to 3
originator [0] EXPLICIT OriginatorIdentifierOrKey,
ukm [1] EXPLICIT UserKeyingMaterial OPTIONAL,
keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
recipientEncryptedKeys RecipientEncryptedKeys }
OriginatorIdentifierOrKey ::= CHOICE {
issuerAndSerialNumber IssuerAndSerialNumber,
subjectKeyIdentifier [0] SubjectKeyIdentifier,
originatorKey [1] OriginatorPublicKey }
OriginatorPublicKey ::= SEQUENCE {
algorithm AlgorithmIdentifier,
publicKey BIT STRING }
RecipientEncryptedKeys ::= SEQUENCE OF RecipientEncryptedKey
RecipientEncryptedKey ::= SEQUENCE {
rid KeyAgreeRecipientIdentifier,
encryptedKey EncryptedKey }
KeyAgreeRecipientIdentifier ::= CHOICE {
issuerAndSerialNumber IssuerAndSerialNumber,
rKeyId [0] IMPLICIT RecipientKeyIdentifier }
RecipientKeyIdentifier ::= SEQUENCE {
subjectKeyIdentifier SubjectKeyIdentifier,
date GeneralizedTime OPTIONAL,
other OtherKeyAttribute OPTIONAL }
SubjectKeyIdentifier ::= OCTET STRING
Now the fields of KeyAgreeRecipientInfo ๐ง
versionis the syntax version number. It shall always be 3.originatoris a CHOICE with three options for the sender's key agreement public key ๐ญ. The sender uses the matching private key and the recipient's public key to make a pairwise key, and the content-encryption key gets encrypted in that pairwise key. TheissuerAndSerialNumberoption identifies the sender's certificate, and therefore the sender's public key, by issuer distinguished name and certificate serial number. ThesubjectKeyIdentifieroption identifies the sender's certificate, and therefore the sender's public key, by the X.509 subjectKeyIdentifier extension value. TheoriginatorKeyoption carries the algorithm identifier and the sender's key agreement public key itself, which allows originator anonymity since the public key is not certified ๐ukmis optional ๐ธ. With some key agreement algorithms, the sender supplies User Keying Material (UKM) so that a different key is generated each time the same two parties make a pairwise key.keyEncryptionAlgorithmidentifies the key-encryption algorithm, plus any associated parameters, used to encrypt the content-encryption key in the key-encryption key. The key-encryption process is described in Section 6.4 ๐recipientEncryptedKeysholds a recipient identifier and an encrypted key for one or more recipients ๐. The KeyAgreeRecipientIdentifier is a CHOICE with two options that specify the recipient's certificate, and therefore the recipient's public key, that the sender used to make a pairwise key-encryption key. The recipient's certificate must contain a key agreement public key. The content-encryption key is encrypted in the pairwise key-encryption key. TheissuerAndSerialNumberoption identifies the recipient's certificate by issuer distinguished name and certificate serial number. The RecipientKeyIdentifier is described below. TheencryptedKeyis the result of encrypting the content-encryption key in the pairwise key-encryption key that the key agreement algorithm generated ๐ซถ
The fields of RecipientKeyIdentifier work like this ๐ง
subjectKeyIdentifieridentifies the recipient's certificate by the X.509 subjectKeyIdentifier extension value.dateis optional. When it's present, it says which of the recipient's previously distributed UKMs the sender used ๐ .otheris optional. When it's present, it holds extra info the recipient uses to find the public keying material the sender used ๐.
6.2.3. KEKRecipientInfo Type ๐๏ธ
Recipient info that uses previously distributed symmetric keys is represented by KEKRecipientInfo. Each instance transfers the content-encryption key to one or more recipients who already have the previously distributed key-encryption key ๐
KEKRecipientInfo ::= SEQUENCE {
version CMSVersion, -- always set to 4
kekid KEKIdentifier,
keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
encryptedKey EncryptedKey }
KEKIdentifier ::= SEQUENCE {
keyIdentifier OCTET STRING,
date GeneralizedTime OPTIONAL,
other OtherKeyAttribute OPTIONAL }
The fields of KEKRecipientInfo are ๐
versionis the syntax version number. It shall always be 4.kekidnames a symmetric key-encryption key that was previously distributed to the sender and one or more recipients ๐.keyEncryptionAlgorithmidentifies the key-encryption algorithm, plus any associated parameters, used to encrypt the content-encryption key with the key-encryption key. The key-encryption process is described in Section 6.4 โจ.encryptedKeyis the result of encrypting the content-encryption key in the key-encryption key ๐ฆ.
The fields of KEKIdentifier are ๐
keyIdentifieridentifies the key-encryption key that was previously distributed to the sender and one or more recipients.dateis optional. When it's present, it picks out a single key-encryption key from a set that was previously distributed ๐.otheris optional. When it's present, it holds extra info the recipient uses to figure out which key-encryption key the sender used ๐.
6.3. Content-encryption Process ๐
The content-encryption key for the desired content-encryption algorithm is randomly generated ๐ฒ. The data to be protected gets padded (more on that below), and then the padded data is encrypted with the content-encryption key. The encryption operation takes an arbitrary string of octets (the data) and maps it to another string of octets (the ciphertext) under control of a content-encryption key. The encrypted data goes into the envelopedData encryptedContentInfo encryptedContent OCTET STRING ๐.
The input to the content-encryption process is the "value" of the content being enveloped. Only the value octets of the envelopedData encryptedContentInfo encryptedContent OCTET STRING get encrypted. The OCTET STRING tag and length octets are not encrypted ๐.
Some content-encryption algorithms assume the input length is a multiple of k octets, where k is greater than one. For those algorithms, the input shall be padded at the trailing end with k-(lth mod k) octets, and every one of those octets has the value k-(lth mod k), where lth is the length of the input. Put another way, the input gets padded at the trailing end with one of these strings ๐งฉ:
01 -- if lth mod k = k-1
02 02 -- if lth mod k = k-2
.
.
.
k k ... k k -- if lth mod k = 0
The padding can be removed unambiguously because all input gets padded, including input values that are already a multiple of the block size, and no padding string is a suffix of another ๐ฏ. This padding method is well defined if and only if k is less than 256 โจ.
6.4. Key-encryption Process ๐๏ธ
The input to the key-encryption process, which is the value supplied to the recipient's key-encryption algorithm, is just the "value" of the content-encryption key ๐.
Any of the three key management techniques can be used for each recipient of the same encrypted content ๐ธ.
7. Digested-data Content Type โจ
okay so the digested-data content type is basically any kind of content glued together with a message digest of that content ๐
It's mostly used for content integrity ๐ซถ, and the result usually becomes an input to the enveloped-data content type ๐
Here's how you build one:
- A message digest is computed on the content with a message-digest algorithm.
- The message-digest algorithm and the message digest get collected together with the content into a DigestedData value.
To verify the message digest, a recipient compares it to one they computed independently. It's giving double-check energy ๐
The digested-data content type is identified by this object identifier ๐ฅ:
id-digestedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs7(7) 5 }
The digested-data content type SHALL have ASN.1 type DigestedData:
DigestedData ::= SEQUENCE {
version CMSVersion,
digestAlgorithm DigestAlgorithmIdentifier,
encapContentInfo EncapsulatedContentInfo,
digest Digest }
Digest ::= OCTET STRING
Here's what each field means ๐ธ:
versionis the syntax version number. If the encapsulated content type is id-data, then the value ofversionSHALL be 0. However, if the encapsulated content type is other than id-data, then the value ofversionSHALL be 2.digestAlgorithmidentifies the message digest algorithm, and any associated parameters, that the content is digested with. The message-digesting process is the same as in Section 5.4 when there are no signed attributes.encapContentInfois the content that gets digested, as defined in section 5.2.digestis the result of the message-digesting process.
The ordering of the digestAlgorithm, encapContentInfo, and digest fields is what lets you process a DigestedData value in a single pass. Lowkey genius ๐ง
8. Encrypted-data Content Type ๐
The encrypted-data content type holds encrypted content of any type. Unlike the enveloped-data content type, it has no recipients and no encrypted content-encryption keys. So the keys MUST be managed by other means ๐
The typical use is encrypting data-content-type content for local storage, maybe where the encryption key is a password ๐
The encrypted-data content type is identified by this object identifier โจ:
id-encryptedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs7(7) 6 }
The encrypted-data content type SHALL have ASN.1 type EncryptedData:
EncryptedData ::= SEQUENCE {
version CMSVersion,
encryptedContentInfo EncryptedContentInfo,
unprotectedAttrs [1] IMPLICIT UnprotectedAttributes OPTIONAL }
Here's what each field means ๐ฆ:
versionis the syntax version number. IfunprotectedAttrsis present, thenversionSHALL be 2. IfunprotectedAttrsis absent, thenversionSHALL be 0.encryptedContentInfois the encrypted content information, as defined in Section 6.1.unprotectedAttrsis a collection of attributes that are not encrypted. The field is optional. Useful attribute types are defined in Section 11.
9. Authenticated-data Content Type ๐ก๏ธ
The authenticated-data content type holds content of any type, a message authentication code (MAC), and encrypted authentication keys for one or more recipients. Each recipient needs the MAC plus their own encrypted authentication key to verify the integrity of the content. Any type of content can be integrity protected for an arbitrary number of recipients, which is so iconic ๐
Building authenticated-data goes like this:
- A message-authentication key for a particular message-authentication algorithm is generated at random.
- The message-authentication key is encrypted for each recipient. The details of this encryption depend on the key management algorithm used.
- For each recipient, the encrypted message-authentication key and other recipient-specific information are collected into a RecipientInfo value, defined in Section 6.2.
- Using the message-authentication key, the originator computes a MAC value on the content. If the originator is authenticating any information in addition to the content (see Section 9.2), a message digest is calculated on the content. Then the message digest of the content and the other information are authenticated using the message-authentication key, and the result becomes the "MAC value."
9.1. AuthenticatedData Type
The authenticated-data content type is identified by this object identifier ๐ :
id-ct-authData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16)
ct(1) 2 }
The authenticated-data content type SHALL have ASN.1 type AuthenticatedData:
AuthenticatedData ::= SEQUENCE {
version CMSVersion,
originatorInfo [0] IMPLICIT OriginatorInfo OPTIONAL,
recipientInfos RecipientInfos,
macAlgorithm MessageAuthenticationCodeAlgorithm,
digestAlgorithm [1] DigestAlgorithmIdentifier OPTIONAL,
encapContentInfo EncapsulatedContentInfo,
authenticatedAttributes [2] IMPLICIT AuthAttributes OPTIONAL,
mac MessageAuthenticationCode,
unauthenticatedAttributes [3] IMPLICIT UnauthAttributes OPTIONAL }
AuthAttributes ::= SET SIZE (1..MAX) OF Attribute
UnauthAttributes ::= SET SIZE (1..MAX) OF Attribute
MessageAuthenticationCode ::= OCTET STRING
Here's what each field means ๐:
versionis the syntax version number. It SHALL be 0.originatorInfooptionally provides information about the originator. It is present only if the key management algorithm requires it. It MAY contain certificates, attribute certificates, and CRLs, as defined in Section 6.1.recipientInfosis a collection of per-recipient information, as defined in Section 6.1. There MUST be at least one element in the collection.macAlgorithmis a message authentication code (MAC) algorithm identifier. It identifies the MAC algorithm, along with any associated parameters, that the originator used. Placing themacAlgorithmfield here facilitates one-pass processing by the recipient.digestAlgorithmidentifies the message digest algorithm, and any associated parameters, used to compute a message digest on the encapsulated content when authenticated attributes are present. The message digesting process is described in Section 9.2. Placing thedigestAlgorithmfield here facilitates one-pass processing by the recipient. If thedigestAlgorithmfield is present, then theauthenticatedAttributesfield MUST also be present.encapContentInfois the content that is authenticated, as defined in section 5.2.authenticatedAttributesis a collection of authenticated attributes. TheauthenticatedAttributesstructure is optional, but it MUST be present if the content type of the EncapsulatedContentInfo value being authenticated is not id-data. If theauthenticatedAttributesfield is present, then thedigestAlgorithmfield MUST also be present. Each AuthenticatedAttribute in the SET MUST be DER encoded. Useful attribute types are defined in Section 11. If theauthenticatedAttributesfield is present, it MUST contain, at a minimum, the following two attributes:- A content-type attribute having as its value the content type of the EncapsulatedContentInfo value being authenticated. Section 11.1 defines the content-type attribute.
- A message-digest attribute, having as its value the message digest of the content. Section 11.2 defines the message-digest attribute.
macis the message authentication code.unauthenticatedAttributesis a collection of attributes that are not authenticated. The field is optional. To date, no attributes have been defined for use as unauthenticated attributes, but other useful attribute types are defined in Section 11.
9.2. MAC Generation
The MAC calculation process computes a message authentication code (MAC) on either the message being authenticated, or a message digest of the message being authenticated together with the originator's authenticated attributes ๐ฆ
If the authenticatedAttributes field is absent, the input to the MAC calculation process is the value of the encapContentInfo eContent OCTET STRING. Only the octets comprising the value of the eContent OCTET STRING are input to the MAC algorithm. The tag and length octets are omitted. This has the advantage that the length of the content being authenticated doesn't need to be known in advance of the MAC generation process ๐
If the authenticatedAttributes field is present, the content-type attribute (as described in Section 11.1) and the message-digest attribute (as described in section 11.2) MUST be included. The input to the MAC calculation process is the DER encoding of authenticatedAttributes. A separate encoding of the authenticatedAttributes field is performed for message digest calculation. The IMPLICIT [2] tag in the authenticatedAttributes field is not used for the DER encoding. Instead, an EXPLICIT SET OF tag is used. That means the DER encoding of the SET OF tag, rather than the IMPLICIT [2] tag, is included in the message digest calculation, along with the length and content octets of the authenticatedAttributes value โจ
The message digest calculation process computes a message digest on the content being authenticated. The initial input is the "value" of the encapsulated content being authenticated. Specifically, the input is the encapContentInfo eContent OCTET STRING that the authentication process is applied to. Only the octets comprising the value of that OCTET STRING go into the message digest algorithm, not the tag or length octets. This has the advantage that the length of the content being authenticated doesn't need to be known in advance. Even though the tag and length octets of the encapContentInfo eContent OCTET STRING aren't in the message digest calculation, they're still protected by other means. The length octets are protected by the nature of the message digest algorithm, since it is computationally infeasible to find any two distinct messages of any length that have the same message digest ๐ฅ
The input to the MAC calculation process includes the MAC input data defined above, plus an authentication key conveyed in a recipientInfo structure. The details of MAC calculation depend on the MAC algorithm employed (e.g., HMAC). The object identifier, along with any parameters, that specifies the MAC algorithm the originator employed is carried in the macAlgorithm field. The MAC value the originator generates is encoded as an OCTET STRING and carried in the mac field ๐
9.3. MAC Verification โจ
Okay so the MAC verification process takes two things: the input data (which depends on whether the authenticatedAttributes field is there or not, as defined in section 9.2) and the authentication key that comes through recipientInfo ๐. The nitty gritty details depend on which MAC algorithm was used, so it's giving "it depends" energy, iykyk.
Now here's the big rule, bestie ๐: the recipient may not rely on any MAC values or message digest values that the originator calculated. Like, you can't just trust those ๐. The content gets authenticated the way section 9.2 describes. If the originator includes authenticated attributes, then the content of authenticatedAttributes is authenticated the way section 9.2 describes too.
For authentication to succeed, the MAC value the recipient calculates must be the same as the value in the mac field. And when authenticatedAttributes is present, the content message digest value the recipient calculates must match the message digest value in the message-digest attribute. Both have to line up, periodt ๐
โจ
10. Useful Types ๐
This section is split into two parts. The first part defines the algorithm identifiers, and the second part defines other useful types ๐ง
10.1. Algorithm Identifier Types
All of the algorithm identifiers have the same type, AlgorithmIdentifier. That definition gets imported from X.509 [X.509-88] ๐ธ
There are a lot of alternatives for each type of algorithm listed. For each of these five types, Section 12 lists the algorithms that must be included in a CMS implementation. So go check Section 12, it's the algorithm checklist ๐
10.1.1. DigestAlgorithmIdentifier
The DigestAlgorithmIdentifier type identifies a message-digest algorithm. Examples include SHA-1, MD2, and MD5. A message-digest algorithm maps an octet string (the message) to another octet string (the message digest) ๐
DigestAlgorithmIdentifier ::= AlgorithmIdentifier
10.1.2. SignatureAlgorithmIdentifier
The SignatureAlgorithmIdentifier type identifies a signature algorithm. Examples include DSS and RSA. A signature algorithm supports signature generation and verification operations. Generation uses the message digest and the signer's private key to make a signature value. Verification uses the message digest and the signer's public key to figure out whether a signature value is valid. Context tells you which operation is meant ๐
SignatureAlgorithmIdentifier ::= AlgorithmIdentifier
10.1.3. KeyEncryptionAlgorithmIdentifier
The KeyEncryptionAlgorithmIdentifier type identifies a key-encryption algorithm, the one used to encrypt a content-encryption key. The encryption operation maps an octet string (the key) to another octet string (the encrypted key) under control of a key-encryption key. Decryption is the inverse of encryption. Context tells you which operation is intended ๐
The details of encryption and decryption depend on the key management algorithm being used. Key transport, key agreement, and previously distributed symmetric key-encrypting keys are all supported, so there's options galore ๐ฆ
KeyEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
10.1.4. ContentEncryptionAlgorithmIdentifier
The ContentEncryptionAlgorithmIdentifier type identifies a content-encryption algorithm. Examples include Triple-DES and RC2. A content-encryption algorithm supports encryption and decryption. Encryption maps an octet string (the message) to another octet string (the ciphertext) under control of a content-encryption key. Decryption is the inverse. Context tells you which operation is meant โจ
ContentEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
10.1.5. MessageAuthenticationCodeAlgorithm
The MessageAuthenticationCodeAlgorithm type identifies a message authentication code (MAC) algorithm. Examples include DES-MAC and HMAC. A MAC algorithm supports generation and verification. Both operations use the same symmetric key, and context tells you which one is intended ๐ง
MessageAuthenticationCodeAlgorithm ::= AlgorithmIdentifier
10.2. Other Useful Types
This section defines types that get used in other places in the document. They aren't listed in any particular order, so no drama ๐
10.2.1. CertificateRevocationLists
The CertificateRevocationLists type gives a set of certificate revocation lists (CRLs). The set is meant to hold enough info to figure out whether the certificates and attribute certificates it goes with are revoked or not. However, there may be more CRLs than necessary, or there may be fewer CRLs than necessary ๐
The CertificateList may hold a CRL, an Authority Revocation List (ARL), a Delta Revocation List, or an Attribute Certificate Revocation List. All of these lists share a common syntax, which is so clean ๐ซถ
CRLs are specified in X.509 [X.509-97], and they're profiled for use on the Internet in RFC 2459 [PROFILE]. The definition of CertificateList gets imported from X.509.
CertificateRevocationLists ::= SET OF CertificateList
10.2.2. CertificateChoices
The CertificateChoices type gives you either a PKCS #6 extended certificate [PKCS#6], an X.509 certificate, or an X.509 attribute certificate [X.509-97]. The PKCS #6 extended certificate is obsolete. PKCS #6 certificates are only included for backward compatibility, and their use should be avoided. The Internet profile of X.509 certificates is specified in the "Internet X.509 Public Key Infrastructure: Certificate and CRL Profile" [PROFILE] ๐ฅฒ
The definitions of Certificate and AttributeCertificate get imported from X.509.
CertificateChoices ::= CHOICE {
certificate Certificate, -- See X.509
extendedCertificate [0] IMPLICIT ExtendedCertificate,
-- Obsolete
attrCert [1] IMPLICIT AttributeCertificate }
-- See X.509 and X9.57
10.2.3. CertificateSet
The CertificateSet type gives a set of certificates. The set is meant to be enough to hold chains from a recognized "root" or "top-level certification authority" down to all of the sender certificates it goes with. However, there may be more certificates than necessary, or fewer than necessary ๐ช
What a "chain" actually means is outside the scope of this document. Some applications may put upper limits on how long a chain can be, and others may enforce certain relationships between the subjects and issuers of certificates in a chain ๐
CertificateSet ::= SET OF CertificateChoices
10.2.4. IssuerAndSerialNumber
The IssuerAndSerialNumber type identifies a certificate, and therefore an entity and a public key, by the distinguished name of the certificate issuer plus an issuer-specific certificate serial number ๐ชช
The definition of Name gets imported from X.501 [X.501-88], and the definition of CertificateSerialNumber gets imported from X.509 [X.509-97].
IssuerAndSerialNumber ::= SEQUENCE {
issuer Name,
serialNumber CertificateSerialNumber }
CertificateSerialNumber ::= INTEGER
10.2.5. CMSVersion
The Version type gives a syntax version number, so future revisions of this document stay compatible ๐ข
CMSVersion ::= INTEGER { v0(0), v1(1), v2(2), v3(3), v4(4) }
10.2.6. UserKeyingMaterial
The UserKeyingMaterial type gives a syntax for user keying material (UKM). Some key agreement algorithms need UKMs so that a different key gets generated each time the same two parties make a pairwise key. The sender provides a UKM for use with a specific key agreement algorithm ๐ท
UserKeyingMaterial ::= OCTET STRING
10.2.7. OtherKeyAttribute
The OtherKeyAttribute type gives a syntax for including other key attributes that let the recipient select the key the sender used. The attribute object identifier must be registered along with the syntax of the attribute itself. Using this structure should be avoided, since it may impede interoperability ๐ฌ
OtherKeyAttribute ::= SEQUENCE {
keyAttrId OBJECT IDENTIFIER,
keyAttr ANY DEFINED BY keyAttrId OPTIONAL }
11. Useful Attributes ๐
This section defines attributes that may be used with signed-data, enveloped-data, encrypted-data, or authenticated-data. The syntax of Attribute is compatible with X.501 [X.501-88] and RFC 2459 [PROFILE]. Some of the attributes here were originally defined in PKCS #9 [PKCS#9], and others weren't defined anywhere before. The attributes aren't listed in any particular order ๐ญ
Additional attributes are defined in lots of places, notably the S/MIME Version 3 Message Specification [MSG] and the Enhanced Security Services for S/MIME [ESS]. Those also include recommendations on where to place these attributes ๐ฌ
11.1. Content Type
The content-type attribute type specifies the content type of the ContentInfo value being signed in signed-data. The content-type attribute type is required if any authenticated attributes are present ๐
The content-type attribute must be a signed attribute or an authenticated attribute. It can't be an unsigned attribute, an unauthenticated attribute, or an unprotectedAttribute ๐
โโ๏ธ
The following object identifier identifies the content-type attribute:
id-contentType OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs9(9) 3 }
Content-type attribute values have the ASN.1 type ContentType:
ContentType ::= OBJECT IDENTIFIER
A content-type attribute must have a single attribute value, even though the syntax is defined as a SET OF AttributeValue. There must not be zero or multiple instances of AttributeValue present, so keep it to exactly one ๐ซง
The SignedAttributes and AuthAttributes syntaxes are each defined as a SET OF Attributes. The SignedAttributes in a signerInfo must not include multiple instances of the content-type attribute. Similarly, the AuthAttributes in an AuthenticatedData must not include multiple instances of the content-type attribute. No doubles, bestie ๐
11.2 Message Digest ๐ธ
Okay so the message-digest attribute is basically the receipt for your content ๐งพ. It holds the message digest of the encapContentInfo eContent OCTET STRING that's being signed in signed-data (see section 5.4) or authenticated in authenticated-data (see section 9.2). For signed-data, the digest is computed with the signer's message digest algorithm. For authenticated-data, it's computed with the originator's message digest algorithm. ๐
Within signed-data, the message-digest signed attribute type is required if there are any attributes present. Within authenticated-data, the message-digest authenticated attribute type is required if there are any attributes present. ๐
The message-digest attribute MUST be a signed attribute or an authenticated attribute. It cannot be an unsigned attribute or an unauthenticated attribute, no cap ๐
The following object identifier identifies the message-digest attribute:
id-messageDigest OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs9(9) 4 }
Message-digest attribute values have ASN.1 type MessageDigest:
MessageDigest ::= OCTET STRING
A message-digest attribute MUST have a single attribute value, even though the syntax is defined as a SET OF AttributeValue. There MUST NOT be zero or multiple instances of AttributeValue present. Main character energy means exactly one โจ
The SignedAttributes syntax is defined as a SET OF Attributes. The SignedAttributes in a signerInfo MUST NOT include multiple instances of the message-digest attribute. ๐ซถ
11.3 Signing Time โฐ
The signing-time attribute type specifies the time at which the signer (purportedly) performed the signing process. It's meant for use in signed-data ๐ฆ
The signing-time attribute MAY be a signed attribute. It cannot be an unsigned attribute, an authenticated attribute, or an unauthenticated attribute.
The following object identifier identifies the signing-time attribute:
id-signingTime OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs9(9) 5 }
Signing-time attribute values have ASN.1 type SigningTime:
SigningTime ::= Time
Time ::= CHOICE {
utcTime UTCTime,
generalizedTime GeneralizedTime }
Note: The definition of Time matches the one specified in the 1997 version of X.509 [X.509-97]. ๐
Dates between 1 January 1950 and 31 December 2049 (inclusive) MUST be encoded as UTCTime. Any dates with year values before 1950 or after 2049 MUST be encoded as GeneralizedTime. The date ranges are giving very specific vibes ๐ฐ๏ธ
UTCTime values MUST be expressed in Greenwich Mean Time (Zulu) and MUST include seconds (i.e., times are YYMMDDHHMMSSZ), even where the number of seconds is zero. Midnight (GMT) MUST be represented as "YYMMDD000000Z". Century information is implicit, and the century MUST be determined as follows:
- Where YY is greater than or equal to 50, the year SHALL be interpreted as 19YY; and
- Where YY is less than 50, the year SHALL be interpreted as 20YY.
GeneralizedTime values SHALL be expressed in Greenwich Mean Time (Zulu) and MUST include seconds (i.e., times are YYYYMMDDHHMMSSZ), even where the number of seconds is zero. GeneralizedTime values MUST NOT include fractional seconds. No fractions, we are not doing fractions ๐ โโ๏ธ
A signing-time attribute MUST have a single attribute value, even though the syntax is defined as a SET OF AttributeValue. There MUST NOT be zero or multiple instances of AttributeValue present. One value, iconic โจ
The SignedAttributes syntax is defined as a SET OF Attributes. The SignedAttributes in a signerInfo MUST NOT include multiple instances of the signing-time attribute. ๐
No requirement is imposed concerning the correctness of the signing time, and acceptance of a purported signing time is a matter of a recipient's discretion. It is expected, however, that some signers, such as time-stamp servers, will be trusted implicitly. Trust the time-stamp servers, they're the real ones ๐ง
11.4 Countersignature โ๏ธ
The countersignature attribute type specifies one or more signatures on the contents octets of the DER encoding of the signatureValue field of a SignerInfo value in signed-data. So the countersignature attribute type countersigns (signs in serial) another signature. It's a signature on a signature, which is so extra and I'm obsessed ๐ซ
The countersignature attribute MUST be an unsigned attribute. It cannot be a signed attribute, an authenticated attribute, or an unauthenticated attribute.
The following object identifier identifies the countersignature attribute:
id-countersignature OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs9(9) 6 }
Countersignature attribute values have ASN.1 type Countersignature:
Countersignature ::= SignerInfo
Countersignature values have the same meaning as SignerInfo values for ordinary signatures, except that:
- The signedAttributes field MUST contain a message-digest attribute if it contains any other attributes, but need not contain a content-type attribute, as there is no content type for countersignatures.
- The input to the message-digesting process is the contents octets of the DER encoding of the signatureValue field of the SignerInfo value with which the attribute is associated.
A countersignature attribute can have multiple attribute values. The syntax is defined as a SET OF AttributeValue, and there MUST be one or more instances of AttributeValue present. ๐
The UnsignedAttributes syntax is defined as a SET OF Attributes. The UnsignedAttributes in a signerInfo MAY include multiple instances of the countersignature attribute.
A countersignature, since it has type SignerInfo, can itself contain a countersignature attribute. Thus it is possible to construct arbitrarily long series of countersignatures. It's a whole chain of signatures, bestie ๐
12 Supported Algorithms ๐ง
This section lists the algorithms that MUST be implemented. Additional algorithms that SHOULD be implemented are also included. This is the menu, babe ๐
12.1 Digest Algorithms
CMS implementations MUST include SHA-1. CMS implementations SHOULD include MD5.
Digest algorithm identifiers are located in the SignedData digestAlgorithms field, the SignerInfo digestAlgorithm field, the DigestedData digestAlgorithm field, and the AuthenticatedData digestAlgorithm field.
Digest values are located in the DigestedData digest field, and digest values are located in the Message Digest authenticated attribute. In addition, digest values are input to signature algorithms. ๐
12.1.1 SHA-1
The SHA-1 digest algorithm is defined in FIPS Pub 180-1 [SHA1]. The algorithm identifier for SHA-1 is:
sha-1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3)
oiw(14) secsig(3) algorithm(2) 26 }
The AlgorithmIdentifier parameters field is optional. If present, the parameters field MUST contain an ASN.1 NULL. Implementations SHOULD accept SHA-1 AlgorithmIdentifiers with absent parameters as well as NULL parameters. Implementations SHOULD generate SHA-1 AlgorithmIdentifiers with NULL parameters. ๐
12.1.2 MD5
The MD5 digest algorithm is defined in RFC 1321 [MD5]. The algorithm identifier for MD5 is:
md5 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840)
rsadsi(113549) digestAlgorithm(2) 5 }
The AlgorithmIdentifier parameters field MUST be present, and the parameters field MUST contain NULL. Implementations MAY accept the MD5 AlgorithmIdentifiers with absent parameters as well as NULL parameters. ๐ฆ
12.2 Signature Algorithms
CMS implementations MUST include DSA. CMS implementations MAY include RSA.
Signature algorithm identifiers are located in the SignerInfo signatureAlgorithm field. Also, signature algorithm identifiers are located in the SignerInfo signatureAlgorithm field of countersignature attributes.
Signature values are located in the SignerInfo signature field. Also, signature values are located in the SignerInfo signature field of countersignature attributes. โจ
12.2.1 DSA
The DSA signature algorithm is defined in FIPS Pub 186 [DSS]. DSA is always used with the SHA-1 message digest algorithm. The algorithm identifier for DSA is:
id-dsa-with-sha1 OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) x9-57 (10040) x9cm(4) 3 }
The AlgorithmIdentifier parameters field MUST NOT be present. ๐
12.2.2 RSA
The RSA signature algorithm is defined in RFC 2347 [NEWPKCS#1]. RFC 2347 specifies the use of the RSA signature algorithm with the SHA-1 and MD5 message digest algorithms. The algorithm identifier for RSA is:
rsaEncryption OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs-1(1) 1 }
12.3 Key Management Algorithms
CMS accommodates three general key management techniques: key agreement, key transport, and previously distributed symmetric key-encryption keys. Three techniques, three vibes ๐
12.3.1 Key Agreement Algorithms
CMS implementations MUST include key agreement using X9.42 Ephemeral-Static Diffie-Hellman. ๐ธ
Any symmetric encryption algorithm that a CMS implementation includes as a content-encryption algorithm MUST also be included as a key-encryption algorithm. CMS implementations MUST include key agreement of Triple-DES pairwise key-encryption keys and Triple-DES wrapping of Triple-DES content-encryption keys. CMS implementations SHOULD include key agreement of RC2 pairwise key-encryption keys and RC2 wrapping of RC2 content-encryption keys. The key wrap algorithm for Triple-DES and RC2 is described in section 12.3.3. ๐ฅ
A CMS implementation MAY support mixed key-encryption and content-encryption algorithms. For example, a 128-bit RC2 content-encryption key may be wrapped with 168-bit Triple-DES key-encryption key. Similarly, a 40-bit RC2 content-encryption key may be wrapped with 128-bit RC2 key-encryption key. Mix and match, it's giving flexibility ๐
For key agreement of RC2 key-encryption keys, 128 bits MUST be generated as input to the key expansion process used to compute the RC2 effective key [RC2].
Key agreement algorithm identifiers are located in the EnvelopedData RecipientInfos KeyAgreeRecipientInfo keyEncryptionAlgorithm and AuthenticatedData RecipientInfos KeyAgreeRecipientInfo keyEncryptionAlgorithm fields.
Key wrap algorithm identifiers are located in the KeyWrapAlgorithm parameters within the EnvelopedData RecipientInfos KeyAgreeRecipientInfo keyEncryptionAlgorithm and AuthenticatedData RecipientInfos KeyAgreeRecipientInfo keyEncryptionAlgorithm fields.
Wrapped content-encryption keys are located in the EnvelopedData RecipientInfos KeyAgreeRecipientInfo RecipientEncryptedKeys encryptedKey field. Wrapped message-authentication keys are located in the AuthenticatedData RecipientInfos KeyAgreeRecipientInfo RecipientEncryptedKeys encryptedKey field. ๐ซถ
12.3.1.1. X9.42 Ephemeral-Static Diffie-Hellman ๐
Okay so Ephemeral-Static Diffie-Hellman key agreement is defined in RFC 2631 [DH-X9.42] ๐ฆ When you use it, the EnvelopedData RecipientInfos KeyAgreeRecipientInfo and AuthenticatedData RecipientInfos KeyAgreeRecipientInfo fields get used like this ๐
versionMUST be 3.originatorMUST be the originatorKey alternative. The originatorKey algorithm fields MUST contain the dh-public-number object identifier with absent parameters. The originatorKey publicKey field MUST contain the sender's ephemeral public key. The dh-public-number object identifier is:
dh-public-number OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) ansi-x942(10046) number-type(2) 1 }
ukmMAY be absent. When it's present, the ukm is used to make sure a different key-encryption key is generated when the ephemeral private key might be used more than once ๐ฅkeyEncryptionAlgorithmMUST be the id-alg-ESDH algorithm identifier. The algorithm identifier parameter field for id-alg-ESDH isKeyWrapAlgorihtm, and this parameter MUST be present. TheKeyWrapAlgorithmdenotes the symmetric encryption algorithm used to encrypt the content-encryption key with the pairwise key-encryption key generated using the Ephemeral-Static Diffie-Hellman key agreement algorithm. Triple-DES and RC2 key wrap algorithms are discussed in section 12.3.3. The id-alg-ESDH algorithm identifier and parameter syntax is:
id-alg-ESDH OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840)
rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 5 }
KeyWrapAlgorithm ::= AlgorithmIdentifier
recipientEncryptedKeyscontains an identifier and an encrypted key for each recipient. The RecipientEncryptedKey KeyAgreeRecipientIdentifier MUST contain either the issuerAndSerialNumber identifying the recipient's certificate or the RecipientKeyIdentifier containing the subject key identifier from the recipient's certificate. In both cases, the recipient's certificate contains the recipient's static public key. RecipientEncryptedKey EncryptedKey MUST contain the content-encryption key encrypted with the Ephemeral-Static Diffie-Hellman generated pairwise key-encryption key using the algorithm specified by theKeyWrapAlgortihm. โจ
12.3.2. Key Transport Algorithms ๐ธ
CMS implementations SHOULD include key transport using RSA. RSA implementations MUST include key transport of Triple-DES content-encryption keys. RSA implementations SHOULD include key transport of RC2 content-encryption keys.
Key transport algorithm identifiers are located in the EnvelopedData RecipientInfos KeyTransRecipientInfo keyEncryptionAlgorithm and AuthenticatedData RecipientInfos KeyTransRecipientInfo keyEncryptionAlgorithm fields.
Key transport encrypted content-encryption keys are located in the EnvelopedData RecipientInfos KeyTransRecipientInfo encryptedKey field. Key transport encrypted message-authentication keys are located in the AuthenticatedData RecipientInfos KeyTransRecipientInfo encryptedKey field.
12.3.2.1. RSA ๐ง
The RSA key transport algorithm is the RSA encryption scheme defined in RFC 2313 [PKCS#1], block type is 02, where the message to be encrypted is the content-encryption key. The algorithm identifier for RSA is:
rsaEncryption OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs-1(1) 1 }
The AlgorithmIdentifier parameters field MUST be present, and the parameters field MUST contain NULL.
When using a Triple-DES content-encryption key, adjust the parity bits for each DES key comprising the Triple-DES key prior to RSA encryption.
โ ๏ธ The use of RSA encryption, as defined in RFC 2313 [PKCS#1], to provide confidentiality has a known vulnerability concerns. The vulnerability is primarily relevant to usage in interactive applications rather than to store-and-forward environments. Further information and proposed countermeasures are discussed in the Security Considerations section of this document.
Note that the same encryption scheme is also defined in RFC 2437 [NEWPKCS#1]. Within RFC 2437, this scheme is called RSAES-PKCS1-v1_5.
12.3.3. Symmetric Key-Encryption Key Algorithms ๐
CMS implementations MAY include symmetric key-encryption key management. Such CMS implementations MUST include Triple-DES key-encryption keys wrapping Triple-DES content-encryption keys, and such CMS implementations SHOULD include RC2 key-encryption keys wrapping RC2 content-encryption keys. Only 128-bit RC2 keys MAY be used as key-encryption keys, and they MUST be used with the RC2ParameterVersion parameter set to 58. A CMS implementation MAY support mixed key-encryption and content-encryption algorithms. For example, a 40-bit RC2 content-encryption key MAY be wrapped with 168-bit Triple-DES key-encryption key or with a 128-bit RC2 key-encryption key. ๐
Key wrap algorithm identifiers are located in the EnvelopedData RecipientInfos KEKRecipientInfo keyEncryptionAlgorithm and AuthenticatedData RecipientInfos KEKRecipientInfo keyEncryptionAlgorithm fields.
Wrapped content-encryption keys are located in the EnvelopedData RecipientInfos KEKRecipientInfo encryptedKey field. Wrapped message-authentication keys are located in the AuthenticatedData RecipientInfos KEKRecipientInfo encryptedKey field.
The output of a key agreement algorithm is a key-encryption key, and this key-encryption key is used to encrypt the content-encryption key. In conjunction with key agreement algorithms, CMS implementations MUST include encryption of content-encryption keys with the pairwise key-encryption key generated using a key agreement algorithm. To support key agreement, key wrap algorithm identifiers are located in the KeyWrapAlgorithm parameter of the EnvelopedData RecipientInfos KeyAgreeRecipientInfo keyEncryptionAlgorithm and AuthenticatedData RecipientInfos KeyAgreeRecipientInfo keyEncryptionAlgorithm fields. Wrapped content-encryption keys are located in the EnvelopedData RecipientInfos KeyAgreeRecipientInfo RecipientEncryptedKeys encryptedKey field, and wrapped message-authentication keys are located in the AuthenticatedData RecipientInfos KeyAgreeRecipientInfo RecipientEncryptedKeys encryptedKey field.
12.3.3.1. Triple-DES Key Wrap ๐
Triple-DES key encryption has the algorithm identifier:
id-alg-CMS3DESwrap OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 6 }
The AlgorithmIdentifier parameter field MUST be NULL.
The key wrap algorithm used to encrypt a Triple-DES content-encryption key with a Triple-DES key-encryption key is specified in section 12.6.
Out-of-band distribution of the Triple-DES key-encryption key used to encrypt the Triple-DES content-encryption key is beyond of the scope of this document.
12.3.3.2. RC2 Key Wrap ๐ฆ
RC2 key encryption has the algorithm identifier:
id-alg-CMSRC2wrap OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 7 }
The AlgorithmIdentifier parameter field MUST be RC2wrapParameter:
RC2wrapParameter ::= RC2ParameterVersion
RC2ParameterVersion ::= INTEGER
The RC2 effective-key-bits (key size) greater than 32 and less than 256 is encoded in the RC2ParameterVersion. For the effective-key-bits of 40, 64, and 128, the rc2ParameterVersion values are 160, 120, and 58 respectively. These values are not simply the RC2 key length. Note that the value 160 MUST be encoded as two octets (00 A0), because the one octet (A0) encoding represents a negative number. ๐
Only 128-bit RC2 keys MAY be used as key-encryption keys, and they MUST be used with the RC2ParameterVersion parameter set to 58.
The key wrap algorithm used to encrypt a RC2 content-encryption key with a RC2 key-encryption key is specified in section 12.6.
Out-of-band distribution of the RC2 key-encryption key used to encrypt the RC2 content-encryption key is beyond of the scope of this document.
12.4. Content Encryption Algorithms ๐
CMS implementations MUST include Triple-DES in CBC mode. CMS implementations SHOULD include RC2 in CBC mode.
Content encryption algorithms identifiers are located in the EnvelopedData EncryptedContentInfo contentEncryptionAlgorithm and the EncryptedData EncryptedContentInfo contentEncryptionAlgorithm fields.
Content encryption algorithms are used to encipher the content located in the EnvelopedData EncryptedContentInfo encryptedContent field and the EncryptedData EncryptedContentInfo encryptedContent field.
12.4.1. Triple-DES CBC ๐
The Triple-DES algorithm is described in ANSI X9.52 [3DES]. The Triple-DES is composed from three sequential DES [DES] operations: encrypt, decrypt, and encrypt. Three-Key Triple-DES uses a different key for each DES operation. Two-Key Triple-DES uses one key for the two encrypt operations and different key for the decrypt operation. The same algorithm identifiers are used for Three-Key Triple-DES and Two-Key Triple-DES. The algorithm identifier for Triple-DES in Cipher Block Chaining (CBC) mode is:
des-ede3-cbc OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) encryptionAlgorithm(3) 7 }
The AlgorithmIdentifier parameters field MUST be present, and the parameters field MUST contain a CBCParameter:
CBCParameter ::= IV
IV ::= OCTET STRING -- exactly 8 octets
12.4.2. RC2 CBC ๐
The RC2 algorithm is described in RFC 2268 [RC2]. The algorithm identifier for RC2 in CBC mode is:
rc2-cbc OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840)
rsadsi(113549) encryptionAlgorithm(3) 2 }
The AlgorithmIdentifier parameters field MUST be present, and the parameters field MUST contain a RC2CBCParameter:
RC2CBCParameter ::= SEQUENCE {
rc2ParameterVersion INTEGER,
iv OCTET STRING } -- exactly 8 octets
The RC2 effective-key-bits (key size) greater than 32 and less than 256 is encoded in the rc2ParameterVersion. For the effective-key-bits of 40, 64, and 128, the rc2ParameterVersion values are 160, 120, and 58 respectively. These values are not simply the RC2 key length. Note that the value 160 MUST be encoded as two octets (00 A0), since the one octet (A0) encoding represents a negative number. ๐
12.5. Message Authentication Code Algorithms ๐ฅ
CMS implementations that support authenticatedData MUST include HMAC with SHA-1.
MAC algorithm identifiers are located in the AuthenticatedData macAlgorithm field.
MAC values are located in the AuthenticatedData mac field.
12.5.1. HMAC with SHA-1 ๐
The HMAC with SHA-1 algorithm is described in RFC 2104 [HMAC]. The algorithm identifier for HMAC with SHA-1 is:
hMAC-SHA1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3)
dod(6) internet(1) security(5) mechanisms(5) 8 1 2 }
The AlgorithmIdentifier parameters field MUST be absent.
12.6. Triple-DES and RC2 Key Wrap Algorithms โจ
okay bestie, we're now in the key wrap zone ๐ CMS implementations MUST include encryption of a Triple-DES content-encryption key with a Triple-DES key-encryption key, using the algorithm in Sections 12.6.2 and 12.6.3. CMS implementations SHOULD include encryption of an RC2 content-encryption key with an RC2 key-encryption key, using the algorithm in Sections 12.6.4 and 12.6.5. Both the Triple-DES and RC2 content-encryption keys get encrypted in Cipher Block Chaining (CBC) mode [MODES] ๐
Key Transport algorithms can encrypt the content-encryption key directly ๐ Key agreement and symmetric key-encryption key algorithms are different: they encrypt the content-encryption key with a second symmetric encryption algorithm. This section explains how the Triple-DES or RC2 content-encryption key gets formatted and encrypted โจ
Key agreement algorithms generate a pairwise key-encryption key, and a key wrap algorithm then encrypts the content-encryption key with that pairwise key-encryption key ๐ฆ Similarly, a key wrap algorithm is used to encrypt the content-encryption key in a previously distributed key-encryption key ๐ซถ
The key-encryption key is either generated by the key agreement algorithm or distributed out of band. For key agreement of RC2 key-encryption keys, 128 bits MUST be generated as input to the key expansion process used to compute the RC2 effective key [RC2] ๐ฅ
The same algorithm identifier is used for both 2-key and 3-key Triple-DES. When the content-encryption key being wrapped is a 2-key Triple-DES key, a third key with the same value as the first key is created. So all Triple-DES content-encryption keys get wrapped like 3-key Triple-DES keys, no cap ๐ธ
12.6.1. Key Checksum
The CMS Checksum Algorithm gives the content-encryption key an integrity check value ๐ง Here's the recipe:
- Compute a 20 octet SHA-1 [SHA1] message digest on the content-encryption key.
- Use the most significant (first) eight octets of the message digest value as the checksum value.
12.6.2. Triple-DES Key Wrap
The Triple-DES key wrap algorithm encrypts a Triple-DES content-encryption key with a Triple-DES key-encryption key ๐ The steps are:
- Set odd parity for each of the DES key octets comprising the content-encryption key, and call the result
CEK. - Compute an 8 octet key checksum value on
CEKas described above in Section 12.6.1, and call the resultICV. - Let
CEKICV = CEK || ICV. - Generate 8 octets at random, and call the result
IV. - Encrypt
CEKICVin CBC mode using the key-encryption key. Use the random value generated in the previous step as the initialization vector (IV). Call the ciphertextTEMP1. - Let
TEMP2 = IV || TEMP1. - Reverse the order of the octets in
TEMP2. That is, the most significant (first) octet is swapped with the least significant (last) octet, and so on. Call the resultTEMP3. - Encrypt
TEMP3in CBC mode using the key-encryption key. Use an initialization vector (IV) of0x4adda22c79e82105. The ciphertext is 40 octets long.
Note: When the same content-encryption key is wrapped in different key-encryption keys, a fresh initialization vector (IV) MUST be generated for each invocation of the key wrap algorithm ๐
12.6.3. Triple-DES Key Unwrap
The Triple-DES key unwrap algorithm decrypts a Triple-DES content-encryption key using a Triple-DES key-encryption key ๐ The steps are:
- If the wrapped content-encryption key is not 40 octets, then error.
- Decrypt the wrapped content-encryption key in CBC mode using the key-encryption key. Use an initialization vector (IV) of
0x4adda22c79e82105. Call the outputTEMP3. - Reverse the order of the octets in
TEMP3. That is, the most significant (first) octet is swapped with the least significant (last) octet, and so on. Call the resultTEMP2. - Decompose
TEMP2intoIVandTEMP1.IVis the most significant (first) 8 octets, andTEMP1is the least significant (last) 32 octets. - Decrypt
TEMP1in CBC mode using the key-encryption key. Use theIVvalue from the previous step as the initialization vector. Call the ciphertextCEKICV. - Decompose
CEKICVintoCEKandICV.CEKis the most significant (first) 24 octets, andICVis the least significant (last) 8 octets. - Compute an 8 octet key checksum value on
CEKas described above in Section 12.6.1. If the computed key checksum value does not match the decrypted key checksum value,ICV, then error. - Check for odd parity on each of the DES key octets comprising
CEK. If parity is incorrect, then there is an error. - Use
CEKas the content-encryption key.
12.6.4. RC2 Key Wrap
The RC2 key wrap algorithm encrypts an RC2 content-encryption key with an RC2 key-encryption key ๐ The steps are:
- Let the content-encryption key be called
CEK, and let the length of the content-encryption key in octets be calledLENGTH.LENGTHis a single octet. - Let
LCEK = LENGTH || CEK. - Let
LCEKPAD = LCEK || PAD. If the length ofLCEKis a multiple of 8, thePADhas a length of zero. If the length ofLCEKis not a multiple of 8, thenPADcontains the fewest number of random octets to make the length ofLCEKPADa multiple of 8. - Compute an 8 octet key checksum value on
LCEKPADas described above in Section 12.6.1, and call the resultICV. - Let
LCEKPADICV = LCEKPAD || ICV. - Generate 8 octets at random, and call the result
IV. - Encrypt
LCEKPADICVin CBC mode using the key-encryption key. Use the random value generated in the previous step as the initialization vector (IV). Call the ciphertextTEMP1. - Let
TEMP2 = IV || TEMP1. - Reverse the order of the octets in
TEMP2. That is, the most significant (first) octet is swapped with the least significant (last) octet, and so on. Call the resultTEMP3. - Encrypt
TEMP3in CBC mode using the key-encryption key. Use an initialization vector (IV) of0x4adda22c79e82105.
Note: When the same content-encryption key is wrapped in different key-encryption keys, a fresh initialization vector (IV) MUST be generated for each invocation of the key wrap algorithm ๐
12.6.5. RC2 Key Unwrap
The RC2 key unwrap algorithm decrypts an RC2 content-encryption key using an RC2 key-encryption key โญ The steps are:
- If the wrapped content-encryption key is not a multiple of 8 octets, then error.
- Decrypt the wrapped content-encryption key in CBC mode using the key-encryption key. Use an initialization vector (IV) of
0x4adda22c79e82105. Call the outputTEMP3. - Reverse the order of the octets in
TEMP3. That is, the most significant (first) octet is swapped with the least significant (last) octet, and so on. Call the resultTEMP2. - Decompose
TEMP2intoIVandTEMP1.IVis the most significant (first) 8 octets, andTEMP1is the remaining octets. - Decrypt
TEMP1in CBC mode using the key-encryption key. Use theIVvalue from the previous step as the initialization vector. Call the plaintextLCEKPADICV. - Decompose
LCEKPADICVintoLCEKPADandICV.ICVis the least significant (last) octet 8 octets.LCEKPADis the remaining octets. - Compute an 8 octet key checksum value on
LCEKPADas described above in Section 12.6.1. If the computed key checksum value does not match the decrypted key checksum value,ICV, then error. - Decompose
LCEKPADintoLENGTH,CEK, andPAD.LENGTHis the most significant (first) octet.CEKis the followingLENGTHoctets.PADis the remaining octets, if any. - If the length of
PADis more than 7 octets, then error. - Use
CEKas the content-encryption key.
Appendix A: ASN.1 Module ๐
CryptographicMessageSyntax
{ iso(1) member-body(2) us(840) rsadsi(113549)
pkcs(1) pkcs-9(9) smime(16) modules(0) cms(1) }
DEFINITIONS IMPLICIT TAGS ::=
BEGIN
-- EXPORTS All
-- The types and values defined in this module are exported for use in
-- the other ASN.1 modules. Other applications may use them for their
-- own purposes.
IMPORTS
-- Directory Information Framework (X.501)
Name
FROM InformationFramework { joint-iso-itu-t ds(5) modules(1)
informationFramework(1) 3 }
-- Directory Authentication Framework (X.509)
AlgorithmIdentifier, AttributeCertificate, Certificate,
CertificateList, CertificateSerialNumber
FROM AuthenticationFramework { joint-iso-itu-t ds(5)
module(1) authenticationFramework(7) 3 } ;
-- Cryptographic Message Syntax
ContentInfo ::= SEQUENCE {
contentType ContentType,
content [0] EXPLICIT ANY DEFINED BY contentType }
ContentType ::= OBJECT IDENTIFIER
SignedData ::= SEQUENCE {
version CMSVersion,
digestAlgorithms DigestAlgorithmIdentifiers,
encapContentInfo EncapsulatedContentInfo,
certificates [0] IMPLICIT CertificateSet OPTIONAL,
crls [1] IMPLICIT CertificateRevocationLists OPTIONAL,
signerInfos SignerInfos }
DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier
SignerInfos ::= SET OF SignerInfo
EncapsulatedContentInfo ::= SEQUENCE {
eContentType ContentType,
eContent [0] EXPLICIT OCTET STRING OPTIONAL }
SignerInfo ::= SEQUENCE {
version CMSVersion,
sid SignerIdentifier,
digestAlgorithm DigestAlgorithmIdentifier,
signedAttrs [0] IMPLICIT SignedAttributes OPTIONAL,
signatureAlgorithm SignatureAlgorithmIdentifier,
signature SignatureValue,
unsignedAttrs [1] IMPLICIT UnsignedAttributes OPTIONAL }
SignerIdentifier ::= CHOICE {
issuerAndSerialNumber IssuerAndSerialNumber,
subjectKeyIdentifier [0] SubjectKeyIdentifier }
SignedAttributes ::= SET SIZE (1..MAX) OF Attribute
UnsignedAttributes ::= SET SIZE (1..MAX) OF Attribute
Attribute ::= SEQUENCE {
attrType OBJECT IDENTIFIER,
attrValues SET OF AttributeValue }
AttributeValue ::= ANY
SignatureValue ::= OCTET STRING
EnvelopedData ::= SEQUENCE {
version CMSVersion,
originatorInfo [0] IMPLICIT OriginatorInfo OPTIONAL,
recipientInfos RecipientInfos,
encryptedContentInfo EncryptedContentInfo,
unprotectedAttrs [1] IMPLICIT UnprotectedAttributes OPTIONAL }
OriginatorInfo ::= SEQUENCE {
certs [0] IMPLICIT CertificateSet OPTIONAL,
crls [1] IMPLICIT CertificateRevocationLists OPTIONAL }
RecipientInfos ::= SET OF RecipientInfo
EncryptedContentInfo ::= SEQUENCE {
contentType ContentType,
contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier,
encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL }
EncryptedContent ::= OCTET STRING
UnprotectedAttributes ::= SET SIZE (1..MAX) OF Attribute
RecipientInfo ::= CHOICE {
ktri KeyTransRecipientInfo,
kari [1] KeyAgreeRecipientInfo,
kekri [2] KEKRecipientInfo }
EncryptedKey ::= OCTET STRING
KeyTransRecipientInfo ::= SEQUENCE {
version CMSVersion, -- always set to 0 or 2
rid RecipientIdentifier,
keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
encryptedKey EncryptedKey }
RecipientIdentifier ::= CHOICE {
issuerAndSerialNumber IssuerAndSerialNumber,
subjectKeyIdentifier [0] SubjectKeyIdentifier }
KeyAgreeRecipientInfo ::= SEQUENCE {
version CMSVersion, -- always set to 3
originator [0] EXPLICIT OriginatorIdentifierOrKey,
ukm [1] EXPLICIT UserKeyingMaterial OPTIONAL,
keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
recipientEncryptedKeys RecipientEncryptedKeys }
okay bestie, we're picking up right where the ASN.1 module left off ๐ the originator stuff comes first, then it's all the content types, attributes and OIDs ๐
OriginatorIdentifierOrKey ::= CHOICE {
issuerAndSerialNumber IssuerAndSerialNumber,
subjectKeyIdentifier [0] SubjectKeyIdentifier,
originatorKey [1] OriginatorPublicKey }
OriginatorPublicKey ::= SEQUENCE {
algorithm AlgorithmIdentifier,
publicKey BIT STRING }
RecipientEncryptedKeys ::= SEQUENCE OF RecipientEncryptedKey
RecipientEncryptedKey ::= SEQUENCE {
rid KeyAgreeRecipientIdentifier,
encryptedKey EncryptedKey }
KeyAgreeRecipientIdentifier ::= CHOICE {
issuerAndSerialNumber IssuerAndSerialNumber,
rKeyId [0] IMPLICIT RecipientKeyIdentifier }
RecipientKeyIdentifier ::= SEQUENCE {
subjectKeyIdentifier SubjectKeyIdentifier,
date GeneralizedTime OPTIONAL,
other OtherKeyAttribute OPTIONAL }
SubjectKeyIdentifier ::= OCTET STRING
KEKRecipientInfo ::= SEQUENCE {
version CMSVersion, -- always set to 4
kekid KEKIdentifier,
keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
encryptedKey EncryptedKey }
KEKIdentifier ::= SEQUENCE {
keyIdentifier OCTET STRING,
date GeneralizedTime OPTIONAL,
other OtherKeyAttribute OPTIONAL }
DigestedData ::= SEQUENCE {
version CMSVersion,
digestAlgorithm DigestAlgorithmIdentifier,
encapContentInfo EncapsulatedContentInfo,
digest Digest }
Digest ::= OCTET STRING
EncryptedData ::= SEQUENCE {
version CMSVersion,
encryptedContentInfo EncryptedContentInfo,
unprotectedAttrs [1] IMPLICIT UnprotectedAttributes OPTIONAL }
AuthenticatedData ::= SEQUENCE {
version CMSVersion,
originatorInfo [0] IMPLICIT OriginatorInfo OPTIONAL,
recipientInfos RecipientInfos,
macAlgorithm MessageAuthenticationCodeAlgorithm,
digestAlgorithm [1] DigestAlgorithmIdentifier OPTIONAL,
encapContentInfo EncapsulatedContentInfo,
authenticatedAttributes [2] IMPLICIT AuthAttributes OPTIONAL,
mac MessageAuthenticationCode,
unauthenticatedAttributes [3] IMPLICIT UnauthAttributes OPTIONAL }
AuthAttributes ::= SET SIZE (1..MAX) OF Attribute
UnauthAttributes ::= SET SIZE (1..MAX) OF Attribute
MessageAuthenticationCode ::= OCTET STRING
DigestAlgorithmIdentifier ::= AlgorithmIdentifier
SignatureAlgorithmIdentifier ::= AlgorithmIdentifier
KeyEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
ContentEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
MessageAuthenticationCodeAlgorithm ::= AlgorithmIdentifier
CertificateRevocationLists ::= SET OF CertificateList
CertificateChoices ::= CHOICE {
certificate Certificate, -- See X.509
extendedCertificate [0] IMPLICIT ExtendedCertificate, -- Obsolete
attrCert [1] IMPLICIT AttributeCertificate } -- See X.509 & X9.57
CertificateSet ::= SET OF CertificateChoices
IssuerAndSerialNumber ::= SEQUENCE {
issuer Name,
serialNumber CertificateSerialNumber }
CMSVersion ::= INTEGER { v0(0), v1(1), v2(2), v3(3), v4(4) }
UserKeyingMaterial ::= OCTET STRING
OtherKeyAttribute ::= SEQUENCE {
keyAttrId OBJECT IDENTIFIER,
keyAttr ANY DEFINED BY keyAttrId OPTIONAL }
-- CMS Attributes
MessageDigest ::= OCTET STRING
SigningTime ::= Time
Time ::= CHOICE {
utcTime UTCTime,
generalTime GeneralizedTime }
Countersignature ::= SignerInfo
-- Algorithm Identifiers
sha-1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3)
oiw(14) secsig(3) algorithm(2) 26 }
md5 OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840)
rsadsi(113549) digestAlgorithm(2) 5 }
id-dsa-with-sha1 OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) x9-57 (10040) x9cm(4) 3 }
rsaEncryption OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs-1(1) 1 }
dh-public-number OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) ansi-x942(10046) number-type(2) 1 }
id-alg-ESDH OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840)
rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 5 }
id-alg-CMS3DESwrap OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 6 }
id-alg-CMSRC2wrap OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16) alg(3) 7 }
des-ede3-cbc OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) encryptionAlgorithm(3) 7 }
rc2-cbc OBJECT IDENTIFIER ::= { iso(1) member-body(2) us(840)
rsadsi(113549) encryptionAlgorithm(3) 2 }
hMAC-SHA1 OBJECT IDENTIFIER ::= { iso(1) identified-organization(3)
dod(6) internet(1) security(5) mechanisms(5) 8 1 2 }
-- Algorithm Parameters
KeyWrapAlgorithm ::= AlgorithmIdentifier
RC2wrapParameter ::= RC2ParameterVersion
RC2ParameterVersion ::= INTEGER
CBCParameter ::= IV
IV ::= OCTET STRING -- exactly 8 octets
RC2CBCParameter ::= SEQUENCE {
rc2ParameterVersion INTEGER,
iv OCTET STRING } -- exactly 8 octets
-- Content Type Object Identifiers
id-ct-contentInfo OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16)
ct(1) 6 }
id-data OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs7(7) 1 }
id-signedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs7(7) 2 }
id-envelopedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs7(7) 3 }
id-digestedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs7(7) 5 }
id-encryptedData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs7(7) 6 }
id-ct-authData OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs-9(9) smime(16)
ct(1) 2 }
-- Attribute Object Identifiers
id-contentType OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs9(9) 3 }
id-messageDigest OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs9(9) 4 }
id-signingTime OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs9(9) 5 }
id-countersignature OBJECT IDENTIFIER ::= { iso(1) member-body(2)
us(840) rsadsi(113549) pkcs(1) pkcs9(9) 6 }
-- Obsolete Extended Certificate syntax from PKCS#6
ExtendedCertificate ::= SEQUENCE {
extendedCertificateInfo ExtendedCertificateInfo,
signatureAlgorithm SignatureAlgorithmIdentifier,
signature Signature }
ExtendedCertificateInfo ::= SEQUENCE {
version CMSVersion,
certificate Certificate,
attributes UnauthAttributes }
Signature ::= BIT STRING
END -- of CryptographicMessageSyntax
okay and now the references ๐ these are the receipts, so every single detail stays put ๐ซถ
References
3DES American National Standards Institute. ANSI X9.52-1998,
Triple Data Encryption Algorithm Modes of Operation. 1998.
DES American National Standards Institute. ANSI X3.106,
"American National Standard for Information Systems - Data
Link Encryption". 1983.
DH-X9.42 Rescorla, E., "Diffie-Hellman Key Agreement Method",
RFC 2631, June 1999.
DSS National Institute of Standards and Technology.
FIPS Pub 186: Digital Signature Standard. 19 May 1994.
ESS Hoffman, P., Editor, "Enhanced Security Services for
S/MIME", RFC 2634, June 1999.
HMAC Krawczyk, H., "HMAC: Keyed-Hashing for Message
Authentication", RFC 2104, February 1997.
MD5 Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321,
April 1992.
MODES National Institute of Standards and Technology.
FIPS Pub 81: DES Modes of Operation. 2 December 1980.
MSG Ramsdell, B., Editor, "S/MIME Version 3 Message
Specification", RFC 2633, June 1999.
NEWPKCS#1 Kaliski, B., "PKCS #1: RSA Encryption, Version 2.0",
RFC 2347, October 1998.
PROFILE Housley, R., Ford, W., Polk, W. and D. Solo, "Internet
X.509 Public Key Infrastructure: Certificate and CRL
Profile", RFC 2459, January 1999.
PKCS#1 Kaliski, B., "PKCS #1: RSA Encryption, Version 1.5.",
RFC 2313, March 1998.
PKCS#6 RSA Laboratories. PKCS #6: Extended-Certificate Syntax
Standard, Version 1.5. November 1993.
PKCS#7 Kaliski, B., "PKCS #7: Cryptographic Message Syntax,
Version 1.5.", RFC 2315, March 1998.
PKCS#9 RSA Laboratories. PKCS #9: Selected Attribute Types,
Version 1.1. November 1993.
RANDOM Eastlake, D., Crocker, S. and J. Schiller, "Randomness
Recommendations for Security", RFC 1750, December 1994.
RC2 Rivest, R., "A Description of the RC2 (r) Encryption
Algorithm", RFC 2268, March 1998.
SHA1 National Institute of Standards and Technology.
FIPS Pub 180-1: Secure Hash Standard. 17 April 1995.
X.208-88 CCITT. Recommendation X.208: Specification of Abstract
Syntax Notation One (ASN.1). 1988.
X.209-88 CCITT. Recommendation X.209: Specification of Basic
Encoding Rules for Abstract Syntax Notation One (ASN.1).
1988.
X.501-88 CCITT. Recommendation X.501: The Directory - Models.
1988.
X.509-88 CCITT. Recommendation X.509: The Directory -
Authentication Framework. 1988.
X.509-97 ITU-T. Recommendation X.509: The Directory -
Authentication Framework. 1997.
that's the end of this bit, more coming up ๐
Security Considerations ๐โจ
Okay bestie, this part is serious, so listen up ๐ฅบ CMS can sign data, digest data, encrypt data, and authenticate data, which means a lot is riding on getting it right ๐
Implementations must protect the signer's private key. If somebody gets that key, they can masquerade as the signer ๐ That's a whole identity crisis.
Implementations must protect the key management private key, the key-encryption key, and the content-encryption key. If the key management private key or the key-encryption key gets compromised, all messages protected with that key could be disclosed ๐ญ And if the content-encryption key leaks, the encrypted content tied to it can be disclosed too.
Implementations must also protect the key management private key and the message-authentication key. Losing the key management private key lets someone masquerade as the authenticated data's sender. Losing the message-authentication key is just as scary, because someone could modify the authenticated content without anyone noticing ๐
Implementations must randomly generate content-encryption keys, message-authentication keys, initialization vectors (IVs), and padding. Generating key pairs also relies on random numbers. If the pseudo-random number generators (PRNGs) are weak, security can drop to basically nothing ๐ญ An attacker may find it much easier to recreate the PRNG environment that produced the keys and search that small set of possibilities, instead of brute forcing the entire key space. Generating truly good random numbers is hard, so RFC 1750 [RANDOM] gives important guidance here, and Appendix 3 of FIPS Pub 186 [DSS] describes one quality PRNG technique ๐
When you use key agreement algorithms or previously distributed symmetric key-encryption keys, a key-encryption key is used to encrypt the content-encryption key. If the key-encryption and content-encryption algorithms are different, the effective security is set by the weaker of the two ๐ฅ For example, say message content is encrypted with 168-bit Triple-DES, and the Triple-DES content-encryption key is wrapped with a 40-bit RC2 key. Then at most 40 bits of protection is provided. A trivial search for that 40-bit RC2 key can recover the Triple-DES key, and then the Triple-DES key can decrypt the content. So implementers must make sure key-encryption algorithms are as strong as or stronger than content-encryption algorithms ๐ โโ๏ธ
Section 12.6 specifies key wrap algorithms that encrypt a Triple-DES [3DES] content-encryption key with a Triple-DES key-encryption key, or encrypt an RC2 [RC2] content-encryption key with an RC2 key-encryption key. These key wrap algorithms use CBC mode [MODES]. They've only been reviewed for Triple-DES and RC2. They haven't been reviewed for other cryptographic modes or other encryption algorithms. So if a CMS implementation wants to support ciphers beyond Triple-DES or RC2, additional key wrap algorithms need to be defined for those ciphers ๐ง
Implementers should know that cryptographic algorithms get weaker over time ๐ฐ๏ธ As new cryptanalysis techniques show up and computing performance improves, the work factor to break an algorithm goes down. That's why implementations should be modular, so new algorithms can be slotted in easily. Basically, implementers should be ready for the set of mandatory-to-implement algorithms to change over time โจ
The countersignature unauthenticated attribute includes a digital signature computed over the content signature value. That means the countersigning process doesn't need to know the original signed content ๐ง
This structure gives implementation efficiency advantages. But it may also allow the countersigning of an inappropriate signature value ๐ฌ So implementations that perform countersignatures should either verify the original signature value before countersigning it (this verification requires processing the original content), or perform countersigning in a context that makes sure only appropriate signature values get countersigned.
Users of CMS, especially anyone using CMS for interactive applications, should be aware that PKCS #1 Version 1.5 as specified in RFC 2313 [PKCS#1] is vulnerable to adaptive chosen ciphertext attacks when used for encryption ๐ฑ Exploiting this vulnerability, which reveals the result of a particular RSA decryption, requires an oracle that responds to a huge number of ciphertexts (based on current results, hundreds of thousands or more). Those ciphertexts are built adaptively, based on replies about whether earlier decryption attempts succeeded or failed. So the attack looks much less feasible for store-and-forward S/MIME environments than for directly interactive protocols. But if CMS constructs are used as an intermediate encryption layer inside an interactive request-response environment, exploitation could be more feasible ๐
An updated version, PKCS #1 Version 2.0 [NEWPKCS#1], has been published, and it will supersede RFC 2313. PKCS #1 Version 2.0 keeps support for the encryption padding format from PKCS #1 Version 1.5 [PKCS#1], and it also defines a new alternative. To fix the adaptive chosen ciphertext vulnerability, PKCS #1 Version 2.0 specifies and recommends Optimal Asymmetric Encryption Padding (OAEP) whenever RSA encryption is used to provide confidentiality ๐ธ Designers of protocols and systems that use CMS in interactive environments should either consider using OAEP, or make sure that information which could reveal whether PKCS #1 Version 1.5 decryption attempts succeeded or failed is never provided. Support for OAEP will likely be added to a future version of the CMS specification ๐ฎ
Acknowledgments ๐ซถ
This document is the result of contributions from many professionals. Big thanks to everyone in the IETF S/MIME Working Group for all the hard work ๐ Special shoutouts to Rich Ankney, Tim Dean, Steve Dusse, Carl Ellison, Peter Gutmann, Bob Jueneman, Stephen Henson, Paul Hoffman, Scott Hollenbeck, Don Johnson, Burt Kaliski, John Linn, John Pawling, Blake Ramsdell, Francois Rousseau, Jim Schaad, and Dave Solo for their efforts and support ๐
Author's Address ๐ฎ
Russell Housley SPYRUS 381 Elden Street Suite 1120 Herndon, VA 20170 USA
EMail: housley@spyrus.com
Full Copyright Statement ยฉ๏ธ
Copyright (C) The Internet Society (1999). All Rights Reserved. ๐
This document and translations of it may be copied and furnished to others. Derivative works that comment on or explain it, or help with its implementation, may be prepared, copied, published, and distributed, in whole or in part, without restriction of any kind. The only condition is that the above copyright notice and this paragraph are included on all such copies and derivative works ๐ฆ However, this document itself may not be modified in any way, such as by removing the copyright notice or references to the Internet Society or other Internet organizations. The exceptions are when it's needed for developing Internet standards (in which case the copyright procedures defined in the Internet Standards process must be followed), or when it's translated into languages other than English.
The limited permissions granted above are perpetual and will not be revoked by the Internet Society or its successors or assigns โพ๏ธ
This document and the information in it are provided on an "AS IS" basis, and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ๐
Acknowledgement ๐ท
Funding for the RFC Editor function is currently provided by the Internet Society ๐ โจ
๐ฆ where this page comes from
- ietf: rfc2630 1999-06
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms