<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc [
  <!ENTITY MAY "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>MAY</bcp14>">
  <!ENTITY MUST "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>MUST</bcp14>">
  <!ENTITY MUST-NOT "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>MUST NOT</bcp14>">
  <!ENTITY OPTIONAL "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>OPTIONAL</bcp14>">
  <!ENTITY RECOMMENDED "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>RECOMMENDED</bcp14>">
  <!ENTITY REQUIRED "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>REQUIRED</bcp14>">
  <!ENTITY SHALL "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>SHALL</bcp14>">
  <!ENTITY SHALL-NOT "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>SHALL NOT</bcp14>">
  <!ENTITY SHOULD "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>SHOULD</bcp14>">
  <!ENTITY SHOULD-NOT "<bcp14 xmlns='http://purl.org/net/xml2rfc/ext'>SHOULD NOT</bcp14>">
]>
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<?rfc toc="yes" ?>
<?rfc tocdepth="3" ?>
<?rfc tocindent="no" ?>
<?rfc symrefs="yes" ?>
<?rfc sortrefs="no"?>
<?rfc iprnotified="no" ?>
<?rfc strict="yes" ?>
<?rfc compact="yes" ?>
<?rfc comments="yes" ?>
<?rfc inline="yes" ?>
<?rfc rfcedstyle="yes" ?>
<rfc number="2818" category="info">
 <front>
  <title>HTTP Over TLS</title>
  <author initials="E." surname="Rescorla" fullname="Eric Rescorla">
   <organization>RTFM, Inc.</organization>
   <address>		
      <postal>
        <street>30 Newell Road, #16</street>
        <city>East Palo Alto</city><region>CA</region><code>94303</code>
      </postal>
      <phone>(650) 328-8631</phone>
      <email>ekr@rtfm.com</email>	
  	</address>
  </author>
  <date month="May" year="2000"/>

  <abstract>
  <t>
   This memo describes how to use TLS to secure HTTP connections over
   the Internet. Current practice is to layer HTTP over SSL (the
   predecessor to TLS), distinguishing secured traffic from insecure
   traffic by the use of a different server port. This document
   documents that practice using TLS. A companion document describes a
   method for using HTTP/TLS over the same port as normal HTTP
   [RFC2817].
  </t>
  </abstract>

 </front>

 <middle>

<section title="Introduction">
<t>
   HTTP <xref target="RFC2616"/> was originally used in the clear on the Internet.
   However, increased use of HTTP for sensitive applications has
   required security measures. SSL, and its successor TLS <xref target="RFC2246"/> were
   designed to provide channel-oriented security. This document
   describes how to use HTTP over TLS.
</t>

<section title="Requirements Terminology">
<t>
   Keywords "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT" and
   "MAY" that appear in this document are to be interpreted as described
   in <xref target="RFC2119"/>.
</t>
</section>

</section>

<section title="HTTP Over TLS">
<t>
   Conceptually, HTTP/TLS is very simple. Simply use HTTP over TLS
   precisely as you would use HTTP over TCP.
</t>

<section title="Connection Initiation">
<t>
   The agent acting as the HTTP client should also act as the TLS
   client.  It should initiate a connection to the server on the
   appropriate port and then send the TLS ClientHello to begin the TLS
   handshake. When the TLS handshake has finished. The client may then
   initiate the first HTTP request.  All HTTP data &MUST; be sent as TLS
   "application data".  Normal HTTP behavior, including retained
   connections should be followed.
</t>
</section>

<section title="Connection Closure">
<t>
   TLS provides a facility for secure connection closure. When a valid
   closure alert is received, an implementation can be assured that no
   further data will be received on that connection.  TLS
   implementations &MUST; initiate an exchange of closure alerts before
   closing a connection. A TLS implementation &MAY;, after sending a
   closure alert, close the connection without waiting for the peer to
   send its closure alert, generating an "incomplete close".  Note that
   an implementation which does this &MAY; choose to reuse the session.
   This &SHOULD; only be done when the application knows (typically
   through detecting HTTP message boundaries) that it has received all
   the message data that it cares about.
</t>
<t>
   As specified in <xref target="RFC2246"/>, any implementation which receives a
   connection close without first receiving a valid closure alert (a
   "premature close") &MUST-NOT; reuse that session.  Note that a
   premature close does not call into question the security of the data
   already received, but simply indicates that subsequent data might
   have been truncated. Because TLS is oblivious to HTTP
   request/response boundaries, it is necessary to examine the HTTP data
   itself (specifically the Content-Length header) to determine whether
   the truncation occurred inside a message or between messages.
</t>

<section title="Client Behavior">
<t>
   Because HTTP uses connection closure to signal end of server data,
   client implementations &MUST; treat any premature closes as errors and
   the data received as potentially truncated.  While in some cases the
   HTTP protocol allows the client to find out whether truncation took
   place so that, if it received the complete reply, it may tolerate
   such errors following the principle to "[be] strict when sending and
   tolerant when receiving" [RFC1958], often truncation does not show in
   the HTTP protocol data; two cases in particular deserve special note:
