Re: [pkix] Clarification on "zero" hash value in SigPolicyHash (CAdES)

Andrea Caccia <andrea.caccia@studiocaccia.com> Tue, 16 July 2019 15:21 UTC

Return-Path: <andrea.caccia@studiocaccia.com>
X-Original-To: pkix@ietfa.amsl.com
Delivered-To: pkix@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 7439212076B for <pkix@ietfa.amsl.com>; Tue, 16 Jul 2019 08:21:40 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.899
X-Spam-Level:
X-Spam-Status: No, score=-1.899 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=aruba.it
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oeuYQRtw-_zA for <pkix@ietfa.amsl.com>; Tue, 16 Jul 2019 08:21:37 -0700 (PDT)
Received: from smtpcmd04131.aruba.it (smtpcmd04131.aruba.it [62.149.158.131]) by ietfa.amsl.com (Postfix) with ESMTP id DE171120757 for <pkix@ietf.org>; Tue, 16 Jul 2019 08:21:36 -0700 (PDT)
Received: from acmac1.station ([2.34.126.254]) by smtpcmd04.ad.aruba.it with bizsmtp id dTMa2000m5VT1yS01TMaFP; Tue, 16 Jul 2019 17:21:35 +0200
From: Andrea Caccia <andrea.caccia@studiocaccia.com>
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\))
Date: Tue, 16 Jul 2019 17:21:33 +0200
References: <20190712200549.2kgzjqodj5afnxlt@nmhq.net> <20190716145808.x6slwzijkvdkodyg@nmhq.net>
To: pkix@ietf.org
In-Reply-To: <20190716145808.x6slwzijkvdkodyg@nmhq.net>
Message-Id: <A307DBA2-DE9F-455F-9711-047119D41751@studiocaccia.com>
X-Mailer: Apple Mail (2.3445.104.11)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aruba.it; s=a1; t=1563290495; bh=MJKhuOq7R4w83liuGCGCXqYefAvl/kXguDWcM004aZs=; h=From:Content-Type:Mime-Version:Subject:Date:To; b=jiCgZtu8dkWbS8f300VpXoaesNWjpJYh4tMLQiRxPucDNf9TaFhrM6bGyR9d2OzTv Mu7nF38qmVfBGueDmc2alrSc1gpOLmOEPgtTZP5u6aGgR6LtO8eElKFPKtZYIlycoq 7YQ1tEHJ6PWAg67yqPBIjgLjoTJe4hLNqypVRlSeGwmD9kn66EzMo1s++cn2sQbagk anhjci3rmcyZra1UJy4urZTnupmtxzlJVQuFJZTHaT4vGPPFxjzFqIo2spvdScv/Kg xdXyEyHaoAbYYcObyr1qDvpkV7ZsNvyJwRB0vI/X8xK/iR/jsnm5cYf/+5kvoxys0y uIqjtI6H7dU0Q==
Archived-At: <https://mailarchive.ietf.org/arch/msg/pkix/1ZuDB70h8_EY4DQcn1N3v15iCHQ>
Subject: Re: [pkix] Clarification on "zero" hash value in SigPolicyHash (CAdES)
X-BeenThere: pkix@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: PKIX Working Group <pkix.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/pkix>, <mailto:pkix-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/pkix/>
List-Post: <mailto:pkix@ietf.org>
List-Help: <mailto:pkix-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/pkix>, <mailto:pkix-request@ietf.org?subject=subscribe>
X-List-Received-Date: Tue, 16 Jul 2019 15:21:41 -0000

Dear Niklas and all,
option 3 seems the original intention, also looking at the "shall be set to all zero" in Annex K. 
Being the correct interpretation of the text does not imply also to be the best option of course...

Regards,
Andrea


