<?xml version="1.0"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
<rfc ipr="trust200902" docName="draft-bennish-httpbis-tldr-00" category="std">
<!--
useful resources:
- http://www.ietf.org/id-info/guidelines.html
- http://xml2rfc.tools.ietf.org/
- http://www.ietf.org/tools/idnits/
-->
<front>
	<title>Trusted Linker Download Redirection (TLDR)</title>
	<author initials="B.A." surname="Kennish" fullname="Ben A. Kennish">
		<organization>Bennish.net</organization>
		<address>
			<email>ben@kennish.net</email>
			<uri>http://www.bennish.net/</uri>
		</address>
	</author>

	<date month="April" year="2015" />

	<area>Applications</area>

	<keyword>HTTP</keyword>
	<keyword>Hypertext Transfer Protocol</keyword>
	<keyword>downloads</keyword>
	<keyword>verification</keyword>
	<keyword>integrity</keyword>
	<keyword>checksum</keyword>

	<abstract>
		<t>
		This document describes an HTTP extension that allows user agents to verify	downloaded
		data.  It provides a standardised way for an HTTPS URL (assumed trustworthy) to redirect
		to a non-HTTPS URL and give the user agent extra information about the resulting output
		(e.g. a downloaded file.) Once that is retrieved, it can check whether or not the data
		has been modified since the trustworthy site checked it (e.g. altered during transit or as a result of the destination site having been compromised.)
		</t>
	</abstract>
