RFC 2630

Cryptographic Message Syntax

๐Ÿ“… published June 1999, from ietf

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 (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:

  1. 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." ๐Ÿง
  2. For each signer, the message digest is digitally signed using the signer's private key.
  3. 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.
  4. 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:

  • version is 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. ๐ŸŽ€
  • digestAlgorithms is 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.
  • encapContentInfo is 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.
  • certificates is 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. ๐ŸŒธ
  • crls is 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.
  • signerInfos is 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:

  • eContentType is an object identifier that uniquely specifies the content type.
  • eContent is 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:

  • version is 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. ๐ŸŽ€
  • sid specifies 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. ๐Ÿ”‘
  • digestAlgorithm identifies 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.
  • signedAttributes is 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. ๐Ÿ’–
  • signatureAlgorithm identifies the signature algorithm, and any associated parameters, used by the signer to generate the digital signature.
  • signature is the result of digital signature generation, using the message digest and the signer's private key. โœจ
  • unsignedAttributes is 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:

  • attrType indicates the type of attribute. It is an object identifier.
  • attrValues is 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:

  1. A content-encryption key for a particular content-encryption algorithm is generated at random ๐ŸŽฒ.
  2. 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.
  3. For each recipient, the encrypted content-encryption key and other recipient-specific information get collected into a RecipientInfo value, defined in Section 6.2 ๐Ÿ“.
  4. 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 ๐Ÿซง.
  5. 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 ๐ŸŽ€

  • version is the syntax version number. If the RecipientIdentifier is the CHOICE issuerAndSerialNumber, then the version shall be 0. If the RecipientIdentifier is subjectKeyIdentifier, then the version shall be 2.
  • rid names 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. The issuerAndSerialNumber option finds the certificate using the issuer's distinguished name and the certificate serial number. The subjectKeyIdentifier option finds it using the X.509 subjectKeyIdentifier extension value ๐Ÿฆ‹
  • keyEncryptionAlgorithm identifies 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 ๐Ÿ’…
  • encryptedKey is 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 ๐Ÿง

  • version is the syntax version number. It shall always be 3.
  • originator is 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. The issuerAndSerialNumber option identifies the sender's certificate, and therefore the sender's public key, by issuer distinguished name and certificate serial number. The subjectKeyIdentifier option identifies the sender's certificate, and therefore the sender's public key, by the X.509 subjectKeyIdentifier extension value. The originatorKey option carries the algorithm identifier and the sender's key agreement public key itself, which allows originator anonymity since the public key is not certified ๐Ÿ™ˆ
  • ukm is 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.
  • keyEncryptionAlgorithm identifies 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 ๐Ÿ‘‘
  • recipientEncryptedKeys holds 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. The issuerAndSerialNumber option identifies the recipient's certificate by issuer distinguished name and certificate serial number. The RecipientKeyIdentifier is described below. The encryptedKey is 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 ๐Ÿงš

  • subjectKeyIdentifier identifies the recipient's certificate by the X.509 subjectKeyIdentifier extension value.
  • date is optional. When it's present, it says which of the recipient's previously distributed UKMs the sender used ๐Ÿ“….
  • other is 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 ๐ŸŒˆ

  • version is the syntax version number. It shall always be 4.
  • kekid names a symmetric key-encryption key that was previously distributed to the sender and one or more recipients ๐ŸŽ€.
  • keyEncryptionAlgorithm identifies 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 โœจ.
  • encryptedKey is the result of encrypting the content-encryption key in the key-encryption key ๐Ÿฆ‹.

The fields of KEKIdentifier are ๐Ÿ’…

  • keyIdentifier identifies the key-encryption key that was previously distributed to the sender and one or more recipients.
  • date is optional. When it's present, it picks out a single key-encryption key from a set that was previously distributed ๐Ÿ“†.
  • other is 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:

  1. A message digest is computed on the content with a message-digest algorithm.
  2. 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 ๐ŸŒธ:

  • version is the syntax version number. If the encapsulated content type is id-data, then the value of version SHALL be 0. However, if the encapsulated content type is other than id-data, then the value of version SHALL be 2.
  • digestAlgorithm identifies 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.
  • encapContentInfo is the content that gets digested, as defined in section 5.2.
  • digest is 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 ๐Ÿฆ‹:

  • version is the syntax version number. If unprotectedAttrs is present, then version SHALL be 2. If unprotectedAttrs is absent, then version SHALL be 0.
  • encryptedContentInfo is the encrypted content information, as defined in Section 6.1.
  • unprotectedAttrs is 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:

  1. A message-authentication key for a particular message-authentication algorithm is generated at random.
  2. The message-authentication key is encrypted for each recipient. The details of this encryption depend on the key management algorithm used.
  3. For each recipient, the encrypted message-authentication key and other recipient-specific information are collected into a RecipientInfo value, defined in Section 6.2.
  4. 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 ๐Ÿ“:

  • version is the syntax version number. It SHALL be 0.
  • originatorInfo optionally 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.
  • recipientInfos is a collection of per-recipient information, as defined in Section 6.1. There MUST be at least one element in the collection.
  • macAlgorithm is a message authentication code (MAC) algorithm identifier. It identifies the MAC algorithm, along with any associated parameters, that the originator used. Placing the macAlgorithm field here facilitates one-pass processing by the recipient.
  • digestAlgorithm identifies 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 the digestAlgorithm field here facilitates one-pass processing by the recipient. If the digestAlgorithm field is present, then the authenticatedAttributes field MUST also be present.
  • encapContentInfo is the content that is authenticated, as defined in section 5.2.
  • authenticatedAttributes is a collection of authenticated attributes. The authenticatedAttributes structure is optional, but it MUST be present if the content type of the EncapsulatedContentInfo value being authenticated is not id-data. If the authenticatedAttributes field is present, then the digestAlgorithm field MUST also be present. Each AuthenticatedAttribute in the SET MUST be DER encoded. Useful attribute types are defined in Section 11. If the authenticatedAttributes 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 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.
  • mac is the message authentication code.
  • unauthenticatedAttributes is 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:

  1. 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.
  2. 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 ๐Ÿ’…

  • version MUST be 3.
  • originator MUST 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 }
  • ukm MAY 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 ๐Ÿ”ฅ
  • keyEncryptionAlgorithm MUST be the id-alg-ESDH algorithm identifier. The algorithm identifier parameter field for id-alg-ESDH is KeyWrapAlgorihtm, and this parameter MUST be present. The KeyWrapAlgorithm denotes 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
  • recipientEncryptedKeys contains 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 the KeyWrapAlgortihm. โœจ

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:

  1. Compute a 20 octet SHA-1 [SHA1] message digest on the content-encryption key.
  2. 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:

  1. Set odd parity for each of the DES key octets comprising the content-encryption key, and call the result CEK.
  2. Compute an 8 octet key checksum value on CEK as described above in Section 12.6.1, and call the result ICV.
  3. Let CEKICV = CEK || ICV.
  4. Generate 8 octets at random, and call the result IV.
  5. Encrypt CEKICV in CBC mode using the key-encryption key. Use the random value generated in the previous step as the initialization vector (IV). Call the ciphertext TEMP1.
  6. Let TEMP2 = IV || TEMP1.
  7. 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 result TEMP3.
  8. Encrypt TEMP3 in CBC mode using the key-encryption key. Use an initialization vector (IV) of 0x4adda22c79e82105. 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:

  1. If the wrapped content-encryption key is not 40 octets, then error.
  2. Decrypt the wrapped content-encryption key in CBC mode using the key-encryption key. Use an initialization vector (IV) of 0x4adda22c79e82105. Call the output TEMP3.
  3. 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 result TEMP2.
  4. Decompose TEMP2 into IV and TEMP1. IV is the most significant (first) 8 octets, and TEMP1 is the least significant (last) 32 octets.
  5. Decrypt TEMP1 in CBC mode using the key-encryption key. Use the IV value from the previous step as the initialization vector. Call the ciphertext CEKICV.
  6. Decompose CEKICV into CEK and ICV. CEK is the most significant (first) 24 octets, and ICV is the least significant (last) 8 octets.
  7. Compute an 8 octet key checksum value on CEK as described above in Section 12.6.1. If the computed key checksum value does not match the decrypted key checksum value, ICV, then error.
  8. Check for odd parity on each of the DES key octets comprising CEK. If parity is incorrect, then there is an error.
  9. Use CEK as 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:

  1. Let the content-encryption key be called CEK, and let the length of the content-encryption key in octets be called LENGTH. LENGTH is a single octet.
  2. Let LCEK = LENGTH || CEK.
  3. Let LCEKPAD = LCEK || PAD. If the length of LCEK is a multiple of 8, the PAD has a length of zero. If the length of LCEK is not a multiple of 8, then PAD contains the fewest number of random octets to make the length of LCEKPAD a multiple of 8.
  4. Compute an 8 octet key checksum value on LCEKPAD as described above in Section 12.6.1, and call the result ICV.
  5. Let LCEKPADICV = LCEKPAD || ICV.
  6. Generate 8 octets at random, and call the result IV.
  7. Encrypt LCEKPADICV in CBC mode using the key-encryption key. Use the random value generated in the previous step as the initialization vector (IV). Call the ciphertext TEMP1.
  8. Let TEMP2 = IV || TEMP1.
  9. 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 result TEMP3.
  10. Encrypt TEMP3 in CBC mode using the key-encryption key. Use an initialization vector (IV) of 0x4adda22c79e82105.
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:

  1. If the wrapped content-encryption key is not a multiple of 8 octets, then error.
  2. Decrypt the wrapped content-encryption key in CBC mode using the key-encryption key. Use an initialization vector (IV) of 0x4adda22c79e82105. Call the output TEMP3.
  3. 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 result TEMP2.
  4. Decompose TEMP2 into IV and TEMP1. IV is the most significant (first) 8 octets, and TEMP1 is the remaining octets.
  5. Decrypt TEMP1 in CBC mode using the key-encryption key. Use the IV value from the previous step as the initialization vector. Call the plaintext LCEKPADICV.
  6. Decompose LCEKPADICV into LCEKPAD and ICV. ICV is the least significant (last) octet 8 octets. LCEKPAD is the remaining octets.
  7. Compute an 8 octet key checksum value on LCEKPAD as described above in Section 12.6.1. If the computed key checksum value does not match the decrypted key checksum value, ICV, then error.
  8. Decompose LCEKPAD into LENGTH, CEK, and PAD. LENGTH is the most significant (first) octet. CEK is the following LENGTH octets. PAD is the remaining octets, if any.
  9. If the length of PAD is more than 7 octets, then error.
  10. Use CEK as 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

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