<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
<!-- generated by https://github.com/cabo/kramdown-rfc2629 version 1.2.13 -->
<?rfc toc="yes"?>
<?rfc tocindent="yes"?>
<?rfc sortrefs="yes"?>
<?rfc symrefs="yes"?>
<?rfc strict="yes"?>
<?rfc compact="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc docmapping="yes"?>
<?rfc-ext html-pretty-print="prettyprint https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"?>
<rfc xmlns:x="http://purl.org/net/xml2rfc/ext"
     category="std"
     docName="draft-ietf-httpbis-digest-headers-01"
     ipr="trust200902"
     submissionType="IETF">
   <x:feedback template="mailto:ietf-http-wg@w3.org?subject={docname},%20%22{section}%22\&amp;amp;body=%3c{ref}%3e:"/>
   <front>
      <title>Digest Headers</title>
      <author fullname="Roberto Polli" initials="R." surname="Polli">
         <organization>Team Digitale, Italian Government</organization>
         <address>
            <email>robipolli@gmail.com</email>
         </address>
      </author>
      <author fullname="Lucas Pardue" initials="L." surname="Pardue">
         <organization>Cloudflare</organization>
         <address>
            <email>lucaspardue.24.7@gmail.com</email>
         </address>
      </author>
      <date day="03" month="November" year="2019"/>
      <area>Applications and Real-Time</area>
      <workgroup>HTTP</workgroup>
      <keyword>Digest</keyword>
      <abstract>
         <t>This document defines the Digest and Want-Digest header fields for HTTP, thus allowing client and server to negotiate an integrity checksum of the exchanged resource representation data.</t>
         <t>This document obsoletes RFC 3230. It replaces the term “instance” with “representation”, which makes it consistent with the HTTP Semantic and Context defined in RFC 7231.</t>
      </abstract>
      <note title="Note to Readers">
         <t>
            <spanx>RFC EDITOR: please remove this section before publication</spanx>
         </t>
         <t>Discussion of this draft takes place on the HTTP working group mailing list (ietf-http-wg@w3.org), which is archived at <eref target="https://lists.w3.org/Archives/Public/ietf-http-wg/">https://lists.w3.org/Archives/Public/ietf-http-wg/</eref>.</t>
         <t>The source code and issues list for this draft can be found at <eref target="https://github.com/httpwg/http-extensions">https://github.com/httpwg/http-extensions</eref>.</t>
      </note>
   </front>
   <middle>
      <section anchor="introduction" title="Introduction">
         <t>The core specification of HTTP does not define a means to protect the integrity of resources. When HTTP messages are transferred between endpoints, the protocol might choose to make use of features of the lower layer in order to provide some integrity protection; for instance TCP checksums or TLS records <xref target="RFC2818"/>.</t>
         <t>However, there are cases where relying on this alone is insufficient. An HTTP-level integrity mechanism that operates independent of transfer can be used to detect programming errors and/or corruption of data at rest, be used across multiple hops in order to provide end-to-end integrity guarantees, aid fault diagnosis across hops and system boundaries, and can be used to validate integrity when reconstructing a resource fetched using different HTTP connections.</t>
         <t>This document defines a mechanism that acts on HTTP representation-data. It can be combined with other mechanisms that protect representation-metadata, such as digital signatures, in order to protect the desired parts of an HTTP exchange in whole or in part.</t>
         <section anchor="a-brief-history-of-integrity-header-fields"
                  title="A Brief History of Integrity Header Fields">
            <t>The Content-MD5 header field was originally introduced to provide integrity, but HTTP/1.1 (<xref target="RFC7231" x:fmt="," x:sec="B"/>) obsoleted it:</t>
            <t>
               <list style="empty">
                  <t>The Content-MD5 header field has been removed because it was inconsistently implemented with respect to partial responses.</t>
               </list>
            </t>
            <t>
               <xref target="RFC3230"/> provided a more flexible solution introducing the concept of “instance”, and the header fields <spanx style="verb">Digest</spanx> and <spanx style="verb">Want-Digest</spanx>.</t>
         </section>
         <section anchor="this-proposal" title="This Proposal">
            <t>The concept of <spanx style="verb">selected representation</spanx> defined in <xref target="RFC7231"/> made <xref target="RFC3230"/> definitions inconsistent with the current standard. A refresh was then required.</t>
            <t>This document updates the <spanx style="verb">Digest</spanx> and <spanx style="verb">Want-Digest</spanx> header field definitions to align with <xref target="RFC7231"/> concepts.</t>
            <t>This approach can be easily adapted to use-cases where the transferred data does require some sort of manipulation to be considered a representation or conveys a partial representation of a resource (eg. Range Requests <xref target="RFC7233"/>).</t>
            <t>Changes are semantically compatible with existing implementations and better cover both the request and response cases.</t>
            <t>The value of <spanx style="verb">Digest</spanx> is calculated on selected representation, which is tied to the value contained in any <spanx style="verb">Content-Encoding</spanx> or <spanx style="verb">Content-Type</spanx> header fields. Therefore, a given resource may have multiple different digest values.</t>
            <t>To allow both parties to exchange a Digest of a representation with <eref target="https://tools.ietf.org/html/rfc7231#section-3.1.2.1">no content codings</eref> two more algorithms are added (<spanx style="verb">ID-SHA-256</spanx> and <spanx style="verb">ID-SHA-512</spanx>).</t>
         </section>
         <section anchor="goals" title="Goals">
            <t>The goals of this proposal are:</t>
            <t>
               <list style="numbers">
                  <t>Digest coverage for either the resource’s <spanx style="verb">representation data</spanx> or <spanx style="verb">selected representation data</spanx> communicated via HTTP.</t>
                  <t>Support for multiple digest algorithms.</t>
                  <t>Negotiation of the use of digests.</t>
               </list>
            </t>
            <t>The goals do not include:</t>
            <t>
               <list style="hanging">
                  <t hangText="HTTP Message integrity:">The digest mechanism described here does not cover the full HTTP message nor its semantic, as representation metadata are not included in the checksum.</t>
                  <t hangText="Header field integrity:">The digest mechanisms described here cover only representation and selected representation data, and do not protect the integrity of associated representation metadata or other message header fields.</t>
                  <t hangText="Authentication:">The digest mechanisms described here are not meant to support authentication of the source of a digest or of a message or anything else. These mechanisms, therefore, are not a sufficient defense against many kinds of malicious attacks.</t>
                  <t hangText="Privacy:">Digest mechanisms do not provide message privacy.</t>
                  <t hangText="Authorization:">The digest mechanisms described here are not meant to support authorization or other kinds of access controls.</t>
               </list>
            </t>
         </section>
         <section anchor="notational-conventions" title="Notational Conventions">
            <t>The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in BCP 14 (<xref target="RFC2119"/> and <xref target="RFC8174"/>) when, and only when, they appear in all capitals, as shown here.</t>
            <t>This document uses the Augmented BNF defined in <xref target="RFC5234"/> and updated by <xref target="RFC7405"/> along with the “#rule” extension defined in <xref target="RFC7230" x:fmt="of" x:sec="7"/>.</t>
            <t>The definitions “representation”, “selected representation”, “representation data”, “representation metadata”, and “payload body” in this document are to be interpreted as described in <xref target="RFC7230"/> and <xref target="RFC7231"/>.</t>
            <t>The definition “validator” in this document is to be interpreted as described in <xref target="RFC7231" x:fmt="of" x:sec="7.2"/>.</t>
         </section>
      </section>
      <section anchor="resource-representation"
               title="Resource Representation and Representation-Data">
         <t>To avoid inconsistencies, an integrity mechanism for HTTP messages should decouple the checksum calculation from:</t>
         <t>
            <list style="symbols">
               <t>the payload body - which may be altered by mechanism like Range Requests <xref target="RFC7233"/> or the method (eg. HEAD);</t>
               <t>and the message body - which depends on <spanx style="verb">Transfer-Encoding</spanx> and whatever transformations the intermediaries may apply.</t>
            </list>
         </t>
         <t>The following examples show how representation metadata, payload transformations and method impacts on the message and payload body.</t>
         <t>Here is a gzip-compressed json object</t>
         <t>Request:</t>
         <figure>
            <artwork>
