<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="../rfc2629xslt/rfc2629.xslt"?>
<?rfc symrefs="yes"?>
<?rfc toc="yes"?>

<!ENTITY RFC2119 PUBLIC '' 'bibxml/reference.RFC.2119.xml'>
<!ENTITY RFC2634 PUBLIC '' 'bibxml/reference.RFC.2634.xml'>
<!ENTITY RFC5035 PUBLIC '' 'bibxml/reference.RFC.5035.xml'>
<!ENTITY RFC5280 PUBLIC '' 'bibxml/reference.RFC.5280.xml'>
<!ENTITY RFC5652 PUBLIC '' 'bibxml/reference.RFC.5652.xml'>
<!ENTITY RFC5912 PUBLIC '' 'bibxml/reference.RFC.5912.xml'>
<!ENTITY schaad-hash PUBLIC '' 'bibxml3/reference.I-D.draft-schaad-smime-hash-experiment-01.xml'>
<!ENTITY algorithm-asn PUBLIC '' 'ForDraft/algorithm.incl'>

<rfc ipr="trust200902" docName="draft-schaad-smime-algorithm-attribute-04" category="std">
  <front>
    <title abbrev="Algorithm Attribute">Signer Info Algorithm Protection Attribute</title>
    <author initials="J." surname="Schaad" fullname="Jim Schaad">
      <organization>Soaring Hawk Consulting</organization>
      <address>
	<postal>
	  <street>PO Box 675</street>
	  <city>Gold Bar</city>
	  <region>WA</region>
	  <code>98251</code>
	</postal>
	<email>ietf@augustcellars.com</email>
      </address>
    </author>
    <date/>
    <abstract>
      <t>A new attribute is defined that allows for protection of the digest and signature algorithm structures in an authenticated data or a signer info structure.  Using the attribute includes the algorithm definition information in the integrity protection process.</t>
    </abstract>
  </front>
  <middle>
    <section title="Introduction">
      <t>Over past 20 years since the original definition of CMS as PKCS #7 in 1991, the number of signature and digest algorithms has grown from a small number to a fairly substantial number and the trend is expected to accelerate in the future.  This has led to a new possible attack that was not addressed at the time, the algorithm substitution attack.  In the algorithm substitution attack, the attacker looks for collisions not only within the same algorithm as the creator of the message used, but in all algorithms that have similar characteristics.  Thus if the creator of the message used SHA-1 as the digest algorithm to hash the content, an attacker could look for collisions in SHA-1, SHA-0 or RIPEMD-160 if those algorithms were in use at the time the message was created.  Once a collision had been found, the attacker would change both the message content and the digest identifier in the message.</t>

      <t>If one looks at parameterized algorithms, then attacker could also potentially attack the set of parameters that are chosen by the message creator.  We currently have RSASSA-PSS as a parameterized signature algorithm and a number different hash algorithms have been proposed (such as randomized hashing in <xref target="RANDOM-HASH"/>).  Part of the security proof for these algorithms assumes that the attacker does not have the ability to select the parameters, although in the case of a choice of digest algorithms it may influence them.</t>

      <t>Algorithm substitution attacks are of greater interest to situations where messages are expected to be long-lived than for very short term messages.  It is much simpler to prove what the current set of constraints of a system are in the present time than it is for a great deal of time in the past.  Thus this attribute is expected to be of greater interest in the timestamping and archiving communities than in the S/MIME community.</t>

      <t>In the current definition of <xref target="CMS"/>, there are fields that are not protected for either signature or authentication validation.  In this document a new signed or authenticated attribute is defined which permits these fields to be protected as part of the validation process.</t>

      <t>Using the  SignerInfo structure from CMS, let's look at each of the fields in that structure and discuss what is and is not protected by the signature.  The ASN.1 is included here for convenience.  (The analysis of AuthenticatedData is similar.)</t>
<figure>
<artwork>
      SignerInfo ::= SEQUENCE {
        version CMSVersion,
        sid SignerIdentifier,
        digestAlgorithm DigestAlgorithmIdentifier,
        signedAttrs [0] IMPLICIT SignedAttributes OPTIONAL,
        signatureAlgorithm SignatureAlgorithmIdentifier,
        signature SignatureValue,
        unsignedAttrs [1] IMPLICIT UnsignedAttributes OPTIONAL }