> Il giorno 16 lug 2019, alle ore 16:58, Niklas Matthies <pkix@nmhq.net>; ha scritto:
> 
> It now occurred to me that sigPolicyHash field being optional in ETSI TS 101 733 V1.6.3 (2005-09) probably was discovered to be a mistake because (1) it introduces a parsing ambiguity with sigPolicyQualifiers, as both are optional SEQUENCEs, and (2) because it broke compatibility with existing implementation.
> 
> So it would seem that the zero hash value was introduced as a workaround to still be able to have an optional hash, syntactically masquerading as a real hash, and thus maintaining compatibility with the earlier versions at least on the ASN.1 level. Then the note about backwards compatibility would not be referring to the support of "zero" hash values, but to the fact that keeping the sigPolicyHash field mandatory for backwards compatibility reasons leaves no other choice than to use a "compatible" encoding for a missing hash value.
> 
> This interpretation would favor option 3 (using the length implied by the hash algorithm), as this arguably causes the least disruption for pre-V1.6.3 (and RFC-3126-based) implementations.
> 
> Niklas
> 
> 
> On Fri 2019-07-12 at 22:05h, Niklas Matthies wrote on pkix:
>> Dear all,
>> 
>> I hope that someone can shed some light on the definition and origin of the special-case "zero" hash value for SigPolicyHash in CAdES. The main question is what exactly constitutes a "zero" hash value on the ASN.1 level.
>> 
>> In the most current CAdES specification, ETSI EN 319 122-1 V1.1.1 (2016-04), the zero hash value is described as follows (clause 5.2.9.1, page 20):        The sigPolicyHash field shall contain the identifier of the hash    algorithm and the hash of the value of the signature policy.
>>  The hashValue within the sigPolicyHash may be set to zero to    indicate that the policy hash value is not known.
>> 
>>      NOTE: The use of a zero-sigPolicyHash value is to ensure        backwards compatibility with earlier versions of ETSI TS 101 733 [1].
>> 
>> The ASN.1 definition of SigPolicyHash is as follows:
>> 
>>  SignaturePolicyId ::= SEQUENCE {
>>      sigPolicyId SigPolicyId,
>>      sigPolicyHash SigPolicyHash,
>>      sigPolicyQualifiers SEQUENCE SIZE (1..MAX) OF            SigPolicyQualifierInfo OPTIONAL
>>  }
>> 
>>  SigPolicyHash ::= OtherHashAlgAndValue
>> 
>>  OtherHashAlgAndValue ::= SEQUENCE {
>>      hashAlgorithm   AlgorithmIdentifier,
>>      hashValue       OtherHashValue }
>> 
>>  OtherHashValue ::= OCTET STRING
>> 
>> The question is what constitutes a "zero" hash value. A zero-length octet string? Any octet string where all octets are zero? Is the length of the octet string relevant, e.g. can or should it match the length implied by the hash algorithm?
>> 
>> I spent some time going back the history of the standards to find the "earlier version" relevant for the note about backwards compatibility, however that search was inconclusive.
>> 
>> All versions of ETSI TS 101 733 from the latest V2.2.1 (2013-04) back to V1.7.4 (2008-07) include the following note, which had a second sentence added:
>> 
>>      NOTE: The use of a zero-sigPolicyHash value is to ensure        backwards compatibility with earlier versions of the
>>      current document. If sigPolicyHash is zero, then the hash        value should not be checked against the calculated hash value        of the signature policy.
>> 
>> Confusingly, this now talks about sigPolicyHash being zero (whatever that would mean), not about the hashValue field within sigPolicyHash.
>> 
>> The same text appears in RFC 5126 (February 2008).
>> 
>> The previous version ETSI TS 101 733 V1.7.3 (2007-01) is the first version to talk about a zero hash value, and the note is just one sentence again:
>> 
>>  The hashValue within the sigPolicyHash max [sic] be set to zero to    indicate that the policy hash value is not known.
>> 
>>      NOTE: The use of zero policy hash value is to ensure backward        compatibility with earlier versions of the current document.
>> 
>> In addition, the annex states the following:
>> 
>>  Annex K (informative): Changes from the previous version
>> 
>>      • if the hash of the signature policy is unknown, then, by        convention, the sigPolicyHash shall be set to all zero
>> 
>> Here again, the annex talks about sigPolicyHash being set to zero, not the hashValue within sigPolicyHash.
>> 
>> On the RFC side, the same note first appears in https://tools.ietf.org/html/draft-ietf-smime-cades-02 (May 2007), and the sentence above (without the note) first appears in https://tools.ietf.org/html/draft-ietf-smime-cades-01 (April 2006).
>> 
>> In the previous ETSI TS 101 733 V1.6.3 (2005-09), the sigPolicyHash field is optional (which is mandatory in all previous and all subsequent versions), and the following note is included:
>> 
>>      NOTE: In the previous version of TS 101 733 (i.e. version 1.5.1)        sigPolicyHash was mandatory. Implementations requiring to be        backward compatible with version 1.5.1 and previous versions        of the current document MUST include SigPolicyHash.
>> 
>> None of the previous versions, from ETSI TS 101 733 V1.5.1 (2003-12) back to ETSI TS 101 733 V1.2.2 (2000-12) (the earliest version available at https://www.etsi.org/deliver/etsi_ts/101700_101799/101733/), as well as RFC 3126 (September 2001), do mention anything about zero hash values.
>> 
>> So it remains unclear to which specification backwards compatiblity is intended. The point where the wording about zero hash values was introduced suggests that this may be about V1.6.3, where the
>> sigPolicyHash field was optional. However, it's not clear how a "zero" hash value would achieve compatibility with the case of a missing sigPolicyHash field.
>> 
>> I would appreciate any clarification on that topic.
>> 
>> Kind regards,
>> Niklas
>> 
>> _______________________________________________
>> pkix mailing list
>> pkix@ietf.org
>> https://www.ietf.org/mailman/listinfo/pkix
> 
> _______________________________________________
> pkix mailing list
> pkix@ietf.org
> https://www.ietf.org/mailman/listinfo/pkix