<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE rfc SYSTEM "rfc2629-xhtml.ent">

<rfc xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902" docName="draft-ietf-lamps-cms-update-alg-id-protect-05" number="8933" updates="5652" obsoletes="" submissionType="IETF" category="std" consensus="true" xml:lang="en" tocInclude="true" sortRefs="true" symRefs="true" version="3">

  <front>
    <title abbrev="CMS Algorithm Identifier Protection">Update to the Cryptographic Message Syntax (CMS) for Algorithm Identifier Protection</title>
    <seriesInfo name="RFC" value="8933"/>
    <author initials="R." surname="Housley" fullname="Russ Housley">
      <organization abbrev="Vigil Security">Vigil Security, LLC</organization>
      <address>
        <postal>
          <street>516 Dranesville Road</street>
          <city>Herndon</city>
	  <region>VA</region>
          <code>20170</code>
          <country>United States of America</country>
        </postal>
        <email>housley@vigilsec.com</email>
      </address>
    </author>
    <date year="2020" month="October"/>
    <area>Security</area>
    <workgroup>LAMPS</workgroup>

<keyword>digitally sign</keyword>
<keyword>authenticate</keyword>
<keyword>algorithm identifier integrity</keyword>

    <abstract>
      <t>This document updates the Cryptographic Message Syntax (CMS) specified in RFC 5652 to ensure that algorithm identifiers in signed-data and authenticated-data content types are adequately protected.</t>
    </abstract>
  </front>
  <middle>
    <section anchor="intro" numbered="true" toc="default">
      <name>Introduction</name>
      <t>This document updates the Cryptographic Message Syntax (CMS) <xref target="RFC5652" format="default"/> to ensure that algorithm identifiers in signed-data and authenticated-data content types are adequately protected.</t>
      <t>The CMS signed-data content type <xref target="RFC5652" format="default"/>, unlike X.509 certificates <xref target="RFC5280" format="default"/>, can be vulnerable to algorithm substitution attacks.  In an algorithm substitution attack, the attacker changes either the algorithm identifier or the parameters associated with the algorithm identifier to change the verification process used by the recipient.  The X.509 certificate structure protects the algorithm identifier and the associated parameters by signing them.</t>
      <t>In an algorithm substitution attack, the attacker looks for a different algorithm that produces the same result as the algorithm used by the originator.  As an example, if the signer of a message used SHA-256 <xref target="SHS" format="default"/> as the digest algorithm to hash the message content, then the attacker looks for a weaker hash algorithm that produces a result that is of the same length.  The attacker's goal is to find a different message that results in the same hash value, which is called a cross-algorithm collision.  Today, there are many hash functions that produce 256-bit results.  One of them may be found to be weak in the future.</t>
      <t>Further, when a digest algorithm produces a larger result than is
      needed by a digital signature algorithm, the digest value is reduced to
      the size needed by the signature algorithm.  This can be done both by
      truncation and modulo operations, with the simplest being
      straightforward truncation.  In this situation, the attacker needs to
      find a collision with the reduced digest value.  As an example, if the
      message signer uses SHA-512 <xref target="SHS" format="default"/> as the
      digest algorithm and the Elliptic Curve Digital Signature Algorithm (ECDSA)
      with the P-256 curve <xref target="DSS" format="default"/> as the
      signature algorithm, then the attacker needs to find a collision with
      the first half of the digest.</t>
      <t>Similar attacks can be mounted against parameterized algorithm
      identifiers.  