</artwork>
</figure>
      <t>
      <list style="hanging">
        <t hangText="version">is not protected by the signature.  Many implementations of CMS today just ignore the value of this field.  If the structure decodes then this is considered sufficient to continue processing.  Using most decoders on the market the value of this field does not control how the decoding is  processed.</t>
        <t hangText="sid">can be protected by the use of either version of the signing certificate authenticated attribute.  SigningCertificateV2 is defined in <xref target="RFC5035"/>.  SigningCertificate is defined in <xref target="ESS-BASE"/>.  In addition to allowing for the protection of the signer identifier, the specific certificate is protected by including a hash of the certificate to be used for validation.</t>
        <t hangText="digestAlgorithm">the digest algorithm used has been implicitly protected by the fact that CMS has only defined one digest algorithm for each hash value length. (The algorithm RIPEM-160 was never standardized).  If newer digest algorithms are defined where there are multiple algorithms for a given hash length, or where parameters are defined for a specific algorithm, this implicit protection will no longer exist.</t>
        <t hangText="signedAttributes">are directly protected by the signature when they are present.  The DER encoding of this value is what is hashed for the signature computation.</t>
        <t hangText="signatureAlgorithm">has been protected by implication in the past.  

The use of an RSA public key implied that the RSA v 1.5 signature algorithm was being used.  The hash algorithm and this fact could be checked by the internal padding defined.  This is no longer true with the addition of the RSA-PSS signature algorithms.

The use of a DSA public key implied the SHA-1 hash algorithm as that was the only possible hash algorithm and the DSA was the public signature algorithm.  This is longer true with the addition of the SHA2 signature algorithms.
</t>

        <t hangText="signature">is not directly protected by any other value unless a counter signature is present.  However this represents the cryptographically computed value that protects the rest of the signature information.</t>
        <t hangText="unsignedAttrs">is not protected by the signature value.  It is also explicitly designed not to be protected by the signature value.</t>
      </list></t>

      <t>As can be seen above, the digestAlgorithm and signatureAlgorithm fields have been indirectly rather than explicitly protected in the past.  With new algorithms that have been or are being defined this will no longer be the case.  This document defines and describes a new attribute that will explicitly protect these fields along with the macAlgorithm field of the AuthenticatedData structure.</t>
      <section title="Notation">
	      <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in <xref target="RFC2119"/>.</t>
      </section>
      </section>
		<section title="Attribute Structure">
      <t>The following defines the algorithm protection attribute:</t>
<t>The algorithm-protection attribute has the ASN.1 type CMSAlgorithmProtection:</t>
      <figure>
        <artwork>
    aa-cmsAlgorithmProtection ATTRIBUTE ::= {
        TYPE CMSAlgorithmProtection
        IDENTIFIED BY { id-aa-CMSAlgorithmProtection }
    }
</artwork></figure>
      <t>The following object identifier identifies the algorithm-protection attribute:</t>
      <figure>
        <artwork>
    id-aa-CMSAlgorithmProtection OBJECT IDENTIFIER ::= { iso(1)
         member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs9(9) 52 }
</artwork>
      </figure>
<t>The algorithm-protection attribute uses the following ASN.1 type:</t>
<figure><artwork>

   CMSAlgorithmProtection ::= SEQUENCE {
       digestAlgorithm         DigestAlgorithmIdentifier,
       signatureAlgorithm  [1] SignatureAlgorithmIdentifier OPTIONAL,
       macAlgorithm        [2] MessageAuthenticationCodeAlgorithm 
                                        OPTIONAL
   }
   (WITH COMPONENTS { signatureAlgorithm PRESENT,
                      macAlgorithm ABSENT } |
    WITH COMPONENTS { signatureAlgorithm ABSENT,
                      macAlgorithm PRESENT })
