<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc PUBLIC "-//IETF//DTD RFC 2629//EN" "http://xml.resource.org/authoring/rfc2629.dtd" [
  <!ENTITY rfc2119 PUBLIC "" "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml">
  <!ENTITY rfc2616 PUBLIC "" "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2616.xml">
  <!ENTITY rfc2617 PUBLIC "" "http://xml.resource.org/public/rfc/bibxml/reference.RFC.2617.xml">
  <!ENTITY rfc3339 PUBLIC "" "http://xml.resource.org/public/rfc/bibxml/reference.RFC.3339.xml">
  <!ENTITY rfc5246 PUBLIC "" "http://xml.resource.org/public/rfc/bibxml/reference.RFC.5246.xml">
]>
<?xml-stylesheet type="text/xsl" href="rfc2629.xsl" ?>
<?rfc compact="yes" ?>
<?rfc subcompact="no" ?>
<?rfc toc="yes" ?>
<?rfc sortrefs="yes" ?>
<?rfc symrefs="yes" ?>
<rfc category="std" ipr="trust200902" submissionType="independent" 
     docName="draft-cavage-http-signatures-01">
<front>
 <title>HTTP Signatures</title>

 <author initials="M.C." surname="Cavage" fullname="Mark Cavage">
  <organization>Joyent</organization>
  <address>
   <postal>
    <street>One Embarcadero Center</street>
    <street>9th Floor</street>
    <city>San Francisco</city> <region>CA</region>
    <code>94111</code>
    <country>US</country>
   </postal>
   <phone>+1 415 400 0626 </phone>
   <email>mark.cavage@joyent.com</email>
   <uri>http://www.joyent.com/</uri>
  </address>
 </author>

 <author initials="M.S." surname="Sporny" fullname="Manu Sporny">
  <organization>Digital Bazaar</organization>
  <address>
   <postal>
    <street>1700 Kraft Drive</street>
    <street>Suite 2408</street>
    <city>Blacksburg</city> <region>VA</region>
    <code>24060</code>
    <country>US</country>
   </postal>
   <phone>+1 540 961 4469</phone>
   <email>msporny@digitalbazaar.com</email>
   <uri>http://manu.sporny.org/</uri>
  </address>
 </author>

 <date month="February" year="2014" />
 <area>Security</area>
 <workgroup></workgroup>
 <keyword>HTTP</keyword>
 <keyword>digital signature</keyword>
 <keyword>PKI</keyword>
 <abstract>
 <t>
When communicating over the Internet using the HTTP protocol, it is often
desirable to be able to securely verify the sender of a message as well as
ensure that the message was not tampered with during transit. This document 
describes a way to add origin authentication and message integrity to HTTP 
messages.
 </t>
 </abstract>
</front>

<middle>

 <section anchor="intro" title="Introduction">
  <t>
This protocol is intended to provide a standard way for clients to sign HTTP
requests.  <xref target="RFC2617">RFC 2617</xref> (HTTP Authentication) 
defines Basic and Digest authentication mechanisms, and 
<xref target="RFC5246">RFC 5246</xref> (TLS 1.2) 
defines client-auth, both of which are widely
employed on the Internet today.  However, it is common place that the burdens of
PKI prevent web service operators from deploying that methodoloy, and so many
fall back to Basic authentication, which has poor security characteristics.
  </t>

  <t>
Additionally, OAuth provides a fully-specified alternative for authorization
of web service requests, but is not (always) ideal for machine to machine
communication, as the key acquisition steps (generally) imply a fixed
infrastructure that may not make sense to a service provider (e.g., symmetric
keys).
  </t>

  <t>
Several web service providers have invented their own schemes for signing
HTTP requests, but to date, none have been placed in the public domain as a
standard.  This document serves that purpose.  There are no techniques in this
proposal that are novel beyond previous art, however, this aims to be a simple
mechanism for signing these requests.
  </t> 
 
 </section>
 
  <section anchor="auth" title="Signature Authentication Scheme">

  <t>
The "signature" authentication scheme is based on the model that the client must
authenticate itself with a digital signature produced by either a private
asymmetric key (e.g., RSA) or a shared symmetric key (e.g., HMAC).  The scheme
is parameterized enough such that it is not bound to any particular key type or
signing algorithm.  However, it does explicitly assume that clients can send an
HTTP `Date` header.
  </t>
  
  <section anchor="header" title="Authorization Header">

   <t>
The client is expected to send an Authorization header (as defined in RFC 2617)
with the following parameterization:
   </t>

   <figure>
    <artwork>