When randomized hash functions are employed, such as the example in <xref target="RFC6210" format="default"/>, the algorithm identifier parameter includes a random value that can be manipulated by an attacker looking for collisions.  Some other algorithm identifiers include complex parameter structures, and each value provides another opportunity for manipulation by an attacker.</t>
      <t>This document makes two updates to CMS to provide protection for the
      algorithm identifier.  First, it mandates a convention followed by many
      implementations by requiring the originator to use the same hash
      algorithm to compute the digest of the message content and the digest of
      signed attributes.  Second, it recommends that the originator include
      the CMSAlgorithmProtection attribute <xref target="RFC6211"
      format="default"/>.</t>
    </section>
    <section anchor="terms" numbered="true" toc="default">
      <name>Terminology</name>
        <t>
    The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>", "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL
    NOT</bcp14>", "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>", "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
    "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are to be interpreted as
    described in BCP&nbsp;14 <xref target="RFC2119"/> <xref target="RFC8174"/> 
    when, and only when, they appear in all capitals, as shown here.
        </t>
    </section>

    <section anchor="required-use-the-same-hash-algorithm" numbered="true"
	     toc="default">
      <name>Required Use of the Same Hash Algorithm</name>
      <t>This section updates <xref target="RFC5652" format="default"/> to require the originator to use the same hash algorithm to compute the digest of the message content and the digest of signed attributes.</t>
      <section anchor="rfc-5652-section-53" numbered="true" toc="default">
        <name>RFC 5652, Section 5.3</name>
        <t>Change the paragraph describing the digestAlgorithm as follows:</t>
        <t>OLD:</t>