PUT /entries/1234 HTTP/1.1
Content-Type: application/json
Content-Encoding: gzip

H4sIAItWyFwC/6tWSlSyUlAypANQqgUAREcqfG0AAAA=
</artwork>
         </figure>
         <t>Now the same payload body conveys a malformed json object.</t>
         <t>Request:</t>
         <figure>
            <artwork>
PUT /entries/1234 HTTP/1.1
Content-Type: application/json

H4sIAItWyFwC/6tWSlSyUlAypANQqgUAREcqfG0AAAA=
</artwork>
         </figure>
         <t>A Range-Request alters the payload body, conveying a partial representation.</t>
         <t>Request:</t>
         <figure>
            <artwork>
GET /entries/1234 HTTP/1.1
Range: bytes=1-7

</artwork>
         </figure>
         <t>Response:</t>
         <figure>
            <artwork>
HTTP/1.1 206 Partial Content
Content-Encoding: gzip
Content-Type: application/json
Content-Range: bytes 1-7/18

iwgAla3RXA==
</artwork>
         </figure>
         <t>Now the method too alters the payload body.</t>
         <t>Request:</t>
         <figure>
            <artwork>
HEAD /entries/1234 HTTP/1.1
Accept: application/json
Accept-Encoding: gzip

</artwork>
         </figure>
         <t>Response:</t>
         <figure>
            <artwork>
HTTP/1.1 200 OK
Content-Type: application/json
Content-Encoding: gzip

</artwork>
         </figure>
      </section>
      <section anchor="algorithms" title="Digest Algorithm Values">
         <t>Digest algorithm values are used to indicate a specific digest computation. For some algorithms, one or more parameters may be supplied.</t>
         <figure>
            <artwork>
   digest-algorithm = token
</artwork>
         </figure>
         <t>The BNF for “parameter” is as is used in <xref target="RFC7230"/>. All digest-algorithm values are case-insensitive.</t>
         <t>The Internet Assigned Numbers Authority (IANA) acts as a registry for digest-algorithm values. The registry contains the following tokens.</t>
         <t>
            <list style="hanging">
               <t hangText="SHA-256:">
                  <list style="symbols">
                     <t>Description: The SHA-256 algorithm <xref target="RFC6234"/>. The output of this algorithm is encoded using the base64 encoding <xref target="RFC4648"/>.</t>
                     <t>Reference: <xref target="RFC6234"/>, <xref target="RFC4648"/>, this document.</t>
                     <t>Status: standard</t>
                  </list>
               </t>
               <t hangText="SHA-512:">
                  <list style="symbols">
                     <t>Description: The SHA-512 algorithm <xref target="RFC6234"/>. The output of this algorithm is encoded using the base64 encoding <xref target="RFC4648"/>.</t>
                     <t>Reference: <xref target="RFC6234"/>, <xref target="RFC4648"/>, this document.</t>
                     <t>Status: standard</t>
                  </list>
               </t>
               <t hangText="MD5:">
                  <list style="symbols">
                     <t>Description: The MD5 algorithm, as specified in <xref target="RFC1321"/>. The output of this algorithm is encoded using the base64 encoding <xref target="RFC4648"/>. The MD5 algorithm MUST NOT be used as it’s now vulnerable to collision attacks <xref target="CMU-836068"/>.</t>
                     <t>Reference: <xref target="RFC1321"/>, <xref target="RFC4648"/>, this document.</t>
                     <t>Status: deprecated</t>
                  </list>
               </t>
               <t hangText="SHA:">
                  <list style="symbols">
                     <t>Description: The SHA-1 algorithm <xref target="RFC3174"/>. The output of this algorithm is encoded using the base64 encoding <xref target="RFC4648"/>. The SHA algorithm is NOT RECOMMENDED as it’s now vulnerable to collision attacks <xref target="IACR-2019-459"/>.</t>
                     <t>Reference: <xref target="RFC3174"/>, <xref target="RFC6234"/>, <xref target="RFC4648"/>, this document.</t>
                     <t>Status: obsoleted</t>
                  </list>
               </t>
               <t hangText="UNIXsum:">
                  <list style="symbols">
                     <t>Description: The algorithm computed by the UNIX “sum” command, as defined by the Single UNIX Specification, Version 2 <xref target="UNIX"/>. The output of this algorithm is an ASCII decimal-digit string representing the 16-bit checksum, which is the first word of the output of the UNIX “sum” command.</t>
                     <t>Reference: <xref target="UNIX"/>, this document.</t>
                     <t>Status: standard</t>
                  </list>
               </t>
               <t hangText="UNIXcksum:">
                  <list style="symbols">
                     <t>Description: The algorithm computed by the UNIX “cksum” command, as defined by the Single UNIX Specification, Version 2 <xref target="UNIX"/>. The output of this algorithm is an ASCII digit string representing the 32-bit CRC, which is the first word of the output of the UNIX “cksum” command.</t>
                     <t>Reference: <xref target="UNIX"/>, this document.</t>
                     <t>Status: standard</t>
                  </list>
               </t>
            </list>
         </t>
         <t>To allow sender and recipient to provide a checksum which is independent from <spanx style="verb">Content-Encoding</spanx>, the following additional algorithms are defined:</t>
         <t>
            <list style="hanging">
               <t hangText="ID-SHA-512:">
                  <list style="symbols">
                     <t>Description: The sha-512 digest of the representation-data of the resource when no content coding is applied (eg. <spanx style="verb">Content-Encoding: identity</spanx>)</t>
                     <t>Reference: <xref target="RFC6234"/>, <xref target="RFC4648"/>, this document.</t>
                     <t>Status: standard</t>
                  </list>
               </t>
               <t hangText="ID-SHA-256:">
                  <list style="symbols">
                     <t>Description: The sha-256 digest of the representation-data of the resource when no content coding is applied (eg. <spanx style="verb">Content-Encoding: identity</spanx>)</t>
                     <t>Reference: <xref target="RFC6234"/>, <xref target="RFC4648"/>, this document.</t>
                     <t>Status: standard</t>
                  </list>
               </t>
            </list>
         </t>
         <t>If other digest-algorithm values are defined, the associated encoding MUST either be represented as a quoted string, or MUST NOT include “;” or “,” in the character sets used for the encoding.</t>
         <section anchor="representation-digest" title="Representation Digest">
            <t>A representation digest is the value of the output of a digest algorithm, together with an indication of the algorithm used (and any parameters).</t>
            <figure>
               <artwork>
   representation-data-digest = digest-algorithm "="
                                &lt;encoded digest output&gt;
</artwork>
            </figure>
            <t>As explained in <xref target="resource-representation"/> the digest is computed on the entire selected <spanx style="verb">representation data</spanx> of the resource defined in <xref target="RFC7231"/>:</t>
            <figure>
               <artwork>
   representation-data := Content-Encoding( Content-Type( bits ) )
</artwork>
            </figure>
            <t>The encoded digest output uses the encoding format defined for the specific digest-algorithm.</t>
            <section anchor="digest-algorithm-encoding-examples"
                     title="digest-algorithm Encoding Examples">
               <t>The <spanx style="verb">sha-256</spanx> digest-algorithm uses base64 encoding. Note that digest-algorithm values are case insensitive.</t>
               <figure>
                  <artwork>
   sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=
</artwork>
               </figure>
               <t>The “UNIXsum” digest-algorithm uses ASCII string of decimal digits.</t>
               <figure>
                  <artwork>
   UNIXsum=30637
