[lamps] Re: [COSE] Re: Thoughts about the Context Information in COSE

Phillip Hallam-Baker <ietf@hallambaker.com> Thu, 26 September 2024 22:00 UTC

Return-Path: <hallam@gmail.com>
X-Original-To: spasm@ietfa.amsl.com
Delivered-To: spasm@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 0E4F1C14F5F6; Thu, 26 Sep 2024 15:00:08 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -6.654
X-Spam-Level:
X-Spam-Status: No, score=-6.654 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4nijEuqkl1N2; Thu, 26 Sep 2024 15:00:06 -0700 (PDT)
Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id CB756C14F5E9; Thu, 26 Sep 2024 15:00:06 -0700 (PDT)
Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-7124352ecc3so836293a34.3; Thu, 26 Sep 2024 15:00:06 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727388006; x=1727992806; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=E+yfHqlEfKnrRrrFFSqZdlE+38InWhOvXoH0vfirmXs=; b=OMCXaxyEawfXFZPj20obFrC2mxPIg3KmJmaUqH7WGXYkQ5gS5qOIYB0JmlCdZYAmp0 cRB5IZIUpVTngaeeCiPQ6lWke8JNBaeKF+jtKLRXcF8uC7eIMgowbdg7mnpjmsX493L8 WHZgoaBGRj0aiZ2Jb2g/fapAPy5F6uu4vbgHtX5HhO4AQIsu6d5fYsB352iBdj1ElcCh QSD5b8KFJ3PleNs84gHfIkbs9+pLS3YSDljQZ+gY3R5eUYPAWq7ldigMwms58Zn6kFcn s20iDdILzbDW2czh3/X32N6fQFU+1BxyIwJEX/GO3NDsXMn6EWnpMs5wfcuRvYy6jNtl jESA==
X-Forwarded-Encrypted: i=1; AJvYcCV5aCMWJyuHQHJxtLdMYpZ0TVlQPVoU3GXgFDLgDJbPFYY+l9UqmAZV1O8mD/0sBIpzNGYT@ietf.org
X-Gm-Message-State: AOJu0YzvgCOZKopdRMEzFUvqQLh3Djbif7G5EqWRh0uGm4iS9eMwIstf MU0A9jOGb265nM6886iVkJ9k3UcnFgG1uzlEgaUxMjc+xAHw8+H8uTbiJSDspwu66p4huotixUv VGHc24atHSU1b9eJ3WJ/pAXy2+RggyDuP
X-Google-Smtp-Source: AGHT+IEOSUQp+eDbktDPaS/Ebx2KTyZeMHItAdE2oxOdAc+aLnizTltiubtScUjx2G7ga4LemS8rBL24LxGRln0Bvfk=
X-Received: by 2002:a05:6830:4186:b0:713:ce15:d4d1 with SMTP id 46e09a7af769-714fbf0cc18mr796199a34.26.1727388005899; Thu, 26 Sep 2024 15:00:05 -0700 (PDT)
MIME-Version: 1.0
References: <00d801db08dc$3b4dbfa0$b1e93ee0$@gmx.net> <CAN8C-_K+=sQ6d+n1JZ13zv4u8rdo2W8G4Rf=iYpxeifD06m-XA@mail.gmail.com> <CAEEbLAYkJPQO2kf3QkVS=CNJzEsiE88s_7e8=SmPQBs2Z6bASA@mail.gmail.com> <ZunkcXuBBlmfF6K6@LK-Perkele-VII2.locald> <CAEEbLAZN3g_se2oJhVp7=mrWyUSh83W41c2w5oYfFdHDBejZxQ@mail.gmail.com> <ZuvSW4JZtrOQbzPP@LK-Perkele-VII2.locald> <CAEEbLAYrDEATtisVaO9xZN-fg9wjj=h3ohrRi61LS1CJ22=z-Q@mail.gmail.com> <CAMm+LwjZub6_qCCwgsGh-dAqiPvy_Xmhh+Hmaqmnd-b8fYZF+g@mail.gmail.com> <CAEEbLAb9id6d=MvGCVT8BAFd_XHgpmS5s_Pc2OC1gy89bWtiSQ@mail.gmail.com> <CAMm+LwgAkrmorQQaojA-sNaArOaTACQajvN3c1ODzNQVZESb8Q@mail.gmail.com> <CAEEbLAbNj+TkTGUbWit7p_YuGqUFjLM9oCmQ5uvXh_kYD7LXQg@mail.gmail.com>
In-Reply-To: <CAEEbLAbNj+TkTGUbWit7p_YuGqUFjLM9oCmQ5uvXh_kYD7LXQg@mail.gmail.com>
From: Phillip Hallam-Baker <ietf@hallambaker.com>
Date: Thu, 26 Sep 2024 17:59:54 -0400
Message-ID: <CAMm+LwhYM748YZv8N22g_zO4az15ddt9P7t=_0tNy-=7-i2TuA@mail.gmail.com>
To: Sophie Schmieg <sschmieg@google.com>
Content-Type: multipart/alternative; boundary="0000000000007b2c4b06230cdc03"
Message-ID-Hash: GHK4OQ5QAQYYUYBIG4E7EJTBCP6ZBCHS
X-Message-ID-Hash: GHK4OQ5QAQYYUYBIG4E7EJTBCP6ZBCHS
X-MailFrom: hallam@gmail.com
X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-spasm.ietf.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header
CC: SPASM <SPASM@ietf.org>, Ilari Liusvaara <ilariliusvaara@welho.com>, cose@ietf.org
X-Mailman-Version: 3.3.9rc4
Precedence: list
Subject: [lamps] Re: [COSE] Re: Thoughts about the Context Information in COSE
List-Id: This is the mail list for the LAMPS Working Group <spasm.ietf.org>
Archived-At: <https://mailarchive.ietf.org/arch/msg/spasm/8gv8ZNSn6MgUIMuvlwv_-q0CFSE>
List-Archive: <https://mailarchive.ietf.org/arch/browse/spasm>
List-Help: <mailto:spasm-request@ietf.org?subject=help>
List-Owner: <mailto:spasm-owner@ietf.org>
List-Post: <mailto:spasm@ietf.org>
List-Subscribe: <mailto:spasm-join@ietf.org>
List-Unsubscribe: <mailto:spasm-leave@ietf.org>