<blockquote>
          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 the content
   together with the signed attributes using the process described in Section <xref target="RFC5652" sectionFormat="bare" section="5.4"/>.  The message digest algorithm <bcp14>SHOULD</bcp14> be among those
   listed in the digestAlgorithms field of the associated SignerData.
   Implementations <bcp14>MAY</bcp14> fail to validate signatures that use a digest
   algorithm that is not included in the SignedData digestAlgorithms
   set.</blockquote>
        
        <t>NEW:</t>
          <blockquote>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 the content
   together with the signedAttrs using the process described in Section <xref target="RFC5652" sectionFormat="bare" section="5.4"/>.  The message digest algorithm <bcp14>SHOULD</bcp14> be among those
   listed in the digestAlgorithms field of the associated SignerData.
   If the signedAttrs field is present in the SignerInfo, then the same
   digest algorithm <bcp14>MUST</bcp14> be used to compute both the digest of the
   SignedData encapContentInfo eContent, which is carried in the
   message-digest attribute, and the digest of the DER-encoded
   signedAttrs, which is passed to the signature algorithm.
   Implementations <bcp14>MAY</bcp14> fail to validate signatures that use a
   digest algorithm that is not included in the SignedData
   digestAlgorithms set.</blockquote>
        
      </section>
      <section anchor="rfc-5652-section-54" numbered="true" toc="default">
        <name>RFC 5652, Section 5.4</name>
        <t>Add the following paragraph as the second paragraph in Section <xref target="RFC5652" sectionFormat="bare" section="5.4"/>.</t>
        <t>ADD:</t>
          <blockquote>When the signedAttrs field is present, the same digest algorithm
   <bcp14>MUST</bcp14> be used to compute the digest of the encapContentInfo
   eContent OCTET STRING, which is carried in the message-digest
   attribute and the digest of the collection of attributes that
   are signed.</blockquote>
      </section>
      <section anchor="rfc-5652-section-56" numbered="true" toc="default">
        <name>RFC 5652, Section 5.6</name>
        <t>Change the paragraph discussing the signed attributes as follows:</t>
        <t>OLD:</t>
          <blockquote>The recipient <bcp14>MUST NOT</bcp14> rely on any message digest values computed
   by the originator.  If the SignedData signerInfo includes
   signedAttributes, then the content message digest <bcp14>MUST</bcp14> be
   calculated as described in Section <xref target="RFC5652" sectionFormat="bare" section="5.4"/>.  For the signature to be
   valid, the message digest value calculated by the recipient <bcp14>MUST</bcp14>
   be the same as the value of the messageDigest attribute included
   in the signedAttributes of the SignedData signerInfo.</blockquote>
        <t>NEW:</t>
          <blockquote>The recipient <bcp14>MUST NOT</bcp14> rely on any message digest values computed
   by the originator.  If the SignedData signerInfo includes the
   signedAttrs field, then the content message digest <bcp14>MUST</bcp14> be
   calculated as described in Section <xref target="RFC5652" sectionFormat="bare" section="5.4"/> using the same digest
   algorithm to compute the digest of the encapContentInfo eContent
   OCTET STRING and the message-digest attribute.  For the signature
   to be valid, the message digest value calculated by the recipient
   <bcp14>MUST</bcp14> be the same as the value of the messageDigest attribute
   included in the signedAttrs field of the SignedData signerInfo.</blockquote>
      </section>
      <section anchor="backward-compatibility-considerations" numbered="true" toc="default">
        <name>Backward Compatibility Considerations</name>
        <t>The new requirement introduced above might lead to incompatibility with an implementation that allowed different digest algorithms to be used to compute the digest of the message content and the digest of signed attributes.  The signatures produced by such an implementation when two different digest algorithms are used will be considered invalid by an implementation that follows this specification.  However, most, if not all, implementations already require the originator to use the same digest algorithm for both operations.</t>
      </section>
      <section anchor="timestamp-compatibility-considerations" numbered="true" toc="default">
        <name>Timestamp Compatibility Considerations</name>
        <t>The new requirement introduced above might lead to compatibility
	issues for timestamping systems when the originator does not wish to
	share the message content with the Time Stamping Authority (TSA) <xref
	target="RFC3161" format="default"/>.  In this situation, the
	originator sends a TimeStampReq to the TSA that includes a
	MessageImprint, which consists of a digest algorithm identifier and a
	digest value. The TSA then uses the originator-provided digest in the MessageImprint.</t>
        <t>When producing the TimeStampToken, the TSA <bcp14>MUST</bcp14> use the same digest algorithm to compute the digest of the encapContentInfo eContent, which is an OCTET STRING that contains the TSTInfo, and the message-digest attribute within the SignerInfo.</t>
        <t>To ensure that TimeStampToken values that were generated before this update remain valid, no requirement is placed on a TSA to ensure that the digest algorithm for the TimeStampToken matches the digest algorithm for the MessageImprint embedded within the TSTInfo.</t>
      </section>
    </section>
    <section anchor="recommended-inclusion-of-the-cmsalgorithmprotection-attribute" numbered="true" toc="default">
      <name>Recommended Inclusion of the CMSAlgorithmProtection Attribute</name>
      <t>This section updates <xref target="RFC5652" format="default"/> to recommend that the originator include the CMSAlgorithmProtection attribute <xref target="RFC6211" format="default"/> whenever signed attributes or authenticated attributes are present.</t>
      <section anchor="rfc-5652-section-14" numbered="true" toc="default">
        <name>RFC 5652, Section 14</name>
        <t>Add the following paragraph as the eighth paragraph in Section <xref target="RFC5652" sectionFormat="bare" section="14"/>:</t>
        <t>ADD:</t>
          <blockquote>While there are no known algorithm substitution attacks today,
   the inclusion of the algorithm identifiers used by the originator
   as a signed attribute or an authenticated attribute makes such an
   attack significantly more difficult.  Therefore, the originator
   of a signed-data content type that includes signed attributes
   <bcp14>SHOULD</bcp14> include the CMSAlgorithmProtection attribute <xref target="RFC6211" format="default"/> as
   one of the signed attributes.  Likewise, the originator of an
   authenticated-data content type that includes authenticated
   attributes <bcp14>SHOULD</bcp14> include the CMSAlgorithmProtection attribute
   <xref target="RFC6211" format="default"/> as one of the authenticated attributes.</blockquote>
        
      </section>
    </section>
    <section anchor="iana-considerations" numbered="true" toc="default">
      <name>IANA Considerations</name>
      <t>This document has no IANA actions.</t>
    </section>
    <section anchor="security-considerations" numbered="true" toc="default">
      <name>Security Considerations</name>
      <t>The security properties of the CMS <xref target="RFC5652" format="default"/> signed-data and
authenticated-data content types are updated to offer protection for
algorithm identifiers, which makes algorithm substitution attacks
significantly more difficult.</t>
      <t>For the signed-data content type, the improvements specified in this