</artwork>
               </figure>
            </section>
         </section>
      </section>
      <section anchor="header-field-specifications"
               title="Header Field Specifications">
         <t>The following headers are defined</t>
         <section anchor="want-digest-header" title="Want-Digest">
            <t>The Want-Digest message header field indicates the sender’s desire to receive a representation digest on messages associated with the request URI and representation metadata.</t>
            <figure>
               <artwork>
   Want-Digest = "Want-Digest" ":" OWS 1#want-digest-value
   want-digest-value = digest-algorithm [ ";" "q" "=" qvalue]
   qvalue = ( "0"  [ "."  0*1DIGIT ] ) /  ( "1"  [ "."  0*1( "0" ) ] )
</artwork>
            </figure>
            <t>If a digest-algorithm is not accompanied by a qvalue, it is treated as if its associated qvalue were 1.0.</t>
            <t>The sender is willing to accept a digest-algorithm if and only if it is listed in a Want-Digest header field of a message, and its qvalue is non-zero.</t>
            <t>If multiple acceptable digest-algorithm values are given, the sender’s preferred digest-algorithm is the one (or ones) with the highest qvalue.</t>
            <t>Two examples of its use are</t>
            <figure>
               <artwork>
   Want-Digest: sha-256
   Want-Digest: SHA-512;q=0.3, sha-256;q=1, md5;q=0
</artwork>
            </figure>
         </section>
         <section anchor="digest-header" title="Digest">
            <t>The Digest header field provides a digest of the representation data.</t>
            <figure>
               <artwork>
   Digest = "Digest" ":" OWS 1#representation-data-digest
</artwork>
            </figure>
            <t>
               <spanx style="verb">Representation data</spanx> might be:</t>
            <t>
               <list style="symbols">
                  <t>fully contained in the message body,</t>
                  <t>partially-contained in the message body,</t>
                  <t>or not at all contained in the message body.</t>
               </list>
            </t>
            <t>The resource is specified by the effective request URI and any <spanx style="verb">validator</spanx> contained in the message.</t>
            <t>For example, in a response to a HEAD request, the digest is calculated using the representation data that would have been enclosed in the payload body if the same request had been a GET.</t>
            <t>Digest can be used in requests too.</t>
            <t>The <spanx style="verb">Digest</spanx> value depends on the representation metadata.</t>
            <t>A Digest header field MAY contain multiple representation-data-digest values. This could be useful for responses expected to reside in caches shared by users with different browsers, for example.</t>
            <t>A recipient MAY ignore any or all of the representation-data-digests in a Digest header field. This allows the recipient to chose which digest-algorithm(s) to use for validation instead of verifying every received representation-data-digest.</t>
            <t>A sender MAY send a representation-data-digest using a digest-algorithm without knowing whether the recipient supports the digest-algorithm, or even knowing that the recipient will ignore it.</t>
            <t>Two examples of its use are</t>
            <figure>
               <artwork>
   Digest: id-sha-512=WZDPaVn/7XgHaAy8pmojAkGWoRx2UFChF41A2svX+TaPm+AbwAgBWnrIiYllu7BNNyealdVLvRwE\nmTHWXvJwew==
   Digest: sha-256=4REjxQ4yrqUVicfSKYNO/cF9zNj5ANbzgDZt3/h3Qxo=, id-sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=
</artwork>
            </figure>
         </section>
      </section>
      <section anchor="acting-on-resources"
               title="Use of Digest when acting on resources">
         <t>POST and PATCH requests may appear to convey partial representations but are semantically acting on resources. The enclosed representation, including its metadata refers to that action.</t>
         <t>In these requests the representation digest MUST be computed on the representation-data of that action.</t>
         <t>This is the only possible choice because representation digest requires complete representation metadata (see <xref target="representation-digest"/>).</t>
         <t>In responses,</t>
         <t>
            <list style="symbols">
               <t>if the representation describes the status of the request, <spanx style="verb">Digest</spanx> MUST be computed on the enclosed representation (see <xref target="post-referencing-action"/> );</t>
               <t>if there is a referenced resource <spanx style="verb">Digest</spanx> MUST be computed on the selected representation of the referenced resource even if that is different from the target resource. That may or may not result in computing <spanx style="verb">Digest</spanx> on the enclosed representation.</t>
            </list>
         </t>
         <t>The latter case might be done accordingly to the HTTP semantics of the given method, for example using the <spanx style="verb">Content-Location</spanx> header field.</t>
         <t>Differently from <spanx style="verb">Content-Location</spanx>, which is representation metadata, the <spanx style="verb">Location</spanx> header field does not affect <spanx style="verb">Digest</spanx>.</t>
         <section anchor="digest-and-patch" title="Digest and PATCH">
            <t>In PATCH requests the representation digest MUST be computed on the patch document.</t>
            <t>This is because the representation metadata refers to the patch document and not to the target resource (see <xref target="RFC5789" x:fmt="of" x:sec="2"/>).</t>
            <t>In PATCH responses the representation digest MUST be computed on the selected representation of the patched resource.</t>
            <t>
               <spanx style="verb">Digest</spanx> usage with PATCH is thus very similar to the POST one, but with the resource’s own semantic partly implied by the method and by the patch document.</t>
         </section>
      </section>
      <section anchor="deprecate-negotiation-of-content-md5"
               title="Deprecate Negotiation of Content-MD5">
         <t>This RFC deprecates the negotiation of Content-MD5 as it has been obsoleted by <xref target="RFC7231"/>
         </t>
      </section>
      <section anchor="broken-cryptographic-algorithms"
               title="Broken Cryptographic Algorithms">
         <t>The MD5 algorithm MUST NOT be used as it has been found vulnerable to collision attacks <xref target="CMU-836068"/>.</t>
         <t>The SHA algorithm is NOT RECOMMENDED as it has been found vulnerable to collision attacks <xref target="IACR-2019-459"/>.</t>
      </section>
      <section anchor="relationship-to-subresource-integrity-sri"
               title="Relationship to Subresource Integrity (SRI)">
         <t>Subresource Integrity <xref target="SRI"/> is an integrity mechanism that shares some similarities to the present document’s mechanism. However, there are differences in motivating factors, threat model and specification of integrity digest generation, signalling and validation.</t>
         <t>SRI allows a first-party authority to declare an integrity assertion on a resource served by a first or third party authority. This is done via the <spanx style="verb">integrity</spanx> attribute that can added to <spanx style="verb">script</spanx> or <spanx style="verb">link</spanx> HTML elements. Therefore, the integrity assertion is always made out-of-band to the resource fetch. In contrast, the <spanx style="verb">Digest</spanx> header field is supplied in-band alongside the selected representation, meaning that an authority can only declare an integrity assertion for itself. Methods to improve the security properties of representation digests are presented in <xref target="security-considerations"/>. This contrast is interesting because on one hand self-assertion is less likely to be affected by coordination problems such as the first-party holding stale information about the third party, but on the other hand the self-assertion is only as trustworthy as the authority that provided it.</t>
         <t>The SRI <spanx style="verb">integrity</spanx> attribute contains a cryptographic hash algorithm and digest value which is similar to <spanx style="verb">representation-data-digest</spanx> (see <xref target="representation-digest"/>). The major differences are in serialization format.</t>
         <t>The SRI digest value is calculated over the identity encoding of the resource, not the selected representation (as specified for <spanx style="verb">representation-data-digest</spanx> in this document). Section 3.4.5 of <xref target="SRI"/> describes the benefit of the identity approach - the SRI <spanx style="verb">integrity</spanx> attribute can contain multiple algorithm-value pairs where each applies to a different identity encoded payload. This allows for protection of distinct resources sharing a URL. However, this is a contrast to the design of representation digests, where multiple <spanx style="verb">Digest</spanx> field-values all protect the same representation.</t>
         <t>SRI does not specify handling of partial representation data (e.g. Range requests). In contrast, this document specifies handling in terms that are fully compatible with core HTTP concepts (an example is provided in <xref target="server-returns-partial-representation-data"/>).</t>
         <t>SRI specifies strong requirements on the selection of algorithm for generation and validation of digests. In contrast, the requirements in this document are weaker.</t>
         <t>SRI defines no method for a client to declare an integrity assertion on resources it transfers to a server. In contrast, the <spanx style="verb">Digest</spanx> header field can appear on requests.</t>
         <section anchor="supporting-both-sri-and-representation-digest"
                  title="Supporting Both SRI and Representation Digest">
            <t>The SRI and Representation Digest mechanism are different and complementary but one is not capable of replacing the other because they have have different threat, security and implementation properties.</t>
            <t>A user agent that supports both mechanisms is expected to apply the rules specified for each but since the two mechanisms are independent, the ordering is not important. However, a user agent supporting both could benefit from performing representation digest validation first because the it does not require a conversion to into identity encoding.</t>
            <t>There is a chance that a user agent supporting both mechanisms may find one validates successfully while the other fails. This document specifies no requirements or guidance for user agents that experience such cases.</t>
         </section>
      </section>
      <section anchor="examples-of-unsolicited-digest"
               title="Examples of Unsolicited Digest">
         <t>The following examples demonstrate interactions where a server responds with a <spanx style="verb">Digest</spanx> header field even though the client did not solicit one using <spanx style="verb">Want-Digest</spanx>.</t>
         <section anchor="server-returns-full-representation-data"
                  title="Server Returns Full Representation Data">
            <t>Request:</t>
            <figure>
               <artwork>