</t>
<t><list><t>
     A HTTP response without a Content-Length header. Since data length
     in this situation is signalled by connection close a premature
     close generated by the server cannot be distinguished from a
     spurious close generated by an attacker.
</t><t>
     A HTTP response with a valid Content-Length header closed before
     all data has been read. Because TLS does not provide document
     oriented protection, it is impossible to determine whether the
     server has miscomputed the Content-Length or an attacker has
     truncated the connection.
</t></list></t>
<t>
   There is one exception to the above rule. When encountering a
   premature close, a client &SHOULD; treat as completed all requests for
   which it has received as much data as specified in the Content-Length
   header.
</t>
<t>
   A client detecting an incomplete close &SHOULD; recover gracefully.  It
   &MAY; resume a TLS session closed in this fashion.
</t>
<t>
   Clients &MUST; send a closure alert before closing the connection.
   Clients which are unprepared to receive any more data &MAY; choose not
   to wait for the server's closure alert and simply close the
   connection, thus generating an incomplete close on the server side.
</t>
</section>

<section title="Server Behavior">
<t>
   RFC 2616 permits an HTTP client to close the connection at any time,
   and requires servers to recover gracefully.  In particular, servers
   &SHOULD; be prepared to receive an incomplete close from the client,
   since the client can often determine when the end of server data is.
   Servers &SHOULD; be willing to resume TLS sessions closed in this
   fashion.
</t>
<t>
   Implementation note: In HTTP implementations which do not use
   persistent connections, the server ordinarily expects to be able to
   signal end of data by closing the connection. When Content-Length is
   used, however, the client may have already sent the closure alert and
   dropped the connection.
</t>
<t>
   Servers &MUST; attempt to initiate an exchange of closure alerts with
   the client before closing the connection. Servers &MAY; close the
   connection after sending the closure alert, thus generating an
   incomplete close on the client side.
</t>
</section>
</section>

<section title="Port Number">
<t>
   The first data that an HTTP server expects to receive from the client
   is the Request-Line production. The first data that a TLS server (and
   hence an HTTP/TLS server) expects to receive is the ClientHello.
   Consequently, common practice has been to run HTTP/TLS over a
   separate port in order to distinguish which protocol is being used.
   When HTTP/TLS is being run over a TCP/IP connection, the default port
   is 443. This does not preclude HTTP/TLS from being run over another
   transport. TLS only presumes a reliable connection-oriented data
   stream.
</t>
</section>

<section title="URI Format">
<iref item="https URI scheme" primary="true"/> 
<iref item="URI scheme" subitem="https" primary="true"/> 
<t>
   HTTP/TLS is differentiated from HTTP URIs by using the 'https'
   protocol identifier in place of the 'http' protocol identifier. An
   example URI specifying HTTP/TLS is:
</t>
<figure><artwork type="example">
  https://www.example.com/~smith/home.html
</artwork></figure>
</section>
</section>

<section title="Endpoint Identification">

<section title="Server Identity">
<t>
   In general, HTTP/TLS requests are generated by dereferencing a URI.
   As a consequence, the hostname for the server is known to the client.
   If the hostname is available, the client &MUST; check it against the
   server's identity as presented in the server's Certificate message,
   in order to prevent man-in-the-middle attacks.
</t>
<t>
   If the client has external information as to the expected identity of
   the server, the hostname check &MAY; be omitted. (For instance, a
   client may be connecting to a machine whose address and hostname are
   dynamic but the client knows the certificate that the server will
   present.) In such cases, it is important to narrow the scope of
   acceptable certificates as much as possible in order to prevent man
   in the middle attacks.  In special cases, it may be appropriate for
   the client to simply ignore the server's identity, but it must be
   understood that this leaves the connection open to active attack.
</t>
<t>
   If a subjectAltName extension of type dNSName is present, that &MUST;
   be used as the identity. Otherwise, the (most specific) Common Name
   field in the Subject field of the certificate &MUST; be used. Although
   the use of the Common Name is existing practice, it is deprecated and
   Certification Authorities are encouraged to use the dNSName instead.
</t>
<t>
   Matching is performed using the matching rules specified by
   <xref target="RFC2459"/>.  If more than one identity of a given type is present in
   the certificate (e.g., more than one dNSName name, a match in any one
   of the set is considered acceptable.) Names may contain the wildcard
   character * which is considered to match any single domain name
   component or component fragment. E.g., *.a.com matches foo.a.com but
   not bar.foo.a.com. f*.com matches foo.com but not bar.com.
</t>
<t>
   In some cases, the URI is specified as an IP address rather than a
   hostname. In this case, the iPAddress subjectAltName must be present
   in the certificate and must exactly match the IP in the URI.
</t>
<t>
   If the hostname does not match the identity in the certificate, user
   oriented clients &MUST; either notify the user (clients &MAY; give the
   user the opportunity to continue with the connection in any case) or
   terminate the connection with a bad certificate error. Automated
   clients &MUST; log the error to an appropriate audit log (if available)
   and &SHOULD; terminate the connection (with a bad certificate error).
   Automated clients &MAY; provide a configuration setting that disables
   this check, but &MUST; provide a setting which enables it.