</front>
<middle>

	<section title="Introduction" anchor="introduction">
		<t>
		Transport Layer Security (TLS/SSL) <xref target="RFC-5246" /> can add an often much
		needed level of security to the Hypertext Transfer Protocol (HTTP)
		<xref target="RFC-7230" /> (a combination normally referred to as HTTPS) but the
		encryption algorithms are often too much of a strain for busy public file download
		servers, especially when arguably the data stream does not really need to be encrypted
		(the files are publicly accessible anyway).
		</t>
		<t>
		As a result, servers providing public file downloads, even potentially dangerous
		file types such as those with executable code, scripts, etc., often do not deliver
		the files using HTTPS.  However, this makes the downloads vulnerable to
		Man-in-the-Middle (MitM) attacks; an attacker could change the data during transit
		to serve the client with malware.
		</t>
		<t>
		Trusted Linker Download Redirection (TLDR) describes a process by which an (assumed
		trustworthy) HTTPS URL can redirect to a non-HTTPS download URL and give the user agent
		extra information about the file so that, once downloaded, the agent can check whether
		the file is the same one that the trustworthy site verified.
		</t>

		<section title="Conventions and Terminology" anchor="conventionsAndTerminology">
			<t>
			The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
			"SHOULD", "SHOULD NOT", "RECOMMENDED",  "MAY", and "OPTIONAL" in this
			document are to be interpreted as described in <xref target="RFC-2119" />
			</t>
			<t>
			<list style="hanging">
				<t hangText="Trusted Linker">
				The URL that provides the TLDR HTTP headers as it redirects the user agent to
				a new URL (using the "Location:" header).
				</t>
				<t hangText="The Link">
				The URL that the trusted linker redirects to.  Will be identical to 'Final
				Destination' unless the Link redirects elsewhere.
				</t>
				<t hangText="Final Destination">
				The final URL (not necessarily using HTTP) that provides the file data (may be
				identical to "The link")
				</t>
			</list>
			</t>
		</section>

	</section>

	<section title="Appropriate HTTP status codes" anchor="appropriateHTTPStatusCodes">
		<t>
		The TLDR headers SHOULD only be sent by the Trusted Link web server with responses that
		use one of the following HTTP status codes:

		<list style="symbols">
			<t>302 "Found"</t>
			<t>303 "See Other"</t>
			<t>307 "Temporary Redirect"</t>
		</list>
		</t>
		<t>
		Note that the permanent redirects (such as 301 "Moved Permanently" and 308 "Permanent
		Redirect") are not included in the list.  These status codes instruct user agents to
		send all future requests to the URL provided in the "Location" header, thereby bypassing
		the Trusted Linker completely. It seems nonsensical to provide a TLDR service for the
		user agent's first request only!
		</t>
	</section>

	<section title="Redirection with plain HTTP" anchor="redirectionWithPlainHTTP">
		<t>
		Ideally, servers implementing TLDR should do so over the HTTPS protocol and not plain
		HTTP.  If the headers are delivered without the safety that TLS/SSL provides, TLDR
		cannot detect Man in the Middle (MitM) attacks.
		</t>
		<t>
		However, it does provides a bit of extra protection if used over plain HTTP assuming
		no MitM. For example, if the Final Destination server becomes compromised or for any
		other reason starts providing a different file to the one that it was before, the
		checksum will not match and this will be detected.
		</t>
	</section>

	<section title="Checksum-related headers" anchor="checksumRelatedHeaders">
		<t>
		These HTTP response headers are all OPTIONAL but a web server must provide at least one
	    to be a Trusted Linker. It should provide as many of them as possible in order to give
		user agents the biggest choice. To avoid ambiguity, a web server MUST NOT return more
		than one TLDR header with the same name.
		</t>
		<t>
		When more than one checksum is provided by the server, it is not recommended for a user
		agent to use more than one of the checksums provided. It should select one; preferably
		the checksum function considered most secure at the time. The method by which the user
		agent selects a hash function MAY be user configurable.
		</t>
		<t>
		All checksums are calculated on the complete file contents. If the file is delivered to
		the client using any kind of transfer encoding (such as HTTP gzip, chunked, etc.), the
		checksums MUST be calculated on the decoded data.  Any kind of transfer mechanism that
		results in ambiguous output data (such as "ASCII mode" FTP) is not supported.
		</t>
		<t>
		The examples given below each show the server replying with a different value for the
		HTTP status code. This is just to illustrate the different codes that can use TLDR and
		bears no relationship to the checksum hash function used.
		</t>
		<t>
		While the examples with the longer header values are shown split to multiple lines, this
		is to aid the readability of this document and it is recommended that the actual header
		values are kept on a single line.
		</t>

		<section title="Location-Checksum-MD5">
			<t>
			Location-Checksum-MD5 = "Location-Checksum-MD5: " md5-checksum
			</t>
			<t>
			md5-checksum should be a string giving the expected 128-bit MD5 message
			digest for the resulting downloaded file (see <xref target="RFC-1321" />).
			</t>
			<section title="Example">
			<t>
			<figure>
				<artwork>
HTTP/1.0 302 Moved Temporarily
Location: http://www.example.com/files/download.tar.gz
Location-Checksum-MD5: ccca8352847856cd4c2df77ce675de2b</artwork>
			</figure>
			</t>
			</section>
		</section>

		<section title="Location-Checksum-SHA1">
			<t>
			Location-Checksum-SHA1 = "Location-Checksum-SHA1: " sha1-checksum
			</t>
			<t>
				sha1-checksum should be a string giving the expected 160bit SHA1 message
				digest for the resulting downloaded file (see <xref target="RFC-3174" />).
			</t>
			<section title="Example">
			<t>
			<figure>
				<artwork>
HTTP/1.1 302 Found
Location: http://www.example.com/files/download.tar.gz
Location-Checksum-SHA1: d98eaf66de93d9512958d6c7f5ed58d059dea53f</artwork>
			</figure>
			</t>
			</section>
		</section>

		<section title="Location-Checksum-SHA256">
			<t>
			Location-Checksum-SHA256 = "Location-Checksum-SHA256: " sha256-checksum
			</t>
			<t>
				sha256-checksum should be a string giving the expected 256bit SHA-256 message
				digest for the resulting downloaded file (see <xref target="RFC-6234" />).
			</t>
			<section title="Example">
			<t>
			<figure>
				<artwork>
HTTP/1.1 303 See Other
Location: http://www.example.com/files/download.tar.gz
Location-Checksum-SHA256: d9c30fccbfd25469b41c1e2c68b3b1a8f2a241e1808
 07d6beb3bc63ddfef6ff2</artwork>
			</figure>
			</t>
			</section>
		</section>

		<section title="Location-Checksum-SHA512">
			<t>
			Location-Checksum-SHA512 = "Location-Checksum-SHA512: " sha512-checksum
			</t>
			<t>
				sha512-checksum should be a string giving the expected 512bit SHA-512 message
				digest for the resulting downloaded file (see <xref target="RFC-6234" />).
			</t>

			<section title="Example">
			<t>
			<figure>
				<artwork>
HTTP/1.1 307 Temporary Redirect
Location: http://www.example.com/files/download.tar.gz
Location-Checksum-SHA5126: a5555882da0419d98dd6b098e616aa66d7a5c13e54
 9c2ab59dd7634ed07e379fafb4370925f65ff08d0cd50a19691acb6671a8d30b5298
 0130dcc1bbfaf6a351</artwork>
			</figure>
			</t>
			</section>
		</section>
	</section>

	<section title="Appropriate user agent responses">

		<section title="On starting a TLDR download">
			<t>
			The user agent MAY display some kind of notification to the user upon starting
			a download using TLDR.  However, it SHOULD NOT show any notification unless
			the Trusted Linker used HTTPS (because it might give the user a false sense
			of safety.)
			</t>
		</section>

		<section title="On completing a TLDR download">
			<t>
			Once the file has completely downloaded, the user agent calculates a checksum
			using its choice of the provided message digest algorithms and compares it to the
			one provided by the Trusted Linker. It then takes appropriate action depending on
			the result:
			</t>

			<section title="When the checksums match">
				<t>
				If the original TLDR checksum headers were sent using HTTPS, user agents
				MAY notify the user that the downloaded file was as expected according to the
				Trusted Linker. However, if they do, they SHOULD clearly provide the user with
				enough information about the Trusted Linker URL so that they can decide whether
				or not they do actually trust it (e.g. the fully qualified domain name). See the
				Security Considerations section for an explanation as to why this is necessary.
				</t>
				<t>
				If the original TLDR checksum headers were sent over plain HTTP, user agents
				SHOULD NOT give any positive feedback to the user because of the possibility of
				a Man in the Middle (MitM) attack.
				</t>
			</section>

			<section title="When the checksums do not match">
				<t>
				All the statements in this section apply even if the TLDR checksum headers were
				sent over plain HTTP.  Any checksum mismatch is a cause for alarm.
				</t>
				<t>
				If the checksums do not match, the user agent MUST give some kind of feedback to
				warn the user that something is wrong.
				</t>
				<t>
				The user agent SHOULD also remove or quarantine the downloaded file to prevent
				it being used accidentally.
				</t>
			</section>
		</section>

	</section>

	<section title="TLDR multiple times in a single request chain">
		<t>
		It is possible for a Trusted Linker to redirect to a Link that redirects again.
		There could be any number of redirections and any of the hops along this redirect chain
		could also provide new TLDR headers. If this happens, a user agent SHOULD simply ignore
		these headers. The first hop in a chain of redirects that provides TLDR is considered
		the most trust-worthy.
		</t>
	</section>

	<section title="In practice">
		<t>
		The author has created a prototype Add-on for the Mozilla Firefox web browser which
		demonstrates TLDR in action. Links to download the Add-on and some example download
		links that implement TLDR can be found at <xref target="TLDR-Demo">a page on the
		author's website</xref>.
		</t>
	</section>

	<section title="Possible future extension">
		<t>
		TLDR could be extended in the future to take advantage of other types of verification.
		Perhaps <eref target="http://www.openpgp.org">OpenPGP</eref> related HTTP response
		headers could be used, possibly by providing one or more trusted public key fingerprints
		along with the URL of a signature for the file. I hope to explore this idea in future
		revisions of this document.
		</t>
		<!--
			Benefits of OpenPGP:
			- the file contents might change, but as long as the signature is updated and remains
			  valid, the Trusted linker need not change anything
		   - we could silently create an _assumed_ web of trust based on browser habits!
		-->
	</section>

	<section title="TL;DR">
		<t>
		The author is aware of the existing acronym "TL;DR" meaning "Too Long; Didn't Read" and
		feels that it is appropriate that this proposed standard has the same acronym as it
		aptly describes the way most people probably feel when they see instructions on how to
		manually verify the integrity of their downloads such as
		<eref target="http://httpd.apache.org/download.cgi#verify">these instructions on
		httpd.apache.org.</eref>  The author would like to make it clear that he is not
		criticising these instructions in any way but instead pointing out that a manual
		verification process is quite lengthy and tedious, and therefore often skipped completely.
		</t>
	</section>

	<section title="IANA Considerations">
		<section title="Header Field Registrations">
			<t>
			[TO BE REMOVED: HTTP header fields should be registered within the
			"Message Headers" registry maintained at
			https://www.iana.org/assignments/message-headers/ ]
			</t>
			<t>
			This document defines a number of HTTP header fields, so their associated registry
			entries shall be added according to the permanent registrations below (see [BCP90]):
			</t>
			<t>
			<figure>
				<artwork>
+--------------------------+----------+----------+-------------+
| Header Field Name        | Protocol | Status   | Reference   |
+--------------------------+----------+----------+-------------+
| Location-Checksum-MD5    | http     | standard | Section 4.1 |
| Location-Checksum-SHA1   | http     | standard | Section 4.2 |
| Location-Checksum-SHA256 | http     | standard | Section 4.3 |
| Location-Checksum-SHA512 | http     | standard | Section 4.4 |
+--------------------------+----------+----------+-------------+</artwork>
			</figure>
			</t>
			<t>
				The change controller is: "IETF (iesg@ietf.org) - Internet Engineering Task
				Force". This specification defines a number of response header fields for the
				Hypertext Transfer Protocol (HTTP) that has been registered with the Internet
   				Assigned Numbers Authority (IANA) following the "Registration Procedures for
   				Message Header Fields" [RFC3864]. <!-- reference ? -->
			</t>
		</section>
	</section>

	<section title="Security Considerations">
		<t>
		The purpose of TLDR is to allow for an automated process of file verification assuming
		a Trusted Linker.  Provided the Trusted Linker can be truly trusted, the method is sound.
		</t>
		<section title="Trusted Linker">
			<t>
			The most important consideration is whether or not the the Trusted Linker is
			actually trustworthy.  If it is not, then TLDR offers no benefit. As a result, user
			agents that implement TLDR SHOULD make it clear to the user which https:// URL is
			being trusted.
			</t>
			<t>
			<figure>
				<preamble>
				This is necessary because a string of redirects (using HTTP, JavaScript, or
				any other method) could trick the user into confusing the actual Trusted Linker
				for a different site:
				</preamble>
				<artwork>
https://trusted.example.com/files/file.tar.gz
   |=== redirects in some way to ===&gt;
http://hacked.example.org/files/file.tar.gz
   |=== which then redirects to ===&gt;
https://evil.example.net/tldr/file.tar.gz
   |=== which redirects using TLDR to ===&gt;
http://hacked.example.org/filez/file.tar.gz
   (which is malware and downloads with TLDR)</artwork>
   				<postamble>
				In the example, without information to the contrary, the user may incorrectly
				assume that the Trusted Linker is trusted.example.com but it is actually
				evil.example.net
   				</postamble>
   			</figure>
			</t>
		</section>

		<section title="Man in the Middle">
			<t>
			As stated in <xref target="redirectionWithPlainHTTP" />, TLDR only provides
			detection of modification by a Man in the Middle (MitM) if the checksum headers are
			delivered via HTTPS. If they are instead delivered by plain HTTP, they can be
			modified in transit by the MitM such that the checksums verify a different file of
			the MitM's choosing which they can then deliver to the user agent.
			</t>
		</section>

		<section title="Limitations">
			<t>
			Although TLDR can help to detect when there is an integrity problem with a file
			download, it offers no means to retrieve a verified file should this situation
			arise.
			</t>
			<t>
			How can a Trusted Linker obtain the file in a secure way such that they can be sure
			of its integrity before calculating the checksum?  This is somewhat outside of the
			scope of this document but a few options include:
			<list style="symbols">
				<t>
				The Trusted Linker may have downloaded the file using HTTPS
				</t>
				<t>
				The Trusted Linker may have verified the file using OpenPGP and an established
				Web of Trust.
				</t>
				<t>
				The Trusted Linker and Final Destination servers may belong to the same
				organisation, e.g. the Trusted Linker could be https://trusted.example.com/tldr/software.tar.gz and
				the Final Destination could be http://trusted.example.com/files/software.tar.gz
				</t>
			</list>
			</t>
		</section>
	</section>
</middle>
<back>
	<!--
	References MUST be split into normative and informative sections
	(see http://www.rfc-editor.org/policy.html).

	A. All references must be stable and resolvable
	B. A bare HTTP URL is not generally considered a stable reference.
    For Web-only documents, adding a reference number, title and/or an author will help make the
    reference more stable.
    C. Judgment can be used here; the stability of normative references is even more important
    than the stability of informative references.
	D. In case of references to Internet-Drafts, use the format: author, "title" (I-D file name).
    Normative references to I-Ds will cause a standards-track or BCP document to wait in the
    RFC-Editor queue (see RFC-Editor queue) for the referenced I-Ds to be published as RFCs.
	E. Normative and informative references to non-IETF documents are permitted. However, it is
	best to minimize such normative references, because assessing their status when the IETF
	document advances on the standards-track is very difficult. It is important to use the exact
	title, author name(s), organization and publication date.
	-->
    <references title='Normative References'>
    	<!-- Normative references specify documents that must be read to understand or implement
    	the technology in the new RFC, or whose technology must be present for the technology in
    	the new RFC to work.-->

    	<!-- avoid non-IETF normative references -->
    	<reference anchor="RFC-2119">
    		<front>
    			<title>
    				RFC 2119 - Key words for use in RFCs to Indicate Requirement Levels
    			</title>
    			<author initials="S." surname="Bradner" fullname="Scott Bradner">
    				<organization>
    					Harvard University
    				</organization>
    			</author>
    			<date month="March" year="1997" />
    		</front>
    		<seriesInfo name="RFC" value="2119" />
    	</reference>

    	<reference anchor="RFC-7230">
    		<front>
    			<title>RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing</title>

    			<author initials="R.T." surname="Fielding" fullname="Roy T. Fielding">
    				<organization>
    					Adobe Systems Incorporated
    				</organization>
    			</author>
    			<author initials="J.F." surname="Reschke" fullname="Julian F. Reschke">
    				<organization>
    					greenbytes GmbH
    				</organization>
    			</author>
    			<date month="June" year="2014" />
    		</front>
    		<seriesInfo name="RFC" value="7230" />
    	</reference>

    	<reference anchor="RFC-5246">
    		<front>
    			<title>RFC 5246 - The Transport Layer Security (TLS) Protocol Version 1.2</title>
    			<author initials="T." surname="Dierks" fullname="Tim Dierks">
    				<organization>
    					Independent
    				</organization>
    			</author>
    			<author initials="E." surname="Rescorla" fullname="Eric Rescorla">
    				<organization>
    					RTFM, Inc.
    				</organization>
    			</author>
    			<date month="August" year="2008" />
    		</front>
    		<seriesInfo name="RFC" value="5246" />
    	</reference>

    </references>
    <references title='Informative References'>
    	<!-- An informative reference is not normative; rather, it only provides additional
    	information. For example, an informative reference might provide background or
    	historical information. Informative references are not required to implement the
    	technology in the RFC. -->

    	<!-- TODO: link to OpenPGP RFC? -->

   		<reference anchor="RFC-1321">
    		<front>
    			<title>RFC 1321 - The MD5 Message-Digest Algorithm</title>
    			<author initials="R." surname="Rivest" fullname="Ronald L. Rivest">
    				<organization>
    					MIT Laboratory for Computer Science and RSA Data Security, Inc.
    				</organization>
    			</author>
    			<date month="April" year="1992" />
    		</front>
    		<seriesInfo name="RFC" value="1321" />
    	</reference>

    	<reference anchor="RFC-3174">
    		<front>
    			<title>RFC 3174 - US Secure Hash Algorithm 1 (SHA1)</title>
    			<author initials="D." surname="Eastlake 3rd" fullname="Donald E. Eastlake 3rd">
    				<organization>
    					Motorola
    				</organization>
    			</author>
    			<author initials="P." surname="Jones" fullname="Paul E. Jones">
    				<organization>
    					Cisco Sytems
    				</organization>
    			</author>
    			<date month="September" year="2001" />
    		</front>
    		<seriesInfo name="RFC" value="3174" />
    	</reference>

    	<reference anchor="RFC-6234">
    		<front>
    			<title>
    				RFC 6234 - US Secure Hash Algorithms (SHA and SHA-based HMAC and HKDF)
    			</title>
    			<author initials="D." surname="Eastlake 3rd" fullname="Donald E. Eastlake 3rd">
    				<organization>
    					Huawei
    				</organization>
    			</author>
    			<author initials="T." surname="Hansen" fullname="Tony Hansen">
    				<organization>
    					AT&amp;T Labs
    				</organization>
    			</author>
    			<date month="May" year="2011" />
    		</front>
    		<seriesInfo name="RFC" value="6234" />
    	</reference>

    	<reference anchor="TLDR-Demo" target="https://www.bennish.net/tldr/">
    		<front>
    			<title>Trusted Linker Download Redirection (TLDR)</title>
    			<author initials="B.A." surname="Kennish" fullname="Ben A. Kennish">
    				<organization>
    					Bennish.net
    				</organization>
    			</author>
    			<date month="September" year="2014" />
    		</front>
    	</reference>

    </references>
</back>
</rfc>