Now sign the same message with two signatures over the same data without
hashing the message  a second time.

ML-DSAhash is a hack so that CMS and other existing ASN.1 things can be
made to do the right thing without a digest substitution attack possibility.

The context should be "COSE" or "JOSE" so that someone can't take a COSE
signature and slap it on a JOSE message. But it should be the same string
for a given envelope format. And then the application gets to fill in the
COSE/JOSE manifest with its own semantic separation distinguisher.


There is a similar issue that arises with Concat KDF [NIST.800-56A] which
does patch what could be a possible hole in certain applications. I have
spent the past three hours convincing myself that I do not need Concat KDF
[NIST.800-56A] and can leave PartyUInfo/PartyVInfo empty for my application
because they are a mechanism for credential binding which I do explicitly
through a different mechanism when I need it.

These are now very large systems and some parts are 35 or more years old.


On Thu, Sep 26, 2024 at 1:12 PM Sophie Schmieg <sschmieg@google.com> wrote:

> You can use the comment on Algorithm 7, line 6. "message representative
> that may optionally be computed in a different cryptographic module"
> The hash function is SHAKE256(SHAKE256(pk, 64) || 0x00 || 0x00 || m, 64),
> which already takes care of the context (by setting it to the empty string,
> as it always should be, since that is a question for the protocol, not the
> signature scheme). While you can argue that that breaks the cryptographic
> module boundary (even if explicitly allowed by NIST's comment), the same is
> true for HashML-DSA, with Algorithm 5 taking an arbitrary size message and
> a hash function, not the hash of the message itself, so computing it
> outside of the cryptographic module similarly breaks module boundaries,
> this time without that being explicitly allowed by the standard.
>
> On Thu, Sep 26, 2024 at 9:28 AM Phillip Hallam-Baker <ietf@hallambaker.com>
> wrote:
>
>> Right now, we are discussing this in LAMPS, JOSE, COSE, OpenPGP and the
>> NIST-PQC list. Which is really not a good way to go about things because
>> this is a systems architecture issue and what we really need is for all the
>> groups to arrive at the same approach so that we avoid issues of semantic
>> substitution, digest substitution, etc. So added LAMPS because the
>> conclusion is relevant there.
>>
>>
>> The Issue is that ML-DSA-pure doesn't use SHAKE(content), it uses
>> SHAKE(0x00 + content + context). And there is no way to divide that
>> operation securely with half taking place inside the HSM and half taking
>> place outside.
>>
>> From the NIST reference code:
>>
>>         //5
>>         int i = 0;
>>         bytes[i++] = 0;
>>         if (context is null) {
>>             bytes[i++] = 0;
>>             }
>>         else {
>>             bytes[i++] = (byte)clen;
>>             Array.Copy(context, 0, bytes, i, length);
>>             i += clen;
>>             }
>>
>> Since my code is designed to support multiple signatures over the same
>> content under different signature algorithms, being told which algorithm to
>> use doesn't work for me because I am only hashing once.
>>
>> The NIST division is actually rather clever because it allows the HSM to
>> have a bit more intelligence than in the past because the body is always at
>> least a manifest. And the HSM can be configured to only sign specific types
>> of content with specific authorization and log what it did.
>>
>>
>> ML-DSA-hash is really only relevant for CMS/PKCS#7. Everything else we do
>> either has a manifest already (COSE, JOSE, OpenPGP, XML-Signature) or is
>> short enough that it can be done inside the HSM (except CRLs without
>> distribution points) . And most of the things that are short enough are
>> exactly the sort of thing we would want an HSM to validate and log.
>>
>> So for example, I might have my HSM configured in such a way that it will
>> only sign an object with the "PKIX Certificate" extension, if and only if
>> TBSCertificate is well formatted DER and the requisite set of proofs (proof
>> of right, validation assertion, CT insertion proof) have been supplied.
>>
>> And yes, that might be more complexity than you would want in a
>> FIPS-140-4 module which is why you might have a second module acting as a
>> front end to a 'signer only' module.
>>
>>
>> Soi we should define a set of context strings to separate the COSE, JOSE,
>> XML-Signature, SAML, Certificate, CRL, etc. domains which are all atomic
>> strings with no parameters.
>>
>> CMS is special in that we have all this infrastructure already committed
>> based on the RSA approach and so there we should probably allow the context
>> string to be a prefix followed by the application specific context
>> separator.
>>
>> So two new IANA registries. One for signature format context strings, one
>> for CMS application contexts.
>>
>>
>> I will write up a draft proposing this and a second draft proposing
>> adding the ML-DSA hash digest to Ed-448 and Ed-25519 so we can use all the
>> algorithms in the same fashion with the same API.
>>
>>
>>
>> On Thu, Sep 26, 2024 at 11:25 AM Sophie Schmieg <sschmieg@google.com>
>> wrote:
>>
>>> SHAKE256 supports streaming. It's a sponge construction, you only need
>>> to keep the sponge as state, and can stream in the data.
>>>
>>> On Wed, Sep 25, 2024 at 4:24 PM Phillip Hallam-Baker <
>>> ietf@hallambaker.com> wrote:
>>>
>>>> ML-DSAhash is designed to support streaming. That isn't necessary if
>>>> you only work at the packet layer but you certainly don't want to sign 1TB
>>>> files using the SHAKE256 construct and pushing all that data into a
>>>> FIPS-140-3 HSM.
>>>>
>>>> For COSE and JOSE, ML-DSAhash is unnecessary because you are always
>>>> signing over a manifest. So if you are going to sign a 1TB file, you hash
>>>> with your favorite digest, specify the digest value and digest algorithm ID
>>>> in the SighedHeader field and then sign over that. That is exactly what
>>>> ML-DSA-pure is intended for.
>>>>
>>>> For other systems, the reason we need ML-DSAhash is that we have a lot
>>>> of APIs that are built around the RSA interface of 'sign digest value and
>>>> OID'. And ML-DSA needs to support a mode where it is a direct drop in
>>>> substitute.
>>>>
>>>> If the digest algorithm identifier is omitted, there is a possibility
>>>> of a digest substitution attack. So it is an important consideration.
>>>>
>>>>
>>>> The other concern is semantic substitution and there there are two
>>>> separate issues, one is crafting a CMS package so that it is a legitimate
>>>> COSE package. Which seems far fetched but so did gifs that render as
>>>> jpgs...
>>>>
>>>> The second is crafting a COSE package for application A so that it is
>>>> accepted as legitimate by application B. This is a much more plausible
>>>> attack.
>>>>
>>>>
>>>> If every signature algorithm supported context, we could use the
>>>> signature context slot for both. Since they don't and since taking data
>>>> provided by the signer and putting it into the signature envelope directly
>>>> is 'icky' to say the least, the better way to do this in a standardized
>>>> envelope that has a manifest is to use the context string to identify the
>>>> envelope format, 'XML-DIG-SIG', 'JOSE', 'COSE', etc. and make a slot in the
>>>> envelope manifest for application level separation.
>>>>
>>>> This is actually done in the SAML assertion format which has an
>>>> Audience field for the express purpose of semantic binding to the terms and
>>>> conditions of the signature.
>>>>
>>>> CMS/PKCS#7 is really rooted in the way we did things 30 years ago and
>>>> the signature context is really the only option.
>>>>
>>>>
>>>> This may seem unnecessarily complex but it is much easier to block this
>>>> class of attack completely than to spend time auditing every application to
>>>> see if there is a problem.
>>>>
>>>> The way we form the key agreement output doing ECDH (P-256 etc) is a
>>>> lot more verbose than X25519 because it binds to the keys used for the key
>>>> agreement. I am really not at all sure what the advantage of doing it that
>>>> way when your key names are 'Alice' and 'Bob' which is what we have in the
>>>> RFC but that's what we did and maybe we should have done X25519 exactly the
>>>> same way so it was the same...
>>>>
>>>>
>>>> On Wed, Sep 25, 2024 at 5:19 PM Sophie Schmieg <sschmieg=
>>>> 40google.com@dmarc.ietf.org> wrote:
>>>>
>>>>> Note that there are two options for prehashing with ML-DSA: You can
>>>>> use the comment on algorithm 7, line 6 and use the hash function
>>>>> SHAKE256(SHAKE256(pk, 64) || 0x00 || 0x00 || m, 64), in which case it works
>>>>> exactly the same as ECDSA (with a known hash function). I.e. the hash can
>>>>> be computed elsewhere and transmitted to a signing oracle, producing a
>>>>> signature that looks the same as if no prehashing has taken place, so from
>>>>> the verifiers perspective this choice does not matter. Or you use the (in
>>>>> my opinion strictly worse) option of using HashML-KEM, where you prehash
>>>>> with say SHA512. In that case, the verifier needs to know that you did so.
>>>>> By calling that algorithm HashML-DSA-SHA512 (and putting the algorithm
>>>>> information in the public key), you can communicate that, but honestly I do
>>>>> not see any reason to do so that would not be better served by just using
>>>>> ML-DSA, prehashing with the SHAKE256 construction mentioned.
>>>>>
>>>>> On Thu, Sep 19, 2024 at 12:34 AM Ilari Liusvaara <
>>>>> ilariliusvaara@welho.com> wrote:
>>>>>
>>>>>> On Wed, Sep 18, 2024 at 01:50:20PM -0700, Sophie Schmieg wrote:
>>>>>> > On Tue, Sep 17, 2024 at 1:20 PM Ilari Liusvaara <
>>>>>> ilariliusvaara@welho.com>
>>>>>> > wrote:
>>>>>> >
>>>>>> > >
>>>>>> > > In case of signed JWT, the very first thing that needs to be
>>>>>> parsed out
>>>>>> > > is "iss".
>>>>>> > >
>>>>>> > > ... Which is a bit problematic.
>>>>>> >
>>>>>> > Yeah, I somewhat intentionally did not mention iss, because yeah,
>>>>>> it is a
>>>>>> > bit problematic, and forces the "authorization decision passed down
>>>>>> to
>>>>>> > downstream system" as a pattern.
>>>>>>
>>>>>> Dedicated JWT validation code could callback to map issuer name to
>>>>>> keyset. But that runs into bit annoying function color issues in many
>>>>>> laguages (fortunately synchronous factorization does not seem to be
>>>>>> too
>>>>>> bad)...
>>>>>>
>>>>>>
>>>>>> > > Unfortunately, that runs into problems with pre-hashing.
>>>>>> > >
>>>>>> > > Currently, that only gets problematic for RSA, but supporting
>>>>>> pre-hashed
>>>>>> > > ML-DSA would also introduce the problem there.
>>>>>> > >
>>>>>> > > ECDSA has essentially fixed prehash (ok), and EdDSA in COSE/JOSE
>>>>>> does
>>>>>> > > not support pre-hashing.
>>>>>> > >
>>>>>> >
>>>>>> > I'm not sure I follow. The hash function used with a signature
>>>>>> scheme is
>>>>>> > part of the signature scheme as well, and so the public key should
>>>>>> allow
>>>>>> > you to derive that information. Several common public key
>>>>>> serialization
>>>>>> > formats unfortunately do not properly include the hash function,
>>>>>> maybe that
>>>>>> > is what you are referring to? Or do you have a system where the
>>>>>> decision
>>>>>> > which hash function to use is taken independently of the decision
>>>>>> of which
>>>>>> > key to use? In that case, yeah you have lots of incompatibilities,
>>>>>> > especially in the case of ML-DSA where the hash function is fixed to
>>>>>> > SHAKE256, and has to be prefixed with a hash of the public key, but
>>>>>> I'm not
>>>>>> > sure why the algorithm has to be part of the token to enable this
>>>>>> use case.
>>>>>>
>>>>>> Because public keys frequently fail to include hash function, one
>>>>>> would
>>>>>> have to deduce the hash function from the key itself.
>>>>>>
>>>>>> That works in practice for ECDSA, EdDSA and HSS-LMS. But it does not
>>>>>> work for RSA (then there is the PSS versus PKCS#1 v1.5 stuff...).
>>>>>>
>>>>>> For ML-DSA, supporting pre-hash mode breaks deducing hash function.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> -Ilari
>>>>>>
>>>>>> _______________________________________________
>>>>>> COSE mailing list -- cose@ietf.org
>>>>>> To unsubscribe send an email to cose-leave@ietf.org
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> Sophie Schmieg | Information Security Engineer | ISE Crypto |
>>>>> sschmieg@google.com
>>>>>
>>>>> _______________________________________________
>>>>> COSE mailing list -- cose@ietf.org
>>>>> To unsubscribe send an email to cose-leave@ietf.org
>>>>>
>>>>
>>>
>>> --
>>>
>>> Sophie Schmieg | Information Security Engineer | ISE Crypto |
>>> sschmieg@google.com
>>>
>>>
>
> --
>
> Sophie Schmieg | Information Security Engineer | ISE Crypto |
> sschmieg@google.com
>
>