GET /items/123

</artwork>
            </figure>
            <t>Response:</t>
            <figure>
               <artwork>
HTTP/1.1 200 OK
Content-Type: application/json
Content-Encoding: identity
Digest: sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=

{"hello": "world"}
</artwork>
            </figure>
         </section>
         <section anchor="server-returns-no-representation-data"
                  title="Server Returns No Representation Data">
            <t>As there is no content coding applied, the <spanx style="verb">sha-256</spanx> and the <spanx style="verb">id-sha-256</spanx> digest-values are the same.</t>
            <t>Request:</t>
            <figure>
               <artwork>
HEAD /items/123

</artwork>
            </figure>
            <t>Response:</t>
            <figure>
               <artwork>
HTTP/1.1 200 OK
Content-Type: application/json
Content-Encoding: identity
Digest: id-sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=

</artwork>
            </figure>
         </section>
         <section anchor="server-returns-partial-representation-data"
                  title="Server Returns Partial Representation Data">
            <t>Request:</t>
            <figure>
               <artwork>
GET /items/123
Range: bytes=1-7

</artwork>
            </figure>
            <t>Response:</t>
            <figure>
               <artwork>
HTTP/1.1 206 Partial Content
Content-Type: application/json
Content-Encoding: identity
Content-Range: bytes 1-7/18
Digest: sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=

"hello"
</artwork>
            </figure>
         </section>
         <section anchor="client-and-server-provide-full-representation-data"
                  title="Client and Server Provide Full Representation Data">
            <t>The request contains a <spanx style="verb">Digest</spanx> header calculated on the enclosed representation.</t>
            <t>It also includes an <spanx style="verb">Accept-Encoding: br</spanx> header field that advertises the client supports brotli encoding.</t>
            <t>The response includes a <spanx style="verb">Content-Encoding: br</spanx> that indicates the selected representation is brotli encoded. The <spanx style="verb">Digest</spanx> field-value is therefore different compared to the request.</t>
            <t>Request:</t>
            <figure>
               <artwork>
PUT /items/123
Content-Type: application/json
Content-Encoding: identity
Accept-Encoding: br
Digest: sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=

{"hello": "world"}
</artwork>
            </figure>
            <t>Response:</t>
            <figure>
               <artwork>
Content-Type: application/json
Content-Encoding: br
Digest: sha-256=4REjxQ4yrqUVicfSKYNO/cF9zNj5ANbzgDZt3/h3Qxo=

iwiAeyJoZWxsbyI6ICJ3b3JsZCJ9Aw==
</artwork>
            </figure>
         </section>
         <section anchor="client-provides-full-representation-data-server-provides-no-representation-data"
                  title="Client Provides Full Representation Data, Server Provides No Representation Data">
            <t>Request <spanx style="verb">Digest</spanx> value is calculated on the enclosed payload. Response <spanx style="verb">Digest</spanx> value depends on the representation metadata header fields, including <spanx style="verb">Content-Encoding: br</spanx> even when the response does not contain a payload body.</t>
            <t>Request:</t>
            <figure>
               <artwork>
PUT /items/123
Content-Type: application/json
Content-Encoding: identity
Content-Length: 18
Accept-Encoding: br
Digest: sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=

{"hello": "world"}
</artwork>
            </figure>
            <t>Response:</t>
            <figure>
               <artwork>
HTTP/1.1 204 No Content
Content-Type: application/json
Content-Encoding: br
Digest: sha-256=4REjxQ4yrqUVicfSKYNO/cF9zNj5ANbzgDZt3/h3Qxo=

</artwork>
            </figure>
         </section>
         <section anchor="client-and-server-provide-full-representation-data-client-uses-id-sha-256"
                  title="Client and Server Provide Full Representation Data, Client Uses id-sha-256.">
            <t>The response contains two digest values:</t>
            <t>
               <list style="symbols">
                  <t>one with no content coding applied, which in this case accidentally matches the unencoded digest-value sent in the request;</t>
                  <t>one taking into account the <spanx style="verb">Content-Encoding</spanx>.</t>
               </list>
            </t>
            <t>Request:</t>
            <figure>
               <artwork>
PUT /items/123 HTTP/1.1
Content-Type: application/json
Content-Encoding: identity
Accept-Encoding: br
Digest: sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=

{"hello": "world"}
</artwork>
            </figure>
            <t>Response:</t>
            <figure>
               <artwork>
HTTP/1.1 200 OK
Content-Type: application/json
Content-Encoding: br
Digest: sha-256=4REjxQ4yrqUVicfSKYNO/cF9zNj5ANbzgDZt3/h3Qxo=, id-sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=

iwiAeyJoZWxsbyI6ICJ3b3JsZCJ9Aw==
</artwork>
            </figure>
         </section>
         <section anchor="post-not-request-uri"
                  title="POST Response does not Reference the Request URI">
            <t>Request <spanx style="verb">Digest</spanx> value is computed on the enclosed representation (see <xref target="acting-on-resources"/>).</t>
            <t>The representation enclosed in the response refers to the resource identified by <spanx style="verb">Content-Location</spanx> (see <xref target="RFC7231"/>
               <xref target="RFC7231" x:fmt="sec" x:sec="3.1.4.2"/> and Section 3.1.4.1 point 4).</t>
            <t>
               <spanx style="verb">Digest</spanx> is thus computed on the enclosed representation.</t>
            <t>Request:</t>
            <figure>
               <artwork>
POST /books HTTP/1.1
Content-Type: application/json
Accept: application/json
Accept-Encoding: identity
Digest: sha-256=bWopGGNiZtbVgHsG+I4knzfEJpmmmQHf7RHDXA3o1hQ=

{"title": "New Title"}
</artwork>
            </figure>
            <t>Response</t>
            <figure>
               <artwork>
HTTP/1.1 201 Created
Content-Type: application/json
Digest: id-sha-256=BZlF2v0IzjuxN01RQ97EUXriaNNLhtI8Chx8Eq+XYSc=
Content-Location: /books/123

{"id": "123", "title": "New Title"}
</artwork>
            </figure>
            <t>Note that a <spanx style="verb">204 No Content</spanx> response without a payload body but with the same <spanx style="verb">Digest</spanx> field-value would have been legitimate too.</t>
         </section>
         <section anchor="post-referencing-action"
                  title="POST Response Describes the Request Status">
            <t>Request <spanx style="verb">Digest</spanx> value is computed on the enclosed representation (see <xref target="acting-on-resources"/>).</t>
            <t>The representation enclosed in the response describes the status of the request, so <spanx style="verb">Digest</spanx> is computed on that enclosed representation.</t>
            <t>Response <spanx style="verb">Digest</spanx> has no explicit relation with the resource referenced by <spanx style="verb">Location</spanx>.</t>
            <t>Request:</t>
            <figure>
               <artwork>