</t>
<t>
   Note that in many cases the URI itself comes from an untrusted
   source. The above-described check provides no protection against
   attacks where this source is compromised. For example, if the URI was
   obtained by clicking on an HTML page which was itself obtained
   without using HTTP/TLS, a man in the middle could have replaced the
   URI.  In order to prevent this form of attack, users should carefully
   examine the certificate presented by the server to determine if it
   meets their expectations.
</t>
</section>

<section title="Client Identity">
<t>
   Typically, the server has no external knowledge of what the client's
   identity ought to be and so checks (other than that the client has a
   certificate chain rooted in an appropriate CA) are not possible. If a
   server has such knowledge (typically from some source external to
   HTTP or TLS) it &SHOULD; check the identity as described above.
</t>
</section>

</section>


 </middle>
 <back>
 
<references>

<reference anchor='RFC2459'>
  <front>
    <title abbrev='Internet Public Key Infrastructure'>Internet X.509 Public Key Infrastructure Certificate and CRL Profile</title>
    <author initials='R.' surname='Housley' fullname='Russell Housley'>
      <organization>SPYRUS</organization>
      <address><email>housley@spyrus.com</email></address>
    </author>
    <author initials='W.' surname='Ford' fullname='Warwick Ford'>
      <organization>VeriSign, Inc.</organization>
      <address><email>wford@verisign.com</email></address>
    </author>
    <author initials='T.' surname='Polk' fullname='Tim Polk'>
      <organization>NIST</organization>
      <address><email>wpolk@nist.gov</email></address>
    </author>
    <author initials='D.' surname='Solo' fullname='David Solo'>
      <organization>Citicorp</organization>
      <address><email>david.solo@citicorp.com</email></address>
    </author>
    <date year='1999' month='January' />
  </front>
  <seriesInfo name='RFC' value='2459' />
</reference>

<reference anchor="RFC2616">
  <front>
    <title>Hypertext Transfer Protocol -- HTTP/1.1</title>
    <author initials="R." surname="Fielding" fullname="R. Fielding">
      <organization>University of California, Irvine</organization>
      <address><email>fielding@ics.uci.edu</email></address>
    </author>
    <author initials="J." surname="Gettys" fullname="J. Gettys">
      <organization>W3C</organization>
      <address><email>jg@w3.org</email></address>
    </author>
    <author initials="J." surname="Mogul" fullname="J. Mogul">
      <organization>Compaq Computer Corporation</organization>
      <address><email>mogul@wrl.dec.com</email></address>
    </author>
    <author initials="H." surname="Frystyk" fullname="H. Frystyk">
      <organization>MIT Laboratory for Computer Science</organization>
      <address><email>frystyk@w3.org</email></address>
    </author>
    <author initials="L." surname="Masinter" fullname="L. Masinter">
      <organization>Xerox Corporation</organization>
      <address><email>masinter@parc.xerox.com</email></address>
    </author>
    <author initials="P." surname="Leach" fullname="P. Leach">
      <organization>Microsoft Corporation</organization>
      <address><email>paulle@microsoft.com</email></address>
    </author>
    <author initials="T." surname="Berners-Lee" fullname="T. Berners-Lee">
      <organization>W3C</organization>
      <address><email>timbl@w3.org</email></address>
    </author>
    <date month="June" year="1999"/>
  </front>
  <seriesInfo name="RFC" value="2616"/>
</reference>

<reference anchor="RFC2119">
  <front>
    <title>Key words for use in RFCs to Indicate Requirement Levels</title>
    <author initials="S." surname="Bradner" fullname="Scott Bradner">
      <organization>Harvard University</organization>
      <address><email>sob@harvard.edu</email></address>
    </author>
    <date month="March" year="1997"/>
  </front>
  <seriesInfo name="BCP" value="14"/>
  <seriesInfo name="RFC" value="2119"/>
</reference>

<reference anchor='RFC2246'>
  <front>
    <title>The TLS Protocol Version 1.0</title>
    <author initials='T.' surname='Dierks' fullname='Tim Dierks'>
    <organization>Certicom</organization>
    <address>
    <email>tdierks@certicom.com</email></address></author>
    <author initials='C.' surname='Allen' fullname='Christopher Allen'>
    <organization>Certicom</organization>
    <address>
    <email>callen@certicom.com</email></address></author>
    <date year='1999' month='January' />
  </front>
  <seriesInfo name='RFC' value='2246' />
</reference>

<reference anchor='RFC2817'>
  <front>
    <title>Upgrading to TLS Within HTTP/1.1</title>
    <author initials='R.' surname='Khare' fullname='R. Khare'>
      <organization />
    </author>
    <author initials='S.' surname='Lawrence' fullname='S. Lawrence'>
      <organization />
    </author>
    <date year='2000' month='May' />
  </front>
  <seriesInfo name='RFC' value='2817' />
</reference>

</references>
 
<section title="Security Considerations">
<t>
   This entire document is about security.
</t>
</section>

 
 </back>
</rfc>
