Signature #2: No CBOR | Re: Formalizing the HTTP State Tokens proposal.

Kari Hurtta <hurtta-ietf@elmme-mailer.org> Mon, 20 May 2019 04:32 UTC

Return-Path: <ietf-http-wg-request+bounce-httpbisa-archive-bis2juki=lists.ie@listhub.w3.org>
X-Original-To: ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com
Delivered-To: ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 76204120122 for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Sun, 19 May 2019 21:32:12 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.899
X-Spam-Level:
X-Spam-Status: No, score=-2.899 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.001, MAILING_LIST_MULTI=-1, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
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 mHjRehGhpaJf for <ietfarch-httpbisa-archive-bis2Juki@ietfa.amsl.com>; Sun, 19 May 2019 21:32:10 -0700 (PDT)
Received: from frink.w3.org (frink.w3.org [IPv6:2603:400a:ffff:804:801e:34:0:38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 6B215120086 for <httpbisa-archive-bis2Juki@lists.ietf.org>; Sun, 19 May 2019 21:32:10 -0700 (PDT)
Received: from lists by frink.w3.org with local (Exim 4.89) (envelope-from <ietf-http-wg-request@listhub.w3.org>) id 1hSZvW-0001Br-UT for ietf-http-wg-dist@listhub.w3.org; Mon, 20 May 2019 04:29:30 +0000
Resent-Date: Mon, 20 May 2019 04:29:30 +0000
Resent-Message-Id: <E1hSZvW-0001Br-UT@frink.w3.org>
Received: from titan.w3.org ([2603:400a:ffff:804:801e:34:0:4c]) by frink.w3.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from <khurtta@welho.com>) id 1hSZvS-0001Ay-Pg for ietf-http-wg@listhub.w3.org; Mon, 20 May 2019 04:29:26 +0000
Received: from welho-filter2.welho.com ([83.102.41.24]) by titan.w3.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from <khurtta@welho.com>) id 1hSZvO-0007Cf-M2 for ietf-http-wg@w3.org; Mon, 20 May 2019 04:29:26 +0000
Received: from localhost (localhost [127.0.0.1]) by welho-filter2.welho.com (Postfix) with ESMTP id 606DEC3F24; Mon, 20 May 2019 07:28:59 +0300 (EEST)
X-Virus-Scanned: Debian amavisd-new at pp.htv.fi
Received: from welho-smtp3.welho.com ([IPv6:::ffff:83.102.41.86]) by localhost (welho-filter2.welho.com [::ffff:83.102.41.24]) (amavisd-new, port 10024) with ESMTP id Ynu0p4du8FGm; Mon, 20 May 2019 07:28:58 +0300 (EEST)
Received: from kasvihuone.keh.iki.fi (89-27-39-95.bb.dnainternet.fi [89.27.39.95]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by welho-smtp3.welho.com (Postfix) with ESMTPS id DF29B2308; Mon, 20 May 2019 07:28:51 +0300 (EEST)
In-Reply-To: <20190328194046.GA26916@LK-Perkele-VII>
References: <20190328194046.GA26916@LK-Perkele-VII>
To: HTTP Working Group <ietf-http-wg@w3.org>
Date: Mon, 20 May 2019 07:28:51 +0300
From: Kari Hurtta <hurtta-ietf@elmme-mailer.org>
CC: Mike West <mkwst@google.com>, Ilari Liusvaara <ilariliusvaara@welho.com>, Kari Hurtta <hurtta-ietf@elmme-mailer.org>
X-Mailer: ELM [version ME+ 2.5 PLalpha49+]
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset="UTF-8"
Message-Id: <20190520042859.606DEC3F24@welho-filter2.welho.com>
Received-SPF: none client-ip=83.102.41.24; envelope-from=khurtta@welho.com; helo=welho-filter2.welho.com
X-W3C-Hub-Spam-Status: No, score=-4.6
X-W3C-Hub-Spam-Report: AWL=0.988, BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_NONE=0.001, W3C_AA=-1, W3C_IRA=-1, W3C_WL=-1
X-W3C-Scan-Sig: titan.w3.org 1hSZvO-0007Cf-M2 4e67e5b575b5a17f01dac0d5357196d9
X-Original-To: ietf-http-wg@w3.org
Subject: Signature #2: No CBOR | Re: Formalizing the HTTP State Tokens proposal.
Archived-At: <https://www.w3.org/mid/20190520042859.606DEC3F24@welho-filter2.welho.com>
Resent-From: ietf-http-wg@w3.org
X-Mailing-List: <ietf-http-wg@w3.org> archive/latest/36648
X-Loop: ietf-http-wg@w3.org
Resent-Sender: ietf-http-wg-request@w3.org
Precedence: list
List-Id: <ietf-http-wg.w3.org>
List-Help: <https://www.w3.org/Mail/>
List-Post: <mailto:ietf-http-wg@w3.org>
List-Unsubscribe: <mailto:ietf-http-wg-request@w3.org?subject=unsubscribe>

HTTP State Tokens
https://tools.ietf.org/html/draft-west-http-state-tokens-00


Ilari Liusvaara:
> - The request signing mechansims looks like one that would break if
>   there is some CDN or reverse proxy in the path that adds a header
>   or a few (sometimes with some non-standard one in the mix). Or is it
>   expected that all CDNs or reverse proxies on path for application
>   using this mechanism can rewrite the MAC?


On my post "Signature" (
<20190504134512.38AF24F94E@welho-filter4.welho.com>
https://lists.w3.org/Archives/Public/ietf-http-wg/2019AprJun/0112.html )

I suggested to exclude certain listed header fields and header fields
listed in the Connection header field.

But that is not enough.  It is better that middleman
does not rewrite signature.



Considering my "Typical request for origin"

---------------------------------------------
       [ browser ]
             
            ⇓ https

  [ TLS termination and load balancing ]

     ⇓ http                 ⇓ http

   [ cache ]               [ cache ]

      ⇓ http                  ⇓ http

  [ -----  reapplying TLS --------- ]

              ⇓  https

  [ TLS termination and load balancing ]

      ⇓ http                 ⇓ http

   [ origin web server ]  [ origin web server ]

----------------------

In here many places can add

X-Frowarded-For
X-Forwarded-Proto
Forwarded                  (RFC 7239)
X-Forwarded-Host
X-Forwarded-Port
Via
CDN-Loop                   (RFC 8586)

header fields to request.  And perhaps some others.

Therefore the list of signed header field's names need to be added
to Sec-Http-State request header field.

Using is CBOR was justified with:

3.2.  CBOR representation of exchange response headers
https://tools.ietf.org/html/draft-yasskin-http-origin-signed-responses-05#section-3.2

|   To sign an exchange's response headers, they need to be serialized
|   into a byte string.  Since intermediaries and distributors
|   (Appendix A.2) might rearrange, add, or just reserialize headers, we
|   can't use the literal bytes of the headers as this serialization.


When  the list of signed header field's names are on
Sec-Http-State request header field usage of CBOR
is NOT justified.

Order of header fields is given on the list of signed header
field's names on Sec-Http-State request header field. This gives
both spelling (lowercase or not) and order of header fields.
There is nothing what using of CBOR adds.

Other details need to be specified anyway. For example:

|   o  The byte string ':status' to the byte string containing the
|      response's 3-digit status code, and
|
|   o  For each response header field, the header field's lowercase name
|      as a byte string to the header field's value as a byte string.

These was not given by CBOR.

There is some requirements:

The list of signed header field's name must not include
names of header fields where header field name occurs
several times on request.

The list of signed header field's names must not include
names of header fields which occur on Connection header field.

Also following header field's names must not be included
to the list of signed header field's names:

  *  Connection 

  *  Any header field name starting with Proxy-

  *  Keep-Alive

  *  Trailer

  *  Transfer-Encoding

  *  Upgrade

  *  Forwarded

  *  Any header field name starting with X-Frowarded-

  *  Via

  *  CDN-Loop


If the  list of signed header field's names on
Sec-Http-State request header field includes non-existing
header field, this header field is just skipped
when calculating signature. These header field
names effectively works as "don't add" list, because
adding of them to request on transit changes signature.

If he  list of signed header field's names on
Sec-Http-State request header field includes header fields
which have more than one occurrence, FAIL calculating
of signature.


So

5.2.  Generate a request's signature
https://tools.ietf.org/html/draft-west-http-state-tokens-00#section-5.2


 ⇒

--------

   || indicates catenation
   0  indicates octet 0 (ASCII NUL).

   Note that redirection causes  Sec-Http-State request header
   field and signature to be recalculated.

   This operates with request, which is httpRequest on
   4.5. HTTP-network-or-cache fetch on Fetch standard.

   Given a request, a base64-encoded token value, and a key:

   1. Generate decimal nonce value for request ( this may be implemented
      by storing nonce value to HTTP State Token for request's
      URL and incrementing that nonce. 

   2. Store generated nonce value as "nonce" for return triple.

   3. Let "serialized-request" to be

      ":method:" || request's method || 0 ||
      ":token:" || base64-encoded token value || 0 ||
      ":url:" || request's current URL || 0 ||
      :nonce:" || request's decimal nonce value || 0

   4. Let "signed list" to be header field names
      from request's  header list, excluding

      o header fields mentioned on Connection: header field

      o header fields which have more than one occurrence
        on request's  header list

      o Connection 

      o Any header field name starting with Proxy-

     o Keep-Alive

     o Trailer

     o Transfer-Encoding

     o Upgrade

     o Forwarded

     o Any header field name starting with X-Frowarded-

     o Via

     o CDN-Loop
  
     [TBD some other?]

   5. [TBD: Add possible  "don't add" header field names
            to "signed list". ]

   6. For each "field name" in  "signed list"

      1. Retrieve "header value" of ""field name" from
         request's  header list

      2. If  "header value" not found, skip next substeps

      3. If more that one  "header value" found, fail this algorithm

      4. Append "field name" value ||  ":" || "header value" value || 0
         to "serialized-request"

         Note that "serialized-request" uses field name spelling
	 from "signed list" and not header field name spelling
	 from request's  header list.

         Specially, when checking signature, order and
	 spelling of header field names from "signed-fields"
         is used.

   7. Let "signed-fields" to be values from "signed list"
      with comma as separator.

   8. Store "signed-fields" as  "signed-fields" for return triple.

   9. Let "sig" to be result  of computing HMAC-SHA256 [RFC2104] over
       "serialized-request".

   10. Store "sig" as "sig" for return triple.

   11. Return triple ( "sig", "signed-fields", "nonce" ).

-----

If there is retries on

  4.6. HTTP-network fetch
  https://fetch.spec.whatwg.org/#http-network-fetch

these use same "Sec-Http-State" header field and
therefore same nonce on every retry.

If server gets second request with same nonce value,
it may

    1. If request is identical (including request body)
       than original request with same nonce,
       server MAY return cached copy of response
       from original request with same nonce.
       Response MAY include update "Age" header field.
       Server MUST NOT execute request with
       have same nonce.

       [TBD: Should re-execution of request to be
             allowed, if request do not have
	     side effects? ]

    2. Otherwise server MAY return response with
       status 4xx "Duplicated nonce value".

If server selects to not keep track used nonce values
(per HTTP State Token key), server MAY process request
as new.

Note: Keeping track used nonce values is hard.
      Therefore server may elect to ignore nonce
      (except for signature validation).


TBD: Should nonce value generation to be defined
     more rigorously, and then allow server return
     4xx "Duplicated or bad nonce value" when
     nonce value is far off from next expected
     nonce value?

     If nonce is defined to be stored on
     HTTP State Token for origin and incremented
     from here, this also makes middleman
     hard to do own requests, because all
     request need change nonce and therefore
     recalculate signature.

5.1.  Attach HTTP State Tokens to a request
https://tools.ietf.org/html/draft-west-http-state-tokens-00#section-5.1


|   9.   If "request-token"'s "key" is not null, then insert a member
|        into "header-value" whose key is "sig", and whose value is the
|        result of executing Section 5.2 on request, "serialized-value",
|        and "request-token"'s "key".

 ⇒

--------

   9.   If "request-token"'s "key" is not null, then
      
        9.1   Execute Section 5.2 on request, "serialized-value",
              and "request-token"'s "key". Result have triple
	      ( "sig", "signed-fields", "nonce" )

        9.2  Insert a member into "header-value" whose key is "sig",
	     whose value is "sig" from triple (using byte sequence
	     (sh-binary, [draft-ietf-httpbis-header-structure-10], Section 3.10)
	     syntax).

        9.3  Insert a member into "header-value" whose key is 
             "signed-fields",  whose value is "signed-fields"
	     from triple (using string syntax, [draft-ietf-httpbis-header-structure-10],
	     Section 3.8).

        9.4  Insert a member into "header-value" whose key is
	     "nonce",  whose value is "nonce" from triple
	     (using integer syntax, [draft-ietf-httpbis-header-structure-10],
	     Section 3.6).

--------

4.1.  The 'Sec-Http-State' HTTP Header Field

https://tools.ietf.org/html/draft-west-http-state-tokens-00#section-4.1



|   The dictionary MAY contain:

Add
 ⇒

--------

   o Exactly one member whose key is "nonce" , and whose value is
     integer ([draft-ietf-httpbis-header-structure-10], Section 3.6).

   o Exactly one member whose key is "signed-fields", and whose value is
     string ( [draft-ietf-httpbis-header-structure-10], Section 3.6).

---------