Network Working Group | M. Thomson |
Internet-Draft | Mozilla |
Intended status: Standards Track | July 1, 2015 |
Expires: January 2, 2016 |
Encrypted Content-Encoding for HTTP
draft-thomson-http-encryption-01
This memo introduces a content-coding for HTTP that allows message payloads to be encrypted.
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at http://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."
This Internet-Draft will expire on January 2, 2016.
Copyright (c) 2015 IETF Trust and the persons identified as the document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.
It is sometimes desirable to encrypt the contents of a HTTP message (request or response) so that when the payload is stored (e.g., with a HTTP PUT), only someone with the appropriate key can read it.
For example, it might be necessary to store a file on a server without exposing its contents to that server. Furthermore, that same file could be replicated to other servers (to make it more resistant to server or network failure), downloaded by clients (to make it available offline), etc. without exposing its contents.
These uses are not met by the use of TLS [RFC5246], since it only encrypts the channel between the client and server.
This document specifies a content-coding (Section 3.1.2 of [RFC7231]) for HTTP to serve these and other use cases.
This content-coding is not a direct adaptation of message-based encryption formats - such as those that are described by [RFC4880], [RFC5652], [RFC7516], and [XMLENC] - which are not suited to stream processing, which is necessary for HTTP. The format described here cleaves more closely to the lower level constructs described in [RFC5116].
To the extent that message-based encryption formats use the same primitives, the format can be considered as sequence of encrypted messages with a particular profile. For instance, Appendix A explains how the format is congruent with a sequence of JSON Web Encryption [RFC7516] values with a fixed header.
This mechanism is likely only a small part of a larger design that uses content encryption. How clients and servers acquire and identify keys will depend on the use case. Though a complete key management system is not described, this document defines an Encryption-Key header field that can be used to convey keying material.
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 [RFC2119].
The “aesgcm128” HTTP content-coding indicates that a payload has been encrypted using Advanced Encryption Standard (AES) in Galois/Counter Mode (GCM) as identified as AEAD_AES_128_GCM in [RFC5116], Section 5.1. The AEAD_AES_128_GCM algorithm uses a 128 bit content encryption key.
When this content-coding is in use, the Encryption header field (Section 3) describes how encryption has been applied. The Encryption-Key header field (Section 4) can be included to describe how the content encryption key is derived or retrieved.
The “aesgcm128” content-coding uses a single fixed set of encryption primitives. Cipher suite agility is achieved by defining a new content-coding scheme. This ensures that only the HTTP Accept-Encoding header field is necessary to negotiate the use of encryption.
The “aesgcm128” content-coding uses a fixed record size. The resulting encoding is a series of fixed-size records, with a final record that is one or more octets shorter than a fixed sized record.
+------+ input of between rs-256 | data | and rs-1 octets +------+ (one fewer for the last record) | v +-----+-----------+ | pad | data | add padding to form plaintext +-----+-----------+ | v +--------------------+ | ciphertext | encrypt with AEAD_AES_128_GCM +--------------------+ expands by 16 octets
The record size determines the length of each portion of plaintext that is enciphered, with the exception of the final record, which is necessarily smaller. The record size defaults to 4096 octets, but can be changed using the “rs” parameter on the Encryption header field.
AEAD_AES_128_GCM expands ciphertext to be 16 octets longer than its input plaintext. Therefore, the length of each enciphered record other than the last is equal to the value of the “rs” parameter plus 16 octets. A receiver MUST fail to decrypt if the final record ciphertext is 16 octets or less in size. Valid records always contain at least one byte of padding and a 16 octet authentication tag.
Each record contains between 1 and 256 octets of padding, inserted into a record before the enciphered content. Padding consists of a length byte, followed that number of zero-valued octets. A receiver MUST fail to decrypt if any padding octet other than the first is non-zero, or a record has more padding than the record size can accommodate.
The nonce for each record is a 96-bit value constructed from the record sequence number and the input keying material. Nonce derivation is covered in Section 3.3.
The additional data passed to each invocation of AEAD_AES_128_GCM is a zero-length octet sequence.
A sequence of full-sized records can be truncated to produce a shorter sequence of records with valid authentication tags. To prevent an attacker from truncating a stream, an encoder MUST append a record that contains only padding and is smaller than the full record size if the final record ends on a record boundary. A receiver MUST treat the stream as failed due to truncation if the final record is the full record size.
A consequence of this record structure is that range requests [RFC7233] and random access to encrypted payload bodies are possible at the granularity of the record size. However, without data from adjacent ranges, partial records cannot be used. Thus, it is best if records start and end on multiples of the record size, plus the 16 octet authentication tag size.
The Encryption HTTP header field describes the encrypted content encoding(s) that have been applied to a payload body, and therefore how those content encoding(s) can be removed.
The Encryption header field uses the extended ABNF syntax defined in Section 1.2 of [RFC7230] and the parameter rule from [RFC7231]
Encryption-val = #encryption_params encryption_params = [ parameter *( ";" parameter ) ]
If the payload is encrypted more than once (as reflected by having multiple content-codings that imply encryption), each application of the content encoding is reflected in the Encryption header field, in the order in which they were applied.
The Encryption header MAY be omitted if the sender does not intend for the immediate recipient to be able to decrypt the payload body. Alternatively, the Encryption header field MAY be omitted if the sender intends for the recipient to acquire the header field by other means.
Servers processing PUT requests MUST persist the value of the Encryption header field, unless they remove the content-coding by decrypting the payload.
The following parameters are used in determining the content encryption key that is used for encryption:
In order to allow the reuse of keying material for multiple different HTTP messages, a content encryption key is derived for each message. The content encryption key is derived from the decoded value of the “salt” parameter using the HMAC-based key derivation function (HKDF) described in [RFC5869] using the SHA-256 hash algorithm [FIPS180-2].
The decoded value of the “salt” parameter is the salt input to HKDF function. The keying material identified by the “keyid” parameter is the input keying material (IKM) to HKDF. Input keying material can either be prearranged, or can be described using the Encryption-Key header field (Section 4). The first step of HKDF is therefore:
PRK = HMAC-SHA-256(salt, IKM)
AEAD_AES_128_GCM requires a 16 octet (128 bit) content encryption key, so the length (L) parameter to HKDF is 16. The info parameter is set to the ASCII-encoded string “Content-Encoding: aesgcm128”. The second step of HKDF can therefore be simplified to the first 16 octets of a single HMAC:
CEK = HMAC-SHA-256(PRK, "Content-Encoding: aesgcm128" || 0x01)
The nonce input to AEAD_AES_128_GCM is constructed for each record. The nonce for each record is a 12 octet (96 bit) value is produced from the record sequence number and a value derived from the input keying material.
The input keying material and salt values are input to HKDF with different info and length parameters. The info parameter for the nonce is the ASCII-encoded string “Content-Encoding: nonce” and the length (L) parameter is 12 octets.
The result is combined with the record sequence number - using exclusive or - to produce the nonce. The record sequence number (SEQ) is a 96-bit unsigned integer in network byte order that starts at zero.
Thus, the final nonce for each record is a 12 octet value:
NONCE = HMAC-SHA-256(PRK, "Content-Encoding: nonce" || 0x01) ^ SEQ
An Encryption-Key header field can be used to describe the input keying material used in the Encryption header field.
The Encryption-Key header field uses the extended ABNF syntax defined in Section 1.2 of [RFC7230] and the parameter rule from [RFC7231].
Encryption-Key-val = #encryption_key_params encryption_key_params = [ parameter *( ";" parameter ) ]
The input keying material used by the content-encoding key derivation (see Section 3.2) can be determined based on the information in the Encryption-Key header field. The method for key derivation depends on the parameters that are present in the header field.
The value or values provided in the Encryption-Key header field is valid only for the current HTTP message unless additional information indicates a greater scope.
Note that different methods for determining input keying material will produce different amounts of data. The HKDF process ensures that the final content encryption key is the necessary size.
Alternative methods for determining input keying material MAY be defined by specifications that use this content-encoding.
The “key” parameter is decoded and used as the input keying material if present. The “key” parameter MUST decode to at least 16 octets in order to be used as input keying material for “aesgcm128” content encoding.
Other key determination parameters can be ignored if the “key” parameter is present.
The “dh” parameter is included to describe a Diffie-Hellman share, either modp (or finite field) Diffie-Hellman [DH] or elliptic curve Diffie-Hellman (ECDH) [RFC4492].
This share is combined with other information at the recipient to determine the HKDF input keying material. In order for the exchange to be successful, the following information MUST be established out of band:
In addition to identifying which content-encoding this input keying material is used for, the “keyid” parameter is used to identify this additional information at the receiver.
The intended recipient recovers their private key and are then able to generate a shared secret using the appropriate Diffie-Hellman process.
Specifications that rely on an Diffie-Hellman exchange for determining input keying material MUST either specify the parameters for Diffie-Hellman (group parameters, or curves and point format) that are used, or describe how those parameters are negotiated between sender and receiver.
HTTP/1.1 200 OK Content-Type: application/octet-stream Content-Encoding: aesgcm128 Connection: close Encryption: keyid="http://example.org/bob/keys/123"; salt="XZwpw6o37R-6qoZjw6KwAw" [encrypted payload]
Here, a successful HTTP GET response has been encrypted using input keying material that is identified by a URI.
Note that the media type has been changed to “application/octet-stream” to avoid exposing information about the content.
HTTP/1.1 200 OK Content-Type: text/html Content-Encoding: aesgcm128, gzip Transfer-Encoding: chunked Encryption: keyid="mailto:me@example.com"; salt="m2hJ_NttRtFyUiMRPwfpHA" [encrypted payload]
PUT /thing HTTP/1.1 Host: storage.example.com Content-Type: application/http Content-Encoding: aesgcm128, aesgcm128 Content-Length: 1234 Encryption: keyid="mailto:me@example.com"; salt="NfzOeuV5USPRA-n_9s1Lag", keyid="http://example.org/bob/keys/123"; salt="bDMSGoc2uobK_IhavSHsHA"; rs=1200 [encrypted payload]
Here, a PUT request has been encrypted twice with different input keying material; decrypting twice is necessary to read the content. The outer layer of encryption uses a 1200 octet record size.
HTTP/1.1 200 OK Content-Length: 32 Content-Encoding: aesgcm128 Encryption: keyid="a1"; salt="ibZx1RNz537h1XNkRcPpjA" Encryption-Key: keyid="a1"; key="9Z57YCb3dK95dSsdFJbkag" zK3kpG__Z8whjIkG6RYgPz11oUkTKcxPy9WP-VPMfuc
This example shows the string “I am the walrus” encrypted using an directly provided value for the input keying material. The content body contains a single record only and is shown here encoded in URL-safe base64 for presentation reasons only.
HTTP/1.1 200 OK Content-Length: 32 Content-Encoding: aesgcm128 Encryption: keyid="dhkey"; salt="5hpuYfxDzG6nSs9-EQuaBg" Encryption-Key: keyid="dhkey"; dh="BLsyIPbDn6bquEOwHaju2gj8kUVoflzTtPs_6fGoock_ dwxi1BcgFtObPVnic4alcEucx8I6G8HmEZCJnAl36Zg" BmuHqRzdD4W1mibxglrPiRHZRSY49Dzdm6jHrWXzZrE
This example shows the same string, “I am the walrus”, encrypted using ECDH over the P-256 curve [FIPS186]. The content body is shown here encoded in URL-safe base64 for presentation reasons only.
The receiver (in this case, the HTTP client) uses a key pair that is identified by the string “dhkey” and the sender (the server) uses a key pair for which the public share is included in the “dh” parameter above. The keys shown below use uncompressed points [X.692] encoded using URL-safe base64. Line wrapping is added for presentation purposes only.
Receiver: private key: iCjNf8v4ox_g1rJuSs_gbNmYuUYx76ZRruQs_CHRzDg public key: BPM1w41cSD4BMeBTY0Fz9ryLM-LeM22Dvt0gaLRukf05 rMhzFAvxVW_mipg5O0hkWad9ZWW0uMRO2Nrd32v8odQ Sender: private key: W0cxgeHDZkR3uMQYAbVgF5swKQUAR7DgoTaaQVlA-Fg public key: <the value of the "dh" parameter>
This mechanism assumes the presence of a key management framework that is used to manage the distribution of keys between valid senders and receivers. Defining key management is part of composing this mechanism into a larger application, protocol, or framework.
Implementation of cryptography - and key management in particular - can be difficult. For instance, implementations need to account for the potential for exposing keying material on side channels, such as might be exposed by the time it takes to perform a given operation. The requirements for a good implementation of cryptographic algorithms can change over time.
Encrypting different plaintext with the same content encryption key and nonce in AES-GCM is not safe [RFC5116]. The scheme defined here uses a fixed progression of nonce values. Thus, a new content encryption key is needed for every application of the content encoding. Since input keying material can be reused, a unique “salt” parameter is needed to ensure a content encryption key is not reused.
If a content encryption key is reused - that is, if input keying material and salt are reused - this could expose the plaintext and the authentication key, nullifying the protection offered by encryption. Thus, if the same input keying material is reused, then the salt parameter MUST be unique each time. This ensures that the content encryption key is not reused. An implementation SHOULD generate a random salt parameter for every message; a counter could achieve the same result.
This mechanism only provides content origin authentication. The authentication tag only ensures that an entity with access to the content encryption key produced the encrypted data.
Any entity with the content encryption key can therefore produce content that will be accepted as valid. This includes all recipients of the same HTTP message.
Furthermore, any entity that is able to modify both the Encryption header field and the HTTP message body can replace the contents. Without the content encryption key or the input keying material, modifications to or replacement of parts of a payload body are not possible.
Because only the payload body is encrypted, information exposed in header fields is visible to anyone who can read the HTTP message. This could expose side-channel information.
For example, the Content-Type header field can leak information about the payload body.
There are a number of strategies available to mitigate this threat, depending upon the application’s threat model and the users’ tolerance for leaked information:
This mechanism only offers encryption of content; it does not perform authentication or authorization, which still needs to be performed (e.g., by HTTP authentication [RFC7235]).
This is especially relevant when a HTTP PUT request is accepted by a server; if the request is unauthenticated, it becomes possible for a third party to deny service and/or poison the store.
Applications using this mechanism need to be aware that the size of encrypted messages, as well as their timing, HTTP methods, URIs and so on, may leak sensitive information.
This risk can be mitigated through the use of the padding that this mechanism provides. Alternatively, splitting up content into segments and storing the separately might reduce exposure. HTTP/2 [RFC7540] combined with TLS [RFC5246] might be used to hide the size of individual messages.
This memo registers the “encrypted” HTTP content-coding in the HTTP Content Codings Registry, as detailed in Section 2.
This memo registers the “Encryption” HTTP header field in the Permanent Message Header Registry, as detailed in Section 3.
This memo registers the “Encryption-Key” HTTP header field in the Permanent Message Header Registry, as detailed in Section 4.
This memo establishes a registry for parameters used by the “Encryption” header field under the “Hypertext Transfer Protocol (HTTP) Parameters” grouping. The “Hypertext Transfer Protocol (HTTP) Encryption Parameters” operates under an “Specification Required” policy [RFC5226].
Entries in this registry are expected to include the following information:
The initial contents of this registry are:
This memo establishes a registry for parameters used by the “Encryption-Key” header field under the “Hypertext Transfer Protocol (HTTP) Parameters” grouping. The “Hypertext Transfer Protocol (HTTP) Encryption Parameters” operates under an “Specification Required” policy [RFC5226].
Entries in this registry are expected to include the following information:
The initial contents of this registry are:
The “aesgcm128” content encoding can be considered as a sequence of JSON Web Encryption (JWE) objects [RFC7516], each corresponding to a single fixed size record. The following transformations are applied to a JWE object that might be expressed using the JWE Compact Serialization:
Thus, the example in Section 5.4 can be rendered using the JWE Compact Serialization as:
eyAiYWxnIjogImRpciIsICJlbmMiOiAiQTEyOEdDTSIgfQ..AAAAAAAAAAAAAAAA. LwTC-fwdKh8de0smD2jfzA.eh1vURhu65M2lxhctbbntA
Where the first line represents the fixed JWE Protected Header, JWE Encrypted Key, and JWE Initialization Vector, all of which are determined algorithmically. The second line contains the encoded body, split into JWE Ciphertext and JWE Authentication Tag.
Mark Nottingham was an original author of this document.
The following people provided valuable feedback and suggestions: Richard Barnes, Mike Jones, Stephen Farrell, Eric Rescorla, and Jim Schaad.