credentials := "Signature" SP params
params := keyId "," algorithm [", " headers] [", " ext] ", " signature

keyId := "keyId" "=" plain-string
algorithm := "algorithm" "=" DQUOTE ( rsa-sha1 / rsa-sha256 / rsa-sha512 / 
                                      dsa-sha1 / hmac-sha1 / hmac-sha256 /
                                      hmac-sha512 )
                             DQUOTE
headers := "headers" "=" plain-string
ext := "ext" "=" plain-string 
signature := "signature" "=" plain-string 

plain-string   = DQUOTE *( %x20-21 / %x23-5B / %x5D-7E ) DQUOTE
    </artwork>
   </figure>

   <section anchor="params" title="Signature Parameters">

    <t>
The following section details the signature parameters of the Authorization
Header.
    </t>

    <section anchor="keyId" title="keyId">
     <t>
REQUIRED.  The `keyId` field is an opaque string that the server can use to look
up the component they need to validate the signature.  It could be an SSH key
fingerprint, an LDAP DN, etc.  Management of keys and assignment of `keyId` is
out of scope for this document.
     </t>
    </section>
    
    <section anchor="algorithm" title="algorithm">

     <t>
REQUIRED. The `algorithm` parameter is used if the client and server agree on a
non-standard digital signature algorithm.  The full list of supported signature
mechanisms is listed below.
     </t>
    </section>
    
    <section anchor="headers" title="headers">

     <t>
OPTIONAL.  The `headers` parameter is used to specify the list of HTTP headers
used to sign the request.  If specified, it should be a quoted list of HTTP
header names, separated by a single space character.  By default, only one
HTTP header is signed, which is the `Date` header.  Note that the list MUST be
specified in the order the values are concatenated together during signing. To
include the HTTP request line in the signature calculation, use the special
`request-line` value.  While this is overloading the definition of `headers` in
HTTP linguism, the request-line is defined in 
<xref target="RFC2616">RFC 2616</xref>, and as the outlier from
headers in useful signature calculation, it is deemed simpler to use
`request-line` than to add a separate parameter for it.
     </t>
    </section>

    <section anchor="extensions" title="extensions">
     <t>
OPTIONAL.  The `extensions` parameter is used to include additional information
which is covered by the request.  The content and format of the string is out of
scope for this document, and expected to be specified by implementors.
     </t>
    </section>
    
    <section anchor="signature" title="signature">
     <t>
REQUIRED.  The `signature` parameter is a `Base64` encoded digital signature
generated by the client. The client uses the `algorithm` and `headers` request
parameters to form a canonicalized `signing string`.  This `signing string` is
then signed with the key associated with `keyId` and the algorithm
corresponding to `algorithm`.  The `signature` parameter is then set to the
`Base64` encoding of the signature.
     </t>
    </section>
   </section>
   
   <section anchor="canonicalization" title="Signature String Construction">
   
   <t>
In order to generate the string that is signed with a key, the client MUST take
the values of each HTTP header specified by `headers` in the order they appear.
It is out of scope for this document to dictate what headers a service provider
will want to enforce, but service providers SHOULD at minimum include the
request line, Host, and Date headers.

    <list style="numbers">
     <t>
If the header name is not `request-line` then append the lowercased header
name followed with an ASCII colon `:` and an ASCII space ` `.
     </t>
     <t>
If the header name is `request-line` then appened the HTTP request line,
otherwise append the header value.
     </t>
     <t>
If value is not the last value then append an ASCII newline `\n`. The string
MUST NOT include a trailing ASCII newline.
     </t>
    </list>
   </t>   
   <t>
The rest of this section uses the following HTTP request as an example.
    <figure>
     <artwork>
POST /foo HTTP/1.1
Host: example.org
Date: Tue, 07 Jun 2014 20:51:35 GMT
Content-Type: application/json
Digest: SHA-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=
Content-Length: 18

{"hello": "world"}
     </artwork>
    </figure>
   </t>
   
   <t>
The following sections also assume that the "rsa-key-1" keyId refers to a 
private key known to the client and a public key known to the server. 
The "hmac-key-1" keyId refers to key known to the client and server.
   </t>
   
   <section anchor="rsa-example" title="RSA Example">
   
   <t>
The authorization header and signature would be generated as:
    <figure>
     <artwork>
Authorization: Signature keyId="rsa-key-1",algorithm="rsa-sha256",
headers="request-line host date digest content-length",
signature="Base64(RSA-SHA256(signing string))"
     </artwork>
    </figure>
   </t>
   
   <t>
The client would compose the signing string as:
    <figure>
     <artwork>