</artwork>
      </figure>
      <t>The fields are defined as follows:</t>

      <t>
      <list style="hanging">
        <t hangText="digestAlgorithm">contains a copy of the SignerInfo.digestAlgorithm field or the AuthenticatedData.digestAlgorithm field including any parameters associated with it.</t>
        <t hangText="signatureAlgorithm">contains a copy of the signature algorithm identifier and any parameters associated with it (SignerInfo.signatureAlgorithm).  This field is only populated if the attribute is placed in a SignerInfo.signedAttrs sequence.</t>
        <t hangText="macAlgorithm">contains a copy of the message authentication code algorithm identifier and any parameters associated with it (AuthenticatedData.macAlgorithm).  This field is only populated if the attribute is placed in an AuthenticatedData.authAttrs sequence.</t>
      </list></t>

      <t>Exactly one of signatureAlgorithm and macAlgorithm SHALL be present.</t>
      <t>An algorithm-protection attribute MUST have a single attribute value, even though the syntax is defined as a SET OF AttributeValue.  There MUST NOT be zero or multiple instances of AttributeValue present.</t>

      <t>The algorithm-protection attribute MUST be a signed attribute or an authenticated attribute;  it MUST NOT be an unsigned attribute, an unauthenticated attribute or an unprotected attribute.</t>

      <t>The SignedAttributes and AuthAttributes syntax are each defined as a SET of Attributes.  The SignedAttributes in a signerInfo MUST include only one instance of the algorithm protection attribute.  Similarly, the AuthAttributes in an AuthenticatedData MUST include only one instance of the algorithm protection attribute.</t>
		</section>

		<section title="Verification Process">
      <t>The exact verification process depends on the structure being dealt with.</t>
      <t>When doing comparisons of the fields, a field whose value is a default value and one which is explicitly provided MUST compare as equivalent.  It is not required that a field which is absent in one case and present in another case be compared as equivalent.  (This means that an algorithm identifier with absent parameters and one with NULL parameters are not expected to compare as equivalent.)</t>
      <section title="Signed Data Verification Changes">
<t>If a CMS validator supports this attribute, the following additional verification steps MUST be performed:</t>
<t>1.  The SignerInfo.digestAlgorithm field MUST be compared to the digestAlgorithm field in the attribute.  If the fields are not the same (modulo encoding) then signature validation MUST fail.</t>
<t>2.  The SignerInfo.signatureAlgorithm field MUST be compared to the signatureAlgorithm field in the attribute.  If the fields are not the same (modulo encoding) then the signature validation MUST fail.</t>
      </section>
      <section title="Authenticated Data Verification Changes">
<t>If a CMS validator supports this attribute, the following additional verification steps MUST be performed:</t>
<t>1.  The AuthenticatedData.digestAlgorithm field MUST be compared to the digestAlgorithm field in the attribute.  If the fields are not same (modulo encoding) then authentication MUST fail.</t>
<t>2.  The AuthenticatedData.macAlgorithm field MUST be compared to the macAlgorithm field in the attribute.  If the fields are not the same (modulo encoding) then the authentication MUST fail.</t>
      </section>
		</section>
                <section title="IANA Considerations"><t>There are no IANA considerations.  All identifiers are assigned out of the S/MIME OID arc.</t>
                  </section>

		<section title="Security Considerations">
			<t>This document is designed to address the security issue of algorithm substitutions of the algorithms used by the validator.  At this time there is no known method to exploit this type of attack.  If the attack could be successful, then either a weaker algorithm could be substituted for a stronger algorithm or the parameters could be modified by an attacker to change the behavior of the hashing algorithm used.  (One example would be changing the initial parameter value for <xref target="XOR-HASH"/>.)</t>
			<t>The attribute defined in this document is to be placed in a location that is protected by the signature or message authentication code.  This attribute does not provide any additional security if placed in an un-signed or un-authenticated location.</t>
		</section>
	</middle>
	<back>
	  <references title="Normative References">
            &RFC2119;
            &RFC2634;
            &RFC5035;
            &RFC5652;
            &RFC5912;
	  </references>

          <references title="Informational References">

            &schaad-hash;
            <reference anchor="RANDOM-HASH">
              <front>
                <title>Randomized Hashing: Secure Digital Signatures without Collision Resistance</title>
                <author initials='S.' surname="Halevi"/>
                <author initials='H.' surname="Krawczyk"/>
              </front>
              <seriesInfo name="IETF" value='74'/>
              <format type='html' target='http://www.ietf.org/proceedings/74/slides/saag-4/saag-4_files/frame.htm'/>
            </reference>
          </references>

	  <section title="ASN.1 Module">
&algorithm-asn;
		</section>
	</back>
</rfc>