POST /books HTTP/1.1
Content-Type: application/json
Accept: application/json
Accept-Encoding: identity
Digest: sha-256=bWopGGNiZtbVgHsG+I4knzfEJpmmmQHf7RHDXA3o1hQ=
Location: /books/123

{"title": "New Title"}
</artwork>
            </figure>
            <t>Response</t>
            <figure>
               <artwork>
HTTP/1.1 201 Created
Content-Type: application/json
Digest: id-sha-256=0o/WKwSfnmIoSlop2LV/ISaBDth05IeW27zzNMUh5l8=
Location: /books/123

{"status": "created", "id": "123", "ts": 1569327729, "instance": "/books/123"}
</artwork>
            </figure>
         </section>
         <section anchor="digest-with-patch" title="Digest with PATCH">
            <t>This case is analogous to a POST request where the target resource reflects the effective request URI.</t>
            <t>The PATCH request uses the <spanx style="verb">application/merge-patch+json</spanx> media type defined in <xref target="RFC7396"/>.</t>
            <t>
               <spanx style="verb">Digest</spanx> is calculated on the enclosed payload, which corresponds to the patch document.</t>
            <t>The response <spanx style="verb">Digest</spanx> is computed on the complete representation of the patched resource.</t>
            <t>Request:</t>
            <figure>
               <artwork>
PATCH /books/123 HTTP/1.1
Content-Type: application/merge-patch+json
Accept: application/json
Accept-Encoding: identity
Digest: sha-256=bWopGGNiZtbVgHsG+I4knzfEJpmmmQHf7RHDXA3o1hQ=

{"title": "New Title"}
</artwork>
            </figure>
            <t>Response:</t>
            <figure>
               <artwork>
HTTP/1.1 200 OK
Content-Type: application/json
Digest: id-sha-256=BZlF2v0IzjuxN01RQ97EUXriaNNLhtI8Chx8Eq+XYSc=

{"id": "123", "title": "New Title"}
</artwork>
            </figure>
            <t>Note that a <spanx style="verb">204 No Content</spanx> response without a payload body but with the same <spanx style="verb">Digest</spanx> field-value would have been legitimate too.</t>
         </section>
      </section>
      <section anchor="examples-of-want-digest-solicited-digest"
               title="Examples of Want-Digest Solicited Digest">
         <t>The following examples demonstrate interactions where a client solicits a <spanx style="verb">Digest</spanx> using <spanx style="verb">Want-Digest</spanx>.</t>
         <section anchor="server-selects-clients-least-preferred-algorithm"
                  title="Server Selects Client’s Least Preferred Algorithm">
            <t>The client requests a digest, preferring sha. The server is free to reply with sha-256 anyway.</t>
            <t>Request:</t>
            <figure>
               <artwork>
GET /items/123 HTTP/1.1
Want-Digest: sha-256;q=0.3, sha;q=1

</artwork>
            </figure>
            <t>Response:</t>
            <figure>
               <artwork>
HTTP/1.1 200 OK
Content-Type: application/json
Content-Encoding: identity
Digest: sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=

{"hello": "world"}
</artwork>
            </figure>
         </section>
         <section anchor="server-selects-algorithm-unsupported-by-client"
                  title="Server Selects Algorithm Unsupported by Client">
            <t>The client requests a sha digest only. The server is currently free to reply with a Digest containing an unsupported algorithm.</t>
            <t>Request:</t>
            <figure>
               <artwork>
GET /items/123
Want-Digest: sha;q=1

</artwork>
            </figure>
            <t>Response:</t>
            <figure>
               <artwork>
HTTP/1.1 200 OK
Content-Type: application/json
Content-Encoding: identity
Digest: id-sha-512=WZDPaVn/7XgHaAy8pmojAkGWoRx2UFChF41A2svX+TaPm+AbwAgBWnrIiYllu7BNNyealdVLvRwE\nmTHWXvJwew==

{"hello": "world"}
</artwork>
            </figure>
         </section>
         <section anchor="server-does-not-support-client-algorithm-and-returns-an-error"
                  title="Server Does Not Support Client Algorithm and Returns an Error">
            <t>The client requests a sha Digest, the server advises for sha-256 and sha-512</t>
            <t>Request:</t>
            <figure>
               <artwork>
GET /items/123
Want-Digest: sha;q=1

</artwork>
            </figure>
            <t>Response:</t>
            <figure>
               <artwork>
HTTP/1.1 400 Bad Request
Want-Digest: sha-256, sha-512