POST /foo HTTP/1.1\n
host: example.org\n
date: Tue, 07 Jun 2014 20:51:35 GMT\n
digest: SHA-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=\n
content-length: 18
     </artwork>
    </figure>
Note that the '\n' symbols above are included to demonstrate where the new 
line character should be inserted. There is no new line on the final line of
the signing string.
   </t>

   <t>
For an RSA-based signature, the authorization header and signature would then
be generated as:
    <figure>
     <artwork>
Authorization: Signature keyId="rsa-key-1",algorithm="rsa-sha256",
headers="request-line host date digest content-length",
signature="Base64(RSA-SHA256(signing string))"
     </artwork>
    </figure>
   </t>
  </section>
  
  <section anchor="hmac-example" title="HMAC Example">

   <t>
For an HMAC-based signature without a list of headers specified, the 
authorization header and signature would be generated as:
    <figure>
     <artwork>
Authorization: Signature keyId="hmac-key-1",algorithm="hmac-sha1",
headers="request-line host date digest content-length",
signature="Base64(HMAC-SHA1(signing string))"
     </artwork>
    </figure>
   </t>

   <t>
The only difference between the RSA Example and the HMAC Example is the
signature algorithm that is used. The client would compose the signing string 
in the same way as the RSA Example above:
    <figure>
     <artwork>
POST /foo HTTP/1.1\n
host: example.org\n
date: Tue, 07 Jun 2014 20:51:35 GMT\n
digest: SHA-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=\n
content-length: 18
     </artwork>
    </figure>
   </t>

    </section>
   </section>
  </section>
 </section>

 <section anchor="appendix-a" title="Appendix A: Security Considerations">
  <t>
There are a number of security considerations to take into account when implementing
or utilizing this specification. A thorough security analysis of this protocol,
including its strengths and weaknesses, can be found in 
<eref target="https://web-payments.org/specs/source/http-signatures-audit/">Security Considerations for HTTP Signatures</eref>.
  </t>
 </section>

 <section anchor="appendix-b" title="Appendix B: Extensions">
  <t>
This specification was designed to be simple, modular, and extensible. There
are a number of other specifications that build on this one. For
example, the 
<eref target="https://web-payments.org/specs/source/http-signature-nonces/">HTTP Signature Nonces</eref>
specification details how to
use HTTP Signatures over a non-secured channel like HTTP and the 
<eref target="https://web-payments.org/specs/source/http-signature-trailers/">HTTP Signature Trailers</eref>
specification explains how to apply HTTP
Signatures to streaming content. Developers that desire more functionality
than this specification provides are urged to ensure that an extension
specification doesn't already exist before implementing a proprietary 
extension.
  </t>
 </section>

 <section anchor="appendix-c" title="Appendix C: Test Values">
  <t>
The following test data uses the following RSA 2048-bit keys, which we will 
refer to as `keyId=Test` in the following samples:

   <figure>
    <artwork>
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCFENGw33yGihy92pDjZQhl0C3
6rPJj+CvfSC8+q28hxA161QFNUd13wuCTUcq0Qd2qsBe/2hFyc2DCJJg0h1L78+6
Z4UMR7EOcpfdUE9Hf3m/hs+FUR45uBJeDK1HSFHD8bHKD6kv8FPGfJTotc+2xjJw
oYi+1hqp1fIekaxsyQIDAQAB
-----END PUBLIC KEY-----
    </artwork>
   </figure>

   <figure>
    <artwork>
-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQDCFENGw33yGihy92pDjZQhl0C36rPJj+CvfSC8+q28hxA161QF
NUd13wuCTUcq0Qd2qsBe/2hFyc2DCJJg0h1L78+6Z4UMR7EOcpfdUE9Hf3m/hs+F
UR45uBJeDK1HSFHD8bHKD6kv8FPGfJTotc+2xjJwoYi+1hqp1fIekaxsyQIDAQAB
AoGBAJR8ZkCUvx5kzv+utdl7T5MnordT1TvoXXJGXK7ZZ+UuvMNUCdN2QPc4sBiA
QWvLw1cSKt5DsKZ8UETpYPy8pPYnnDEz2dDYiaew9+xEpubyeW2oH4Zx71wqBtOK
kqwrXa/pzdpiucRRjk6vE6YY7EBBs/g7uanVpGibOVAEsqH1AkEA7DkjVH28WDUg
f1nqvfn2Kj6CT7nIcE3jGJsZZ7zlZmBmHFDONMLUrXR/Zm3pR5m0tCmBqa5RK95u
412jt1dPIwJBANJT3v8pnkth48bQo/fKel6uEYyboRtA5/uHuHkZ6FQF7OUkGogc
mSJluOdc5t6hI1VsLn0QZEjQZMEOWr+wKSMCQQCC4kXJEsHAve77oP6HtG/IiEn7
kpyUXRNvFsDE0czpJJBvL/aRFUJxuRK91jhjC68sA7NsKMGg5OXb5I5Jj36xAkEA
gIT7aFOYBFwGgQAQkWNKLvySgKbAZRTeLBacpHMuQdl1DfdntvAyqpAZ0lY0RKmW
G6aFKaqQfOXKCyWoUiVknQJAXrlgySFci/2ueKlIE1QqIiLSZ8V8OlpFLRnb1pzI
7U1yQXnTAEFYM560yJlzUpOb1V4cScGd365tiSMvxLOvTA==
-----END RSA PRIVATE KEY-----
    </artwork>
   </figure>
  </t>

  <t>
