home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / rfc / 3 / rfc2315.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  68.0 KB  |  1,796 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Network Working Group                                          B. Kaliski
  8. Request for Comments: 2315                         RSA Laboratories, East
  9. Category: Informational                                        March 1998
  10.  
  11.  
  12.                  PKCS #7: Cryptographic Message Syntax
  13.                               Version 1.5
  14.  
  15. Status of this Memo
  16.  
  17.    This memo provides information for the Internet community.  It does
  18.    not specify an Internet standard of any kind.  Distribution of this
  19.    memo is unlimited.
  20.  
  21. Copyright Notice
  22.  
  23.    Copyright (C) The Internet Society (1998).  All Rights Reserved.
  24.  
  25. Overview
  26.  
  27.    This document describes a general syntax for data that may have
  28.    cryptography applied to it, such as digital signatures and digital
  29.    envelopes. The syntax admits recursion, so that, for example, one
  30.    envelope can be nested inside another, or one party can sign some
  31.    previously enveloped digital data.  It also allows arbitrary
  32.    attributes, such as signing time, to be authenticated along with the
  33.    content of a message, and provides for other attributes such as
  34.    countersignatures to be associated with a signature. A degenerate
  35.    case of the syntax provides a means for disseminating certificates
  36.    and certificate-revocation lists.
  37.  
  38. 1. Scope
  39.  
  40.    This document is compatible with Privacy-Enhanced Mail (PEM) in that
  41.    signed-data and signed-and-enveloped-data content, constructed in a
  42.    PEM-compatible mode, can be converted into PEM messages without any
  43.    cryptographic operations. PEM messages can similarly be converted
  44.    into the signed-data and signed-and-enveloped data content types.
  45.  
  46.    This document can support a variety of architectures for
  47.    certificate-based key management, such as the one proposed for
  48.    Privacy-Enhanced Mail in RFC 1422. Architectural decisions such as
  49.    what certificate issuers are considered "top-level," what entities
  50.    certificate issuers are authorized to certify, what distinguished
  51.    names are considered acceptable, and what policies certificate
  52.    issuers must follow (such as signing only with secure hardware, or
  53.    requiring entities to present specific forms of identification) are
  54.    left outside the document.
  55.  
  56.  
  57.  
  58. Kaliski                      Informational                      [Page 1]
  59.  
  60. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  61.  
  62.  
  63.    The values produced according to this document are intended to be
  64.    BER-encoded, which means that the values would typically be
  65.    represented as octet strings. While many systems are capable of
  66.    transmitting arbitrary octet strings reliably, it is well known that
  67.    many electronic-mail systems are not. This document does not address
  68.    mechanisms for encoding octet strings as (say) strings of ASCII
  69.    characters or other techniques for enabling reliable transmission by
  70.    re-encoding the octet string. RFC 1421 suggests one possible solution
  71.    to this problem.
  72.  
  73. 2. References
  74.  
  75.       FIPS PUB 46-1  National Bureau of Standards. FIPS PUB 46-1:
  76.                 Data Encryption Standard. January 1988.
  77.  
  78.       PKCS #1   RSA Laboratories. PKCS #1: RSA Encryption.
  79.                 Version 1.5, November 1993.
  80.  
  81.       PKCS #6   RSA Laboratories. PKCS #6: Extended-Certificate
  82.                 Syntax. Version 1.5, November 1993.
  83.  
  84.       PKCS #9   RSA Laboratories. PKCS #9: Selected Attribute
  85.                 Types. Version 1.1, November 1993.
  86.  
  87.       RFC 1421  Linn, J., "Privacy Enhancement for
  88.                 Internet Electronic Mail: Part I: Message
  89.                 Encryption and Authentication Procedures," RFC 1421
  90.                 February 1993.
  91.  
  92.       RFC 1422  Kent, S., "Privacy Enhancement for
  93.                 Internet Electronic Mail: Part II: Certificate-
  94.                 Based Key Management," RFC 1422, February 1993.
  95.  
  96.       RFC 1423  Balenson, D., "Privacy Enhancement for
  97.                 Internet Electronic Mail: Part III: Algorithms,
  98.                 Modes, and Identifiers," RFC 1423, February 1993.
  99.  
  100.       RFC 1424  Kaliski, B., "Privacy Enhancement for
  101.                 Internet Electronic Mail: Part IV: Key
  102.                 Certification and Related Services," RFC 1424,
  103.                 February 1993.
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. Kaliski                      Informational                      [Page 2]
  115.  
  116. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  117.  
  118.  
  119.       RFC 1319  Kaliski, B., "The MD2 Message-Digest
  120.                 Algorithm," RFC 1319, April 1992.
  121.  
  122.       RFC 1321  Rivest, R., "The MD5 Message-Digest
  123.                 Algorithm," RFC 1321, April 1992.
  124.  
  125.       X.208     CCITT. Recommendation X.208: Specification of
  126.                 Abstract Syntax Notation One (ASN.1). 1988.
  127.  
  128.       X.209     CCITT. Recommendation X.209: Specification of
  129.                 Basic Encoding Rules for Abstract Syntax Notation
  130.                 One (ASN.1). 1988.
  131.  
  132.       X.500     CCITT. Recommendation X.500: The Directory--
  133.                 Overview of Concepts, Models and
  134.                 Services. 1988.
  135.  
  136.       X.501     CCITT. Recommendation X.501: The Directory--
  137.                 Models. 1988.
  138.  
  139.       X.509     CCITT. Recommendation X.509: The Directory--
  140.                 Authentication Framework. 1988.
  141.  
  142.       [NIST91]  NIST. Special Publication 500-202: Stable
  143.                 Implementation Agreements for Open Systems
  144.                 Interconnection Protocols. Version 5, Edition 1,
  145.                 Part 12. December 1991.
  146.  
  147.       [RSA78]   R.L. Rivest, A. Shamir, and L. Adleman. A method
  148.                 for obtaining digital signatures and public-key
  149.                 cryptosystems. Communications of the ACM,
  150.                 21(2):120-126, February 1978.
  151.  
  152. 3. Definitions
  153.  
  154.    For the purposes of this document, the following definitions apply.
  155.  
  156.    AlgorithmIdentifier: A type that identifies an algorithm (by object
  157.    identifier) and associated parameters. This type is defined in X.509.
  158.  
  159.    ASN.1: Abstract Syntax Notation One, as defined in X.208.
  160.  
  161.    Attribute: A type that contains an attribute type (specified by
  162.    object identifier) and one or more attribute values. This type is
  163.    defined in X.501.
  164.  
  165.    BER: Basic Encoding Rules, as defined in X.209.
  166.  
  167.  
  168.  
  169.  
  170. Kaliski                      Informational                      [Page 3]
  171.  
  172. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  173.  
  174.  
  175.    Certificate: A type that binds an entity's distinguished name to a
  176.    public key with a digital signature. This type is defined in X.509.
  177.    This type also contains the distinguished name of the certificate
  178.    issuer (the signer), an issuer-specific serial number, the issuer's
  179.    signature algorithm identifier, and a validity period.
  180.  
  181.    CertificateSerialNumber: A type that uniquely identifies a
  182.    certificate (and thereby an entity and a public key) among those
  183.    signed by a particular certificate issuer. This type is defined in
  184.    X.509.
  185.  
  186.    CertificateRevocationList: A type that contains information about
  187.    certificates whose validity an issuer has prematurely revoked. The
  188.    information consists of an issuer name, the time of issue, the next
  189.    scheduled time of issue, and a list of certificate serial numbers and
  190.    their associated revocation times. The CRL is signed by the issuer.
  191.    The type intended by this document is the one defined RFC 1422.
  192.  
  193.    DER: Distinguished Encoding Rules for ASN.1, as defined in X.509,
  194.    Section 8.7.
  195.  
  196.    DES: Data Encryption Standard, as defined in FIPS PUB 46-1.
  197.  
  198.    desCBC: The object identifier for DES in cipher-block chaining (CBC)
  199.    mode, as defined in [NIST91].
  200.  
  201.    ExtendedCertificate: A type that consists of an X.509 public-key
  202.    certificate and a set of attributes, collectively signed by the
  203.    issuer of the X.509 public-key certificate. This type is defined in
  204.    PKCS #6.
  205.  
  206.    MD2: RSA Data Security, Inc.'s MD2 message-digest algorithm, as
  207.    defined in RFC 1319.
  208.  
  209.    md2: The object identifier for MD2, as defined in RFC 1319.
  210.  
  211.    MD5: RSA Data Security, Inc.'s MD5 message-digest algorithm, as
  212.    defined in RFC 1321.
  213.  
  214.    md5: The object identifier for MD5, as defined in RFC 1321.
  215.  
  216.    Name: A type that uniquely identifies or "distinguishes" objects in
  217.    an X.500 directory. This type is defined in X.501. In an X.509
  218.    certificate, the type identifies the certificate issuer and the
  219.    entity whose public key is certified.
  220.  
  221.    PEM: Internet Privacy-Enhanced Mail, as defined in RFCs 1421-1424.
  222.  
  223.  
  224.  
  225.  
  226. Kaliski                      Informational                      [Page 4]
  227.  
  228. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  229.  
  230.  
  231.    RSA: The RSA public-key cryptosystem, as defined in [RSA78].
  232.  
  233.    rsaEncryption: The object identifier for RSA encryption, as defined
  234.    in PKCS #1.
  235.  
  236. 4. Symbols and abbreviations
  237.  
  238.    No symbols or abbreviations are defined in this document.
  239.  
  240. 5. General overview
  241.  
  242.    The following nine sections specify useful types, general syntax, six
  243.    content types, and object identifiers.
  244.  
  245.    The syntax is general enough to support many different content types.
  246.    This document defines six: data, signed data, enveloped data,
  247.    signed-and-enveloped data, digested data, and encrypted data. Other
  248.    content types may be added in the future. The use of content types
  249.    defined outside this document is possible, but is subject to
  250.    bilateral agreement between parties exchanging content.
  251.  
  252.    This document exports one type, ContentInfo, as well as the various
  253.    object identifiers.
  254.  
  255.    There are two classes of content types: base and enhanced.  Content
  256.    types in the base class contain "just data," with no cryptographic
  257.    enhancements. Presently, one content type is in this class, the data
  258.    content type. Content types in the enhanced class contain content of
  259.    some type (possibly encrypted), and other cryptographic enhancements.
  260.    For example, enveloped-data content can contain (encrypted) signed-
  261.    data content, which can contain data content. The four non-data
  262.    content types fall into the enhanced class.  The content types in the
  263.    enhanced class thus employ encapsulation, giving rise to the terms
  264.    "outer" content (the one containing the enhancements) and "inner"
  265.    content (the one being enhanced).
  266.  
  267.    The document is designed such that the enhanced content types can be
  268.    prepared in a single pass using indefinite-length BER encoding, and
  269.    processed in a single pass in any BER encoding. Single-pass operation
  270.    is especially helpful if content is stored on tapes, or is "piped"
  271.    from another process. One of the drawbacks of single-pass operation,
  272.    however, is that it is difficult to output a DER encoding in a single
  273.    pass, since the lengths of the various components may not be known in
  274.    advance. Since DER encoding is required by the signed-data, signed-
  275.    and-enveloped data, and digested-data content types, an extra pass
  276.    may be necessary when a content type other than data is the inner
  277.    content of one of those content types.
  278.  
  279.  
  280.  
  281.  
  282. Kaliski                      Informational                      [Page 5]
  283.  
  284. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  285.  
  286.  
  287. 6. Useful types
  288.  
  289.    This section defines types that are useful in at least two places in
  290.    the document.
  291.  
  292. 6.1 CertificateRevocationLists
  293.  
  294.    The CertificateRevocationLists type gives a set of certificate-
  295.    revocation lists. It is intended that the set contain information
  296.    sufficient to determine whether the certificates with which the set
  297.    is associated are "hot listed," but there may be more certificate-
  298.    revocation lists than necessary, or there may be fewer than
  299.    necessary.
  300.  
  301.    CertificateRevocationLists ::=
  302.      SET OF CertificateRevocationList
  303.  
  304. 6.2 ContentEncryptionAlgorithmIdentifier
  305.  
  306.    The ContentEncryptionAlgorithmIdentifier type identifies a content-
  307.    encryption algorithm such as DES. A content-encryption algorithm
  308.    supports encryption and decryption operations. The encryption
  309.    operation maps an octet string (the message) to another octet string
  310.    (the ciphertext) under control of a content-encryption key. The
  311.    decryption operation is the inverse of the encryption operation.
  312.    Context determines which operation is intended.
  313.  
  314.    ContentEncryptionAlgorithmIdentifier ::=
  315.      AlgorithmIdentifier
  316.  
  317. 6.3 DigestAlgorithmIdentifier
  318.  
  319.    The DigestAlgorithmIdentifier type identifies a message-digest
  320.    algorithm. Examples include MD2 and MD5. A message-digest algorithm
  321.    maps an octet string (the message) to another octet string (the
  322.    message digest).
  323.  
  324.    DigestAlgorithmIdentifier ::= AlgorithmIdentifier
  325.  
  326. 6.4 DigestEncryptionAlgorithmIdentifier
  327.  
  328.    The DigestEncryptionAlgorithmIdentifier type identifies a digest-
  329.    encryption algorithm under which a message digest can be encrypted.
  330.    One example is PKCS #1's rsaEncryption. A digest-encryption algorithm
  331.    supports encryption and decryption operations. The encryption
  332.    operation maps an octet string (the message digest) to another octet
  333.    .bp string (the encrypted message digest) under control of a digest-
  334.    encryption key. The decryption operation is the inverse of the
  335.  
  336.  
  337.  
  338. Kaliski                      Informational                      [Page 6]
  339.  
  340. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  341.  
  342.  
  343.    encryption operation. Context determines which operation is intended.
  344.  
  345.    DigestEncryptionAlgorithmIdentifier ::=
  346.      AlgorithmIdentifier
  347.  
  348. 6.5 ExtendedCertificateOrCertificate
  349.  
  350.    The ExtendedCertificateOrCertificate type gives either a PKCS #6
  351.    extended certificate or an X.509 certificate.  This type follows the
  352.    syntax recommended in Section 6 of PKCS #6:
  353.  
  354.    ExtendedCertificateOrCertificate ::= CHOICE {
  355.      certificate Certificate, -- X.509
  356.  
  357.      extendedCertificate [0] IMPLICIT ExtendedCertificate }
  358.  
  359. 6.6 ExtendedCertificatesAndCertificates
  360.  
  361.    The ExtendedCertificatesAndCertificates type gives a set of extended
  362.    certificates and X.509 certificates. It is intended that the set be
  363.    sufficient to contain chains from a recognized "root" or "top-level
  364.    certification authority" to all of the signers with which the set is
  365.    associated, but there may be more certificates than necessary, or
  366.    there may be fewer than necessary.
  367.  
  368.    ExtendedCertificatesAndCertificates ::=
  369.      SET OF ExtendedCertificateOrCertificate
  370.  
  371.    Note. The precise meaning of a "chain" is outside the scope of this
  372.    document. Some applications of this document may impose upper limits
  373.    on the length of a chain; others may enforce certain relationships
  374.    between the subjects and issuers of certificates in a chain. An
  375.    example of such relationships has been proposed for Privacy-Enhanced
  376.    Mail in RFC 1422.
  377.  
  378. 6.7 IssuerAndSerialNumber
  379.  
  380.    The IssuerAndSerialNumber type identifies a certificate (and thereby
  381.    an entity and a public key) by the distinguished name of the
  382.    certificate issuer and an issuer-specific certificate serial number.
  383.  
  384.    IssuerAndSerialNumber ::= SEQUENCE {
  385.      issuer Name,
  386.      serialNumber CertificateSerialNumber }
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394. Kaliski                      Informational                      [Page 7]
  395.  
  396. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  397.  
  398.  
  399. 6.8 KeyEncryptionAlgorithmIdentifier
  400.  
  401.    The KeyEncryptionAlgorithmIdentifier type identifies a key-encryption
  402.    algorithm under which a content-encryption key can be encrypted. One
  403.    example is PKCS #1's rsaEncryption. A key-encryption algorithm
  404.    supports encryption and decryption operations. The encryption
  405.    operation maps an octet string (the key) to another octet string (the
  406.    encrypted key) under control of a key-encryption key. The decryption
  407.    operation is the inverse of the encryption operation.  Context
  408.    determines which operation is intended.
  409.  
  410.    KeyEncryptionAlgorithmIdentifier ::=
  411.      AlgorithmIdentifier
  412.  
  413. 6.9 Version
  414.  
  415.    The Version type gives a syntax version number, for compatibility
  416.    with future revisions of this document.
  417.  
  418.    Version ::= INTEGER
  419.  
  420. 7. General syntax
  421.  
  422.    The general syntax for content exchanged between entities according
  423.    to this document associates a content type with content. The syntax
  424.    shall have ASN.1 type ContentInfo:
  425.  
  426.    ContentInfo ::= SEQUENCE {
  427.      contentType ContentType,
  428.      content
  429.        [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }
  430.  
  431.    ContentType ::= OBJECT IDENTIFIER
  432.  
  433.    The fields of type ContentInfo have the following meanings:
  434.  
  435.         o    contentType indicates the type of content. It is
  436.              an object identifier, which means it is a unique string of
  437.              integers assigned by the authority that defines the content
  438.              type. This document defines six content types (see Section
  439.              14): data, signedData, envelopedData,
  440.              signedAndEnvelopedData, digestedData, and encryptedData.
  441.  
  442.         o    content is the content. The field is optional, and
  443.              if the field is not present, its intended value must be
  444.              supplied by other means. Its type is defined along with the
  445.              object identifier for contentType.
  446.  
  447.  
  448.  
  449.  
  450. Kaliski                      Informational                      [Page 8]
  451.  
  452. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  453.  
  454.  
  455.    Notes.
  456.  
  457.         1.   The methods below assume that the type of content
  458.              can be determined uniquely by contentType, so the type
  459.              defined along with the object identifier should not be a
  460.              CHOICE type.
  461.  
  462.         2.   When a ContentInfo value is the inner content of
  463.              signed-data, signed-and-enveloped-data, or digested-data
  464.              content, a message-digest algorithm is applied to the
  465.              contents octets of the DER encoding of the content field.
  466.              When a ContentInfo value is the inner content of
  467.              enveloped-data or signed-and-enveloped-data content, a
  468.              content-encryption algorithm is applied to the contents
  469.              octets of a definite-length BER encoding of the content
  470.              field.
  471.  
  472.         3.   The optional omission of the content field makes
  473.              it possible to construct "external signatures," for
  474.              example, without modification to or replication of the
  475.              content to which the signatures apply. In the case of
  476.              external signatures, the content being signed would be
  477.              omitted from the "inner" encapsulated ContentInfo value
  478.              included in the signed-data content type.
  479.  
  480. 8. Data content type
  481.  
  482.    The data content type is just an octet string. It shall have ASN.1
  483.    type Data:
  484.  
  485.    Data ::= OCTET STRING
  486.  
  487.    The data content type is intended to refer to arbitrary octet
  488.    strings, such as ASCII text files; the interpretation is left to the
  489.    application. Such strings need not have any internal structure
  490.    (although they may; they could even be DER encodings).
  491.  
  492. 9. Signed-data content type
  493.  
  494.    The signed-data content type consists of content of any type and
  495.    encrypted message digests of the content for zero or more signers.
  496.    The encrypted digest for a signer is a "digital signature" on the
  497.    content for that signer. Any type of content can be signed by any
  498.    number of signers in parallel. Furthermore, the syntax has a
  499.    degenerate case in which there are no signers on the content. The
  500.    degenerate case provides a means for disseminating certificates and
  501.    certificate-revocation lists.
  502.  
  503.  
  504.  
  505.  
  506. Kaliski                      Informational                      [Page 9]
  507.  
  508. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  509.  
  510.  
  511.    It is expected that the typical application of the signed-data
  512.    content type will be to represent one signer's digital signature on
  513.    content of the data content type. Another typical application will be
  514.    to disseminate certificates and certificate-revocation lists.
  515.  
  516.    The process by which signed data is constructed involves the
  517.    following steps:
  518.  
  519.         1.   For each signer, a message digest is computed on
  520.              the content with a signer-specific message-digest
  521.              algorithm. (If two signers employ the same message-digest
  522.              algorithm, then the message digest need be computed for
  523.              only one of them.) If the signer is authenticating any
  524.              information other than the content (see Section 9.2), the
  525.              message digest of the content and the other information are
  526.              digested with the signer's message digest algorithm, and
  527.              the result becomes the "message digest."
  528.  
  529.         2.   For each signer, the message digest and associated
  530.              information are encrypted with the signer's private key.
  531.  
  532.         3.   For each signer, the encrypted message digest and
  533.              other signer-specific information are collected into a
  534.              SignerInfo value, defined in Section 9.2.  Certificates and
  535.              certificate-revocation lists for each signer, and those not
  536.              corresponding to any signer, are collected in this step.
  537.  
  538.         4.   The message-digest algorithms for all the signers
  539.              and the SignerInfo values for all the signers are collected
  540.              together with the content into a SignedData value, defined
  541.              in Section 9.1.
  542.  
  543.    A recipient verifies the signatures by decrypting the encrypted
  544.    message digest for each signer with the signer's public key, then
  545.    comparing the recovered message digest to an independently computed
  546.    message digest. The signer's public key is either contained in a
  547.    certificate included in the signer information, or is referenced by
  548.    an issuer distinguished name and an issuer-specific serial number
  549.    that uniquely identify the certificate for the public key.
  550.  
  551.    This section is divided into five parts. The first part describes the
  552.    top-level type SignedData, the second part describes the per-signer
  553.    information type SignerInfo, and the third and fourth parts describe
  554.    the message-digesting and digest-encryption processes. The fifth part
  555.    summarizes compatibility with Privacy-Enhanced Mail.
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562. Kaliski                      Informational                     [Page 10]
  563.  
  564. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  565.  
  566.  
  567. 9.1 SignedData type
  568.  
  569.    The signed-data content type shall have ASN.1 type SignedData:
  570.  
  571.    SignedData ::= SEQUENCE {
  572.      version Version,
  573.      digestAlgorithms DigestAlgorithmIdentifiers,
  574.      contentInfo ContentInfo,
  575.      certificates
  576.         [0] IMPLICIT ExtendedCertificatesAndCertificates
  577.           OPTIONAL,
  578.      crls
  579.        [1] IMPLICIT CertificateRevocationLists OPTIONAL,
  580.      signerInfos SignerInfos }
  581.  
  582.    DigestAlgorithmIdentifiers ::=
  583.  
  584.      SET OF DigestAlgorithmIdentifier
  585.  
  586.    SignerInfos ::= SET OF SignerInfo
  587.  
  588.    The fields of type SignedData have the following meanings:
  589.  
  590.         o    version is the syntax version number. It shall be
  591.              1 for this version of the document.
  592.  
  593.         o    digestAlgorithms is a collection of message-digest
  594.              algorithm identifiers. There may be any number of
  595.              elements in the collection, including zero. Each
  596.              element identifies the message-digest algorithm
  597.              (and any associated parameters) under which the
  598.              content is digested for a some signer. The
  599.              collection is intended to list the message-digest
  600.              algorithms employed by all of the signers, in any
  601.              order, to facilitate one-pass signature
  602.              verification. The message-digesting process is
  603.              described in Section 9.3.
  604.  
  605.         o    contentInfo is the content that is signed. It can
  606.              have any of the defined content types.
  607.  
  608.         o    certificates is a set of PKCS #6 extended
  609.              certificates and X.509 certificates. It is intended that
  610.              the set be sufficient to contain chains from a recognized
  611.              "root" or "top-level certification authority" to all of the
  612.              signers in the signerInfos field. There may be more
  613.              certificates than necessary, and there may be certificates
  614.              sufficient to contain chains from two or more independent
  615.  
  616.  
  617.  
  618. Kaliski                      Informational                     [Page 11]
  619.  
  620. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  621.  
  622.  
  623.              top-level certification authorities. There may also be
  624.              fewer certificates than necessary, if it is expected that
  625.              those verifying the signatures have an alternate means of
  626.              obtaining necessary certificates (e.g., from a previous set
  627.              of certificates).
  628.  
  629.         o    crls is a set of certificate-revocation lists. It
  630.              is intended that the set contain information sufficient to
  631.              determine whether or not the certificates in the
  632.              certificates field are "hot listed," but such
  633.              correspondence is not necessary.  There may be more
  634.              certificate-revocation lists than necessary, and there may
  635.              also be fewer certificate-revocation lists than necessary.
  636.  
  637.         o    signerInfos is a collection of per-signer
  638.              information. There may be any number of elements in the
  639.              collection, including zero.
  640.  
  641.    Notes.
  642.  
  643.         1.   The fact that the digestAlgorithms field comes
  644.              before the contentInfo field and the signerInfos field
  645.              comes after it makes it possible to process a SignedData
  646.              value in a single pass. (Single-pass processing is
  647.              described in Section 5.)
  648.  
  649.         2.   The differences between version 1 SignedData and
  650.              version 0 SignedData (defined in PKCS #7, Version 1.4) are
  651.              the following:
  652.  
  653.                   o    the digestAlgorithms and signerInfos
  654.                        fields may contain zero elements in version 1,
  655.                        but not in version 0
  656.  
  657.                   o    the crls field is allowed in version 1,
  658.                        but not in version 0
  659.  
  660.              Except for the difference in version number, version 0
  661.              SignedData values are acceptable as version 1 values. An
  662.              implementation can therefore process SignedData values of
  663.              either version as though they were version 1 values. It is
  664.              suggested that PKCS implementations generate only version 1
  665.              SignedData values, but be prepared to process SignedData
  666.              values of either version.
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674. Kaliski                      Informational                     [Page 12]
  675.  
  676. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  677.  
  678.  
  679.         3.   In the degenerate case where there are no signers
  680.              on the content, the ContentInfo value being "signed" is
  681.              irrelevant. It is recommended in that case that the content
  682.              type of the ContentInfo value being "signed" be data, and
  683.              the content field of the ContentInfo value be omitted.
  684.  
  685. 9.2 SignerInfo type
  686.  
  687.    Per-signer information is represented in the type SignerInfo:
  688.  
  689.    SignerInfo ::= SEQUENCE {
  690.      version Version,
  691.      issuerAndSerialNumber IssuerAndSerialNumber,
  692.      digestAlgorithm DigestAlgorithmIdentifier,
  693.      authenticatedAttributes
  694.        [0] IMPLICIT Attributes OPTIONAL,
  695.      digestEncryptionAlgorithm
  696.        DigestEncryptionAlgorithmIdentifier,
  697.      encryptedDigest EncryptedDigest,
  698.      unauthenticatedAttributes
  699.        [1] IMPLICIT Attributes OPTIONAL }
  700.  
  701.    EncryptedDigest ::= OCTET STRING
  702.  
  703.    The fields of type SignerInfo have the following meanings:
  704.  
  705.         o    version is the syntax version number. It shall be
  706.              1 for this version of the document.
  707.  
  708.         o    issuerAndSerialNumber specifies the signer's
  709.              certificate (and thereby the signer's distinguished name
  710.              and public key) by issuer distinguished name and issuer-
  711.              specific serial number.
  712.  
  713.         o    digestAlgorithm identifies the message-digest
  714.              algorithm (and any associated parameters) under which the
  715.              content and authenticated attributes (if present) are
  716.              digested. It should be among those in the digestAlgorithms
  717.              field of the superior SignerInfo value. The message-
  718.              digesting process is described in Section 9.3.
  719.  
  720.         o    authenticatedAttributes is a set of attributes
  721.              that are signed (i.e., authenticated) by the signer. The
  722.              field is optional, but it must be present if the content
  723.              type of the ContentInfo value being signed is not data. If
  724.              the field is present, it must contain, at a minimum, two
  725.              attributes:
  726.  
  727.  
  728.  
  729.  
  730. Kaliski                      Informational                     [Page 13]
  731.  
  732. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  733.  
  734.  
  735.                   1.   A PKCS #9 content-type attribute having
  736.                        as its value the content type of the
  737.                        ContentInfo value being signed.
  738.  
  739.                   2.   A PKCS #9 message-digest attribute,
  740.                        having as its value the message digest
  741.                        of the content (see below).
  742.  
  743.              Other attribute types that might be useful here, such as
  744.              signing time, are also defined in PKCS #9.
  745.  
  746.         o    digestEncryptionAlgorithm identifies the digest-
  747.              encryption algorithm (and any associated parameters) under
  748.              which the message digest and associated information are
  749.              encrypted with the signer's private key. The digest-
  750.              encryption process is described in Section 9.4.
  751.  
  752.         o    encryptedDigest is the result of encrypting the
  753.              message digest and associated information with the signer's
  754.              private key.
  755.  
  756.         o    unauthenticatedAttributes is a set of attributes
  757.              that are not signed (i.e., authenticated) by the signer.
  758.              The field is optional. Attribute types that might be useful
  759.              here, such as countersignatures, are defined in PKCS #9.
  760.  
  761.    Notes.
  762.  
  763.         1.   It is recommended in the interest of PEM
  764.              compatibility that the authenticatedAttributes field be
  765.              omitted whenever the content type of the ContentInfo value
  766.              being signed is data and there are no other authenticated
  767.              attributes.
  768.  
  769.         2.   The difference between version 1 SignerInfo and
  770.              version 0 SignerInfo (defined in PKCS #7, Version 1.4) is
  771.              in the message-digest encryption process (see Section 9.4).
  772.              Only the PEM-compatible processes are different, reflecting
  773.              changes in Privacy-Enhanced Mail signature methods. There
  774.              is no difference in the non-PEM-compatible message-digest
  775.              encryption process.
  776.  
  777.              It is suggested that PKCS implementations generate only
  778.              version 1 SignedData values. Since the PEM signature method
  779.              with which version 0 is compatible is obsolescent, it is
  780.              suggested that PKCS implementations be prepared to receive
  781.              only version 1 SignedData values.
  782.  
  783.  
  784.  
  785.  
  786. Kaliski                      Informational                     [Page 14]
  787.  
  788. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  789.  
  790.  
  791. 9.3 Message-digesting process
  792.  
  793.    The message-digesting process computes a message digest on either the
  794.    content being signed or the content together with the signer's
  795.    authenticated attributes. In either case, the initial input to the
  796.    message-digesting process is the "value" of the content being signed.
  797.    Specifically, the initial input is the contents octets of the DER
  798.    encoding of the content field of the ContentInfo value to which the
  799.    signing process is applied. Only the contents octets of the DER
  800.    encoding of that field are digested, not the identifier octets or the
  801.    length octets.
  802.  
  803.    The result of the message-digesting process (which is called,
  804.    informally, the "message digest") depends on whether the
  805.    authenticatedAttributes field is present. When the field is absent,
  806.    the result is just the message digest of the content. When the field
  807.    is present, however, the result is the message digest of the complete
  808.    DER encoding of the Attributes value containted in the
  809.    authenticatedAttributes field. (For clarity: The IMPLICIT [0] tag in
  810.    the authenticatedAttributes field is not part of the Attributes
  811.    value. The Attributes value's tag is SET OF, and the DER encoding of
  812.    the SET OF tag, rather than of the IMPLICIT [0] tag, is to be
  813.    digested along with the length and contents octets of the Attributes
  814.    value.) Since the Attributes value, when the field is present, must
  815.    contain as attributes the content type and the message digest of the
  816.    content, those values are indirectly included in the result.
  817.  
  818.    When the content being signed has content type data and the
  819.    authenticatedAttributes field is absent, then just the value of the
  820.    data (e.g., the contents of a file) is digested. This has the
  821.    advantage that the length of the content being signed need not be
  822.    known in advance of the encryption process. This method is compatible
  823.    with Privacy-Enhanced Mail.
  824.  
  825.    Although the identifier octets and the length octets are not
  826.    digested, they are still protected by other means. The length octets
  827.    are protected by the nature of the message-digest algorithm since it
  828.    is by assumption computationally infeasible to find any two distinct
  829.    messages of any length that have the same message digest.
  830.    Furthermore, assuming that the content type uniquely determines the
  831.    identifier octets, the identifier octets are protected implicitly in
  832.    one of two ways: either by the inclusion of the content type in the
  833.    authenticated attributes, or by the use of the PEM-compatible
  834.    alternative in Section 9.4 which implies that the content type is
  835.    data.
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842. Kaliski                      Informational                     [Page 15]
  843.  
  844. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  845.  
  846.  
  847.    Note. The fact that the message digest is computed on part of a DER
  848.    encoding does not mean that DER is the required method of
  849.    representing that part for data transfer. Indeed, it is expected that
  850.    some implementations of this document may store objects in other than
  851.    their DER encodings, but such practices do not affect message-digest
  852.    computation.
  853.  
  854. 9.4 Digest-encryption process
  855.  
  856.    The input to the digest-encryption process--the value supplied to the
  857.    signer's digest-encryption algorithm--includes the result of the
  858.    message-digesting process (informally, the "message digest") and the
  859.    digest algorithm identifier (or object identifier). The result of the
  860.    digest-encryption process is the encryption with the signer's private
  861.    key of the BER encoding of a value of type DigestInfo:
  862.  
  863.    DigestInfo ::= SEQUENCE {
  864.      digestAlgorithm DigestAlgorithmIdentifier,
  865.      digest Digest }
  866.  
  867.    Digest ::= OCTET STRING
  868.  
  869.    The fields of type DigestInfo have the following meanings:
  870.  
  871.         o    digestAlgorithm identifies the message-digest
  872.              algorithm (and any associated parameters) under which the
  873.              content and authenticated attributes are digested. It
  874.              should be the same as the digestAlgorithm field of the
  875.              superior SignerInfo value.
  876.  
  877.         o    digest is the result of the message-digesting
  878.              process.
  879.  
  880.    Notes.
  881.  
  882.         1.   The only difference between the signature process
  883.              defined here and the signature algorithms defined in PKCS
  884.              #1 is that signatures there are represented as bit strings,
  885.              for consistency with the X.509 SIGNED macro. Here,
  886.              encrypted message digests are octet strings.
  887.  
  888.         2.   The input to the encryption process typically will
  889.              have 30 or fewer octets. If digestEncryptionAlgorithm is
  890.              PKCS #1's rsaEncryption, then this means that the input can
  891.              be encrypted in a single block as long as the length of the
  892.              RSA modulus is at least 328 bits, which is reasonable and
  893.              consistent with security recommendations.
  894.  
  895.  
  896.  
  897.  
  898. Kaliski                      Informational                     [Page 16]
  899.  
  900. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  901.  
  902.  
  903.         3.   A message-digest algorithm identifier is included
  904.              in the DigestInfo value to limit the damage resulting from
  905.              the compromise of one message-digest algorithm. For
  906.              instance, suppose an adversary were able to find messages
  907.              with a given MD2 message digest.  That adversary could then
  908.              forge a signature by finding a message with the same MD2
  909.              message digest as one that a signer previously signed, and
  910.              presenting the previous signature as the signature on the
  911.              new message.  This attack would succeed only if the signer
  912.              previously used MD2, since the DigestInfo value contains
  913.              the message-digest algorithm.  If a signer never trusted
  914.              the MD2 algorithm and always used MD5, then the compromise
  915.              of MD2 would not affect the signer. If the DigestInfo value
  916.              contained only the message digest, however, the compromise
  917.              of MD2 would affect signers that use any message-digest
  918.              algorithm.
  919.  
  920.         4.   There is potential for ambiguity due to the fact
  921.              that the DigestInfo value does not indicate whether the
  922.              digest field contains just the message digest of the
  923.              content or the message digest of the complete DER encoding
  924.              of the authenticatedAttributes field. In other words, it is
  925.              possible for an adversary to transform a signature on
  926.              authenticated attributes to one that appears to be just on
  927.              content by changing the content to be the DER encoding of
  928.              the authenticatedAttributes field, and then removing the
  929.              authenticatedAttributes field. (The reverse transformation
  930.              is possible, but requires that the content be the DER
  931.              encoding of an authenticated attributes value, which is
  932.              unlikely.) This ambiguity is not a new problem, nor is it a
  933.              significant one, as context will generally prevent misuse.
  934.              Indeed, it is also possible for an adversary to transform a
  935.              signature on a certificate or certificate-revocation list
  936.              to one that appears to be just on signed-data content.
  937.  
  938. 9.5 Compatibility with Privacy-Enhanced Mail
  939.  
  940.    Compatibility with the MIC-ONLY and MIC-CLEAR process types in PEM
  941.    occurs when the content type of the ContentInfo value being signed is
  942.    data, there are no authenticated attributes, the message-digest
  943.    algorithm is md2 or md5, and the digest-encryption algorithm is PKCS
  944.    #1's rsaEncryption. Under all those conditions, the encrypted message
  945.    digest produced here matches the one produced in PEM because:
  946.  
  947.         1.   The value input to the message-digest algorithm in
  948.              PEM is the same as in this document when there are no
  949.              authenticated attributes. MD2 and MD5 in PEM are the same
  950.              as md2 and md5.
  951.  
  952.  
  953.  
  954. Kaliski                      Informational                     [Page 17]
  955.  
  956. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  957.  
  958.  
  959.         2.   The value encrypted with the signer's private key
  960.              in PEM (as specified in RFC 1423) is the same as in this
  961.              document when there are no authenticated attributes. RSA
  962.              private-key encryption in PEM is the same as PKCS #1's
  963.              rsaEncryption.
  964.  
  965.    The other parts of the signed-data content type (certificates, CRLs,
  966.    algorithm identifiers, etc.) are easily translated to and from their
  967.    corresponding PEM components.
  968.  
  969. 10. Enveloped-data content type
  970.  
  971.    The enveloped-data content type consists of encrypted content of any
  972.    type and encrypted content-encryption keys for one or more
  973.    recipients. The combination of encrypted content and encrypted
  974.    content-encryption key for a recipient is a "digital envelope" for
  975.    that recipient. Any type of content can be enveloped for any number
  976.    of recipients in parallel.
  977.  
  978.    It is expected that the typical application of the enveloped-data
  979.    content type will be to represent one or more recipients' digital
  980.    envelopes on content of the data, digested-data, or signed-data
  981.    content types.
  982.  
  983.    The process by which enveloped data is constructed involves the
  984.    following steps:
  985.  
  986.         1.   A content-encryption key for a particular content-
  987.              encryption algorithm is generated at random.
  988.  
  989.         2.   For each recipient, the content-encryption key is
  990.              encrypted with the recipient's public key.
  991.  
  992.         3.   For each recipient, the encrypted content-
  993.              encryption key and other recipient-specific information are
  994.              collected into a RecipientInfo value, defined in Section
  995.              10.2.
  996.  
  997.         4.   The content is encrypted with the content-
  998.              encryption key. (Content encryption may require that the
  999.              content be padded to a multiple of some block size; see
  1000.              Section 10.3 for discussion.)
  1001.  
  1002.         5.   The RecipientInfo values for all the recipients
  1003.              are collected together with the encrypted content into a
  1004.              EnvelopedData value, defined in Section 10.1.
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010. Kaliski                      Informational                     [Page 18]
  1011.  
  1012. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  1013.  
  1014.  
  1015.    A recipient opens the envelope by decrypting the one of the encrypted
  1016.    content-encryption keys with the recipient's private key and
  1017.    decrypting the encrypted content with the recovered content-
  1018.    encryption key. The recipient's private key is referenced by an
  1019.    issuer distinguished name and an issuer-specific serial number that
  1020.    uniquely identify the certificate for the corresponding public key.
  1021.  
  1022.    This section is divided into four parts. The first part describes the
  1023.    top-level type EnvelopedData, the second part describes the per-
  1024.    recipient information type RecipientInfo, and the third and fourth
  1025.    parts describe the content-encryption and key-encryption processes.
  1026.  
  1027.    This content type is not compatible with Privacy-Enhanced Mail
  1028.    (although some processes it defines are compatible with their PEM
  1029.    counterparts), since Privacy-Enhanced Mail always involves digital
  1030.    signatures, never digital envelopes alone.
  1031.  
  1032. 10.1 EnvelopedData type
  1033.  
  1034.    The enveloped-data content type shall have ASN.1 type EnvelopedData:
  1035.  
  1036.    EnvelopedData ::= SEQUENCE {
  1037.      version Version,
  1038.      recipientInfos RecipientInfos,
  1039.      encryptedContentInfo EncryptedContentInfo }
  1040.  
  1041.    RecipientInfos ::= SET OF RecipientInfo
  1042.  
  1043.    EncryptedContentInfo ::= SEQUENCE {
  1044.      contentType ContentType,
  1045.      contentEncryptionAlgorithm
  1046.        ContentEncryptionAlgorithmIdentifier,
  1047.      encryptedContent
  1048.        [0] IMPLICIT EncryptedContent OPTIONAL }
  1049.  
  1050.    EncryptedContent ::= OCTET STRING
  1051.  
  1052.    The fields of type EnvelopedData have the following meanings:
  1053.  
  1054.         o    version is the syntax version number. It shall be
  1055.              0 for this version of the document.
  1056.  
  1057.         o    recipientInfos is a collection of per-recipient
  1058.              information. There must be at least one element in
  1059.              the collection.
  1060.  
  1061.         o    encryptedContentInfo is the encrypted content
  1062.              information.
  1063.  
  1064.  
  1065.  
  1066. Kaliski                      Informational                     [Page 19]
  1067.  
  1068. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  1069.  
  1070.  
  1071.    The fields of type EncryptedContentInfo have the following meanings:
  1072.  
  1073.         o    contentType indicates the type of content.
  1074.  
  1075.         o    contentEncryptionAlgorithm identifies the content-
  1076.              encryption algorithm (and any associated
  1077.              parameters) under which the content is encrypted.
  1078.              The content-encryption process is described in
  1079.              Section 10.3. This algorithm is the same for all
  1080.              recipients.
  1081.  
  1082.         o    encryptedContent is the result of encrypting the
  1083.              content. The field is optional, and if the field
  1084.              is not present, its intended value must be
  1085.              supplied by other means.
  1086.  
  1087.    Note. The fact that the recipientInfos field comes before the
  1088.    encryptedContentInfo field makes it possible to process an
  1089.    EnvelopedData value in a single pass. (Single-pass processing is
  1090.    described in Section 5.)
  1091.  
  1092. 10.2 RecipientInfo type
  1093.  
  1094.    Per-recipient information is represented in the type RecipientInfo:
  1095.  
  1096.    RecipientInfo ::= SEQUENCE {
  1097.      version Version,
  1098.      issuerAndSerialNumber IssuerAndSerialNumber,
  1099.      keyEncryptionAlgorithm
  1100.  
  1101.        KeyEncryptionAlgorithmIdentifier,
  1102.      encryptedKey EncryptedKey }
  1103.  
  1104.    EncryptedKey ::= OCTET STRING
  1105.  
  1106.    The fields of type RecipientInfo have the following meanings:
  1107.  
  1108.         o    version is the syntax version number. It shall be
  1109.              0 for this version of the document.
  1110.  
  1111.         o    issuerAndSerialNumber specifies the recipient's
  1112.              certificate (and thereby the recipient's
  1113.              distinguished name and public key) by issuer
  1114.              distinguished name and issuer-specific serial
  1115.              number.
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122. Kaliski                      Informational                     [Page 20]
  1123.  
  1124. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  1125.  
  1126.  
  1127.         o    keyEncryptionAlgorithm identifies the key-
  1128.              encryption algorithm (and any associated
  1129.              parameters) under which the content-encryption key
  1130.              is encrypted with the recipient's public key. The
  1131.              key-encryption process is described in Section
  1132.              10.4.
  1133.  
  1134.         o    encryptedKey is the result of encrypting the
  1135.              content-encryption key with the recipient's public
  1136.              key (see below).
  1137.  
  1138. 10.3 Content-encryption process
  1139.  
  1140.    The input to the content-encryption process is the "value" of the
  1141.    content being enveloped. Specifically, the input is the contents
  1142.    octets of a definite-length BER encoding of the content field of the
  1143.    ContentInfo value to which the enveloping process is applied. Only
  1144.    the contents octets of the BER encoding are encrypted, not the
  1145.    identifier octets or length octets; those other octets are not
  1146.    represented at all.
  1147.  
  1148.    When the content being enveloped has content type data, then just the
  1149.    value of the data (e.g., the contents of a file) is encrypted. This
  1150.    has the advantage that the length of the content being encrypted need
  1151.    not be known in advance of the encryption process. This method is
  1152.    compatible with Privacy-Enhanced Mail.
  1153.  
  1154.    The identifier octets and the length octets are not encrypted. The
  1155.    length octets may be protected implicitly by the encryption process,
  1156.    depending on the encryption algorithm. The identifier octets are not
  1157.    protected at all, although they can be recovered from the content
  1158.    type, assuming that the content type uniquely determines the
  1159.    identifier octets. Explicit protection of the identifier and length
  1160.    octets requires that the signed-and-enveloped-data content type be
  1161.    employed, or that the digested-data and enveloped-data content types
  1162.    be applied in succession.
  1163.  
  1164.    Notes.
  1165.  
  1166.         1.   The reason that a definite-length BER encoding is
  1167.              required is that the bit indicating whether the length is
  1168.              definite or indefinite is not recorded anywhere in the
  1169.              enveloped-data content type.  Definite-length encoding is
  1170.              more appropriate for simple types such as octet strings, so
  1171.              definite-length encoding is chosen.
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178. Kaliski                      Informational                     [Page 21]
  1179.  
  1180. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  1181.  
  1182.  
  1183.         2.   Some content-encryption algorithms assume the
  1184.              input length is a multiple of k octets, where k > 1, and
  1185.              let the application define a method for handling inputs
  1186.              whose lengths are not a multiple of k octets. For such
  1187.              algorithms, the method shall be to pad the input at the
  1188.              trailing end with k - (l mod k) octets all having value k -
  1189.              (l mod k), where l is the length of the input. In other
  1190.              words, the input is padded at the trailing end with one of
  1191.              the following strings:
  1192.  
  1193.                       01 -- if l mod k = k-1
  1194.                      02 02 -- if l mod k = k-2
  1195.                                  .
  1196.                                  .
  1197.                                  .
  1198.                    k k ... k k -- if l mod k = 0
  1199.  
  1200.              The padding can be removed unambiguously since all input is
  1201.              padded and no padding string is a suffix of another. This
  1202.              padding method is well-defined if and only if k < 256;
  1203.              methods for larger k are an open issue for further study.
  1204.  
  1205. 10.4 Key-encryption process
  1206.  
  1207.    The input to the key-encryption process--the value supplied to the
  1208.    recipient's key-encryption algorithm--is just the "value" of the
  1209.    content-encryption key.
  1210.  
  1211. 11. Signed-and-enveloped-data content type
  1212.  
  1213.    This section defines the signed-and-enveloped-data content type. For
  1214.    brevity, much of this section is expressed in terms of material in
  1215.    Sections 9 and 10.
  1216.  
  1217.    The signed-and-enveloped-data content type consists of encrypted
  1218.    content of any type, encrypted content-encryption keys for one or
  1219.    more recipients, and doubly encrypted message digests for one or more
  1220.    signers. The "double encryption" consists of an encryption with a
  1221.    signer's private key followed by an encryption with the content-
  1222.    encryption key.
  1223.  
  1224.    The combination of encrypted content and encrypted content-encryption
  1225.    key for a recipient is a "digital envelope" for that recipient. The
  1226.    recovered singly encrypted message digest for a signer is a "digital
  1227.    signature" on the recovered content for that signer.  Any type of
  1228.    content can be enveloped for any number of recipients and signed by
  1229.    any number of signers in parallel.
  1230.  
  1231.  
  1232.  
  1233.  
  1234. Kaliski                      Informational                     [Page 22]
  1235.  
  1236. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  1237.  
  1238.  
  1239.    It is expected that the typical application of the signed-and-
  1240.    enveloped-data content type will be to represent one signer's digital
  1241.    signature and one or more recipients' digital envelopes on content of
  1242.    the data content type.
  1243.  
  1244.    The process by which signed-and-enveloped data is constructed
  1245.    involves the following steps:
  1246.  
  1247.         1.   A content-encryption key for a particular content-
  1248.              encryption algorithm is generated at random.
  1249.  
  1250.         2.   For each recipient, the content-encryption key is
  1251.              encrypted with the recipient's public key.
  1252.  
  1253.         3.   For each recipient, the encrypted content-
  1254.              encryption key and other recipient-specific
  1255.              information are collected into a RecipientInfo
  1256.              value, defined in Section 10.2.
  1257.  
  1258.         4.   For each signer, a message digest is computed on
  1259.              the content with a signer-specific message-digest
  1260.              algorithm. (If two signers employ the same message-
  1261.              digest algorithm, then the message digest need be
  1262.              computed for only one of them.)
  1263.  
  1264.         5.   For each signer, the message digest and associated
  1265.              information are encrypted with the signer's
  1266.              private key, and the result is encrypted with the
  1267.              content-encryption key. (The second encryption may
  1268.              require that the result of the first encryption be
  1269.              padded to a multiple of some block size; see
  1270.              Section 10.3 for discussion.)
  1271.  
  1272.         6.   For each signer, the doubly encrypted message
  1273.              digest and other signer-specific information are
  1274.              collected into a SignerInfo value, defined in
  1275.              Section 9.2.
  1276.  
  1277.         7.   The content is encrypted with the content-
  1278.              encryption key. (See Section 10.3 for discussion.)
  1279.  
  1280.         8.   The message-digest algorithms for all the signers,
  1281.              the SignerInfo values for all the signers and the
  1282.              RecipientInfo values for all the recipients are
  1283.              collected together with the encrypted content into
  1284.              a SignedAndEnvelopedData value, defined in Section
  1285.              11.1.
  1286.  
  1287.  
  1288.  
  1289.  
  1290. Kaliski                      Informational                     [Page 23]
  1291.  
  1292. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  1293.  
  1294.  
  1295.    A recipient opens the envelope and verifies the signatures in two
  1296.    steps. First, the one of the encrypted content-encryption keys is
  1297.    decrypted with the recipient's private key, and the encrypted content
  1298.    is decrypted with the recovered content-encryption key. Second, the
  1299.    doubly encrypted message digest for each signer is decrypted with the
  1300.    recovered content-encryption key, the result is decrypted with the
  1301.    signer's public key, and the recovered message digest is compared to
  1302.    an independently computed message digest.
  1303.  
  1304.    Recipient private keys and signer public keys are contained or
  1305.    referenced as discussed in Sections 9 and 10.
  1306.  
  1307.    This section is divided into three parts. The first part describes
  1308.    the top-level type SignedAndEnvelopedData and the second part
  1309.    describes the digest-encryption process. Other types and processes
  1310.    are the same as in Sections 9 and 10.  The third part summarizes
  1311.    compatibility with Privacy-Enhanced Mail.
  1312.  
  1313.    Note. The signed-and-enveloped-data content type provides
  1314.    cryptographic enhancements similar to those resulting from the
  1315.    sequential combination of signed-data and enveloped-data content
  1316.    types. However, since the signed-and-enveloped-data content type does
  1317.    not have authenticated or unauthenticated attributes, nor does it
  1318.    provide enveloping of signer information other than the signature,
  1319.    the sequential combination of signed-data and enveloped-data content
  1320.    types is generally preferable to the SignedAndEnvelopedData content
  1321.    type, except when compatibility with the ENCRYPTED process type in
  1322.    Privacy-Enhanced Mail in intended.
  1323.  
  1324. 11.1 SignedAndEnvelopedData type
  1325.  
  1326.    The signed-and-enveloped-data content type shall have ASN.1 type
  1327.    SignedAndEnvelopedData:
  1328.  
  1329.    SignedAndEnvelopedData ::= SEQUENCE {
  1330.      version Version,
  1331.      recipientInfos RecipientInfos,
  1332.      digestAlgorithms DigestAlgorithmIdentifiers,
  1333.      encryptedContentInfo EncryptedContentInfo,
  1334.      certificates
  1335.         [0] IMPLICIT ExtendedCertificatesAndCertificates
  1336.           OPTIONAL,
  1337.      crls
  1338.        [1] IMPLICIT CertificateRevocationLists OPTIONAL,
  1339.      signerInfos SignerInfos }
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346. Kaliski                      Informational                     [Page 24]
  1347.  
  1348. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  1349.  
  1350.  
  1351.    The fields of type SignedAndEnvelopedData have the following
  1352.    meanings:
  1353.  
  1354.         o    version is the syntax version number. It shall be
  1355.              1 for this version of the document.
  1356.  
  1357.         o    recipientInfos is a collection of per-recipient
  1358.              information, as in Section 10. There must be at
  1359.              least one element in the collection.
  1360.  
  1361.         o    digestAlgorithms is a collection of message-digest
  1362.              algorithm identifiers, as in Section 9. The
  1363.              message-digesting process is the same as in
  1364.              Section 9 in the case when there are no
  1365.              authenticated attributes.
  1366.  
  1367.         o    encryptedContentInfo is the encrypted content, as
  1368.              in Section 10. It can have any of the defined
  1369.              content types.
  1370.  
  1371.         o    certificates is a set of PKCS #6 extended
  1372.              certificates and X.509 certificates, as in Section
  1373.              9.
  1374.  
  1375.         o    crls is a set of certificate-revocation lists, as
  1376.              in Section 9.
  1377.  
  1378.         o    signerInfos is a collection of per-signer
  1379.              information. There must be at least one element in
  1380.              the collection. SignerInfo values have the same
  1381.              meaning as in Section 9 with the exception of the
  1382.              encryptedDigest field (see below).
  1383.  
  1384.    Notes.
  1385.  
  1386.         1.   The fact that the recipientInfos and
  1387.              digestAlgorithms fields come before the contentInfo field
  1388.              and the signerInfos field comes after it makes it possible
  1389.              to process a SignedAndEnvelopedData value in a single pass.
  1390.              (Single-pass processing is described in Section 5.)
  1391.  
  1392.         2.   The difference between version 1
  1393.              SignedAndEnvelopedData and version 0 SignedAndEnvelopedData
  1394.              (defined in PKCS #7, Version 1.4) is that the crls field is
  1395.              allowed in version 1, but not in version 0. Except for the
  1396.              difference in version number, version 0
  1397.              SignedAndEnvelopedData values are acceptable as version 1
  1398.              values. An implementation can therefore process
  1399.  
  1400.  
  1401.  
  1402. Kaliski                      Informational                     [Page 25]
  1403.  
  1404. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  1405.  
  1406.  
  1407.              SignedAndEnvelopedData values of either version as though
  1408.              they were version 1 values. It is suggested that PKCS
  1409.              implementations generate only version 1
  1410.              SignedAndEnvelopedData values, but be prepared to process
  1411.              SignedAndEnvelopedData values of either version.
  1412.  
  1413. 11.2 Digest-encryption process
  1414.  
  1415.    The input to the digest-encryption process is the same as in Section
  1416.    9, but the process itself is different.  Specifically, the process
  1417.    involves two steps. First, the input to the process is supplied to
  1418.    the signer's digest-encryption algorithm, as in Section 9. Second,
  1419.    the result of the first step is encrypted with the content-encryption
  1420.    key.  There is no DER encoding between the two steps; the "value"
  1421.    output by the first step is input directly to the second step. (See
  1422.    Section 10.3 for discussion.)
  1423.  
  1424.    This process is compatible with the ENCRYPTED process type in
  1425.    Privacy-Enhanced Mail.
  1426.  
  1427.    Note. The purpose of the second step is to prevent an adversary from
  1428.    recovering the message digest of the content.  Otherwise, an
  1429.    adversary would be able to determine which of a list of candidate
  1430.    contents (e.g., "Yes" or "No") is the actual content by comparing the
  1431.    their message digests to the actual message digest.
  1432.  
  1433. 11.3 Compatibility with Privacy-Enhanced Mail
  1434.  
  1435.    Compatibility with the ENCRYPTED process type of PEM occurs when the
  1436.    content type of the ContentInfo value being signed and enveloped is
  1437.    data, the message-digest algorithm is md2 or md5, the content-
  1438.    encryption algorithm is DES in CBC mode, the digest-encryption
  1439.    algorithm is PKCS #1's rsaEncryption, and the key-encryption
  1440.    algorithm is PKCS #1's rsaEncryption.  Under all those conditions,
  1441.    the doubly encrypted message digest and the encrypted content
  1442.    encryption key match the ones produced in PEM because of reasons
  1443.    similar to those given in Section 9.5, as well as the following:
  1444.  
  1445.         1.   The value input to the content-encryption
  1446.              algorithm in PEM is the same as in this document.
  1447.              DES in CBC mode is the same as desCBC.
  1448.  
  1449.         2.   The value input to the key-encryption algorithm in
  1450.              PEM is the same as in this document (see Section
  1451.              10.4). RSA public-key encryption in PEM is the
  1452.              same as PKCS #1's rsaEncryption.
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458. Kaliski                      Informational                     [Page 26]
  1459.  
  1460. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  1461.  
  1462.  
  1463.         3.   The double-encryption process applied to the
  1464.              message digest in this document and in PEM are the
  1465.              same.
  1466.  
  1467.    The other parts of the signed-and-enveloped-data content type
  1468.    (certificates, CRLs, algorithm identifiers, etc.) are easily
  1469.    translated to and from their corresponding PEM components. (CRLs are
  1470.    carried in a separate PEM message.)
  1471.  
  1472. 12. Digested-data content type
  1473.  
  1474.    The digested-data content type consists of content of any type and a
  1475.    message digest of the content.
  1476.  
  1477.    It is expected that the typical application of the digested-data
  1478.    content type will be to add integrity to content of the data content
  1479.    type, and that the result would become the content input to the
  1480.    enveloped-data content type.
  1481.  
  1482.    The process by which digested-data is constructed involves the
  1483.    following steps:
  1484.  
  1485.         1.   A message digest is computed on the content with a
  1486.              message-digest algorithm.
  1487.  
  1488.         2.   The message-digest algorithm and the message
  1489.              digest are collected together with the content
  1490.              into a DigestedData value.
  1491.  
  1492.    A recipient verifies the message digest by comparing the message
  1493.    digest to an independently computed message digest.
  1494.  
  1495.    The digested-data content type shall have ASN.1 type DigestedData:
  1496.  
  1497.    DigestedData ::= SEQUENCE {
  1498.      version Version,
  1499.      digestAlgorithm DigestAlgorithmIdentifier,
  1500.      contentInfo ContentInfo,
  1501.      digest Digest }
  1502.  
  1503.    Digest ::= OCTET STRING
  1504.  
  1505.    The fields of type DigestedData have the following meanings:
  1506.  
  1507.         o    version is the syntax version number. It shall be
  1508.              0 for this version of the document.
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514. Kaliski                      Informational                     [Page 27]
  1515.  
  1516. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  1517.  
  1518.  
  1519.         o    digestAlgorithm identifies the message-digest
  1520.              algorithm (and any associated parameters) under which the
  1521.              content is digested. (The message-digesting process is the
  1522.              same as in Section 9 in the case when there are no
  1523.              authenticated attributes.)
  1524.  
  1525.         o    contentInfo is the content that is digested. It
  1526.              can have any of the defined content types.
  1527.  
  1528.         o    digest is the result of the message-digesting process.
  1529.  
  1530.    Note. The fact that the digestAlgorithm field comes before the
  1531.    contentInfo field and the digest field comes after it makes it
  1532.    possible to process a DigestedData value in a single pass.  (Single-
  1533.    pass processing is described in Section 5.)
  1534.  
  1535. 13. Encrypted-data content type
  1536.  
  1537.    The encrypted-data content type consists of encrypted content of any
  1538.    type. Unlike the enveloped-data content type, the encrypted-data
  1539.    content type has neither recipients nor encrypted content-encryption
  1540.    keys. Keys are assumed to be managed by other means.
  1541.  
  1542.    It is expected that the typical application of the encrypted-data
  1543.    content type will be to encrypt content of the data content type for
  1544.    local storage, perhaps where the encryption key is a password.
  1545.  
  1546.    The encrypted-data content type shall have ASN.1 type EncryptedData:
  1547.  
  1548.    EncryptedData ::= SEQUENCE {
  1549.      version Version,
  1550.      encryptedContentInfo EncryptedContentInfo }
  1551.  
  1552.    The fields of type EncryptedData have the following meanings:
  1553.  
  1554.         o    version is the syntax version number. It shall be
  1555.              0 for this version of the document.
  1556.  
  1557.         o    encryptedContentInfo is the encrypted content
  1558.              information, as in Section 10.
  1559.  
  1560. 14. Object identifiers
  1561.  
  1562.    This document defines seven object identifiers: pkcs-7, data,
  1563.    signedData, envelopedData, signedAndEnvelopedData, digestedData, and
  1564.    encryptedData.
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570. Kaliski                      Informational                     [Page 28]
  1571.  
  1572. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  1573.  
  1574.  
  1575.    The object identifier pkcs-7 identifies this document.
  1576.  
  1577.    pkcs-7 OBJECT IDENTIFIER ::=
  1578.      { iso(1) member-body(2) US(840) rsadsi(113549)
  1579.          pkcs(1) 7 }
  1580.  
  1581.    The object identifiers data, signedData, envelopedData,
  1582.    signedAndEnvelopedData, digestedData, and encryptedData, identify,
  1583.    respectively, the data, signed-data, enveloped-data, signed-and-
  1584.    enveloped-data, digested-data, and encrypted-data content types
  1585.    defined in Sections 8-13.
  1586.  
  1587.    data OBJECT IDENTIFIER ::= { pkcs-7 1 }
  1588.    signedData OBJECT IDENTIFIER ::= { pkcs-7 2 }
  1589.    envelopedData OBJECT IDENTIFIER ::= { pkcs-7 3 }
  1590.    signedAndEnvelopedData OBJECT IDENTIFIER ::=
  1591.       { pkcs-7 4 }
  1592.    digestedData OBJECT IDENTIFIER ::= { pkcs-7 5 }
  1593.    encryptedData OBJECT IDENTIFIER ::= { pkcs-7 6 }
  1594.  
  1595.    These object identifiers are intended to be used in the contentType
  1596.    field of a value of type ContentInfo (see Section 5). The content
  1597.    field of that type, which has the content-type-specific syntax ANY
  1598.    DEFINED BY contentType, would have ASN.1 type Data, SignedData,
  1599.    EnvelopedData, SignedAndEnvelopedData, DigestedData, and
  1600.    EncryptedData, respectively. These object identifiers are also
  1601.    intended to be used in a PKCS #9 content-type attribute.
  1602.  
  1603. Security Considerations
  1604.  
  1605.    Security issues are discussed throughout this memo.
  1606.  
  1607. Revision history
  1608.  
  1609.  
  1610.    Versions 1.0-1.3
  1611.  
  1612.    Versions 1.0-1.3 were distributed to participants in RSA Data
  1613.    Security, Inc.'s Public-Key Cryptography Standards meetings in
  1614.    February and March 1991.
  1615.  
  1616.  
  1617.    Version 1.4
  1618.  
  1619.    Version 1.4 is part of the June 3, 1991 initial public release of
  1620.    PKCS. Version 1.4 was published as NIST/OSI Implementors' Workshop
  1621.    document SEC-SIG-91-22.
  1622.  
  1623.  
  1624.  
  1625.  
  1626. Kaliski                      Informational                     [Page 29]
  1627.  
  1628. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  1629.  
  1630.  
  1631.    Version 1.5
  1632.  
  1633.    Version 1.5 incorporates several editorial changes, including updates
  1634.    to the references and the addition of a revision history. The
  1635.    following substantive changes were made:
  1636.  
  1637.         o    Section 6: CertificateRevocationLists type is
  1638.              added.
  1639.  
  1640.         o    Section 9.1: SignedData syntax is revised. The new
  1641.              version allows for the dissemination of
  1642.              certificate-revocation lists along with
  1643.              signatures. It also allows for the dissemination
  1644.              of certificates and certificate-revocation lists
  1645.              alone, without any signatures.
  1646.  
  1647.         o    Section 9.2: SignerInfo syntax is revised. The new
  1648.              version includes a message-digest encryption
  1649.              process compatible with Privacy-Enhanced Mail as
  1650.              specified in RFC 1423.
  1651.  
  1652.         o    Section 9.3: Meaning of "the DER encoding of the
  1653.              authenticatedAttributes field" is clarified as
  1654.              "the DER encoding of the Attributes value."
  1655.  
  1656.         o    Section 10.3: Padding method for content-
  1657.              encryption algorithms is described.
  1658.  
  1659.         o    Section 11.1: SignedAndEnvelopedData syntax is
  1660.              revised. The new version allows for the
  1661.              dissemination of certificate-revocation lists.
  1662.  
  1663.         o    Section 13: Encrypted-data content type is added.
  1664.              This content type consists of encrypted content of
  1665.              any type.
  1666.  
  1667.         o    Section 14: encryptedData object identifier is
  1668.              added.
  1669.  
  1670.    Supersedes June 3, 1991 version, which was also published as NIST/OSI
  1671.    Implementors' Workshop document SEC-SIG-91-22.
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682. Kaliski                      Informational                     [Page 30]
  1683.  
  1684. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  1685.  
  1686.  
  1687. Acknowledgements
  1688.  
  1689.    This document is based on a contribution of RSA Laboratories, a
  1690.    division of RSA Data Security, Inc.  Any substantial use of the text
  1691.    from this document must acknowledge RSA Data Security, Inc. RSA Data
  1692.    Security, Inc.  requests that all material mentioning or referencing
  1693.    this document identify this as "RSA Data Security, Inc. PKCS #7".
  1694.  
  1695. Author's Address
  1696.  
  1697.    Burt Kaliski
  1698.    RSA Laboratories East
  1699.    20 Crosby Drive
  1700.    Bedford, MA  01730
  1701.  
  1702.    Phone: (617) 687-7000
  1703.    EMail: burt@rsa.com
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.  
  1724.  
  1725.  
  1726.  
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738. Kaliski                      Informational                     [Page 31]
  1739.  
  1740. RFC 2315          PKCS #7: Crytographic Message Syntax        March 1998
  1741.  
  1742.  
  1743. Full Copyright Statement
  1744.  
  1745.    Copyright (C) The Internet Society (1998).  All Rights Reserved.
  1746.  
  1747.    This document and translations of it may be copied and furnished to
  1748.    others, and derivative works that comment on or otherwise explain it
  1749.    or assist in its implementation may be prepared, copied, published
  1750.    and distributed, in whole or in part, without restriction of any
  1751.    kind, provided that the above copyright notice and this paragraph are
  1752.    included on all such copies and derivative works.  However, this
  1753.    document itself may not be modified in any way, such as by removing
  1754.    the copyright notice or references to the Internet Society or other
  1755.    Internet organizations, except as needed for the purpose of
  1756.    developing Internet standards in which case the procedures for
  1757.    copyrights defined in the Internet Standards process must be
  1758.    followed, or as required to translate it into languages other than
  1759.    English.
  1760.  
  1761.    The limited permissions granted above are perpetual and will not be
  1762.    revoked by the Internet Society or its successors or assigns.
  1763.  
  1764.    This document and the information contained herein is provided on an
  1765.    "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
  1766.    TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
  1767.    BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
  1768.    HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
  1769.    MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790.  
  1791.  
  1792.  
  1793.  
  1794. Kaliski                      Informational                     [Page 32]
  1795.  
  1796.