</artwork>
            </figure>
         </section>
      </section>
      <section anchor="security-considerations" title="Security Considerations">
         <section anchor="digest-does-not-protect-the-full-http-message"
                  title="Digest Does Not Protect the Full HTTP Message">
            <t>This document specifies a data integrity mechanism that protects HTTP <spanx style="verb">representation data</spanx>, but not HTTP <spanx style="verb">representation metadata</spanx> header fields, from certain kinds of accidental corruption.</t>
            <t>
               <spanx style="verb">Digest</spanx> is not intended as general protection against malicious tampering with HTTP messages, this can be achieved by combining it with other approaches such as transport-layer security or digital signatures.</t>
         </section>
         <section anchor="broken-cryptographic-algorithms-1"
                  title="Broken Cryptographic Algorithms">
            <t>Cryptographic algorithms are intended to provide a proof of integrity suited towards cryptographic constructions such as signatures.</t>
            <t>However, these rely on collision-resistance for their security proofs <xref target="CMU-836068"/>. The MD5 and SHA-1 algorithms are vulnerable to collisions attacks, so MD5 MUST NOT be used and SHA-1 is NOT RECOMMENDED for use with <spanx style="verb">Digest</spanx>.</t>
         </section>
         <section anchor="other-deprecated-algorithms"
                  title="Other Deprecated Algorithms">
            <t>The ADLER32 algorithm defined in <xref target="RFC1950"/> has been deprecated by <xref target="RFC3309"/> because under certain conditions it provides weak detection of errors and is now NOT RECOMMENDED for use with <spanx style="verb">Digest</spanx>.</t>
         </section>
         <section anchor="digest-for-end-to-end-integrity"
                  title="Digest for End-to-End Integrity">
            <t>
               <spanx style="verb">Digest</spanx> alone does not provide end-to-end integrity of HTTP messages over multiple hops, as it just covers the <spanx style="verb">representation data</spanx> and not the <spanx style="verb">representation metadata</spanx>.</t>
            <t>Besides, it allows to protect <spanx style="verb">representation data</spanx> from buggy manipulation, buggy compression, etc.</t>
            <t>Moreover identity digest algorithms (eg. ID-SHA-256 and ID-SHA-512) allow piecing together a resource from different sources (e.g. different servers that perhaps apply different content codings) enabling the user-agent to detect that the application-layer tasks completed properly, before handing off to say the HTML parser, video player etc.</t>
            <t>Even a simple mechanism for end-to-end validation is thus valuable.</t>
         </section>
         <section anchor="usage-in-signatures" title="Usage in Signatures">
            <t>Digital signatures are widely used together with checksums to provide the certain identification of the origin of a message <xref target="NIST800-32"/>. Such signatures can protect one or more header fields and there are additional considerations when <spanx style="verb">Digest</spanx> is included in this set.</t>
            <t>Since the <spanx style="verb">Digest</spanx> header field is a hash of a resource representation, it explicitly depends on the <spanx style="verb">representation metadata</spanx> (eg. the values of <spanx style="verb">Content-Type</spanx>, <spanx style="verb">Content-Encoding</spanx> etc). A signature that protects <spanx style="verb">Digest</spanx> but not other <spanx style="verb">representation metadata</spanx> may expose the communication to tampering. For example, an actor could manipulate the <spanx style="verb">Content-Type</spanx> field-value and cause a digest validation failure at the recipient, preventing the application from accessing the representation. Such an attack consumes the resources of both endpoints.</t>
            <t>
               <spanx style="verb">Digest</spanx> SHOULD always be used over a connection which provides integrity at transport layer that protects HTTP header fields.</t>
            <t>A <spanx style="verb">Digest</spanx> header field using NOT RECOMMENDED digest-algorithms SHOULD NOT be used in signatures.</t>
         </section>
         <section anchor="message-truncation" title="Message Truncation">
            <t>…</t>
         </section>
         <section anchor="algorithm-agility" title="Algorithm Agility">
            <t>…</t>
         </section>
      </section>
      <section anchor="iana-considerations" title="IANA Considerations">
         <section anchor="establish-the-http-digest-algorithm-values"
                  title="Establish the HTTP Digest Algorithm Values">
            <t>This memo sets this spec to be the establishing document for the <eref target="https://www.iana.org/assignments/http-dig-alg/http-dig-alg.xhtml">HTTP Digest Algorithm Values</eref>
            </t>
         </section>
         <section anchor="the-status-field-in-the-http-digest-algorithm-values"
                  title="The “status” Field in the HTTP Digest Algorithm Values">
            <t>This memo adds the field “Status” to the <eref target="https://www.iana.org/assignments/http-dig-alg/http-dig-alg.xhtml">HTTP Digest Algorithm Values</eref> registry. The allowed values for the “Status” fields are described below.</t>
            <t>
               <list style="hanging">
                  <t hangText="Status">Specify “standard”, “experimental”, “historic”, “obsoleted”, or “deprecated” according to the type and status of the primary document in which the algorithm is defined.</t>
               </list>
            </t>
         </section>
         <section anchor="iana-MD5" title="Deprecate “MD5” Digest Algorithm">
            <t>This memo updates the “MD5” digest algorithm in the <eref target="https://www.iana.org/assignments/http-dig-alg/http-dig-alg.xhtml">HTTP Digest Algorithm Values</eref> registry:</t>
            <t>
               <list style="symbols">
                  <t>Digest Algorithm: MD5</t>
                  <t>Description: As specified in <xref target="algorithms"/>.</t>
                  <t>Status: As specified in <xref target="algorithms"/>.</t>
               </list>
            </t>
         </section>
         <section anchor="iana-CRC32C" title="Update “CRC32C” Digest Algorithm">
            <t>This memo updates the “CRC32c” digest algorithm in the <eref target="https://www.iana.org/assignments/http-dig-alg/http-dig-alg.xhtml">HTTP Digest Algorithm Values</eref> registry:</t>
            <t>
               <list style="symbols">
                  <t>Digest Algorithm: CRC32c</t>
                  <t>Description: The CRC32c algorithm is a 32-bit cyclic redundancy check. It achieves a better hamming distance (for better error-detection performance) than many other 32-bit CRC functions. Other places it is used include iSCSI and SCTP. The 32-bit output is encoded in hexadecimal (using between 1 and 8 ASCII characters from 0-9, A-F, and a-f; leading 0’s are allowed). For example, CRC32c=0a72a4df and crc32c=A72A4DF are both valid checksums for the 3-byte message “dog”.</t>
                  <t>Reference: <xref target="RFC4960"/> appendix B, this document.</t>
                  <t>Status: standard.</t>
               </list>
            </t>
         </section>
         <section anchor="iana-SHA" title="Obsolete “SHA” Digest Algorithm">
            <t>This memo updates the “SHA” digest algorithm in the <eref target="https://www.iana.org/assignments/http-dig-alg/http-dig-alg.xhtml">HTTP Digest Algorithm Values</eref> registry:</t>
            <t>
               <list style="symbols">
                  <t>Digest Algorithm: SHA</t>
                  <t>Description: As specified in <xref target="algorithms"/>.</t>
                  <t>Status: As specified in <xref target="algorithms"/>.</t>
               </list>
            </t>
         </section>
         <section anchor="iana-adler-32" title="Obsolete “ADLER32” Digest Algorithm">
            <t>This memo updates the “ADLER32” digest algorithm in the <eref target="https://www.iana.org/assignments/http-dig-alg/http-dig-alg.xhtml">HTTP Digest Algorithm Values</eref> registry:</t>
            <t>
               <list style="symbols">
                  <t>Digest Algorithm: ADLER32</t>
                  <t>Description: The ADLER32 algorithm is a checksum specified in <xref target="RFC1950"/> “ZLIB Compressed Data Format”. The 32-bit output is encoded in hexadecimal (using between 1 and 8 ASCII characters from 0-9, A-F, and a-f; leading 0’s are allowed). For example, ADLER32=03da0195 and ADLER32=3DA0195 are both valid checksums for the 4-byte message “Wiki”. This algorithm is obsoleted and SHOULD NOT be used.</t>
                  <t>Status: obsoleted</t>
               </list>
            </t>
         </section>
         <section anchor="iana-ID-SHA-256" title="The “ID-SHA-256” Digest Algorithm">
            <t>This memo registers the “ID-SHA-256” digest algorithm in the <eref target="https://www.iana.org/assignments/http-dig-alg/http-dig-alg.xhtml">HTTP Digest Algorithm Values</eref> registry:</t>
            <t>
               <list style="symbols">
                  <t>Digest Algorithm: ID-SHA-256</t>
                  <t>Description: As specified in <xref target="algorithms"/>.</t>
                  <t>Status: As specified in <xref target="algorithms"/>.</t>
               </list>
            </t>
         </section>
         <section anchor="iana-ID-SHA-512" title="The “ID-SHA-512” Digest Algorithm">
            <t>This memo registers the “ID-SHA-512” digest algorithm in the <eref target="https://www.iana.org/assignments/http-dig-alg/http-dig-alg.xhtml">HTTP Digest Algorithm Values</eref> registry:</t>
            <t>
               <list style="symbols">
                  <t>Digest Algorithm: ID-SHA-512</t>
                  <t>Description: As specified in <xref target="algorithms"/>.</t>
                  <t>Status: As specified in <xref target="algorithms"/>.</t>
               </list>
            </t>
         </section>
         <section anchor="changes-compared-to-rfc5843"
                  title="Changes compared to RFC5843">
            <t>The status of “MD5” has been updated to “deprecated”, and its description states that this algorithm MUST NOT be used.</t>
            <t>The status of “SHA” has been updated to “obsoleted”, and its description states that this algorithm is NOT RECOMMENDED.</t>
            <t>The status for “CRC32C” has been updated to “standard”.</t>
            <t>The “ID-SHA-256” and “ID-SHA-512” algorithms have been added to the registry.</t>
         </section>
         <section anchor="want-digest-header-field-registration"
                  title="Want-Digest Header Field Registration">
            <t>This section registers the <spanx style="verb">Want-Digest</spanx> header field in the “Permanent Message Header Field Names” registry (<xref target="RFC3864"/>).</t>
            <t>Header field name: <spanx style="verb">Want-Digest</spanx>
            </t>
            <t>Applicable protocol: http</t>
            <t>Status: standard</t>
            <t>Author/Change controller: IETF</t>
            <t>Specification document(s): <xref target="want-digest-header"/> of this document</t>
         </section>
         <section anchor="digest-header-field-registration"
                  title="Digest Header Field Registration">
            <t>This section registers the <spanx style="verb">Digest</spanx> header field in the “Permanent Message Header Field Names” registry (<xref target="RFC3864"/>).</t>
            <t>Header field name: <spanx style="verb">Digest</spanx>
            </t>
            <t>Applicable protocol: http</t>
            <t>Status: standard</t>
            <t>Author/Change controller: IETF</t>
            <t>Specification document(s): <xref target="digest-header"/> of this document</t>
         </section>
      </section>
   </middle>
   <back>
      <references title="Normative References">
         <reference anchor="RFC1321">
            <front>
               <title>The MD5 Message-Digest Algorithm</title>
               <author fullname="R. Rivest" initials="R." surname="Rivest"/>
               <date month="April" year="1992"/>
            </front>
            <seriesInfo name="RFC" value="1321"/>
            <seriesInfo name="DOI" value="10.17487/RFC1321"/>
         </reference>
         <reference anchor="RFC3174">
            <front>
               <title>US Secure Hash Algorithm 1 (SHA1)</title>
               <author fullname="D. Eastlake 3rd" initials="D." surname="Eastlake 3rd"/>
               <author fullname="P. Jones" initials="P." surname="Jones"/>
               <date month="September" year="2001"/>
            </front>
            <seriesInfo name="RFC" value="3174"/>
            <seriesInfo name="DOI" value="10.17487/RFC3174"/>
         </reference>
         <reference anchor="RFC1950">
            <front>
               <title>ZLIB Compressed Data Format Specification version 3.3</title>
               <author fullname="P. Deutsch" initials="P." surname="Deutsch"/>
               <author fullname="J-L. Gailly" initials="J-L." surname="Gailly"/>
               <date month="May" year="1996"/>
            </front>
            <seriesInfo name="RFC" value="1950"/>
            <seriesInfo name="DOI" value="10.17487/RFC1950"/>
         </reference>
         <reference anchor="RFC3230">
            <front>
               <title>Instance Digests in HTTP</title>
               <author fullname="J. Mogul" initials="J." surname="Mogul"/>
               <author fullname="A. Van Hoff" initials="A." surname="Van Hoff"/>
               <date month="January" year="2002"/>
            </front>
            <seriesInfo name="RFC" value="3230"/>
            <seriesInfo name="DOI" value="10.17487/RFC3230"/>
         </reference>
         <reference anchor="RFC3309">
            <front>
               <title>Stream Control Transmission Protocol (SCTP) Checksum Change</title>
               <author fullname="J. Stone" initials="J." surname="Stone"/>
               <author fullname="R. Stewart" initials="R." surname="Stewart"/>
               <author fullname="D. Otis" initials="D." surname="Otis"/>
               <date month="September" year="2002"/>
            </front>
            <seriesInfo name="RFC" value="3309"/>
            <seriesInfo name="DOI" value="10.17487/RFC3309"/>
         </reference>
         <reference anchor="RFC2119">
            <front>
               <title>Key words for use in RFCs to Indicate Requirement Levels</title>
               <author fullname="S. Bradner" initials="S." surname="Bradner"/>
               <date month="March" year="1997"/>
            </front>
            <seriesInfo name="BCP" value="14"/>
            <seriesInfo name="RFC" value="2119"/>
            <seriesInfo name="DOI" value="10.17487/RFC2119"/>
         </reference>
         <reference anchor="RFC5843">
            <front>
               <title>Additional Hash Algorithms for HTTP Instance Digests</title>
               <author fullname="A. Bryan" initials="A." surname="Bryan"/>
               <date month="April" year="2010"/>
            </front>
            <seriesInfo name="RFC" value="5843"/>
            <seriesInfo name="DOI" value="10.17487/RFC5843"/>
         </reference>
         <reference anchor="RFC4648">
            <front>
               <title>The Base16, Base32, and Base64 Data Encodings</title>
               <author fullname="S. Josefsson" initials="S." surname="Josefsson"/>
               <date month="October" year="2006"/>
            </front>
            <seriesInfo name="RFC" value="4648"/>
            <seriesInfo name="DOI" value="10.17487/RFC4648"/>
         </reference>
         <reference anchor="RFC5234">
            <front>
               <title>Augmented BNF for Syntax Specifications: ABNF</title>
               <author fullname="D. Crocker"
                       initials="D."
                       role="editor"
                       surname="Crocker"/>
               <author fullname="P. Overell" initials="P." surname="Overell"/>
               <date month="January" year="2008"/>
            </front>
            <seriesInfo name="STD" value="68"/>
            <seriesInfo name="RFC" value="5234"/>
            <seriesInfo name="DOI" value="10.17487/RFC5234"/>
         </reference>
         <reference anchor="RFC6234">
            <front>
               <title>US Secure Hash Algorithms (SHA and SHA-based HMAC and HKDF)</title>
               <author fullname="D. Eastlake 3rd" initials="D." surname="Eastlake 3rd"/>
               <author fullname="T. Hansen" initials="T." surname="Hansen"/>
               <date month="May" year="2011"/>
            </front>
            <seriesInfo name="RFC" value="6234"/>
            <seriesInfo name="DOI" value="10.17487/RFC6234"/>
         </reference>
         <reference anchor="RFC7230">
            <front>
               <title>Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing</title>
               <author fullname="R. Fielding"
                       initials="R."
                       role="editor"
                       surname="Fielding"/>
               <author fullname="J. Reschke"
                       initials="J."
                       role="editor"
                       surname="Reschke"/>
               <date month="June" year="2014"/>
            </front>
            <seriesInfo name="RFC" value="7230"/>
            <seriesInfo name="DOI" value="10.17487/RFC7230"/>
         </reference>
         <reference anchor="RFC7231">
            <front>
               <title>Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content</title>
               <author fullname="R. Fielding"
                       initials="R."
                       role="editor"
                       surname="Fielding"/>
               <author fullname="J. Reschke"
                       initials="J."
                       role="editor"
                       surname="Reschke"/>
               <date month="June" year="2014"/>
            </front>
            <seriesInfo name="RFC" value="7231"/>
            <seriesInfo name="DOI" value="10.17487/RFC7231"/>
         </reference>
         <reference anchor="RFC7233">
            <front>
               <title>Hypertext Transfer Protocol (HTTP/1.1): Range Requests</title>
               <author fullname="R. Fielding"
                       initials="R."
                       role="editor"
                       surname="Fielding"/>
               <author fullname="Y. Lafon" initials="Y." role="editor" surname="Lafon"/>
               <author fullname="J. Reschke"
                       initials="J."
                       role="editor"
                       surname="Reschke"/>
               <date month="June" year="2014"/>
            </front>
            <seriesInfo name="RFC" value="7233"/>
            <seriesInfo name="DOI" value="10.17487/RFC7233"/>
         </reference>
         <reference anchor="RFC7405">
            <front>
               <title>Case-Sensitive String Support in ABNF</title>
               <author fullname="P. Kyzivat" initials="P." surname="Kyzivat"/>
               <date month="December" year="2014"/>
            </front>
            <seriesInfo name="RFC" value="7405"/>
            <seriesInfo name="DOI" value="10.17487/RFC7405"/>
         </reference>
         <reference anchor="RFC8174">
            <front>
               <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
               <author fullname="B. Leiba" initials="B." surname="Leiba"/>
               <date month="May" year="2017"/>
            </front>
            <seriesInfo name="BCP" value="14"/>
            <seriesInfo name="RFC" value="8174"/>
            <seriesInfo name="DOI" value="10.17487/RFC8174"/>
         </reference>
         <reference anchor="UNIX">
            <front>
               <title>The Single UNIX Specification, Version 2 - 6 Vol Set for UNIX 98</title>
               <author>
                  <organization>The Open Group</organization>
               </author>
               <date month="February" year="1997"/>
            </front>
         </reference>
         <reference anchor="NIST800-32"
                    target="https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-32.pdf">
            <front>
               <title>Introduction to Public Key Technology and the Federal PKI Infrastructure</title>
               <author>
                  <organization>National Institute of Standards and Technology, U.S. Department of Commerce</organization>
               </author>
               <date month="February" year="2001"/>
            </front>
         </reference>
         <reference anchor="CMU-836068" target="https://www.kb.cert.org/vuls/id/836068/">
            <front>
               <title>MD5 Vulnerable to collision attacks</title>
               <author>
                  <organization>Carnagie Mellon University, Software Engineering Institute</organization>
               </author>
               <date day="31" month="December" year="2008"/>
            </front>
         </reference>
         <reference anchor="IACR-2019-459" target="https://eprint.iacr.org/2019/459.pdf">
            <front>
               <title>From Collisions to Chosen-Prefix Collisions Application to Full SHA-1</title>
               <author initials="G." surname="Leurent">
                  <organization>Inria, France</organization>
               </author>
               <author initials="T." surname="Peyrin">
                  <organization>Nanyang Technological University, Singapore; Temasek Laboratories, Singapore</organization>
               </author>
               <date day="06" month="May" year="2019"/>
            </front>
         </reference>
         <reference anchor="RFC4960">
            <front>
               <title>Stream Control Transmission Protocol</title>
               <author fullname="R. Stewart"
                       initials="R."
                       role="editor"
                       surname="Stewart"/>
               <date month="September" year="2007"/>
            </front>
            <seriesInfo name="RFC" value="4960"/>
            <seriesInfo name="DOI" value="10.17487/RFC4960"/>
         </reference>
         <reference anchor="RFC3864">
            <front>
               <title>Registration Procedures for Message Header Fields</title>
               <author fullname="G. Klyne" initials="G." surname="Klyne"/>
               <author fullname="M. Nottingham" initials="M." surname="Nottingham"/>
               <author fullname="J. Mogul" initials="J." surname="Mogul"/>
               <date month="September" year="2004"/>
            </front>
            <seriesInfo name="BCP" value="90"/>
            <seriesInfo name="RFC" value="3864"/>
            <seriesInfo name="DOI" value="10.17487/RFC3864"/>
         </reference>
      </references>
      <references title="Informative References">
         <reference anchor="RFC2818">
            <front>
               <title>HTTP Over TLS</title>
               <author fullname="E. Rescorla" initials="E." surname="Rescorla"/>
               <date month="May" year="2000"/>
            </front>
            <seriesInfo name="RFC" value="2818"/>
            <seriesInfo name="DOI" value="10.17487/RFC2818"/>
         </reference>
         <reference anchor="RFC7396">
            <front>
               <title>JSON Merge Patch</title>
               <author fullname="P. Hoffman" initials="P." surname="Hoffman"/>
               <author fullname="J. Snell" initials="J." surname="Snell"/>
               <date month="October" year="2014"/>
            </front>
            <seriesInfo name="RFC" value="7396"/>
            <seriesInfo name="DOI" value="10.17487/RFC7396"/>
         </reference>
         <reference anchor="SRI" target="https://www.w3.org/TR/2016/REC-SRI-20160623/">
            <front>
               <title>Subresource Integrity</title>
               <author initials="D." surname="Akhawe"/>
               <author initials="F." surname="Braun"/>
               <author initials="F." surname="Marier"/>
               <author initials="J." surname="Weinberger"/>
               <date day="23" month="June" year="2016"/>
            </front>
            <seriesInfo name="W3C Recommendation" value="REC-SRI-20160623"/>
         </reference>
         <reference anchor="RFC5789">
            <front>
               <title>PATCH Method for HTTP</title>
               <author fullname="L. Dusseault" initials="L." surname="Dusseault"/>
               <author fullname="J. Snell" initials="J." surname="Snell"/>
               <date month="March" year="2010"/>
            </front>
            <seriesInfo name="RFC" value="5789"/>
            <seriesInfo name="DOI" value="10.17487/RFC5789"/>
         </reference>
      </references>
      <section anchor="faq" title="FAQ">
         <t>
            <list style="numbers">
               <t>Why remove all references to content-md5? <vspace blankLines="1"/> Those were unnecessary to understanding and using this spec.</t>
               <t>Why remove references to instance manipulation? <vspace blankLines="1"/> Those were unnecessary for correctly using and applying the spec. An example with Range Request is more than enough. This doc uses the term “partial representation” which should group all those cases.</t>
               <t>How to use <spanx style="verb">Digest</spanx> with <spanx style="verb">PATCH</spanx> method? <vspace blankLines="1"/> See <xref target="acting-on-resources"/>.</t>
               <t>Why remove references to delta-encoding? <vspace blankLines="1"/> Unnecessary for a correct implementation of this spec. The revised spec can be nicely adapted to “delta encoding”, but all the references here to delta encoding don’t add anything to this RFC. Another job would be to refresh delta encoding.</t>
               <t>Why remove references to Digest Authentication? <vspace blankLines="1"/> This RFC seems to me completely unrelated to Digest Authentication but for the word “Digest”.</t>
               <t>What changes in <spanx style="verb">Want-Digest</spanx>? <vspace blankLines="1"/> We allow to use the <spanx style="verb">Want-Digest</spanx> in responses to advertise the supported digest-algorithms and the inability to accept requests with unsupported digest-algorithms.</t>
               <t>Does this spec changes supported algorithms? <vspace blankLines="1"/> This RFC updates <xref target="RFC5843"/> which is still delegated for all algorithms updates, and adds two more algorithms: ID-SHA-256 and ID-SHA-512 which allows to send a checksum of a resource representation with no content codings applied.</t>
            </list>
         </t>
      </section>
      <section anchor="acknowledgements" numbered="false" title="Acknowledgements">
         <t>The vast majority of this document is inherited from <xref target="RFC3230"/>, so thanks to J. Mogul and A. Van Hoff for their great work. The original idea of refreshing this document arose from an interesting discussion with M. Nottingham, J. Yasskin and M. Thomson when reviewing the MICE content coding.</t>
      </section>
      <section anchor="code-samples" numbered="false" title="Code Samples">
         <t>
            <spanx>RFC Editor: Please remove this section before publication.</spanx>
         </t>
         <t>How can I generate and validate the Digest values shown in the examples throughout this document?</t>
         <t>The following python3 code can be used to generate digests for json objects using SHA algorithms for a range of encodings. Note that these are formatted as base64. This function could be adapted to other algorithms and should take into account their specific formatting rules.</t>
         <figure>
            <artwork>