All examples use this request:
   <figure>
    <artwork>
POST /foo?param=value&amp;pet=dog HTTP/1.1
Host: example.com
Date: Thu, 05 Jan 2014 21:31:40 GMT
Content-Type: application/json
Digest: SHA-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=
Content-Length: 18

{"hello": "world"}
    </artwork>
   </figure>
  </t>

  <section anchor="default-test" title="Default Test">
   <t>
If a list of headers is not included, the date is the only header that is
signed by default. The string to sign would be:
    <figure>
     <artwork>
date: Thu, 05 Jan 2014 21:31:40 GMT
    </artwork>
   </figure>
   </t>
   
   <t>
The Authorization header would be:
    <figure>
     <artwork>
Authorization: Signature keyId="Test",algorithm="rsa-sha256",
signature="ATp0r26dbMIxOopqw0OfABDT7CKMIoENumuruOtarj8n/97Q3htH
FYpH8yOSQk3Z5zh8UxUym6FYTb5+A0Nz3NRsXJibnYi7brE/4tx5But9kkFGzG+
xpUmimN4c3TMN7OFH//+r8hBf7BT9/GmHDUVZT2JzWGLZES2xDOUuMtA="
    </artwork>
   </figure>
   </t>
  </section>

  <section anchor="basic-test" title="Basic Test">
   <t>
The minimum recommended data to sign is the request-line, host, and date. In
this case, the string to sign would be:
    <figure>
     <artwork>
POST /foo?param=value&amp;pet=dog HTTP/1.1
host: example.com
date: Thu, 05 Jan 2014 21:31:40 GMT
    </artwork>
   </figure>
   </t>
   
   <t>
The Authorization header would be:
    <figure>
     <artwork>
Authorization: Signature keyId="Test",algorithm="rsa-sha256",
headers="request-line host date", signature="KcLSABBj/m3v2Dhxi
CKJmzYJvnx74tDO1SaURD8Dr8XpugN5wpy8iBVJtpkHUIp4qBYpzx2QvD16t8X
0BUMiKc53Age+baQFWwb2iYYJzvuUL+krrl/Q7H6fPBADBsHqEZ7IE8rR0Ys3l
b7J5A6VB9J/4yVTRiBcxTypW/mpr5w="
    </artwork>
   </figure>
   </t>
  </section>
  
  <section anchor="all-headers-test" title="All Headers Test">
   <t>
A strong signature including all of the headers and a digest of the body of
the HTTP request would result in the following signing string:
    <figure>
     <artwork>
POST /foo?param=value&amp;pet=dog HTTP/1.1
host: example.com
date: Thu, 05 Jan 2014 21:31:40 GMT
content-type: application/json
digest: SHA-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=
content-length: 18
     </artwork>
    </figure>
   </t>
   
   <t>
The Authorization header would be:
    <figure>
     <artwork>
Authorization: Signature keyId="Test",algorithm="rsa-sha256",
headers="request-line host date content-type digest content-length",
signature="jgSqYK0yKclIHfF9zdApVEbDp5eqj8C4i4X76pE+XHoxugXv7q
nVrGR+30bmBgtpR39I4utq17s9ghz/2QFVxlnToYAvbSVZJ9ulLd1HQBugO0j
Oyn9sXOtcN7uNHBjqNCqUsnt0sw/cJA6B6nJZpyNqNyAXKdxZZItOuhIs78w="
     </artwork>
    </figure>
   </t>
 </section>
 </section>
</middle>
<back>
 <references title="Normative References">
  &rfc2119;
  &rfc2616;
  &rfc2617;
  &rfc3339;
  &rfc5246;
 </references>
</back>
</rfc>