document force an attacker to mount a hash algorithm substitution attack
on the overall signature, not just on the message digest of the
encapContentInfo eContent.</t>
      <t>Some digital signature algorithms have prevented hash function
      substitutions by including a digest algorithm identifier as an input to
      the signature algorithm.  As discussed in <xref target="HASHID"
      format="default"/>, such a "firewall" may not be effective or even
      possible with newer signature algorithms.  For example,
      RSASSA-PKCS1-v1_5 <xref target="RFC8017" format="default"/> protects the
      digest algorithm identifier, but RSASSA-PSS <xref target="RFC8017"
      format="default"/> does not.  Therefore, it remains important that a
      signer have a way to signal to a recipient which digest algorithms are
      allowed to be used in conjunction with the verification of an overall
      signature.  This signaling can be done as part of the specification of
      the signature algorithm in an X.509v3 certificate extension <xref
      target="RFC5280" format="default"/> or some other means.  The Digital
      Signature Standard (DSS) <xref target="DSS" format="default"/> takes the
      first approach by requiring the use of an "approved" one-way hash
      algorithm.</t>
      <t>For the authenticated-data content type, the improvements specified in
this document force an attacker to mount a MAC algorithm substitution
attack, which is difficult because the attacker does not know the
authentication key.</t>
      <t>The CMSAlgorithmProtection attribute <xref target="RFC6211" format="default"/> offers protection for the algorithm identifiers used in the signed-data and authenticated-data content types.  However, no protection is provided for the algorithm identifiers in the enveloped-data, digested-data, or encrypted-data content types.  Likewise, the CMSAlgorithmProtection attribute provides no protection for the algorithm identifiers used in the authenticated-enveloped-data content type defined in <xref target="RFC5083" format="default"/>.  A mechanism for algorithm identifier protection for these content types is work for the future.</t>
    </section>
  </middle>
  <back>
    <references>
      <name>References</name>
      <references>
        <name>Normative References</name>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.3161.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.5652.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.6211.xml"/>
      </references>
      <references>
        <name>Informative References</name>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.5083.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.5280.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.6210.xml"/>
        <xi:include href="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8017.xml"/>

        <reference anchor="SHS">
          <front>
            <title>Secure Hash Standard (SHS)</title>
            <author>
              <organization>National Institute of Standards and Technology (NIST)</organization>
            </author>
            <date year="2015" month="August"/>
          </front>
            <seriesInfo name="FIPS" value="180-4"/>
	    <seriesInfo name="DOI" value="10.6028/NIST.FIPS.180-4"/>
        </reference>

        <reference anchor="DSS">
          <front>
            <title>Digital Signature Standard (DSS)</title>
            <author>
              <organization>National Institute of Standards and Technology (NIST)</organization>
            </author>
            <date year="2013" month="July"/>
          </front>
            <seriesInfo name="FIPS" value="186-4"/>
	    <seriesInfo name="DOI" value="10.6028/NIST.FIPS.186-4"/>
        </reference>

        <reference anchor="HASHID">
          <front>
            <title>On Hash Function Firewalls in Signature Schemes</title>
            <author initials="B." surname="Kaliski" fullname="Burton S. Kaliski, Jr.">
              <organization/>
            </author>
            <date year="2002" month="February"/>
          </front>
            <seriesInfo name="DOI" value="10.1007/3-540-45760-7_1"/>
            <seriesInfo name="Lecture Notes in Computer Science," value="Volume 2271"/>
        </reference>
      </references>
    </references>
    <section anchor="acknowledgements" numbered="false" toc="default">
      <name>Acknowledgements</name>
      <t>Many thanks to <contact fullname="Jim Schaad"/> and <contact
      fullname="Peter Gutmann"/>; without knowing it, they motivated me to
      write this document.  Thanks to <contact fullname="Roman Danyliw"/>,
      <contact fullname="Ben Kaduk"/>, and <contact fullname="Peter Yee"/> for
      their careful review and editorial suggestions.</t>
    </section>
  </back>
</rfc>