import base64, json, hashlib, brotli


def digest(item, encoding=lambda x: x, algorithm=hashlib.sha256):
    json_bytes = json.dumps(item).encode()
    content_encoded = encoding(json_bytes)
    checksum_bytes = algorithm(content_encoded).digest()
    return base64.encodebytes(checksum_bytes).strip()


item = {"hello": "world"}

print("Identity encoding, sha256", digest(item))
# Out: Identity encoding, sha256 4REjxQ4yrqUVicfSKYNO/cF9zNj5ANbzgDZt3/h3Qxo=

print("Brotli encoding, sha256", digest(item, encoding=brotli.compress))
# Out: Brotli encoding, sha256 4REjxQ4yrqUVicfSKYNO/cF9zNj5ANbzgDZt3/h3Qxo=

print("Identity encoding, sha512", digest(item, algorithm=hashlib.sha512))
# Out: Identity encoding, sha512 b'WZDPaVn/7XgHaAy8pmojAkGWoRx2UFChF41A2svX+TaPm+AbwAgBWnrIiYllu7BNNyealdVLvRwE\nmTHWXvJwew==\n'
</artwork>
         </figure>
      </section>
      <section anchor="changes" numbered="false" title="Changes">
         <t>
            <spanx>RFC Editor: Please remove this section before publication.</spanx>
         </t>
         <section anchor="since-draft-ietf-httpbis-digest-headers-00"
                  title="Since draft-ietf-httpbis-digest-headers-00">
            <t>
               <list style="symbols">
                  <t>Align title with document name</t>
                  <t>Add id-sha-* algorithm examples #880</t>
                  <t>Reference <xref target="RFC6234"/> and <xref target="RFC3174"/> instead of FIPS-1</t>
                  <t>Deprecate MD5</t>
                  <t>Obsolete ADLER-32 but don’t forbid it #828</t>
                  <t>Update CRC32C value in IANA table #828</t>
                  <t>Use when acting on resources (POST, PATCH) #853</t>
                  <t>Added Relationship with SRI, draft Use Cases #868, #971</t>
               </list>
            </t>
         </section>
      </section>
   </back>
</rfc>
